nodes
stringlengths
501
22.4k
edges
stringlengths
138
5.07k
code
stringlengths
108
19.3k
0, module; 1, function_definition; 2, function_name:usearch_chimera_filter_de_novo; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, if_statement; 17, if_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, if_statement; 22, expression_statement; 23, if_statement; 24, expression_statement; 25, if_statement; 26, return_statement; 27, identifier:output_chimera_filepath; 28, None; 29, identifier:output_non_chimera_filepath; 30, None; 31, identifier:abundance_skew; 32, float:2.0; 33, identifier:log_name; 34, string:"uchime_de_novo_chimera_filtering.log"; 35, identifier:usersort; 36, False; 37, identifier:HALT_EXEC; 38, False; 39, identifier:save_intermediate_files; 40, False; 41, identifier:remove_usearch_logs; 42, False; 43, identifier:working_dir; 44, None; 45, comment:""" Chimera filter de novo, output chimeras and non-chimeras to fastas fasta_filepath = input fasta file, generally a dereplicated fasta output_chimera_filepath = output chimera filepath output_non_chimera_filepath = output non chimera filepath abundance_skew = abundance skew setting for de novo filtering. usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """; 46, not_operator; 47, block; 48, not_operator; 49, block; 50, assignment; 51, assignment; 52, assignment; 53, identifier:usersort; 54, block; 55, assignment; 56, not_operator; 57, block; 58, assignment; 59, not_operator; 60, block; 61, expression_list; 62, identifier:output_chimera_filepath; 63, expression_statement; 64, identifier:output_non_chimera_filepath; 65, expression_statement; 66, identifier:log_filepath; 67, call; 68, identifier:params; 69, dictionary; 70, identifier:app; 71, call; 72, expression_statement; 73, identifier:data; 74, dictionary; 75, identifier:remove_usearch_logs; 76, expression_statement; 77, identifier:app_result; 78, call; 79, identifier:save_intermediate_files; 80, expression_statement; 81, identifier:app_result; 82, identifier:output_non_chimera_filepath; 83, assignment; 84, assignment; 85, identifier:join; 86, argument_list; 87, pair; 88, identifier:Usearch; 89, argument_list; 90, call; 91, pair; 92, pair; 93, pair; 94, assignment; 95, identifier:app; 96, argument_list; 97, call; 98, pattern_list; 99, call; 100, pattern_list; 101, call; 102, identifier:working_dir; 103, identifier:log_name; 104, string; 105, identifier:abundance_skew; 106, identifier:params; 107, keyword_argument; 108, keyword_argument; 109, attribute; 110, argument_list; 111, string; 112, identifier:fasta_filepath; 113, string; 114, identifier:output_chimera_filepath; 115, string; 116, identifier:output_non_chimera_filepath; 117, subscript; 118, identifier:log_filepath; 119, identifier:data; 120, identifier:remove_files; 121, argument_list; 122, identifier:_; 123, identifier:output_chimera_filepath; 124, identifier:mkstemp; 125, argument_list; 126, identifier:_; 127, identifier:output_non_chimera_filepath; 128, identifier:mkstemp; 129, argument_list; 130, string_content:--abskew; 131, identifier:WorkingDir; 132, identifier:working_dir; 133, identifier:HALT_EXEC; 134, identifier:HALT_EXEC; 135, subscript; 136, identifier:on; 137, string_content:--uchime; 138, string_content:--chimeras; 139, string_content:--nonchimeras; 140, identifier:data; 141, string; 142, list; 143, keyword_argument; 144, keyword_argument; 145, keyword_argument; 146, keyword_argument; 147, attribute; 148, string; 149, string_content:--log; 150, identifier:output_chimera_filepath; 151, identifier:prefix; 152, string; 153, identifier:suffix; 154, string; 155, identifier:prefix; 156, string; 157, identifier:suffix; 158, string; 159, identifier:app; 160, identifier:Parameters; 161, string_content:--usersort; 162, string_content:uchime_chimeras_; 163, string_content:.fasta; 164, string_content:uchime_non_chimeras_; 165, string_content:.fasta
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 6, 27; 6, 28; 7, 29; 7, 30; 8, 31; 8, 32; 9, 33; 9, 34; 10, 35; 10, 36; 11, 37; 11, 38; 12, 39; 12, 40; 13, 41; 13, 42; 14, 43; 14, 44; 15, 45; 16, 46; 16, 47; 17, 48; 17, 49; 18, 50; 19, 51; 20, 52; 21, 53; 21, 54; 22, 55; 23, 56; 23, 57; 24, 58; 25, 59; 25, 60; 26, 61; 46, 62; 47, 63; 48, 64; 49, 65; 50, 66; 50, 67; 51, 68; 51, 69; 52, 70; 52, 71; 54, 72; 55, 73; 55, 74; 56, 75; 57, 76; 58, 77; 58, 78; 59, 79; 60, 80; 61, 81; 61, 82; 63, 83; 65, 84; 67, 85; 67, 86; 69, 87; 71, 88; 71, 89; 72, 90; 74, 91; 74, 92; 74, 93; 76, 94; 78, 95; 78, 96; 80, 97; 83, 98; 83, 99; 84, 100; 84, 101; 86, 102; 86, 103; 87, 104; 87, 105; 89, 106; 89, 107; 89, 108; 90, 109; 90, 110; 91, 111; 91, 112; 92, 113; 92, 114; 93, 115; 93, 116; 94, 117; 94, 118; 96, 119; 97, 120; 97, 121; 98, 122; 98, 123; 99, 124; 99, 125; 100, 126; 100, 127; 101, 128; 101, 129; 104, 130; 107, 131; 107, 132; 108, 133; 108, 134; 109, 135; 109, 136; 111, 137; 113, 138; 115, 139; 117, 140; 117, 141; 121, 142; 125, 143; 125, 144; 129, 145; 129, 146; 135, 147; 135, 148; 141, 149; 142, 150; 143, 151; 143, 152; 144, 153; 144, 154; 145, 155; 145, 156; 146, 157; 146, 158; 147, 159; 147, 160; 148, 161; 152, 162; 154, 163; 156, 164; 158, 165
def usearch_chimera_filter_de_novo( fasta_filepath, output_chimera_filepath=None, output_non_chimera_filepath=None, abundance_skew=2.0, log_name="uchime_de_novo_chimera_filtering.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): """ Chimera filter de novo, output chimeras and non-chimeras to fastas fasta_filepath = input fasta file, generally a dereplicated fasta output_chimera_filepath = output chimera filepath output_non_chimera_filepath = output non chimera filepath abundance_skew = abundance skew setting for de novo filtering. usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """ if not output_chimera_filepath: _, output_chimera_filepath = mkstemp(prefix='uchime_chimeras_', suffix='.fasta') if not output_non_chimera_filepath: _, output_non_chimera_filepath = mkstemp(prefix='uchime_non_chimeras_', suffix='.fasta') log_filepath = join(working_dir, log_name) params = {'--abskew': abundance_skew} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() data = {'--uchime': fasta_filepath, '--chimeras': output_chimera_filepath, '--nonchimeras': output_non_chimera_filepath } if not remove_usearch_logs: data['--log'] = log_filepath app_result = app(data) if not save_intermediate_files: remove_files([output_chimera_filepath]) return app_result, output_non_chimera_filepath
0, module; 1, function_definition; 2, function_name:usearch_cluster_seqs_ref; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, default_parameter; 21, default_parameter; 22, default_parameter; 23, expression_statement; 24, if_statement; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, if_statement; 30, if_statement; 31, expression_statement; 32, if_statement; 33, expression_statement; 34, expression_statement; 35, comment:# Need to create fasta file of all hits (with reference IDs),; 36, comment:# recluster failures if new clusters allowed, and create complete fasta; 37, comment:# file, with unique fasta label IDs.; 38, if_statement; 39, if_statement; 40, return_statement; 41, identifier:output_filepath; 42, None; 43, identifier:percent_id; 44, float:0.97; 45, identifier:sizein; 46, True; 47, identifier:sizeout; 48, True; 49, identifier:w; 50, integer:64; 51, identifier:slots; 52, integer:16769023; 53, identifier:maxrejects; 54, integer:64; 55, identifier:log_name; 56, string:"usearch_cluster_seqs.log"; 57, identifier:usersort; 58, True; 59, identifier:HALT_EXEC; 60, False; 61, identifier:save_intermediate_files; 62, False; 63, identifier:remove_usearch_logs; 64, False; 65, identifier:suppress_new_clusters; 66, False; 67, identifier:refseqs_fp; 68, None; 69, identifier:output_dir; 70, None; 71, identifier:working_dir; 72, None; 73, identifier:rev; 74, False; 75, comment:""" Cluster seqs at percent_id, output consensus fasta Also appends de novo clustered seqs if suppress_new_clusters is False. Forced to handle reference + de novo in hackish fashion as usearch does not work as listed in the helpstrings. Any failures are clustered de novo, and given unique cluster IDs. fasta_filepath = input fasta file, generally a dereplicated fasta output_filepath = output reference clustered uc filepath percent_id = minimum identity percent. sizein = not defined in usearch helpstring sizeout = not defined in usearch helpstring w = Word length for U-sorting slots = Size of compressed index table. Should be prime, e.g. 40000003. Should also specify --w, typical is --w 16 or --w 32. maxrejects = Max rejected targets, 0=ignore, default 32. log_name = string specifying output log name usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. In post chimera checked sequences, the seqs are sorted by abundance, so this should be set to True. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. suppress_new_clusters: Disables de novo OTUs when ref based OTU picking enabled. refseqs_fp: Filepath for ref based OTU picking output_dir: output directory rev = search plus and minus strands of sequences """; 76, not_operator; 77, block; 78, assignment; 79, assignment; 80, assignment; 81, assignment; 82, identifier:usersort; 83, block; 84, identifier:rev; 85, block; 86, assignment; 87, not_operator; 88, block; 89, assignment; 90, assignment; 91, identifier:suppress_new_clusters; 92, block; 93, else_clause; 94, not_operator; 95, block; 96, expression_list; 97, identifier:output_filepath; 98, expression_statement; 99, identifier:log_filepath; 100, call; 101, identifier:uc_filepath; 102, call; 103, identifier:params; 104, dictionary; 105, identifier:app; 106, call; 107, expression_statement; 108, expression_statement; 109, identifier:data; 110, dictionary; 111, identifier:remove_usearch_logs; 112, expression_statement; 113, identifier:app_result; 114, call; 115, identifier:files_to_remove; 116, list; 117, expression_statement; 118, expression_statement; 119, expression_statement; 120, comment:# Get fasta of successful ref based clusters; 121, block; 122, identifier:save_intermediate_files; 123, expression_statement; 124, identifier:app_result; 125, identifier:output_filepath; 126, assignment; 127, identifier:join; 128, argument_list; 129, identifier:join; 130, argument_list; 131, pair; 132, pair; 133, pair; 134, pair; 135, pair; 136, pair; 137, identifier:Usearch; 138, argument_list; 139, call; 140, call; 141, pair; 142, pair; 143, pair; 144, assignment; 145, identifier:app; 146, argument_list; 147, assignment; 148, assignment; 149, call; 150, expression_statement; 151, expression_statement; 152, comment:# get failures and recluster; 153, expression_statement; 154, expression_statement; 155, comment:# de novo cluster the failures; 156, expression_statement; 157, expression_statement; 158, expression_statement; 159, expression_statement; 160, expression_statement; 161, call; 162, pattern_list; 163, call; 164, identifier:working_dir; 165, identifier:log_name; 166, identifier:working_dir; 167, string:"clustered_seqs_post_chimera.uc"; 168, string; 169, identifier:sizein; 170, string; 171, identifier:sizeout; 172, string; 173, identifier:percent_id; 174, string; 175, identifier:w; 176, string; 177, identifier:slots; 178, string; 179, identifier:maxrejects; 180, identifier:params; 181, keyword_argument; 182, keyword_argument; 183, attribute; 184, argument_list; 185, attribute; 186, argument_list; 187, string; 188, identifier:fasta_filepath; 189, string; 190, identifier:uc_filepath; 191, string; 192, identifier:refseqs_fp; 193, subscript; 194, identifier:log_filepath; 195, identifier:data; 196, identifier:output_fna_filepath; 197, call; 198, pattern_list; 199, call; 200, attribute; 201, argument_list; 202, assignment; 203, assignment; 204, assignment; 205, assignment; 206, assignment; 207, assignment; 208, call; 209, call; 210, call; 211, identifier:remove_files; 212, argument_list; 213, identifier:_; 214, identifier:output_filepath; 215, identifier:mkstemp; 216, argument_list; 217, string_content:--sizein; 218, string_content:--sizeout; 219, string_content:--id; 220, string_content:--w; 221, string_content:--slots; 222, string_content:--maxrejects; 223, identifier:WorkingDir; 224, identifier:working_dir; 225, identifier:HALT_EXEC; 226, identifier:HALT_EXEC; 227, subscript; 228, identifier:on; 229, subscript; 230, identifier:on; 231, string_content:--query; 232, string_content:--uc; 233, string_content:--db; 234, identifier:data; 235, string; 236, identifier:join; 237, argument_list; 238, identifier:output_filepath; 239, identifier:labels_hits; 240, identifier:get_fasta_from_uc_file; 241, argument_list; 242, identifier:files_to_remove; 243, identifier:append; 244, identifier:uc_filepath; 245, identifier:output_fna_clustered; 246, call; 247, pattern_list; 248, line_continuation:\; 249, call; 250, identifier:output_fna_failures; 251, line_continuation:\; 252, call; 253, pattern_list; 254, line_continuation:\; 255, call; 256, pattern_list; 257, line_continuation:\; 258, call; 259, identifier:output_filepath; 260, call; 261, attribute; 262, argument_list; 263, attribute; 264, argument_list; 265, attribute; 266, argument_list; 267, identifier:files_to_remove; 268, keyword_argument; 269, keyword_argument; 270, attribute; 271, string; 272, attribute; 273, string; 274, string_content:--log; 275, identifier:output_dir; 276, string; 277, identifier:fasta_filepath; 278, identifier:uc_filepath; 279, keyword_argument; 280, keyword_argument; 281, keyword_argument; 282, identifier:join; 283, argument_list; 284, identifier:output_filepath_ref_clusters; 285, identifier:labels_hits; 286, identifier:get_fasta_from_uc_file; 287, argument_list; 288, identifier:join; 289, argument_list; 290, identifier:output_filepath_failures; 291, identifier:labels_hits; 292, identifier:get_fasta_from_uc_file; 293, argument_list; 294, identifier:app_result; 295, identifier:output_filepath_clustered_failures; 296, identifier:usearch_cluster_seqs; 297, argument_list; 298, identifier:concatenate_fastas; 299, argument_list; 300, identifier:files_to_remove; 301, identifier:append; 302, identifier:output_fna_clustered; 303, identifier:files_to_remove; 304, identifier:append; 305, identifier:output_fna_failures; 306, identifier:files_to_remove; 307, identifier:append; 308, identifier:output_filepath_clustered_failures; 309, identifier:prefix; 310, string; 311, identifier:suffix; 312, string; 313, identifier:app; 314, identifier:Parameters; 315, string_content:--usersort; 316, identifier:app; 317, identifier:Parameters; 318, string_content:--rev; 319, string_content:ref_clustered_seqs.fasta; 320, identifier:hit_type; 321, string:"H"; 322, identifier:output_dir; 323, identifier:output_dir; 324, identifier:output_fna_filepath; 325, identifier:output_fna_filepath; 326, identifier:output_dir; 327, string; 328, identifier:fasta_filepath; 329, identifier:uc_filepath; 330, keyword_argument; 331, keyword_argument; 332, keyword_argument; 333, identifier:output_dir; 334, string; 335, identifier:fasta_filepath; 336, identifier:uc_filepath; 337, keyword_argument; 338, keyword_argument; 339, keyword_argument; 340, identifier:output_fna_failures; 341, keyword_argument; 342, keyword_argument; 343, keyword_argument; 344, keyword_argument; 345, keyword_argument; 346, keyword_argument; 347, keyword_argument; 348, keyword_argument; 349, keyword_argument; 350, keyword_argument; 351, identifier:output_fna_clustered; 352, identifier:output_fna_failures; 353, keyword_argument; 354, string_content:usearch_cluster_ref_based; 355, string_content:.uc; 356, string_content:ref_clustered_seqs.fasta; 357, identifier:hit_type; 358, string:"H"; 359, identifier:output_dir; 360, identifier:output_dir; 361, identifier:output_fna_filepath; 362, identifier:output_fna_clustered; 363, string_content:ref_clustered_seqs_failures.fasta; 364, identifier:hit_type; 365, string:"N"; 366, identifier:output_dir; 367, identifier:output_dir; 368, identifier:output_fna_filepath; 369, identifier:output_fna_failures; 370, identifier:output_filepath; 371, call; 372, identifier:percent_id; 373, identifier:percent_id; 374, identifier:sizein; 375, identifier:sizein; 376, identifier:sizeout; 377, identifier:sizeout; 378, identifier:w; 379, identifier:w; 380, identifier:slots; 381, identifier:slots; 382, identifier:maxrejects; 383, identifier:maxrejects; 384, identifier:save_intermediate_files; 385, identifier:save_intermediate_files; 386, identifier:remove_usearch_logs; 387, identifier:remove_usearch_logs; 388, identifier:working_dir; 389, identifier:working_dir; 390, identifier:output_concat_filepath; 391, call; 392, identifier:join; 393, argument_list; 394, identifier:join; 395, argument_list; 396, identifier:output_dir; 397, string; 398, identifier:output_dir; 399, string; 400, string_content:clustered_seqs_reference_failures.fasta; 401, string_content:concatenated_reference_denovo_clusters.fasta
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; 3, 16; 3, 17; 3, 18; 3, 19; 3, 20; 3, 21; 3, 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; 4, 36; 4, 37; 4, 38; 4, 39; 4, 40; 6, 41; 6, 42; 7, 43; 7, 44; 8, 45; 8, 46; 9, 47; 9, 48; 10, 49; 10, 50; 11, 51; 11, 52; 12, 53; 12, 54; 13, 55; 13, 56; 14, 57; 14, 58; 15, 59; 15, 60; 16, 61; 16, 62; 17, 63; 17, 64; 18, 65; 18, 66; 19, 67; 19, 68; 20, 69; 20, 70; 21, 71; 21, 72; 22, 73; 22, 74; 23, 75; 24, 76; 24, 77; 25, 78; 26, 79; 27, 80; 28, 81; 29, 82; 29, 83; 30, 84; 30, 85; 31, 86; 32, 87; 32, 88; 33, 89; 34, 90; 38, 91; 38, 92; 38, 93; 39, 94; 39, 95; 40, 96; 76, 97; 77, 98; 78, 99; 78, 100; 79, 101; 79, 102; 80, 103; 80, 104; 81, 105; 81, 106; 83, 107; 85, 108; 86, 109; 86, 110; 87, 111; 88, 112; 89, 113; 89, 114; 90, 115; 90, 116; 92, 117; 92, 118; 92, 119; 93, 120; 93, 121; 94, 122; 95, 123; 96, 124; 96, 125; 98, 126; 100, 127; 100, 128; 102, 129; 102, 130; 104, 131; 104, 132; 104, 133; 104, 134; 104, 135; 104, 136; 106, 137; 106, 138; 107, 139; 108, 140; 110, 141; 110, 142; 110, 143; 112, 144; 114, 145; 114, 146; 117, 147; 118, 148; 119, 149; 121, 150; 121, 151; 121, 152; 121, 153; 121, 154; 121, 155; 121, 156; 121, 157; 121, 158; 121, 159; 121, 160; 123, 161; 126, 162; 126, 163; 128, 164; 128, 165; 130, 166; 130, 167; 131, 168; 131, 169; 132, 170; 132, 171; 133, 172; 133, 173; 134, 174; 134, 175; 135, 176; 135, 177; 136, 178; 136, 179; 138, 180; 138, 181; 138, 182; 139, 183; 139, 184; 140, 185; 140, 186; 141, 187; 141, 188; 142, 189; 142, 190; 143, 191; 143, 192; 144, 193; 144, 194; 146, 195; 147, 196; 147, 197; 148, 198; 148, 199; 149, 200; 149, 201; 150, 202; 151, 203; 153, 204; 154, 205; 156, 206; 157, 207; 158, 208; 159, 209; 160, 210; 161, 211; 161, 212; 162, 213; 162, 214; 163, 215; 163, 216; 168, 217; 170, 218; 172, 219; 174, 220; 176, 221; 178, 222; 181, 223; 181, 224; 182, 225; 182, 226; 183, 227; 183, 228; 185, 229; 185, 230; 187, 231; 189, 232; 191, 233; 193, 234; 193, 235; 197, 236; 197, 237; 198, 238; 198, 239; 199, 240; 199, 241; 200, 242; 200, 243; 201, 244; 202, 245; 202, 246; 203, 247; 203, 248; 203, 249; 204, 250; 204, 251; 204, 252; 205, 253; 205, 254; 205, 255; 206, 256; 206, 257; 206, 258; 207, 259; 207, 260; 208, 261; 208, 262; 209, 263; 209, 264; 210, 265; 210, 266; 212, 267; 216, 268; 216, 269; 227, 270; 227, 271; 229, 272; 229, 273; 235, 274; 237, 275; 237, 276; 241, 277; 241, 278; 241, 279; 241, 280; 241, 281; 246, 282; 246, 283; 247, 284; 247, 285; 249, 286; 249, 287; 252, 288; 252, 289; 253, 290; 253, 291; 255, 292; 255, 293; 256, 294; 256, 295; 258, 296; 258, 297; 260, 298; 260, 299; 261, 300; 261, 301; 262, 302; 263, 303; 263, 304; 264, 305; 265, 306; 265, 307; 266, 308; 268, 309; 268, 310; 269, 311; 269, 312; 270, 313; 270, 314; 271, 315; 272, 316; 272, 317; 273, 318; 276, 319; 279, 320; 279, 321; 280, 322; 280, 323; 281, 324; 281, 325; 283, 326; 283, 327; 287, 328; 287, 329; 287, 330; 287, 331; 287, 332; 289, 333; 289, 334; 293, 335; 293, 336; 293, 337; 293, 338; 293, 339; 297, 340; 297, 341; 297, 342; 297, 343; 297, 344; 297, 345; 297, 346; 297, 347; 297, 348; 297, 349; 297, 350; 299, 351; 299, 352; 299, 353; 310, 354; 312, 355; 327, 356; 330, 357; 330, 358; 331, 359; 331, 360; 332, 361; 332, 362; 334, 363; 337, 364; 337, 365; 338, 366; 338, 367; 339, 368; 339, 369; 341, 370; 341, 371; 342, 372; 342, 373; 343, 374; 343, 375; 344, 376; 344, 377; 345, 378; 345, 379; 346, 380; 346, 381; 347, 382; 347, 383; 348, 384; 348, 385; 349, 386; 349, 387; 350, 388; 350, 389; 353, 390; 353, 391; 371, 392; 371, 393; 391, 394; 391, 395; 393, 396; 393, 397; 395, 398; 395, 399; 397, 400; 399, 401
def usearch_cluster_seqs_ref( fasta_filepath, output_filepath=None, percent_id=0.97, sizein=True, sizeout=True, w=64, slots=16769023, maxrejects=64, log_name="usearch_cluster_seqs.log", usersort=True, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, suppress_new_clusters=False, refseqs_fp=None, output_dir=None, working_dir=None, rev=False): """ Cluster seqs at percent_id, output consensus fasta Also appends de novo clustered seqs if suppress_new_clusters is False. Forced to handle reference + de novo in hackish fashion as usearch does not work as listed in the helpstrings. Any failures are clustered de novo, and given unique cluster IDs. fasta_filepath = input fasta file, generally a dereplicated fasta output_filepath = output reference clustered uc filepath percent_id = minimum identity percent. sizein = not defined in usearch helpstring sizeout = not defined in usearch helpstring w = Word length for U-sorting slots = Size of compressed index table. Should be prime, e.g. 40000003. Should also specify --w, typical is --w 16 or --w 32. maxrejects = Max rejected targets, 0=ignore, default 32. log_name = string specifying output log name usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. In post chimera checked sequences, the seqs are sorted by abundance, so this should be set to True. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. suppress_new_clusters: Disables de novo OTUs when ref based OTU picking enabled. refseqs_fp: Filepath for ref based OTU picking output_dir: output directory rev = search plus and minus strands of sequences """ if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_cluster_ref_based', suffix='.uc') log_filepath = join(working_dir, log_name) uc_filepath = join(working_dir, "clustered_seqs_post_chimera.uc") params = {'--sizein': sizein, '--sizeout': sizeout, '--id': percent_id, '--w': w, '--slots': slots, '--maxrejects': maxrejects} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() if rev: app.Parameters['--rev'].on() data = {'--query': fasta_filepath, '--uc': uc_filepath, '--db': refseqs_fp } if not remove_usearch_logs: data['--log'] = log_filepath app_result = app(data) files_to_remove = [] # Need to create fasta file of all hits (with reference IDs), # recluster failures if new clusters allowed, and create complete fasta # file, with unique fasta label IDs. if suppress_new_clusters: output_fna_filepath = join(output_dir, 'ref_clustered_seqs.fasta') output_filepath, labels_hits = get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="H", output_dir=output_dir, output_fna_filepath=output_fna_filepath) files_to_remove.append(uc_filepath) else: # Get fasta of successful ref based clusters output_fna_clustered = join(output_dir, 'ref_clustered_seqs.fasta') output_filepath_ref_clusters, labels_hits =\ get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="H", output_dir=output_dir, output_fna_filepath=output_fna_clustered) # get failures and recluster output_fna_failures =\ join(output_dir, 'ref_clustered_seqs_failures.fasta') output_filepath_failures, labels_hits =\ get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="N", output_dir=output_dir, output_fna_filepath=output_fna_failures) # de novo cluster the failures app_result, output_filepath_clustered_failures =\ usearch_cluster_seqs(output_fna_failures, output_filepath= join( output_dir, 'clustered_seqs_reference_failures.fasta'), percent_id=percent_id, sizein=sizein, sizeout=sizeout, w=w, slots=slots, maxrejects=maxrejects, save_intermediate_files=save_intermediate_files, remove_usearch_logs=remove_usearch_logs, working_dir=working_dir) output_filepath = concatenate_fastas(output_fna_clustered, output_fna_failures, output_concat_filepath=join( output_dir, 'concatenated_reference_denovo_clusters.fasta')) files_to_remove.append(output_fna_clustered) files_to_remove.append(output_fna_failures) files_to_remove.append(output_filepath_clustered_failures) if not save_intermediate_files: remove_files(files_to_remove) return app_result, output_filepath
0, module; 1, function_definition; 2, function_name:assign_reads_to_otus; 3, parameters; 4, block; 5, identifier:original_fasta; 6, identifier:filtered_fasta; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, comment:# Not sure if I feel confortable using blast as a way to recapitulate; 17, comment:# original read ids....; 18, if_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, if_statement; 24, expression_statement; 25, return_statement; 26, identifier:output_filepath; 27, None; 28, identifier:log_name; 29, string:"assign_reads_to_otus.log"; 30, identifier:perc_id_blast; 31, float:0.97; 32, identifier:global_alignment; 33, True; 34, identifier:HALT_EXEC; 35, False; 36, identifier:save_intermediate_files; 37, False; 38, identifier:remove_usearch_logs; 39, False; 40, identifier:working_dir; 41, None; 42, comment:""" Uses original fasta file, blasts to assign reads to filtered fasta original_fasta = filepath to original query fasta filtered_fasta = filepath to enumerated, filtered fasta output_filepath = output path to clusters (uc) file log_name = string specifying output log name perc_id_blast = percent ID for blasting original seqs against filtered set usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. In post chimera checked sequences, the seqs are sorted by abundance, so this should be set to True. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """; 43, not_operator; 44, block; 45, assignment; 46, assignment; 47, assignment; 48, assignment; 49, not_operator; 50, block; 51, assignment; 52, expression_list; 53, identifier:output_filepath; 54, expression_statement; 55, identifier:log_filepath; 56, call; 57, identifier:params; 58, dictionary; 59, identifier:app; 60, call; 61, identifier:data; 62, dictionary; 63, identifier:remove_usearch_logs; 64, expression_statement; 65, identifier:app_result; 66, call; 67, identifier:app_result; 68, identifier:output_filepath; 69, assignment; 70, identifier:join; 71, argument_list; 72, pair; 73, pair; 74, identifier:Usearch; 75, argument_list; 76, pair; 77, pair; 78, pair; 79, assignment; 80, identifier:app; 81, argument_list; 82, pattern_list; 83, call; 84, identifier:working_dir; 85, identifier:log_name; 86, string; 87, identifier:perc_id_blast; 88, string; 89, identifier:global_alignment; 90, identifier:params; 91, keyword_argument; 92, keyword_argument; 93, string; 94, identifier:original_fasta; 95, string; 96, identifier:filtered_fasta; 97, string; 98, identifier:output_filepath; 99, subscript; 100, identifier:log_filepath; 101, identifier:data; 102, identifier:_; 103, identifier:output_filepath; 104, identifier:mkstemp; 105, argument_list; 106, string_content:--id; 107, string_content:--global; 108, identifier:WorkingDir; 109, identifier:working_dir; 110, identifier:HALT_EXEC; 111, identifier:HALT_EXEC; 112, string_content:--query; 113, string_content:--db; 114, string_content:--uc; 115, identifier:data; 116, string; 117, keyword_argument; 118, keyword_argument; 119, string_content:--log; 120, identifier:prefix; 121, string; 122, identifier:suffix; 123, string; 124, string_content:assign_reads_to_otus; 125, string_content:.uc
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 7, 26; 7, 27; 8, 28; 8, 29; 9, 30; 9, 31; 10, 32; 10, 33; 11, 34; 11, 35; 12, 36; 12, 37; 13, 38; 13, 39; 14, 40; 14, 41; 15, 42; 18, 43; 18, 44; 19, 45; 20, 46; 21, 47; 22, 48; 23, 49; 23, 50; 24, 51; 25, 52; 43, 53; 44, 54; 45, 55; 45, 56; 46, 57; 46, 58; 47, 59; 47, 60; 48, 61; 48, 62; 49, 63; 50, 64; 51, 65; 51, 66; 52, 67; 52, 68; 54, 69; 56, 70; 56, 71; 58, 72; 58, 73; 60, 74; 60, 75; 62, 76; 62, 77; 62, 78; 64, 79; 66, 80; 66, 81; 69, 82; 69, 83; 71, 84; 71, 85; 72, 86; 72, 87; 73, 88; 73, 89; 75, 90; 75, 91; 75, 92; 76, 93; 76, 94; 77, 95; 77, 96; 78, 97; 78, 98; 79, 99; 79, 100; 81, 101; 82, 102; 82, 103; 83, 104; 83, 105; 86, 106; 88, 107; 91, 108; 91, 109; 92, 110; 92, 111; 93, 112; 95, 113; 97, 114; 99, 115; 99, 116; 105, 117; 105, 118; 116, 119; 117, 120; 117, 121; 118, 122; 118, 123; 121, 124; 123, 125
def assign_reads_to_otus(original_fasta, filtered_fasta, output_filepath=None, log_name="assign_reads_to_otus.log", perc_id_blast=0.97, global_alignment=True, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): """ Uses original fasta file, blasts to assign reads to filtered fasta original_fasta = filepath to original query fasta filtered_fasta = filepath to enumerated, filtered fasta output_filepath = output path to clusters (uc) file log_name = string specifying output log name perc_id_blast = percent ID for blasting original seqs against filtered set usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. In post chimera checked sequences, the seqs are sorted by abundance, so this should be set to True. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """ # Not sure if I feel confortable using blast as a way to recapitulate # original read ids.... if not output_filepath: _, output_filepath = mkstemp(prefix='assign_reads_to_otus', suffix='.uc') log_filepath = join(working_dir, log_name) params = {'--id': perc_id_blast, '--global': global_alignment} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) data = {'--query': original_fasta, '--db': filtered_fasta, '--uc': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath app_result = app(data) return app_result, output_filepath
0, module; 1, function_definition; 2, function_name:sort_by_abundance_usearch61; 3, parameters; 4, block; 5, identifier:seq_path; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, if_statement; 17, if_statement; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, if_statement; 22, expression_statement; 23, expression_statement; 24, return_statement; 25, identifier:output_dir; 26, string; 27, identifier:rev; 28, False; 29, identifier:minlen; 30, integer:64; 31, identifier:remove_usearch_logs; 32, False; 33, identifier:HALT_EXEC; 34, False; 35, identifier:output_fna_filepath; 36, None; 37, identifier:output_uc_filepath; 38, None; 39, identifier:log_name; 40, string:"abundance_sorted.log"; 41, identifier:threads; 42, float:1.0; 43, comment:""" usearch61 application call to sort fasta file by abundance. seq_path: fasta filepath to be clustered with usearch61 output_dir: directory to output log, OTU mapping, and intermediate files rev: enable reverse strand matching for clustering/sorting minlen: minimum sequence length remove_usearch_logs: Saves usearch log files HALT_EXEC: application controller option to halt execution output_fna_filepath: path to write sorted fasta filepath output_uc_filepath: path to write usearch61 generated .uc file log_name: filepath to write usearch61 generated log file threads: Specify number of threads used per core per CPU """; 44, not_operator; 45, block; 46, not_operator; 47, block; 48, assignment; 49, assignment; 50, identifier:rev; 51, block; 52, not_operator; 53, block; 54, assignment; 55, assignment; 56, expression_list; 57, string_content:.; 58, identifier:output_fna_filepath; 59, expression_statement; 60, identifier:output_uc_filepath; 61, expression_statement; 62, identifier:log_filepath; 63, call; 64, identifier:params; 65, dictionary; 66, expression_statement; 67, identifier:remove_usearch_logs; 68, expression_statement; 69, identifier:app; 70, call; 71, identifier:app_result; 72, call; 73, identifier:output_fna_filepath; 74, identifier:output_uc_filepath; 75, identifier:app_result; 76, assignment; 77, assignment; 78, identifier:join; 79, argument_list; 80, pair; 81, pair; 82, pair; 83, pair; 84, pair; 85, pair; 86, assignment; 87, assignment; 88, identifier:Usearch61; 89, argument_list; 90, identifier:app; 91, argument_list; 92, pattern_list; 93, call; 94, pattern_list; 95, call; 96, identifier:output_dir; 97, identifier:log_name; 98, string; 99, identifier:minlen; 100, string; 101, True; 102, string; 103, identifier:seq_path; 104, string; 105, identifier:output_fna_filepath; 106, string; 107, identifier:output_uc_filepath; 108, string; 109, identifier:threads; 110, subscript; 111, string; 112, subscript; 113, identifier:log_filepath; 114, identifier:params; 115, keyword_argument; 116, keyword_argument; 117, identifier:_; 118, identifier:output_fna_filepath; 119, identifier:mkstemp; 120, argument_list; 121, identifier:_; 122, identifier:output_uc_filepath; 123, identifier:mkstemp; 124, argument_list; 125, string_content:--minseqlength; 126, string_content:--sizeout; 127, string_content:--derep_fulllength; 128, string_content:--output; 129, string_content:--uc; 130, string_content:--threads; 131, identifier:params; 132, string; 133, string_content:both; 134, identifier:params; 135, string; 136, identifier:WorkingDir; 137, identifier:output_dir; 138, identifier:HALT_EXEC; 139, identifier:HALT_EXEC; 140, keyword_argument; 141, keyword_argument; 142, keyword_argument; 143, keyword_argument; 144, string_content:--strand; 145, string_content:--log; 146, identifier:prefix; 147, string; 148, identifier:suffix; 149, string; 150, identifier:prefix; 151, string; 152, identifier:suffix; 153, string; 154, string_content:abundance_sorted; 155, string_content:.fna; 156, string_content:abundance_sorted; 157, string_content:.uc
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 6, 25; 6, 26; 7, 27; 7, 28; 8, 29; 8, 30; 9, 31; 9, 32; 10, 33; 10, 34; 11, 35; 11, 36; 12, 37; 12, 38; 13, 39; 13, 40; 14, 41; 14, 42; 15, 43; 16, 44; 16, 45; 17, 46; 17, 47; 18, 48; 19, 49; 20, 50; 20, 51; 21, 52; 21, 53; 22, 54; 23, 55; 24, 56; 26, 57; 44, 58; 45, 59; 46, 60; 47, 61; 48, 62; 48, 63; 49, 64; 49, 65; 51, 66; 52, 67; 53, 68; 54, 69; 54, 70; 55, 71; 55, 72; 56, 73; 56, 74; 56, 75; 59, 76; 61, 77; 63, 78; 63, 79; 65, 80; 65, 81; 65, 82; 65, 83; 65, 84; 65, 85; 66, 86; 68, 87; 70, 88; 70, 89; 72, 90; 72, 91; 76, 92; 76, 93; 77, 94; 77, 95; 79, 96; 79, 97; 80, 98; 80, 99; 81, 100; 81, 101; 82, 102; 82, 103; 83, 104; 83, 105; 84, 106; 84, 107; 85, 108; 85, 109; 86, 110; 86, 111; 87, 112; 87, 113; 89, 114; 89, 115; 89, 116; 92, 117; 92, 118; 93, 119; 93, 120; 94, 121; 94, 122; 95, 123; 95, 124; 98, 125; 100, 126; 102, 127; 104, 128; 106, 129; 108, 130; 110, 131; 110, 132; 111, 133; 112, 134; 112, 135; 115, 136; 115, 137; 116, 138; 116, 139; 120, 140; 120, 141; 124, 142; 124, 143; 132, 144; 135, 145; 140, 146; 140, 147; 141, 148; 141, 149; 142, 150; 142, 151; 143, 152; 143, 153; 147, 154; 149, 155; 151, 156; 153, 157
def sort_by_abundance_usearch61(seq_path, output_dir='.', rev=False, minlen=64, remove_usearch_logs=False, HALT_EXEC=False, output_fna_filepath=None, output_uc_filepath=None, log_name="abundance_sorted.log", threads=1.0): """ usearch61 application call to sort fasta file by abundance. seq_path: fasta filepath to be clustered with usearch61 output_dir: directory to output log, OTU mapping, and intermediate files rev: enable reverse strand matching for clustering/sorting minlen: minimum sequence length remove_usearch_logs: Saves usearch log files HALT_EXEC: application controller option to halt execution output_fna_filepath: path to write sorted fasta filepath output_uc_filepath: path to write usearch61 generated .uc file log_name: filepath to write usearch61 generated log file threads: Specify number of threads used per core per CPU """ if not output_fna_filepath: _, output_fna_filepath = mkstemp(prefix='abundance_sorted', suffix='.fna') if not output_uc_filepath: _, output_uc_filepath = mkstemp(prefix='abundance_sorted', suffix='.uc') log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--sizeout': True, '--derep_fulllength': seq_path, '--output': output_fna_filepath, '--uc': output_uc_filepath, '--threads': threads } if rev: params['--strand'] = 'both' if not remove_usearch_logs: params['--log'] = log_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return output_fna_filepath, output_uc_filepath, app_result
0, module; 1, function_definition; 2, function_name:sort_by_length_usearch61; 3, parameters; 4, block; 5, identifier:seq_path; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, if_statement; 17, expression_statement; 18, expression_statement; 19, return_statement; 20, identifier:output_dir; 21, string:"."; 22, identifier:minlen; 23, integer:64; 24, identifier:remove_usearch_logs; 25, False; 26, identifier:HALT_EXEC; 27, False; 28, identifier:output_fna_filepath; 29, None; 30, identifier:log_name; 31, string:"length_sorted.log"; 32, comment:""" usearch61 application call to sort fasta file by length. seq_path: fasta filepath to be clustered with usearch61 output_dir: directory to output log, OTU mapping, and intermediate files minlen: minimum sequence length remove_usearch_logs: Saves usearch log files HALT_EXEC: application controller option to halt execution output_fna_filepath: path to write sorted fasta filepath log_name: filepath to write usearch61 generated log file """; 33, not_operator; 34, block; 35, assignment; 36, assignment; 37, not_operator; 38, block; 39, assignment; 40, assignment; 41, expression_list; 42, identifier:output_fna_filepath; 43, expression_statement; 44, identifier:log_filepath; 45, call; 46, identifier:params; 47, dictionary; 48, identifier:remove_usearch_logs; 49, expression_statement; 50, identifier:app; 51, call; 52, identifier:app_result; 53, call; 54, identifier:output_fna_filepath; 55, identifier:app_result; 56, assignment; 57, identifier:join; 58, argument_list; 59, pair; 60, pair; 61, pair; 62, assignment; 63, identifier:Usearch61; 64, argument_list; 65, identifier:app; 66, argument_list; 67, pattern_list; 68, call; 69, identifier:output_dir; 70, identifier:log_name; 71, string; 72, identifier:minlen; 73, string; 74, identifier:seq_path; 75, string; 76, identifier:output_fna_filepath; 77, subscript; 78, identifier:log_filepath; 79, identifier:params; 80, keyword_argument; 81, keyword_argument; 82, identifier:_; 83, identifier:output_fna_filepath; 84, identifier:mkstemp; 85, argument_list; 86, string_content:--minseqlength; 87, string_content:--sortbylength; 88, string_content:--output; 89, identifier:params; 90, string; 91, identifier:WorkingDir; 92, identifier:output_dir; 93, identifier:HALT_EXEC; 94, identifier:HALT_EXEC; 95, keyword_argument; 96, keyword_argument; 97, string_content:--log; 98, identifier:prefix; 99, string; 100, identifier:suffix; 101, string; 102, string_content:length_sorted; 103, string_content:.fna
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; 6, 20; 6, 21; 7, 22; 7, 23; 8, 24; 8, 25; 9, 26; 9, 27; 10, 28; 10, 29; 11, 30; 11, 31; 12, 32; 13, 33; 13, 34; 14, 35; 15, 36; 16, 37; 16, 38; 17, 39; 18, 40; 19, 41; 33, 42; 34, 43; 35, 44; 35, 45; 36, 46; 36, 47; 37, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 41, 54; 41, 55; 43, 56; 45, 57; 45, 58; 47, 59; 47, 60; 47, 61; 49, 62; 51, 63; 51, 64; 53, 65; 53, 66; 56, 67; 56, 68; 58, 69; 58, 70; 59, 71; 59, 72; 60, 73; 60, 74; 61, 75; 61, 76; 62, 77; 62, 78; 64, 79; 64, 80; 64, 81; 67, 82; 67, 83; 68, 84; 68, 85; 71, 86; 73, 87; 75, 88; 77, 89; 77, 90; 80, 91; 80, 92; 81, 93; 81, 94; 85, 95; 85, 96; 90, 97; 95, 98; 95, 99; 96, 100; 96, 101; 99, 102; 101, 103
def sort_by_length_usearch61(seq_path, output_dir=".", minlen=64, remove_usearch_logs=False, HALT_EXEC=False, output_fna_filepath=None, log_name="length_sorted.log"): """ usearch61 application call to sort fasta file by length. seq_path: fasta filepath to be clustered with usearch61 output_dir: directory to output log, OTU mapping, and intermediate files minlen: minimum sequence length remove_usearch_logs: Saves usearch log files HALT_EXEC: application controller option to halt execution output_fna_filepath: path to write sorted fasta filepath log_name: filepath to write usearch61 generated log file """ if not output_fna_filepath: _, output_fna_filepath = mkstemp(prefix='length_sorted', suffix='.fna') log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--sortbylength': seq_path, '--output': output_fna_filepath } if not remove_usearch_logs: params['--log'] = log_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return output_fna_filepath, app_result
0, module; 1, function_definition; 2, function_name:usearch61_fast_cluster; 3, parameters; 4, block; 5, identifier:intermediate_fasta; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, return_statement; 25, identifier:percent_id; 26, float:0.97; 27, identifier:minlen; 28, integer:64; 29, identifier:output_dir; 30, string:"."; 31, identifier:remove_usearch_logs; 32, False; 33, identifier:wordlength; 34, integer:8; 35, identifier:usearch61_maxrejects; 36, integer:8; 37, identifier:usearch61_maxaccepts; 38, integer:1; 39, identifier:HALT_EXEC; 40, False; 41, identifier:output_uc_filepath; 42, None; 43, identifier:log_name; 44, string:"fast_clustered.log"; 45, identifier:threads; 46, float:1.0; 47, comment:""" Performs usearch61 de novo fast clustering via cluster_fast option Only supposed to be used with length sorted data (and performs length sorting automatically) and does not support reverse strand matching intermediate_fasta: fasta filepath to be clustered with usearch61 percent_id: percentage id to cluster at minlen: minimum sequence length output_dir: directory to output log, OTU mapping, and intermediate files remove_usearch_logs: Saves usearch log files wordlength: word length to use for initial high probability sequence matches usearch61_maxrejects: Set to 'default' or an int value specifying max rejects usearch61_maxaccepts: Number of accepts allowed by usearch61 HALT_EXEC: application controller option to halt execution output_uc_filepath: Path to write clusters (.uc) file. log_name: filepath to write usearch61 generated log file threads: Specify number of threads used per core per CPU """; 48, assignment; 49, assignment; 50, not_operator; 51, block; 52, assignment; 53, assignment; 54, assignment; 55, expression_list; 56, identifier:log_filepath; 57, call; 58, identifier:params; 59, dictionary; 60, identifier:remove_usearch_logs; 61, expression_statement; 62, identifier:clusters_fp; 63, identifier:output_uc_filepath; 64, identifier:app; 65, call; 66, identifier:app_result; 67, call; 68, identifier:clusters_fp; 69, identifier:app_result; 70, identifier:join; 71, argument_list; 72, pair; 73, pair; 74, pair; 75, pair; 76, pair; 77, pair; 78, pair; 79, pair; 80, pair; 81, assignment; 82, identifier:Usearch61; 83, argument_list; 84, identifier:app; 85, argument_list; 86, identifier:output_dir; 87, identifier:log_name; 88, string; 89, identifier:minlen; 90, string; 91, identifier:intermediate_fasta; 92, string; 93, identifier:percent_id; 94, string; 95, identifier:output_uc_filepath; 96, string; 97, identifier:wordlength; 98, string; 99, identifier:usearch61_maxrejects; 100, string; 101, identifier:usearch61_maxaccepts; 102, string; 103, True; 104, string; 105, identifier:threads; 106, subscript; 107, identifier:log_filepath; 108, identifier:params; 109, keyword_argument; 110, keyword_argument; 111, string_content:--minseqlength; 112, string_content:--cluster_fast; 113, string_content:--id; 114, string_content:--uc; 115, string_content:--wordlength; 116, string_content:--maxrejects; 117, string_content:--maxaccepts; 118, string_content:--usersort; 119, string_content:--threads; 120, identifier:params; 121, string; 122, identifier:WorkingDir; 123, identifier:output_dir; 124, identifier:HALT_EXEC; 125, identifier:HALT_EXEC; 126, string_content:--log
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; 3, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 6, 25; 6, 26; 7, 27; 7, 28; 8, 29; 8, 30; 9, 31; 9, 32; 10, 33; 10, 34; 11, 35; 11, 36; 12, 37; 12, 38; 13, 39; 13, 40; 14, 41; 14, 42; 15, 43; 15, 44; 16, 45; 16, 46; 17, 47; 18, 48; 19, 49; 20, 50; 20, 51; 21, 52; 22, 53; 23, 54; 24, 55; 48, 56; 48, 57; 49, 58; 49, 59; 50, 60; 51, 61; 52, 62; 52, 63; 53, 64; 53, 65; 54, 66; 54, 67; 55, 68; 55, 69; 57, 70; 57, 71; 59, 72; 59, 73; 59, 74; 59, 75; 59, 76; 59, 77; 59, 78; 59, 79; 59, 80; 61, 81; 65, 82; 65, 83; 67, 84; 67, 85; 71, 86; 71, 87; 72, 88; 72, 89; 73, 90; 73, 91; 74, 92; 74, 93; 75, 94; 75, 95; 76, 96; 76, 97; 77, 98; 77, 99; 78, 100; 78, 101; 79, 102; 79, 103; 80, 104; 80, 105; 81, 106; 81, 107; 83, 108; 83, 109; 83, 110; 88, 111; 90, 112; 92, 113; 94, 114; 96, 115; 98, 116; 100, 117; 102, 118; 104, 119; 106, 120; 106, 121; 109, 122; 109, 123; 110, 124; 110, 125; 121, 126
def usearch61_fast_cluster(intermediate_fasta, percent_id=0.97, minlen=64, output_dir=".", remove_usearch_logs=False, wordlength=8, usearch61_maxrejects=8, usearch61_maxaccepts=1, HALT_EXEC=False, output_uc_filepath=None, log_name="fast_clustered.log", threads=1.0): """ Performs usearch61 de novo fast clustering via cluster_fast option Only supposed to be used with length sorted data (and performs length sorting automatically) and does not support reverse strand matching intermediate_fasta: fasta filepath to be clustered with usearch61 percent_id: percentage id to cluster at minlen: minimum sequence length output_dir: directory to output log, OTU mapping, and intermediate files remove_usearch_logs: Saves usearch log files wordlength: word length to use for initial high probability sequence matches usearch61_maxrejects: Set to 'default' or an int value specifying max rejects usearch61_maxaccepts: Number of accepts allowed by usearch61 HALT_EXEC: application controller option to halt execution output_uc_filepath: Path to write clusters (.uc) file. log_name: filepath to write usearch61 generated log file threads: Specify number of threads used per core per CPU """ log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--cluster_fast': intermediate_fasta, '--id': percent_id, '--uc': output_uc_filepath, '--wordlength': wordlength, '--maxrejects': usearch61_maxrejects, '--maxaccepts': usearch61_maxaccepts, '--usersort': True, '--threads': threads } if not remove_usearch_logs: params['--log'] = log_filepath clusters_fp = output_uc_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return clusters_fp, app_result
0, module; 1, function_definition; 2, function_name:usearch61_smallmem_cluster; 3, parameters; 4, block; 5, identifier:intermediate_fasta; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, if_statement; 24, if_statement; 25, if_statement; 26, if_statement; 27, if_statement; 28, expression_statement; 29, expression_statement; 30, expression_statement; 31, return_statement; 32, identifier:percent_id; 33, float:0.97; 34, identifier:minlen; 35, integer:64; 36, identifier:rev; 37, False; 38, identifier:output_dir; 39, string:"."; 40, identifier:remove_usearch_logs; 41, False; 42, identifier:wordlength; 43, integer:8; 44, identifier:usearch61_maxrejects; 45, integer:32; 46, identifier:usearch61_maxaccepts; 47, integer:1; 48, identifier:sizeorder; 49, False; 50, identifier:HALT_EXEC; 51, False; 52, identifier:output_uc_filepath; 53, None; 54, identifier:log_name; 55, string:"smallmem_clustered.log"; 56, identifier:sizeout; 57, False; 58, identifier:consout_filepath; 59, None; 60, comment:""" Performs usearch61 de novo clustering via cluster_smallmem option Only supposed to be used with length sorted data (and performs length sorting automatically) and does not support reverse strand matching intermediate_fasta: fasta filepath to be clustered with usearch61 percent_id: percentage id to cluster at minlen: minimum sequence length rev: will enable reverse strand matching if True output_dir: directory to output log, OTU mapping, and intermediate files remove_usearch_logs: Saves usearch log files wordlength: word length to use for initial high probability sequence matches usearch61_maxrejects: Set to 'default' or an int value specifying max rejects usearch61_maxaccepts: Number of accepts allowed by usearch61 HALT_EXEC: application controller option to halt execution output_uc_filepath: Path to write clusters (.uc) file. log_name: filepath to write usearch61 generated log file sizeout: If True, will save abundance data in output fasta labels. consout_filepath: Needs to be set to save clustered consensus fasta filepath used for chimera checking. """; 61, assignment; 62, assignment; 63, identifier:sizeorder; 64, block; 65, not_operator; 66, block; 67, identifier:rev; 68, block; 69, else_clause; 70, identifier:sizeout; 71, block; 72, identifier:consout_filepath; 73, block; 74, assignment; 75, assignment; 76, assignment; 77, expression_list; 78, identifier:log_filepath; 79, call; 80, identifier:params; 81, dictionary; 82, expression_statement; 83, identifier:remove_usearch_logs; 84, expression_statement; 85, expression_statement; 86, block; 87, expression_statement; 88, expression_statement; 89, identifier:clusters_fp; 90, identifier:output_uc_filepath; 91, identifier:app; 92, call; 93, identifier:app_result; 94, call; 95, identifier:clusters_fp; 96, identifier:app_result; 97, identifier:join; 98, argument_list; 99, pair; 100, pair; 101, pair; 102, pair; 103, pair; 104, pair; 105, pair; 106, pair; 107, assignment; 108, assignment; 109, assignment; 110, expression_statement; 111, assignment; 112, assignment; 113, identifier:Usearch61; 114, argument_list; 115, identifier:app; 116, argument_list; 117, identifier:output_dir; 118, identifier:log_name; 119, string; 120, identifier:minlen; 121, string; 122, identifier:intermediate_fasta; 123, string; 124, identifier:percent_id; 125, string; 126, identifier:output_uc_filepath; 127, string; 128, identifier:wordlength; 129, string; 130, identifier:usearch61_maxrejects; 131, string; 132, identifier:usearch61_maxaccepts; 133, string; 134, True; 135, subscript; 136, True; 137, subscript; 138, identifier:log_filepath; 139, subscript; 140, string; 141, assignment; 142, subscript; 143, True; 144, subscript; 145, identifier:consout_filepath; 146, identifier:params; 147, keyword_argument; 148, keyword_argument; 149, string_content:--minseqlength; 150, string_content:--cluster_smallmem; 151, string_content:--id; 152, string_content:--uc; 153, string_content:--wordlength; 154, string_content:--maxrejects; 155, string_content:--maxaccepts; 156, string_content:--usersort; 157, identifier:params; 158, string; 159, identifier:params; 160, string; 161, identifier:params; 162, string; 163, string_content:both; 164, subscript; 165, string; 166, identifier:params; 167, string; 168, identifier:params; 169, string; 170, identifier:WorkingDir; 171, identifier:output_dir; 172, identifier:HALT_EXEC; 173, identifier:HALT_EXEC; 174, string_content:--sizeorder; 175, string_content:--log; 176, string_content:--strand; 177, identifier:params; 178, string; 179, string_content:plus; 180, string_content:--sizeout; 181, string_content:--consout; 182, string_content:--strand
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; 3, 16; 3, 17; 3, 18; 3, 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; 6, 32; 6, 33; 7, 34; 7, 35; 8, 36; 8, 37; 9, 38; 9, 39; 10, 40; 10, 41; 11, 42; 11, 43; 12, 44; 12, 45; 13, 46; 13, 47; 14, 48; 14, 49; 15, 50; 15, 51; 16, 52; 16, 53; 17, 54; 17, 55; 18, 56; 18, 57; 19, 58; 19, 59; 20, 60; 21, 61; 22, 62; 23, 63; 23, 64; 24, 65; 24, 66; 25, 67; 25, 68; 25, 69; 26, 70; 26, 71; 27, 72; 27, 73; 28, 74; 29, 75; 30, 76; 31, 77; 61, 78; 61, 79; 62, 80; 62, 81; 64, 82; 65, 83; 66, 84; 68, 85; 69, 86; 71, 87; 73, 88; 74, 89; 74, 90; 75, 91; 75, 92; 76, 93; 76, 94; 77, 95; 77, 96; 79, 97; 79, 98; 81, 99; 81, 100; 81, 101; 81, 102; 81, 103; 81, 104; 81, 105; 81, 106; 82, 107; 84, 108; 85, 109; 86, 110; 87, 111; 88, 112; 92, 113; 92, 114; 94, 115; 94, 116; 98, 117; 98, 118; 99, 119; 99, 120; 100, 121; 100, 122; 101, 123; 101, 124; 102, 125; 102, 126; 103, 127; 103, 128; 104, 129; 104, 130; 105, 131; 105, 132; 106, 133; 106, 134; 107, 135; 107, 136; 108, 137; 108, 138; 109, 139; 109, 140; 110, 141; 111, 142; 111, 143; 112, 144; 112, 145; 114, 146; 114, 147; 114, 148; 119, 149; 121, 150; 123, 151; 125, 152; 127, 153; 129, 154; 131, 155; 133, 156; 135, 157; 135, 158; 137, 159; 137, 160; 139, 161; 139, 162; 140, 163; 141, 164; 141, 165; 142, 166; 142, 167; 144, 168; 144, 169; 147, 170; 147, 171; 148, 172; 148, 173; 158, 174; 160, 175; 162, 176; 164, 177; 164, 178; 165, 179; 167, 180; 169, 181; 178, 182
def usearch61_smallmem_cluster(intermediate_fasta, percent_id=0.97, minlen=64, rev=False, output_dir=".", remove_usearch_logs=False, wordlength=8, usearch61_maxrejects=32, usearch61_maxaccepts=1, sizeorder=False, HALT_EXEC=False, output_uc_filepath=None, log_name="smallmem_clustered.log", sizeout=False, consout_filepath=None): """ Performs usearch61 de novo clustering via cluster_smallmem option Only supposed to be used with length sorted data (and performs length sorting automatically) and does not support reverse strand matching intermediate_fasta: fasta filepath to be clustered with usearch61 percent_id: percentage id to cluster at minlen: minimum sequence length rev: will enable reverse strand matching if True output_dir: directory to output log, OTU mapping, and intermediate files remove_usearch_logs: Saves usearch log files wordlength: word length to use for initial high probability sequence matches usearch61_maxrejects: Set to 'default' or an int value specifying max rejects usearch61_maxaccepts: Number of accepts allowed by usearch61 HALT_EXEC: application controller option to halt execution output_uc_filepath: Path to write clusters (.uc) file. log_name: filepath to write usearch61 generated log file sizeout: If True, will save abundance data in output fasta labels. consout_filepath: Needs to be set to save clustered consensus fasta filepath used for chimera checking. """ log_filepath = join(output_dir, log_name) params = {'--minseqlength': minlen, '--cluster_smallmem': intermediate_fasta, '--id': percent_id, '--uc': output_uc_filepath, '--wordlength': wordlength, '--maxrejects': usearch61_maxrejects, '--maxaccepts': usearch61_maxaccepts, '--usersort': True } if sizeorder: params['--sizeorder'] = True if not remove_usearch_logs: params['--log'] = log_filepath if rev: params['--strand'] = 'both' else: params['--strand'] = 'plus' if sizeout: params['--sizeout'] = True if consout_filepath: params['--consout'] = consout_filepath clusters_fp = output_uc_filepath app = Usearch61(params, WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) app_result = app() return clusters_fp, app_result
0, module; 1, function_definition; 2, function_name:normalize; 3, parameters; 4, block; 5, identifier:self; 6, dictionary_splat_pattern; 7, expression_statement; 8, comment:# FIXME: should it be performed in place? if it should; 9, comment:# be, the should there be no return value?; 10, for_statement; 11, return_statement; 12, identifier:kwargs; 13, comment:""" Adjust the offsetvector so that a particular instrument has the desired offset. All other instruments have their offsets adjusted so that the relative offsets are preserved. The instrument to noramlize, and the offset one wishes it to have, are provided as a key-word argument. The return value is the time slide dictionary, which is modified in place. If more than one key-word argument is provided the keys are sorted and considered in order until a key is found that is in the offset vector. The offset vector is normalized to that value. This function is a no-op if no key-word argument is found that applies. Example: >>> a = offsetvector({"H1": -10, "H2": -10, "L1": -10}) >>> a.normalize(L1 = 0) offsetvector({'H2': 0, 'H1': 0, 'L1': 0}) >>> a = offsetvector({"H1": -10, "H2": -10}) >>> a.normalize(L1 = 0, H2 = 5) offsetvector({'H2': 5, 'H1': 5}) """; 14, pattern_list; 15, call; 16, block; 17, identifier:self; 18, identifier:key; 19, identifier:offset; 20, identifier:sorted; 21, argument_list; 22, if_statement; 23, call; 24, comparison_operator:key in self; 25, block; 26, attribute; 27, argument_list; 28, identifier:key; 29, identifier:self; 30, expression_statement; 31, for_statement; 32, break_statement; 33, identifier:kwargs; 34, identifier:items; 35, assignment; 36, identifier:key; 37, call; 38, block; 39, identifier:delta; 40, binary_operator:offset - self[key]; 41, attribute; 42, argument_list; 43, expression_statement; 44, identifier:offset; 45, subscript; 46, identifier:self; 47, identifier:keys; 48, augmented_assignment; 49, identifier:self; 50, identifier:key; 51, subscript; 52, identifier:delta; 53, identifier:self; 54, identifier:key
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; 10, 14; 10, 15; 10, 16; 11, 17; 14, 18; 14, 19; 15, 20; 15, 21; 16, 22; 21, 23; 22, 24; 22, 25; 23, 26; 23, 27; 24, 28; 24, 29; 25, 30; 25, 31; 25, 32; 26, 33; 26, 34; 30, 35; 31, 36; 31, 37; 31, 38; 35, 39; 35, 40; 37, 41; 37, 42; 38, 43; 40, 44; 40, 45; 41, 46; 41, 47; 43, 48; 45, 49; 45, 50; 48, 51; 48, 52; 51, 53; 51, 54
def normalize(self, **kwargs): """ Adjust the offsetvector so that a particular instrument has the desired offset. All other instruments have their offsets adjusted so that the relative offsets are preserved. The instrument to noramlize, and the offset one wishes it to have, are provided as a key-word argument. The return value is the time slide dictionary, which is modified in place. If more than one key-word argument is provided the keys are sorted and considered in order until a key is found that is in the offset vector. The offset vector is normalized to that value. This function is a no-op if no key-word argument is found that applies. Example: >>> a = offsetvector({"H1": -10, "H2": -10, "L1": -10}) >>> a.normalize(L1 = 0) offsetvector({'H2': 0, 'H1': 0, 'L1': 0}) >>> a = offsetvector({"H1": -10, "H2": -10}) >>> a.normalize(L1 = 0, H2 = 5) offsetvector({'H2': 5, 'H1': 5}) """ # FIXME: should it be performed in place? if it should # be, the should there be no return value? for key, offset in sorted(kwargs.items()): if key in self: delta = offset - self[key] for key in self.keys(): self[key] += delta break return self
0, module; 1, function_definition; 2, function_name:_modifyInternal; 3, parameters; 4, block; 5, identifier:self; 6, keyword_separator; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, function_definition; 14, function_definition; 15, return_statement; 16, identifier:sort; 17, None; 18, identifier:purge; 19, False; 20, identifier:done; 21, None; 22, comment:"""Creates a whole new database from existing one, based on given modifiers. :sort: pattern should look like this: ([(<index>, True|False)], {<level_index>: [(<index>, True|False)]}), where True|False indicate whether to reverse or not, <index> are one of Model.indexes and <level_index> indicate a number of level to sort. Of course, the lists above may contain multiple items. :done: patterns looks similar to :sort:, except that it has additional <regexp> values and that True|False means to mark as done|undone. @note: Should not be used directly. It was defined here, because :save: decorator needs undecorated version of Model.modify. :sort: Pattern on which to sort the database. :purge: Whether to purge done items. :done: Pattern on which to mark items as done/undone. :returns: New database, modified according to supplied arguments. """; 23, assignment; 24, assignment; 25, function_name:_mark; 26, parameters; 27, block; 28, function_name:_modify; 29, parameters; 30, block; 31, call; 32, pattern_list; 33, boolean_operator; 34, pattern_list; 35, boolean_operator; 36, identifier:v; 37, identifier:i; 38, if_statement; 39, function_definition; 40, try_statement; 41, for_statement; 42, if_statement; 43, return_statement; 44, identifier:submodel; 45, identifier:i; 46, expression_statement; 47, for_statement; 48, expression_statement; 49, for_statement; 50, return_statement; 51, identifier:_modify; 52, argument_list; 53, identifier:sortAll; 54, identifier:sortLevels; 55, boolean_operator; 56, tuple; 57, identifier:doneAll; 58, identifier:doneLevels; 59, boolean_operator; 60, tuple; 61, comparison_operator:done is None; 62, block; 63, function_name:_mark_; 64, parameters; 65, block; 66, block; 67, except_clause; 68, identifier:doneAll_; 69, identifier:doneAll; 70, block; 71, comparison_operator:result is None; 72, block; 73, identifier:result; 74, assignment; 75, identifier:v; 76, identifier:submodel; 77, block; 78, assignment; 79, pattern_list; 80, boolean_operator; 81, block; 82, identifier:_new; 83, attribute; 84, integer:1; 85, comparison_operator:sort is not None; 86, identifier:sort; 87, list; 88, dictionary; 89, comparison_operator:done is not None; 90, identifier:done; 91, list; 92, dictionary; 93, identifier:done; 94, None; 95, return_statement; 96, identifier:index; 97, identifier:regexp; 98, identifier:du; 99, if_statement; 100, if_statement; 101, if_statement; 102, for_statement; 103, if_statement; 104, identifier:KeyError; 105, block; 106, expression_statement; 107, identifier:result; 108, None; 109, return_statement; 110, identifier:_new; 111, call; 112, if_statement; 113, identifier:levels; 114, boolean_operator; 115, identifier:index; 116, identifier:reverse; 117, identifier:levels; 118, identifier:sortAll; 119, expression_statement; 120, identifier:self; 121, identifier:data; 122, identifier:sort; 123, None; 124, identifier:done; 125, None; 126, subscript; 127, comparison_operator:du is None; 128, block; 129, comparison_operator:index is None; 130, block; 131, boolean_operator; 132, block; 133, identifier:doneLevel; 134, subscript; 135, block; 136, comparison_operator:result is not None; 137, block; 138, pass_statement; 139, assignment; 140, subscript; 141, identifier:list; 142, argument_list; 143, identifier:purge; 144, block; 145, else_clause; 146, call; 147, call; 148, assignment; 149, identifier:v; 150, slice; 151, identifier:du; 152, None; 153, return_statement; 154, identifier:index; 155, None; 156, for_statement; 157, return_statement; 158, comparison_operator:regexp is None; 159, call; 160, return_statement; 161, identifier:doneLevels; 162, identifier:i; 163, expression_statement; 164, identifier:result; 165, None; 166, return_statement; 167, identifier:result; 168, call; 169, identifier:v; 170, slice; 171, if_statement; 172, block; 173, attribute; 174, argument_list; 175, attribute; 176, argument_list; 177, identifier:_new; 178, call; 179, integer:4; 180, subscript; 181, identifier:v_; 182, subscript; 183, block; 184, subscript; 185, identifier:regexp; 186, None; 187, attribute; 188, argument_list; 189, binary_operator:v[:3] + [du]; 190, assignment; 191, identifier:result; 192, identifier:_mark_; 193, argument_list; 194, integer:4; 195, not_operator; 196, block; 197, expression_statement; 198, identifier:sortLevels; 199, identifier:get; 200, identifier:i; 201, identifier:sortLevels; 202, identifier:get; 203, call; 204, identifier:sorted; 205, argument_list; 206, identifier:v; 207, slice; 208, identifier:v; 209, slice; 210, if_statement; 211, identifier:v; 212, slice; 213, identifier:re; 214, identifier:match; 215, identifier:regexp; 216, call; 217, subscript; 218, list; 219, identifier:result; 220, call; 221, list_splat; 222, subscript; 223, expression_statement; 224, call; 225, identifier:str; 226, argument_list; 227, identifier:_new; 228, keyword_argument; 229, keyword_argument; 230, integer:4; 231, integer:3; 232, boolean_operator; 233, block; 234, integer:4; 235, identifier:str; 236, argument_list; 237, identifier:v; 238, slice; 239, identifier:du; 240, identifier:_mark_; 241, argument_list; 242, identifier:doneAll_; 243, identifier:v; 244, integer:3; 245, call; 246, attribute; 247, argument_list; 248, identifier:i; 249, identifier:key; 250, lambda; 251, identifier:reverse; 252, identifier:reverse; 253, comparison_operator:regexp is None; 254, call; 255, return_statement; 256, subscript; 257, integer:3; 258, list_splat; 259, attribute; 260, argument_list; 261, identifier:_new; 262, identifier:append; 263, binary_operator:_mark(v, i) + [_modify(v[4], i + 1)]; 264, lambda_parameters; 265, subscript; 266, identifier:regexp; 267, None; 268, attribute; 269, argument_list; 270, binary_operator:v[:3] + [du]; 271, identifier:v; 272, identifier:index; 273, identifier:doneLevel; 274, identifier:_new; 275, identifier:append; 276, binary_operator:_mark(v, i) + [_modify(v[4], i + 1)]; 277, call; 278, list; 279, identifier:e; 280, identifier:e; 281, identifier:index; 282, identifier:re; 283, identifier:match; 284, identifier:regexp; 285, call; 286, subscript; 287, list; 288, call; 289, list; 290, identifier:_mark; 291, argument_list; 292, call; 293, identifier:str; 294, argument_list; 295, identifier:v; 296, slice; 297, identifier:du; 298, identifier:_mark; 299, argument_list; 300, call; 301, identifier:v; 302, identifier:i; 303, identifier:_modify; 304, argument_list; 305, identifier:v_; 306, integer:3; 307, identifier:v; 308, identifier:i; 309, identifier:_modify; 310, argument_list; 311, subscript; 312, binary_operator:i + 1; 313, subscript; 314, binary_operator:i + 1; 315, identifier:v; 316, integer:4; 317, identifier:i; 318, integer:1; 319, identifier:v; 320, integer:4; 321, identifier:i; 322, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 7, 17; 8, 18; 8, 19; 9, 20; 9, 21; 10, 22; 11, 23; 12, 24; 13, 25; 13, 26; 13, 27; 14, 28; 14, 29; 14, 30; 15, 31; 23, 32; 23, 33; 24, 34; 24, 35; 26, 36; 26, 37; 27, 38; 27, 39; 27, 40; 27, 41; 27, 42; 27, 43; 29, 44; 29, 45; 30, 46; 30, 47; 30, 48; 30, 49; 30, 50; 31, 51; 31, 52; 32, 53; 32, 54; 33, 55; 33, 56; 34, 57; 34, 58; 35, 59; 35, 60; 38, 61; 38, 62; 39, 63; 39, 64; 39, 65; 40, 66; 40, 67; 41, 68; 41, 69; 41, 70; 42, 71; 42, 72; 43, 73; 46, 74; 47, 75; 47, 76; 47, 77; 48, 78; 49, 79; 49, 80; 49, 81; 50, 82; 52, 83; 52, 84; 55, 85; 55, 86; 56, 87; 56, 88; 59, 89; 59, 90; 60, 91; 60, 92; 61, 93; 61, 94; 62, 95; 64, 96; 64, 97; 64, 98; 65, 99; 65, 100; 65, 101; 66, 102; 66, 103; 67, 104; 67, 105; 70, 106; 71, 107; 71, 108; 72, 109; 74, 110; 74, 111; 77, 112; 78, 113; 78, 114; 79, 115; 79, 116; 80, 117; 80, 118; 81, 119; 83, 120; 83, 121; 85, 122; 85, 123; 89, 124; 89, 125; 95, 126; 99, 127; 99, 128; 100, 129; 100, 130; 101, 131; 101, 132; 102, 133; 102, 134; 102, 135; 103, 136; 103, 137; 105, 138; 106, 139; 109, 140; 111, 141; 111, 142; 112, 143; 112, 144; 112, 145; 114, 146; 114, 147; 119, 148; 126, 149; 126, 150; 127, 151; 127, 152; 128, 153; 129, 154; 129, 155; 130, 156; 130, 157; 131, 158; 131, 159; 132, 160; 134, 161; 134, 162; 135, 163; 136, 164; 136, 165; 137, 166; 139, 167; 139, 168; 140, 169; 140, 170; 144, 171; 145, 172; 146, 173; 146, 174; 147, 175; 147, 176; 148, 177; 148, 178; 150, 179; 153, 180; 156, 181; 156, 182; 156, 183; 157, 184; 158, 185; 158, 186; 159, 187; 159, 188; 160, 189; 163, 190; 166, 191; 168, 192; 168, 193; 170, 194; 171, 195; 171, 196; 172, 197; 173, 198; 173, 199; 174, 200; 175, 201; 175, 202; 176, 203; 178, 204; 178, 205; 180, 206; 180, 207; 182, 208; 182, 209; 183, 210; 184, 211; 184, 212; 187, 213; 187, 214; 188, 215; 188, 216; 189, 217; 189, 218; 190, 219; 190, 220; 193, 221; 195, 222; 196, 223; 197, 224; 203, 225; 203, 226; 205, 227; 205, 228; 205, 229; 207, 230; 209, 231; 210, 232; 210, 233; 212, 234; 216, 235; 216, 236; 217, 237; 217, 238; 218, 239; 220, 240; 220, 241; 221, 242; 222, 243; 222, 244; 223, 245; 224, 246; 224, 247; 226, 248; 228, 249; 228, 250; 229, 251; 229, 252; 232, 253; 232, 254; 233, 255; 236, 256; 238, 257; 241, 258; 245, 259; 245, 260; 246, 261; 246, 262; 247, 263; 250, 264; 250, 265; 253, 266; 253, 267; 254, 268; 254, 269; 255, 270; 256, 271; 256, 272; 258, 273; 259, 274; 259, 275; 260, 276; 263, 277; 263, 278; 264, 279; 265, 280; 265, 281; 268, 282; 268, 283; 269, 284; 269, 285; 270, 286; 270, 287; 276, 288; 276, 289; 277, 290; 277, 291; 278, 292; 285, 293; 285, 294; 286, 295; 286, 296; 287, 297; 288, 298; 288, 299; 289, 300; 291, 301; 291, 302; 292, 303; 292, 304; 294, 305; 296, 306; 299, 307; 299, 308; 300, 309; 300, 310; 304, 311; 304, 312; 310, 313; 310, 314; 311, 315; 311, 316; 312, 317; 312, 318; 313, 319; 313, 320; 314, 321; 314, 322
def _modifyInternal(self, *, sort=None, purge=False, done=None): """Creates a whole new database from existing one, based on given modifiers. :sort: pattern should look like this: ([(<index>, True|False)], {<level_index>: [(<index>, True|False)]}), where True|False indicate whether to reverse or not, <index> are one of Model.indexes and <level_index> indicate a number of level to sort. Of course, the lists above may contain multiple items. :done: patterns looks similar to :sort:, except that it has additional <regexp> values and that True|False means to mark as done|undone. @note: Should not be used directly. It was defined here, because :save: decorator needs undecorated version of Model.modify. :sort: Pattern on which to sort the database. :purge: Whether to purge done items. :done: Pattern on which to mark items as done/undone. :returns: New database, modified according to supplied arguments. """ sortAll, sortLevels = sort is not None and sort or ([], {}) doneAll, doneLevels = done is not None and done or ([], {}) def _mark(v, i): if done is None: return v[:4] def _mark_(index, regexp, du): if du is None: return v[:4] if index is None: for v_ in v[:3]: if regexp is None or re.match(regexp, str(v_)): return v[:3] + [du] return v[:4] if regexp is None or re.match(regexp, str(v[index])): return v[:3] + [du] try: for doneLevel in doneLevels[i]: result = _mark_(*doneLevel) if result is not None: return result except KeyError: pass for doneAll_ in doneAll: result = _mark_(*doneAll_) if result is None: return v[:4] return result def _modify(submodel, i): _new = list() for v in submodel: if purge: if not v[3]: _new.append(_mark(v, i) + [_modify(v[4], i + 1)]) else: _new.append(_mark(v, i) + [_modify(v[4], i + 1)]) levels = sortLevels.get(i) or sortLevels.get(str(i)) for index, reverse in levels or sortAll: _new = sorted(_new, key=lambda e: e[index], reverse=reverse) return _new return _modify(self.data, 1)
0, module; 1, function_definition; 2, function_name:_getPattern; 3, parameters; 4, block; 5, identifier:self; 6, identifier:ipattern; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, if_statement; 11, function_definition; 12, function_definition; 13, function_definition; 14, expression_statement; 15, expression_statement; 16, for_statement; 17, return_statement; 18, identifier:done; 19, None; 20, comment:"""Parses sort pattern. :ipattern: A pattern to parse. :done: If :ipattern: refers to done|undone, use this to indicate proper state. :returns: A pattern suitable for Model.modify. """; 21, comparison_operator:ipattern is None; 22, block; 23, comparison_operator:ipattern is True; 24, block; 25, function_name:_getReverse; 26, parameters; 27, block; 28, function_name:_getIndex; 29, parameters; 30, block; 31, function_name:_getDone; 32, parameters; 33, block; 34, assignment; 35, assignment; 36, identifier:s; 37, call; 38, block; 39, tuple; 40, identifier:ipattern; 41, None; 42, return_statement; 43, identifier:ipattern; 44, True; 45, if_statement; 46, comment:# REMEMBER: This False is for sort reverse!; 47, return_statement; 48, identifier:pm; 49, return_statement; 50, identifier:k; 51, try_statement; 52, identifier:p; 53, expression_statement; 54, if_statement; 55, return_statement; 56, identifier:ipattern1; 57, call; 58, identifier:ipattern2; 59, call; 60, attribute; 61, argument_list; 62, if_statement; 63, expression_statement; 64, if_statement; 65, expression_statement; 66, identifier:ipattern1; 67, identifier:ipattern2; 68, None; 69, comparison_operator:done is not None; 70, block; 71, tuple; 72, comparison_operator:pm == '-'; 73, block; 74, except_clause; 75, assignment; 76, comparison_operator:len(v) == 2; 77, block; 78, tuple; 79, identifier:list; 80, argument_list; 81, identifier:dict; 82, argument_list; 83, identifier:ipattern; 84, identifier:split; 85, string; 86, comparison_operator:done is not None; 87, block; 88, else_clause; 89, assignment; 90, comparison_operator:len(k) == 1; 91, block; 92, elif_clause; 93, else_clause; 94, call; 95, identifier:done; 96, None; 97, return_statement; 98, list; 99, dictionary; 100, identifier:pm; 101, string; 102, return_statement; 103, identifier:ValueError; 104, block; 105, identifier:v; 106, call; 107, call; 108, integer:2; 109, try_statement; 110, None; 111, subscript; 112, identifier:done; 113, string_content:,; 114, identifier:done; 115, None; 116, expression_statement; 117, block; 118, identifier:k; 119, call; 120, call; 121, integer:1; 122, if_statement; 123, expression_statement; 124, try_statement; 125, expression_statement; 126, comparison_operator:len(k) == 2; 127, block; 128, block; 129, attribute; 130, argument_list; 131, tuple; 132, tuple; 133, string_content:-; 134, call; 135, raise_statement; 136, attribute; 137, argument_list; 138, identifier:len; 139, argument_list; 140, block; 141, except_clause; 142, identifier:v; 143, integer:0; 144, assignment; 145, expression_statement; 146, attribute; 147, argument_list; 148, identifier:len; 149, argument_list; 150, comparison_operator:done is not None; 151, block; 152, assignment; 153, block; 154, except_clause; 155, else_clause; 156, assignment; 157, call; 158, integer:2; 159, try_statement; 160, raise_statement; 161, call; 162, identifier:append; 163, identifier:v; 164, list; 165, dictionary; 166, integer:0; 167, False; 168, identifier:int; 169, argument_list; 170, call; 171, identifier:p; 172, identifier:split; 173, string; 174, identifier:v; 175, return_statement; 176, identifier:KeyError; 177, block; 178, identifier:v; 179, identifier:done; 180, assignment; 181, identifier:s; 182, identifier:split; 183, string; 184, identifier:k; 185, identifier:done; 186, None; 187, expression_statement; 188, continue_statement; 189, identifier:ko; 190, subscript; 191, if_statement; 192, identifier:KeyError; 193, block; 194, block; 195, identifier:v; 196, tuple; 197, identifier:len; 198, argument_list; 199, block; 200, except_clause; 201, call; 202, attribute; 203, argument_list; 204, tuple; 205, identifier:k; 206, identifier:InvalidPatternError; 207, argument_list; 208, string_content:=; 209, tuple; 210, raise_statement; 211, identifier:v; 212, call; 213, string_content::; 214, call; 215, subscript; 216, slice; 217, comparison_operator:len(k[0]) == 1; 218, block; 219, else_clause; 220, expression_statement; 221, expression_statement; 222, continue_statement; 223, integer:0; 224, identifier:v; 225, identifier:k; 226, if_statement; 227, expression_statement; 228, identifier:KeyError; 229, block; 230, identifier:InvalidPatternError; 231, argument_list; 232, identifier:ipattern2; 233, identifier:setdefault; 234, identifier:k; 235, list; 236, None; 237, None; 238, identifier:done; 239, identifier:k; 240, string:"Invalid level number"; 241, subscript; 242, subscript; 243, identifier:done; 244, call; 245, identifier:_getReverse; 246, argument_list; 247, attribute; 248, argument_list; 249, identifier:k; 250, integer:0; 251, unary_operator; 252, call; 253, integer:1; 254, expression_statement; 255, block; 256, assignment; 257, call; 258, comparison_operator:done is not None; 259, block; 260, else_clause; 261, assignment; 262, raise_statement; 263, identifier:s; 264, string; 265, attribute; 266, subscript; 267, identifier:v; 268, integer:1; 269, identifier:InvalidPatternError; 270, argument_list; 271, subscript; 272, identifier:ipattern1; 273, identifier:append; 274, call; 275, integer:1; 276, identifier:len; 277, argument_list; 278, assignment; 279, expression_statement; 280, identifier:k; 281, call; 282, attribute; 283, argument_list; 284, identifier:done; 285, None; 286, expression_statement; 287, block; 288, identifier:k; 289, call; 290, call; 291, string_content:Unrecognized token in; 292, identifier:Model; 293, identifier:indexes; 294, identifier:v; 295, integer:0; 296, subscript; 297, string; 298, identifier:s; 299, unary_operator; 300, identifier:_getDone; 301, argument_list; 302, subscript; 303, identifier:k; 304, integer:0; 305, assignment; 306, identifier:_getIndex; 307, argument_list; 308, identifier:ipattern1; 309, identifier:append; 310, tuple; 311, assignment; 312, expression_statement; 313, identifier:_getIndex; 314, argument_list; 315, identifier:InvalidPatternError; 316, argument_list; 317, identifier:v; 318, integer:0; 319, string_content:Invalid field name; 320, integer:1; 321, subscript; 322, identifier:k; 323, integer:0; 324, identifier:k; 325, subscript; 326, subscript; 327, identifier:k; 328, identifier:v; 329, identifier:v; 330, call; 331, assignment; 332, subscript; 333, subscript; 334, string; 335, identifier:k; 336, integer:0; 337, attribute; 338, identifier:ko; 339, subscript; 340, slice; 341, identifier:_getDone; 342, argument_list; 343, identifier:v; 344, tuple; 345, identifier:k; 346, integer:0; 347, subscript; 348, slice; 349, string_content:Invalid field name; 350, identifier:Model; 351, identifier:indexes; 352, identifier:k; 353, integer:0; 354, unary_operator; 355, subscript; 356, subscript; 357, identifier:v; 358, identifier:k; 359, integer:1; 360, unary_operator; 361, integer:1; 362, identifier:k; 363, integer:1; 364, attribute; 365, subscript; 366, integer:1; 367, identifier:Model; 368, identifier:indexes; 369, subscript; 370, slice; 371, identifier:k; 372, integer:1; 373, unary_operator; 374, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 7, 18; 7, 19; 8, 20; 9, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 11, 27; 12, 28; 12, 29; 12, 30; 13, 31; 13, 32; 13, 33; 14, 34; 15, 35; 16, 36; 16, 37; 16, 38; 17, 39; 21, 40; 21, 41; 22, 42; 23, 43; 23, 44; 24, 45; 24, 46; 24, 47; 26, 48; 27, 49; 29, 50; 30, 51; 32, 52; 33, 53; 33, 54; 33, 55; 34, 56; 34, 57; 35, 58; 35, 59; 37, 60; 37, 61; 38, 62; 38, 63; 38, 64; 38, 65; 39, 66; 39, 67; 42, 68; 45, 69; 45, 70; 47, 71; 49, 72; 51, 73; 51, 74; 53, 75; 54, 76; 54, 77; 55, 78; 57, 79; 57, 80; 59, 81; 59, 82; 60, 83; 60, 84; 61, 85; 62, 86; 62, 87; 62, 88; 63, 89; 64, 90; 64, 91; 64, 92; 64, 93; 65, 94; 69, 95; 69, 96; 70, 97; 71, 98; 71, 99; 72, 100; 72, 101; 73, 102; 74, 103; 74, 104; 75, 105; 75, 106; 76, 107; 76, 108; 77, 109; 78, 110; 78, 111; 78, 112; 85, 113; 86, 114; 86, 115; 87, 116; 88, 117; 89, 118; 89, 119; 90, 120; 90, 121; 91, 122; 91, 123; 91, 124; 91, 125; 92, 126; 92, 127; 93, 128; 94, 129; 94, 130; 97, 131; 98, 132; 101, 133; 102, 134; 104, 135; 106, 136; 106, 137; 107, 138; 107, 139; 109, 140; 109, 141; 111, 142; 111, 143; 116, 144; 117, 145; 119, 146; 119, 147; 120, 148; 120, 149; 122, 150; 122, 151; 123, 152; 124, 153; 124, 154; 124, 155; 125, 156; 126, 157; 126, 158; 127, 159; 128, 160; 129, 161; 129, 162; 130, 163; 131, 164; 131, 165; 132, 166; 132, 167; 134, 168; 134, 169; 135, 170; 136, 171; 136, 172; 137, 173; 139, 174; 140, 175; 141, 176; 141, 177; 144, 178; 144, 179; 145, 180; 146, 181; 146, 182; 147, 183; 149, 184; 150, 185; 150, 186; 151, 187; 151, 188; 152, 189; 152, 190; 153, 191; 154, 192; 154, 193; 155, 194; 156, 195; 156, 196; 157, 197; 157, 198; 159, 199; 159, 200; 160, 201; 161, 202; 161, 203; 164, 204; 169, 205; 170, 206; 170, 207; 173, 208; 175, 209; 177, 210; 180, 211; 180, 212; 183, 213; 187, 214; 190, 215; 190, 216; 191, 217; 191, 218; 191, 219; 193, 220; 194, 221; 194, 222; 196, 223; 196, 224; 198, 225; 199, 226; 199, 227; 200, 228; 200, 229; 201, 230; 201, 231; 202, 232; 202, 233; 203, 234; 203, 235; 204, 236; 204, 237; 204, 238; 207, 239; 207, 240; 209, 241; 209, 242; 209, 243; 210, 244; 212, 245; 212, 246; 214, 247; 214, 248; 215, 249; 215, 250; 216, 251; 217, 252; 217, 253; 218, 254; 219, 255; 220, 256; 221, 257; 226, 258; 226, 259; 226, 260; 227, 261; 229, 262; 231, 263; 231, 264; 241, 265; 241, 266; 242, 267; 242, 268; 244, 269; 244, 270; 246, 271; 247, 272; 247, 273; 248, 274; 251, 275; 252, 276; 252, 277; 254, 278; 255, 279; 256, 280; 256, 281; 257, 282; 257, 283; 258, 284; 258, 285; 259, 286; 260, 287; 261, 288; 261, 289; 262, 290; 264, 291; 265, 292; 265, 293; 266, 294; 266, 295; 270, 296; 270, 297; 271, 298; 271, 299; 274, 300; 274, 301; 277, 302; 278, 303; 278, 304; 279, 305; 281, 306; 281, 307; 282, 308; 282, 309; 283, 310; 286, 311; 287, 312; 289, 313; 289, 314; 290, 315; 290, 316; 296, 317; 296, 318; 297, 319; 299, 320; 301, 321; 302, 322; 302, 323; 305, 324; 305, 325; 307, 326; 310, 327; 310, 328; 311, 329; 311, 330; 312, 331; 314, 332; 316, 333; 316, 334; 321, 335; 321, 336; 325, 337; 325, 338; 326, 339; 326, 340; 330, 341; 330, 342; 331, 343; 331, 344; 332, 345; 332, 346; 333, 347; 333, 348; 334, 349; 337, 350; 337, 351; 339, 352; 339, 353; 340, 354; 342, 355; 344, 356; 344, 357; 347, 358; 347, 359; 348, 360; 354, 361; 355, 362; 355, 363; 356, 364; 356, 365; 360, 366; 364, 367; 364, 368; 365, 369; 365, 370; 369, 371; 369, 372; 370, 373; 373, 374
def _getPattern(self, ipattern, done=None): """Parses sort pattern. :ipattern: A pattern to parse. :done: If :ipattern: refers to done|undone, use this to indicate proper state. :returns: A pattern suitable for Model.modify. """ if ipattern is None: return None if ipattern is True: if done is not None: return ([(None, None, done)], {}) # REMEMBER: This False is for sort reverse! return ([(0, False)], {}) def _getReverse(pm): return pm == '-' def _getIndex(k): try: return int(k) except ValueError: raise InvalidPatternError(k, "Invalid level number") def _getDone(p): v = p.split('=') if len(v) == 2: try: return (Model.indexes[v[0]], v[1], done) except KeyError: raise InvalidPatternError(v[0], 'Invalid field name') return (None, v[0], done) ipattern1 = list() ipattern2 = dict() for s in ipattern.split(','): if done is not None: v = done else: v = _getReverse(s[-1]) k = s.split(':') if len(k) == 1: if done is not None: ipattern1.append(_getDone(k[0])) continue ko = k[0][:-1] try: if len(k[0]) == 1: k = 0 else: k = Model.indexes[ko] except KeyError: k = _getIndex(k[0][:-1]) else: ipattern1.append((k, v)) continue v = (0, v) elif len(k) == 2: try: if done is not None: v = _getDone(k[1]) else: v = (Model.indexes[k[1][:-1]], v) k = _getIndex(k[0]) except KeyError: raise InvalidPatternError(k[1][:-1], 'Invalid field name') else: raise InvalidPatternError(s, 'Unrecognized token in') ipattern2.setdefault(k, []).append(v) return (ipattern1, ipattern2)
0, module; 1, function_definition; 2, function_name:view; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, dictionary_splat_pattern; 11, expression_statement; 12, expression_statement; 13, identifier:sort; 14, None; 15, identifier:purge; 16, False; 17, identifier:done; 18, None; 19, identifier:undone; 20, None; 21, identifier:kwargs; 22, comment:"""Handles the 'v' command. :sort: Sort pattern. :purge: Whether to purge items marked as 'done'. :done: Done pattern. :undone: Not done pattern. :kwargs: Additional arguments to pass to the View object. """; 23, call; 24, identifier:View; 25, argument_list; 26, call; 27, dictionary_splat; 28, attribute; 29, argument_list; 30, identifier:kwargs; 31, attribute; 32, identifier:modify; 33, keyword_argument; 34, keyword_argument; 35, keyword_argument; 36, identifier:self; 37, identifier:model; 38, identifier:sort; 39, call; 40, identifier:purge; 41, identifier:purge; 42, identifier:done; 43, call; 44, attribute; 45, argument_list; 46, attribute; 47, argument_list; 48, identifier:self; 49, identifier:_getPattern; 50, identifier:sort; 51, identifier:self; 52, identifier:_getDone; 53, identifier:done; 54, identifier:undone
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 9, 20; 10, 21; 11, 22; 12, 23; 23, 24; 23, 25; 25, 26; 25, 27; 26, 28; 26, 29; 27, 30; 28, 31; 28, 32; 29, 33; 29, 34; 29, 35; 31, 36; 31, 37; 33, 38; 33, 39; 34, 40; 34, 41; 35, 42; 35, 43; 39, 44; 39, 45; 43, 46; 43, 47; 44, 48; 44, 49; 45, 50; 46, 51; 46, 52; 47, 53; 47, 54
def view(self, sort=None, purge=False, done=None, undone=None, **kwargs): """Handles the 'v' command. :sort: Sort pattern. :purge: Whether to purge items marked as 'done'. :done: Done pattern. :undone: Not done pattern. :kwargs: Additional arguments to pass to the View object. """ View(self.model.modify( sort=self._getPattern(sort), purge=purge, done=self._getDone(done, undone) ), **kwargs)
0, module; 1, function_definition; 2, function_name:modify; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, identifier:sort; 13, None; 14, identifier:purge; 15, False; 16, identifier:done; 17, None; 18, identifier:undone; 19, None; 20, comment:"""Handles the 'm' command. :sort: Sort pattern. :purge: Whether to purge items marked as 'done'. :done: Done pattern. :undone: Not done pattern. """; 21, call; 22, attribute; 23, argument_list; 24, attribute; 25, identifier:modifyInPlace; 26, keyword_argument; 27, keyword_argument; 28, keyword_argument; 29, identifier:self; 30, identifier:model; 31, identifier:sort; 32, call; 33, identifier:purge; 34, identifier:purge; 35, identifier:done; 36, call; 37, attribute; 38, argument_list; 39, attribute; 40, argument_list; 41, identifier:self; 42, identifier:_getPattern; 43, identifier:sort; 44, identifier:self; 45, identifier:_getDone; 46, identifier:done; 47, identifier:undone
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; 9, 19; 10, 20; 11, 21; 21, 22; 21, 23; 22, 24; 22, 25; 23, 26; 23, 27; 23, 28; 24, 29; 24, 30; 26, 31; 26, 32; 27, 33; 27, 34; 28, 35; 28, 36; 32, 37; 32, 38; 36, 39; 36, 40; 37, 41; 37, 42; 38, 43; 39, 44; 39, 45; 40, 46; 40, 47
def modify(self, sort=None, purge=False, done=None, undone=None): """Handles the 'm' command. :sort: Sort pattern. :purge: Whether to purge items marked as 'done'. :done: Done pattern. :undone: Not done pattern. """ self.model.modifyInPlace( sort=self._getPattern(sort), purge=purge, done=self._getDone(done, undone) )
0, module; 1, function_definition; 2, function_name:inorder; 3, parameters; 4, block; 5, list_splat_pattern; 6, dictionary_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:# default = identity; 11, if_statement; 12, expression_statement; 13, for_statement; 14, if_statement; 15, if_statement; 16, expression_statement; 17, if_statement; 18, comment:# exactly one sequence remains, short circuit and drain it; 19, expression_statement; 20, expression_statement; 21, while_statement; 22, identifier:iterables; 23, identifier:kwargs; 24, comment:""" A generator that yields the values from several ordered iterables in order. Example: >>> x = [0, 1, 2, 3] >>> y = [1.5, 2.5, 3.5, 4.5] >>> z = [1.75, 2.25, 3.75, 4.25] >>> list(inorder(x, y, z)) [0, 1, 1.5, 1.75, 2, 2.25, 2.5, 3, 3.5, 3.75, 4.25, 4.5] >>> list(inorder(x, y, z, key=lambda x: x * x)) [0, 1, 1.5, 1.75, 2, 2.25, 2.5, 3, 3.5, 3.75, 4.25, 4.5] >>> x.sort(key=lambda x: abs(x-3)) >>> y.sort(key=lambda x: abs(x-3)) >>> z.sort(key=lambda x: abs(x-3)) >>> list(inorder(x, y, z, key=lambda x: abs(x - 3))) [3, 2.5, 3.5, 2.25, 3.75, 2, 1.75, 4.25, 1.5, 4.5, 1, 0] >>> x = [3, 2, 1, 0] >>> y = [4.5, 3.5, 2.5, 1.5] >>> z = [4.25, 3.75, 2.25, 1.75] >>> list(inorder(x, y, z, reverse = True)) [4.5, 4.25, 3.75, 3.5, 3, 2.5, 2.25, 2, 1.75, 1.5, 1, 0] >>> list(inorder(x, y, z, key = lambda x: -x)) [4.5, 4.25, 3.75, 3.5, 3, 2.5, 2.25, 2, 1.75, 1.5, 1, 0] NOTE: this function will never reverse the order of elements in the input iterables. If the reverse keyword argument is False (the default) then the input sequences must yield elements in increasing order, likewise if the keyword argument is True then the input sequences must yield elements in decreasing order. Failure to adhere to this yields undefined results, and for performance reasons no check is performed to validate the element order in the input sequences. """; 25, assignment; 26, assignment; 27, identifier:kwargs; 28, block; 29, assignment; 30, identifier:iterable; 31, identifier:iterables; 32, block; 33, not_operator; 34, comment:# all sequences are empty; 35, block; 36, identifier:reverse; 37, block; 38, else_clause; 39, assignment; 40, comparison_operator:len(nextvals) > 1; 41, block; 42, assignment; 43, yield; 44, integer:1; 45, block; 46, identifier:reverse; 47, call; 48, identifier:keyfunc; 49, call; 50, raise_statement; 51, identifier:nextvals; 52, dictionary; 53, expression_statement; 54, try_statement; 55, identifier:nextvals; 56, return_statement; 57, expression_statement; 58, block; 59, identifier:values; 60, attribute; 61, call; 62, integer:1; 63, while_statement; 64, pattern_list; 65, call; 66, identifier:val; 67, expression_statement; 68, attribute; 69, argument_list; 70, attribute; 71, argument_list; 72, call; 73, assignment; 74, block; 75, except_clause; 76, assignment; 77, expression_statement; 78, identifier:nextvals; 79, identifier:itervalues; 80, identifier:len; 81, argument_list; 82, integer:1; 83, block; 84, tuple_pattern; 85, identifier:values; 86, argument_list; 87, yield; 88, identifier:kwargs; 89, identifier:pop; 90, string:"reverse"; 91, False; 92, identifier:kwargs; 93, identifier:pop; 94, string:"key"; 95, lambda; 96, identifier:TypeError; 97, argument_list; 98, identifier:next; 99, attribute; 100, expression_statement; 101, expression_statement; 102, identifier:StopIteration; 103, block; 104, identifier:select; 105, identifier:max; 106, assignment; 107, identifier:nextvals; 108, expression_statement; 109, expression_statement; 110, try_statement; 111, identifier:_; 112, identifier:val; 113, identifier:next; 114, call; 115, lambda_parameters; 116, identifier:x; 117, binary_operator:"invalid keyword argument '%s'" % kwargs.keys()[0]; 118, call; 119, identifier:next; 120, assignment; 121, assignment; 122, pass_statement; 123, identifier:select; 124, identifier:min; 125, assignment; 126, yield; 127, block; 128, except_clause; 129, identifier:next; 130, argument_list; 131, identifier:x; 132, string:"invalid keyword argument '%s'"; 133, subscript; 134, identifier:iter; 135, argument_list; 136, identifier:nextval; 137, call; 138, subscript; 139, expression_list; 140, pattern_list; 141, call; 142, identifier:val; 143, expression_statement; 144, expression_statement; 145, identifier:StopIteration; 146, block; 147, call; 148, integer:0; 149, identifier:iterable; 150, identifier:next; 151, argument_list; 152, identifier:nextvals; 153, identifier:next; 154, call; 155, identifier:nextval; 156, identifier:next; 157, identifier:_; 158, identifier:val; 159, identifier:next; 160, identifier:select; 161, argument_list; 162, assignment; 163, assignment; 164, delete_statement; 165, if_statement; 166, attribute; 167, argument_list; 168, identifier:keyfunc; 169, argument_list; 170, call; 171, identifier:nextval; 172, call; 173, subscript; 174, expression_list; 175, subscript; 176, comparison_operator:len(nextvals) < 2; 177, block; 178, identifier:kwargs; 179, identifier:keys; 180, identifier:nextval; 181, identifier:values; 182, argument_list; 183, identifier:next; 184, argument_list; 185, identifier:nextvals; 186, identifier:next; 187, call; 188, identifier:nextval; 189, identifier:next; 190, identifier:nextvals; 191, identifier:next; 192, call; 193, integer:2; 194, break_statement; 195, identifier:keyfunc; 196, argument_list; 197, identifier:len; 198, argument_list; 199, identifier:nextval; 200, identifier:nextvals
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 5, 22; 6, 23; 7, 24; 8, 25; 9, 26; 11, 27; 11, 28; 12, 29; 13, 30; 13, 31; 13, 32; 14, 33; 14, 34; 14, 35; 15, 36; 15, 37; 15, 38; 16, 39; 17, 40; 17, 41; 19, 42; 20, 43; 21, 44; 21, 45; 25, 46; 25, 47; 26, 48; 26, 49; 28, 50; 29, 51; 29, 52; 32, 53; 32, 54; 33, 55; 35, 56; 37, 57; 38, 58; 39, 59; 39, 60; 40, 61; 40, 62; 41, 63; 42, 64; 42, 65; 43, 66; 45, 67; 47, 68; 47, 69; 49, 70; 49, 71; 50, 72; 53, 73; 54, 74; 54, 75; 57, 76; 58, 77; 60, 78; 60, 79; 61, 80; 61, 81; 63, 82; 63, 83; 64, 84; 65, 85; 65, 86; 67, 87; 68, 88; 68, 89; 69, 90; 69, 91; 70, 92; 70, 93; 71, 94; 71, 95; 72, 96; 72, 97; 73, 98; 73, 99; 74, 100; 74, 101; 75, 102; 75, 103; 76, 104; 76, 105; 77, 106; 81, 107; 83, 108; 83, 109; 83, 110; 84, 111; 84, 112; 84, 113; 87, 114; 95, 115; 95, 116; 97, 117; 99, 118; 99, 119; 100, 120; 101, 121; 103, 122; 106, 123; 106, 124; 108, 125; 109, 126; 110, 127; 110, 128; 114, 129; 114, 130; 115, 131; 117, 132; 117, 133; 118, 134; 118, 135; 120, 136; 120, 137; 121, 138; 121, 139; 125, 140; 125, 141; 126, 142; 127, 143; 127, 144; 128, 145; 128, 146; 133, 147; 133, 148; 135, 149; 137, 150; 137, 151; 138, 152; 138, 153; 139, 154; 139, 155; 139, 156; 140, 157; 140, 158; 140, 159; 141, 160; 141, 161; 143, 162; 144, 163; 146, 164; 146, 165; 147, 166; 147, 167; 154, 168; 154, 169; 161, 170; 162, 171; 162, 172; 163, 173; 163, 174; 164, 175; 165, 176; 165, 177; 166, 178; 166, 179; 169, 180; 170, 181; 170, 182; 172, 183; 172, 184; 173, 185; 173, 186; 174, 187; 174, 188; 174, 189; 175, 190; 175, 191; 176, 192; 176, 193; 177, 194; 187, 195; 187, 196; 192, 197; 192, 198; 196, 199; 198, 200
def inorder(*iterables, **kwargs): """ A generator that yields the values from several ordered iterables in order. Example: >>> x = [0, 1, 2, 3] >>> y = [1.5, 2.5, 3.5, 4.5] >>> z = [1.75, 2.25, 3.75, 4.25] >>> list(inorder(x, y, z)) [0, 1, 1.5, 1.75, 2, 2.25, 2.5, 3, 3.5, 3.75, 4.25, 4.5] >>> list(inorder(x, y, z, key=lambda x: x * x)) [0, 1, 1.5, 1.75, 2, 2.25, 2.5, 3, 3.5, 3.75, 4.25, 4.5] >>> x.sort(key=lambda x: abs(x-3)) >>> y.sort(key=lambda x: abs(x-3)) >>> z.sort(key=lambda x: abs(x-3)) >>> list(inorder(x, y, z, key=lambda x: abs(x - 3))) [3, 2.5, 3.5, 2.25, 3.75, 2, 1.75, 4.25, 1.5, 4.5, 1, 0] >>> x = [3, 2, 1, 0] >>> y = [4.5, 3.5, 2.5, 1.5] >>> z = [4.25, 3.75, 2.25, 1.75] >>> list(inorder(x, y, z, reverse = True)) [4.5, 4.25, 3.75, 3.5, 3, 2.5, 2.25, 2, 1.75, 1.5, 1, 0] >>> list(inorder(x, y, z, key = lambda x: -x)) [4.5, 4.25, 3.75, 3.5, 3, 2.5, 2.25, 2, 1.75, 1.5, 1, 0] NOTE: this function will never reverse the order of elements in the input iterables. If the reverse keyword argument is False (the default) then the input sequences must yield elements in increasing order, likewise if the keyword argument is True then the input sequences must yield elements in decreasing order. Failure to adhere to this yields undefined results, and for performance reasons no check is performed to validate the element order in the input sequences. """ reverse = kwargs.pop("reverse", False) keyfunc = kwargs.pop("key", lambda x: x) # default = identity if kwargs: raise TypeError("invalid keyword argument '%s'" % kwargs.keys()[0]) nextvals = {} for iterable in iterables: next = iter(iterable).next try: nextval = next() nextvals[next] = keyfunc(nextval), nextval, next except StopIteration: pass if not nextvals: # all sequences are empty return if reverse: select = max else: select = min values = nextvals.itervalues if len(nextvals) > 1: while 1: _, val, next = select(values()) yield val try: nextval = next() nextvals[next] = keyfunc(nextval), nextval, next except StopIteration: del nextvals[next] if len(nextvals) < 2: break # exactly one sequence remains, short circuit and drain it (_, val, next), = values() yield val while 1: yield next()
0, module; 1, function_definition; 2, function_name:add_tag; 3, parameters; 4, block; 5, identifier:self; 6, identifier:tag; 7, identifier:value; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, if_statement; 13, comment:""" as tags are kept in a sorted order, a bisection is a fastest way to identify a correct position of or a new tag to be added. An additional check is required to make sure w don't add duplicates """; 14, assignment; 15, assignment; 16, comparison_operator:index < len(self.tags); 17, block; 18, not_operator; 19, block; 20, identifier:index; 21, call; 22, identifier:contains; 23, False; 24, identifier:index; 25, call; 26, expression_statement; 27, identifier:contains; 28, expression_statement; 29, identifier:bisect_left; 30, argument_list; 31, identifier:len; 32, argument_list; 33, assignment; 34, call; 35, attribute; 36, tuple; 37, attribute; 38, identifier:contains; 39, comparison_operator:self.tags[index] == (tag, value); 40, attribute; 41, argument_list; 42, identifier:self; 43, identifier:tags; 44, identifier:tag; 45, identifier:value; 46, identifier:self; 47, identifier:tags; 48, subscript; 49, tuple; 50, attribute; 51, identifier:insert; 52, identifier:index; 53, tuple; 54, attribute; 55, identifier:index; 56, identifier:tag; 57, identifier:value; 58, identifier:self; 59, identifier:tags; 60, identifier:tag; 61, identifier:value; 62, identifier:self; 63, identifier:tags
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; 12, 18; 12, 19; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 18, 27; 19, 28; 21, 29; 21, 30; 25, 31; 25, 32; 26, 33; 28, 34; 30, 35; 30, 36; 32, 37; 33, 38; 33, 39; 34, 40; 34, 41; 35, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 39, 48; 39, 49; 40, 50; 40, 51; 41, 52; 41, 53; 48, 54; 48, 55; 49, 56; 49, 57; 50, 58; 50, 59; 53, 60; 53, 61; 54, 62; 54, 63
def add_tag(self, tag, value): """ as tags are kept in a sorted order, a bisection is a fastest way to identify a correct position of or a new tag to be added. An additional check is required to make sure w don't add duplicates """ index = bisect_left(self.tags, (tag, value)) contains = False if index < len(self.tags): contains = self.tags[index] == (tag, value) if not contains: self.tags.insert(index, (tag, value))
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, if_statement; 22, if_statement; 23, return_statement; 24, identifier:by; 25, None; 26, identifier:external; 27, None; 28, identifier:offset; 29, integer:0; 30, identifier:limit; 31, None; 32, identifier:order; 33, None; 34, identifier:alpha; 35, False; 36, identifier:store_as; 37, None; 38, comment:"""Returns or stores the elements contained in the list, set or sorted set at key. By default, sorting is numeric and elements are compared by their value interpreted as double precision floating point number. The ``external`` parameter is used to specify the `GET <http://redis.io/commands/sort#retrieving-external-keys>_` parameter for retrieving external keys. It can be a single string or a list of strings. .. note:: **Time complexity**: ``O(N+M*log(M))`` where ``N`` is the number of elements in the list or set to sort, and ``M`` the number of returned elements. When the elements are not sorted, complexity is currently ``O(N)`` as there is a copy step that will be avoided in next releases. :param key: The key to get the refcount for :type key: :class:`str`, :class:`bytes` :param by: The optional pattern for external sorting keys :type by: :class:`str`, :class:`bytes` :param external: Pattern or list of patterns to return external keys :type external: :class:`str`, :class:`bytes`, list :param int offset: The starting offset when using limit :param int limit: The number of elements to return :param order: The sort order - one of ``ASC`` or ``DESC`` :type order: :class:`str`, :class:`bytes` :param bool alpha: Sort the results lexicographically :param store_as: When specified, the key to store the results as :type store_as: :class:`str`, :class:`bytes`, None :rtype: list|int :raises: :exc:`~tredis.exceptions.RedisError` :raises: :exc:`ValueError` """; 39, boolean_operator; 40, block; 41, assignment; 42, identifier:by; 43, block; 44, boolean_operator; 45, block; 46, elif_clause; 47, identifier:limit; 48, block; 49, identifier:order; 50, block; 51, comparison_operator:alpha is True; 52, block; 53, identifier:store_as; 54, block; 55, call; 56, identifier:order; 57, comparison_operator:order not in [b'ASC', b'DESC', 'ASC', 'DESC']; 58, raise_statement; 59, identifier:command; 60, list; 61, expression_statement; 62, identifier:external; 63, call; 64, for_statement; 65, identifier:external; 66, block; 67, expression_statement; 68, expression_statement; 69, identifier:alpha; 70, True; 71, expression_statement; 72, expression_statement; 73, attribute; 74, argument_list; 75, identifier:order; 76, list; 77, call; 78, string; 79, identifier:key; 80, augmented_assignment; 81, identifier:isinstance; 82, argument_list; 83, identifier:entry; 84, identifier:external; 85, block; 86, expression_statement; 87, augmented_assignment; 88, call; 89, call; 90, augmented_assignment; 91, identifier:self; 92, identifier:_execute; 93, identifier:command; 94, string; 95, string; 96, string; 97, string; 98, identifier:ValueError; 99, argument_list; 100, string_content:SORT; 101, identifier:command; 102, list; 103, identifier:external; 104, identifier:list; 105, expression_statement; 106, augmented_assignment; 107, identifier:command; 108, list; 109, attribute; 110, argument_list; 111, attribute; 112, argument_list; 113, identifier:command; 114, list; 115, string_content:ASC; 116, string_content:DESC; 117, string_content:ASC; 118, string_content:DESC; 119, call; 120, string; 121, identifier:by; 122, augmented_assignment; 123, identifier:command; 124, list; 125, string; 126, call; 127, call; 128, identifier:command; 129, identifier:append; 130, identifier:order; 131, identifier:command; 132, identifier:append; 133, string; 134, string; 135, identifier:store_as; 136, attribute; 137, argument_list; 138, string_content:BY; 139, identifier:command; 140, list; 141, string; 142, identifier:external; 143, string_content:LIMIT; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, string_content:ALPHA; 149, string_content:STORE; 150, string:'invalid sort order "{}"'; 151, identifier:format; 152, identifier:order; 153, string; 154, identifier:entry; 155, string_content:GET; 156, call; 157, identifier:encode; 158, string; 159, call; 160, identifier:encode; 161, string; 162, string_content:GET; 163, identifier:ascii; 164, argument_list; 165, string_content:utf-8; 166, identifier:ascii; 167, argument_list; 168, string_content:utf-8; 169, identifier:offset; 170, identifier:limit
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 7, 24; 7, 25; 8, 26; 8, 27; 9, 28; 9, 29; 10, 30; 10, 31; 11, 32; 11, 33; 12, 34; 12, 35; 13, 36; 13, 37; 14, 38; 15, 39; 15, 40; 16, 41; 17, 42; 17, 43; 18, 44; 18, 45; 18, 46; 19, 47; 19, 48; 20, 49; 20, 50; 21, 51; 21, 52; 22, 53; 22, 54; 23, 55; 39, 56; 39, 57; 40, 58; 41, 59; 41, 60; 43, 61; 44, 62; 44, 63; 45, 64; 46, 65; 46, 66; 48, 67; 50, 68; 51, 69; 51, 70; 52, 71; 54, 72; 55, 73; 55, 74; 57, 75; 57, 76; 58, 77; 60, 78; 60, 79; 61, 80; 63, 81; 63, 82; 64, 83; 64, 84; 64, 85; 66, 86; 67, 87; 68, 88; 71, 89; 72, 90; 73, 91; 73, 92; 74, 93; 76, 94; 76, 95; 76, 96; 76, 97; 77, 98; 77, 99; 78, 100; 80, 101; 80, 102; 82, 103; 82, 104; 85, 105; 86, 106; 87, 107; 87, 108; 88, 109; 88, 110; 89, 111; 89, 112; 90, 113; 90, 114; 94, 115; 95, 116; 96, 117; 97, 118; 99, 119; 102, 120; 102, 121; 105, 122; 106, 123; 106, 124; 108, 125; 108, 126; 108, 127; 109, 128; 109, 129; 110, 130; 111, 131; 111, 132; 112, 133; 114, 134; 114, 135; 119, 136; 119, 137; 120, 138; 122, 139; 122, 140; 124, 141; 124, 142; 125, 143; 126, 144; 126, 145; 127, 146; 127, 147; 133, 148; 134, 149; 136, 150; 136, 151; 137, 152; 140, 153; 140, 154; 141, 155; 144, 156; 144, 157; 145, 158; 146, 159; 146, 160; 147, 161; 153, 162; 156, 163; 156, 164; 158, 165; 159, 166; 159, 167; 161, 168; 164, 169; 167, 170
def sort(self, key, by=None, external=None, offset=0, limit=None, order=None, alpha=False, store_as=None): """Returns or stores the elements contained in the list, set or sorted set at key. By default, sorting is numeric and elements are compared by their value interpreted as double precision floating point number. The ``external`` parameter is used to specify the `GET <http://redis.io/commands/sort#retrieving-external-keys>_` parameter for retrieving external keys. It can be a single string or a list of strings. .. note:: **Time complexity**: ``O(N+M*log(M))`` where ``N`` is the number of elements in the list or set to sort, and ``M`` the number of returned elements. When the elements are not sorted, complexity is currently ``O(N)`` as there is a copy step that will be avoided in next releases. :param key: The key to get the refcount for :type key: :class:`str`, :class:`bytes` :param by: The optional pattern for external sorting keys :type by: :class:`str`, :class:`bytes` :param external: Pattern or list of patterns to return external keys :type external: :class:`str`, :class:`bytes`, list :param int offset: The starting offset when using limit :param int limit: The number of elements to return :param order: The sort order - one of ``ASC`` or ``DESC`` :type order: :class:`str`, :class:`bytes` :param bool alpha: Sort the results lexicographically :param store_as: When specified, the key to store the results as :type store_as: :class:`str`, :class:`bytes`, None :rtype: list|int :raises: :exc:`~tredis.exceptions.RedisError` :raises: :exc:`ValueError` """ if order and order not in [b'ASC', b'DESC', 'ASC', 'DESC']: raise ValueError('invalid sort order "{}"'.format(order)) command = [b'SORT', key] if by: command += [b'BY', by] if external and isinstance(external, list): for entry in external: command += [b'GET', entry] elif external: command += [b'GET', external] if limit: command += [ b'LIMIT', ascii(offset).encode('utf-8'), ascii(limit).encode('utf-8') ] if order: command.append(order) if alpha is True: command.append(b'ALPHA') if store_as: command += [b'STORE', store_as] return self._execute(command)
0, module; 1, function_definition; 2, function_name:zrange; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:start; 15, integer:0; 16, identifier:stop; 17, unary_operator; 18, identifier:with_scores; 19, False; 20, comment:"""Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score. See :meth:`tredis.Client.zrevrange` when you need the elements ordered from highest to lowest score (and descending lexicographical order for elements with equal score). Both start and stop are zero-based indexes, where ``0`` is the first element, ``1`` is the next element and so on. They can also be negative numbers indicating offsets from the end of the sorted set, with ``-1`` being the last element of the sorted set, ``-2`` the penultimate element and so on. ``start`` and ``stop`` are inclusive ranges, so for example ``ZRANGE myzset 0 1`` will return both the first and the second element of the sorted set. Out of range indexes will not produce an error. If start is larger than the largest index in the sorted set, or ``start > stop``, an empty list is returned. If stop is larger than the end of the sorted set Redis will treat it like it is the last element of the sorted set. It is possible to pass the ``WITHSCORES`` option in order to return the scores of the elements together with the elements. The returned list will contain ``value1,score1,...,valueN,scoreN`` instead of ``value1,...,valueN``. Client libraries are free to return a more appropriate data type (suggestion: an array with (value, score) arrays/tuples). .. note:: **Time complexity**: ``O(log(N)+M)`` with ``N`` being the number of elements in the sorted set and ``M`` the number of elements returned. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param int start: The starting index of the sorted set :param int stop: The ending index of the sorted set :param bool with_scores: Return the scores with the elements :rtype: list :raises: :exc:`~tredis.exceptions.RedisError` """; 21, assignment; 22, identifier:with_scores; 23, block; 24, call; 25, integer:1; 26, identifier:command; 27, list; 28, expression_statement; 29, attribute; 30, argument_list; 31, string; 32, identifier:key; 33, identifier:start; 34, identifier:stop; 35, augmented_assignment; 36, identifier:self; 37, identifier:_execute; 38, identifier:command; 39, string_content:ZRANGE; 40, identifier:command; 41, list; 42, string; 43, string_content:WITHSCORES
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; 12, 23; 13, 24; 17, 25; 21, 26; 21, 27; 23, 28; 24, 29; 24, 30; 27, 31; 27, 32; 27, 33; 27, 34; 28, 35; 29, 36; 29, 37; 30, 38; 31, 39; 35, 40; 35, 41; 41, 42; 42, 43
def zrange(self, key, start=0, stop=-1, with_scores=False): """Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score. See :meth:`tredis.Client.zrevrange` when you need the elements ordered from highest to lowest score (and descending lexicographical order for elements with equal score). Both start and stop are zero-based indexes, where ``0`` is the first element, ``1`` is the next element and so on. They can also be negative numbers indicating offsets from the end of the sorted set, with ``-1`` being the last element of the sorted set, ``-2`` the penultimate element and so on. ``start`` and ``stop`` are inclusive ranges, so for example ``ZRANGE myzset 0 1`` will return both the first and the second element of the sorted set. Out of range indexes will not produce an error. If start is larger than the largest index in the sorted set, or ``start > stop``, an empty list is returned. If stop is larger than the end of the sorted set Redis will treat it like it is the last element of the sorted set. It is possible to pass the ``WITHSCORES`` option in order to return the scores of the elements together with the elements. The returned list will contain ``value1,score1,...,valueN,scoreN`` instead of ``value1,...,valueN``. Client libraries are free to return a more appropriate data type (suggestion: an array with (value, score) arrays/tuples). .. note:: **Time complexity**: ``O(log(N)+M)`` with ``N`` being the number of elements in the sorted set and ``M`` the number of elements returned. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param int start: The starting index of the sorted set :param int stop: The ending index of the sorted set :param bool with_scores: Return the scores with the elements :rtype: list :raises: :exc:`~tredis.exceptions.RedisError` """ command = [b'ZRANGE', key, start, stop] if with_scores: command += ['WITHSCORES'] return self._execute(command)
0, module; 1, function_definition; 2, function_name:zrem; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, list_splat_pattern; 8, expression_statement; 9, return_statement; 10, identifier:members; 11, comment:"""Removes the specified members from the sorted set stored at key. Non existing members are ignored. An error is returned when key exists and does not hold a sorted set. .. note:: **Time complexity**: ``O(M*log(N))`` with ``N`` being the number of elements in the sorted set and ``M`` the number of elements to be removed. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param members: One or more member values to remove :type members: :class:`str`, :class:`bytes` :rtype: int :raises: :exc:`~tredis.exceptions.RedisError` """; 12, call; 13, attribute; 14, argument_list; 15, identifier:self; 16, identifier:_execute; 17, binary_operator:[b'ZREM', key] + list(members); 18, list; 19, call; 20, string; 21, identifier:key; 22, identifier:list; 23, argument_list; 24, string_content:ZREM; 25, identifier:members
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 7, 10; 8, 11; 9, 12; 12, 13; 12, 14; 13, 15; 13, 16; 14, 17; 17, 18; 17, 19; 18, 20; 18, 21; 19, 22; 19, 23; 20, 24; 23, 25
def zrem(self, key, *members): """Removes the specified members from the sorted set stored at key. Non existing members are ignored. An error is returned when key exists and does not hold a sorted set. .. note:: **Time complexity**: ``O(M*log(N))`` with ``N`` being the number of elements in the sorted set and ``M`` the number of elements to be removed. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param members: One or more member values to remove :type members: :class:`str`, :class:`bytes` :rtype: int :raises: :exc:`~tredis.exceptions.RedisError` """ return self._execute([b'ZREM', key] + list(members))
0, module; 1, function_definition; 2, function_name:zremrangebyscore; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, identifier:min_score; 8, identifier:max_score; 9, expression_statement; 10, return_statement; 11, comment:"""Removes all elements in the sorted set stored at key with a score between min and max. Intervals are described in :meth:`~tredis.RedisClient.zrangebyscore`. Returns the number of elements removed. .. note:: **Time complexity**: ``O(log(N)+M)`` with ``N`` being the number of elements in the sorted set and M the number of elements removed by the operation. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param min_score: Lowest score definition :type min_score: :class:`str`, :class:`bytes` :param max_score: Highest score definition :type max_score: :class:`str`, :class:`bytes` :rtype: int :raises: :exc:`~tredis.exceptions.RedisError` """; 12, call; 13, attribute; 14, argument_list; 15, identifier:self; 16, identifier:_execute; 17, list; 18, string; 19, identifier:key; 20, identifier:min_score; 21, identifier:max_score; 22, string_content:ZREMRANGEBYSCORE
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 9, 11; 10, 12; 12, 13; 12, 14; 13, 15; 13, 16; 14, 17; 17, 18; 17, 19; 17, 20; 17, 21; 18, 22
def zremrangebyscore(self, key, min_score, max_score): """Removes all elements in the sorted set stored at key with a score between min and max. Intervals are described in :meth:`~tredis.RedisClient.zrangebyscore`. Returns the number of elements removed. .. note:: **Time complexity**: ``O(log(N)+M)`` with ``N`` being the number of elements in the sorted set and M the number of elements removed by the operation. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param min_score: Lowest score definition :type min_score: :class:`str`, :class:`bytes` :param max_score: Highest score definition :type max_score: :class:`str`, :class:`bytes` :rtype: int :raises: :exc:`~tredis.exceptions.RedisError` """ return self._execute([b'ZREMRANGEBYSCORE', key, min_score, max_score])
0, module; 1, function_definition; 2, function_name:zrevrange; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:start; 15, integer:0; 16, identifier:stop; 17, unary_operator; 18, identifier:with_scores; 19, False; 20, comment:"""Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score. Apart from the reversed ordering, :py:meth:`~tredis.Client.zrevrange` is similar to :py:meth:`~tredis.Client.zrange` . .. note:: **Time complexity**: ``O(log(N)+M)`` with ``N`` being the number of elements in the sorted set and ``M`` the number of elements returned. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param int start: The starting index of the sorted set :param int stop: The ending index of the sorted set :param bool with_scores: Return the scores with the elements :rtype: list :raises: :exc:`~tredis.exceptions.RedisError` """; 21, assignment; 22, identifier:with_scores; 23, block; 24, call; 25, integer:1; 26, identifier:command; 27, list; 28, expression_statement; 29, attribute; 30, argument_list; 31, string; 32, identifier:key; 33, identifier:start; 34, identifier:stop; 35, augmented_assignment; 36, identifier:self; 37, identifier:_execute; 38, identifier:command; 39, string_content:ZREVRANGE; 40, identifier:command; 41, list; 42, string; 43, string_content:WITHSCORES
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; 12, 23; 13, 24; 17, 25; 21, 26; 21, 27; 23, 28; 24, 29; 24, 30; 27, 31; 27, 32; 27, 33; 27, 34; 28, 35; 29, 36; 29, 37; 30, 38; 31, 39; 35, 40; 35, 41; 41, 42; 42, 43
def zrevrange(self, key, start=0, stop=-1, with_scores=False): """Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score. Apart from the reversed ordering, :py:meth:`~tredis.Client.zrevrange` is similar to :py:meth:`~tredis.Client.zrange` . .. note:: **Time complexity**: ``O(log(N)+M)`` with ``N`` being the number of elements in the sorted set and ``M`` the number of elements returned. :param key: The key of the sorted set :type key: :class:`str`, :class:`bytes` :param int start: The starting index of the sorted set :param int stop: The ending index of the sorted set :param bool with_scores: Return the scores with the elements :rtype: list :raises: :exc:`~tredis.exceptions.RedisError` """ command = [b'ZREVRANGE', key, start, stop] if with_scores: command += ['WITHSCORES'] return self._execute(command)
0, module; 1, function_definition; 2, function_name:_sortObjects; 3, parameters; 4, block; 5, default_parameter; 6, dictionary_splat_pattern; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:orderby; 15, string; 16, identifier:kwargs; 17, comment:"""Sorts lists of objects and combines them into a single list"""; 18, assignment; 19, identifier:m; 20, call; 21, block; 22, assignment; 23, assignment; 24, attribute; 25, block; 26, else_clause; 27, identifier:o; 28, string_content:created; 29, identifier:o; 30, list; 31, attribute; 32, argument_list; 33, for_statement; 34, identifier:o; 35, call; 36, identifier:sortfunc; 37, conditional_expression:_sortByCreated if orderby == 'created' else _sortByModified; 38, identifier:six; 39, identifier:PY2; 40, expression_statement; 41, block; 42, identifier:kwargs; 43, identifier:values; 44, identifier:l; 45, call; 46, block; 47, identifier:list; 48, argument_list; 49, identifier:_sortByCreated; 50, comparison_operator:orderby == 'created'; 51, identifier:_sortByModified; 52, call; 53, expression_statement; 54, identifier:iter; 55, argument_list; 56, expression_statement; 57, call; 58, identifier:orderby; 59, string; 60, attribute; 61, argument_list; 62, call; 63, identifier:m; 64, call; 65, identifier:set; 66, argument_list; 67, string_content:created; 68, identifier:o; 69, identifier:sort; 70, identifier:sortfunc; 71, attribute; 72, argument_list; 73, attribute; 74, argument_list; 75, identifier:o; 76, identifier:o; 77, identifier:sort; 78, keyword_argument; 79, identifier:o; 80, identifier:append; 81, identifier:l; 82, identifier:key; 83, call; 84, attribute; 85, argument_list; 86, identifier:functools; 87, identifier:cmp_to_key; 88, identifier:sortfunc
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; 5, 14; 5, 15; 6, 16; 7, 17; 8, 18; 9, 19; 9, 20; 9, 21; 10, 22; 11, 23; 12, 24; 12, 25; 12, 26; 13, 27; 15, 28; 18, 29; 18, 30; 20, 31; 20, 32; 21, 33; 22, 34; 22, 35; 23, 36; 23, 37; 24, 38; 24, 39; 25, 40; 26, 41; 31, 42; 31, 43; 33, 44; 33, 45; 33, 46; 35, 47; 35, 48; 37, 49; 37, 50; 37, 51; 40, 52; 41, 53; 45, 54; 45, 55; 46, 56; 48, 57; 50, 58; 50, 59; 52, 60; 52, 61; 53, 62; 55, 63; 56, 64; 57, 65; 57, 66; 59, 67; 60, 68; 60, 69; 61, 70; 62, 71; 62, 72; 64, 73; 64, 74; 66, 75; 71, 76; 71, 77; 72, 78; 73, 79; 73, 80; 74, 81; 78, 82; 78, 83; 83, 84; 83, 85; 84, 86; 84, 87; 85, 88
def _sortObjects(orderby='created', **kwargs): """Sorts lists of objects and combines them into a single list""" o = [] for m in kwargs.values(): for l in iter(m): o.append(l) o = list(set(o)) sortfunc = _sortByCreated if orderby == 'created' else _sortByModified if six.PY2: o.sort(sortfunc) else: o.sort(key=functools.cmp_to_key(sortfunc)) return o
0, module; 1, function_definition; 2, function_name:_sortByCreated; 3, parameters; 4, block; 5, identifier:a; 6, identifier:b; 7, expression_statement; 8, if_statement; 9, comment:"""Sort function for object by created date"""; 10, comparison_operator:a.created < b.created; 11, block; 12, elif_clause; 13, else_clause; 14, attribute; 15, attribute; 16, return_statement; 17, comparison_operator:a.created > b.created; 18, block; 19, block; 20, identifier:a; 21, identifier:created; 22, identifier:b; 23, identifier:created; 24, integer:1; 25, attribute; 26, attribute; 27, return_statement; 28, return_statement; 29, identifier:a; 30, identifier:created; 31, identifier:b; 32, identifier:created; 33, unary_operator; 34, integer:0; 35, integer:1
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; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 17, 25; 17, 26; 18, 27; 19, 28; 25, 29; 25, 30; 26, 31; 26, 32; 27, 33; 28, 34; 33, 35
def _sortByCreated(a, b): """Sort function for object by created date""" if a.created < b.created: return 1 elif a.created > b.created: return -1 else: return 0
0, module; 1, function_definition; 2, function_name:_sortByModified; 3, parameters; 4, block; 5, identifier:a; 6, identifier:b; 7, expression_statement; 8, if_statement; 9, comment:"""Sort function for object by modified date"""; 10, comparison_operator:a.modified < b.modified; 11, block; 12, elif_clause; 13, else_clause; 14, attribute; 15, attribute; 16, return_statement; 17, comparison_operator:a.modified > b.modified; 18, block; 19, block; 20, identifier:a; 21, identifier:modified; 22, identifier:b; 23, identifier:modified; 24, integer:1; 25, attribute; 26, attribute; 27, return_statement; 28, return_statement; 29, identifier:a; 30, identifier:modified; 31, identifier:b; 32, identifier:modified; 33, unary_operator; 34, integer:0; 35, integer:1
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; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 17, 25; 17, 26; 18, 27; 19, 28; 25, 29; 25, 30; 26, 31; 26, 32; 27, 33; 28, 34; 33, 35
def _sortByModified(a, b): """Sort function for object by modified date""" if a.modified < b.modified: return 1 elif a.modified > b.modified: return -1 else: return 0
0, module; 1, function_definition; 2, function_name:wngram2idngram; 3, parameters; 4, block; 5, identifier:input_file; 6, identifier:vocab_file; 7, identifier:output_file; 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, if_statement; 24, if_statement; 25, if_statement; 26, comment:# Ensure that every parameter is of type 'str'; 27, expression_statement; 28, with_statement; 29, expression_statement; 30, expression_statement; 31, if_statement; 32, if_statement; 33, return_statement; 34, identifier:buffersize; 35, integer:100; 36, identifier:hashtablesize; 37, integer:2000000; 38, identifier:files; 39, integer:20; 40, identifier:compress; 41, False; 42, identifier:verbosity; 43, integer:2; 44, identifier:n; 45, integer:3; 46, identifier:write_ascii; 47, False; 48, identifier:fof_size; 49, integer:10; 50, comment:""" Takes a word N-gram file and a vocabulary file and lists every id n-gram which occurred in the text, along with its number of occurrences, in either ASCII or binary format. Note : It is important that the vocabulary file is in alphabetical order. If you are using vocabularies generated by wfreq2vocab then this should not be an issue, as they will already be alphabetically sorted. """; 51, assignment; 52, identifier:buffersize; 53, block; 54, identifier:hashtablesize; 55, block; 56, identifier:files; 57, block; 58, identifier:verbosity; 59, block; 60, identifier:n; 61, block; 62, identifier:fof_size; 63, block; 64, identifier:compress; 65, block; 66, identifier:write_ascii; 67, block; 68, assignment; 69, with_clause; 70, block; 71, assignment; 72, call; 73, comparison_operator:exitcode != 0; 74, block; 75, boolean_operator; 76, block; 77, call; 78, identifier:cmd; 79, list; 80, expression_statement; 81, expression_statement; 82, expression_statement; 83, expression_statement; 84, expression_statement; 85, expression_statement; 86, expression_statement; 87, expression_statement; 88, identifier:cmd; 89, list_comprehension; 90, with_item; 91, with_statement; 92, expression_statement; 93, identifier:logger; 94, call; 95, attribute; 96, argument_list; 97, identifier:exitcode; 98, integer:0; 99, raise_statement; 100, comparison_operator:sys.version_info >= (3,); 101, comparison_operator:type(output) is bytes; 102, expression_statement; 103, attribute; 104, argument_list; 105, string; 106, string; 107, call; 108, string; 109, call; 110, call; 111, call; 112, call; 113, call; 114, call; 115, call; 116, call; 117, call; 118, call; 119, for_in_clause; 120, as_pattern; 121, with_clause; 122, block; 123, assignment; 124, attribute; 125, argument_list; 126, identifier:logger; 127, identifier:debug; 128, binary_operator:"Command '%s' returned with exit code '%d'." % (' '.join(cmd), exitcode); 129, call; 130, attribute; 131, tuple; 132, call; 133, identifier:bytes; 134, assignment; 135, identifier:output; 136, identifier:strip; 137, string_content:wngram2idngram; 138, string_content:-vocab; 139, attribute; 140, argument_list; 141, string_content:-idngram; 142, attribute; 143, argument_list; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, attribute; 149, argument_list; 150, attribute; 151, argument_list; 152, attribute; 153, argument_list; 154, attribute; 155, argument_list; 156, attribute; 157, argument_list; 158, attribute; 159, argument_list; 160, identifier:str; 161, argument_list; 162, identifier:x; 163, identifier:cmd; 164, call; 165, as_pattern_target; 166, with_item; 167, expression_statement; 168, expression_statement; 169, with_statement; 170, identifier:output; 171, call; 172, identifier:logging; 173, identifier:getLogger; 174, identifier:__name__; 175, string:"Command '%s' returned with exit code '%d'."; 176, tuple; 177, identifier:ConversionError; 178, argument_list; 179, identifier:sys; 180, identifier:version_info; 181, integer:3; 182, identifier:type; 183, argument_list; 184, identifier:output; 185, call; 186, attribute; 187, identifier:abspath; 188, identifier:vocab_file; 189, attribute; 190, identifier:abspath; 191, identifier:output_file; 192, identifier:cmd; 193, identifier:extend; 194, list; 195, identifier:cmd; 196, identifier:extend; 197, list; 198, identifier:cmd; 199, identifier:extend; 200, list; 201, identifier:cmd; 202, identifier:extend; 203, list; 204, identifier:cmd; 205, identifier:extend; 206, list; 207, identifier:cmd; 208, identifier:extend; 209, list; 210, identifier:cmd; 211, identifier:append; 212, string; 213, identifier:cmd; 214, identifier:append; 215, string; 216, identifier:x; 217, attribute; 218, argument_list; 219, identifier:output_f; 220, as_pattern; 221, call; 222, call; 223, with_clause; 224, block; 225, attribute; 226, argument_list; 227, call; 228, identifier:exitcode; 229, binary_operator:"'%r' returned with non-zero exit status '%s'" % (cmd, exitcode); 230, identifier:output; 231, attribute; 232, argument_list; 233, identifier:os; 234, identifier:path; 235, identifier:os; 236, identifier:path; 237, string; 238, identifier:buffersize; 239, string; 240, identifier:hashtablesize; 241, string; 242, identifier:files; 243, string; 244, identifier:verbosity; 245, string; 246, identifier:n; 247, string; 248, identifier:fof_size; 249, string_content:-compress; 250, string_content:-write_ascii; 251, identifier:tempfile; 252, identifier:SpooledTemporaryFile; 253, call; 254, as_pattern_target; 255, attribute; 256, argument_list; 257, attribute; 258, argument_list; 259, with_item; 260, with_statement; 261, identifier:output_f; 262, identifier:read; 263, attribute; 264, argument_list; 265, string:"'%r' returned with non-zero exit status '%s'"; 266, tuple; 267, identifier:output; 268, identifier:decode; 269, string; 270, string_content:-buffer; 271, string_content:-hash; 272, string_content:-files; 273, string_content:-verbosity; 274, string_content:-n; 275, string_content:-fof_size; 276, attribute; 277, argument_list; 278, identifier:input_f; 279, identifier:input_f; 280, identifier:write; 281, conditional_expression:text.encode('utf-8') if sys.version_info >= (3,) and type(text) is str else text; 282, identifier:input_f; 283, identifier:seek; 284, integer:0; 285, as_pattern; 286, with_clause; 287, block; 288, string; 289, identifier:join; 290, identifier:cmd; 291, identifier:cmd; 292, identifier:exitcode; 293, string_content:utf-8; 294, identifier:tempfile; 295, identifier:SpooledTemporaryFile; 296, call; 297, boolean_operator; 298, identifier:text; 299, call; 300, as_pattern_target; 301, with_item; 302, expression_statement; 303, string_content:; 304, attribute; 305, argument_list; 306, comparison_operator:sys.version_info >= (3,); 307, comparison_operator:type(text) is str; 308, identifier:output_to_debuglogger; 309, argument_list; 310, identifier:err_f; 311, call; 312, assignment; 313, identifier:text; 314, identifier:encode; 315, string; 316, attribute; 317, tuple; 318, call; 319, identifier:str; 320, identifier:do_in_tempdir; 321, argument_list; 322, identifier:exitcode; 323, call; 324, string_content:utf-8; 325, identifier:sys; 326, identifier:version_info; 327, integer:3; 328, identifier:type; 329, argument_list; 330, attribute; 331, argument_list; 332, identifier:text; 333, identifier:subprocess; 334, identifier:call; 335, identifier:cmd; 336, keyword_argument; 337, keyword_argument; 338, keyword_argument; 339, identifier:stdin; 340, identifier:input_f; 341, identifier:stdout; 342, identifier:output_f; 343, identifier:stderr; 344, identifier:err_f
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; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 8, 34; 8, 35; 9, 36; 9, 37; 10, 38; 10, 39; 11, 40; 11, 41; 12, 42; 12, 43; 13, 44; 13, 45; 14, 46; 14, 47; 15, 48; 15, 49; 16, 50; 17, 51; 18, 52; 18, 53; 19, 54; 19, 55; 20, 56; 20, 57; 21, 58; 21, 59; 22, 60; 22, 61; 23, 62; 23, 63; 24, 64; 24, 65; 25, 66; 25, 67; 27, 68; 28, 69; 28, 70; 29, 71; 30, 72; 31, 73; 31, 74; 32, 75; 32, 76; 33, 77; 51, 78; 51, 79; 53, 80; 55, 81; 57, 82; 59, 83; 61, 84; 63, 85; 65, 86; 67, 87; 68, 88; 68, 89; 69, 90; 70, 91; 70, 92; 71, 93; 71, 94; 72, 95; 72, 96; 73, 97; 73, 98; 74, 99; 75, 100; 75, 101; 76, 102; 77, 103; 77, 104; 79, 105; 79, 106; 79, 107; 79, 108; 79, 109; 80, 110; 81, 111; 82, 112; 83, 113; 84, 114; 85, 115; 86, 116; 87, 117; 89, 118; 89, 119; 90, 120; 91, 121; 91, 122; 92, 123; 94, 124; 94, 125; 95, 126; 95, 127; 96, 128; 99, 129; 100, 130; 100, 131; 101, 132; 101, 133; 102, 134; 103, 135; 103, 136; 105, 137; 106, 138; 107, 139; 107, 140; 108, 141; 109, 142; 109, 143; 110, 144; 110, 145; 111, 146; 111, 147; 112, 148; 112, 149; 113, 150; 113, 151; 114, 152; 114, 153; 115, 154; 115, 155; 116, 156; 116, 157; 117, 158; 117, 159; 118, 160; 118, 161; 119, 162; 119, 163; 120, 164; 120, 165; 121, 166; 122, 167; 122, 168; 122, 169; 123, 170; 123, 171; 124, 172; 124, 173; 125, 174; 128, 175; 128, 176; 129, 177; 129, 178; 130, 179; 130, 180; 131, 181; 132, 182; 132, 183; 134, 184; 134, 185; 139, 186; 139, 187; 140, 188; 142, 189; 142, 190; 143, 191; 144, 192; 144, 193; 145, 194; 146, 195; 146, 196; 147, 197; 148, 198; 148, 199; 149, 200; 150, 201; 150, 202; 151, 203; 152, 204; 152, 205; 153, 206; 154, 207; 154, 208; 155, 209; 156, 210; 156, 211; 157, 212; 158, 213; 158, 214; 159, 215; 161, 216; 164, 217; 164, 218; 165, 219; 166, 220; 167, 221; 168, 222; 169, 223; 169, 224; 171, 225; 171, 226; 176, 227; 176, 228; 178, 229; 183, 230; 185, 231; 185, 232; 186, 233; 186, 234; 189, 235; 189, 236; 194, 237; 194, 238; 197, 239; 197, 240; 200, 241; 200, 242; 203, 243; 203, 244; 206, 245; 206, 246; 209, 247; 209, 248; 212, 249; 215, 250; 217, 251; 217, 252; 220, 253; 220, 254; 221, 255; 221, 256; 222, 257; 222, 258; 223, 259; 224, 260; 225, 261; 225, 262; 227, 263; 227, 264; 229, 265; 229, 266; 231, 267; 231, 268; 232, 269; 237, 270; 239, 271; 241, 272; 243, 273; 245, 274; 247, 275; 253, 276; 253, 277; 254, 278; 255, 279; 255, 280; 256, 281; 257, 282; 257, 283; 258, 284; 259, 285; 260, 286; 260, 287; 263, 288; 263, 289; 264, 290; 266, 291; 266, 292; 269, 293; 276, 294; 276, 295; 281, 296; 281, 297; 281, 298; 285, 299; 285, 300; 286, 301; 287, 302; 288, 303; 296, 304; 296, 305; 297, 306; 297, 307; 299, 308; 299, 309; 300, 310; 301, 311; 302, 312; 304, 313; 304, 314; 305, 315; 306, 316; 306, 317; 307, 318; 307, 319; 311, 320; 311, 321; 312, 322; 312, 323; 315, 324; 316, 325; 316, 326; 317, 327; 318, 328; 318, 329; 323, 330; 323, 331; 329, 332; 330, 333; 330, 334; 331, 335; 331, 336; 331, 337; 331, 338; 336, 339; 336, 340; 337, 341; 337, 342; 338, 343; 338, 344
def wngram2idngram(input_file, vocab_file, output_file, buffersize=100, hashtablesize=2000000, files=20, compress=False, verbosity=2, n=3, write_ascii=False, fof_size=10): """ Takes a word N-gram file and a vocabulary file and lists every id n-gram which occurred in the text, along with its number of occurrences, in either ASCII or binary format. Note : It is important that the vocabulary file is in alphabetical order. If you are using vocabularies generated by wfreq2vocab then this should not be an issue, as they will already be alphabetically sorted. """ cmd = ['wngram2idngram', '-vocab', os.path.abspath(vocab_file), '-idngram', os.path.abspath(output_file)] if buffersize: cmd.extend(['-buffer', buffersize]) if hashtablesize: cmd.extend(['-hash', hashtablesize]) if files: cmd.extend(['-files', files]) if verbosity: cmd.extend(['-verbosity', verbosity]) if n: cmd.extend(['-n', n]) if fof_size: cmd.extend(['-fof_size', fof_size]) if compress: cmd.append('-compress') if write_ascii: cmd.append('-write_ascii') # Ensure that every parameter is of type 'str' cmd = [str(x) for x in cmd] with tempfile.SpooledTemporaryFile() as output_f: with tempfile.SpooledTemporaryFile() as input_f: input_f.write(text.encode('utf-8') if sys.version_info >= (3,) and type(text) is str else text) input_f.seek(0) with output_to_debuglogger() as err_f: with do_in_tempdir(): exitcode = subprocess.call(cmd, stdin=input_f, stdout=output_f, stderr=err_f) output = output_f.read() logger = logging.getLogger(__name__) logger.debug("Command '%s' returned with exit code '%d'." % (' '.join(cmd), exitcode)) if exitcode != 0: raise ConversionError("'%r' returned with non-zero exit status '%s'" % (cmd, exitcode)) if sys.version_info >= (3,) and type(output) is bytes: output = output.decode('utf-8') return output.strip()
0, module; 1, function_definition; 2, function_name:get_top; 3, parameters; 4, block; 5, identifier:self; 6, identifier:stat; 7, identifier:n; 8, expression_statement; 9, return_statement; 10, comment:"""Return the top n values when sorting by 'stat'"""; 11, subscript; 12, call; 13, slice; 14, identifier:sorted; 15, argument_list; 16, identifier:n; 17, attribute; 18, keyword_argument; 19, keyword_argument; 20, identifier:self; 21, identifier:stats; 22, identifier:key; 23, lambda; 24, identifier:reverse; 25, True; 26, lambda_parameters; 27, call; 28, identifier:x; 29, identifier:getattr; 30, argument_list; 31, identifier:x; 32, identifier:stat
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 11, 12; 11, 13; 12, 14; 12, 15; 13, 16; 15, 17; 15, 18; 15, 19; 17, 20; 17, 21; 18, 22; 18, 23; 19, 24; 19, 25; 23, 26; 23, 27; 26, 28; 27, 29; 27, 30; 30, 31; 30, 32
def get_top(self, stat, n): """Return the top n values when sorting by 'stat'""" return sorted(self.stats, key=lambda x: getattr(x, stat), reverse=True)[:n]
0, module; 1, function_definition; 2, function_name:toposort; 3, parameters; 4, block; 5, identifier:initialAtoms; 6, identifier:initialBonds; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# for the atom and bond hashes; 13, comment:# we ignore the first atom since we; 14, comment:# would have deleted it from the hash anyway; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, for_statement; 19, expression_statement; 20, expression_statement; 21, comment:# do until all the atoms are gone; 22, while_statement; 23, assert_statement; 24, assert_statement; 25, expression_statement; 26, assert_statement; 27, expression_statement; 28, return_statement; 29, comment:"""initialAtoms, initialBonds -> atoms, bonds Given the list of atoms and bonds in a ring return the topologically sorted atoms and bonds. That is each atom is connected to the following atom and each bond is connected to the following bond in the following manner a1 - b1 - a2 - b2 - ... """; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, assignment; 35, assignment; 36, identifier:atom; 37, subscript; 38, block; 39, identifier:bond; 40, identifier:initialBonds; 41, block; 42, assignment; 43, call; 44, identifier:ahash; 45, comment:# traverse to all the connected atoms; 46, block; 47, comparison_operator:len(initialAtoms) == len(atoms); 48, comparison_operator:len(bonds) == len(atoms) - 1; 49, assignment; 50, identifier:lastBond; 51, call; 52, expression_list; 53, identifier:atoms; 54, list; 55, identifier:a_append; 56, attribute; 57, identifier:bonds; 58, list; 59, identifier:b_append; 60, attribute; 61, identifier:ahash; 62, dictionary; 63, identifier:bhash; 64, dictionary; 65, identifier:initialAtoms; 66, slice; 67, expression_statement; 68, expression_statement; 69, identifier:next; 70, subscript; 71, identifier:a_append; 72, argument_list; 73, for_statement; 74, call; 75, call; 76, call; 77, binary_operator:len(atoms) - 1; 78, identifier:lastBond; 79, call; 80, identifier:b_append; 81, argument_list; 82, identifier:atoms; 83, identifier:bonds; 84, identifier:atoms; 85, identifier:append; 86, identifier:bonds; 87, identifier:append; 88, integer:1; 89, assignment; 90, assignment; 91, identifier:initialAtoms; 92, integer:0; 93, identifier:next; 94, identifier:atom; 95, attribute; 96, comment:# both the bond and the atom have to be; 97, comment:# in our list of atoms and bonds to use; 98, comment:# ugg, nested if's... There has to be a; 99, comment:# better control structure; 100, block; 101, else_clause; 102, identifier:len; 103, argument_list; 104, identifier:len; 105, argument_list; 106, identifier:len; 107, argument_list; 108, call; 109, integer:1; 110, attribute; 111, argument_list; 112, identifier:lastBond; 113, subscript; 114, integer:1; 115, subscript; 116, identifier:bond; 117, identifier:next; 118, identifier:oatoms; 119, if_statement; 120, block; 121, identifier:initialAtoms; 122, identifier:atoms; 123, identifier:bonds; 124, identifier:len; 125, argument_list; 126, subscript; 127, identifier:findbond; 128, subscript; 129, identifier:ahash; 130, attribute; 131, identifier:bhash; 132, attribute; 133, call; 134, block; 135, raise_statement; 136, identifier:atoms; 137, identifier:atoms; 138, integer:0; 139, identifier:atoms; 140, unary_operator; 141, identifier:atom; 142, identifier:handle; 143, identifier:bond; 144, identifier:handle; 145, attribute; 146, argument_list; 147, expression_statement; 148, assert_statement; 149, comment:# but wait! the bond has to be in our; 150, comment:# list of bonds we can use!; 151, if_statement; 152, call; 153, integer:1; 154, identifier:ahash; 155, identifier:has_key; 156, attribute; 157, assignment; 158, identifier:bond; 159, call; 160, block; 161, identifier:RingException; 162, argument_list; 163, identifier:atom; 164, identifier:handle; 165, identifier:bond; 166, call; 167, attribute; 168, argument_list; 169, expression_statement; 170, expression_statement; 171, delete_statement; 172, expression_statement; 173, break_statement; 174, string:"Atoms are not in ring"; 175, attribute; 176, argument_list; 177, identifier:bhash; 178, identifier:has_key; 179, attribute; 180, call; 181, call; 182, subscript; 183, assignment; 184, identifier:next; 185, identifier:findbond; 186, identifier:atom; 187, identifier:bond; 188, identifier:handle; 189, identifier:a_append; 190, argument_list; 191, identifier:b_append; 192, argument_list; 193, identifier:ahash; 194, attribute; 195, identifier:next; 196, identifier:atom; 197, identifier:atom; 198, identifier:bond; 199, identifier:atom; 200, identifier:handle
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 7, 29; 8, 30; 9, 31; 10, 32; 11, 33; 15, 34; 16, 35; 17, 36; 17, 37; 17, 38; 18, 39; 18, 40; 18, 41; 19, 42; 20, 43; 22, 44; 22, 45; 22, 46; 23, 47; 24, 48; 25, 49; 26, 50; 27, 51; 28, 52; 30, 53; 30, 54; 31, 55; 31, 56; 32, 57; 32, 58; 33, 59; 33, 60; 34, 61; 34, 62; 35, 63; 35, 64; 37, 65; 37, 66; 38, 67; 41, 68; 42, 69; 42, 70; 43, 71; 43, 72; 46, 73; 47, 74; 47, 75; 48, 76; 48, 77; 49, 78; 49, 79; 51, 80; 51, 81; 52, 82; 52, 83; 56, 84; 56, 85; 60, 86; 60, 87; 66, 88; 67, 89; 68, 90; 70, 91; 70, 92; 72, 93; 73, 94; 73, 95; 73, 96; 73, 97; 73, 98; 73, 99; 73, 100; 73, 101; 74, 102; 74, 103; 75, 104; 75, 105; 76, 106; 76, 107; 77, 108; 77, 109; 79, 110; 79, 111; 81, 112; 89, 113; 89, 114; 90, 115; 90, 116; 95, 117; 95, 118; 100, 119; 101, 120; 103, 121; 105, 122; 107, 123; 108, 124; 108, 125; 110, 126; 110, 127; 111, 128; 113, 129; 113, 130; 115, 131; 115, 132; 119, 133; 119, 134; 120, 135; 125, 136; 126, 137; 126, 138; 128, 139; 128, 140; 130, 141; 130, 142; 132, 143; 132, 144; 133, 145; 133, 146; 134, 147; 134, 148; 134, 149; 134, 150; 134, 151; 135, 152; 140, 153; 145, 154; 145, 155; 146, 156; 147, 157; 148, 158; 151, 159; 151, 160; 152, 161; 152, 162; 156, 163; 156, 164; 157, 165; 157, 166; 159, 167; 159, 168; 160, 169; 160, 170; 160, 171; 160, 172; 160, 173; 162, 174; 166, 175; 166, 176; 167, 177; 167, 178; 168, 179; 169, 180; 170, 181; 171, 182; 172, 183; 175, 184; 175, 185; 176, 186; 179, 187; 179, 188; 180, 189; 180, 190; 181, 191; 181, 192; 182, 193; 182, 194; 183, 195; 183, 196; 190, 197; 192, 198; 194, 199; 194, 200
def toposort(initialAtoms, initialBonds): """initialAtoms, initialBonds -> atoms, bonds Given the list of atoms and bonds in a ring return the topologically sorted atoms and bonds. That is each atom is connected to the following atom and each bond is connected to the following bond in the following manner a1 - b1 - a2 - b2 - ... """ atoms = [] a_append = atoms.append bonds = [] b_append = bonds.append # for the atom and bond hashes # we ignore the first atom since we # would have deleted it from the hash anyway ahash = {} bhash = {} for atom in initialAtoms[1:]: ahash[atom.handle] = 1 for bond in initialBonds: bhash[bond.handle] = bond next = initialAtoms[0] a_append(next) # do until all the atoms are gone while ahash: # traverse to all the connected atoms for atom in next.oatoms: # both the bond and the atom have to be # in our list of atoms and bonds to use # ugg, nested if's... There has to be a # better control structure if ahash.has_key(atom.handle): bond = next.findbond(atom) assert bond # but wait! the bond has to be in our # list of bonds we can use! if bhash.has_key(bond.handle): a_append(atom) b_append(bond) del ahash[atom.handle] next = atom break else: raise RingException("Atoms are not in ring") assert len(initialAtoms) == len(atoms) assert len(bonds) == len(atoms) - 1 lastBond = atoms[0].findbond(atoms[-1]) assert lastBond b_append(lastBond) return atoms, bonds
0, module; 1, function_definition; 2, function_name:flip_uuid_parts; 3, parameters; 4, block; 5, identifier:uuid; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:""" Flips high and low segments of the timestamp portion of a UUID string. This enables correct lexicographic sorting. Because it is a simple flip, this function works in both directions. """; 12, assignment; 13, assignment; 14, assignment; 15, identifier:flipped_uuid; 16, identifier:flipped_uuid; 17, call; 18, pattern_list; 19, expression_list; 20, identifier:flipped_uuid; 21, call; 22, attribute; 23, argument_list; 24, subscript; 25, subscript; 26, subscript; 27, subscript; 28, attribute; 29, argument_list; 30, identifier:uuid; 31, identifier:split; 32, string; 33, identifier:flipped_uuid; 34, integer:0; 35, identifier:flipped_uuid; 36, integer:2; 37, identifier:flipped_uuid; 38, integer:2; 39, identifier:flipped_uuid; 40, integer:0; 41, string; 42, identifier:join; 43, identifier:flipped_uuid; 44, string_content:-; 45, string_content:-
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 13, 19; 14, 20; 14, 21; 17, 22; 17, 23; 18, 24; 18, 25; 19, 26; 19, 27; 21, 28; 21, 29; 22, 30; 22, 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; 32, 44; 41, 45
def flip_uuid_parts(uuid): """ Flips high and low segments of the timestamp portion of a UUID string. This enables correct lexicographic sorting. Because it is a simple flip, this function works in both directions. """ flipped_uuid = uuid.split('-') flipped_uuid[0], flipped_uuid[2] = flipped_uuid[2], flipped_uuid[0] flipped_uuid = '-'.join(flipped_uuid) return flipped_uuid
0, module; 1, function_definition; 2, function_name:SortedSet; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, default_parameter; 8, expression_statement; 9, return_statement; 10, identifier:initial; 11, None; 12, comment:"""The sorted set datatype. :param name: The name of the sorted set. :param initial: Initial members of the set as an iterable of ``(element, score)`` tuples. See :class:`redish.types.SortedSet`. """; 13, call; 14, attribute; 15, argument_list; 16, identifier:types; 17, identifier:SortedSet; 18, identifier:name; 19, attribute; 20, identifier:initial; 21, identifier:self; 22, identifier:api
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 7, 10; 7, 11; 8, 12; 9, 13; 13, 14; 13, 15; 14, 16; 14, 17; 15, 18; 15, 19; 15, 20; 19, 21; 19, 22
def SortedSet(self, name, initial=None): """The sorted set datatype. :param name: The name of the sorted set. :param initial: Initial members of the set as an iterable of ``(element, score)`` tuples. See :class:`redish.types.SortedSet`. """ return types.SortedSet(name, self.api, initial)
0, module; 1, function_definition; 2, function_name:add; 3, parameters; 4, block; 5, identifier:self; 6, identifier:member; 7, identifier:score; 8, expression_statement; 9, return_statement; 10, comment:"""Add the specified member to the sorted set, or update the score if it already exist."""; 11, call; 12, attribute; 13, argument_list; 14, attribute; 15, identifier:zadd; 16, attribute; 17, identifier:member; 18, identifier:score; 19, identifier:self; 20, identifier:client; 21, identifier:self; 22, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 11, 12; 11, 13; 12, 14; 12, 15; 13, 16; 13, 17; 13, 18; 14, 19; 14, 20; 16, 21; 16, 22
def add(self, member, score): """Add the specified member to the sorted set, or update the score if it already exist.""" return self.client.zadd(self.name, member, score)
0, module; 1, function_definition; 2, function_name:deserialize; 3, parameters; 4, block; 5, identifier:cls; 6, identifier:value; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, comment:""" Generates a Peer instance via a JSON string of the sort generated by `Peer.deserialize`. The `name` and `ip` keys are required to be present in the JSON map, if the `port` key is not present the default is used. """; 14, assignment; 15, comparison_operator:"name" not in parsed; 16, block; 17, comparison_operator:"ip" not in parsed; 18, block; 19, comparison_operator:"port" not in parsed; 20, block; 21, call; 22, identifier:parsed; 23, call; 24, string:"name"; 25, identifier:parsed; 26, raise_statement; 27, string:"ip"; 28, identifier:parsed; 29, raise_statement; 30, string:"port"; 31, identifier:parsed; 32, expression_statement; 33, identifier:cls; 34, argument_list; 35, attribute; 36, argument_list; 37, call; 38, call; 39, assignment; 40, subscript; 41, subscript; 42, subscript; 43, identifier:json; 44, identifier:loads; 45, identifier:value; 46, identifier:ValueError; 47, argument_list; 48, identifier:ValueError; 49, argument_list; 50, subscript; 51, identifier:DEFAULT_PEER_PORT; 52, identifier:parsed; 53, string:"name"; 54, identifier:parsed; 55, string:"ip"; 56, identifier:parsed; 57, string:"port"; 58, string:"No peer name."; 59, string:"No peer IP."; 60, identifier:parsed; 61, string:"port"
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; 9, 15; 9, 16; 10, 17; 10, 18; 11, 19; 11, 20; 12, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 17, 27; 17, 28; 18, 29; 19, 30; 19, 31; 20, 32; 21, 33; 21, 34; 23, 35; 23, 36; 26, 37; 29, 38; 32, 39; 34, 40; 34, 41; 34, 42; 35, 43; 35, 44; 36, 45; 37, 46; 37, 47; 38, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 41, 54; 41, 55; 42, 56; 42, 57; 47, 58; 49, 59; 50, 60; 50, 61
def deserialize(cls, value): """ Generates a Peer instance via a JSON string of the sort generated by `Peer.deserialize`. The `name` and `ip` keys are required to be present in the JSON map, if the `port` key is not present the default is used. """ parsed = json.loads(value) if "name" not in parsed: raise ValueError("No peer name.") if "ip" not in parsed: raise ValueError("No peer IP.") if "port" not in parsed: parsed["port"] = DEFAULT_PEER_PORT return cls(parsed["name"], parsed["ip"], parsed["port"])
0, module; 1, function_definition; 2, function_name:apply_config; 3, parameters; 4, block; 5, identifier:self; 6, identifier:config; 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, comment:""" Takes a given validated config dictionary and sets an instance attribute for each one. For check definitions, a Check instance is is created and a `checks` attribute set to a dictionary keyed off of the checks' names. If the Check instance has some sort of error while being created an error is logged and the check skipped. """; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, call; 21, assignment; 22, call; 23, attribute; 24, call; 25, attribute; 26, call; 27, attribute; 28, subscript; 29, attribute; 30, call; 31, attribute; 32, argument_list; 33, attribute; 34, subscript; 35, attribute; 36, argument_list; 37, identifier:self; 38, identifier:host; 39, attribute; 40, argument_list; 41, identifier:self; 42, identifier:configured_ports; 43, attribute; 44, argument_list; 45, identifier:self; 46, identifier:discovery; 47, identifier:config; 48, string:"discovery"; 49, identifier:self; 50, identifier:metadata; 51, attribute; 52, argument_list; 53, identifier:self; 54, identifier:update_ports; 55, identifier:self; 56, identifier:check_interval; 57, subscript; 58, string:"interval"; 59, identifier:self; 60, identifier:update_checks; 61, subscript; 62, identifier:config; 63, identifier:get; 64, string:"host"; 65, string:"127.0.0.1"; 66, identifier:config; 67, identifier:get; 68, string:"ports"; 69, list; 70, identifier:config; 71, identifier:get; 72, string:"metadata"; 73, dictionary; 74, identifier:config; 75, string:"checks"; 76, identifier:config; 77, string:"checks"; 78, call; 79, attribute; 80, argument_list; 81, identifier:config; 82, identifier:get; 83, string:"port"
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 7, 15; 8, 16; 9, 17; 10, 18; 11, 19; 12, 20; 13, 21; 14, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 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; 29, 49; 29, 50; 30, 51; 30, 52; 31, 53; 31, 54; 33, 55; 33, 56; 34, 57; 34, 58; 35, 59; 35, 60; 36, 61; 39, 62; 39, 63; 40, 64; 40, 65; 43, 66; 43, 67; 44, 68; 44, 69; 51, 70; 51, 71; 52, 72; 52, 73; 57, 74; 57, 75; 61, 76; 61, 77; 69, 78; 78, 79; 78, 80; 79, 81; 79, 82; 80, 83
def apply_config(self, config): """ Takes a given validated config dictionary and sets an instance attribute for each one. For check definitions, a Check instance is is created and a `checks` attribute set to a dictionary keyed off of the checks' names. If the Check instance has some sort of error while being created an error is logged and the check skipped. """ self.host = config.get("host", "127.0.0.1") self.configured_ports = config.get("ports", [config.get("port")]) self.discovery = config["discovery"] self.metadata = config.get("metadata", {}) self.update_ports() self.check_interval = config["checks"]["interval"] self.update_checks(config["checks"])
0, module; 1, function_definition; 2, function_name:get_key; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, return_statement; 10, identifier:key; 11, None; 12, identifier:keyfile; 13, None; 14, comment:""" returns a key given either its value, a path to it on the filesystem or as last resort it checks the environment variable CRYPTOYAML_SECRET """; 15, comparison_operator:key is None; 16, block; 17, identifier:key; 18, identifier:key; 19, None; 20, if_statement; 21, comparison_operator:keyfile is None; 22, block; 23, else_clause; 24, identifier:keyfile; 25, None; 26, expression_statement; 27, if_statement; 28, block; 29, assignment; 30, comparison_operator:key is None; 31, block; 32, else_clause; 33, expression_statement; 34, identifier:key; 35, call; 36, identifier:key; 37, None; 38, raise_statement; 39, block; 40, assignment; 41, attribute; 42, argument_list; 43, call; 44, expression_statement; 45, identifier:key; 46, call; 47, identifier:environ; 48, identifier:get; 49, string; 50, identifier:MissingKeyException; 51, argument_list; 52, assignment; 53, attribute; 54, argument_list; 55, string_content:CRYPTOYAML_SECRET; 56, concatenated_string; 57, identifier:key; 58, call; 59, call; 60, identifier:read; 61, string; 62, string; 63, string; 64, attribute; 65, argument_list; 66, identifier:open; 67, argument_list; 68, string_content:You must either provide a key value,; 69, string_content:a path to a key or its value via the environment variable; 70, string_content:CRYPTOYAML_SECRET; 71, identifier:key; 72, identifier:encode; 73, string; 74, identifier:keyfile; 75, string; 76, string_content:utf-8; 77, string_content:rb
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 5, 10; 5, 11; 6, 12; 6, 13; 7, 14; 8, 15; 8, 16; 9, 17; 15, 18; 15, 19; 16, 20; 20, 21; 20, 22; 20, 23; 21, 24; 21, 25; 22, 26; 22, 27; 23, 28; 26, 29; 27, 30; 27, 31; 27, 32; 28, 33; 29, 34; 29, 35; 30, 36; 30, 37; 31, 38; 32, 39; 33, 40; 35, 41; 35, 42; 38, 43; 39, 44; 40, 45; 40, 46; 41, 47; 41, 48; 42, 49; 43, 50; 43, 51; 44, 52; 46, 53; 46, 54; 49, 55; 51, 56; 52, 57; 52, 58; 53, 59; 53, 60; 56, 61; 56, 62; 56, 63; 58, 64; 58, 65; 59, 66; 59, 67; 61, 68; 62, 69; 63, 70; 64, 71; 64, 72; 65, 73; 67, 74; 67, 75; 73, 76; 75, 77
def get_key(key=None, keyfile=None): """ returns a key given either its value, a path to it on the filesystem or as last resort it checks the environment variable CRYPTOYAML_SECRET """ if key is None: if keyfile is None: key = environ.get('CRYPTOYAML_SECRET') if key is None: raise MissingKeyException( '''You must either provide a key value,''' ''' a path to a key or its value via the environment variable ''' ''' CRYPTOYAML_SECRET''' ) else: key = key.encode('utf-8') else: key = open(keyfile, 'rb').read() return key
0, module; 1, function_definition; 2, function_name:getList; 3, parameters; 4, block; 5, identifier:self; 6, identifier:full_path; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, identifier:type; 20, integer:1; 21, identifier:dept; 22, integer:0; 23, identifier:sort; 24, string; 25, identifier:order; 26, string; 27, identifier:startnum; 28, integer:0; 29, identifier:pagingrow; 30, integer:1000; 31, identifier:dummy; 32, integer:56184; 33, comment:"""Get a list of files >>> nd_list = nd.getList('/', type=3) >>> print nd_list There are 5 kinds of ``type``: - 1 => only directories with idxfolder property - 2 => only files - 3 => directories and files with thumbnail info (like viewHeight, viewWidth for Image file) - 4 => only directories except idxfolder - 5 => directories and files without thumbnail info There are 5 kindes of ``sort``: - file : file type, 종류 - length : size of file, 크기 - date : edited date, 수정한 날짜 - credate : creation date, 올린 날짜 - protect : protect or not, 중요 표시 :param full_path: The full path to get the file list. :param type: 1, 2, 3, 4 or 5 :param depth: Dept for file list :param sort: name => 이름 :param order: Order by (asc, desc) :return: metadata (list of dict) or False when failed to get list :metadata: - u'copyright': u'N', - u'creationdate': u'2013-05-12T21:17:23+09:00', - u'filelink': None, - u'fileuploadstatus': u'1', - u'getcontentlength': 0, - u'getlastmodified': u'2014-01-26T12:23:07+09:00', - u'href': u'/Codes/', - u'lastaccessed': u'2013-05-12T21:17:23+09:00', - u'lastmodifieduser': None, - u'priority': u'1', - u'protect': u'N', - u'resourceno': 204041859, - u'resourcetype': u'collection', - u'sharedinfo': u'F', - u'sharemsgcnt': 0, - u'shareno': 0, - u'subfoldercnt': 5, - u'thumbnailpath': u'N', - u'virusstatus': u'N' """; 34, comparison_operator:type not in range(1, 6); 35, block; 36, assignment; 37, assignment; 38, comparison_operator:s is True; 39, block; 40, else_clause; 41, string_content:name; 42, string_content:asc; 43, identifier:type; 44, call; 45, print_statement; 46, return_statement; 47, identifier:data; 48, dictionary; 49, pattern_list; 50, call; 51, identifier:s; 52, True; 53, return_statement; 54, block; 55, identifier:range; 56, argument_list; 57, string:"Error getList: `type` should be between 1 to 5"; 58, False; 59, pair; 60, pair; 61, pair; 62, pair; 63, pair; 64, pair; 65, pair; 66, pair; 67, pair; 68, pair; 69, identifier:s; 70, identifier:metadata; 71, attribute; 72, argument_list; 73, identifier:metadata; 74, print_statement; 75, return_statement; 76, integer:1; 77, integer:6; 78, string; 79, identifier:full_path; 80, string; 81, identifier:type; 82, string; 83, identifier:dept; 84, string; 85, identifier:sort; 86, string; 87, identifier:order; 88, string; 89, identifier:startnum; 90, string; 91, identifier:pagingrow; 92, string; 93, attribute; 94, string; 95, attribute; 96, string; 97, identifier:dummy; 98, identifier:self; 99, identifier:POST; 100, string; 101, identifier:data; 102, identifier:metadata; 103, False; 104, string_content:orgresource; 105, string_content:type; 106, string_content:dept; 107, string_content:sort; 108, string_content:order; 109, string_content:startnum; 110, string_content:pagingrow; 111, string_content:userid; 112, identifier:self; 113, identifier:user_id; 114, string_content:useridx; 115, identifier:self; 116, identifier:useridx; 117, string_content:dummy; 118, string_content:getList
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 7, 19; 7, 20; 8, 21; 8, 22; 9, 23; 9, 24; 10, 25; 10, 26; 11, 27; 11, 28; 12, 29; 12, 30; 13, 31; 13, 32; 14, 33; 15, 34; 15, 35; 16, 36; 17, 37; 18, 38; 18, 39; 18, 40; 24, 41; 26, 42; 34, 43; 34, 44; 35, 45; 35, 46; 36, 47; 36, 48; 37, 49; 37, 50; 38, 51; 38, 52; 39, 53; 40, 54; 44, 55; 44, 56; 45, 57; 46, 58; 48, 59; 48, 60; 48, 61; 48, 62; 48, 63; 48, 64; 48, 65; 48, 66; 48, 67; 48, 68; 49, 69; 49, 70; 50, 71; 50, 72; 53, 73; 54, 74; 54, 75; 56, 76; 56, 77; 59, 78; 59, 79; 60, 80; 60, 81; 61, 82; 61, 83; 62, 84; 62, 85; 63, 86; 63, 87; 64, 88; 64, 89; 65, 90; 65, 91; 66, 92; 66, 93; 67, 94; 67, 95; 68, 96; 68, 97; 71, 98; 71, 99; 72, 100; 72, 101; 74, 102; 75, 103; 78, 104; 80, 105; 82, 106; 84, 107; 86, 108; 88, 109; 90, 110; 92, 111; 93, 112; 93, 113; 94, 114; 95, 115; 95, 116; 96, 117; 100, 118
def getList(self, full_path, type = 1, dept = 0, sort = 'name', order = 'asc', startnum = 0, pagingrow = 1000, dummy = 56184): """Get a list of files >>> nd_list = nd.getList('/', type=3) >>> print nd_list There are 5 kinds of ``type``: - 1 => only directories with idxfolder property - 2 => only files - 3 => directories and files with thumbnail info (like viewHeight, viewWidth for Image file) - 4 => only directories except idxfolder - 5 => directories and files without thumbnail info There are 5 kindes of ``sort``: - file : file type, 종류 - length : size of file, 크기 - date : edited date, 수정한 날짜 - credate : creation date, 올린 날짜 - protect : protect or not, 중요 표시 :param full_path: The full path to get the file list. :param type: 1, 2, 3, 4 or 5 :param depth: Dept for file list :param sort: name => 이름 :param order: Order by (asc, desc) :return: metadata (list of dict) or False when failed to get list :metadata: - u'copyright': u'N', - u'creationdate': u'2013-05-12T21:17:23+09:00', - u'filelink': None, - u'fileuploadstatus': u'1', - u'getcontentlength': 0, - u'getlastmodified': u'2014-01-26T12:23:07+09:00', - u'href': u'/Codes/', - u'lastaccessed': u'2013-05-12T21:17:23+09:00', - u'lastmodifieduser': None, - u'priority': u'1', - u'protect': u'N', - u'resourceno': 204041859, - u'resourcetype': u'collection', - u'sharedinfo': u'F', - u'sharemsgcnt': 0, - u'shareno': 0, - u'subfoldercnt': 5, - u'thumbnailpath': u'N', - u'virusstatus': u'N' """ if type not in range(1, 6): print "Error getList: `type` should be between 1 to 5" return False data = {'orgresource': full_path, 'type': type, 'dept': dept, 'sort': sort, 'order': order, 'startnum': startnum, 'pagingrow': pagingrow, 'userid': self.user_id, 'useridx': self.useridx, 'dummy': dummy, } s, metadata = self.POST('getList', data) if s is True: return metadata else: print metadata return False
0, module; 1, function_definition; 2, function_name:list_assignment_groups; 3, parameters; 4, block; 5, identifier:self; 6, identifier:course_id; 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, comment:# REQUIRED - PATH - course_id; 17, expression_statement; 18, expression_statement; 19, comment:# OPTIONAL - include; 20, expression_statement; 21, if_statement; 22, comment:# OPTIONAL - exclude_assignment_submission_types; 23, expression_statement; 24, if_statement; 25, comment:# OPTIONAL - override_assignment_dates; 26, expression_statement; 27, if_statement; 28, comment:# OPTIONAL - grading_period_id; 29, expression_statement; 30, if_statement; 31, comment:# OPTIONAL - scope_assignments_to_student; 32, expression_statement; 33, if_statement; 34, expression_statement; 35, return_statement; 36, identifier:exclude_assignment_submission_types; 37, None; 38, identifier:grading_period_id; 39, None; 40, identifier:include; 41, None; 42, identifier:override_assignment_dates; 43, None; 44, identifier:scope_assignments_to_student; 45, None; 46, comment:""" List assignment groups. Returns the list of assignment groups for the current context. The returned groups are sorted by their position field. """; 47, assignment; 48, assignment; 49, assignment; 50, comment:"""ID"""; 51, assignment; 52, comment:"""Associations to include with the group. "discussion_topic", "all_dates" "assignment_visibility" & "submission" are only valid are only valid if "assignments" is also included. The "assignment_visibility" option additionally requires that the Differentiated Assignments course feature be turned on."""; 53, comparison_operator:include is not None; 54, block; 55, comment:"""If "assignments" are included, those with the specified submission types will be excluded from the assignment groups."""; 56, comparison_operator:exclude_assignment_submission_types is not None; 57, block; 58, comment:"""Apply assignment overrides for each assignment, defaults to true."""; 59, comparison_operator:override_assignment_dates is not None; 60, block; 61, comment:"""The id of the grading period in which assignment groups are being requested (Requires the Multiple Grading Periods feature turned on.)"""; 62, comparison_operator:grading_period_id is not None; 63, block; 64, comment:"""If true, all assignments returned will apply to the current user in the specified grading period. If assignments apply to other students in the specified grading period, but not the current user, they will not be returned. (Requires the grading_period_id argument and the Multiple Grading Periods feature turned on. In addition, the current user must be a student.)"""; 65, comparison_operator:scope_assignments_to_student is not None; 66, block; 67, call; 68, call; 69, identifier:path; 70, dictionary; 71, identifier:data; 72, dictionary; 73, identifier:params; 74, dictionary; 75, subscript; 76, identifier:course_id; 77, identifier:include; 78, None; 79, expression_statement; 80, expression_statement; 81, identifier:exclude_assignment_submission_types; 82, None; 83, expression_statement; 84, expression_statement; 85, identifier:override_assignment_dates; 86, None; 87, expression_statement; 88, identifier:grading_period_id; 89, None; 90, expression_statement; 91, identifier:scope_assignments_to_student; 92, None; 93, expression_statement; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, identifier:path; 99, string:"course_id"; 100, call; 101, assignment; 102, call; 103, assignment; 104, assignment; 105, assignment; 106, assignment; 107, attribute; 108, identifier:debug; 109, call; 110, identifier:self; 111, identifier:generic_request; 112, string:"GET"; 113, call; 114, keyword_argument; 115, keyword_argument; 116, keyword_argument; 117, attribute; 118, argument_list; 119, subscript; 120, identifier:include; 121, attribute; 122, argument_list; 123, subscript; 124, identifier:exclude_assignment_submission_types; 125, subscript; 126, identifier:override_assignment_dates; 127, subscript; 128, identifier:grading_period_id; 129, subscript; 130, identifier:scope_assignments_to_student; 131, identifier:self; 132, identifier:logger; 133, attribute; 134, argument_list; 135, attribute; 136, argument_list; 137, identifier:data; 138, identifier:data; 139, identifier:params; 140, identifier:params; 141, identifier:all_pages; 142, True; 143, identifier:self; 144, identifier:_validate_enum; 145, identifier:include; 146, list; 147, identifier:params; 148, string:"include"; 149, identifier:self; 150, identifier:_validate_enum; 151, identifier:exclude_assignment_submission_types; 152, list; 153, identifier:params; 154, string:"exclude_assignment_submission_types"; 155, identifier:params; 156, string:"override_assignment_dates"; 157, identifier:params; 158, string:"grading_period_id"; 159, identifier:params; 160, string:"scope_assignments_to_student"; 161, string:"GET /api/v1/courses/{course_id}/assignment_groups with query params: {params} and form data: {data}"; 162, identifier:format; 163, keyword_argument; 164, keyword_argument; 165, dictionary_splat; 166, string:"/api/v1/courses/{course_id}/assignment_groups"; 167, identifier:format; 168, dictionary_splat; 169, string:"assignments"; 170, string:"discussion_topic"; 171, string:"all_dates"; 172, string:"assignment_visibility"; 173, string:"overrides"; 174, string:"submission"; 175, string:"online_quiz"; 176, string:"discussion_topic"; 177, string:"wiki_page"; 178, string:"external_tool"; 179, identifier:params; 180, identifier:params; 181, identifier:data; 182, identifier:data; 183, identifier:path; 184, identifier:path
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 4, 34; 4, 35; 7, 36; 7, 37; 8, 38; 8, 39; 9, 40; 9, 41; 10, 42; 10, 43; 11, 44; 11, 45; 12, 46; 13, 47; 14, 48; 15, 49; 17, 50; 18, 51; 20, 52; 21, 53; 21, 54; 23, 55; 24, 56; 24, 57; 26, 58; 27, 59; 27, 60; 29, 61; 30, 62; 30, 63; 32, 64; 33, 65; 33, 66; 34, 67; 35, 68; 47, 69; 47, 70; 48, 71; 48, 72; 49, 73; 49, 74; 51, 75; 51, 76; 53, 77; 53, 78; 54, 79; 54, 80; 56, 81; 56, 82; 57, 83; 57, 84; 59, 85; 59, 86; 60, 87; 62, 88; 62, 89; 63, 90; 65, 91; 65, 92; 66, 93; 67, 94; 67, 95; 68, 96; 68, 97; 75, 98; 75, 99; 79, 100; 80, 101; 83, 102; 84, 103; 87, 104; 90, 105; 93, 106; 94, 107; 94, 108; 95, 109; 96, 110; 96, 111; 97, 112; 97, 113; 97, 114; 97, 115; 97, 116; 100, 117; 100, 118; 101, 119; 101, 120; 102, 121; 102, 122; 103, 123; 103, 124; 104, 125; 104, 126; 105, 127; 105, 128; 106, 129; 106, 130; 107, 131; 107, 132; 109, 133; 109, 134; 113, 135; 113, 136; 114, 137; 114, 138; 115, 139; 115, 140; 116, 141; 116, 142; 117, 143; 117, 144; 118, 145; 118, 146; 119, 147; 119, 148; 121, 149; 121, 150; 122, 151; 122, 152; 123, 153; 123, 154; 125, 155; 125, 156; 127, 157; 127, 158; 129, 159; 129, 160; 133, 161; 133, 162; 134, 163; 134, 164; 134, 165; 135, 166; 135, 167; 136, 168; 146, 169; 146, 170; 146, 171; 146, 172; 146, 173; 146, 174; 152, 175; 152, 176; 152, 177; 152, 178; 163, 179; 163, 180; 164, 181; 164, 182; 165, 183; 168, 184
def list_assignment_groups(self, course_id, exclude_assignment_submission_types=None, grading_period_id=None, include=None, override_assignment_dates=None, scope_assignments_to_student=None): """ List assignment groups. Returns the list of assignment groups for the current context. The returned groups are sorted by their position field. """ path = {} data = {} params = {} # REQUIRED - PATH - course_id """ID""" path["course_id"] = course_id # OPTIONAL - include """Associations to include with the group. "discussion_topic", "all_dates" "assignment_visibility" & "submission" are only valid are only valid if "assignments" is also included. The "assignment_visibility" option additionally requires that the Differentiated Assignments course feature be turned on.""" if include is not None: self._validate_enum(include, ["assignments", "discussion_topic", "all_dates", "assignment_visibility", "overrides", "submission"]) params["include"] = include # OPTIONAL - exclude_assignment_submission_types """If "assignments" are included, those with the specified submission types will be excluded from the assignment groups.""" if exclude_assignment_submission_types is not None: self._validate_enum(exclude_assignment_submission_types, ["online_quiz", "discussion_topic", "wiki_page", "external_tool"]) params["exclude_assignment_submission_types"] = exclude_assignment_submission_types # OPTIONAL - override_assignment_dates """Apply assignment overrides for each assignment, defaults to true.""" if override_assignment_dates is not None: params["override_assignment_dates"] = override_assignment_dates # OPTIONAL - grading_period_id """The id of the grading period in which assignment groups are being requested (Requires the Multiple Grading Periods feature turned on.)""" if grading_period_id is not None: params["grading_period_id"] = grading_period_id # OPTIONAL - scope_assignments_to_student """If true, all assignments returned will apply to the current user in the specified grading period. If assignments apply to other students in the specified grading period, but not the current user, they will not be returned. (Requires the grading_period_id argument and the Multiple Grading Periods feature turned on. In addition, the current user must be a student.)""" if scope_assignments_to_student is not None: params["scope_assignments_to_student"] = scope_assignments_to_student self.logger.debug("GET /api/v1/courses/{course_id}/assignment_groups with query params: {params} and form data: {data}".format(params=params, data=data, **path)) return self.generic_request("GET", "/api/v1/courses/{course_id}/assignment_groups".format(**path), data=data, params=params, all_pages=True)
0, module; 1, function_definition; 2, function_name:_sorted_keys; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, try_statement; 8, return_statement; 9, comment:""" Return list of keys sorted by version Sorting is done based on :py:func:`pkg_resources.parse_version` """; 10, block; 11, except_clause; 12, identifier:keys; 13, expression_statement; 14, identifier:KeyError; 15, block; 16, assignment; 17, expression_statement; 18, identifier:keys; 19, subscript; 20, assignment; 21, attribute; 22, string; 23, identifier:keys; 24, assignment; 25, identifier:self; 26, identifier:_cache; 27, string_content:sorted_keys; 28, subscript; 29, call; 30, attribute; 31, string; 32, identifier:sorted; 33, argument_list; 34, identifier:self; 35, identifier:_cache; 36, string_content:sorted_keys; 37, call; 38, keyword_argument; 39, attribute; 40, argument_list; 41, identifier:key; 42, identifier:parse_version; 43, identifier:self; 44, identifier:keys
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 7, 11; 8, 12; 10, 13; 11, 14; 11, 15; 13, 16; 15, 17; 16, 18; 16, 19; 17, 20; 19, 21; 19, 22; 20, 23; 20, 24; 21, 25; 21, 26; 22, 27; 24, 28; 24, 29; 28, 30; 28, 31; 29, 32; 29, 33; 30, 34; 30, 35; 31, 36; 33, 37; 33, 38; 37, 39; 37, 40; 38, 41; 38, 42; 39, 43; 39, 44
def _sorted_keys(self): """ Return list of keys sorted by version Sorting is done based on :py:func:`pkg_resources.parse_version` """ try: keys = self._cache['sorted_keys'] except KeyError: keys = self._cache['sorted_keys'] = sorted(self.keys(), key=parse_version) return keys
0, module; 1, function_definition; 2, function_name:query; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, comment:# Use shards parameter only if there are several cores active; 16, if_statement; 17, comment:# Prepare filters; 18, if_statement; 19, comment:# Append sorting parameters; 20, if_statement; 21, comment:# Do request to Solr server to default endpoint (other cores will be queried with shard functionality); 22, assert_statement; 23, expression_statement; 24, expression_statement; 25, if_statement; 26, assert_statement; 27, comment:# Check for response status; 28, if_statement; 29, assert_statement; 30, expression_statement; 31, return_statement; 32, identifier:filters; 33, None; 34, identifier:columns; 35, None; 36, identifier:sort; 37, None; 38, identifier:start; 39, integer:0; 40, identifier:rows; 41, integer:30; 42, comment:""" Queries Solr and returns results query - Text query to search for filters - dictionary of filters to apply when searching in form of { "field":"filter_value" } columns - columns to return, list of strings sort - list of fields to sort on in format of ["field asc", "field desc", ... ] start - start number of first result (used in pagination) rows - number of rows to return (used for pagination, defaults to 30) """; 43, not_operator; 44, block; 45, assignment; 46, comparison_operator:len(self.endpoints) > 1; 47, block; 48, not_operator; 49, block; 50, not_operator; 51, block; 52, comparison_operator:self.default_endpoint in self.endpoints; 53, assignment; 54, assignment; 55, not_operator; 56, block; 57, comparison_operator:"responseHeader" in results; 58, not_operator; 59, block; 60, comparison_operator:"response" in results; 61, assignment; 62, identifier:result_obj; 63, identifier:columns; 64, expression_statement; 65, identifier:fields; 66, dictionary; 67, call; 68, integer:1; 69, expression_statement; 70, comparison_operator:filters is None; 71, expression_statement; 72, for_statement; 73, expression_statement; 74, comparison_operator:sort is None; 75, expression_statement; 76, attribute; 77, attribute; 78, identifier:request_url; 79, call; 80, identifier:results; 81, call; 82, identifier:results; 83, return_statement; 84, string:"responseHeader"; 85, identifier:results; 86, comparison_operator:results.get("responseHeader").get("status") == 0; 87, expression_statement; 88, return_statement; 89, string:"response"; 90, identifier:results; 91, identifier:result_obj; 92, call; 93, assignment; 94, pair; 95, pair; 96, comment:# Return facets as JSON objects; 97, pair; 98, comment:# Return score along with results; 99, pair; 100, pair; 101, pair; 102, identifier:len; 103, argument_list; 104, assignment; 105, identifier:filters; 106, None; 107, assignment; 108, pattern_list; 109, call; 110, block; 111, assignment; 112, identifier:sort; 113, None; 114, assignment; 115, identifier:self; 116, identifier:default_endpoint; 117, identifier:self; 118, identifier:endpoints; 119, identifier:_get_url; 120, argument_list; 121, attribute; 122, argument_list; 123, None; 124, call; 125, integer:0; 126, call; 127, None; 128, attribute; 129, argument_list; 130, identifier:columns; 131, list; 132, string:"q"; 133, identifier:query; 134, string:"json.nl"; 135, string:"map"; 136, string:"fl"; 137, call; 138, string:"start"; 139, call; 140, string:"rows"; 141, call; 142, string:"wt"; 143, string:"json"; 144, attribute; 145, subscript; 146, call; 147, identifier:filter_list; 148, list; 149, identifier:filter_field; 150, identifier:value; 151, attribute; 152, argument_list; 153, expression_statement; 154, subscript; 155, call; 156, subscript; 157, call; 158, subscript; 159, string:"select"; 160, identifier:self; 161, identifier:_send_solr_query; 162, identifier:request_url; 163, identifier:fields; 164, attribute; 165, argument_list; 166, attribute; 167, argument_list; 168, identifier:self; 169, identifier:_parse_response; 170, identifier:results; 171, string:"*"; 172, string:"score"; 173, attribute; 174, argument_list; 175, identifier:str; 176, argument_list; 177, identifier:str; 178, argument_list; 179, identifier:self; 180, identifier:endpoints; 181, identifier:fields; 182, string:"shards"; 183, attribute; 184, argument_list; 185, identifier:filters; 186, identifier:items; 187, call; 188, identifier:fields; 189, string:"fq"; 190, attribute; 191, argument_list; 192, identifier:fields; 193, string:"sort"; 194, attribute; 195, argument_list; 196, attribute; 197, attribute; 198, call; 199, identifier:get; 200, string:"status"; 201, identifier:logger; 202, identifier:error; 203, string:"Server error while retrieving results: %s"; 204, identifier:results; 205, string:","; 206, identifier:join; 207, identifier:columns; 208, identifier:start; 209, identifier:rows; 210, identifier:self; 211, identifier:_get_shards; 212, attribute; 213, argument_list; 214, string:" AND "; 215, identifier:join; 216, identifier:filter_list; 217, string:","; 218, identifier:join; 219, identifier:sort; 220, identifier:self; 221, identifier:endpoints; 222, identifier:self; 223, identifier:default_endpoint; 224, attribute; 225, argument_list; 226, identifier:filter_list; 227, identifier:append; 228, binary_operator:"%s:%s" % (filter_field, value); 229, identifier:results; 230, identifier:get; 231, string:"responseHeader"; 232, string:"%s:%s"; 233, tuple; 234, identifier:filter_field; 235, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 7, 32; 7, 33; 8, 34; 8, 35; 9, 36; 9, 37; 10, 38; 10, 39; 11, 40; 11, 41; 12, 42; 13, 43; 13, 44; 14, 45; 16, 46; 16, 47; 18, 48; 18, 49; 20, 50; 20, 51; 22, 52; 23, 53; 24, 54; 25, 55; 25, 56; 26, 57; 28, 58; 28, 59; 29, 60; 30, 61; 31, 62; 43, 63; 44, 64; 45, 65; 45, 66; 46, 67; 46, 68; 47, 69; 48, 70; 49, 71; 49, 72; 49, 73; 50, 74; 51, 75; 52, 76; 52, 77; 53, 78; 53, 79; 54, 80; 54, 81; 55, 82; 56, 83; 57, 84; 57, 85; 58, 86; 59, 87; 59, 88; 60, 89; 60, 90; 61, 91; 61, 92; 64, 93; 66, 94; 66, 95; 66, 96; 66, 97; 66, 98; 66, 99; 66, 100; 66, 101; 67, 102; 67, 103; 69, 104; 70, 105; 70, 106; 71, 107; 72, 108; 72, 109; 72, 110; 73, 111; 74, 112; 74, 113; 75, 114; 76, 115; 76, 116; 77, 117; 77, 118; 79, 119; 79, 120; 81, 121; 81, 122; 83, 123; 86, 124; 86, 125; 87, 126; 88, 127; 92, 128; 92, 129; 93, 130; 93, 131; 94, 132; 94, 133; 95, 134; 95, 135; 97, 136; 97, 137; 99, 138; 99, 139; 100, 140; 100, 141; 101, 142; 101, 143; 103, 144; 104, 145; 104, 146; 107, 147; 107, 148; 108, 149; 108, 150; 109, 151; 109, 152; 110, 153; 111, 154; 111, 155; 114, 156; 114, 157; 120, 158; 120, 159; 121, 160; 121, 161; 122, 162; 122, 163; 124, 164; 124, 165; 126, 166; 126, 167; 128, 168; 128, 169; 129, 170; 131, 171; 131, 172; 137, 173; 137, 174; 139, 175; 139, 176; 141, 177; 141, 178; 144, 179; 144, 180; 145, 181; 145, 182; 146, 183; 146, 184; 151, 185; 151, 186; 153, 187; 154, 188; 154, 189; 155, 190; 155, 191; 156, 192; 156, 193; 157, 194; 157, 195; 158, 196; 158, 197; 164, 198; 164, 199; 165, 200; 166, 201; 166, 202; 167, 203; 167, 204; 173, 205; 173, 206; 174, 207; 176, 208; 178, 209; 183, 210; 183, 211; 187, 212; 187, 213; 190, 214; 190, 215; 191, 216; 194, 217; 194, 218; 195, 219; 196, 220; 196, 221; 197, 222; 197, 223; 198, 224; 198, 225; 212, 226; 212, 227; 213, 228; 224, 229; 224, 230; 225, 231; 228, 232; 228, 233; 233, 234; 233, 235
def query(self, query, filters=None, columns=None, sort=None, start=0, rows=30): """ Queries Solr and returns results query - Text query to search for filters - dictionary of filters to apply when searching in form of { "field":"filter_value" } columns - columns to return, list of strings sort - list of fields to sort on in format of ["field asc", "field desc", ... ] start - start number of first result (used in pagination) rows - number of rows to return (used for pagination, defaults to 30) """ if not columns: columns = ["*", "score"] fields = {"q": query, "json.nl" :"map", # Return facets as JSON objects "fl": ",".join(columns), # Return score along with results "start": str(start), "rows": str(rows), "wt": "json"} # Use shards parameter only if there are several cores active if len(self.endpoints) > 1: fields["shards"] = self._get_shards() # Prepare filters if not filters is None: filter_list = [] for filter_field, value in filters.items(): filter_list.append("%s:%s" % (filter_field, value)) fields["fq"] = " AND ".join(filter_list) # Append sorting parameters if not sort is None: fields["sort"] = ",".join(sort) # Do request to Solr server to default endpoint (other cores will be queried with shard functionality) assert self.default_endpoint in self.endpoints request_url = _get_url(self.endpoints[self.default_endpoint], "select") results = self._send_solr_query(request_url, fields) if not results: return None assert "responseHeader" in results # Check for response status if not results.get("responseHeader").get("status") == 0: logger.error("Server error while retrieving results: %s", results) return None assert "response" in results result_obj = self._parse_response(results) return result_obj
0, module; 1, function_definition; 2, function_name:search_videohub; 3, parameters; 4, block; 5, identifier:cls; 6, identifier:query; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, comment:# construct url; 14, expression_statement; 15, comment:# construct auth headers; 16, expression_statement; 17, comment:# construct payload; 18, expression_statement; 19, if_statement; 20, if_statement; 21, if_statement; 22, if_statement; 23, if_statement; 24, comment:# send request; 25, expression_statement; 26, comment:# raise if not 200; 27, if_statement; 28, comment:# parse and return response; 29, return_statement; 30, identifier:filters; 31, None; 32, identifier:status; 33, None; 34, identifier:sort; 35, None; 36, identifier:size; 37, None; 38, identifier:page; 39, None; 40, comment:"""searches the videohub given a query and applies given filters and other bits :see: https://github.com/theonion/videohub/blob/master/docs/search/post.md :see: https://github.com/theonion/videohub/blob/master/docs/search/get.md :param query: query terms to search by :type query: str :example query: "brooklyn hipsters" # although, this is a little redundant... :param filters: video field value restrictions :type filters: dict :default filters: None :example filters: {"channel": "onion"} or {"series": "Today NOW"} :param status: limit the results to videos that are published, scheduled, draft :type status: str :default status: None :example status: "published" or "draft" or "scheduled" :param sort: video field related sorting :type sort: dict :default sort: None :example sort: {"title": "desc"} or {"description": "asc"} :param size: the page size (number of results) :type size: int :default size: None :example size": {"size": 20} :param page: the page number of the results :type page: int :default page: None :example page: {"page": 2} # note, you should use `size` in conjunction with `page` :return: a dictionary of results and meta information :rtype: dict """; 41, assignment; 42, assignment; 43, assignment; 44, identifier:filters; 45, block; 46, identifier:status; 47, block; 48, identifier:sort; 49, block; 50, identifier:size; 51, block; 52, identifier:page; 53, block; 54, assignment; 55, comparison_operator:res.status_code != 200; 56, block; 57, call; 58, identifier:url; 59, call; 60, identifier:headers; 61, dictionary; 62, identifier:payload; 63, dictionary; 64, assert_statement; 65, expression_statement; 66, assert_statement; 67, expression_statement; 68, expression_statement; 69, assert_statement; 70, expression_statement; 71, assert_statement; 72, expression_statement; 73, assert_statement; 74, expression_statement; 75, identifier:res; 76, call; 77, attribute; 78, integer:200; 79, expression_statement; 80, attribute; 81, argument_list; 82, identifier:getattr; 83, argument_list; 84, pair; 85, pair; 86, pair; 87, call; 88, assignment; 89, call; 90, call; 91, assignment; 92, call; 93, assignment; 94, call; 95, assignment; 96, call; 97, assignment; 98, attribute; 99, argument_list; 100, identifier:res; 101, identifier:status_code; 102, call; 103, identifier:json; 104, identifier:loads; 105, attribute; 106, identifier:settings; 107, string:"VIDEOHUB_API_SEARCH_URL"; 108, attribute; 109, string:"Content-Type"; 110, string:"application/json"; 111, string:"Authorization"; 112, attribute; 113, string:"query"; 114, identifier:query; 115, identifier:isinstance; 116, argument_list; 117, subscript; 118, identifier:filters; 119, identifier:isinstance; 120, argument_list; 121, attribute; 122, argument_list; 123, subscript; 124, identifier:status; 125, identifier:isinstance; 126, argument_list; 127, subscript; 128, identifier:sort; 129, identifier:isinstance; 130, argument_list; 131, subscript; 132, identifier:size; 133, identifier:isinstance; 134, argument_list; 135, subscript; 136, identifier:page; 137, identifier:requests; 138, identifier:post; 139, identifier:url; 140, keyword_argument; 141, keyword_argument; 142, attribute; 143, argument_list; 144, identifier:res; 145, identifier:content; 146, identifier:cls; 147, identifier:DEFAULT_VIDEOHUB_API_SEARCH_URL; 148, identifier:settings; 149, identifier:VIDEOHUB_API_TOKEN; 150, identifier:filters; 151, identifier:dict; 152, identifier:payload; 153, string:"filters"; 154, identifier:status; 155, attribute; 156, identifier:payload; 157, identifier:setdefault; 158, string:"filters"; 159, dictionary; 160, subscript; 161, string:"status"; 162, identifier:sort; 163, identifier:dict; 164, identifier:payload; 165, string:"sort"; 166, identifier:size; 167, tuple; 168, identifier:payload; 169, string:"size"; 170, identifier:page; 171, tuple; 172, identifier:payload; 173, string:"page"; 174, identifier:data; 175, call; 176, identifier:headers; 177, identifier:headers; 178, identifier:res; 179, identifier:raise_for_status; 180, identifier:six; 181, identifier:string_types; 182, identifier:payload; 183, string:"filters"; 184, attribute; 185, identifier:int; 186, attribute; 187, identifier:int; 188, attribute; 189, argument_list; 190, identifier:six; 191, identifier:string_types; 192, identifier:six; 193, identifier:string_types; 194, identifier:json; 195, identifier:dumps; 196, identifier:payload
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 7, 30; 7, 31; 8, 32; 8, 33; 9, 34; 9, 35; 10, 36; 10, 37; 11, 38; 11, 39; 12, 40; 14, 41; 16, 42; 18, 43; 19, 44; 19, 45; 20, 46; 20, 47; 21, 48; 21, 49; 22, 50; 22, 51; 23, 52; 23, 53; 25, 54; 27, 55; 27, 56; 29, 57; 41, 58; 41, 59; 42, 60; 42, 61; 43, 62; 43, 63; 45, 64; 45, 65; 47, 66; 47, 67; 47, 68; 49, 69; 49, 70; 51, 71; 51, 72; 53, 73; 53, 74; 54, 75; 54, 76; 55, 77; 55, 78; 56, 79; 57, 80; 57, 81; 59, 82; 59, 83; 61, 84; 61, 85; 63, 86; 64, 87; 65, 88; 66, 89; 67, 90; 68, 91; 69, 92; 70, 93; 71, 94; 72, 95; 73, 96; 74, 97; 76, 98; 76, 99; 77, 100; 77, 101; 79, 102; 80, 103; 80, 104; 81, 105; 83, 106; 83, 107; 83, 108; 84, 109; 84, 110; 85, 111; 85, 112; 86, 113; 86, 114; 87, 115; 87, 116; 88, 117; 88, 118; 89, 119; 89, 120; 90, 121; 90, 122; 91, 123; 91, 124; 92, 125; 92, 126; 93, 127; 93, 128; 94, 129; 94, 130; 95, 131; 95, 132; 96, 133; 96, 134; 97, 135; 97, 136; 98, 137; 98, 138; 99, 139; 99, 140; 99, 141; 102, 142; 102, 143; 105, 144; 105, 145; 108, 146; 108, 147; 112, 148; 112, 149; 116, 150; 116, 151; 117, 152; 117, 153; 120, 154; 120, 155; 121, 156; 121, 157; 122, 158; 122, 159; 123, 160; 123, 161; 126, 162; 126, 163; 127, 164; 127, 165; 130, 166; 130, 167; 131, 168; 131, 169; 134, 170; 134, 171; 135, 172; 135, 173; 140, 174; 140, 175; 141, 176; 141, 177; 142, 178; 142, 179; 155, 180; 155, 181; 160, 182; 160, 183; 167, 184; 167, 185; 171, 186; 171, 187; 175, 188; 175, 189; 184, 190; 184, 191; 186, 192; 186, 193; 188, 194; 188, 195; 189, 196
def search_videohub(cls, query, filters=None, status=None, sort=None, size=None, page=None): """searches the videohub given a query and applies given filters and other bits :see: https://github.com/theonion/videohub/blob/master/docs/search/post.md :see: https://github.com/theonion/videohub/blob/master/docs/search/get.md :param query: query terms to search by :type query: str :example query: "brooklyn hipsters" # although, this is a little redundant... :param filters: video field value restrictions :type filters: dict :default filters: None :example filters: {"channel": "onion"} or {"series": "Today NOW"} :param status: limit the results to videos that are published, scheduled, draft :type status: str :default status: None :example status: "published" or "draft" or "scheduled" :param sort: video field related sorting :type sort: dict :default sort: None :example sort: {"title": "desc"} or {"description": "asc"} :param size: the page size (number of results) :type size: int :default size: None :example size": {"size": 20} :param page: the page number of the results :type page: int :default page: None :example page: {"page": 2} # note, you should use `size` in conjunction with `page` :return: a dictionary of results and meta information :rtype: dict """ # construct url url = getattr(settings, "VIDEOHUB_API_SEARCH_URL", cls.DEFAULT_VIDEOHUB_API_SEARCH_URL) # construct auth headers headers = { "Content-Type": "application/json", "Authorization": settings.VIDEOHUB_API_TOKEN, } # construct payload payload = { "query": query, } if filters: assert isinstance(filters, dict) payload["filters"] = filters if status: assert isinstance(status, six.string_types) payload.setdefault("filters", {}) payload["filters"]["status"] = status if sort: assert isinstance(sort, dict) payload["sort"] = sort if size: assert isinstance(size, (six.string_types, int)) payload["size"] = size if page: assert isinstance(page, (six.string_types, int)) payload["page"] = page # send request res = requests.post(url, data=json.dumps(payload), headers=headers) # raise if not 200 if res.status_code != 200: res.raise_for_status() # parse and return response return json.loads(res.content)
0, module; 1, function_definition; 2, function_name:insert; 3, parameters; 4, block; 5, identifier:self; 6, identifier:key; 7, identifier:value; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:"""Insert a key-value pair in the list. The pair is inserted at the correct location so that the list remains sorted on *key*. If a pair with the same key is already in the list, then the pair is appended after all other pairs with that key. """; 13, call; 14, assignment; 15, call; 16, attribute; 17, argument_list; 18, identifier:node; 19, call; 20, attribute; 21, argument_list; 22, identifier:self; 23, identifier:_find_lte; 24, identifier:key; 25, attribute; 26, argument_list; 27, identifier:self; 28, identifier:_insert; 29, identifier:node; 30, identifier:self; 31, identifier:_create_node; 32, identifier:key; 33, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 8, 12; 9, 13; 10, 14; 11, 15; 13, 16; 13, 17; 14, 18; 14, 19; 15, 20; 15, 21; 16, 22; 16, 23; 17, 24; 19, 25; 19, 26; 20, 27; 20, 28; 21, 29; 25, 30; 25, 31; 26, 32; 26, 33
def insert(self, key, value): """Insert a key-value pair in the list. The pair is inserted at the correct location so that the list remains sorted on *key*. If a pair with the same key is already in the list, then the pair is appended after all other pairs with that key. """ self._find_lte(key) node = self._create_node(key, value) self._insert(node)
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, if_statement; 12, return_statement; 13, identifier:sorting; 14, identifier:kwargs; 15, comment:"""Sort resources."""; 16, assignment; 17, pattern_list; 18, identifier:sorting; 19, block; 20, identifier:sorting_; 21, block; 22, attribute; 23, identifier:sorting_; 24, list; 25, identifier:name; 26, identifier:desc; 27, expression_statement; 28, if_statement; 29, if_statement; 30, expression_statement; 31, return_statement; 32, identifier:self; 33, identifier:collection; 34, assignment; 35, comparison_operator:field is None; 36, block; 37, identifier:desc; 38, block; 39, call; 40, call; 41, identifier:field; 42, call; 43, identifier:field; 44, None; 45, continue_statement; 46, expression_statement; 47, attribute; 48, argument_list; 49, attribute; 50, argument_list; 51, attribute; 52, argument_list; 53, assignment; 54, identifier:sorting_; 55, identifier:append; 56, identifier:field; 57, attribute; 58, identifier:order_by; 59, list_splat; 60, attribute; 61, identifier:get; 62, identifier:name; 63, identifier:field; 64, call; 65, identifier:self; 66, identifier:collection; 67, identifier:sorting_; 68, attribute; 69, identifier:fields; 70, attribute; 71, argument_list; 72, attribute; 73, identifier:_meta; 74, identifier:field; 75, identifier:desc; 76, attribute; 77, identifier:model; 78, identifier:self; 79, identifier:meta
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 7, 14; 8, 15; 9, 16; 10, 17; 10, 18; 10, 19; 11, 20; 11, 21; 12, 22; 16, 23; 16, 24; 17, 25; 17, 26; 19, 27; 19, 28; 19, 29; 19, 30; 21, 31; 22, 32; 22, 33; 27, 34; 28, 35; 28, 36; 29, 37; 29, 38; 30, 39; 31, 40; 34, 41; 34, 42; 35, 43; 35, 44; 36, 45; 38, 46; 39, 47; 39, 48; 40, 49; 40, 50; 42, 51; 42, 52; 46, 53; 47, 54; 47, 55; 48, 56; 49, 57; 49, 58; 50, 59; 51, 60; 51, 61; 52, 62; 53, 63; 53, 64; 57, 65; 57, 66; 59, 67; 60, 68; 60, 69; 64, 70; 64, 71; 68, 72; 68, 73; 70, 74; 70, 75; 72, 76; 72, 77; 76, 78; 76, 79
def sort(self, *sorting, **kwargs): """Sort resources.""" sorting_ = [] for name, desc in sorting: field = self.meta.model._meta.fields.get(name) if field is None: continue if desc: field = field.desc() sorting_.append(field) if sorting_: return self.collection.order_by(*sorting_) return self.collection
0, module; 1, function_definition; 2, function_name:split; 3, parameters; 4, block; 5, identifier:self; 6, identifier:indices; 7, expression_statement; 8, return_statement; 9, comment:""" Splits logical networks according to given indices Parameters ---------- indices : list 1-D array of sorted integers, the entries indicate where the array is split Returns ------- list List of :class:`caspo.core.logicalnetwork.LogicalNetworkList` object instances .. seealso:: `numpy.split <http://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html#numpy-split>`_ """; 10, list_comprehension; 11, call; 12, for_in_clause; 13, identifier:LogicalNetworkList; 14, argument_list; 15, identifier:part; 16, call; 17, attribute; 18, identifier:part; 19, attribute; 20, argument_list; 21, identifier:self; 22, identifier:hg; 23, identifier:np; 24, identifier:split; 25, attribute; 26, identifier:indices; 27, identifier:self; 28, identifier:__matrix
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 11, 13; 11, 14; 12, 15; 12, 16; 14, 17; 14, 18; 16, 19; 16, 20; 17, 21; 17, 22; 19, 23; 19, 24; 20, 25; 20, 26; 25, 27; 25, 28
def split(self, indices): """ Splits logical networks according to given indices Parameters ---------- indices : list 1-D array of sorted integers, the entries indicate where the array is split Returns ------- list List of :class:`caspo.core.logicalnetwork.LogicalNetworkList` object instances .. seealso:: `numpy.split <http://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html#numpy-split>`_ """ return [LogicalNetworkList(self.hg, part) for part in np.split(self.__matrix, indices)]
0, module; 1, function_definition; 2, function_name:movies_box_office; 3, parameters; 4, block; 5, identifier:self; 6, dictionary_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:kwargs; 13, comment:"""Gets the top box office earning movies from the API. Sorted by most recent weekend gross ticket sales. Args: limit (optional): limits the number of movies returned, default=10 country (optional): localized data for selected country, default="us" Returns: A dict respresentation of the JSON returned from the API. """; 14, assignment; 15, assignment; 16, call; 17, identifier:response; 18, identifier:path; 19, call; 20, identifier:response; 21, call; 22, attribute; 23, argument_list; 24, attribute; 25, argument_list; 26, attribute; 27, argument_list; 28, identifier:self; 29, identifier:_set_attrs_to_values; 30, identifier:response; 31, identifier:self; 32, identifier:_get_path; 33, string; 34, identifier:self; 35, identifier:_GET; 36, identifier:path; 37, identifier:kwargs; 38, string_content:movies_box_office
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; 11, 17; 14, 18; 14, 19; 15, 20; 15, 21; 16, 22; 16, 23; 19, 24; 19, 25; 21, 26; 21, 27; 22, 28; 22, 29; 23, 30; 24, 31; 24, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 33, 38
def movies_box_office(self, **kwargs): """Gets the top box office earning movies from the API. Sorted by most recent weekend gross ticket sales. Args: limit (optional): limits the number of movies returned, default=10 country (optional): localized data for selected country, default="us" Returns: A dict respresentation of the JSON returned from the API. """ path = self._get_path('movies_box_office') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
0, module; 1, function_definition; 2, function_name:get_parents; 3, parameters; 4, block; 5, expression_statement; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, return_statement; 10, comment:"""Return sorted list of names of packages without dependants."""; 11, assignment; 12, assignment; 13, assignment; 14, call; 15, identifier:distributions; 16, call; 17, identifier:remaining; 18, set_comprehension; 19, identifier:requirements; 20, set_comprehension; 21, identifier:get_realnames; 22, argument_list; 23, identifier:get_installed_distributions; 24, argument_list; 25, call; 26, for_in_clause; 27, call; 28, for_in_clause; 29, for_in_clause; 30, binary_operator:remaining - requirements; 31, keyword_argument; 32, attribute; 33, argument_list; 34, identifier:d; 35, identifier:distributions; 36, attribute; 37, argument_list; 38, identifier:d; 39, identifier:distributions; 40, identifier:r; 41, call; 42, identifier:remaining; 43, identifier:requirements; 44, identifier:user_only; 45, identifier:ENABLE_USER_SITE; 46, attribute; 47, identifier:lower; 48, attribute; 49, identifier:lower; 50, attribute; 51, argument_list; 52, identifier:d; 53, identifier:project_name; 54, identifier:r; 55, identifier:project_name; 56, identifier:d; 57, identifier:requires
0, 1; 1, 2; 1, 3; 1, 4; 4, 5; 4, 6; 4, 7; 4, 8; 4, 9; 5, 10; 6, 11; 7, 12; 8, 13; 9, 14; 11, 15; 11, 16; 12, 17; 12, 18; 13, 19; 13, 20; 14, 21; 14, 22; 16, 23; 16, 24; 18, 25; 18, 26; 20, 27; 20, 28; 20, 29; 22, 30; 24, 31; 25, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 28, 38; 28, 39; 29, 40; 29, 41; 30, 42; 30, 43; 31, 44; 31, 45; 32, 46; 32, 47; 36, 48; 36, 49; 41, 50; 41, 51; 46, 52; 46, 53; 48, 54; 48, 55; 50, 56; 50, 57
def get_parents(): """Return sorted list of names of packages without dependants.""" distributions = get_installed_distributions(user_only=ENABLE_USER_SITE) remaining = {d.project_name.lower() for d in distributions} requirements = {r.project_name.lower() for d in distributions for r in d.requires()} return get_realnames(remaining - requirements)
0, module; 1, function_definition; 2, function_name:get_realnames; 3, parameters; 4, block; 5, identifier:packages; 6, expression_statement; 7, return_statement; 8, comment:""" Return list of unique case-correct package names. Packages are listed in a case-insensitive sorted order. """; 9, call; 10, identifier:sorted; 11, argument_list; 12, set_comprehension; 13, keyword_argument; 14, attribute; 15, for_in_clause; 16, identifier:key; 17, lambda; 18, call; 19, identifier:project_name; 20, identifier:p; 21, identifier:packages; 22, lambda_parameters; 23, call; 24, identifier:get_distribution; 25, argument_list; 26, identifier:n; 27, attribute; 28, argument_list; 29, identifier:p; 30, identifier:n; 31, identifier:lower
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; 12, 14; 12, 15; 13, 16; 13, 17; 14, 18; 14, 19; 15, 20; 15, 21; 17, 22; 17, 23; 18, 24; 18, 25; 22, 26; 23, 27; 23, 28; 25, 29; 27, 30; 27, 31
def get_realnames(packages): """ Return list of unique case-correct package names. Packages are listed in a case-insensitive sorted order. """ return sorted({get_distribution(p).project_name for p in packages}, key=lambda n: n.lower())
0, module; 1, function_definition; 2, function_name:build_sort; 3, parameters; 4, block; 5, expression_statement; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, return_statement; 10, string; 11, assignment; 12, assignment; 13, assignment; 14, list_comprehension; 15, string_content:Build sort query paramter from kwargs; 16, identifier:sorts; 17, call; 18, identifier:sorts; 19, conditional_expression:[sorts] if isinstance(sorts, basestring) else sorts; 20, identifier:sorts; 21, list_comprehension; 22, dictionary; 23, for_in_clause; 24, if_clause; 25, attribute; 26, argument_list; 27, list; 28, call; 29, identifier:sorts; 30, call; 31, for_in_clause; 32, pair; 33, pattern_list; 34, identifier:sorts; 35, comparison_operator:s in SORTS; 36, attribute; 37, identifier:getlist; 38, string; 39, identifier:sorts; 40, identifier:isinstance; 41, argument_list; 42, attribute; 43, argument_list; 44, identifier:s; 45, identifier:sorts; 46, subscript; 47, identifier:d; 48, identifier:s; 49, identifier:d; 50, identifier:s; 51, identifier:SORTS; 52, identifier:request; 53, identifier:args; 54, string_content:sort; 55, identifier:sorts; 56, identifier:basestring; 57, identifier:s; 58, identifier:split; 59, string; 60, identifier:SORTS; 61, identifier:s; 62, string_content:
0, 1; 1, 2; 1, 3; 1, 4; 4, 5; 4, 6; 4, 7; 4, 8; 4, 9; 5, 10; 6, 11; 7, 12; 8, 13; 9, 14; 10, 15; 11, 16; 11, 17; 12, 18; 12, 19; 13, 20; 13, 21; 14, 22; 14, 23; 14, 24; 17, 25; 17, 26; 19, 27; 19, 28; 19, 29; 21, 30; 21, 31; 22, 32; 23, 33; 23, 34; 24, 35; 25, 36; 25, 37; 26, 38; 27, 39; 28, 40; 28, 41; 30, 42; 30, 43; 31, 44; 31, 45; 32, 46; 32, 47; 33, 48; 33, 49; 35, 50; 35, 51; 36, 52; 36, 53; 38, 54; 41, 55; 41, 56; 42, 57; 42, 58; 43, 59; 46, 60; 46, 61; 59, 62
def build_sort(): '''Build sort query paramter from kwargs''' sorts = request.args.getlist('sort') sorts = [sorts] if isinstance(sorts, basestring) else sorts sorts = [s.split(' ') for s in sorts] return [{SORTS[s]: d} for s, d in sorts if s in SORTS]
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:transactions; 6, expression_statement; 7, return_statement; 8, comment:""" Return a list of sorted transactions by date. """; 9, subscript; 10, call; 11, slice; 12, attribute; 13, argument_list; 14, identifier:transactions; 15, identifier:sort; 16, keyword_argument; 17, identifier:key; 18, lambda; 19, lambda_parameters; 20, call; 21, identifier:x; 22, attribute; 23, argument_list; 24, attribute; 25, identifier:strptime; 26, subscript; 27, string; 28, identifier:datetime; 29, identifier:datetime; 30, call; 31, integer:0; 32, string_content:%Y-%m-%d; 33, attribute; 34, argument_list; 35, identifier:x; 36, identifier:split; 37, string; 38, string_content::
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; 12, 14; 12, 15; 13, 16; 16, 17; 16, 18; 18, 19; 18, 20; 19, 21; 20, 22; 20, 23; 22, 24; 22, 25; 23, 26; 23, 27; 24, 28; 24, 29; 26, 30; 26, 31; 27, 32; 30, 33; 30, 34; 33, 35; 33, 36; 34, 37; 37, 38
def sort(transactions): """ Return a list of sorted transactions by date. """ return transactions.sort(key=lambda x: datetime.datetime.strptime(x.split(':')[0], '%Y-%m-%d'))[:]
0, module; 1, function_definition; 2, function_name:duplicates; 3, parameters; 4, block; 5, identifier:base; 6, identifier:items; 7, expression_statement; 8, for_statement; 9, comment:"""Get an iterator of items similar but not equal to the base. @param base: base item to perform comparison against @param items: list of items to compare to the base @return: generator of items sorted by similarity to the base """; 10, identifier:item; 11, identifier:items; 12, block; 13, if_statement; 14, boolean_operator; 15, block; 16, call; 17, not_operator; 18, expression_statement; 19, attribute; 20, argument_list; 21, call; 22, yield; 23, identifier:item; 24, identifier:similarity; 25, identifier:base; 26, attribute; 27, argument_list; 28, identifier:item; 29, identifier:item; 30, identifier:equality; 31, identifier:base
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 8, 11; 8, 12; 12, 13; 13, 14; 13, 15; 14, 16; 14, 17; 15, 18; 16, 19; 16, 20; 17, 21; 18, 22; 19, 23; 19, 24; 20, 25; 21, 26; 21, 27; 22, 28; 26, 29; 26, 30; 27, 31
def duplicates(base, items): """Get an iterator of items similar but not equal to the base. @param base: base item to perform comparison against @param items: list of items to compare to the base @return: generator of items sorted by similarity to the base """ for item in items: if item.similarity(base) and not item.equality(base): yield item
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:base; 6, identifier:items; 7, expression_statement; 8, return_statement; 9, comment:"""Get a sorted list of items ranked in descending similarity. @param base: base item to perform comparison against @param items: list of items to compare to the base @return: list of items sorted by similarity to the base """; 10, call; 11, identifier:sorted; 12, argument_list; 13, identifier:items; 14, keyword_argument; 15, keyword_argument; 16, identifier:key; 17, attribute; 18, identifier:reverse; 19, True; 20, identifier:base; 21, identifier:similarity
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 12, 13; 12, 14; 12, 15; 14, 16; 14, 17; 15, 18; 15, 19; 17, 20; 17, 21
def sort(base, items): """Get a sorted list of items ranked in descending similarity. @param base: base item to perform comparison against @param items: list of items to compare to the base @return: list of items sorted by similarity to the base """ return sorted(items, key=base.similarity, reverse=True)
0, module; 1, function_definition; 2, function_name:Subclasses; 3, parameters; 4, block; 5, identifier:cls; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, if_statement; 12, expression_statement; 13, return_statement; 14, identifier:sort_by; 15, None; 16, identifier:reverse; 17, False; 18, comment:"""Get all nested Constant class and it's name pair. :param sort_by: the attribute name used for sorting. :param reverse: if True, return in descend order. :returns: [(attr, value),...] pairs. :: >>> class MyClass(Constant): ... a = 1 # non-class attributre ... b = 2 # non-class attributre ... ... class C(Constant): ... pass ... ... class D(Constant): ... pass >>> MyClass.Subclasses() [("C", MyClass.C), ("D", MyClass.D)] .. versionadded:: 0.0.3 """; 19, assignment; 20, pattern_list; 21, call; 22, block; 23, comparison_operator:sort_by is None; 24, block; 25, assignment; 26, identifier:l; 27, identifier:l; 28, call; 29, identifier:attr; 30, identifier:value; 31, identifier:get_all_attributes; 32, argument_list; 33, try_statement; 34, identifier:sort_by; 35, None; 36, expression_statement; 37, identifier:l; 38, call; 39, identifier:list; 40, argument_list; 41, identifier:cls; 42, block; 43, except_clause; 44, assignment; 45, identifier:list; 46, argument_list; 47, if_statement; 48, block; 49, identifier:sort_by; 50, string:"__creation_index__"; 51, call; 52, call; 53, block; 54, pass_statement; 55, identifier:sorted; 56, argument_list; 57, identifier:issubclass; 58, argument_list; 59, expression_statement; 60, identifier:l; 61, keyword_argument; 62, keyword_argument; 63, identifier:value; 64, identifier:Constant; 65, call; 66, identifier:key; 67, lambda; 68, identifier:reverse; 69, identifier:reverse; 70, attribute; 71, argument_list; 72, lambda_parameters; 73, call; 74, identifier:l; 75, identifier:append; 76, tuple; 77, identifier:x; 78, identifier:getattr; 79, argument_list; 80, identifier:attr; 81, identifier:value; 82, subscript; 83, identifier:sort_by; 84, identifier:x; 85, 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; 6, 14; 6, 15; 7, 16; 7, 17; 8, 18; 9, 19; 10, 20; 10, 21; 10, 22; 11, 23; 11, 24; 12, 25; 13, 26; 19, 27; 19, 28; 20, 29; 20, 30; 21, 31; 21, 32; 22, 33; 23, 34; 23, 35; 24, 36; 25, 37; 25, 38; 28, 39; 28, 40; 32, 41; 33, 42; 33, 43; 36, 44; 38, 45; 38, 46; 42, 47; 43, 48; 44, 49; 44, 50; 46, 51; 47, 52; 47, 53; 48, 54; 51, 55; 51, 56; 52, 57; 52, 58; 53, 59; 56, 60; 56, 61; 56, 62; 58, 63; 58, 64; 59, 65; 61, 66; 61, 67; 62, 68; 62, 69; 65, 70; 65, 71; 67, 72; 67, 73; 70, 74; 70, 75; 71, 76; 72, 77; 73, 78; 73, 79; 76, 80; 76, 81; 79, 82; 79, 83; 82, 84; 82, 85
def Subclasses(cls, sort_by=None, reverse=False): """Get all nested Constant class and it's name pair. :param sort_by: the attribute name used for sorting. :param reverse: if True, return in descend order. :returns: [(attr, value),...] pairs. :: >>> class MyClass(Constant): ... a = 1 # non-class attributre ... b = 2 # non-class attributre ... ... class C(Constant): ... pass ... ... class D(Constant): ... pass >>> MyClass.Subclasses() [("C", MyClass.C), ("D", MyClass.D)] .. versionadded:: 0.0.3 """ l = list() for attr, value in get_all_attributes(cls): try: if issubclass(value, Constant): l.append((attr, value)) except: pass if sort_by is None: sort_by = "__creation_index__" l = list( sorted(l, key=lambda x: getattr(x[1], sort_by), reverse=reverse)) return l
0, module; 1, function_definition; 2, function_name:subclasses; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, identifier:sort_by; 13, None; 14, identifier:reverse; 15, False; 16, comment:"""Get all nested Constant class instance and it's name pair. :param sort_by: the attribute name used for sorting. :param reverse: if True, return in descend order. :returns: [(attr, value),...] pairs. :: >>> class MyClass(Constant): ... a = 1 # non-class attributre ... b = 2 # non-class attributre ... ... class C(Constant): ... pass ... ... class D(Constant): ... pass >>> my_class = MyClass() >>> my_class.subclasses() [("C", my_class.C), ("D", my_class.D)] .. versionadded:: 0.0.4 """; 17, assignment; 18, pattern_list; 19, call; 20, block; 21, identifier:l; 22, identifier:l; 23, call; 24, identifier:attr; 25, identifier:_; 26, attribute; 27, argument_list; 28, expression_statement; 29, expression_statement; 30, identifier:list; 31, argument_list; 32, identifier:self; 33, identifier:Subclasses; 34, identifier:sort_by; 35, identifier:reverse; 36, assignment; 37, call; 38, identifier:value; 39, call; 40, attribute; 41, argument_list; 42, identifier:getattr; 43, argument_list; 44, identifier:l; 45, identifier:append; 46, tuple; 47, identifier:self; 48, identifier:attr; 49, identifier:attr; 50, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 7, 15; 8, 16; 9, 17; 10, 18; 10, 19; 10, 20; 11, 21; 17, 22; 17, 23; 18, 24; 18, 25; 19, 26; 19, 27; 20, 28; 20, 29; 23, 30; 23, 31; 26, 32; 26, 33; 27, 34; 27, 35; 28, 36; 29, 37; 36, 38; 36, 39; 37, 40; 37, 41; 39, 42; 39, 43; 40, 44; 40, 45; 41, 46; 43, 47; 43, 48; 46, 49; 46, 50
def subclasses(self, sort_by=None, reverse=False): """Get all nested Constant class instance and it's name pair. :param sort_by: the attribute name used for sorting. :param reverse: if True, return in descend order. :returns: [(attr, value),...] pairs. :: >>> class MyClass(Constant): ... a = 1 # non-class attributre ... b = 2 # non-class attributre ... ... class C(Constant): ... pass ... ... class D(Constant): ... pass >>> my_class = MyClass() >>> my_class.subclasses() [("C", my_class.C), ("D", my_class.D)] .. versionadded:: 0.0.4 """ l = list() for attr, _ in self.Subclasses(sort_by, reverse): value = getattr(self, attr) l.append((attr, value)) return l
0, module; 1, function_definition; 2, function_name:organize_dir; 3, parameters; 4, block; 5, identifier:orig_dir; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, for_statement; 16, string; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, identifier:dup; 22, identifier:dups; 23, block; 24, assignment; 25, assignment; 26, identifier:key; 27, identifier:clustered; 28, block; 29, pattern_list; 30, call; 31, block; 32, string_content:scans through the given directory and organizes DICOMs that look similar into subdirectories output directory is the ``orig_dir`` with ``-sorted`` appended to the end; 33, identifier:tags; 34, list; 35, identifier:orig_dir; 36, call; 37, identifier:files; 38, call; 39, identifier:dups; 40, call; 41, expression_statement; 42, for_statement; 43, identifier:clustered; 44, call; 45, identifier:output_dir; 46, binary_operator:'%s-sorted' % orig_dir; 47, if_statement; 48, for_statement; 49, expression_statement; 50, expression_statement; 51, expression_statement; 52, try_statement; 53, identifier:r; 54, identifier:ds; 55, identifier:fs; 56, attribute; 57, argument_list; 58, for_statement; 59, tuple; 60, comment:# Subj ID; 61, tuple; 62, comment:# Date; 63, tuple; 64, comment:# Time; 65, tuple; 66, comment:# Descr; 67, attribute; 68, argument_list; 69, identifier:scan_dir; 70, argument_list; 71, identifier:find_dups; 72, argument_list; 73, call; 74, identifier:each_dup; 75, subscript; 76, block; 77, identifier:cluster_files; 78, argument_list; 79, string; 80, identifier:orig_dir; 81, comparison_operator:(0x8,0x31) in clustered[key]['info']; 82, block; 83, identifier:t; 84, identifier:tags; 85, block; 86, assignment; 87, assignment; 88, call; 89, block; 90, except_clause; 91, else_clause; 92, identifier:os; 93, identifier:walk; 94, identifier:output_dir; 95, keyword_argument; 96, identifier:d; 97, identifier:ds; 98, block; 99, integer:0x10; 100, integer:0x20; 101, integer:0x8; 102, integer:0x21; 103, integer:0x8; 104, integer:0x31; 105, integer:0x8; 106, integer:0x103e; 107, identifier:orig_dir; 108, identifier:rstrip; 109, string; 110, identifier:orig_dir; 111, keyword_argument; 112, keyword_argument; 113, identifier:files; 114, attribute; 115, argument_list; 116, identifier:dup; 117, slice; 118, expression_statement; 119, try_statement; 120, delete_statement; 121, identifier:files; 122, string_content:%s-sorted; 123, tuple; 124, subscript; 125, expression_statement; 126, if_statement; 127, identifier:run_name; 128, binary_operator:'-'.join([scrub_fname(str(clustered[key]['info'][x])) for x in tags])+'-%d_images' %len(clustered[key]['files']); 129, identifier:run_dir; 130, call; 131, attribute; 132, argument_list; 133, if_statement; 134, identifier:IOError; 135, block; 136, block; 137, identifier:topdown; 138, False; 139, expression_statement; 140, if_statement; 141, string_content:/; 142, identifier:tags; 143, identifier:tags; 144, identifier:md5_hash; 145, True; 146, identifier:nl; 147, identifier:notify; 148, binary_operator:'Found duplicates of %s...' % dup[0]; 149, integer:1; 150, call; 151, block; 152, except_clause; 153, parenthesized_expression; 154, integer:0x8; 155, integer:0x31; 156, subscript; 157, string; 158, assignment; 159, comparison_operator:t not in clustered[key]['info']; 160, block; 161, call; 162, binary_operator:'-%d_images' %len(clustered[key]['files']); 163, attribute; 164, argument_list; 165, identifier:nl; 166, identifier:notify; 167, binary_operator:'Moving files into %s' % run_dir; 168, not_operator; 169, block; 170, expression_statement; 171, for_statement; 172, assignment; 173, comparison_operator:len(os.listdir(dname))==0; 174, block; 175, string; 176, subscript; 177, attribute; 178, argument_list; 179, expression_statement; 180, identifier:IOError; 181, block; 182, subscript; 183, identifier:clustered; 184, identifier:key; 185, string_content:info; 186, subscript; 187, call; 188, identifier:t; 189, subscript; 190, expression_statement; 191, attribute; 192, argument_list; 193, string; 194, call; 195, attribute; 196, identifier:join; 197, identifier:output_dir; 198, identifier:run_name; 199, string; 200, identifier:run_dir; 201, call; 202, expression_statement; 203, call; 204, identifier:f; 205, subscript; 206, block; 207, identifier:dname; 208, call; 209, call; 210, integer:0; 211, expression_statement; 212, string_content:Found duplicates of %s...; 213, identifier:dup; 214, integer:0; 215, identifier:nl; 216, identifier:notify; 217, binary_operator:'\tdeleting %s' % each_dup; 218, call; 219, expression_statement; 220, identifier:files; 221, identifier:each_dup; 222, subscript; 223, tuple; 224, identifier:str; 225, argument_list; 226, subscript; 227, string; 228, assignment; 229, string; 230, identifier:join; 231, list_comprehension; 232, string_content:-%d_images; 233, identifier:len; 234, argument_list; 235, identifier:os; 236, identifier:path; 237, string_content:Moving files into %s; 238, attribute; 239, argument_list; 240, call; 241, attribute; 242, argument_list; 243, subscript; 244, string; 245, try_statement; 246, attribute; 247, argument_list; 248, identifier:len; 249, argument_list; 250, call; 251, string; 252, identifier:each_dup; 253, attribute; 254, argument_list; 255, call; 256, subscript; 257, string; 258, integer:0x8; 259, integer:0x31; 260, call; 261, identifier:clustered; 262, identifier:key; 263, string_content:info; 264, subscript; 265, string; 266, string_content:-; 267, call; 268, for_in_clause; 269, subscript; 270, attribute; 271, identifier:exists; 272, identifier:run_dir; 273, attribute; 274, argument_list; 275, identifier:nl; 276, identifier:notify; 277, binary_operator:'Error: failed to create directory %s' % run_dir; 278, identifier:clustered; 279, identifier:key; 280, string_content:files; 281, block; 282, except_clause; 283, attribute; 284, identifier:join; 285, identifier:r; 286, identifier:d; 287, call; 288, attribute; 289, argument_list; 290, string_content; 291, identifier:os; 292, identifier:remove; 293, identifier:each_dup; 294, attribute; 295, argument_list; 296, identifier:clustered; 297, identifier:key; 298, string_content:info; 299, identifier:int; 300, argument_list; 301, subscript; 302, identifier:t; 303, string_content:_; 304, identifier:scrub_fname; 305, argument_list; 306, identifier:x; 307, identifier:tags; 308, subscript; 309, string; 310, identifier:os; 311, identifier:path; 312, identifier:os; 313, identifier:makedirs; 314, identifier:run_dir; 315, string; 316, identifier:run_dir; 317, expression_statement; 318, if_statement; 319, expression_statement; 320, tuple; 321, block; 322, identifier:os; 323, identifier:path; 324, attribute; 325, argument_list; 326, identifier:os; 327, identifier:remove; 328, identifier:dname; 329, escape_sequence:\t; 330, identifier:nl; 331, identifier:notify; 332, string; 333, call; 334, subscript; 335, string; 336, call; 337, identifier:clustered; 338, identifier:key; 339, string_content:files; 340, string_content:Error: failed to create directory %s; 341, assignment; 342, comparison_operator:dset_fname[0]=='.'; 343, block; 344, call; 345, identifier:IOError; 346, identifier:OSError; 347, pass_statement; 348, identifier:os; 349, identifier:listdir; 350, identifier:dname; 351, string_content; 352, identifier:float; 353, argument_list; 354, identifier:clustered; 355, identifier:key; 356, string_content:info; 357, identifier:str; 358, argument_list; 359, identifier:dset_fname; 360, subscript; 361, subscript; 362, string; 363, expression_statement; 364, attribute; 365, argument_list; 366, escape_sequence:\t; 367, subscript; 368, subscript; 369, call; 370, integer:1; 371, identifier:dset_fname; 372, integer:0; 373, string_content:.; 374, assignment; 375, identifier:os; 376, identifier:rename; 377, identifier:f; 378, call; 379, subscript; 380, tuple; 381, subscript; 382, identifier:x; 383, attribute; 384, argument_list; 385, identifier:dset_fname; 386, binary_operator:'_' + dset_fname[1:]; 387, attribute; 388, argument_list; 389, subscript; 390, string; 391, integer:0x8; 392, integer:0x31; 393, subscript; 394, string; 395, attribute; 396, identifier:split; 397, identifier:f; 398, string; 399, subscript; 400, attribute; 401, identifier:join; 402, identifier:run_dir; 403, identifier:dset_fname; 404, identifier:clustered; 405, identifier:key; 406, string_content:info; 407, identifier:clustered; 408, identifier:key; 409, string_content:info; 410, identifier:os; 411, identifier:path; 412, string_content:_; 413, identifier:dset_fname; 414, slice; 415, identifier:os; 416, identifier:path; 417, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 6, 16; 7, 17; 8, 18; 9, 19; 10, 20; 11, 21; 11, 22; 11, 23; 12, 24; 13, 25; 14, 26; 14, 27; 14, 28; 15, 29; 15, 30; 15, 31; 16, 32; 17, 33; 17, 34; 18, 35; 18, 36; 19, 37; 19, 38; 20, 39; 20, 40; 23, 41; 23, 42; 24, 43; 24, 44; 25, 45; 25, 46; 28, 47; 28, 48; 28, 49; 28, 50; 28, 51; 28, 52; 29, 53; 29, 54; 29, 55; 30, 56; 30, 57; 31, 58; 34, 59; 34, 60; 34, 61; 34, 62; 34, 63; 34, 64; 34, 65; 34, 66; 36, 67; 36, 68; 38, 69; 38, 70; 40, 71; 40, 72; 41, 73; 42, 74; 42, 75; 42, 76; 44, 77; 44, 78; 46, 79; 46, 80; 47, 81; 47, 82; 48, 83; 48, 84; 48, 85; 49, 86; 50, 87; 51, 88; 52, 89; 52, 90; 52, 91; 56, 92; 56, 93; 57, 94; 57, 95; 58, 96; 58, 97; 58, 98; 59, 99; 59, 100; 61, 101; 61, 102; 63, 103; 63, 104; 65, 105; 65, 106; 67, 107; 67, 108; 68, 109; 70, 110; 70, 111; 70, 112; 72, 113; 73, 114; 73, 115; 75, 116; 75, 117; 76, 118; 76, 119; 76, 120; 78, 121; 79, 122; 81, 123; 81, 124; 82, 125; 85, 126; 86, 127; 86, 128; 87, 129; 87, 130; 88, 131; 88, 132; 89, 133; 90, 134; 90, 135; 91, 136; 95, 137; 95, 138; 98, 139; 98, 140; 109, 141; 111, 142; 111, 143; 112, 144; 112, 145; 114, 146; 114, 147; 115, 148; 117, 149; 118, 150; 119, 151; 119, 152; 120, 153; 123, 154; 123, 155; 124, 156; 124, 157; 125, 158; 126, 159; 126, 160; 128, 161; 128, 162; 130, 163; 130, 164; 131, 165; 131, 166; 132, 167; 133, 168; 133, 169; 135, 170; 136, 171; 139, 172; 140, 173; 140, 174; 148, 175; 148, 176; 150, 177; 150, 178; 151, 179; 152, 180; 152, 181; 153, 182; 156, 183; 156, 184; 157, 185; 158, 186; 158, 187; 159, 188; 159, 189; 160, 190; 161, 191; 161, 192; 162, 193; 162, 194; 163, 195; 163, 196; 164, 197; 164, 198; 167, 199; 167, 200; 168, 201; 169, 202; 170, 203; 171, 204; 171, 205; 171, 206; 172, 207; 172, 208; 173, 209; 173, 210; 174, 211; 175, 212; 176, 213; 176, 214; 177, 215; 177, 216; 178, 217; 179, 218; 181, 219; 182, 220; 182, 221; 186, 222; 186, 223; 187, 224; 187, 225; 189, 226; 189, 227; 190, 228; 191, 229; 191, 230; 192, 231; 193, 232; 194, 233; 194, 234; 195, 235; 195, 236; 199, 237; 201, 238; 201, 239; 202, 240; 203, 241; 203, 242; 205, 243; 205, 244; 206, 245; 208, 246; 208, 247; 209, 248; 209, 249; 211, 250; 217, 251; 217, 252; 218, 253; 218, 254; 219, 255; 222, 256; 222, 257; 223, 258; 223, 259; 225, 260; 226, 261; 226, 262; 227, 263; 228, 264; 228, 265; 229, 266; 231, 267; 231, 268; 234, 269; 238, 270; 238, 271; 239, 272; 240, 273; 240, 274; 241, 275; 241, 276; 242, 277; 243, 278; 243, 279; 244, 280; 245, 281; 245, 282; 246, 283; 246, 284; 247, 285; 247, 286; 249, 287; 250, 288; 250, 289; 251, 290; 253, 291; 253, 292; 254, 293; 255, 294; 255, 295; 256, 296; 256, 297; 257, 298; 260, 299; 260, 300; 264, 301; 264, 302; 265, 303; 267, 304; 267, 305; 268, 306; 268, 307; 269, 308; 269, 309; 270, 310; 270, 311; 273, 312; 273, 313; 274, 314; 277, 315; 277, 316; 281, 317; 281, 318; 281, 319; 282, 320; 282, 321; 283, 322; 283, 323; 287, 324; 287, 325; 288, 326; 288, 327; 289, 328; 290, 329; 294, 330; 294, 331; 295, 332; 300, 333; 301, 334; 301, 335; 305, 336; 308, 337; 308, 338; 309, 339; 315, 340; 317, 341; 318, 342; 318, 343; 319, 344; 320, 345; 320, 346; 321, 347; 324, 348; 324, 349; 325, 350; 332, 351; 333, 352; 333, 353; 334, 354; 334, 355; 335, 356; 336, 357; 336, 358; 341, 359; 341, 360; 342, 361; 342, 362; 343, 363; 344, 364; 344, 365; 351, 366; 353, 367; 358, 368; 360, 369; 360, 370; 361, 371; 361, 372; 362, 373; 363, 374; 364, 375; 364, 376; 365, 377; 365, 378; 367, 379; 367, 380; 368, 381; 368, 382; 369, 383; 369, 384; 374, 385; 374, 386; 378, 387; 378, 388; 379, 389; 379, 390; 380, 391; 380, 392; 381, 393; 381, 394; 383, 395; 383, 396; 384, 397; 386, 398; 386, 399; 387, 400; 387, 401; 388, 402; 388, 403; 389, 404; 389, 405; 390, 406; 393, 407; 393, 408; 394, 409; 395, 410; 395, 411; 398, 412; 399, 413; 399, 414; 400, 415; 400, 416; 414, 417
def organize_dir(orig_dir): '''scans through the given directory and organizes DICOMs that look similar into subdirectories output directory is the ``orig_dir`` with ``-sorted`` appended to the end''' tags = [ (0x10,0x20), # Subj ID (0x8,0x21), # Date (0x8,0x31), # Time (0x8,0x103e) # Descr ] orig_dir = orig_dir.rstrip('/') files = scan_dir(orig_dir,tags=tags,md5_hash=True) dups = find_dups(files) for dup in dups: nl.notify('Found duplicates of %s...' % dup[0]) for each_dup in dup[1:]: nl.notify('\tdeleting %s' % each_dup) try: os.remove(each_dup) except IOError: nl.notify('\t[failed]') del(files[each_dup]) clustered = cluster_files(files) output_dir = '%s-sorted' % orig_dir for key in clustered: if (0x8,0x31) in clustered[key]['info']: clustered[key]['info'][(0x8,0x31)] = str(int(float(clustered[key]['info'][(0x8,0x31)]))) for t in tags: if t not in clustered[key]['info']: clustered[key]['info'][t] = '_' run_name = '-'.join([scrub_fname(str(clustered[key]['info'][x])) for x in tags])+'-%d_images' %len(clustered[key]['files']) run_dir = os.path.join(output_dir,run_name) nl.notify('Moving files into %s' % run_dir) try: if not os.path.exists(run_dir): os.makedirs(run_dir) except IOError: nl.notify('Error: failed to create directory %s' % run_dir) else: for f in clustered[key]['files']: try: dset_fname = os.path.split(f)[1] if dset_fname[0]=='.': dset_fname = '_' + dset_fname[1:] os.rename(f,os.path.join(run_dir,dset_fname)) except (IOError, OSError): pass for r,ds,fs in os.walk(output_dir,topdown=False): for d in ds: dname = os.path.join(r,d) if len(os.listdir(dname))==0: os.remove(dname)
0, module; 1, function_definition; 2, function_name:reconstruct_files; 3, parameters; 4, block; 5, identifier:input_dir; 6, expression_statement; 7, expression_statement; 8, with_statement; 9, string; 10, assignment; 11, with_clause; 12, comment:# Some datasets start with a ".", which confuses many programs; 13, block; 14, string_content:sorts ``input_dir`` and tries to reconstruct the subdirectories found; 15, identifier:input_dir; 16, call; 17, with_item; 18, for_statement; 19, expression_statement; 20, expression_statement; 21, if_statement; 22, attribute; 23, argument_list; 24, call; 25, pattern_list; 26, call; 27, block; 28, call; 29, assignment; 30, call; 31, block; 32, else_clause; 33, identifier:input_dir; 34, identifier:rstrip; 35, string; 36, attribute; 37, argument_list; 38, identifier:r; 39, identifier:ds; 40, identifier:fs; 41, attribute; 42, argument_list; 43, for_statement; 44, attribute; 45, argument_list; 46, identifier:output_dir; 47, binary_operator:'%s-sorted' % input_dir; 48, attribute; 49, argument_list; 50, with_statement; 51, block; 52, string_content:/; 53, identifier:nl; 54, identifier:notify; 55, string; 56, identifier:os; 57, identifier:walk; 58, identifier:input_dir; 59, identifier:f; 60, identifier:fs; 61, block; 62, attribute; 63, identifier:organize_dir; 64, identifier:input_dir; 65, string; 66, identifier:input_dir; 67, attribute; 68, identifier:exists; 69, identifier:output_dir; 70, with_clause; 71, block; 72, expression_statement; 73, string_content:Attempting to organize/reconstruct directory; 74, if_statement; 75, identifier:nl; 76, identifier:dicom; 77, string_content:%s-sorted; 78, identifier:os; 79, identifier:path; 80, with_item; 81, for_statement; 82, call; 83, comparison_operator:f[0]=='.'; 84, block; 85, call; 86, identifier:dset_dir; 87, call; 88, block; 89, attribute; 90, argument_list; 91, subscript; 92, string; 93, expression_statement; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, with_statement; 99, identifier:nl; 100, identifier:notify; 101, binary_operator:'Warning: failed to auto-organize directory %s' % input_dir; 102, keyword_argument; 103, identifier:f; 104, integer:0; 105, string_content:.; 106, call; 107, identifier:nl; 108, identifier:run_in; 109, identifier:output_dir; 110, identifier:os; 111, identifier:listdir; 112, string; 113, with_clause; 114, block; 115, string; 116, identifier:input_dir; 117, identifier:level; 118, attribute; 119, attribute; 120, argument_list; 121, string_content:.; 122, with_item; 123, expression_statement; 124, string_content:Warning: failed to auto-organize directory %s; 125, attribute; 126, identifier:warning; 127, identifier:shutil; 128, identifier:move; 129, call; 130, call; 131, call; 132, call; 133, identifier:nl; 134, identifier:level; 135, attribute; 136, argument_list; 137, attribute; 138, argument_list; 139, attribute; 140, argument_list; 141, attribute; 142, argument_list; 143, attribute; 144, identifier:join; 145, identifier:r; 146, identifier:f; 147, attribute; 148, identifier:join; 149, identifier:r; 150, binary_operator:'i'+f; 151, identifier:nl; 152, identifier:notify; 153, binary_operator:'creating dataset from %s' % dset_dir; 154, attribute; 155, identifier:create_dset; 156, identifier:dset_dir; 157, identifier:os; 158, identifier:path; 159, identifier:os; 160, identifier:path; 161, string; 162, identifier:f; 163, string; 164, identifier:dset_dir; 165, identifier:nl; 166, identifier:dicom; 167, string_content:i; 168, string_content:creating dataset from %s
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 8, 12; 8, 13; 9, 14; 10, 15; 10, 16; 11, 17; 13, 18; 13, 19; 13, 20; 13, 21; 16, 22; 16, 23; 17, 24; 18, 25; 18, 26; 18, 27; 19, 28; 20, 29; 21, 30; 21, 31; 21, 32; 22, 33; 22, 34; 23, 35; 24, 36; 24, 37; 25, 38; 25, 39; 25, 40; 26, 41; 26, 42; 27, 43; 28, 44; 28, 45; 29, 46; 29, 47; 30, 48; 30, 49; 31, 50; 32, 51; 35, 52; 36, 53; 36, 54; 37, 55; 41, 56; 41, 57; 42, 58; 43, 59; 43, 60; 43, 61; 44, 62; 44, 63; 45, 64; 47, 65; 47, 66; 48, 67; 48, 68; 49, 69; 50, 70; 50, 71; 51, 72; 55, 73; 61, 74; 62, 75; 62, 76; 65, 77; 67, 78; 67, 79; 70, 80; 71, 81; 72, 82; 74, 83; 74, 84; 80, 85; 81, 86; 81, 87; 81, 88; 82, 89; 82, 90; 83, 91; 83, 92; 84, 93; 85, 94; 85, 95; 87, 96; 87, 97; 88, 98; 89, 99; 89, 100; 90, 101; 90, 102; 91, 103; 91, 104; 92, 105; 93, 106; 94, 107; 94, 108; 95, 109; 96, 110; 96, 111; 97, 112; 98, 113; 98, 114; 101, 115; 101, 116; 102, 117; 102, 118; 106, 119; 106, 120; 112, 121; 113, 122; 114, 123; 115, 124; 118, 125; 118, 126; 119, 127; 119, 128; 120, 129; 120, 130; 122, 131; 123, 132; 125, 133; 125, 134; 129, 135; 129, 136; 130, 137; 130, 138; 131, 139; 131, 140; 132, 141; 132, 142; 135, 143; 135, 144; 136, 145; 136, 146; 137, 147; 137, 148; 138, 149; 138, 150; 139, 151; 139, 152; 140, 153; 141, 154; 141, 155; 142, 156; 143, 157; 143, 158; 147, 159; 147, 160; 150, 161; 150, 162; 153, 163; 153, 164; 154, 165; 154, 166; 161, 167; 163, 168
def reconstruct_files(input_dir): '''sorts ``input_dir`` and tries to reconstruct the subdirectories found''' input_dir = input_dir.rstrip('/') with nl.notify('Attempting to organize/reconstruct directory'): # Some datasets start with a ".", which confuses many programs for r,ds,fs in os.walk(input_dir): for f in fs: if f[0]=='.': shutil.move(os.path.join(r,f),os.path.join(r,'i'+f)) nl.dicom.organize_dir(input_dir) output_dir = '%s-sorted' % input_dir if os.path.exists(output_dir): with nl.run_in(output_dir): for dset_dir in os.listdir('.'): with nl.notify('creating dataset from %s' % dset_dir): nl.dicom.create_dset(dset_dir) else: nl.notify('Warning: failed to auto-organize directory %s' % input_dir,level=nl.level.warning)
0, module; 1, function_definition; 2, function_name:lint; 3, parameters; 4, block; 5, identifier:self; 6, identifier:targets; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, with_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""Run linters in parallel and sort all results. Args: targets (list): List of files and folders to lint. """; 15, assignment; 16, assignment; 17, with_clause; 18, block; 19, assignment; 20, assignment; 21, expression_list; 22, attribute; 23, identifier:targets; 24, identifier:linters; 25, call; 26, with_item; 27, expression_statement; 28, identifier:out_err; 29, list_comprehension; 30, pattern_list; 31, call; 32, call; 33, call; 34, identifier:LinterRunner; 35, identifier:targets; 36, attribute; 37, argument_list; 38, as_pattern; 39, assignment; 40, identifier:item; 41, for_in_clause; 42, if_clause; 43, identifier:stdout; 44, identifier:stderr; 45, identifier:zip; 46, argument_list; 47, identifier:sorted; 48, argument_list; 49, attribute; 50, argument_list; 51, attribute; 52, identifier:get_linter_classes; 53, call; 54, as_pattern_target; 55, identifier:out_err_none; 56, call; 57, identifier:item; 58, identifier:out_err_none; 59, comparison_operator:item is not None; 60, list_splat; 61, call; 62, identifier:chain; 63, identifier:from_iterable; 64, identifier:stderr; 65, identifier:self; 66, identifier:_config; 67, identifier:Pool; 68, argument_list; 69, identifier:pool; 70, attribute; 71, argument_list; 72, identifier:item; 73, None; 74, identifier:out_err; 75, attribute; 76, argument_list; 77, identifier:pool; 78, identifier:map; 79, attribute; 80, identifier:linters; 81, identifier:chain; 82, identifier:from_iterable; 83, identifier:stdout; 84, identifier:LinterRunner; 85, identifier:run
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 7, 14; 8, 15; 9, 16; 10, 17; 10, 18; 11, 19; 12, 20; 13, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 18, 27; 19, 28; 19, 29; 20, 30; 20, 31; 21, 32; 21, 33; 22, 34; 22, 35; 25, 36; 25, 37; 26, 38; 27, 39; 29, 40; 29, 41; 29, 42; 30, 43; 30, 44; 31, 45; 31, 46; 32, 47; 32, 48; 33, 49; 33, 50; 36, 51; 36, 52; 38, 53; 38, 54; 39, 55; 39, 56; 41, 57; 41, 58; 42, 59; 46, 60; 48, 61; 49, 62; 49, 63; 50, 64; 51, 65; 51, 66; 53, 67; 53, 68; 54, 69; 56, 70; 56, 71; 59, 72; 59, 73; 60, 74; 61, 75; 61, 76; 70, 77; 70, 78; 71, 79; 71, 80; 75, 81; 75, 82; 76, 83; 79, 84; 79, 85
def lint(self, targets): """Run linters in parallel and sort all results. Args: targets (list): List of files and folders to lint. """ LinterRunner.targets = targets linters = self._config.get_linter_classes() with Pool() as pool: out_err_none = pool.map(LinterRunner.run, linters) out_err = [item for item in out_err_none if item is not None] stdout, stderr = zip(*out_err) return sorted(chain.from_iterable(stdout)), chain.from_iterable(stderr)
0, module; 1, function_definition; 2, function_name:_linear_interp; 3, parameters; 4, block; 5, identifier:curve; 6, identifier:test_x; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, identifier:round_result; 12, False; 13, comment:""" Take a series of points and interpolate between them at ``test_x``. Args: curve (list[tuple]): A list of ``(x, y)`` points sorted in nondecreasing ``x`` value. If multiple points have the same ``x`` value, all but the last will be ignored. test_x (float): The ``x`` value to find the ``y`` value of Returns: float: The ``y`` value of the curve at ``test_x`` if ``round_result is False`` int: if ``round_result is True`` or the result is a whole number, the ``y`` value of the curve at ``test_x`` rounded to the nearest whole number. Raises: ProbabilityUndefinedError: if ``test_x`` is out of the domain of ``curve`` Example: >>> curve = [(0, 0), (2, 1)] >>> _linear_interp(curve, 0.5) 0.25 >>> _linear_interp(curve, 0.5, round_result=True) 0 """; 14, assignment; 15, identifier:index; 16, call; 17, comment:# Ignore points which share an x value with the following point; 18, block; 19, else_clause; 20, identifier:index; 21, integer:0; 22, identifier:range; 23, argument_list; 24, if_statement; 25, if_statement; 26, block; 27, binary_operator:len(curve) - 1; 28, comparison_operator:curve[index][0] == curve[index + 1][0]; 29, block; 30, comparison_operator:curve[index][0] <= test_x <= curve[index + 1][0]; 31, block; 32, raise_statement; 33, call; 34, integer:1; 35, subscript; 36, subscript; 37, continue_statement; 38, subscript; 39, identifier:test_x; 40, subscript; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, if_statement; 45, identifier:ProbabilityUndefinedError; 46, identifier:len; 47, argument_list; 48, subscript; 49, integer:0; 50, subscript; 51, integer:0; 52, subscript; 53, integer:0; 54, subscript; 55, integer:0; 56, assignment; 57, assignment; 58, assignment; 59, identifier:round_result; 60, block; 61, else_clause; 62, identifier:curve; 63, identifier:curve; 64, identifier:index; 65, identifier:curve; 66, binary_operator:index + 1; 67, identifier:curve; 68, identifier:index; 69, identifier:curve; 70, binary_operator:index + 1; 71, identifier:slope; 72, parenthesized_expression; 73, identifier:y_intercept; 74, binary_operator:curve[index][1] - (slope * curve[index][0]); 75, identifier:result; 76, binary_operator:(slope * test_x) + y_intercept; 77, return_statement; 78, block; 79, identifier:index; 80, integer:1; 81, identifier:index; 82, integer:1; 83, binary_operator:(curve[index + 1][1] - curve[index][1]) / (curve[index + 1][0] - curve[index][0]); 84, subscript; 85, parenthesized_expression; 86, parenthesized_expression; 87, identifier:y_intercept; 88, call; 89, if_statement; 90, parenthesized_expression; 91, parenthesized_expression; 92, subscript; 93, integer:1; 94, binary_operator:slope * curve[index][0]; 95, binary_operator:slope * test_x; 96, identifier:int; 97, argument_list; 98, call; 99, block; 100, else_clause; 101, binary_operator:curve[index + 1][1] - curve[index][1]; 102, binary_operator:curve[index + 1][0] - curve[index][0]; 103, identifier:curve; 104, identifier:index; 105, identifier:slope; 106, subscript; 107, identifier:slope; 108, identifier:test_x; 109, call; 110, attribute; 111, argument_list; 112, return_statement; 113, block; 114, subscript; 115, subscript; 116, subscript; 117, subscript; 118, subscript; 119, integer:0; 120, identifier:round; 121, argument_list; 122, identifier:result; 123, identifier:is_integer; 124, call; 125, return_statement; 126, subscript; 127, integer:1; 128, subscript; 129, integer:1; 130, subscript; 131, integer:0; 132, subscript; 133, integer:0; 134, identifier:curve; 135, identifier:index; 136, identifier:result; 137, identifier:int; 138, argument_list; 139, identifier:result; 140, identifier:curve; 141, binary_operator:index + 1; 142, identifier:curve; 143, identifier:index; 144, identifier:curve; 145, binary_operator:index + 1; 146, identifier:curve; 147, identifier:index; 148, identifier:result; 149, identifier:index; 150, integer:1; 151, identifier:index; 152, integer:1
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; 10, 18; 10, 19; 14, 20; 14, 21; 16, 22; 16, 23; 18, 24; 18, 25; 19, 26; 23, 27; 24, 28; 24, 29; 25, 30; 25, 31; 26, 32; 27, 33; 27, 34; 28, 35; 28, 36; 29, 37; 30, 38; 30, 39; 30, 40; 31, 41; 31, 42; 31, 43; 31, 44; 32, 45; 33, 46; 33, 47; 35, 48; 35, 49; 36, 50; 36, 51; 38, 52; 38, 53; 40, 54; 40, 55; 41, 56; 42, 57; 43, 58; 44, 59; 44, 60; 44, 61; 47, 62; 48, 63; 48, 64; 50, 65; 50, 66; 52, 67; 52, 68; 54, 69; 54, 70; 56, 71; 56, 72; 57, 73; 57, 74; 58, 75; 58, 76; 60, 77; 61, 78; 66, 79; 66, 80; 70, 81; 70, 82; 72, 83; 74, 84; 74, 85; 76, 86; 76, 87; 77, 88; 78, 89; 83, 90; 83, 91; 84, 92; 84, 93; 85, 94; 86, 95; 88, 96; 88, 97; 89, 98; 89, 99; 89, 100; 90, 101; 91, 102; 92, 103; 92, 104; 94, 105; 94, 106; 95, 107; 95, 108; 97, 109; 98, 110; 98, 111; 99, 112; 100, 113; 101, 114; 101, 115; 102, 116; 102, 117; 106, 118; 106, 119; 109, 120; 109, 121; 110, 122; 110, 123; 112, 124; 113, 125; 114, 126; 114, 127; 115, 128; 115, 129; 116, 130; 116, 131; 117, 132; 117, 133; 118, 134; 118, 135; 121, 136; 124, 137; 124, 138; 125, 139; 126, 140; 126, 141; 128, 142; 128, 143; 130, 144; 130, 145; 132, 146; 132, 147; 138, 148; 141, 149; 141, 150; 145, 151; 145, 152
def _linear_interp(curve, test_x, round_result=False): """ Take a series of points and interpolate between them at ``test_x``. Args: curve (list[tuple]): A list of ``(x, y)`` points sorted in nondecreasing ``x`` value. If multiple points have the same ``x`` value, all but the last will be ignored. test_x (float): The ``x`` value to find the ``y`` value of Returns: float: The ``y`` value of the curve at ``test_x`` if ``round_result is False`` int: if ``round_result is True`` or the result is a whole number, the ``y`` value of the curve at ``test_x`` rounded to the nearest whole number. Raises: ProbabilityUndefinedError: if ``test_x`` is out of the domain of ``curve`` Example: >>> curve = [(0, 0), (2, 1)] >>> _linear_interp(curve, 0.5) 0.25 >>> _linear_interp(curve, 0.5, round_result=True) 0 """ index = 0 for index in range(len(curve) - 1): # Ignore points which share an x value with the following point if curve[index][0] == curve[index + 1][0]: continue if curve[index][0] <= test_x <= curve[index + 1][0]: slope = ((curve[index + 1][1] - curve[index][1]) / (curve[index + 1][0] - curve[index][0])) y_intercept = curve[index][1] - (slope * curve[index][0]) result = (slope * test_x) + y_intercept if round_result: return int(round(result)) else: if result.is_integer(): return int(result) else: return result else: raise ProbabilityUndefinedError
0, module; 1, function_definition; 2, function_name:bound_weights; 3, parameters; 4, block; 5, identifier:weights; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, comment:# Copy weights to avoid side-effects; 10, expression_statement; 11, comment:# Remove weights outside of minimum and maximum; 12, if_statement; 13, comment:# If weights were removed, attach new endpoints where they would have; 14, comment:# appeared in the original curve; 15, if_statement; 16, if_statement; 17, return_statement; 18, identifier:minimum; 19, None; 20, identifier:maximum; 21, None; 22, comment:""" Bound a weight list so that all outcomes fit within specified bounds. The probability distribution within the ``minimum`` and ``maximum`` values remains the same. Weights in the list with outcomes outside of ``minimum`` and ``maximum`` are removed. If weights are removed from either end, attach weights at the modified edges at the same weight (y-axis) position they had interpolated in the original list. If neither ``minimum`` nor ``maximum`` are set, ``weights`` will be returned unmodified. If both are set, ``minimum`` must be less than ``maximum``. Args: weights (list): the list of weights where each weight is a ``tuple`` of form ``(float, float)`` corresponding to ``(outcome, weight)``. Must be sorted in increasing order of outcomes minimum (float): Lowest allowed outcome for the weight list maximum (float): Highest allowed outcome for the weight list Returns: list: A list of 2-tuples of form ``(float, float)``, the bounded weight list. Raises: ValueError: if ``maximum < minimum`` Example: >>> weights = [(0, 0), (2, 2), (4, 0)] >>> bound_weights(weights, 1, 3) [(1, 1), (2, 2), (3, 1)] """; 23, assignment; 24, boolean_operator; 25, block; 26, elif_clause; 27, elif_clause; 28, else_clause; 29, parenthesized_expression; 30, block; 31, parenthesized_expression; 32, block; 33, identifier:bounded_weights; 34, identifier:bounded_weights; 35, subscript; 36, comparison_operator:minimum is not None; 37, comparison_operator:maximum is not None; 38, if_statement; 39, expression_statement; 40, comparison_operator:minimum is not None; 41, block; 42, comparison_operator:maximum is not None; 43, block; 44, comment:# Both minimum and maximum are None - the bound list is the same; 45, comment:# as the original; 46, block; 47, boolean_operator; 48, expression_statement; 49, boolean_operator; 50, expression_statement; 51, identifier:weights; 52, slice; 53, identifier:minimum; 54, None; 55, identifier:maximum; 56, None; 57, comparison_operator:maximum < minimum; 58, block; 59, assignment; 60, identifier:minimum; 61, None; 62, expression_statement; 63, identifier:maximum; 64, None; 65, expression_statement; 66, return_statement; 67, comparison_operator:bounded_weights[0][0] > weights[0][0]; 68, comparison_operator:bounded_weights[0][0] != minimum; 69, call; 70, comparison_operator:bounded_weights[-1][0] < weights[-1][0]; 71, comparison_operator:bounded_weights[-1][0] != maximum; 72, call; 73, identifier:maximum; 74, identifier:minimum; 75, raise_statement; 76, identifier:bounded_weights; 77, list_comprehension; 78, assignment; 79, assignment; 80, identifier:bounded_weights; 81, subscript; 82, subscript; 83, subscript; 84, identifier:minimum; 85, attribute; 86, argument_list; 87, subscript; 88, subscript; 89, subscript; 90, identifier:maximum; 91, attribute; 92, argument_list; 93, identifier:ValueError; 94, identifier:bw; 95, for_in_clause; 96, if_clause; 97, identifier:bounded_weights; 98, list_comprehension; 99, identifier:bounded_weights; 100, list_comprehension; 101, subscript; 102, integer:0; 103, subscript; 104, integer:0; 105, subscript; 106, integer:0; 107, identifier:bounded_weights; 108, identifier:insert; 109, integer:0; 110, tuple; 111, subscript; 112, integer:0; 113, subscript; 114, integer:0; 115, subscript; 116, integer:0; 117, identifier:bounded_weights; 118, identifier:append; 119, tuple; 120, identifier:bw; 121, identifier:bounded_weights; 122, comparison_operator:minimum <= bw[0] <= maximum; 123, identifier:bw; 124, for_in_clause; 125, if_clause; 126, identifier:bw; 127, for_in_clause; 128, if_clause; 129, identifier:bounded_weights; 130, integer:0; 131, identifier:weights; 132, integer:0; 133, identifier:bounded_weights; 134, integer:0; 135, identifier:minimum; 136, call; 137, identifier:bounded_weights; 138, unary_operator; 139, identifier:weights; 140, unary_operator; 141, identifier:bounded_weights; 142, unary_operator; 143, identifier:maximum; 144, call; 145, identifier:minimum; 146, subscript; 147, identifier:maximum; 148, identifier:bw; 149, identifier:bounded_weights; 150, comparison_operator:minimum <= bw[0]; 151, identifier:bw; 152, identifier:bounded_weights; 153, comparison_operator:bw[0] <= maximum; 154, identifier:_linear_interp; 155, argument_list; 156, integer:1; 157, integer:1; 158, integer:1; 159, identifier:_linear_interp; 160, argument_list; 161, identifier:bw; 162, integer:0; 163, identifier:minimum; 164, subscript; 165, subscript; 166, identifier:maximum; 167, identifier:weights; 168, identifier:minimum; 169, identifier:weights; 170, identifier:maximum; 171, identifier:bw; 172, integer:0; 173, identifier:bw; 174, integer:0
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; 6, 18; 6, 19; 7, 20; 7, 21; 8, 22; 10, 23; 12, 24; 12, 25; 12, 26; 12, 27; 12, 28; 15, 29; 15, 30; 16, 31; 16, 32; 17, 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; 28, 46; 29, 47; 30, 48; 31, 49; 32, 50; 35, 51; 35, 52; 36, 53; 36, 54; 37, 55; 37, 56; 38, 57; 38, 58; 39, 59; 40, 60; 40, 61; 41, 62; 42, 63; 42, 64; 43, 65; 46, 66; 47, 67; 47, 68; 48, 69; 49, 70; 49, 71; 50, 72; 57, 73; 57, 74; 58, 75; 59, 76; 59, 77; 62, 78; 65, 79; 66, 80; 67, 81; 67, 82; 68, 83; 68, 84; 69, 85; 69, 86; 70, 87; 70, 88; 71, 89; 71, 90; 72, 91; 72, 92; 75, 93; 77, 94; 77, 95; 77, 96; 78, 97; 78, 98; 79, 99; 79, 100; 81, 101; 81, 102; 82, 103; 82, 104; 83, 105; 83, 106; 85, 107; 85, 108; 86, 109; 86, 110; 87, 111; 87, 112; 88, 113; 88, 114; 89, 115; 89, 116; 91, 117; 91, 118; 92, 119; 95, 120; 95, 121; 96, 122; 98, 123; 98, 124; 98, 125; 100, 126; 100, 127; 100, 128; 101, 129; 101, 130; 103, 131; 103, 132; 105, 133; 105, 134; 110, 135; 110, 136; 111, 137; 111, 138; 113, 139; 113, 140; 115, 141; 115, 142; 119, 143; 119, 144; 122, 145; 122, 146; 122, 147; 124, 148; 124, 149; 125, 150; 127, 151; 127, 152; 128, 153; 136, 154; 136, 155; 138, 156; 140, 157; 142, 158; 144, 159; 144, 160; 146, 161; 146, 162; 150, 163; 150, 164; 153, 165; 153, 166; 155, 167; 155, 168; 160, 169; 160, 170; 164, 171; 164, 172; 165, 173; 165, 174
def bound_weights(weights, minimum=None, maximum=None): """ Bound a weight list so that all outcomes fit within specified bounds. The probability distribution within the ``minimum`` and ``maximum`` values remains the same. Weights in the list with outcomes outside of ``minimum`` and ``maximum`` are removed. If weights are removed from either end, attach weights at the modified edges at the same weight (y-axis) position they had interpolated in the original list. If neither ``minimum`` nor ``maximum`` are set, ``weights`` will be returned unmodified. If both are set, ``minimum`` must be less than ``maximum``. Args: weights (list): the list of weights where each weight is a ``tuple`` of form ``(float, float)`` corresponding to ``(outcome, weight)``. Must be sorted in increasing order of outcomes minimum (float): Lowest allowed outcome for the weight list maximum (float): Highest allowed outcome for the weight list Returns: list: A list of 2-tuples of form ``(float, float)``, the bounded weight list. Raises: ValueError: if ``maximum < minimum`` Example: >>> weights = [(0, 0), (2, 2), (4, 0)] >>> bound_weights(weights, 1, 3) [(1, 1), (2, 2), (3, 1)] """ # Copy weights to avoid side-effects bounded_weights = weights[:] # Remove weights outside of minimum and maximum if minimum is not None and maximum is not None: if maximum < minimum: raise ValueError bounded_weights = [bw for bw in bounded_weights if minimum <= bw[0] <= maximum] elif minimum is not None: bounded_weights = [bw for bw in bounded_weights if minimum <= bw[0]] elif maximum is not None: bounded_weights = [bw for bw in bounded_weights if bw[0] <= maximum] else: # Both minimum and maximum are None - the bound list is the same # as the original return bounded_weights # If weights were removed, attach new endpoints where they would have # appeared in the original curve if (bounded_weights[0][0] > weights[0][0] and bounded_weights[0][0] != minimum): bounded_weights.insert(0, (minimum, _linear_interp(weights, minimum))) if (bounded_weights[-1][0] < weights[-1][0] and bounded_weights[-1][0] != maximum): bounded_weights.append((maximum, _linear_interp(weights, maximum))) return bounded_weights
0, module; 1, function_definition; 2, function_name:weighted_rand; 3, parameters; 4, block; 5, identifier:weights; 6, default_parameter; 7, expression_statement; 8, comment:# If just one weight is passed, simply return the weight's name; 9, if_statement; 10, comment:# Is there a way to do this more efficiently? Maybe even require that; 11, comment:# ``weights`` already be sorted?; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, comment:# Roll random numbers until a valid one is found; 18, expression_statement; 19, while_statement; 20, identifier:round_result; 21, False; 22, comment:""" Generate a non-uniform random value based on a list of weight tuples. Treats weights as coordinates for a probability distribution curve and rolls accordingly. Constructs a piece-wise linear curve according to coordinates given in ``weights`` and rolls random values in the curve's bounding box until a value is found under the curve Weight tuples should be of the form: (outcome, strength). Args: weights: (list): the list of weights where each weight is a tuple of form ``(float, float)`` corresponding to ``(outcome, strength)``. Weights with strength ``0`` or less will have no chance to be rolled. The list must be sorted in increasing order of outcomes. round_result (bool): Whether or not to round the resulting value to the nearest integer. Returns: float: A weighted random number int: A weighted random number rounded to the nearest ``int`` Example: >>> weighted_rand([(-3, 4), (0, 10), (5, 1)]) # doctest: +SKIP -0.650612268193731 >>> weighted_rand([(-3, 4), (0, 10), (5, 1)]) # doctest: +SKIP -2 """; 23, comparison_operator:len(weights) == 1; 24, block; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, comparison_operator:attempt_count < 500000; 32, comment:# Get sample point; 33, block; 34, else_clause; 35, call; 36, integer:1; 37, return_statement; 38, identifier:weights; 39, call; 40, identifier:x_min; 41, subscript; 42, identifier:x_max; 43, subscript; 44, identifier:y_min; 45, integer:0; 46, identifier:y_max; 47, call; 48, identifier:attempt_count; 49, integer:0; 50, identifier:attempt_count; 51, integer:500000; 52, expression_statement; 53, if_statement; 54, expression_statement; 55, block; 56, identifier:len; 57, argument_list; 58, subscript; 59, identifier:sorted; 60, argument_list; 61, subscript; 62, integer:0; 63, subscript; 64, integer:0; 65, identifier:max; 66, argument_list; 67, assignment; 68, call; 69, comment:# The sample point is under the curve; 70, block; 71, augmented_assignment; 72, expression_statement; 73, return_statement; 74, identifier:weights; 75, subscript; 76, integer:0; 77, identifier:weights; 78, keyword_argument; 79, identifier:weights; 80, integer:0; 81, identifier:weights; 82, unary_operator; 83, list_comprehension; 84, identifier:sample; 85, tuple; 86, identifier:_point_under_curve; 87, argument_list; 88, if_statement; 89, identifier:attempt_count; 90, integer:1; 91, call; 92, subscript; 93, identifier:weights; 94, integer:0; 95, identifier:key; 96, lambda; 97, integer:1; 98, subscript; 99, for_in_clause; 100, call; 101, call; 102, identifier:weights; 103, identifier:sample; 104, identifier:round_result; 105, block; 106, else_clause; 107, attribute; 108, argument_list; 109, call; 110, integer:0; 111, lambda_parameters; 112, subscript; 113, identifier:point; 114, integer:1; 115, identifier:point; 116, identifier:weights; 117, attribute; 118, argument_list; 119, attribute; 120, argument_list; 121, return_statement; 122, block; 123, identifier:warnings; 124, identifier:warn; 125, concatenated_string; 126, attribute; 127, argument_list; 128, identifier:w; 129, identifier:w; 130, integer:0; 131, identifier:random; 132, identifier:uniform; 133, identifier:x_min; 134, identifier:x_max; 135, identifier:random; 136, identifier:uniform; 137, identifier:y_min; 138, identifier:y_max; 139, call; 140, return_statement; 141, string; 142, string; 143, string; 144, identifier:random; 145, identifier:choice; 146, identifier:weights; 147, identifier:int; 148, argument_list; 149, subscript; 150, string_content:Point not being found in weighted_rand() after 500000; 151, string_content:attempts, defaulting to a random weight point.; 152, string_content:If this happens often, it is probably a bug.; 153, call; 154, identifier:sample; 155, integer:0; 156, identifier:round; 157, argument_list; 158, subscript; 159, identifier:sample; 160, integer:0
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; 9, 23; 9, 24; 12, 25; 13, 26; 14, 27; 15, 28; 16, 29; 18, 30; 19, 31; 19, 32; 19, 33; 19, 34; 23, 35; 23, 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; 33, 54; 34, 55; 35, 56; 35, 57; 37, 58; 39, 59; 39, 60; 41, 61; 41, 62; 43, 63; 43, 64; 47, 65; 47, 66; 52, 67; 53, 68; 53, 69; 53, 70; 54, 71; 55, 72; 55, 73; 57, 74; 58, 75; 58, 76; 60, 77; 60, 78; 61, 79; 61, 80; 63, 81; 63, 82; 66, 83; 67, 84; 67, 85; 68, 86; 68, 87; 70, 88; 71, 89; 71, 90; 72, 91; 73, 92; 75, 93; 75, 94; 78, 95; 78, 96; 82, 97; 83, 98; 83, 99; 85, 100; 85, 101; 87, 102; 87, 103; 88, 104; 88, 105; 88, 106; 91, 107; 91, 108; 92, 109; 92, 110; 96, 111; 96, 112; 98, 113; 98, 114; 99, 115; 99, 116; 100, 117; 100, 118; 101, 119; 101, 120; 105, 121; 106, 122; 107, 123; 107, 124; 108, 125; 109, 126; 109, 127; 111, 128; 112, 129; 112, 130; 117, 131; 117, 132; 118, 133; 118, 134; 119, 135; 119, 136; 120, 137; 120, 138; 121, 139; 122, 140; 125, 141; 125, 142; 125, 143; 126, 144; 126, 145; 127, 146; 139, 147; 139, 148; 140, 149; 141, 150; 142, 151; 143, 152; 148, 153; 149, 154; 149, 155; 153, 156; 153, 157; 157, 158; 158, 159; 158, 160
def weighted_rand(weights, round_result=False): """ Generate a non-uniform random value based on a list of weight tuples. Treats weights as coordinates for a probability distribution curve and rolls accordingly. Constructs a piece-wise linear curve according to coordinates given in ``weights`` and rolls random values in the curve's bounding box until a value is found under the curve Weight tuples should be of the form: (outcome, strength). Args: weights: (list): the list of weights where each weight is a tuple of form ``(float, float)`` corresponding to ``(outcome, strength)``. Weights with strength ``0`` or less will have no chance to be rolled. The list must be sorted in increasing order of outcomes. round_result (bool): Whether or not to round the resulting value to the nearest integer. Returns: float: A weighted random number int: A weighted random number rounded to the nearest ``int`` Example: >>> weighted_rand([(-3, 4), (0, 10), (5, 1)]) # doctest: +SKIP -0.650612268193731 >>> weighted_rand([(-3, 4), (0, 10), (5, 1)]) # doctest: +SKIP -2 """ # If just one weight is passed, simply return the weight's name if len(weights) == 1: return weights[0][0] # Is there a way to do this more efficiently? Maybe even require that # ``weights`` already be sorted? weights = sorted(weights, key=lambda w: w[0]) x_min = weights[0][0] x_max = weights[-1][0] y_min = 0 y_max = max([point[1] for point in weights]) # Roll random numbers until a valid one is found attempt_count = 0 while attempt_count < 500000: # Get sample point sample = (random.uniform(x_min, x_max), random.uniform(y_min, y_max)) if _point_under_curve(weights, sample): # The sample point is under the curve if round_result: return int(round(sample[0])) else: return sample[0] attempt_count += 1 else: warnings.warn( 'Point not being found in weighted_rand() after 500000 ' 'attempts, defaulting to a random weight point. ' 'If this happens often, it is probably a bug.') return random.choice(weights)[0]
0, module; 1, function_definition; 2, function_name:_cmp_key; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:obj; 13, None; 14, comment:"""Comparison key for sorting results from all linters. The sort should group files and lines from different linters to make it easier for refactoring. """; 15, not_operator; 16, block; 17, assignment; 18, assignment; 19, tuple; 20, identifier:obj; 21, expression_statement; 22, identifier:line_nr; 23, conditional_expression:int(obj.line_nr) if obj.line_nr else 0; 24, identifier:col; 25, conditional_expression:int(obj.col) if obj.col else 0; 26, attribute; 27, identifier:line_nr; 28, identifier:col; 29, attribute; 30, assignment; 31, call; 32, attribute; 33, integer:0; 34, call; 35, attribute; 36, integer:0; 37, identifier:obj; 38, identifier:path; 39, identifier:obj; 40, identifier:msg; 41, identifier:obj; 42, identifier:self; 43, identifier:int; 44, argument_list; 45, identifier:obj; 46, identifier:line_nr; 47, identifier:int; 48, argument_list; 49, identifier:obj; 50, identifier:col; 51, attribute; 52, attribute; 53, identifier:obj; 54, identifier:line_nr; 55, identifier:obj; 56, identifier:col
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; 8, 16; 9, 17; 10, 18; 11, 19; 15, 20; 16, 21; 17, 22; 17, 23; 18, 24; 18, 25; 19, 26; 19, 27; 19, 28; 19, 29; 21, 30; 23, 31; 23, 32; 23, 33; 25, 34; 25, 35; 25, 36; 26, 37; 26, 38; 29, 39; 29, 40; 30, 41; 30, 42; 31, 43; 31, 44; 32, 45; 32, 46; 34, 47; 34, 48; 35, 49; 35, 50; 44, 51; 48, 52; 51, 53; 51, 54; 52, 55; 52, 56
def _cmp_key(self, obj=None): """Comparison key for sorting results from all linters. The sort should group files and lines from different linters to make it easier for refactoring. """ if not obj: obj = self line_nr = int(obj.line_nr) if obj.line_nr else 0 col = int(obj.col) if obj.col else 0 return (obj.path, line_nr, col, obj.msg)
0, module; 1, function_definition; 2, function_name:_create_output_from_match; 3, parameters; 4, block; 5, identifier:self; 6, identifier:match_result; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:"""As isort outputs full path, we change it to relative path."""; 12, assignment; 13, assignment; 14, call; 15, identifier:full_path; 16, subscript; 17, identifier:path; 18, call; 19, identifier:LinterOutput; 20, argument_list; 21, identifier:match_result; 22, string; 23, attribute; 24, argument_list; 25, attribute; 26, identifier:path; 27, subscript; 28, string_content:full_path; 29, identifier:self; 30, identifier:_get_relative_path; 31, identifier:full_path; 32, identifier:self; 33, identifier:name; 34, identifier:match_result; 35, string; 36, string_content:msg
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; 12, 15; 12, 16; 13, 17; 13, 18; 14, 19; 14, 20; 16, 21; 16, 22; 18, 23; 18, 24; 20, 25; 20, 26; 20, 27; 22, 28; 23, 29; 23, 30; 24, 31; 25, 32; 25, 33; 27, 34; 27, 35; 35, 36
def _create_output_from_match(self, match_result): """As isort outputs full path, we change it to relative path.""" full_path = match_result['full_path'] path = self._get_relative_path(full_path) return LinterOutput(self.name, path, match_result['msg'])
0, module; 1, function_definition; 2, function_name:get_cached_filename; 3, parameters; 4, block; 5, identifier:self; 6, identifier:filename; 7, identifier:extention; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:settings_list; 13, None; 14, comment:"""Creates a filename with md5 cache string based on settings list Args: filename (str): the filename without extention extention (str): the file extention without dot. (i.e. 'pkl') settings_list (dict|list): the settings list as list (optional) NB! The dictionaries have to be sorted or hash id will change arbitrarely. """; 15, assignment; 16, call; 17, identifier:cached_name; 18, call; 19, attribute; 20, argument_list; 21, attribute; 22, argument_list; 23, string:"."; 24, identifier:join; 25, list; 26, string:"_"; 27, identifier:join; 28, list; 29, identifier:cached_name; 30, identifier:extention; 31, identifier:filename; 32, call; 33, attribute; 34, argument_list; 35, identifier:self; 36, identifier:get_hash
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 8, 12; 8, 13; 9, 14; 10, 15; 11, 16; 15, 17; 15, 18; 16, 19; 16, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 21, 26; 21, 27; 22, 28; 25, 29; 25, 30; 28, 31; 28, 32; 32, 33; 32, 34; 33, 35; 33, 36
def get_cached_filename(self, filename, extention, settings_list=None): """Creates a filename with md5 cache string based on settings list Args: filename (str): the filename without extention extention (str): the file extention without dot. (i.e. 'pkl') settings_list (dict|list): the settings list as list (optional) NB! The dictionaries have to be sorted or hash id will change arbitrarely. """ cached_name = "_".join([filename, self.get_hash()]) return ".".join([cached_name, extention])
0, module; 1, function_definition; 2, function_name:sort_func; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, expression_statement; 8, return_statement; 9, identifier:variant; 10, identifier:VARIANT1; 11, identifier:case_sensitive; 12, False; 13, comment:"""A function generator that can be used for sorting. All keywords are passed to `normalize()` and generate keywords that can be passed to `sorted()`:: >>> key = sort_func() >>> print(sorted(["fur", "far"], key=key)) [u'far', u'fur'] Please note, that `sort_func` returns a function. """; 14, lambda; 15, lambda_parameters; 16, call; 17, identifier:x; 18, identifier:normalize; 19, argument_list; 20, identifier:x; 21, keyword_argument; 22, keyword_argument; 23, identifier:variant; 24, identifier:variant; 25, identifier:case_sensitive; 26, identifier:case_sensitive
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 5, 9; 5, 10; 6, 11; 6, 12; 7, 13; 8, 14; 14, 15; 14, 16; 15, 17; 16, 18; 16, 19; 19, 20; 19, 21; 19, 22; 21, 23; 21, 24; 22, 25; 22, 26
def sort_func(variant=VARIANT1, case_sensitive=False): """A function generator that can be used for sorting. All keywords are passed to `normalize()` and generate keywords that can be passed to `sorted()`:: >>> key = sort_func() >>> print(sorted(["fur", "far"], key=key)) [u'far', u'fur'] Please note, that `sort_func` returns a function. """ return lambda x: normalize( x, variant=variant, case_sensitive=case_sensitive)
0, module; 1, function_definition; 2, function_name:_notify_reader_writes; 3, parameters; 4, block; 5, identifier:writeto; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:"""Notify reader closures about these writes and return a sorted list of thus-satisfied closures. """; 11, assignment; 12, identifier:var; 13, identifier:writeto; 14, block; 15, call; 16, identifier:satisfied; 17, list; 18, if_statement; 19, attribute; 20, argument_list; 21, attribute; 22, block; 23, identifier:Closure; 24, identifier:sort; 25, identifier:satisfied; 26, identifier:var; 27, identifier:readable; 28, for_statement; 29, identifier:reader; 30, attribute; 31, block; 32, identifier:var; 33, identifier:readers; 34, expression_statement; 35, if_statement; 36, call; 37, attribute; 38, block; 39, attribute; 40, argument_list; 41, identifier:reader; 42, identifier:satisfied; 43, expression_statement; 44, identifier:reader; 45, identifier:notify_read_ready; 46, call; 47, attribute; 48, argument_list; 49, identifier:satisfied; 50, identifier:append; 51, identifier:reader
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; 15, 19; 15, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 21, 26; 21, 27; 22, 28; 28, 29; 28, 30; 28, 31; 30, 32; 30, 33; 31, 34; 31, 35; 34, 36; 35, 37; 35, 38; 36, 39; 36, 40; 37, 41; 37, 42; 38, 43; 39, 44; 39, 45; 43, 46; 46, 47; 46, 48; 47, 49; 47, 50; 48, 51
def _notify_reader_writes(writeto): """Notify reader closures about these writes and return a sorted list of thus-satisfied closures. """ satisfied = [] for var in writeto: if var.readable: for reader in var.readers: reader.notify_read_ready() if reader.satisfied: satisfied.append(reader) return Closure.sort(satisfied)
0, module; 1, function_definition; 2, function_name:getFilePathsWithExtensionsInDirectory; 3, parameters; 4, block; 5, identifier:dirTree; 6, identifier:patterns; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, if_statement; 12, return_statement; 13, identifier:sort; 14, True; 15, comment:""" Returns all file paths that match any one of patterns in a file tree with its root at dirTree. Sorts the paths by default. """; 16, assignment; 17, pattern_list; 18, call; 19, block; 20, identifier:sort; 21, block; 22, identifier:filePaths; 23, identifier:filePaths; 24, list; 25, identifier:root; 26, identifier:dirs; 27, identifier:files; 28, attribute; 29, argument_list; 30, for_statement; 31, expression_statement; 32, identifier:os; 33, identifier:walk; 34, identifier:dirTree; 35, identifier:filePath; 36, identifier:files; 37, block; 38, call; 39, for_statement; 40, attribute; 41, argument_list; 42, identifier:pattern; 43, identifier:patterns; 44, block; 45, identifier:filePaths; 46, identifier:sort; 47, if_statement; 48, call; 49, block; 50, attribute; 51, argument_list; 52, expression_statement; 53, expression_statement; 54, break_statement; 55, identifier:fnmatch; 56, identifier:fnmatch; 57, identifier:filePath; 58, identifier:pattern; 59, assignment; 60, call; 61, identifier:fullPath; 62, call; 63, attribute; 64, argument_list; 65, attribute; 66, argument_list; 67, identifier:filePaths; 68, identifier:append; 69, identifier:fullPath; 70, attribute; 71, identifier:join; 72, identifier:root; 73, identifier:filePath; 74, identifier:os; 75, identifier:path
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 7, 14; 8, 15; 9, 16; 10, 17; 10, 18; 10, 19; 11, 20; 11, 21; 12, 22; 16, 23; 16, 24; 17, 25; 17, 26; 17, 27; 18, 28; 18, 29; 19, 30; 21, 31; 28, 32; 28, 33; 29, 34; 30, 35; 30, 36; 30, 37; 31, 38; 37, 39; 38, 40; 38, 41; 39, 42; 39, 43; 39, 44; 40, 45; 40, 46; 44, 47; 47, 48; 47, 49; 48, 50; 48, 51; 49, 52; 49, 53; 49, 54; 50, 55; 50, 56; 51, 57; 51, 58; 52, 59; 53, 60; 59, 61; 59, 62; 60, 63; 60, 64; 62, 65; 62, 66; 63, 67; 63, 68; 64, 69; 65, 70; 65, 71; 66, 72; 66, 73; 70, 74; 70, 75
def getFilePathsWithExtensionsInDirectory(dirTree, patterns, sort=True): """ Returns all file paths that match any one of patterns in a file tree with its root at dirTree. Sorts the paths by default. """ filePaths = [] for root, dirs, files in os.walk(dirTree): for filePath in files: for pattern in patterns: if fnmatch.fnmatch(filePath, pattern): fullPath = os.path.join(root, filePath) filePaths.append(fullPath) break if sort: filePaths.sort() return filePaths
0, module; 1, function_definition; 2, function_name:shellsort; 3, parameters; 4, block; 5, identifier:inlist; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# integer division needed; 12, while_statement; 13, comment:# svec is now sorted inlist, and ivec has the order svec[i] = vec[ivec[i]]; 14, return_statement; 15, comment:""" Shellsort algorithm. Sorts a 1D-list. Usage: lshellsort(inlist) Returns: sorted-inlist, sorting-index-vector (for original list) """; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, comparison_operator:gap > 0; 21, block; 22, expression_list; 23, identifier:n; 24, call; 25, identifier:svec; 26, call; 27, identifier:ivec; 28, call; 29, identifier:gap; 30, binary_operator:n / 2; 31, identifier:gap; 32, integer:0; 33, for_statement; 34, expression_statement; 35, comment:# integer division needed; 36, identifier:svec; 37, identifier:ivec; 38, identifier:len; 39, argument_list; 40, attribute; 41, argument_list; 42, identifier:range; 43, argument_list; 44, identifier:n; 45, integer:2; 46, identifier:i; 47, call; 48, block; 49, assignment; 50, identifier:inlist; 51, identifier:copy; 52, identifier:deepcopy; 53, identifier:inlist; 54, identifier:n; 55, identifier:range; 56, argument_list; 57, for_statement; 58, identifier:gap; 59, binary_operator:gap / 2; 60, identifier:gap; 61, identifier:n; 62, identifier:j; 63, call; 64, block; 65, identifier:gap; 66, integer:2; 67, identifier:range; 68, argument_list; 69, while_statement; 70, binary_operator:i - gap; 71, unary_operator; 72, unary_operator; 73, boolean_operator; 74, block; 75, identifier:i; 76, identifier:gap; 77, integer:1; 78, identifier:gap; 79, comparison_operator:j >= 0; 80, comparison_operator:svec[j] > svec[j + gap]; 81, expression_statement; 82, expression_statement; 83, expression_statement; 84, expression_statement; 85, expression_statement; 86, expression_statement; 87, identifier:j; 88, integer:0; 89, subscript; 90, subscript; 91, assignment; 92, assignment; 93, assignment; 94, assignment; 95, assignment; 96, assignment; 97, identifier:svec; 98, identifier:j; 99, identifier:svec; 100, binary_operator:j + gap; 101, identifier:temp; 102, subscript; 103, subscript; 104, subscript; 105, subscript; 106, identifier:temp; 107, identifier:itemp; 108, subscript; 109, subscript; 110, subscript; 111, subscript; 112, identifier:itemp; 113, identifier:j; 114, identifier:gap; 115, identifier:svec; 116, identifier:j; 117, identifier:svec; 118, identifier:j; 119, identifier:svec; 120, binary_operator:j + gap; 121, identifier:svec; 122, binary_operator:j + gap; 123, identifier:ivec; 124, identifier:j; 125, identifier:ivec; 126, identifier:j; 127, identifier:ivec; 128, binary_operator:j + gap; 129, identifier:ivec; 130, binary_operator:j + gap; 131, identifier:j; 132, identifier:gap; 133, identifier:j; 134, identifier:gap; 135, identifier:j; 136, identifier:gap; 137, identifier:j; 138, identifier:gap
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; 9, 18; 10, 19; 12, 20; 12, 21; 14, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 20, 31; 20, 32; 21, 33; 21, 34; 21, 35; 22, 36; 22, 37; 24, 38; 24, 39; 26, 40; 26, 41; 28, 42; 28, 43; 30, 44; 30, 45; 33, 46; 33, 47; 33, 48; 34, 49; 39, 50; 40, 51; 40, 52; 41, 53; 43, 54; 47, 55; 47, 56; 48, 57; 49, 58; 49, 59; 56, 60; 56, 61; 57, 62; 57, 63; 57, 64; 59, 65; 59, 66; 63, 67; 63, 68; 64, 69; 68, 70; 68, 71; 68, 72; 69, 73; 69, 74; 70, 75; 70, 76; 71, 77; 72, 78; 73, 79; 73, 80; 74, 81; 74, 82; 74, 83; 74, 84; 74, 85; 74, 86; 79, 87; 79, 88; 80, 89; 80, 90; 81, 91; 82, 92; 83, 93; 84, 94; 85, 95; 86, 96; 89, 97; 89, 98; 90, 99; 90, 100; 91, 101; 91, 102; 92, 103; 92, 104; 93, 105; 93, 106; 94, 107; 94, 108; 95, 109; 95, 110; 96, 111; 96, 112; 100, 113; 100, 114; 102, 115; 102, 116; 103, 117; 103, 118; 104, 119; 104, 120; 105, 121; 105, 122; 108, 123; 108, 124; 109, 125; 109, 126; 110, 127; 110, 128; 111, 129; 111, 130; 120, 131; 120, 132; 122, 133; 122, 134; 128, 135; 128, 136; 130, 137; 130, 138
def shellsort(inlist): """ Shellsort algorithm. Sorts a 1D-list. Usage: lshellsort(inlist) Returns: sorted-inlist, sorting-index-vector (for original list) """ n = len(inlist) svec = copy.deepcopy(inlist) ivec = range(n) gap = n / 2 # integer division needed while gap > 0: for i in range(gap, n): for j in range(i - gap, -1, -gap): while j >= 0 and svec[j] > svec[j + gap]: temp = svec[j] svec[j] = svec[j + gap] svec[j + gap] = temp itemp = ivec[j] ivec[j] = ivec[j + gap] ivec[j + gap] = itemp gap = gap / 2 # integer division needed # svec is now sorted inlist, and ivec has the order svec[i] = vec[ivec[i]] return svec, ivec
0, module; 1, function_definition; 2, function_name:rankdata; 3, parameters; 4, block; 5, identifier:inlist; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, return_statement; 14, comment:""" Ranks the data in inlist, dealing with ties appropritely. Assumes a 1D inlist. Adapted from Gary Perlman's |Stat ranksort. Usage: rankdata(inlist) Returns: a list of length equal to inlist, containing rank scores """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, identifier:i; 21, call; 22, block; 23, identifier:newlist; 24, identifier:n; 25, call; 26, pattern_list; 27, call; 28, identifier:sumranks; 29, integer:0; 30, identifier:dupcount; 31, integer:0; 32, identifier:newlist; 33, binary_operator:[0] * n; 34, identifier:range; 35, argument_list; 36, expression_statement; 37, expression_statement; 38, if_statement; 39, identifier:len; 40, argument_list; 41, identifier:svec; 42, identifier:ivec; 43, identifier:shellsort; 44, argument_list; 45, list; 46, identifier:n; 47, identifier:n; 48, assignment; 49, assignment; 50, boolean_operator; 51, block; 52, identifier:inlist; 53, identifier:inlist; 54, integer:0; 55, identifier:sumranks; 56, binary_operator:sumranks + i; 57, identifier:dupcount; 58, binary_operator:dupcount + 1; 59, comparison_operator:i == n - 1; 60, comparison_operator:svec[i] != svec[i + 1]; 61, expression_statement; 62, for_statement; 63, expression_statement; 64, expression_statement; 65, identifier:sumranks; 66, identifier:i; 67, identifier:dupcount; 68, integer:1; 69, identifier:i; 70, binary_operator:n - 1; 71, subscript; 72, subscript; 73, assignment; 74, identifier:j; 75, call; 76, block; 77, assignment; 78, assignment; 79, identifier:n; 80, integer:1; 81, identifier:svec; 82, identifier:i; 83, identifier:svec; 84, binary_operator:i + 1; 85, identifier:averank; 86, binary_operator:sumranks / float(dupcount) + 1; 87, identifier:range; 88, argument_list; 89, expression_statement; 90, identifier:sumranks; 91, integer:0; 92, identifier:dupcount; 93, integer:0; 94, identifier:i; 95, integer:1; 96, binary_operator:sumranks / float(dupcount); 97, integer:1; 98, binary_operator:i - dupcount + 1; 99, binary_operator:i + 1; 100, assignment; 101, identifier:sumranks; 102, call; 103, binary_operator:i - dupcount; 104, integer:1; 105, identifier:i; 106, integer:1; 107, subscript; 108, identifier:averank; 109, identifier:float; 110, argument_list; 111, identifier:i; 112, identifier:dupcount; 113, identifier:newlist; 114, subscript; 115, identifier:dupcount; 116, identifier:ivec; 117, identifier:j
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 7, 15; 8, 16; 9, 17; 10, 18; 11, 19; 12, 20; 12, 21; 12, 22; 13, 23; 15, 24; 15, 25; 16, 26; 16, 27; 17, 28; 17, 29; 18, 30; 18, 31; 19, 32; 19, 33; 21, 34; 21, 35; 22, 36; 22, 37; 22, 38; 25, 39; 25, 40; 26, 41; 26, 42; 27, 43; 27, 44; 33, 45; 33, 46; 35, 47; 36, 48; 37, 49; 38, 50; 38, 51; 40, 52; 44, 53; 45, 54; 48, 55; 48, 56; 49, 57; 49, 58; 50, 59; 50, 60; 51, 61; 51, 62; 51, 63; 51, 64; 56, 65; 56, 66; 58, 67; 58, 68; 59, 69; 59, 70; 60, 71; 60, 72; 61, 73; 62, 74; 62, 75; 62, 76; 63, 77; 64, 78; 70, 79; 70, 80; 71, 81; 71, 82; 72, 83; 72, 84; 73, 85; 73, 86; 75, 87; 75, 88; 76, 89; 77, 90; 77, 91; 78, 92; 78, 93; 84, 94; 84, 95; 86, 96; 86, 97; 88, 98; 88, 99; 89, 100; 96, 101; 96, 102; 98, 103; 98, 104; 99, 105; 99, 106; 100, 107; 100, 108; 102, 109; 102, 110; 103, 111; 103, 112; 107, 113; 107, 114; 110, 115; 114, 116; 114, 117
def rankdata(inlist): """ Ranks the data in inlist, dealing with ties appropritely. Assumes a 1D inlist. Adapted from Gary Perlman's |Stat ranksort. Usage: rankdata(inlist) Returns: a list of length equal to inlist, containing rank scores """ n = len(inlist) svec, ivec = shellsort(inlist) sumranks = 0 dupcount = 0 newlist = [0] * n for i in range(n): sumranks = sumranks + i dupcount = dupcount + 1 if i == n - 1 or svec[i] != svec[i + 1]: averank = sumranks / float(dupcount) + 1 for j in range(i - dupcount + 1, i + 1): newlist[ivec[j]] = averank sumranks = 0 dupcount = 0 return newlist
0, module; 1, function_definition; 2, function_name:to_json; 3, parameters; 4, block; 5, identifier:self; 6, keyword_separator; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, return_statement; 11, identifier:indent; 12, None; 13, identifier:sort_keys; 14, False; 15, comment:"""Gets the object's JSON representation. Parameters ---------- indent: :class:`int`, optional Number of spaces used as indentation, ``None`` will return the shortest possible string. sort_keys: :class:`bool`, optional Whether keys should be sorted alphabetically or preserve the order defined by the object. Returns ------- :class:`str` JSON representation of the object. """; 16, call; 17, attribute; 18, argument_list; 19, identifier:json; 20, identifier:dumps; 21, dictionary_comprehension; 22, keyword_argument; 23, keyword_argument; 24, keyword_argument; 25, pair; 26, for_in_clause; 27, if_clause; 28, identifier:indent; 29, identifier:indent; 30, identifier:sort_keys; 31, identifier:sort_keys; 32, identifier:default; 33, attribute; 34, identifier:k; 35, identifier:v; 36, pattern_list; 37, call; 38, comparison_operator:v is not None; 39, identifier:self; 40, identifier:_try_dict; 41, identifier:k; 42, identifier:v; 43, attribute; 44, argument_list; 45, identifier:v; 46, None; 47, call; 48, identifier:items; 49, identifier:dict; 50, argument_list; 51, identifier:self
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 7, 11; 7, 12; 8, 13; 8, 14; 9, 15; 10, 16; 16, 17; 16, 18; 17, 19; 17, 20; 18, 21; 18, 22; 18, 23; 18, 24; 21, 25; 21, 26; 21, 27; 22, 28; 22, 29; 23, 30; 23, 31; 24, 32; 24, 33; 25, 34; 25, 35; 26, 36; 26, 37; 27, 38; 33, 39; 33, 40; 36, 41; 36, 42; 37, 43; 37, 44; 38, 45; 38, 46; 43, 47; 43, 48; 47, 49; 47, 50; 50, 51
def to_json(self, *, indent=None, sort_keys = False): """Gets the object's JSON representation. Parameters ---------- indent: :class:`int`, optional Number of spaces used as indentation, ``None`` will return the shortest possible string. sort_keys: :class:`bool`, optional Whether keys should be sorted alphabetically or preserve the order defined by the object. Returns ------- :class:`str` JSON representation of the object. """ return json.dumps({k: v for k, v in dict(self).items() if v is not None}, indent=indent, sort_keys=sort_keys, default=self._try_dict)
0, module; 1, function_definition; 2, function_name:get_sort_field; 3, parameters; 4, block; 5, identifier:attr; 6, identifier:model; 7, expression_statement; 8, try_statement; 9, comment:""" Get's the field to sort on for the given attr. Currently returns attr if it is a field on the given model. If the models has an attribute matching that name and that value has an attribute 'sort_field' than that value is used. TODO: Provide a way to sort based on a non field attribute. """; 10, block; 11, except_clause; 12, if_statement; 13, identifier:FieldDoesNotExist; 14, block; 15, call; 16, block; 17, if_statement; 18, return_statement; 19, attribute; 20, argument_list; 21, return_statement; 22, call; 23, block; 24, None; 25, attribute; 26, identifier:get_field; 27, identifier:attr; 28, identifier:attr; 29, identifier:isinstance; 30, argument_list; 31, expression_statement; 32, if_statement; 33, identifier:model; 34, identifier:_meta; 35, identifier:attr; 36, identifier:basestring; 37, assignment; 38, boolean_operator; 39, block; 40, identifier:val; 41, call; 42, identifier:val; 43, call; 44, return_statement; 45, identifier:getattr; 46, argument_list; 47, identifier:hasattr; 48, argument_list; 49, attribute; 50, identifier:model; 51, identifier:attr; 52, None; 53, identifier:val; 54, string; 55, call; 56, identifier:sort_field; 57, string_content:sort_field; 58, identifier:getattr; 59, argument_list; 60, identifier:model; 61, identifier:attr
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 8, 11; 10, 12; 11, 13; 11, 14; 12, 15; 12, 16; 14, 17; 14, 18; 15, 19; 15, 20; 16, 21; 17, 22; 17, 23; 18, 24; 19, 25; 19, 26; 20, 27; 21, 28; 22, 29; 22, 30; 23, 31; 23, 32; 25, 33; 25, 34; 30, 35; 30, 36; 31, 37; 32, 38; 32, 39; 37, 40; 37, 41; 38, 42; 38, 43; 39, 44; 41, 45; 41, 46; 43, 47; 43, 48; 44, 49; 46, 50; 46, 51; 46, 52; 48, 53; 48, 54; 49, 55; 49, 56; 54, 57; 55, 58; 55, 59; 59, 60; 59, 61
def get_sort_field(attr, model): """ Get's the field to sort on for the given attr. Currently returns attr if it is a field on the given model. If the models has an attribute matching that name and that value has an attribute 'sort_field' than that value is used. TODO: Provide a way to sort based on a non field attribute. """ try: if model._meta.get_field(attr): return attr except FieldDoesNotExist: if isinstance(attr, basestring): val = getattr(model, attr, None) if val and hasattr(val, 'sort_field'): return getattr(model, attr).sort_field return None
0, module; 1, function_definition; 2, function_name:sorted_query_paths; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, return_statement; 8, comment:""" RETURN A LIST OF ALL SCHEMA'S IN DEPTH-FIRST TOPOLOGICAL ORDER """; 9, call; 10, identifier:list; 11, argument_list; 12, call; 13, identifier:reversed; 14, argument_list; 15, call; 16, identifier:sorted; 17, generator_expression; 18, subscript; 19, for_in_clause; 20, identifier:p; 21, integer:0; 22, identifier:p; 23, call; 24, attribute; 25, argument_list; 26, attribute; 27, identifier:get; 28, attribute; 29, attribute; 30, identifier:alias_to_query_paths; 31, identifier:self; 32, identifier:name; 33, identifier:self; 34, identifier:namespace
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; 15, 16; 15, 17; 17, 18; 17, 19; 18, 20; 18, 21; 19, 22; 19, 23; 23, 24; 23, 25; 24, 26; 24, 27; 25, 28; 26, 29; 26, 30; 28, 31; 28, 32; 29, 33; 29, 34
def sorted_query_paths(self): """ RETURN A LIST OF ALL SCHEMA'S IN DEPTH-FIRST TOPOLOGICAL ORDER """ return list(reversed(sorted(p[0] for p in self.namespace.alias_to_query_paths.get(self.name))))
0, module; 1, function_definition; 2, function_name:add_arguments; 3, parameters; 4, block; 5, identifier:self; 6, identifier:actions; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:""" Sort the flags alphabetically """; 11, assignment; 12, call; 13, identifier:actions; 14, call; 15, attribute; 16, argument_list; 17, identifier:sorted; 18, argument_list; 19, call; 20, identifier:add_arguments; 21, identifier:actions; 22, identifier:actions; 23, keyword_argument; 24, identifier:super; 25, argument_list; 26, identifier:key; 27, call; 28, identifier:SortedHelpFormatter; 29, identifier:self; 30, attribute; 31, argument_list; 32, identifier:operator; 33, identifier:attrgetter; 34, string; 35, string_content:option_strings
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 9, 12; 11, 13; 11, 14; 12, 15; 12, 16; 14, 17; 14, 18; 15, 19; 15, 20; 16, 21; 18, 22; 18, 23; 19, 24; 19, 25; 23, 26; 23, 27; 25, 28; 25, 29; 27, 30; 27, 31; 30, 32; 30, 33; 31, 34; 34, 35
def add_arguments(self, actions): """ Sort the flags alphabetically """ actions = sorted( actions, key=operator.attrgetter('option_strings')) super(SortedHelpFormatter, self).add_arguments(actions)
0, module; 1, function_definition; 2, function_name:_iter_indented_subactions; 3, parameters; 4, block; 5, identifier:self; 6, identifier:action; 7, expression_statement; 8, try_statement; 9, comment:""" Sort the subcommands alphabetically """; 10, block; 11, except_clause; 12, else_clause; 13, expression_statement; 14, identifier:AttributeError; 15, block; 16, block; 17, assignment; 18, pass_statement; 19, expression_statement; 20, if_statement; 21, expression_statement; 22, identifier:get_subactions; 23, attribute; 24, call; 25, call; 26, block; 27, else_clause; 28, call; 29, identifier:action; 30, identifier:_get_subactions; 31, attribute; 32, argument_list; 33, identifier:isinstance; 34, argument_list; 35, for_statement; 36, block; 37, attribute; 38, argument_list; 39, identifier:self; 40, identifier:_indent; 41, identifier:action; 42, attribute; 43, identifier:subaction; 44, call; 45, block; 46, for_statement; 47, identifier:self; 48, identifier:_dedent; 49, identifier:argparse; 50, identifier:_SubParsersAction; 51, identifier:sorted; 52, argument_list; 53, expression_statement; 54, identifier:subaction; 55, call; 56, block; 57, call; 58, keyword_argument; 59, yield; 60, identifier:get_subactions; 61, argument_list; 62, expression_statement; 63, identifier:get_subactions; 64, argument_list; 65, identifier:key; 66, lambda; 67, identifier:subaction; 68, yield; 69, lambda_parameters; 70, attribute; 71, identifier:subaction; 72, identifier:x; 73, identifier:x; 74, identifier:dest
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; 11, 14; 11, 15; 12, 16; 13, 17; 15, 18; 16, 19; 16, 20; 16, 21; 17, 22; 17, 23; 19, 24; 20, 25; 20, 26; 20, 27; 21, 28; 23, 29; 23, 30; 24, 31; 24, 32; 25, 33; 25, 34; 26, 35; 27, 36; 28, 37; 28, 38; 31, 39; 31, 40; 34, 41; 34, 42; 35, 43; 35, 44; 35, 45; 36, 46; 37, 47; 37, 48; 42, 49; 42, 50; 44, 51; 44, 52; 45, 53; 46, 54; 46, 55; 46, 56; 52, 57; 52, 58; 53, 59; 55, 60; 55, 61; 56, 62; 57, 63; 57, 64; 58, 65; 58, 66; 59, 67; 62, 68; 66, 69; 66, 70; 68, 71; 69, 72; 70, 73; 70, 74
def _iter_indented_subactions(self, action): """ Sort the subcommands alphabetically """ try: get_subactions = action._get_subactions except AttributeError: pass else: self._indent() if isinstance(action, argparse._SubParsersAction): for subaction in sorted( get_subactions(), key=lambda x: x.dest): yield subaction else: for subaction in get_subactions(): yield subaction self._dedent()
0, module; 1, function_definition; 2, function_name:_sort2sql; 3, parameters; 4, block; 5, identifier:self; 6, identifier:sort; 7, expression_statement; 8, if_statement; 9, return_statement; 10, comment:""" RETURN ORDER BY CLAUSE """; 11, not_operator; 12, block; 13, binary_operator:SQL_ORDERBY + sql_list([quote_column(o.field) + (" DESC" if o.sort == -1 else "") for o in sort]); 14, identifier:sort; 15, return_statement; 16, identifier:SQL_ORDERBY; 17, call; 18, string:""; 19, identifier:sql_list; 20, argument_list; 21, list_comprehension; 22, binary_operator:quote_column(o.field) + (" DESC" if o.sort == -1 else ""); 23, for_in_clause; 24, call; 25, parenthesized_expression; 26, identifier:o; 27, identifier:sort; 28, identifier:quote_column; 29, argument_list; 30, conditional_expression:" DESC" if o.sort == -1 else ""; 31, attribute; 32, string:" DESC"; 33, comparison_operator:o.sort == -1; 34, string:""; 35, identifier:o; 36, identifier:field; 37, attribute; 38, unary_operator; 39, identifier:o; 40, identifier:sort; 41, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 8, 12; 9, 13; 11, 14; 12, 15; 13, 16; 13, 17; 15, 18; 17, 19; 17, 20; 20, 21; 21, 22; 21, 23; 22, 24; 22, 25; 23, 26; 23, 27; 24, 28; 24, 29; 25, 30; 29, 31; 30, 32; 30, 33; 30, 34; 31, 35; 31, 36; 33, 37; 33, 38; 37, 39; 37, 40; 38, 41
def _sort2sql(self, sort): """ RETURN ORDER BY CLAUSE """ if not sort: return "" return SQL_ORDERBY + sql_list([quote_column(o.field) + (" DESC" if o.sort == -1 else "") for o in sort])
0, module; 1, function_definition; 2, function_name:optimize_batch; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, return_statement; 15, identifier:batchsize; 16, integer:10; 17, identifier:returns; 18, string; 19, identifier:paralell; 20, True; 21, comment:""" Run multiple optimizations using different starting coordinates. Args: batchsize (`int`): Number of optimizations to run. returns (`str`): If ``'all'``, return results of all optimizations, ordered by stress, ascending. If ``'best'`` return the projection with the lowest stress. parallel (`bool`): If ``True``, run optimizations in parallel. Examples: .. doctest:: >>> import pandas as pd >>> from pymds import DistanceMatrix >>> dist = pd.DataFrame({ ... 'a': [0.0, 1.0, 2.0], ... 'b': [1.0, 0.0, 3 ** 0.5], ... 'c': [2.0, 3 ** 0.5, 0.0]} , index=['a', 'b', 'c']) >>> dm = DistanceMatrix(dist) >>> batch = dm.optimize_batch(batchsize=3, returns='all') >>> len(batch) 3 >>> type(batch[0]) <class 'pymds.mds.Projection'> Returns: `list` or :py:class:`pymds.Projection`: `list`: Length batchsize, containing instances of :py:class:`pymds.Projection`. Sorted by stress, ascending. or :py:class:`pymds.Projection`: Projection with the lowest stress. """; 22, comparison_operator:returns not in ('best', 'all'); 23, block; 24, assignment; 25, identifier:paralell; 26, block; 27, else_clause; 28, assignment; 29, conditional_expression:results if returns == 'all' else results[0]; 30, string_content:best; 31, identifier:returns; 32, tuple; 33, raise_statement; 34, identifier:starts; 35, list_comprehension; 36, with_statement; 37, block; 38, identifier:results; 39, call; 40, identifier:results; 41, comparison_operator:returns == 'all'; 42, subscript; 43, string; 44, string; 45, call; 46, binary_operator:np.random.rand(self.m * 2) * 10; 47, for_in_clause; 48, with_clause; 49, block; 50, expression_statement; 51, identifier:sorted; 52, argument_list; 53, identifier:returns; 54, string; 55, identifier:results; 56, integer:0; 57, string_content:best; 58, string_content:all; 59, identifier:ValueError; 60, argument_list; 61, call; 62, integer:10; 63, identifier:i; 64, call; 65, with_item; 66, expression_statement; 67, assignment; 68, identifier:results; 69, keyword_argument; 70, string_content:all; 71, string:'returns must be either "best" or "all"'; 72, attribute; 73, argument_list; 74, identifier:range; 75, argument_list; 76, as_pattern; 77, assignment; 78, identifier:results; 79, call; 80, identifier:key; 81, lambda; 82, attribute; 83, identifier:rand; 84, binary_operator:self.m * 2; 85, identifier:batchsize; 86, call; 87, as_pattern_target; 88, identifier:results; 89, call; 90, identifier:map; 91, argument_list; 92, lambda_parameters; 93, attribute; 94, identifier:np; 95, identifier:random; 96, attribute; 97, integer:2; 98, identifier:Pool; 99, argument_list; 100, identifier:p; 101, attribute; 102, argument_list; 103, attribute; 104, identifier:starts; 105, identifier:x; 106, identifier:x; 107, identifier:stress; 108, identifier:self; 109, identifier:m; 110, identifier:p; 111, identifier:map; 112, attribute; 113, identifier:starts; 114, identifier:self; 115, identifier:optimize; 116, identifier:self; 117, identifier:optimize
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 10, 22; 10, 23; 11, 24; 12, 25; 12, 26; 12, 27; 13, 28; 14, 29; 18, 30; 22, 31; 22, 32; 23, 33; 24, 34; 24, 35; 26, 36; 27, 37; 28, 38; 28, 39; 29, 40; 29, 41; 29, 42; 32, 43; 32, 44; 33, 45; 35, 46; 35, 47; 36, 48; 36, 49; 37, 50; 39, 51; 39, 52; 41, 53; 41, 54; 42, 55; 42, 56; 43, 57; 44, 58; 45, 59; 45, 60; 46, 61; 46, 62; 47, 63; 47, 64; 48, 65; 49, 66; 50, 67; 52, 68; 52, 69; 54, 70; 60, 71; 61, 72; 61, 73; 64, 74; 64, 75; 65, 76; 66, 77; 67, 78; 67, 79; 69, 80; 69, 81; 72, 82; 72, 83; 73, 84; 75, 85; 76, 86; 76, 87; 77, 88; 77, 89; 79, 90; 79, 91; 81, 92; 81, 93; 82, 94; 82, 95; 84, 96; 84, 97; 86, 98; 86, 99; 87, 100; 89, 101; 89, 102; 91, 103; 91, 104; 92, 105; 93, 106; 93, 107; 96, 108; 96, 109; 101, 110; 101, 111; 102, 112; 102, 113; 103, 114; 103, 115; 112, 116; 112, 117
def optimize_batch(self, batchsize=10, returns='best', paralell=True): """ Run multiple optimizations using different starting coordinates. Args: batchsize (`int`): Number of optimizations to run. returns (`str`): If ``'all'``, return results of all optimizations, ordered by stress, ascending. If ``'best'`` return the projection with the lowest stress. parallel (`bool`): If ``True``, run optimizations in parallel. Examples: .. doctest:: >>> import pandas as pd >>> from pymds import DistanceMatrix >>> dist = pd.DataFrame({ ... 'a': [0.0, 1.0, 2.0], ... 'b': [1.0, 0.0, 3 ** 0.5], ... 'c': [2.0, 3 ** 0.5, 0.0]} , index=['a', 'b', 'c']) >>> dm = DistanceMatrix(dist) >>> batch = dm.optimize_batch(batchsize=3, returns='all') >>> len(batch) 3 >>> type(batch[0]) <class 'pymds.mds.Projection'> Returns: `list` or :py:class:`pymds.Projection`: `list`: Length batchsize, containing instances of :py:class:`pymds.Projection`. Sorted by stress, ascending. or :py:class:`pymds.Projection`: Projection with the lowest stress. """ if returns not in ('best', 'all'): raise ValueError('returns must be either "best" or "all"') starts = [np.random.rand(self.m * 2) * 10 for i in range(batchsize)] if paralell: with Pool() as p: results = p.map(self.optimize, starts) else: results = map(self.optimize, starts) results = sorted(results, key=lambda x: x.stress) return results if returns == 'all' else results[0]
0, module; 1, function_definition; 2, function_name:list_gewesten; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, function_definition; 9, if_statement; 10, for_statement; 11, return_statement; 12, identifier:sort; 13, integer:1; 14, string; 15, function_name:creator; 16, parameters; 17, block; 18, attribute; 19, block; 20, else_clause; 21, identifier:g; 22, identifier:gewesten; 23, block; 24, identifier:gewesten; 25, string_content:List all `gewesten` in Belgium. :param integer sort: What field to sort on. :rtype: A :class`list` of class: `Gewest`.; 26, expression_statement; 27, expression_statement; 28, for_statement; 29, return_statement; 30, subscript; 31, identifier:is_configured; 32, expression_statement; 33, expression_statement; 34, block; 35, expression_statement; 36, assignment; 37, assignment; 38, identifier:r; 39, attribute; 40, block; 41, list_comprehension; 42, attribute; 43, string; 44, assignment; 45, assignment; 46, expression_statement; 47, call; 48, identifier:res; 49, call; 50, identifier:tmp; 51, dictionary; 52, identifier:res; 53, identifier:GewestItem; 54, if_statement; 55, expression_statement; 56, call; 57, for_in_clause; 58, identifier:self; 59, identifier:caches; 60, string_content:permanent; 61, identifier:key; 62, binary_operator:'ListGewesten#%s' % sort; 63, identifier:gewesten; 64, call; 65, assignment; 66, attribute; 67, argument_list; 68, identifier:crab_gateway_request; 69, argument_list; 70, comparison_operator:r.GewestId not in tmp; 71, block; 72, assignment; 73, identifier:Gewest; 74, argument_list; 75, pattern_list; 76, call; 77, string; 78, identifier:sort; 79, attribute; 80, argument_list; 81, identifier:gewesten; 82, call; 83, identifier:g; 84, identifier:set_gateway; 85, identifier:self; 86, attribute; 87, string; 88, identifier:sort; 89, attribute; 90, identifier:tmp; 91, expression_statement; 92, subscript; 93, attribute; 94, identifier:k; 95, identifier:v; 96, identifier:k; 97, identifier:v; 98, attribute; 99, argument_list; 100, string_content:ListGewesten#%s; 101, subscript; 102, identifier:get_or_create; 103, identifier:key; 104, identifier:creator; 105, identifier:creator; 106, argument_list; 107, identifier:self; 108, identifier:client; 109, string_content:ListGewesten; 110, identifier:r; 111, identifier:GewestId; 112, assignment; 113, subscript; 114, attribute; 115, identifier:r; 116, identifier:GewestNaam; 117, identifier:tmp; 118, identifier:items; 119, attribute; 120, string; 121, subscript; 122, dictionary; 123, identifier:tmp; 124, attribute; 125, identifier:r; 126, identifier:TaalCodeGewestNaam; 127, identifier:self; 128, identifier:caches; 129, string_content:permanent; 130, identifier:tmp; 131, attribute; 132, identifier:r; 133, identifier:GewestId; 134, identifier:r; 135, identifier:GewestId
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; 8, 16; 8, 17; 9, 18; 9, 19; 9, 20; 10, 21; 10, 22; 10, 23; 11, 24; 14, 25; 17, 26; 17, 27; 17, 28; 17, 29; 18, 30; 18, 31; 19, 32; 19, 33; 20, 34; 23, 35; 26, 36; 27, 37; 28, 38; 28, 39; 28, 40; 29, 41; 30, 42; 30, 43; 32, 44; 33, 45; 34, 46; 35, 47; 36, 48; 36, 49; 37, 50; 37, 51; 39, 52; 39, 53; 40, 54; 40, 55; 41, 56; 41, 57; 42, 58; 42, 59; 43, 60; 44, 61; 44, 62; 45, 63; 45, 64; 46, 65; 47, 66; 47, 67; 49, 68; 49, 69; 54, 70; 54, 71; 55, 72; 56, 73; 56, 74; 57, 75; 57, 76; 62, 77; 62, 78; 64, 79; 64, 80; 65, 81; 65, 82; 66, 83; 66, 84; 67, 85; 69, 86; 69, 87; 69, 88; 70, 89; 70, 90; 71, 91; 72, 92; 72, 93; 74, 94; 74, 95; 75, 96; 75, 97; 76, 98; 76, 99; 77, 100; 79, 101; 79, 102; 80, 103; 80, 104; 82, 105; 82, 106; 86, 107; 86, 108; 87, 109; 89, 110; 89, 111; 91, 112; 92, 113; 92, 114; 93, 115; 93, 116; 98, 117; 98, 118; 101, 119; 101, 120; 112, 121; 112, 122; 113, 123; 113, 124; 114, 125; 114, 126; 119, 127; 119, 128; 120, 129; 121, 130; 121, 131; 124, 132; 124, 133; 131, 134; 131, 135
def list_gewesten(self, sort=1): ''' List all `gewesten` in Belgium. :param integer sort: What field to sort on. :rtype: A :class`list` of class: `Gewest`. ''' def creator(): res = crab_gateway_request(self.client, 'ListGewesten', sort) tmp = {} for r in res.GewestItem: if r.GewestId not in tmp: tmp[r.GewestId] = {} tmp[r.GewestId][r.TaalCodeGewestNaam] = r.GewestNaam return[ Gewest( k, v )for k, v in tmp.items() ] if self.caches['permanent'].is_configured: key = 'ListGewesten#%s' % sort gewesten = self.caches['permanent'].get_or_create(key, creator) else: gewesten = creator() for g in gewesten: g.set_gateway(self) return gewesten
0, module; 1, function_definition; 2, function_name:list_provincies; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, try_statement; 9, function_definition; 10, if_statement; 11, for_statement; 12, return_statement; 13, identifier:gewest; 14, integer:2; 15, string; 16, block; 17, except_clause; 18, function_name:creator; 19, parameters; 20, block; 21, attribute; 22, block; 23, else_clause; 24, identifier:p; 25, identifier:provincies; 26, block; 27, identifier:provincies; 28, string_content; 29, expression_statement; 30, identifier:AttributeError; 31, block; 32, return_statement; 33, subscript; 34, identifier:is_configured; 35, expression_statement; 36, expression_statement; 37, block; 38, expression_statement; 39, escape_sequence:\; 40, assignment; 41, expression_statement; 42, list_comprehension; 43, attribute; 44, string; 45, assignment; 46, assignment; 47, expression_statement; 48, call; 49, identifier:gewest_id; 50, attribute; 51, assignment; 52, call; 53, for_in_clause; 54, if_clause; 55, identifier:self; 56, identifier:caches; 57, string_content:permanent; 58, identifier:key; 59, binary_operator:'ListProvinciesByGewestId#%s' % gewest_id; 60, identifier:provincies; 61, call; 62, assignment; 63, attribute; 64, argument_list; 65, identifier:gewest; 66, identifier:id; 67, identifier:gewest_id; 68, identifier:gewest; 69, identifier:Provincie; 70, argument_list; 71, identifier:p; 72, attribute; 73, comparison_operator:p[2] == gewest_id; 74, string; 75, identifier:gewest_id; 76, attribute; 77, argument_list; 78, identifier:provincies; 79, call; 80, identifier:p; 81, identifier:set_gateway; 82, identifier:self; 83, subscript; 84, subscript; 85, call; 86, identifier:self; 87, identifier:provincies; 88, subscript; 89, identifier:gewest_id; 90, string_content:ListProvinciesByGewestId#%s; 91, subscript; 92, identifier:get_or_create; 93, identifier:key; 94, identifier:creator; 95, identifier:creator; 96, argument_list; 97, identifier:p; 98, integer:0; 99, identifier:p; 100, integer:1; 101, identifier:Gewest; 102, argument_list; 103, identifier:p; 104, integer:2; 105, attribute; 106, string; 107, subscript; 108, identifier:self; 109, identifier:caches; 110, string_content:permanent; 111, identifier:p; 112, integer:2
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 8, 16; 8, 17; 9, 18; 9, 19; 9, 20; 10, 21; 10, 22; 10, 23; 11, 24; 11, 25; 11, 26; 12, 27; 15, 28; 16, 29; 17, 30; 17, 31; 20, 32; 21, 33; 21, 34; 22, 35; 22, 36; 23, 37; 26, 38; 28, 39; 29, 40; 31, 41; 32, 42; 33, 43; 33, 44; 35, 45; 36, 46; 37, 47; 38, 48; 40, 49; 40, 50; 41, 51; 42, 52; 42, 53; 42, 54; 43, 55; 43, 56; 44, 57; 45, 58; 45, 59; 46, 60; 46, 61; 47, 62; 48, 63; 48, 64; 50, 65; 50, 66; 51, 67; 51, 68; 52, 69; 52, 70; 53, 71; 53, 72; 54, 73; 59, 74; 59, 75; 61, 76; 61, 77; 62, 78; 62, 79; 63, 80; 63, 81; 64, 82; 70, 83; 70, 84; 70, 85; 72, 86; 72, 87; 73, 88; 73, 89; 74, 90; 76, 91; 76, 92; 77, 93; 77, 94; 79, 95; 79, 96; 83, 97; 83, 98; 84, 99; 84, 100; 85, 101; 85, 102; 88, 103; 88, 104; 91, 105; 91, 106; 102, 107; 105, 108; 105, 109; 106, 110; 107, 111; 107, 112
def list_provincies(self, gewest=2): ''' List all `provincies` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `provincies` are wanted. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Provincie`. ''' try: gewest_id = gewest.id except AttributeError: gewest_id = gewest def creator(): return [Provincie(p[0], p[1], Gewest(p[2])) for p in self.provincies if p[2] == gewest_id] if self.caches['permanent'].is_configured: key = 'ListProvinciesByGewestId#%s' % gewest_id provincies = self.caches['permanent'].get_or_create(key, creator) else: provincies = creator() for p in provincies: p.set_gateway(self) return provincies
0, module; 1, function_definition; 2, function_name:list_gemeenten; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, try_statement; 10, expression_statement; 11, function_definition; 12, if_statement; 13, for_statement; 14, return_statement; 15, identifier:gewest; 16, integer:2; 17, identifier:sort; 18, integer:1; 19, string; 20, block; 21, except_clause; 22, call; 23, function_name:creator; 24, parameters; 25, block; 26, attribute; 27, block; 28, else_clause; 29, identifier:g; 30, identifier:gemeenten; 31, block; 32, identifier:gemeenten; 33, string_content; 34, expression_statement; 35, identifier:AttributeError; 36, block; 37, attribute; 38, argument_list; 39, expression_statement; 40, return_statement; 41, subscript; 42, identifier:is_configured; 43, expression_statement; 44, expression_statement; 45, block; 46, expression_statement; 47, escape_sequence:\; 48, assignment; 49, expression_statement; 50, expression_statement; 51, identifier:gewest; 52, identifier:clear_gateway; 53, assignment; 54, list_comprehension; 55, attribute; 56, string; 57, assignment; 58, assignment; 59, expression_statement; 60, call; 61, identifier:gewest_id; 62, attribute; 63, assignment; 64, assignment; 65, identifier:res; 66, call; 67, call; 68, for_in_clause; 69, if_clause; 70, identifier:self; 71, identifier:caches; 72, string_content:permanent; 73, identifier:key; 74, binary_operator:'ListGemeentenByGewestId#%s#%s' % (gewest_id, sort); 75, identifier:gemeenten; 76, call; 77, assignment; 78, attribute; 79, argument_list; 80, identifier:gewest; 81, identifier:id; 82, identifier:gewest_id; 83, identifier:gewest; 84, identifier:gewest; 85, call; 86, identifier:crab_gateway_request; 87, argument_list; 88, identifier:Gemeente; 89, argument_list; 90, identifier:r; 91, attribute; 92, comparison_operator:r.TaalCode == r.TaalCodeGemeenteNaam; 93, string; 94, tuple; 95, attribute; 96, argument_list; 97, identifier:gemeenten; 98, call; 99, identifier:g; 100, identifier:set_gateway; 101, identifier:self; 102, attribute; 103, argument_list; 104, attribute; 105, string; 106, identifier:gewest_id; 107, identifier:sort; 108, attribute; 109, attribute; 110, attribute; 111, identifier:gewest; 112, identifier:res; 113, identifier:GemeenteItem; 114, attribute; 115, attribute; 116, string_content:ListGemeentenByGewestId#%s#%s; 117, identifier:gewest_id; 118, identifier:sort; 119, subscript; 120, identifier:get_or_create; 121, identifier:key; 122, identifier:creator; 123, identifier:creator; 124, argument_list; 125, identifier:self; 126, identifier:get_gewest_by_id; 127, identifier:gewest_id; 128, identifier:self; 129, identifier:client; 130, string_content:ListGemeentenByGewestId; 131, identifier:r; 132, identifier:GemeenteId; 133, identifier:r; 134, identifier:GemeenteNaam; 135, identifier:r; 136, identifier:NISGemeenteCode; 137, identifier:r; 138, identifier:TaalCode; 139, identifier:r; 140, identifier:TaalCodeGemeenteNaam; 141, attribute; 142, string; 143, identifier:self; 144, identifier:caches; 145, string_content:permanent
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 9, 20; 9, 21; 10, 22; 11, 23; 11, 24; 11, 25; 12, 26; 12, 27; 12, 28; 13, 29; 13, 30; 13, 31; 14, 32; 19, 33; 20, 34; 21, 35; 21, 36; 22, 37; 22, 38; 25, 39; 25, 40; 26, 41; 26, 42; 27, 43; 27, 44; 28, 45; 31, 46; 33, 47; 34, 48; 36, 49; 36, 50; 37, 51; 37, 52; 39, 53; 40, 54; 41, 55; 41, 56; 43, 57; 44, 58; 45, 59; 46, 60; 48, 61; 48, 62; 49, 63; 50, 64; 53, 65; 53, 66; 54, 67; 54, 68; 54, 69; 55, 70; 55, 71; 56, 72; 57, 73; 57, 74; 58, 75; 58, 76; 59, 77; 60, 78; 60, 79; 62, 80; 62, 81; 63, 82; 63, 83; 64, 84; 64, 85; 66, 86; 66, 87; 67, 88; 67, 89; 68, 90; 68, 91; 69, 92; 74, 93; 74, 94; 76, 95; 76, 96; 77, 97; 77, 98; 78, 99; 78, 100; 79, 101; 85, 102; 85, 103; 87, 104; 87, 105; 87, 106; 87, 107; 89, 108; 89, 109; 89, 110; 89, 111; 91, 112; 91, 113; 92, 114; 92, 115; 93, 116; 94, 117; 94, 118; 95, 119; 95, 120; 96, 121; 96, 122; 98, 123; 98, 124; 102, 125; 102, 126; 103, 127; 104, 128; 104, 129; 105, 130; 108, 131; 108, 132; 109, 133; 109, 134; 110, 135; 110, 136; 114, 137; 114, 138; 115, 139; 115, 140; 119, 141; 119, 142; 141, 143; 141, 144; 142, 145
def list_gemeenten(self, gewest=2, sort=1): ''' List all `gemeenten` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `gemeenten` are wanted. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Gemeente`. ''' try: gewest_id = gewest.id except AttributeError: gewest_id = gewest gewest = self.get_gewest_by_id(gewest_id) gewest.clear_gateway() def creator(): res = crab_gateway_request( self.client, 'ListGemeentenByGewestId', gewest_id, sort ) return[ Gemeente( r.GemeenteId, r.GemeenteNaam, r.NISGemeenteCode, gewest )for r in res.GemeenteItem if r.TaalCode == r.TaalCodeGemeenteNaam ] if self.caches['permanent'].is_configured: key = 'ListGemeentenByGewestId#%s#%s' % (gewest_id, sort) gemeenten = self.caches['permanent'].get_or_create(key, creator) else: gemeenten = creator() for g in gemeenten: g.set_gateway(self) return gemeenten
0, module; 1, function_definition; 2, function_name:list_gemeenten; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, function_definition; 9, if_statement; 10, for_statement; 11, return_statement; 12, identifier:sort; 13, integer:1; 14, string; 15, function_name:creator; 16, parameters; 17, block; 18, attribute; 19, block; 20, else_clause; 21, identifier:g; 22, identifier:gemeente; 23, block; 24, identifier:gemeente; 25, string_content:List all `gemeenten` in Vlaanderen. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Gemeente`.; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, expression_statement; 30, return_statement; 31, subscript; 32, identifier:is_configured; 33, expression_statement; 34, expression_statement; 35, block; 36, expression_statement; 37, assignment; 38, assignment; 39, assignment; 40, assignment; 41, list_comprehension; 42, attribute; 43, string; 44, assignment; 45, assignment; 46, expression_statement; 47, call; 48, identifier:url; 49, binary_operator:self.base_url + '/municipality'; 50, identifier:h; 51, attribute; 52, identifier:p; 53, dictionary; 54, identifier:res; 55, call; 56, call; 57, for_in_clause; 58, identifier:self; 59, identifier:caches; 60, string_content:permanent; 61, identifier:key; 62, binary_operator:'list_gemeenten_rest#%s' % sort; 63, identifier:gemeente; 64, call; 65, assignment; 66, attribute; 67, argument_list; 68, attribute; 69, string; 70, identifier:self; 71, identifier:base_headers; 72, pair; 73, attribute; 74, argument_list; 75, identifier:Gemeente; 76, argument_list; 77, identifier:r; 78, subscript; 79, string; 80, identifier:sort; 81, attribute; 82, argument_list; 83, identifier:gemeente; 84, call; 85, identifier:g; 86, identifier:set_gateway; 87, identifier:self; 88, identifier:self; 89, identifier:base_url; 90, string_content:/municipality; 91, string; 92, comparison_operator:sort == 1; 93, call; 94, identifier:json; 95, subscript; 96, subscript; 97, identifier:res; 98, string; 99, string_content:list_gemeenten_rest#%s; 100, subscript; 101, identifier:get_or_create; 102, identifier:key; 103, identifier:creator; 104, identifier:creator; 105, argument_list; 106, string_content:orderbyCode; 107, identifier:sort; 108, integer:1; 109, identifier:capakey_rest_gateway_request; 110, argument_list; 111, identifier:r; 112, string; 113, identifier:r; 114, string; 115, string_content:municipalities; 116, attribute; 117, string; 118, identifier:url; 119, identifier:h; 120, identifier:p; 121, string_content:municipalityCode; 122, string_content:municipalityName; 123, identifier:self; 124, identifier:caches; 125, string_content:permanent
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; 8, 16; 8, 17; 9, 18; 9, 19; 9, 20; 10, 21; 10, 22; 10, 23; 11, 24; 14, 25; 17, 26; 17, 27; 17, 28; 17, 29; 17, 30; 18, 31; 18, 32; 19, 33; 19, 34; 20, 35; 23, 36; 26, 37; 27, 38; 28, 39; 29, 40; 30, 41; 31, 42; 31, 43; 33, 44; 34, 45; 35, 46; 36, 47; 37, 48; 37, 49; 38, 50; 38, 51; 39, 52; 39, 53; 40, 54; 40, 55; 41, 56; 41, 57; 42, 58; 42, 59; 43, 60; 44, 61; 44, 62; 45, 63; 45, 64; 46, 65; 47, 66; 47, 67; 49, 68; 49, 69; 51, 70; 51, 71; 53, 72; 55, 73; 55, 74; 56, 75; 56, 76; 57, 77; 57, 78; 62, 79; 62, 80; 64, 81; 64, 82; 65, 83; 65, 84; 66, 85; 66, 86; 67, 87; 68, 88; 68, 89; 69, 90; 72, 91; 72, 92; 73, 93; 73, 94; 76, 95; 76, 96; 78, 97; 78, 98; 79, 99; 81, 100; 81, 101; 82, 102; 82, 103; 84, 104; 84, 105; 91, 106; 92, 107; 92, 108; 93, 109; 93, 110; 95, 111; 95, 112; 96, 113; 96, 114; 98, 115; 100, 116; 100, 117; 110, 118; 110, 119; 110, 120; 112, 121; 114, 122; 116, 123; 116, 124; 117, 125
def list_gemeenten(self, sort=1): ''' List all `gemeenten` in Vlaanderen. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Gemeente`. ''' def creator(): url = self.base_url + '/municipality' h = self.base_headers p = { 'orderbyCode': sort == 1 } res = capakey_rest_gateway_request(url, h, p).json() return [ Gemeente(r['municipalityCode'], r['municipalityName']) for r in res['municipalities'] ] if self.caches['permanent'].is_configured: key = 'list_gemeenten_rest#%s' % sort gemeente = self.caches['permanent'].get_or_create(key, creator) else: gemeente = creator() for g in gemeente: g.set_gateway(self) return gemeente
0, module; 1, function_definition; 2, function_name:list_kadastrale_afdelingen; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, function_definition; 8, if_statement; 9, return_statement; 10, string; 11, function_name:creator; 12, parameters; 13, block; 14, attribute; 15, block; 16, else_clause; 17, identifier:afdelingen; 18, string_content:List all `kadastrale afdelingen` in Flanders. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Afdeling`.; 19, expression_statement; 20, expression_statement; 21, for_statement; 22, return_statement; 23, subscript; 24, identifier:is_configured; 25, expression_statement; 26, expression_statement; 27, block; 28, assignment; 29, assignment; 30, identifier:g; 31, identifier:gemeentes; 32, block; 33, identifier:res; 34, attribute; 35, string; 36, assignment; 37, assignment; 38, expression_statement; 39, identifier:gemeentes; 40, call; 41, identifier:res; 42, list; 43, expression_statement; 44, identifier:self; 45, identifier:caches; 46, string_content:permanent; 47, identifier:key; 48, string; 49, identifier:afdelingen; 50, call; 51, assignment; 52, attribute; 53, argument_list; 54, augmented_assignment; 55, string_content:list_afdelingen_rest; 56, attribute; 57, argument_list; 58, identifier:afdelingen; 59, call; 60, identifier:self; 61, identifier:list_gemeenten; 62, identifier:res; 63, call; 64, subscript; 65, identifier:get_or_create; 66, identifier:key; 67, identifier:creator; 68, identifier:creator; 69, argument_list; 70, attribute; 71, argument_list; 72, attribute; 73, string; 74, identifier:self; 75, identifier:list_kadastrale_afdelingen_by_gemeente; 76, identifier:g; 77, identifier:self; 78, identifier:caches; 79, string_content:permanent
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 7, 11; 7, 12; 7, 13; 8, 14; 8, 15; 8, 16; 9, 17; 10, 18; 13, 19; 13, 20; 13, 21; 13, 22; 14, 23; 14, 24; 15, 25; 15, 26; 16, 27; 19, 28; 20, 29; 21, 30; 21, 31; 21, 32; 22, 33; 23, 34; 23, 35; 25, 36; 26, 37; 27, 38; 28, 39; 28, 40; 29, 41; 29, 42; 32, 43; 34, 44; 34, 45; 35, 46; 36, 47; 36, 48; 37, 49; 37, 50; 38, 51; 40, 52; 40, 53; 43, 54; 48, 55; 50, 56; 50, 57; 51, 58; 51, 59; 52, 60; 52, 61; 54, 62; 54, 63; 56, 64; 56, 65; 57, 66; 57, 67; 59, 68; 59, 69; 63, 70; 63, 71; 64, 72; 64, 73; 70, 74; 70, 75; 71, 76; 72, 77; 72, 78; 73, 79
def list_kadastrale_afdelingen(self): ''' List all `kadastrale afdelingen` in Flanders. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Afdeling`. ''' def creator(): gemeentes = self.list_gemeenten() res = [] for g in gemeentes: res += self.list_kadastrale_afdelingen_by_gemeente(g) return res if self.caches['permanent'].is_configured: key = 'list_afdelingen_rest' afdelingen = self.caches['permanent'].get_or_create(key, creator) else: afdelingen = creator() return afdelingen
0, module; 1, function_definition; 2, function_name:list_kadastrale_afdelingen_by_gemeente; 3, parameters; 4, block; 5, identifier:self; 6, identifier:gemeente; 7, default_parameter; 8, expression_statement; 9, try_statement; 10, expression_statement; 11, function_definition; 12, if_statement; 13, for_statement; 14, return_statement; 15, identifier:sort; 16, integer:1; 17, string; 18, block; 19, except_clause; 20, call; 21, function_name:creator; 22, parameters; 23, block; 24, attribute; 25, block; 26, else_clause; 27, identifier:a; 28, identifier:afdelingen; 29, block; 30, identifier:afdelingen; 31, string_content; 32, expression_statement; 33, identifier:AttributeError; 34, block; 35, attribute; 36, argument_list; 37, expression_statement; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, return_statement; 42, subscript; 43, identifier:is_configured; 44, expression_statement; 45, expression_statement; 46, block; 47, expression_statement; 48, escape_sequence:\; 49, assignment; 50, expression_statement; 51, expression_statement; 52, identifier:gemeente; 53, identifier:clear_gateway; 54, assignment; 55, assignment; 56, assignment; 57, assignment; 58, list_comprehension; 59, attribute; 60, string; 61, assignment; 62, assignment; 63, expression_statement; 64, call; 65, identifier:gid; 66, attribute; 67, assignment; 68, assignment; 69, identifier:url; 70, binary_operator:self.base_url + '/municipality/%s/department' % gid; 71, identifier:h; 72, attribute; 73, identifier:p; 74, dictionary; 75, identifier:res; 76, call; 77, call; 78, for_in_clause; 79, identifier:self; 80, identifier:caches; 81, string_content:permanent; 82, identifier:key; 83, binary_operator:'list_kadastrale_afdelingen_by_gemeente_rest#%s#%s' % (gid, sort); 84, identifier:afdelingen; 85, call; 86, assignment; 87, attribute; 88, argument_list; 89, identifier:gemeente; 90, identifier:id; 91, identifier:gid; 92, identifier:gemeente; 93, identifier:gemeente; 94, call; 95, attribute; 96, binary_operator:'/municipality/%s/department' % gid; 97, identifier:self; 98, identifier:base_headers; 99, pair; 100, attribute; 101, argument_list; 102, identifier:Afdeling; 103, argument_list; 104, identifier:r; 105, subscript; 106, string; 107, tuple; 108, attribute; 109, argument_list; 110, identifier:afdelingen; 111, call; 112, identifier:a; 113, identifier:set_gateway; 114, identifier:self; 115, attribute; 116, argument_list; 117, identifier:self; 118, identifier:base_url; 119, string; 120, identifier:gid; 121, string; 122, comparison_operator:sort == 1; 123, call; 124, identifier:json; 125, keyword_argument; 126, keyword_argument; 127, keyword_argument; 128, identifier:res; 129, string; 130, string_content:list_kadastrale_afdelingen_by_gemeente_rest#%s#%s; 131, identifier:gid; 132, identifier:sort; 133, subscript; 134, identifier:get_or_create; 135, identifier:key; 136, identifier:creator; 137, identifier:creator; 138, argument_list; 139, identifier:self; 140, identifier:get_gemeente_by_id; 141, identifier:gid; 142, string_content:/municipality/%s/department; 143, string_content:orderbyCode; 144, identifier:sort; 145, integer:1; 146, identifier:capakey_rest_gateway_request; 147, argument_list; 148, identifier:id; 149, subscript; 150, identifier:naam; 151, subscript; 152, identifier:gemeente; 153, identifier:gemeente; 154, string_content:departments; 155, attribute; 156, string; 157, identifier:url; 158, identifier:h; 159, identifier:p; 160, identifier:r; 161, string; 162, identifier:r; 163, string; 164, identifier:self; 165, identifier:caches; 166, string_content:permanent; 167, string_content:departmentCode; 168, string_content:departmentName
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; 7, 15; 7, 16; 8, 17; 9, 18; 9, 19; 10, 20; 11, 21; 11, 22; 11, 23; 12, 24; 12, 25; 12, 26; 13, 27; 13, 28; 13, 29; 14, 30; 17, 31; 18, 32; 19, 33; 19, 34; 20, 35; 20, 36; 23, 37; 23, 38; 23, 39; 23, 40; 23, 41; 24, 42; 24, 43; 25, 44; 25, 45; 26, 46; 29, 47; 31, 48; 32, 49; 34, 50; 34, 51; 35, 52; 35, 53; 37, 54; 38, 55; 39, 56; 40, 57; 41, 58; 42, 59; 42, 60; 44, 61; 45, 62; 46, 63; 47, 64; 49, 65; 49, 66; 50, 67; 51, 68; 54, 69; 54, 70; 55, 71; 55, 72; 56, 73; 56, 74; 57, 75; 57, 76; 58, 77; 58, 78; 59, 79; 59, 80; 60, 81; 61, 82; 61, 83; 62, 84; 62, 85; 63, 86; 64, 87; 64, 88; 66, 89; 66, 90; 67, 91; 67, 92; 68, 93; 68, 94; 70, 95; 70, 96; 72, 97; 72, 98; 74, 99; 76, 100; 76, 101; 77, 102; 77, 103; 78, 104; 78, 105; 83, 106; 83, 107; 85, 108; 85, 109; 86, 110; 86, 111; 87, 112; 87, 113; 88, 114; 94, 115; 94, 116; 95, 117; 95, 118; 96, 119; 96, 120; 99, 121; 99, 122; 100, 123; 100, 124; 103, 125; 103, 126; 103, 127; 105, 128; 105, 129; 106, 130; 107, 131; 107, 132; 108, 133; 108, 134; 109, 135; 109, 136; 111, 137; 111, 138; 115, 139; 115, 140; 116, 141; 119, 142; 121, 143; 122, 144; 122, 145; 123, 146; 123, 147; 125, 148; 125, 149; 126, 150; 126, 151; 127, 152; 127, 153; 129, 154; 133, 155; 133, 156; 147, 157; 147, 158; 147, 159; 149, 160; 149, 161; 151, 162; 151, 163; 155, 164; 155, 165; 156, 166; 161, 167; 163, 168
def list_kadastrale_afdelingen_by_gemeente(self, gemeente, sort=1): ''' List all `kadastrale afdelingen` in a `gemeente`. :param gemeente: The :class:`Gemeente` for which the \ `afdelingen` are wanted. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Afdeling`. ''' try: gid = gemeente.id except AttributeError: gid = gemeente gemeente = self.get_gemeente_by_id(gid) gemeente.clear_gateway() def creator(): url = self.base_url + '/municipality/%s/department' % gid h = self.base_headers p = { 'orderbyCode': sort == 1 } res = capakey_rest_gateway_request(url, h, p).json() return [ Afdeling( id=r['departmentCode'], naam=r['departmentName'], gemeente=gemeente ) for r in res['departments']] if self.caches['permanent'].is_configured: key = 'list_kadastrale_afdelingen_by_gemeente_rest#%s#%s' % (gid, sort) afdelingen = self.caches['permanent'].get_or_create(key, creator) else: afdelingen = creator() for a in afdelingen: a.set_gateway(self) return afdelingen
0, module; 1, function_definition; 2, function_name:list_percelen_by_sectie; 3, parameters; 4, block; 5, identifier:self; 6, identifier:sectie; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, function_definition; 13, if_statement; 14, for_statement; 15, return_statement; 16, string; 17, assignment; 18, assignment; 19, assignment; 20, call; 21, function_name:creator; 22, parameters; 23, block; 24, attribute; 25, block; 26, else_clause; 27, identifier:p; 28, identifier:percelen; 29, block; 30, identifier:percelen; 31, string_content:List all percelen in a `sectie`. :param sectie: The :class:`Sectie` for which the percelen are wanted. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Perceel`.; 32, identifier:sid; 33, attribute; 34, identifier:aid; 35, attribute; 36, identifier:gid; 37, attribute; 38, attribute; 39, argument_list; 40, expression_statement; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, return_statement; 45, subscript; 46, identifier:is_configured; 47, expression_statement; 48, expression_statement; 49, block; 50, expression_statement; 51, identifier:sectie; 52, identifier:id; 53, attribute; 54, identifier:id; 55, attribute; 56, identifier:id; 57, identifier:sectie; 58, identifier:clear_gateway; 59, assignment; 60, assignment; 61, assignment; 62, assignment; 63, list_comprehension; 64, attribute; 65, string; 66, assignment; 67, assignment; 68, expression_statement; 69, call; 70, identifier:sectie; 71, identifier:afdeling; 72, attribute; 73, identifier:gemeente; 74, identifier:url; 75, binary_operator:self.base_url + '/municipality/%s/department/%s/section/%s/parcel' % (gid, aid, sid); 76, identifier:h; 77, attribute; 78, identifier:p; 79, dictionary; 80, identifier:res; 81, call; 82, call; 83, for_in_clause; 84, identifier:self; 85, identifier:caches; 86, string_content:short; 87, identifier:key; 88, binary_operator:'list_percelen_by_sectie_rest#%s#%s#%s' % (gid, aid, sid); 89, identifier:percelen; 90, call; 91, assignment; 92, attribute; 93, argument_list; 94, identifier:sectie; 95, identifier:afdeling; 96, attribute; 97, binary_operator:'/municipality/%s/department/%s/section/%s/parcel' % (gid, aid, sid); 98, identifier:self; 99, identifier:base_headers; 100, pair; 101, attribute; 102, argument_list; 103, identifier:Perceel; 104, argument_list; 105, identifier:r; 106, subscript; 107, string; 108, tuple; 109, attribute; 110, argument_list; 111, identifier:percelen; 112, call; 113, identifier:p; 114, identifier:set_gateway; 115, identifier:self; 116, identifier:self; 117, identifier:base_url; 118, string; 119, tuple; 120, string; 121, string; 122, call; 123, identifier:json; 124, subscript; 125, identifier:sectie; 126, subscript; 127, call; 128, identifier:res; 129, string; 130, string_content:list_percelen_by_sectie_rest#%s#%s#%s; 131, identifier:gid; 132, identifier:aid; 133, identifier:sid; 134, subscript; 135, identifier:get_or_create; 136, identifier:key; 137, identifier:creator; 138, identifier:creator; 139, argument_list; 140, string_content:/municipality/%s/department/%s/section/%s/parcel; 141, identifier:gid; 142, identifier:aid; 143, identifier:sid; 144, string_content:data; 145, string_content:adp; 146, identifier:capakey_rest_gateway_request; 147, argument_list; 148, identifier:r; 149, string; 150, identifier:r; 151, string; 152, attribute; 153, argument_list; 154, string_content:parcels; 155, attribute; 156, string; 157, identifier:url; 158, identifier:h; 159, identifier:p; 160, string_content:perceelnummer; 161, string_content:capakey; 162, identifier:self; 163, identifier:parse_percid; 164, subscript; 165, identifier:self; 166, identifier:caches; 167, string_content:short; 168, identifier:r; 169, string; 170, string_content:capakey
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; 7, 16; 8, 17; 9, 18; 10, 19; 11, 20; 12, 21; 12, 22; 12, 23; 13, 24; 13, 25; 13, 26; 14, 27; 14, 28; 14, 29; 15, 30; 16, 31; 17, 32; 17, 33; 18, 34; 18, 35; 19, 36; 19, 37; 20, 38; 20, 39; 23, 40; 23, 41; 23, 42; 23, 43; 23, 44; 24, 45; 24, 46; 25, 47; 25, 48; 26, 49; 29, 50; 33, 51; 33, 52; 35, 53; 35, 54; 37, 55; 37, 56; 38, 57; 38, 58; 40, 59; 41, 60; 42, 61; 43, 62; 44, 63; 45, 64; 45, 65; 47, 66; 48, 67; 49, 68; 50, 69; 53, 70; 53, 71; 55, 72; 55, 73; 59, 74; 59, 75; 60, 76; 60, 77; 61, 78; 61, 79; 62, 80; 62, 81; 63, 82; 63, 83; 64, 84; 64, 85; 65, 86; 66, 87; 66, 88; 67, 89; 67, 90; 68, 91; 69, 92; 69, 93; 72, 94; 72, 95; 75, 96; 75, 97; 77, 98; 77, 99; 79, 100; 81, 101; 81, 102; 82, 103; 82, 104; 83, 105; 83, 106; 88, 107; 88, 108; 90, 109; 90, 110; 91, 111; 91, 112; 92, 113; 92, 114; 93, 115; 96, 116; 96, 117; 97, 118; 97, 119; 100, 120; 100, 121; 101, 122; 101, 123; 104, 124; 104, 125; 104, 126; 104, 127; 106, 128; 106, 129; 107, 130; 108, 131; 108, 132; 108, 133; 109, 134; 109, 135; 110, 136; 110, 137; 112, 138; 112, 139; 118, 140; 119, 141; 119, 142; 119, 143; 120, 144; 121, 145; 122, 146; 122, 147; 124, 148; 124, 149; 126, 150; 126, 151; 127, 152; 127, 153; 129, 154; 134, 155; 134, 156; 147, 157; 147, 158; 147, 159; 149, 160; 151, 161; 152, 162; 152, 163; 153, 164; 155, 165; 155, 166; 156, 167; 164, 168; 164, 169; 169, 170
def list_percelen_by_sectie(self, sectie): ''' List all percelen in a `sectie`. :param sectie: The :class:`Sectie` for which the percelen are wanted. :param integer sort: Field to sort on. :rtype: A :class:`list` of :class:`Perceel`. ''' sid = sectie.id aid = sectie.afdeling.id gid = sectie.afdeling.gemeente.id sectie.clear_gateway() def creator(): url = self.base_url + '/municipality/%s/department/%s/section/%s/parcel' % (gid, aid, sid) h = self.base_headers p = { 'data': 'adp' } res = capakey_rest_gateway_request(url, h, p).json() return [ Perceel( r['perceelnummer'], sectie, r['capakey'], self.parse_percid(r['capakey']), ) for r in res['parcels'] ] if self.caches['short'].is_configured: key = 'list_percelen_by_sectie_rest#%s#%s#%s' % (gid, aid, sid) percelen = self.caches['short'].get_or_create(key, creator) else: percelen = creator() for p in percelen: p.set_gateway(self) return percelen
0, module; 1, function_definition; 2, function_name:get_urls; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:order; 13, string:"total_clicks desc"; 14, identifier:offset; 15, None; 16, identifier:count; 17, None; 18, comment:"""Returns a list of URLs you've included in messages. List is sorted by ``total_clicks``, starting at an optional integer ``offset``, and optionally limited to the first ``count`` items. """; 19, assignment; 20, call; 21, identifier:req_data; 22, list; 23, attribute; 24, argument_list; 25, None; 26, identifier:order; 27, call; 28, identifier:self; 29, identifier:request; 30, string:"query:Message_Url"; 31, identifier:req_data; 32, identifier:fmt_paging; 33, argument_list; 34, identifier:offset; 35, identifier:count
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 7, 15; 8, 16; 8, 17; 9, 18; 10, 19; 11, 20; 19, 21; 19, 22; 20, 23; 20, 24; 22, 25; 22, 26; 22, 27; 23, 28; 23, 29; 24, 30; 24, 31; 27, 32; 27, 33; 33, 34; 33, 35
def get_urls(self, order="total_clicks desc", offset=None, count=None): """Returns a list of URLs you've included in messages. List is sorted by ``total_clicks``, starting at an optional integer ``offset``, and optionally limited to the first ``count`` items. """ req_data = [ None, order, fmt_paging(offset, count) ] return self.request("query:Message_Url", req_data)
0, module; 1, function_definition; 2, function_name:get_message_urls; 3, parameters; 4, block; 5, identifier:self; 6, identifier:message_id; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, identifier:order; 12, string:"total_clicks desc"; 13, comment:"""Returns a list of URLs you've included in a specific message. List is sorted by ``total_clicks``, starting at an optional integer ``offset``, and optionally limited to the first ``count`` items. """; 14, assignment; 15, call; 16, identifier:req_data; 17, list; 18, attribute; 19, argument_list; 20, dictionary; 21, identifier:order; 22, None; 23, identifier:self; 24, identifier:request; 25, string:"query:Message_Url"; 26, identifier:req_data; 27, pair; 28, string:"message_id"; 29, call; 30, identifier:str; 31, argument_list; 32, identifier:message_id
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; 14, 16; 14, 17; 15, 18; 15, 19; 17, 20; 17, 21; 17, 22; 18, 23; 18, 24; 19, 25; 19, 26; 20, 27; 27, 28; 27, 29; 29, 30; 29, 31; 31, 32
def get_message_urls(self, message_id, order="total_clicks desc"): """Returns a list of URLs you've included in a specific message. List is sorted by ``total_clicks``, starting at an optional integer ``offset``, and optionally limited to the first ``count`` items. """ req_data = [ { "message_id": str(message_id) }, order, None ] return self.request("query:Message_Url", req_data)
0, module; 1, function_definition; 2, function_name:trade_history; 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, default_parameter; 14, expression_statement; 15, return_statement; 16, identifier:from_; 17, None; 18, identifier:count; 19, None; 20, identifier:from_id; 21, None; 22, identifier:end_id; 23, None; 24, identifier:order; 25, None; 26, identifier:since; 27, None; 28, identifier:end; 29, None; 30, identifier:pair; 31, None; 32, comment:""" Returns trade history. To use this method you need a privilege of the info key. :param int or None from_: trade ID, from which the display starts (default 0) :param int or None count: the number of trades for display (default 1000) :param int or None from_id: trade ID, from which the display starts (default 0) :param int or None end_id: trade ID on which the display ends (default inf.) :param str or None order: sorting (default 'DESC') :param int or None since: the time to start the display (default 0) :param int or None end: the time to end the display (default inf.) :param str or None pair: pair to be displayed (ex. 'btc_usd') """; 33, call; 34, attribute; 35, argument_list; 36, identifier:self; 37, identifier:_trade_api_call; 38, string; 39, keyword_argument; 40, keyword_argument; 41, keyword_argument; 42, keyword_argument; 43, keyword_argument; 44, keyword_argument; 45, keyword_argument; 46, keyword_argument; 47, string_content:TradeHistory; 48, identifier:from_; 49, identifier:from_; 50, identifier:count; 51, identifier:count; 52, identifier:from_id; 53, identifier:from_id; 54, identifier:end_id; 55, identifier:end_id; 56, identifier:order; 57, identifier:order; 58, identifier:since; 59, identifier:since; 60, identifier:end; 61, identifier:end; 62, identifier:pair; 63, identifier:pair
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, 14; 4, 15; 6, 16; 6, 17; 7, 18; 7, 19; 8, 20; 8, 21; 9, 22; 9, 23; 10, 24; 10, 25; 11, 26; 11, 27; 12, 28; 12, 29; 13, 30; 13, 31; 14, 32; 15, 33; 33, 34; 33, 35; 34, 36; 34, 37; 35, 38; 35, 39; 35, 40; 35, 41; 35, 42; 35, 43; 35, 44; 35, 45; 35, 46; 38, 47; 39, 48; 39, 49; 40, 50; 40, 51; 41, 52; 41, 53; 42, 54; 42, 55; 43, 56; 43, 57; 44, 58; 44, 59; 45, 60; 45, 61; 46, 62; 46, 63
def trade_history( self, from_=None, count=None, from_id=None, end_id=None, order=None, since=None, end=None, pair=None ): """ Returns trade history. To use this method you need a privilege of the info key. :param int or None from_: trade ID, from which the display starts (default 0) :param int or None count: the number of trades for display (default 1000) :param int or None from_id: trade ID, from which the display starts (default 0) :param int or None end_id: trade ID on which the display ends (default inf.) :param str or None order: sorting (default 'DESC') :param int or None since: the time to start the display (default 0) :param int or None end: the time to end the display (default inf.) :param str or None pair: pair to be displayed (ex. 'btc_usd') """ return self._trade_api_call( 'TradeHistory', from_=from_, count=count, from_id=from_id, end_id=end_id, order=order, since=since, end=end, pair=pair )
0, module; 1, function_definition; 2, function_name:trans_history; 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, return_statement; 15, identifier:from_; 16, None; 17, identifier:count; 18, None; 19, identifier:from_id; 20, None; 21, identifier:end_id; 22, None; 23, identifier:order; 24, None; 25, identifier:since; 26, None; 27, identifier:end; 28, None; 29, comment:""" Returns the history of transactions. To use this method you need a privilege of the info key. :param int or None from_: transaction ID, from which the display starts (default 0) :param int or None count: number of transaction to be displayed (default 1000) :param int or None from_id: transaction ID, from which the display starts (default 0) :param int or None end_id: transaction ID on which the display ends (default inf.) :param str or None order: sorting (default 'DESC') :param int or None since: the time to start the display (default 0) :param int or None end: the time to end the display (default inf.) """; 30, call; 31, attribute; 32, argument_list; 33, identifier:self; 34, identifier:_trade_api_call; 35, string; 36, keyword_argument; 37, keyword_argument; 38, keyword_argument; 39, keyword_argument; 40, keyword_argument; 41, keyword_argument; 42, keyword_argument; 43, string_content:TransHistory; 44, identifier:from_; 45, identifier:from_; 46, identifier:count; 47, identifier:count; 48, identifier:from_id; 49, identifier:from_id; 50, identifier:end_id; 51, identifier:end_id; 52, identifier:order; 53, identifier:order; 54, identifier:since; 55, identifier:since; 56, identifier:end; 57, identifier:end
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; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 12, 27; 12, 28; 13, 29; 14, 30; 30, 31; 30, 32; 31, 33; 31, 34; 32, 35; 32, 36; 32, 37; 32, 38; 32, 39; 32, 40; 32, 41; 32, 42; 35, 43; 36, 44; 36, 45; 37, 46; 37, 47; 38, 48; 38, 49; 39, 50; 39, 51; 40, 52; 40, 53; 41, 54; 41, 55; 42, 56; 42, 57
def trans_history( self, from_=None, count=None, from_id=None, end_id=None, order=None, since=None, end=None ): """ Returns the history of transactions. To use this method you need a privilege of the info key. :param int or None from_: transaction ID, from which the display starts (default 0) :param int or None count: number of transaction to be displayed (default 1000) :param int or None from_id: transaction ID, from which the display starts (default 0) :param int or None end_id: transaction ID on which the display ends (default inf.) :param str or None order: sorting (default 'DESC') :param int or None since: the time to start the display (default 0) :param int or None end: the time to end the display (default inf.) """ return self._trade_api_call( 'TransHistory', from_=from_, count=count, from_id=from_id, end_id=end_id, order=order, since=since, end=end )
0, module; 1, function_definition; 2, function_name:get_atom_type_symbol; 3, parameters; 4, block; 5, identifier:cls; 6, identifier:calc; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:kwargs; 14, comment:""" Returns a list of atom types. Each atom site MUST occur only once in this list. List MUST be sorted. """; 15, assignment; 16, assignment; 17, comparison_operator:'basis_set' not in dictionary.keys(); 18, block; 19, call; 20, identifier:parameters; 21, attribute; 22, identifier:dictionary; 23, call; 24, string; 25, call; 26, return_statement; 27, identifier:sorted; 28, argument_list; 29, attribute; 30, identifier:output; 31, attribute; 32, argument_list; 33, string_content:basis_set; 34, attribute; 35, argument_list; 36, None; 37, call; 38, identifier:calc; 39, identifier:out; 40, identifier:parameters; 41, identifier:get_dict; 42, identifier:dictionary; 43, identifier:keys; 44, attribute; 45, argument_list; 46, subscript; 47, identifier:keys; 48, identifier:dictionary; 49, string; 50, string_content:basis_set
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; 11, 18; 12, 19; 15, 20; 15, 21; 16, 22; 16, 23; 17, 24; 17, 25; 18, 26; 19, 27; 19, 28; 21, 29; 21, 30; 23, 31; 23, 32; 24, 33; 25, 34; 25, 35; 26, 36; 28, 37; 29, 38; 29, 39; 31, 40; 31, 41; 34, 42; 34, 43; 37, 44; 37, 45; 44, 46; 44, 47; 46, 48; 46, 49; 49, 50
def get_atom_type_symbol(cls,calc,**kwargs): """ Returns a list of atom types. Each atom site MUST occur only once in this list. List MUST be sorted. """ parameters = calc.out.output dictionary = parameters.get_dict() if 'basis_set' not in dictionary.keys(): return None return sorted(dictionary['basis_set'].keys())
0, module; 1, function_definition; 2, function_name:sort_url; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, return_statement; 9, comment:""" Return the URL to sort the linked table by this column. If the table is already sorted by this column, the order is reversed. Since there is no canonical URL for a table the current URL (via the HttpRequest linked to the Table instance) is reused, and any unrelated parameters will be included in the output. """; 10, assignment; 11, call; 12, identifier:prefix; 13, boolean_operator; 14, attribute; 15, argument_list; 16, boolean_operator; 17, string:""; 18, attribute; 19, identifier:get_url; 20, keyword_argument; 21, parenthesized_expression; 22, string:"-"; 23, identifier:self; 24, identifier:table; 25, identifier:order_by; 26, binary_operator:prefix + self.name; 27, comparison_operator:self.sort_direction == "asc"; 28, identifier:prefix; 29, attribute; 30, attribute; 31, string:"asc"; 32, identifier:self; 33, identifier:name; 34, identifier:self; 35, identifier:sort_direction
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 10, 12; 10, 13; 11, 14; 11, 15; 13, 16; 13, 17; 14, 18; 14, 19; 15, 20; 16, 21; 16, 22; 18, 23; 18, 24; 20, 25; 20, 26; 21, 27; 26, 28; 26, 29; 27, 30; 27, 31; 29, 32; 29, 33; 30, 34; 30, 35
def sort_url(self): """ Return the URL to sort the linked table by this column. If the table is already sorted by this column, the order is reversed. Since there is no canonical URL for a table the current URL (via the HttpRequest linked to the Table instance) is reused, and any unrelated parameters will be included in the output. """ prefix = (self.sort_direction == "asc") and "-" or "" return self.table.get_url(order_by=prefix + self.name)
0, module; 1, function_definition; 2, function_name:append; 3, parameters; 4, block; 5, identifier:self; 6, identifier:newconfig; 7, expression_statement; 8, comment:# Check for commands where we accept multiple statements (no test_url); 9, for_statement; 10, comment:# Check for single statement commands;; 11, comment:# we do not overwrite existing values.; 12, for_statement; 13, comment:# HEADS UP: PHP → Python port.; 14, if_statement; 15, for_statement; 16, if_statement; 17, comment:""" Append another site config to current instance. All ``newconfig`` attributes are appended one by one to ours. Order matters, eg. current instance values will come first when merging. Thus, if you plan to use some sort of global site config with more generic directives, append it last for specific directives to be tried first. .. note:: this method is also aliased to :meth:`merge`. """; 18, identifier:attr_name; 19, tuple; 20, comment:# Append to ordered set. We keep ordering, but no duplicates.; 21, block; 22, identifier:attr_name; 23, tuple; 24, block; 25, comparison_operator:self.parser == 'libxml'; 26, block; 27, identifier:attr_name; 28, tuple; 29, comment:# Find/replace strings are lists, we extend.; 30, block; 31, attribute; 32, comment:# This will ease replacements in the extractor.; 33, block; 34, else_clause; 35, string; 36, string; 37, string; 38, string; 39, comment:# `language` is fixed in reset() and; 40, comment:# not supported in siteconfig syntax.; 41, string; 42, string; 43, string; 44, string; 45, string; 46, string; 47, string; 48, expression_statement; 49, for_statement; 50, expression_statement; 51, string; 52, string; 53, string; 54, string; 55, if_statement; 56, attribute; 57, string; 58, expression_statement; 59, string; 60, string; 61, expression_statement; 62, identifier:self; 63, identifier:find_string; 64, expression_statement; 65, block; 66, string_content:title; 67, string_content:body; 68, string_content:author; 69, string_content:date; 70, string_content:strip; 71, string_content:strip_id_or_class; 72, string_content:strip_image_src; 73, string_content:single_page_link; 74, string_content:single_page_link_in_feed; 75, string_content:next_page_link; 76, string_content:http_header; 77, assignment; 78, identifier:val; 79, call; 80, comment:# Too bad ordered set has no .union() method.; 81, block; 82, call; 83, string_content:parser; 84, string_content:tidy; 85, string_content:prune; 86, string_content:autodetect_on_failure; 87, comparison_operator:getattr(self, attr_name) is None; 88, block; 89, identifier:self; 90, identifier:parser; 91, string_content:libxml; 92, assignment; 93, string_content:find_string; 94, string_content:replace_string; 95, call; 96, assignment; 97, expression_statement; 98, identifier:current_set; 99, call; 100, identifier:getattr; 101, argument_list; 102, expression_statement; 103, identifier:setattr; 104, argument_list; 105, call; 106, None; 107, if_statement; 108, attribute; 109, string; 110, attribute; 111, argument_list; 112, attribute; 113, call; 114, assignment; 115, identifier:getattr; 116, argument_list; 117, identifier:newconfig; 118, identifier:attr_name; 119, call; 120, identifier:self; 121, identifier:attr_name; 122, identifier:current_set; 123, identifier:getattr; 124, argument_list; 125, comparison_operator:getattr(newconfig, attr_name) is None; 126, block; 127, else_clause; 128, identifier:self; 129, identifier:parser; 130, string_content:lxml; 131, call; 132, identifier:extend; 133, call; 134, identifier:self; 135, identifier:replace_patterns; 136, identifier:zip; 137, argument_list; 138, attribute; 139, None; 140, identifier:self; 141, identifier:attr_name; 142, attribute; 143, argument_list; 144, identifier:self; 145, identifier:attr_name; 146, call; 147, None; 148, expression_statement; 149, block; 150, identifier:getattr; 151, argument_list; 152, identifier:getattr; 153, argument_list; 154, attribute; 155, attribute; 156, identifier:self; 157, identifier:replace_patterns; 158, identifier:current_set; 159, identifier:add; 160, identifier:val; 161, identifier:getattr; 162, argument_list; 163, call; 164, expression_statement; 165, identifier:self; 166, identifier:attr_name; 167, identifier:newconfig; 168, identifier:attr_name; 169, identifier:self; 170, identifier:find_string; 171, identifier:self; 172, identifier:replace_string; 173, identifier:newconfig; 174, identifier:attr_name; 175, identifier:setattr; 176, argument_list; 177, call; 178, identifier:self; 179, identifier:attr_name; 180, subscript; 181, identifier:setattr; 182, argument_list; 183, attribute; 184, identifier:attr_name; 185, identifier:self; 186, identifier:attr_name; 187, call; 188, identifier:self; 189, identifier:defaults; 190, identifier:getattr; 191, argument_list; 192, identifier:newconfig; 193, identifier:attr_name
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; 7, 17; 9, 18; 9, 19; 9, 20; 9, 21; 12, 22; 12, 23; 12, 24; 14, 25; 14, 26; 15, 27; 15, 28; 15, 29; 15, 30; 16, 31; 16, 32; 16, 33; 16, 34; 19, 35; 19, 36; 19, 37; 19, 38; 19, 39; 19, 40; 19, 41; 19, 42; 19, 43; 19, 44; 19, 45; 19, 46; 19, 47; 21, 48; 21, 49; 21, 50; 23, 51; 23, 52; 23, 53; 23, 54; 24, 55; 25, 56; 25, 57; 26, 58; 28, 59; 28, 60; 30, 61; 31, 62; 31, 63; 33, 64; 34, 65; 35, 66; 36, 67; 37, 68; 38, 69; 41, 70; 42, 71; 43, 72; 44, 73; 45, 74; 46, 75; 47, 76; 48, 77; 49, 78; 49, 79; 49, 80; 49, 81; 50, 82; 51, 83; 52, 84; 53, 85; 54, 86; 55, 87; 55, 88; 56, 89; 56, 90; 57, 91; 58, 92; 59, 93; 60, 94; 61, 95; 64, 96; 65, 97; 77, 98; 77, 99; 79, 100; 79, 101; 81, 102; 82, 103; 82, 104; 87, 105; 87, 106; 88, 107; 92, 108; 92, 109; 95, 110; 95, 111; 96, 112; 96, 113; 97, 114; 99, 115; 99, 116; 101, 117; 101, 118; 102, 119; 104, 120; 104, 121; 104, 122; 105, 123; 105, 124; 107, 125; 107, 126; 107, 127; 108, 128; 108, 129; 109, 130; 110, 131; 110, 132; 111, 133; 112, 134; 112, 135; 113, 136; 113, 137; 114, 138; 114, 139; 116, 140; 116, 141; 119, 142; 119, 143; 124, 144; 124, 145; 125, 146; 125, 147; 126, 148; 127, 149; 131, 150; 131, 151; 133, 152; 133, 153; 137, 154; 137, 155; 138, 156; 138, 157; 142, 158; 142, 159; 143, 160; 146, 161; 146, 162; 148, 163; 149, 164; 151, 165; 151, 166; 153, 167; 153, 168; 154, 169; 154, 170; 155, 171; 155, 172; 162, 173; 162, 174; 163, 175; 163, 176; 164, 177; 176, 178; 176, 179; 176, 180; 177, 181; 177, 182; 180, 183; 180, 184; 182, 185; 182, 186; 182, 187; 183, 188; 183, 189; 187, 190; 187, 191; 191, 192; 191, 193
def append(self, newconfig): """ Append another site config to current instance. All ``newconfig`` attributes are appended one by one to ours. Order matters, eg. current instance values will come first when merging. Thus, if you plan to use some sort of global site config with more generic directives, append it last for specific directives to be tried first. .. note:: this method is also aliased to :meth:`merge`. """ # Check for commands where we accept multiple statements (no test_url) for attr_name in ( 'title', 'body', 'author', 'date', # `language` is fixed in reset() and # not supported in siteconfig syntax. 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'single_page_link_in_feed', 'next_page_link', 'http_header' ): # Append to ordered set. We keep ordering, but no duplicates. current_set = getattr(self, attr_name) for val in getattr(newconfig, attr_name): # Too bad ordered set has no .union() method. current_set.add(val) setattr(self, attr_name, current_set) # Check for single statement commands; # we do not overwrite existing values. for attr_name in ( 'parser', 'tidy', 'prune', 'autodetect_on_failure' ): if getattr(self, attr_name) is None: if getattr(newconfig, attr_name) is None: setattr(self, attr_name, self.defaults[attr_name]) else: setattr(self, attr_name, getattr(newconfig, attr_name)) # HEADS UP: PHP → Python port. if self.parser == 'libxml': self.parser = 'lxml' for attr_name in ('find_string', 'replace_string', ): # Find/replace strings are lists, we extend. getattr(self, attr_name).extend(getattr(newconfig, attr_name)) if self.find_string: # This will ease replacements in the extractor. self.replace_patterns = zip( self.find_string, self.replace_string) else: self.replace_patterns = None
0, module; 1, function_definition; 2, function_name:__exportUsers; 3, parameters; 4, block; 5, identifier:self; 6, identifier:sort; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, for_statement; 14, return_statement; 15, identifier:limit; 16, integer:0; 17, comment:"""Export the users to a dictionary. :param sort: field to sort the users :type sort: str. :return: exported users. :rtype: dict. """; 18, assignment; 19, assignment; 20, identifier:limit; 21, block; 22, assignment; 23, identifier:u; 24, identifier:dataUsers; 25, block; 26, identifier:exportedUsers; 27, identifier:position; 28, integer:1; 29, identifier:dataUsers; 30, call; 31, expression_statement; 32, identifier:exportedUsers; 33, list; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, if_statement; 38, expression_statement; 39, attribute; 40, argument_list; 41, assignment; 42, assignment; 43, assignment; 44, call; 45, comparison_operator:position < len(dataUsers); 46, block; 47, augmented_assignment; 48, identifier:self; 49, identifier:getSortedUsers; 50, identifier:sort; 51, identifier:dataUsers; 52, subscript; 53, identifier:userExported; 54, call; 55, subscript; 56, identifier:position; 57, attribute; 58, argument_list; 59, identifier:position; 60, call; 61, expression_statement; 62, identifier:position; 63, integer:1; 64, identifier:dataUsers; 65, slice; 66, attribute; 67, argument_list; 68, identifier:userExported; 69, string:"position"; 70, identifier:exportedUsers; 71, identifier:append; 72, identifier:userExported; 73, identifier:len; 74, argument_list; 75, assignment; 76, identifier:limit; 77, identifier:u; 78, identifier:export; 79, identifier:dataUsers; 80, subscript; 81, True; 82, identifier:userExported; 83, string:"comma"
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; 7, 15; 7, 16; 8, 17; 9, 18; 10, 19; 11, 20; 11, 21; 12, 22; 13, 23; 13, 24; 13, 25; 14, 26; 18, 27; 18, 28; 19, 29; 19, 30; 21, 31; 22, 32; 22, 33; 25, 34; 25, 35; 25, 36; 25, 37; 25, 38; 30, 39; 30, 40; 31, 41; 34, 42; 35, 43; 36, 44; 37, 45; 37, 46; 38, 47; 39, 48; 39, 49; 40, 50; 41, 51; 41, 52; 42, 53; 42, 54; 43, 55; 43, 56; 44, 57; 44, 58; 45, 59; 45, 60; 46, 61; 47, 62; 47, 63; 52, 64; 52, 65; 54, 66; 54, 67; 55, 68; 55, 69; 57, 70; 57, 71; 58, 72; 60, 73; 60, 74; 61, 75; 65, 76; 66, 77; 66, 78; 74, 79; 75, 80; 75, 81; 80, 82; 80, 83
def __exportUsers(self, sort, limit=0): """Export the users to a dictionary. :param sort: field to sort the users :type sort: str. :return: exported users. :rtype: dict. """ position = 1 dataUsers = self.getSortedUsers(sort) if limit: dataUsers = dataUsers[:limit] exportedUsers = [] for u in dataUsers: userExported = u.export() userExported["position"] = position exportedUsers.append(userExported) if position < len(dataUsers): userExported["comma"] = True position += 1 return exportedUsers
0, module; 1, function_definition; 2, function_name:zset_example; 3, parameters; 4, block; 5, expression_statement; 6, import_from_statement; 7, import_from_statement; 8, import_from_statement; 9, expression_statement; 10, expression_statement; 11, comment:# 97-114 is 'a' to 'r' in ASCII; 12, for_statement; 13, expression_statement; 14, expression_statement; 15, comment:# 17; 16, expression_statement; 17, comment:# 3; 18, expression_statement; 19, comment:# [1, 2, 3]; 20, expression_statement; 21, expression_statement; 22, comment:# <Page 3 of 3>; 23, expression_statement; 24, comment:# ['m', 'n', 'o', 'p', 'q']; 25, expression_statement; 26, comment:""" Example sorted set pagination. """; 27, dotted_name; 28, dotted_name; 29, dotted_name; 30, dotted_name; 31, dotted_name; 32, dotted_name; 33, assignment; 34, assignment; 35, identifier:x; 36, call; 37, block; 38, assignment; 39, call; 40, call; 41, call; 42, assignment; 43, call; 44, call; 45, call; 46, identifier:uuid; 47, identifier:uuid4; 48, identifier:redis; 49, identifier:StrictRedis; 50, identifier:zato; 51, identifier:redis_paginator; 52, identifier:ZSetPaginator; 53, identifier:conn; 54, call; 55, identifier:key; 56, call; 57, identifier:range; 58, argument_list; 59, expression_statement; 60, identifier:p; 61, call; 62, identifier:print; 63, argument_list; 64, identifier:print; 65, argument_list; 66, identifier:print; 67, argument_list; 68, identifier:page; 69, call; 70, identifier:print; 71, argument_list; 72, identifier:print; 73, argument_list; 74, attribute; 75, argument_list; 76, identifier:StrictRedis; 77, argument_list; 78, attribute; 79, argument_list; 80, integer:1; 81, integer:18; 82, call; 83, identifier:ZSetPaginator; 84, argument_list; 85, attribute; 86, attribute; 87, attribute; 88, attribute; 89, argument_list; 90, identifier:page; 91, attribute; 92, identifier:conn; 93, identifier:delete; 94, identifier:key; 95, string; 96, identifier:format; 97, attribute; 98, attribute; 99, argument_list; 100, identifier:conn; 101, identifier:key; 102, integer:6; 103, identifier:p; 104, identifier:count; 105, identifier:p; 106, identifier:num_pages; 107, identifier:p; 108, identifier:page_range; 109, identifier:p; 110, identifier:page; 111, integer:3; 112, identifier:page; 113, identifier:object_list; 114, string_content:paginator:{}; 115, call; 116, identifier:hex; 117, identifier:conn; 118, identifier:zadd; 119, identifier:key; 120, identifier:x; 121, call; 122, identifier:uuid4; 123, argument_list; 124, identifier:chr; 125, argument_list; 126, binary_operator:96 + x; 127, integer:96; 128, identifier:x
0, 1; 1, 2; 1, 3; 1, 4; 4, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 5, 26; 6, 27; 6, 28; 7, 29; 7, 30; 8, 31; 8, 32; 9, 33; 10, 34; 12, 35; 12, 36; 12, 37; 13, 38; 14, 39; 16, 40; 18, 41; 20, 42; 21, 43; 23, 44; 25, 45; 27, 46; 28, 47; 29, 48; 30, 49; 31, 50; 31, 51; 32, 52; 33, 53; 33, 54; 34, 55; 34, 56; 36, 57; 36, 58; 37, 59; 38, 60; 38, 61; 39, 62; 39, 63; 40, 64; 40, 65; 41, 66; 41, 67; 42, 68; 42, 69; 43, 70; 43, 71; 44, 72; 44, 73; 45, 74; 45, 75; 54, 76; 54, 77; 56, 78; 56, 79; 58, 80; 58, 81; 59, 82; 61, 83; 61, 84; 63, 85; 65, 86; 67, 87; 69, 88; 69, 89; 71, 90; 73, 91; 74, 92; 74, 93; 75, 94; 78, 95; 78, 96; 79, 97; 82, 98; 82, 99; 84, 100; 84, 101; 84, 102; 85, 103; 85, 104; 86, 105; 86, 106; 87, 107; 87, 108; 88, 109; 88, 110; 89, 111; 91, 112; 91, 113; 95, 114; 97, 115; 97, 116; 98, 117; 98, 118; 99, 119; 99, 120; 99, 121; 115, 122; 115, 123; 121, 124; 121, 125; 125, 126; 126, 127; 126, 128
def zset_example(): """ Example sorted set pagination. """ from uuid import uuid4 from redis import StrictRedis from zato.redis_paginator import ZSetPaginator conn = StrictRedis() key = 'paginator:{}'.format(uuid4().hex) # 97-114 is 'a' to 'r' in ASCII for x in range(1, 18): conn.zadd(key, x, chr(96 + x)) p = ZSetPaginator(conn, key, 6) print(p.count) # 17 print(p.num_pages) # 3 print(p.page_range) # [1, 2, 3] page = p.page(3) print(page) # <Page 3 of 3> print(page.object_list) # ['m', 'n', 'o', 'p', 'q'] conn.delete(key)
0, module; 1, function_definition; 2, function_name:paths_by_depth; 3, parameters; 4, block; 5, identifier:paths; 6, expression_statement; 7, return_statement; 8, comment:"""Sort list of paths by number of directories in it .. todo:: check if a final '/' is consistently given or ommitted. :param iterable paths: iterable containing paths (str) :rtype: list """; 9, call; 10, identifier:sorted; 11, argument_list; 12, identifier:paths; 13, keyword_argument; 14, keyword_argument; 15, identifier:key; 16, lambda; 17, identifier:reverse; 18, True; 19, lambda_parameters; 20, call; 21, identifier:path; 22, attribute; 23, argument_list; 24, identifier:path; 25, identifier:count; 26, attribute; 27, attribute; 28, identifier:sep; 29, identifier:os; 30, identifier:path
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; 13, 15; 13, 16; 14, 17; 14, 18; 16, 19; 16, 20; 19, 21; 20, 22; 20, 23; 22, 24; 22, 25; 23, 26; 26, 27; 26, 28; 27, 29; 27, 30
def paths_by_depth(paths): """Sort list of paths by number of directories in it .. todo:: check if a final '/' is consistently given or ommitted. :param iterable paths: iterable containing paths (str) :rtype: list """ return sorted( paths, key=lambda path: path.count(os.path.sep), reverse=True )
0, module; 1, function_definition; 2, function_name:normalize_date; 3, parameters; 4, block; 5, identifier:date; 6, expression_statement; 7, if_statement; 8, return_statement; 9, string:'''normalize the specified date to milliseconds since the epoch If it is a string, it is assumed to be some sort of datetime such as "2015-12-27" or "2015-12-27T11:01:20.954". If date is a naive datetime, it is assumed to be UTC. If numeric arguments are beyond 5138-11-16 (100,000,000,000 seconds after epoch), they are interpreted as milliseconds since the epoch. '''; 10, call; 11, block; 12, elif_clause; 13, elif_clause; 14, else_clause; 15, call; 16, identifier:isinstance; 17, argument_list; 18, pass_statement; 19, comparison_operator:date == "now"; 20, block; 21, call; 22, block; 23, block; 24, attribute; 25, argument_list; 26, identifier:date; 27, identifier:datetime; 28, identifier:date; 29, string:"now"; 30, expression_statement; 31, identifier:isinstance; 32, argument_list; 33, try_statement; 34, expression_statement; 35, raise_statement; 36, identifier:Metadata; 37, identifier:_from_datetime; 38, identifier:date; 39, assignment; 40, identifier:date; 41, tuple; 42, block; 43, except_clause; 44, assignment; 45, call; 46, identifier:date; 47, call; 48, identifier:basestring; 49, identifier:int; 50, identifier:float; 51, identifier:long; 52, expression_statement; 53, if_statement; 54, comment:# For unix timestamps on command line; 55, expression_statement; 56, identifier:ValueError; 57, block; 58, identifier:msg; 59, call; 60, identifier:InvalidDatalakeMetadata; 61, argument_list; 62, attribute; 63, argument_list; 64, assignment; 65, comparison_operator:ts > MAX_TS_SECONDS; 66, comment:# ts was provided in ms; 67, block; 68, assignment; 69, try_statement; 70, attribute; 71, argument_list; 72, identifier:msg; 73, identifier:datetime; 74, identifier:now; 75, attribute; 76, identifier:ts; 77, call; 78, identifier:ts; 79, identifier:MAX_TS_SECONDS; 80, expression_statement; 81, identifier:date; 82, call; 83, block; 84, except_clause; 85, string; 86, identifier:format; 87, identifier:date; 88, identifier:pytz; 89, identifier:UTC; 90, identifier:float; 91, argument_list; 92, assignment; 93, attribute; 94, argument_list; 95, expression_statement; 96, as_pattern; 97, block; 98, string_content:could not parse a date from {!r}; 99, identifier:date; 100, identifier:ts; 101, binary_operator:ts / 1000.0; 102, identifier:datetime; 103, identifier:utcfromtimestamp; 104, call; 105, assignment; 106, identifier:ValueError; 107, as_pattern_target; 108, raise_statement; 109, identifier:ts; 110, float:1000.0; 111, identifier:float; 112, argument_list; 113, identifier:date; 114, call; 115, identifier:e; 116, call; 117, identifier:ts; 118, identifier:dateparse; 119, argument_list; 120, identifier:InvalidDatalakeMetadata; 121, argument_list; 122, identifier:date; 123, call; 124, identifier:str; 125, argument_list; 126, identifier:e
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 7, 11; 7, 12; 7, 13; 7, 14; 8, 15; 10, 16; 10, 17; 11, 18; 12, 19; 12, 20; 13, 21; 13, 22; 14, 23; 15, 24; 15, 25; 17, 26; 17, 27; 19, 28; 19, 29; 20, 30; 21, 31; 21, 32; 22, 33; 23, 34; 23, 35; 24, 36; 24, 37; 25, 38; 30, 39; 32, 40; 32, 41; 33, 42; 33, 43; 34, 44; 35, 45; 39, 46; 39, 47; 41, 48; 41, 49; 41, 50; 41, 51; 42, 52; 42, 53; 42, 54; 42, 55; 43, 56; 43, 57; 44, 58; 44, 59; 45, 60; 45, 61; 47, 62; 47, 63; 52, 64; 53, 65; 53, 66; 53, 67; 55, 68; 57, 69; 59, 70; 59, 71; 61, 72; 62, 73; 62, 74; 63, 75; 64, 76; 64, 77; 65, 78; 65, 79; 67, 80; 68, 81; 68, 82; 69, 83; 69, 84; 70, 85; 70, 86; 71, 87; 75, 88; 75, 89; 77, 90; 77, 91; 80, 92; 82, 93; 82, 94; 83, 95; 84, 96; 84, 97; 85, 98; 91, 99; 92, 100; 92, 101; 93, 102; 93, 103; 94, 104; 95, 105; 96, 106; 96, 107; 97, 108; 101, 109; 101, 110; 104, 111; 104, 112; 105, 113; 105, 114; 107, 115; 108, 116; 112, 117; 114, 118; 114, 119; 116, 120; 116, 121; 119, 122; 121, 123; 123, 124; 123, 125; 125, 126
def normalize_date(date): '''normalize the specified date to milliseconds since the epoch If it is a string, it is assumed to be some sort of datetime such as "2015-12-27" or "2015-12-27T11:01:20.954". If date is a naive datetime, it is assumed to be UTC. If numeric arguments are beyond 5138-11-16 (100,000,000,000 seconds after epoch), they are interpreted as milliseconds since the epoch. ''' if isinstance(date, datetime): pass elif date == "now": date = datetime.now(pytz.UTC) elif isinstance(date, (basestring, int, float, long)): try: ts = float(date) if ts > MAX_TS_SECONDS: # ts was provided in ms ts = ts / 1000.0 # For unix timestamps on command line date = datetime.utcfromtimestamp(float(ts)) except ValueError: try: date = dateparse(date) except ValueError as e: raise InvalidDatalakeMetadata(str(e)) else: msg = 'could not parse a date from {!r}'.format(date) raise InvalidDatalakeMetadata(msg) return Metadata._from_datetime(date)
0, module; 1, function_definition; 2, function_name:format_float; 3, parameters; 4, block; 5, identifier:x; 6, identifier:max_width; 7, expression_statement; 8, comment:# width of (whole part + 1 (to avoid zero)) + 1 because int floors, not ceils; 9, expression_statement; 10, comment:# for +/- sign; 11, expression_statement; 12, comment:# for . if we show it; 13, expression_statement; 14, return_statement; 15, string; 16, assignment; 17, assignment; 18, assignment; 19, binary_operator:'%.*f' % (max_width - whole_width - sign_width - decimal_point_width, x); 20, string_content:format_float will ensure that a number's decimal part is truncated to fit within some bounds, unless the whole part is wider than max_width, which is a problem you need to sort out yourself.; 21, identifier:whole_width; 22, binary_operator:int(math.log10(abs(x) + 1)) + 1; 23, identifier:sign_width; 24, conditional_expression:1 if x < 0 else 0; 25, identifier:decimal_point_width; 26, conditional_expression:1 if max_width >= whole_width else 0; 27, string; 28, tuple; 29, call; 30, integer:1; 31, integer:1; 32, comparison_operator:x < 0; 33, integer:0; 34, integer:1; 35, comparison_operator:max_width >= whole_width; 36, integer:0; 37, string_content:%.*f; 38, binary_operator:max_width - whole_width - sign_width - decimal_point_width; 39, identifier:x; 40, identifier:int; 41, argument_list; 42, identifier:x; 43, integer:0; 44, identifier:max_width; 45, identifier:whole_width; 46, binary_operator:max_width - whole_width - sign_width; 47, identifier:decimal_point_width; 48, call; 49, binary_operator:max_width - whole_width; 50, identifier:sign_width; 51, attribute; 52, argument_list; 53, identifier:max_width; 54, identifier:whole_width; 55, identifier:math; 56, identifier:log10; 57, binary_operator:abs(x) + 1; 58, call; 59, integer:1; 60, identifier:abs; 61, argument_list; 62, identifier:x
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; 9, 16; 11, 17; 13, 18; 14, 19; 15, 20; 16, 21; 16, 22; 17, 23; 17, 24; 18, 25; 18, 26; 19, 27; 19, 28; 22, 29; 22, 30; 24, 31; 24, 32; 24, 33; 26, 34; 26, 35; 26, 36; 27, 37; 28, 38; 28, 39; 29, 40; 29, 41; 32, 42; 32, 43; 35, 44; 35, 45; 38, 46; 38, 47; 41, 48; 46, 49; 46, 50; 48, 51; 48, 52; 49, 53; 49, 54; 51, 55; 51, 56; 52, 57; 57, 58; 57, 59; 58, 60; 58, 61; 61, 62
def format_float(x, max_width): '''format_float will ensure that a number's decimal part is truncated to fit within some bounds, unless the whole part is wider than max_width, which is a problem you need to sort out yourself. ''' # width of (whole part + 1 (to avoid zero)) + 1 because int floors, not ceils whole_width = int(math.log10(abs(x) + 1)) + 1 # for +/- sign sign_width = 1 if x < 0 else 0 # for . if we show it decimal_point_width = 1 if max_width >= whole_width else 0 return '%.*f' % (max_width - whole_width - sign_width - decimal_point_width, x)
0, module; 1, function_definition; 2, function_name:__cleanup; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, comment:# set run to False and wait some time -> see what happens; 8, expression_statement; 9, if_statement; 10, try_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, comment:""" Wait at most twice as long as the given repetition interval for the _wrapper_function to terminate. If after that time the _wrapper_function has not terminated, send SIGTERM to and the process. Wait at most five times as long as the given repetition interval for the _wrapper_function to terminate. If the process still running send SIGKILL automatically if auto_kill_on_last_resort was set True or ask the user to confirm sending SIGKILL """; 16, assignment; 17, call; 18, block; 19, else_clause; 20, block; 21, except_clause; 22, call; 23, call; 24, call; 25, assignment; 26, attribute; 27, False; 28, identifier:check_process_termination; 29, argument_list; 30, expression_statement; 31, block; 32, expression_statement; 33, expression_statement; 34, identifier:OSError; 35, block; 36, attribute; 37, argument_list; 38, attribute; 39, argument_list; 40, attribute; 41, argument_list; 42, attribute; 43, False; 44, attribute; 45, identifier:value; 46, keyword_argument; 47, keyword_argument; 48, keyword_argument; 49, keyword_argument; 50, call; 51, raise_statement; 52, call; 53, call; 54, pass_statement; 55, identifier:log; 56, identifier:debug; 57, string:"wait for monitor thread to join"; 58, attribute; 59, identifier:join; 60, identifier:log; 61, identifier:debug; 62, string:"monitor thread to joined"; 63, attribute; 64, identifier:value; 65, identifier:self; 66, identifier:_run; 67, identifier:proc; 68, attribute; 69, identifier:timeout; 70, binary_operator:2*self.interval; 71, identifier:prefix; 72, string; 73, identifier:auto_kill_on_last_resort; 74, attribute; 75, attribute; 76, argument_list; 77, call; 78, attribute; 79, argument_list; 80, attribute; 81, argument_list; 82, identifier:self; 83, identifier:_monitor_thread; 84, identifier:self; 85, identifier:_func_running; 86, identifier:self; 87, identifier:_proc; 88, integer:2; 89, attribute; 90, identifier:self; 91, identifier:_auto_kill_on_last_resort; 92, identifier:log; 93, identifier:debug; 94, string:"cleanup successful"; 95, identifier:RuntimeError; 96, argument_list; 97, attribute; 98, identifier:close; 99, attribute; 100, identifier:stop; 101, identifier:self; 102, identifier:interval; 103, string:"cleanup FAILED!"; 104, identifier:self; 105, identifier:conn_send; 106, identifier:self; 107, identifier:_log_queue_listener
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; 8, 16; 9, 17; 9, 18; 9, 19; 10, 20; 10, 21; 11, 22; 12, 23; 13, 24; 14, 25; 16, 26; 16, 27; 17, 28; 17, 29; 18, 30; 19, 31; 20, 32; 20, 33; 21, 34; 21, 35; 22, 36; 22, 37; 23, 38; 23, 39; 24, 40; 24, 41; 25, 42; 25, 43; 26, 44; 26, 45; 29, 46; 29, 47; 29, 48; 29, 49; 30, 50; 31, 51; 32, 52; 33, 53; 35, 54; 36, 55; 36, 56; 37, 57; 38, 58; 38, 59; 40, 60; 40, 61; 41, 62; 42, 63; 42, 64; 44, 65; 44, 66; 46, 67; 46, 68; 47, 69; 47, 70; 48, 71; 48, 72; 49, 73; 49, 74; 50, 75; 50, 76; 51, 77; 52, 78; 52, 79; 53, 80; 53, 81; 58, 82; 58, 83; 63, 84; 63, 85; 68, 86; 68, 87; 70, 88; 70, 89; 74, 90; 74, 91; 75, 92; 75, 93; 76, 94; 77, 95; 77, 96; 78, 97; 78, 98; 80, 99; 80, 100; 89, 101; 89, 102; 96, 103; 97, 104; 97, 105; 99, 106; 99, 107
def __cleanup(self): """ Wait at most twice as long as the given repetition interval for the _wrapper_function to terminate. If after that time the _wrapper_function has not terminated, send SIGTERM to and the process. Wait at most five times as long as the given repetition interval for the _wrapper_function to terminate. If the process still running send SIGKILL automatically if auto_kill_on_last_resort was set True or ask the user to confirm sending SIGKILL """ # set run to False and wait some time -> see what happens self._run.value = False if check_process_termination(proc = self._proc, timeout = 2*self.interval, prefix = '', auto_kill_on_last_resort = self._auto_kill_on_last_resort): log.debug("cleanup successful") else: raise RuntimeError("cleanup FAILED!") try: self.conn_send.close() self._log_queue_listener.stop() except OSError: pass log.debug("wait for monitor thread to join") self._monitor_thread.join() log.debug("monitor thread to joined") self._func_running.value = False
0, module; 1, function_definition; 2, function_name:regroup; 3, parameters; 4, block; 5, identifier:target; 6, identifier:expression; 7, expression_statement; 8, if_statement; 9, return_statement; 10, comment:""" Regroups a list of alike objects by a common attribute. This complex tag is best illustrated by use of an example: say that ``people`` is a list of ``Person`` objects that have ``first_name``, ``last_name``, and ``gender`` attributes, and you'd like to display a list that looks like: * Male: * George Bush * Bill Clinton * Female: * Margaret Thatcher * Colendeeza Rice * Unknown: * Pat Smith The following snippet of template code would accomplish this dubious task:: {% regroup people by gender as grouped %} <ul> {% for group in grouped %} <li>{{ group.grouper }} <ul> {% for item in group.list %} <li>{{ item }}</li> {% endfor %} </ul> {% endfor %} </ul> As you can see, ``{% regroup %}`` populates a variable with a list of objects with ``grouper`` and ``list`` attributes. ``grouper`` contains the item that was grouped by; ``list`` contains the list of objects that share that ``grouper``. In this case, ``grouper`` would be ``Male``, ``Female`` and ``Unknown``, and ``list`` is the list of people with those genders. Note that ``{% regroup %}`` does not work when the list to be grouped is not sorted by the key you are grouping by! This means that if your list of people was not sorted by gender, you'd need to make sure it is sorted before using it, i.e.:: {% regroup people|dictsort:"gender" by gender as grouped %} """; 11, not_operator; 12, block; 13, list_comprehension; 14, identifier:target; 15, return_statement; 16, comment:# List of dictionaries in the format:; 17, comment:# {'grouper': 'key', 'list': [list of contents]}.; 18, dictionary; 19, for_in_clause; 20, string; 21, pair; 22, pair; 23, pattern_list; 24, call; 25, string; 26, identifier:key; 27, string; 28, call; 29, identifier:key; 30, identifier:val; 31, identifier:groupby; 32, argument_list; 33, string_content:grouper; 34, string_content:list; 35, identifier:list; 36, argument_list; 37, identifier:obj_list; 38, lambda; 39, identifier:val; 40, lambda_parameters; 41, call; 42, identifier:v; 43, default_parameter; 44, identifier:f; 45, argument_list; 46, identifier:f; 47, attribute; 48, identifier:v; 49, True; 50, identifier:expression; 51, identifier:resolve
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 8, 12; 9, 13; 11, 14; 12, 15; 13, 16; 13, 17; 13, 18; 13, 19; 15, 20; 18, 21; 18, 22; 19, 23; 19, 24; 21, 25; 21, 26; 22, 27; 22, 28; 23, 29; 23, 30; 24, 31; 24, 32; 25, 33; 27, 34; 28, 35; 28, 36; 32, 37; 32, 38; 36, 39; 38, 40; 38, 41; 40, 42; 40, 43; 41, 44; 41, 45; 43, 46; 43, 47; 45, 48; 45, 49; 47, 50; 47, 51
def regroup(target, expression): """ Regroups a list of alike objects by a common attribute. This complex tag is best illustrated by use of an example: say that ``people`` is a list of ``Person`` objects that have ``first_name``, ``last_name``, and ``gender`` attributes, and you'd like to display a list that looks like: * Male: * George Bush * Bill Clinton * Female: * Margaret Thatcher * Colendeeza Rice * Unknown: * Pat Smith The following snippet of template code would accomplish this dubious task:: {% regroup people by gender as grouped %} <ul> {% for group in grouped %} <li>{{ group.grouper }} <ul> {% for item in group.list %} <li>{{ item }}</li> {% endfor %} </ul> {% endfor %} </ul> As you can see, ``{% regroup %}`` populates a variable with a list of objects with ``grouper`` and ``list`` attributes. ``grouper`` contains the item that was grouped by; ``list`` contains the list of objects that share that ``grouper``. In this case, ``grouper`` would be ``Male``, ``Female`` and ``Unknown``, and ``list`` is the list of people with those genders. Note that ``{% regroup %}`` does not work when the list to be grouped is not sorted by the key you are grouping by! This means that if your list of people was not sorted by gender, you'd need to make sure it is sorted before using it, i.e.:: {% regroup people|dictsort:"gender" by gender as grouped %} """ if not target: return '' return [ # List of dictionaries in the format: # {'grouper': 'key', 'list': [list of contents]}. {'grouper': key, 'list': list(val)} for key, val in groupby(obj_list, lambda v, f=expression.resolve: f(v, True)) ]
0, module; 1, function_definition; 2, function_name:entityTriples; 3, parameters; 4, block; 5, identifier:rdfGraph; 6, identifier:anEntity; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, comment:# extract predicate/object; 14, for_statement; 15, comment:# sorting; 16, if_statement; 17, comment:# if niceURI:; 18, comment:# temp = [(uri2niceString(ontology, y), z) for y,z in temp]; 19, return_statement; 20, identifier:excludeProps; 21, False; 22, identifier:excludeBNodes; 23, False; 24, identifier:orderProps; 25, list; 26, comment:""" Returns the pred-obj for any given resource, excluding selected ones.. Sorting: by default results are sorted alphabetically and according to namespaces: [RDF, RDFS, OWL.OWLNS, DC.DCNS] """; 27, assignment; 28, not_operator; 29, block; 30, pattern_list; 31, call; 32, block; 33, comparison_operator:type(orderProps) == type([]); 34, block; 35, elif_clause; 36, identifier:temp; 37, identifier:RDF; 38, identifier:RDFS; 39, attribute; 40, attribute; 41, identifier:temp; 42, list; 43, identifier:excludeProps; 44, expression_statement; 45, identifier:x; 46, identifier:y; 47, identifier:z; 48, attribute; 49, argument_list; 50, if_statement; 51, if_statement; 52, call; 53, call; 54, expression_statement; 55, comment:# order props only; 56, expression_statement; 57, comment:# create form: [(1, 'something'),(2,'bobby'),(3,'suzy'),(4,'crab')]; 58, expression_statement; 59, comment:# create dict to pass to sorted procedure; 60, expression_statement; 61, identifier:orderProps; 62, comment:# default to alpha sorting unless False; 63, block; 64, identifier:OWL; 65, identifier:OWLNS; 66, identifier:DC; 67, identifier:DCNS; 68, assignment; 69, identifier:rdfGraph; 70, identifier:triples; 71, tuple; 72, boolean_operator; 73, block; 74, comparison_operator:y not in excludeProps; 75, block; 76, identifier:type; 77, argument_list; 78, identifier:type; 79, argument_list; 80, assignment; 81, assignment; 82, assignment; 83, assignment; 84, expression_statement; 85, identifier:excludeProps; 86, list; 87, identifier:anEntity; 88, None; 89, None; 90, identifier:excludeBNodes; 91, call; 92, continue_statement; 93, identifier:y; 94, identifier:excludeProps; 95, expression_statement; 96, identifier:orderProps; 97, list; 98, identifier:orderedUris; 99, call; 100, identifier:orderedUris; 101, list_comprehension; 102, identifier:rank; 103, call; 104, identifier:temp; 105, call; 106, assignment; 107, identifier:isBlankNode; 108, argument_list; 109, augmented_assignment; 110, identifier:sortByNamespacePrefix; 111, argument_list; 112, tuple; 113, for_in_clause; 114, identifier:dict; 115, generator_expression; 116, identifier:sorted; 117, argument_list; 118, identifier:temp; 119, call; 120, identifier:z; 121, identifier:temp; 122, list; 123, list_comprehension; 124, identifier:orderProps; 125, binary_operator:n + 1; 126, identifier:x; 127, pattern_list; 128, call; 129, tuple; 130, for_in_clause; 131, identifier:temp; 132, keyword_argument; 133, identifier:sorted; 134, argument_list; 135, tuple; 136, identifier:y; 137, for_in_clause; 138, identifier:n; 139, integer:1; 140, identifier:n; 141, identifier:x; 142, identifier:enumerate; 143, argument_list; 144, identifier:key; 145, identifier:rank; 146, tuple_pattern; 147, identifier:orderedUris; 148, identifier:key; 149, lambda; 150, identifier:temp; 151, keyword_argument; 152, identifier:y; 153, identifier:z; 154, pattern_list; 155, identifier:temp; 156, identifier:orderedUris; 157, identifier:rank; 158, identifier:key; 159, lambda_parameters; 160, call; 161, identifier:key; 162, lambda; 163, identifier:y; 164, identifier:z; 165, identifier:tup; 166, attribute; 167, argument_list; 168, lambda_parameters; 169, subscript; 170, identifier:rank; 171, identifier:get; 172, subscript; 173, identifier:tup; 174, identifier:tup; 175, integer:0; 176, identifier:tup; 177, integer:0
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; 7, 20; 7, 21; 8, 22; 8, 23; 9, 24; 9, 25; 10, 26; 11, 27; 12, 28; 12, 29; 14, 30; 14, 31; 14, 32; 16, 33; 16, 34; 16, 35; 19, 36; 25, 37; 25, 38; 25, 39; 25, 40; 27, 41; 27, 42; 28, 43; 29, 44; 30, 45; 30, 46; 30, 47; 31, 48; 31, 49; 32, 50; 32, 51; 33, 52; 33, 53; 34, 54; 34, 55; 34, 56; 34, 57; 34, 58; 34, 59; 34, 60; 35, 61; 35, 62; 35, 63; 39, 64; 39, 65; 40, 66; 40, 67; 44, 68; 48, 69; 48, 70; 49, 71; 50, 72; 50, 73; 51, 74; 51, 75; 52, 76; 52, 77; 53, 78; 53, 79; 54, 80; 56, 81; 58, 82; 60, 83; 63, 84; 68, 85; 68, 86; 71, 87; 71, 88; 71, 89; 72, 90; 72, 91; 73, 92; 74, 93; 74, 94; 75, 95; 77, 96; 79, 97; 80, 98; 80, 99; 81, 100; 81, 101; 82, 102; 82, 103; 83, 104; 83, 105; 84, 106; 91, 107; 91, 108; 95, 109; 99, 110; 99, 111; 101, 112; 101, 113; 103, 114; 103, 115; 105, 116; 105, 117; 106, 118; 106, 119; 108, 120; 109, 121; 109, 122; 111, 123; 111, 124; 112, 125; 112, 126; 113, 127; 113, 128; 115, 129; 115, 130; 117, 131; 117, 132; 119, 133; 119, 134; 122, 135; 123, 136; 123, 137; 125, 138; 125, 139; 127, 140; 127, 141; 128, 142; 128, 143; 129, 144; 129, 145; 130, 146; 130, 147; 132, 148; 132, 149; 134, 150; 134, 151; 135, 152; 135, 153; 137, 154; 137, 155; 143, 156; 146, 157; 146, 158; 149, 159; 149, 160; 151, 161; 151, 162; 154, 163; 154, 164; 159, 165; 160, 166; 160, 167; 162, 168; 162, 169; 166, 170; 166, 171; 167, 172; 168, 173; 169, 174; 169, 175; 172, 176; 172, 177
def entityTriples(rdfGraph, anEntity, excludeProps=False, excludeBNodes=False, orderProps=[RDF, RDFS, OWL.OWLNS, DC.DCNS]): """ Returns the pred-obj for any given resource, excluding selected ones.. Sorting: by default results are sorted alphabetically and according to namespaces: [RDF, RDFS, OWL.OWLNS, DC.DCNS] """ temp = [] if not excludeProps: excludeProps = [] # extract predicate/object for x, y, z in rdfGraph.triples((anEntity, None, None)): if excludeBNodes and isBlankNode(z): continue if y not in excludeProps: temp += [(y, z)] # sorting if type(orderProps) == type([]): orderedUris = sortByNamespacePrefix([y for y, z in temp], orderProps) # order props only orderedUris = [(n + 1, x) for n, x in enumerate(orderedUris)] # create form: [(1, 'something'),(2,'bobby'),(3,'suzy'),(4,'crab')] rank = dict((key, rank) for (rank, key) in orderedUris) # create dict to pass to sorted procedure temp = sorted(temp, key=lambda tup: rank.get(tup[0])) elif orderProps: # default to alpha sorting unless False temp = sorted(temp, key=lambda tup: tup[0]) # if niceURI: # temp = [(uri2niceString(ontology, y), z) for y,z in temp] return temp
0, module; 1, function_definition; 2, function_name:msvd; 3, parameters; 4, block; 5, identifier:m; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, comment:# reverse the n first columns of u; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""Modified singular value decomposition. Returns U, S, V where Udagger M V = diag(S) and the singular values are sorted in ascending order (small to large). """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, expression_list; 21, pattern_list; 22, call; 23, identifier:order; 24, call; 25, identifier:s; 26, subscript; 27, identifier:u; 28, subscript; 29, identifier:vdgr; 30, subscript; 31, identifier:u; 32, identifier:s; 33, attribute; 34, identifier:u; 35, identifier:s; 36, identifier:vdgr; 37, attribute; 38, argument_list; 39, attribute; 40, argument_list; 41, identifier:s; 42, identifier:order; 43, identifier:u; 44, slice; 45, identifier:order; 46, identifier:vdgr; 47, identifier:order; 48, call; 49, identifier:T; 50, attribute; 51, identifier:svd; 52, identifier:m; 53, identifier:s; 54, identifier:argsort; 55, attribute; 56, argument_list; 57, identifier:np; 58, identifier:linalg; 59, identifier:vdgr; 60, identifier:conj
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 7, 15; 8, 16; 10, 17; 11, 18; 12, 19; 13, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 20, 31; 20, 32; 20, 33; 21, 34; 21, 35; 21, 36; 22, 37; 22, 38; 24, 39; 24, 40; 26, 41; 26, 42; 28, 43; 28, 44; 28, 45; 30, 46; 30, 47; 33, 48; 33, 49; 37, 50; 37, 51; 38, 52; 39, 53; 39, 54; 48, 55; 48, 56; 50, 57; 50, 58; 55, 59; 55, 60
def msvd(m): """Modified singular value decomposition. Returns U, S, V where Udagger M V = diag(S) and the singular values are sorted in ascending order (small to large). """ u, s, vdgr = np.linalg.svd(m) order = s.argsort() # reverse the n first columns of u s = s[order] u= u[:,order] vdgr = vdgr[order] return u, s, vdgr.conj().T
0, module; 1, function_definition; 2, function_name:_rows_sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:rows; 7, expression_statement; 8, return_statement; 9, comment:""" Returns a list of rows sorted by start and end date. :param list[dict[str,T]] rows: The list of rows. :rtype: list[dict[str,T]] """; 10, call; 11, identifier:sorted; 12, argument_list; 13, identifier:rows; 14, keyword_argument; 15, identifier:key; 16, lambda; 17, lambda_parameters; 18, tuple; 19, identifier:row; 20, subscript; 21, subscript; 22, identifier:row; 23, attribute; 24, identifier:row; 25, attribute; 26, identifier:self; 27, identifier:_key_start_date; 28, identifier:self; 29, identifier:_key_end_date
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 12, 13; 12, 14; 14, 15; 14, 16; 16, 17; 16, 18; 17, 19; 18, 20; 18, 21; 20, 22; 20, 23; 21, 24; 21, 25; 23, 26; 23, 27; 25, 28; 25, 29
def _rows_sort(self, rows): """ Returns a list of rows sorted by start and end date. :param list[dict[str,T]] rows: The list of rows. :rtype: list[dict[str,T]] """ return sorted(rows, key=lambda row: (row[self._key_start_date], row[self._key_end_date]))
0, module; 1, function_definition; 2, function_name:get_rows; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, identifier:sort; 12, False; 13, comment:""" Returns the rows of this Type2Helper. :param bool sort: If True the rows are sorted by the pseudo key. """; 14, assignment; 15, pattern_list; 16, conditional_expression:sorted(self._rows.items()) if sort else self._rows.items(); 17, block; 18, identifier:ret; 19, identifier:ret; 20, list; 21, identifier:_; 22, identifier:rows; 23, call; 24, identifier:sort; 25, call; 26, expression_statement; 27, expression_statement; 28, identifier:sorted; 29, argument_list; 30, attribute; 31, argument_list; 32, call; 33, call; 34, call; 35, attribute; 36, identifier:items; 37, attribute; 38, argument_list; 39, attribute; 40, argument_list; 41, attribute; 42, argument_list; 43, identifier:self; 44, identifier:_rows; 45, identifier:self; 46, identifier:_rows_int2date; 47, identifier:rows; 48, identifier:ret; 49, identifier:extend; 50, identifier:rows; 51, attribute; 52, identifier:items; 53, identifier:self; 54, identifier:_rows
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 8, 14; 9, 15; 9, 16; 9, 17; 10, 18; 14, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 16, 25; 17, 26; 17, 27; 23, 28; 23, 29; 25, 30; 25, 31; 26, 32; 27, 33; 29, 34; 30, 35; 30, 36; 32, 37; 32, 38; 33, 39; 33, 40; 34, 41; 34, 42; 35, 43; 35, 44; 37, 45; 37, 46; 38, 47; 39, 48; 39, 49; 40, 50; 41, 51; 41, 52; 51, 53; 51, 54
def get_rows(self, sort=False): """ Returns the rows of this Type2Helper. :param bool sort: If True the rows are sorted by the pseudo key. """ ret = [] for _, rows in sorted(self._rows.items()) if sort else self._rows.items(): self._rows_int2date(rows) ret.extend(rows) return ret
0, module; 1, function_definition; 2, function_name:get_entries; 3, parameters; 4, block; 5, identifier:path; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, comment:"""Return sorted lists of directories and files in the given path."""; 13, assignment; 14, identifier:entry; 15, call; 16, comment:# Categorize entry as directory or file.; 17, block; 18, call; 19, call; 20, expression_list; 21, pattern_list; 22, expression_list; 23, attribute; 24, argument_list; 25, if_statement; 26, attribute; 27, argument_list; 28, attribute; 29, argument_list; 30, identifier:dirs; 31, identifier:files; 32, identifier:dirs; 33, identifier:files; 34, list; 35, list; 36, identifier:os; 37, identifier:listdir; 38, identifier:path; 39, call; 40, block; 41, else_clause; 42, identifier:dirs; 43, identifier:sort; 44, identifier:files; 45, identifier:sort; 46, attribute; 47, argument_list; 48, expression_statement; 49, block; 50, attribute; 51, identifier:isdir; 52, call; 53, call; 54, expression_statement; 55, identifier:os; 56, identifier:path; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, call; 62, attribute; 63, identifier:join; 64, identifier:path; 65, identifier:entry; 66, identifier:dirs; 67, identifier:append; 68, identifier:entry; 69, attribute; 70, argument_list; 71, identifier:os; 72, identifier:path; 73, identifier:files; 74, identifier:append; 75, identifier:entry
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; 8, 14; 8, 15; 8, 16; 8, 17; 9, 18; 10, 19; 11, 20; 13, 21; 13, 22; 15, 23; 15, 24; 17, 25; 18, 26; 18, 27; 19, 28; 19, 29; 20, 30; 20, 31; 21, 32; 21, 33; 22, 34; 22, 35; 23, 36; 23, 37; 24, 38; 25, 39; 25, 40; 25, 41; 26, 42; 26, 43; 28, 44; 28, 45; 39, 46; 39, 47; 40, 48; 41, 49; 46, 50; 46, 51; 47, 52; 48, 53; 49, 54; 50, 55; 50, 56; 52, 57; 52, 58; 53, 59; 53, 60; 54, 61; 57, 62; 57, 63; 58, 64; 58, 65; 59, 66; 59, 67; 60, 68; 61, 69; 61, 70; 62, 71; 62, 72; 69, 73; 69, 74; 70, 75
def get_entries(path): """Return sorted lists of directories and files in the given path.""" dirs, files = [], [] for entry in os.listdir(path): # Categorize entry as directory or file. if os.path.isdir(os.path.join(path, entry)): dirs.append(entry) else: files.append(entry) dirs.sort() files.sort() return dirs, files
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:ctx; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, comment:"""Sort the variants of a vcf file"""; 14, assignment; 15, assignment; 16, assignment; 17, assignment; 18, call; 19, identifier:line; 20, call; 21, block; 22, identifier:head; 23, attribute; 24, identifier:vcf_handle; 25, attribute; 26, identifier:outfile; 27, attribute; 28, identifier:silent; 29, attribute; 30, identifier:print_headers; 31, argument_list; 32, identifier:sort_variants; 33, argument_list; 34, expression_statement; 35, attribute; 36, identifier:head; 37, attribute; 38, identifier:handle; 39, attribute; 40, identifier:outfile; 41, attribute; 42, identifier:silent; 43, identifier:head; 44, keyword_argument; 45, keyword_argument; 46, identifier:vcf_handle; 47, call; 48, identifier:ctx; 49, identifier:parent; 50, identifier:ctx; 51, identifier:parent; 52, identifier:ctx; 53, identifier:parent; 54, identifier:ctx; 55, identifier:parent; 56, identifier:outfile; 57, identifier:outfile; 58, identifier:silent; 59, identifier:silent; 60, identifier:print_variant; 61, argument_list; 62, keyword_argument; 63, keyword_argument; 64, keyword_argument; 65, identifier:variant_line; 66, identifier:line; 67, identifier:outfile; 68, identifier:outfile; 69, identifier:silent; 70, identifier:silent
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 12, 19; 12, 20; 12, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 16, 27; 17, 28; 17, 29; 18, 30; 18, 31; 20, 32; 20, 33; 21, 34; 23, 35; 23, 36; 25, 37; 25, 38; 27, 39; 27, 40; 29, 41; 29, 42; 31, 43; 31, 44; 31, 45; 33, 46; 34, 47; 35, 48; 35, 49; 37, 50; 37, 51; 39, 52; 39, 53; 41, 54; 41, 55; 44, 56; 44, 57; 45, 58; 45, 59; 47, 60; 47, 61; 61, 62; 61, 63; 61, 64; 62, 65; 62, 66; 63, 67; 63, 68; 64, 69; 64, 70
def sort(ctx): """Sort the variants of a vcf file""" head = ctx.parent.head vcf_handle = ctx.parent.handle outfile = ctx.parent.outfile silent = ctx.parent.silent print_headers(head, outfile=outfile, silent=silent) for line in sort_variants(vcf_handle): print_variant(variant_line=line, outfile=outfile, silent=silent)
0, module; 1, function_definition; 2, function_name:_sort_to_str; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, expression_statement; 12, comment:""" Before exec query, this method transforms sort dict string from {"name": "asc", "timestamp":"desc"} to "name asc, timestamp desc" """; 13, assignment; 14, assignment; 15, pattern_list; 16, call; 17, block; 18, call; 19, assignment; 20, identifier:params_list; 21, list; 22, identifier:timestamp; 23, string:""; 24, identifier:k; 25, identifier:v; 26, attribute; 27, argument_list; 28, if_statement; 29, attribute; 30, argument_list; 31, subscript; 32, call; 33, subscript; 34, identifier:items; 35, comparison_operator:k != "timestamp"; 36, block; 37, else_clause; 38, identifier:params_list; 39, identifier:append; 40, call; 41, attribute; 42, string; 43, attribute; 44, argument_list; 45, attribute; 46, string; 47, identifier:k; 48, string:"timestamp"; 49, expression_statement; 50, block; 51, attribute; 52, argument_list; 53, identifier:self; 54, identifier:_solr_params; 55, string_content:sort; 56, string:", "; 57, identifier:join; 58, identifier:params_list; 59, identifier:self; 60, identifier:_solr_params; 61, string_content:sort; 62, call; 63, expression_statement; 64, string:" "; 65, identifier:join; 66, list; 67, attribute; 68, argument_list; 69, assignment; 70, string; 71, identifier:timestamp; 72, identifier:params_list; 73, identifier:append; 74, call; 75, identifier:timestamp; 76, identifier:v; 77, string_content:timestamp; 78, attribute; 79, argument_list; 80, string:" "; 81, identifier:join; 82, list; 83, identifier:k; 84, identifier:v
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; 8, 14; 9, 15; 9, 16; 9, 17; 10, 18; 11, 19; 13, 20; 13, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 16, 27; 17, 28; 18, 29; 18, 30; 19, 31; 19, 32; 26, 33; 26, 34; 28, 35; 28, 36; 28, 37; 29, 38; 29, 39; 30, 40; 31, 41; 31, 42; 32, 43; 32, 44; 33, 45; 33, 46; 35, 47; 35, 48; 36, 49; 37, 50; 40, 51; 40, 52; 41, 53; 41, 54; 42, 55; 43, 56; 43, 57; 44, 58; 45, 59; 45, 60; 46, 61; 49, 62; 50, 63; 51, 64; 51, 65; 52, 66; 62, 67; 62, 68; 63, 69; 66, 70; 66, 71; 67, 72; 67, 73; 68, 74; 69, 75; 69, 76; 70, 77; 74, 78; 74, 79; 78, 80; 78, 81; 79, 82; 82, 83; 82, 84
def _sort_to_str(self): """ Before exec query, this method transforms sort dict string from {"name": "asc", "timestamp":"desc"} to "name asc, timestamp desc" """ params_list = [] timestamp = "" for k, v in self._solr_params['sort'].items(): if k != "timestamp": params_list.append(" ".join([k, v])) else: timestamp = v params_list.append(" ".join(['timestamp', timestamp])) self._solr_params['sort'] = ", ".join(params_list)
0, module; 1, function_definition; 2, function_name:_get_video_ts_file_paths; 3, parameters; 4, block; 5, identifier:dvd_path; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, comment:"""Returns a sorted list of paths for files contained in th VIDEO_TS folder of the specified DVD path. """; 12, assignment; 13, assignment; 14, identifier:video_ts_folder_content_name; 15, call; 16, block; 17, call; 18, identifier:video_ts_folder_path; 19, call; 20, identifier:video_ts_file_paths; 21, list; 22, identifier:listdir; 23, argument_list; 24, expression_statement; 25, if_statement; 26, identifier:sorted; 27, argument_list; 28, identifier:join; 29, argument_list; 30, identifier:video_ts_folder_path; 31, assignment; 32, call; 33, block; 34, identifier:video_ts_file_paths; 35, identifier:dvd_path; 36, string:"VIDEO_TS"; 37, identifier:video_ts_folder_content_path; 38, call; 39, identifier:isfile; 40, argument_list; 41, expression_statement; 42, identifier:join; 43, argument_list; 44, identifier:video_ts_folder_content_path; 45, call; 46, identifier:video_ts_folder_path; 47, identifier:video_ts_folder_content_name; 48, attribute; 49, argument_list; 50, identifier:video_ts_file_paths; 51, identifier:append; 52, identifier:video_ts_folder_content_path
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 9, 14; 9, 15; 9, 16; 10, 17; 12, 18; 12, 19; 13, 20; 13, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 17, 27; 19, 28; 19, 29; 23, 30; 24, 31; 25, 32; 25, 33; 27, 34; 29, 35; 29, 36; 31, 37; 31, 38; 32, 39; 32, 40; 33, 41; 38, 42; 38, 43; 40, 44; 41, 45; 43, 46; 43, 47; 45, 48; 45, 49; 48, 50; 48, 51; 49, 52
def _get_video_ts_file_paths(dvd_path): """Returns a sorted list of paths for files contained in th VIDEO_TS folder of the specified DVD path. """ video_ts_folder_path = join(dvd_path, "VIDEO_TS") video_ts_file_paths = [] for video_ts_folder_content_name in listdir(video_ts_folder_path): video_ts_folder_content_path = join(video_ts_folder_path, video_ts_folder_content_name) if isfile(video_ts_folder_content_path): video_ts_file_paths.append(video_ts_folder_content_path) return sorted(video_ts_file_paths)
0, module; 1, function_definition; 2, function_name:sort_ranges; 3, parameters; 4, block; 5, identifier:inranges; 6, expression_statement; 7, return_statement; 8, comment:"""from an array of ranges, make a sorted array of ranges :param inranges: List of GenomicRange data :type inranges: GenomicRange[] :returns: a new sorted GenomicRange list :rtype: GenomicRange[] """; 9, call; 10, identifier:sorted; 11, argument_list; 12, identifier:inranges; 13, keyword_argument; 14, identifier:key; 15, lambda; 16, lambda_parameters; 17, tuple; 18, identifier:x; 19, attribute; 20, attribute; 21, attribute; 22, attribute; 23, identifier:x; 24, identifier:chr; 25, identifier:x; 26, identifier:start; 27, identifier:x; 28, identifier:end; 29, identifier:x; 30, identifier:direction
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 11, 12; 11, 13; 13, 14; 13, 15; 15, 16; 15, 17; 16, 18; 17, 19; 17, 20; 17, 21; 17, 22; 19, 23; 19, 24; 20, 25; 20, 26; 21, 27; 21, 28; 22, 29; 22, 30
def sort_ranges(inranges): """from an array of ranges, make a sorted array of ranges :param inranges: List of GenomicRange data :type inranges: GenomicRange[] :returns: a new sorted GenomicRange list :rtype: GenomicRange[] """ return sorted(inranges,key=lambda x: (x.chr,x.start,x.end,x.direction))
0, module; 1, function_definition; 2, function_name:subtract_ranges; 3, parameters; 4, block; 5, identifier:r1s; 6, identifier:r2s; 7, default_parameter; 8, expression_statement; 9, import_from_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, for_statement; 16, comment:#outputs = merge_ranges(outputs); 17, comment:#print [x.get_range_string() for x in outputs]; 18, return_statement; 19, identifier:already_sorted; 20, False; 21, comment:"""Subtract multiple ranges from a list of ranges :param r1s: range list 1 :param r2s: range list 2 :param already_sorted: default (False) :type r1s: GenomicRange[] :type r2s: GenomicRange[] :return: new range r1s minus r2s :rtype: GenomicRange[] """; 22, dotted_name; 23, dotted_name; 24, not_operator; 25, block; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, identifier:loc; 31, identifier:mls; 32, comment:#[beds1,beds2] = loc.get_payload(); 33, block; 34, call; 35, identifier:seqtools; 36, identifier:stream; 37, identifier:MultiLocusStream; 38, identifier:already_sorted; 39, expression_statement; 40, expression_statement; 41, identifier:outputs; 42, list; 43, identifier:mls; 44, call; 45, identifier:tot1; 46, integer:0; 47, identifier:tot2; 48, integer:0; 49, expression_statement; 50, comment:#print v; 51, expression_statement; 52, expression_statement; 53, expression_statement; 54, if_statement; 55, if_statement; 56, comment:#this loop could be made much more efficient; 57, expression_statement; 58, comment:#keyed by beds1 index stores list of overlaping beds2 indecies; 59, for_statement; 60, expression_statement; 61, expression_statement; 62, for_statement; 63, for_statement; 64, comment:#while len(beds2) > 0:; 65, comment:# b2 = beds2.pop(0); 66, comment:# vs = [x.subtract(b2) for x in beds1]; 67, comment:# tot = []; 68, comment:# for res in vs:; 69, comment:# tot = tot + res; 70, comment:# beds1 = tot; 71, comment:#print "subtract "+str(len(beds1))+"\t"+str(len(beds2)); 72, comment:#print beds1[0].get_range_string(); 73, identifier:merge_ranges; 74, argument_list; 75, assignment; 76, assignment; 77, identifier:MultiLocusStream; 78, argument_list; 79, assignment; 80, assignment; 81, assignment; 82, assignment; 83, comparison_operator:len(beds1)==0; 84, block; 85, comparison_operator:len(beds2)==0; 86, block; 87, assignment; 88, identifier:i; 89, call; 90, block; 91, assignment; 92, assignment; 93, identifier:i; 94, call; 95, block; 96, identifier:i; 97, call; 98, block; 99, identifier:outputs; 100, identifier:r1s; 101, call; 102, identifier:r2s; 103, call; 104, list; 105, identifier:v; 106, attribute; 107, list_pattern; 108, identifier:v; 109, identifier:beds1; 110, subscript; 111, identifier:beds2; 112, subscript; 113, call; 114, integer:0; 115, continue_statement; 116, call; 117, integer:0; 118, expression_statement; 119, continue_statement; 120, identifier:mapping; 121, dictionary; 122, identifier:range; 123, argument_list; 124, expression_statement; 125, identifier:beds2min; 126, integer:0; 127, identifier:beds2max; 128, call; 129, identifier:range; 130, argument_list; 131, for_statement; 132, identifier:range; 133, argument_list; 134, if_statement; 135, identifier:merge_ranges; 136, argument_list; 137, identifier:merge_ranges; 138, argument_list; 139, call; 140, call; 141, identifier:loc; 142, identifier:payload; 143, identifier:beds1; 144, identifier:beds2; 145, identifier:beds1; 146, slice; 147, identifier:beds2; 148, slice; 149, identifier:len; 150, argument_list; 151, identifier:len; 152, argument_list; 153, augmented_assignment; 154, integer:0; 155, call; 156, assignment; 157, identifier:len; 158, argument_list; 159, integer:0; 160, call; 161, identifier:j; 162, call; 163, block; 164, integer:0; 165, call; 166, comparison_operator:len(mapping[i])==0; 167, block; 168, else_clause; 169, identifier:r1s; 170, identifier:r2s; 171, identifier:BedArrayStream; 172, argument_list; 173, identifier:BedArrayStream; 174, argument_list; 175, identifier:beds1; 176, identifier:beds2; 177, identifier:outputs; 178, identifier:beds1; 179, identifier:len; 180, argument_list; 181, subscript; 182, list; 183, identifier:beds2; 184, identifier:len; 185, argument_list; 186, identifier:range; 187, argument_list; 188, expression_statement; 189, if_statement; 190, identifier:len; 191, argument_list; 192, call; 193, integer:0; 194, expression_statement; 195, block; 196, identifier:r1s; 197, identifier:r2s; 198, identifier:beds1; 199, identifier:mapping; 200, identifier:i; 201, identifier:beds1; 202, identifier:beds2min; 203, identifier:beds2max; 204, assignment; 205, comparison_operator:cmpval == -1; 206, block; 207, elif_clause; 208, else_clause; 209, identifier:beds1; 210, identifier:len; 211, argument_list; 212, augmented_assignment; 213, expression_statement; 214, identifier:cmpval; 215, call; 216, identifier:cmpval; 217, unary_operator; 218, expression_statement; 219, comparison_operator:cmpval == 0; 220, block; 221, block; 222, subscript; 223, identifier:outputs; 224, identifier:beds1; 225, augmented_assignment; 226, attribute; 227, argument_list; 228, integer:1; 229, assignment; 230, identifier:cmpval; 231, integer:0; 232, expression_statement; 233, break_statement; 234, identifier:mapping; 235, identifier:i; 236, identifier:outputs; 237, call; 238, subscript; 239, identifier:cmp; 240, subscript; 241, identifier:beds2min; 242, binary_operator:j+1; 243, call; 244, identifier:subtract_range_array; 245, argument_list; 246, identifier:beds1; 247, identifier:i; 248, identifier:beds2; 249, identifier:j; 250, identifier:j; 251, integer:1; 252, attribute; 253, argument_list; 254, subscript; 255, list_comprehension; 256, keyword_argument; 257, subscript; 258, identifier:append; 259, identifier:j; 260, identifier:beds1; 261, identifier:i; 262, subscript; 263, for_in_clause; 264, identifier:is_sorted; 265, True; 266, identifier:mapping; 267, identifier:i; 268, identifier:beds2; 269, identifier:j; 270, identifier:j; 271, subscript; 272, identifier:mapping; 273, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 7, 19; 7, 20; 8, 21; 9, 22; 9, 23; 10, 24; 10, 25; 11, 26; 12, 27; 13, 28; 14, 29; 15, 30; 15, 31; 15, 32; 15, 33; 18, 34; 22, 35; 22, 36; 23, 37; 24, 38; 25, 39; 25, 40; 26, 41; 26, 42; 27, 43; 27, 44; 28, 45; 28, 46; 29, 47; 29, 48; 33, 49; 33, 50; 33, 51; 33, 52; 33, 53; 33, 54; 33, 55; 33, 56; 33, 57; 33, 58; 33, 59; 33, 60; 33, 61; 33, 62; 33, 63; 33, 64; 33, 65; 33, 66; 33, 67; 33, 68; 33, 69; 33, 70; 33, 71; 33, 72; 34, 73; 34, 74; 39, 75; 40, 76; 44, 77; 44, 78; 49, 79; 51, 80; 52, 81; 53, 82; 54, 83; 54, 84; 55, 85; 55, 86; 57, 87; 59, 88; 59, 89; 59, 90; 60, 91; 61, 92; 62, 93; 62, 94; 62, 95; 63, 96; 63, 97; 63, 98; 74, 99; 75, 100; 75, 101; 76, 102; 76, 103; 78, 104; 79, 105; 79, 106; 80, 107; 80, 108; 81, 109; 81, 110; 82, 111; 82, 112; 83, 113; 83, 114; 84, 115; 85, 116; 85, 117; 86, 118; 86, 119; 87, 120; 87, 121; 89, 122; 89, 123; 90, 124; 91, 125; 91, 126; 92, 127; 92, 128; 94, 129; 94, 130; 95, 131; 97, 132; 97, 133; 98, 134; 101, 135; 101, 136; 103, 137; 103, 138; 104, 139; 104, 140; 106, 141; 106, 142; 107, 143; 107, 144; 110, 145; 110, 146; 112, 147; 112, 148; 113, 149; 113, 150; 116, 151; 116, 152; 118, 153; 123, 154; 123, 155; 124, 156; 128, 157; 128, 158; 130, 159; 130, 160; 131, 161; 131, 162; 131, 163; 133, 164; 133, 165; 134, 166; 134, 167; 134, 168; 136, 169; 138, 170; 139, 171; 139, 172; 140, 173; 140, 174; 150, 175; 152, 176; 153, 177; 153, 178; 155, 179; 155, 180; 156, 181; 156, 182; 158, 183; 160, 184; 160, 185; 162, 186; 162, 187; 163, 188; 163, 189; 165, 190; 165, 191; 166, 192; 166, 193; 167, 194; 168, 195; 172, 196; 174, 197; 180, 198; 181, 199; 181, 200; 185, 201; 187, 202; 187, 203; 188, 204; 189, 205; 189, 206; 189, 207; 189, 208; 191, 209; 192, 210; 192, 211; 194, 212; 195, 213; 204, 214; 204, 215; 205, 216; 205, 217; 206, 218; 207, 219; 207, 220; 208, 221; 211, 222; 212, 223; 212, 224; 213, 225; 215, 226; 215, 227; 217, 228; 218, 229; 219, 230; 219, 231; 220, 232; 221, 233; 222, 234; 222, 235; 225, 236; 225, 237; 226, 238; 226, 239; 227, 240; 229, 241; 229, 242; 232, 243; 237, 244; 237, 245; 238, 246; 238, 247; 240, 248; 240, 249; 242, 250; 242, 251; 243, 252; 243, 253; 245, 254; 245, 255; 245, 256; 252, 257; 252, 258; 253, 259; 254, 260; 254, 261; 255, 262; 255, 263; 256, 264; 256, 265; 257, 266; 257, 267; 262, 268; 262, 269; 263, 270; 263, 271; 271, 272; 271, 273
def subtract_ranges(r1s,r2s,already_sorted=False): """Subtract multiple ranges from a list of ranges :param r1s: range list 1 :param r2s: range list 2 :param already_sorted: default (False) :type r1s: GenomicRange[] :type r2s: GenomicRange[] :return: new range r1s minus r2s :rtype: GenomicRange[] """ from seqtools.stream import MultiLocusStream if not already_sorted: r1s = merge_ranges(r1s) r2s = merge_ranges(r2s) outputs = [] mls = MultiLocusStream([BedArrayStream(r1s),BedArrayStream(r2s)]) tot1 = 0 tot2 = 0 for loc in mls: #[beds1,beds2] = loc.get_payload() v = loc.payload #print v [beds1,beds2] =v beds1 = beds1[:] beds2 = beds2[:] if len(beds1)==0: continue if len(beds2)==0: outputs += beds1 continue #this loop could be made much more efficient mapping = {} #keyed by beds1 index stores list of overlaping beds2 indecies for i in range(0,len(beds1)): mapping[i] = [] beds2min = 0 beds2max = len(beds2) for i in range(0,len(beds1)): for j in range(beds2min,beds2max): cmpval = beds1[i].cmp(beds2[j]) if cmpval == -1: beds2min = j+1 elif cmpval == 0: mapping[i].append(j) else: break for i in range(0,len(beds1)): if len(mapping[i])==0: outputs += beds1 else: outputs += subtract_range_array(beds1[i],[beds2[j] for j in mapping[i]],is_sorted=True) #while len(beds2) > 0: # b2 = beds2.pop(0) # vs = [x.subtract(b2) for x in beds1] # tot = [] # for res in vs: # tot = tot + res # beds1 = tot #print "subtract "+str(len(beds1))+"\t"+str(len(beds2)) #print beds1[0].get_range_string() #outputs = merge_ranges(outputs) #print [x.get_range_string() for x in outputs] return merge_ranges(outputs)