sequence
stringlengths 546
16.2k
| code
stringlengths 108
19.3k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:movefastq; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 16; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:'Moving FASTQ files'; 15, comment; 16, for_statement; 16, 17; 16, 18; 16, 25; 16, 26; 17, identifier:sample; 18, attribute; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:metadata; 23, identifier:runmetadata; 24, identifier:samples; 25, comment; 26, block; 26, 27; 26, 43; 26, 44; 26, 173; 26, 174; 26, 343; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:outputdir; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:os; 34, identifier:path; 35, identifier:join; 36, argument_list; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:path; 40, attribute; 40, 41; 40, 42; 41, identifier:sample; 42, identifier:name; 43, comment; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:fastqfiles; 47, conditional_expression:if; 47, 48; 47, 72; 47, 73; 47, 97; 47, 98; 48, call; 48, 49; 48, 50; 49, identifier:sorted; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:glob; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:os; 58, identifier:path; 59, identifier:join; 60, argument_list; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:path; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, string:'{}_*.fastq*'; 67, identifier:format; 68, argument_list; 68, 69; 69, attribute; 69, 70; 69, 71; 70, identifier:sample; 71, identifier:name; 72, line_continuation:\; 73, call; 73, 74; 73, 75; 74, identifier:sorted; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:glob; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:os; 83, identifier:path; 84, identifier:join; 85, argument_list; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:path; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:'{}_*.fastq*'; 92, identifier:format; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:sample; 96, identifier:name; 97, line_continuation:\; 98, conditional_expression:if; 98, 99; 98, 123; 98, 124; 98, 148; 98, 149; 99, call; 99, 100; 99, 101; 100, identifier:sorted; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:glob; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:os; 109, identifier:path; 110, identifier:join; 111, argument_list; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:path; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:'{}.fastq*'; 118, identifier:format; 119, argument_list; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:sample; 122, identifier:name; 123, line_continuation:\; 124, call; 124, 125; 124, 126; 125, identifier:sorted; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:glob; 129, argument_list; 129, 130; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:os; 134, identifier:path; 135, identifier:join; 136, argument_list; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:path; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, string:'{}.fastq*'; 143, identifier:format; 144, argument_list; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:sample; 147, identifier:name; 148, line_continuation:\; 149, call; 149, 150; 149, 151; 150, identifier:sorted; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:glob; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:os; 159, identifier:path; 160, identifier:join; 161, argument_list; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:path; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, string:'{}*.fastq*'; 168, identifier:format; 169, argument_list; 169, 170; 170, attribute; 170, 171; 170, 172; 171, identifier:sample; 172, identifier:name; 173, comment; 174, if_statement; 174, 175; 174, 176; 174, 287; 175, identifier:fastqfiles; 176, block; 176, 177; 176, 182; 176, 183; 176, 237; 176, 238; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:make_path; 180, argument_list; 180, 181; 181, identifier:outputdir; 182, comment; 183, try_statement; 183, 184; 183, 233; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:list; 188, argument_list; 188, 189; 189, call; 189, 190; 189, 191; 190, identifier:map; 191, argument_list; 191, 192; 191, 232; 192, lambda; 192, 193; 192, 195; 193, lambda_parameters; 193, 194; 194, identifier:x; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:os; 198, identifier:symlink; 199, argument_list; 199, 200; 199, 216; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:os; 204, identifier:path; 205, identifier:join; 206, argument_list; 206, 207; 206, 208; 207, string:'..'; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:os; 212, identifier:path; 213, identifier:basename; 214, argument_list; 214, 215; 215, identifier:x; 216, call; 216, 217; 216, 222; 217, attribute; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:os; 220, identifier:path; 221, identifier:join; 222, argument_list; 222, 223; 222, 224; 223, identifier:outputdir; 224, call; 224, 225; 224, 230; 225, attribute; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:os; 228, identifier:path; 229, identifier:basename; 230, argument_list; 230, 231; 231, identifier:x; 232, identifier:fastqfiles; 233, except_clause; 233, 234; 233, 235; 234, identifier:OSError; 235, block; 235, 236; 236, pass_statement; 237, comment; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:fastqfiles; 241, list_comprehension; 241, 242; 241, 243; 241, 267; 242, identifier:fastq; 243, for_in_clause; 243, 244; 243, 245; 244, identifier:fastq; 245, call; 245, 246; 245, 247; 246, identifier:sorted; 247, argument_list; 247, 248; 248, call; 248, 249; 248, 250; 249, identifier:glob; 250, argument_list; 250, 251; 251, call; 251, 252; 251, 257; 252, attribute; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:os; 255, identifier:path; 256, identifier:join; 257, argument_list; 257, 258; 257, 259; 258, identifier:outputdir; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, string:'{}*.fastq*'; 262, identifier:format; 263, argument_list; 263, 264; 264, attribute; 264, 265; 264, 266; 265, identifier:sample; 266, identifier:name; 267, if_clause; 267, 268; 268, boolean_operator:and; 268, 269; 268, 284; 269, boolean_operator:and; 269, 270; 269, 281; 270, boolean_operator:and; 270, 271; 270, 278; 271, boolean_operator:and; 271, 272; 271, 275; 272, comparison_operator:not; 272, 273; 272, 274; 273, string:'trimmed'; 274, identifier:fastq; 275, comparison_operator:not; 275, 276; 275, 277; 276, string:'normalised'; 277, identifier:fastq; 278, comparison_operator:not; 278, 279; 278, 280; 279, string:'corrected'; 280, identifier:fastq; 281, comparison_operator:not; 281, 282; 281, 283; 282, string:'paired'; 283, identifier:fastq; 284, comparison_operator:not; 284, 285; 284, 286; 285, string:'unpaired'; 286, identifier:fastq; 287, else_clause; 287, 288; 288, block; 288, 289; 289, if_statement; 289, 290; 289, 291; 289, 292; 290, identifier:outputdir; 291, comment; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:fastqfiles; 296, list_comprehension; 296, 297; 296, 298; 296, 323; 297, identifier:fastq; 298, for_in_clause; 298, 299; 298, 300; 299, identifier:fastq; 300, call; 300, 301; 300, 302; 301, identifier:sorted; 302, argument_list; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:glob; 305, argument_list; 305, 306; 306, call; 306, 307; 306, 312; 307, attribute; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:os; 310, identifier:path; 311, identifier:join; 312, argument_list; 312, 313; 312, 314; 313, identifier:outputdir; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, string:'{}*.fastq*'; 317, identifier:format; 318, argument_list; 318, 319; 318, 320; 319, identifier:outputdir; 320, attribute; 320, 321; 320, 322; 321, identifier:sample; 322, identifier:name; 323, if_clause; 323, 324; 324, boolean_operator:and; 324, 325; 324, 340; 325, boolean_operator:and; 325, 326; 325, 337; 326, boolean_operator:and; 326, 327; 326, 334; 327, boolean_operator:and; 327, 328; 327, 331; 328, comparison_operator:not; 328, 329; 328, 330; 329, string:'trimmed'; 330, identifier:fastq; 331, comparison_operator:not; 331, 332; 331, 333; 332, string:'normalised'; 333, identifier:fastq; 334, comparison_operator:not; 334, 335; 334, 336; 335, string:'corrected'; 336, identifier:fastq; 337, comparison_operator:not; 337, 338; 337, 339; 338, string:'paired'; 339, identifier:fastq; 340, comparison_operator:not; 340, 341; 340, 342; 341, string:'unpaired'; 342, identifier:fastq; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 350; 345, attribute; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:sample; 348, identifier:general; 349, identifier:fastqfiles; 350, identifier:fastqfiles | def movefastq(self):
"""Find .fastq files for each sample and move them to an appropriately named folder"""
logging.info('Moving FASTQ files')
# Iterate through each sample
for sample in self.metadata.runmetadata.samples:
# Retrieve the output directory
outputdir = os.path.join(self.path, sample.name)
# Find any fastq files with the sample name
fastqfiles = sorted(glob(os.path.join(self.path, '{}_*.fastq*'.format(sample.name)))) \
if sorted(glob(os.path.join(self.path, '{}_*.fastq*'.format(sample.name)))) \
else sorted(glob(os.path.join(self.path, '{}.fastq*'.format(sample.name)))) \
if sorted(glob(os.path.join(self.path, '{}.fastq*'.format(sample.name)))) \
else sorted(glob(os.path.join(self.path, '{}*.fastq*'.format(sample.name))))
# Only try and move the files if the files exist
if fastqfiles:
make_path(outputdir)
# Symlink the fastq files to the directory
try:
list(map(lambda x: os.symlink(os.path.join('..', os.path.basename(x)),
os.path.join(outputdir, os.path.basename(x))), fastqfiles))
except OSError:
pass
# Find any fastq files with the sample name
fastqfiles = [fastq for fastq in sorted(glob(os.path.join(outputdir, '{}*.fastq*'.format(sample.name))))
if 'trimmed' not in fastq and 'normalised' not in fastq and 'corrected' not in fastq
and 'paired' not in fastq and 'unpaired' not in fastq]
else:
if outputdir:
# Find any fastq files with the sample name
fastqfiles = [fastq for fastq in sorted(glob(os.path.join(
outputdir, '{}*.fastq*'.format(outputdir, sample.name))))
if 'trimmed' not in fastq and 'normalised' not in fastq and 'corrected' not in fastq
and 'paired' not in fastq and 'unpaired' not in fastq]
sample.general.fastqfiles = fastqfiles |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 11; 2, function_name:add_raw_entity; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:entity; 7, type; 7, 8; 8, identifier:dict; 9, type; 9, 10; 10, identifier:dict; 11, block; 11, 12; 11, 14; 11, 23; 11, 37; 11, 45; 11, 53; 11, 54; 11, 55; 11, 112; 11, 124; 11, 125; 11, 145; 11, 162; 11, 179; 11, 196; 11, 204; 11, 205; 11, 206; 11, 217; 11, 218; 11, 236; 11, 237; 11, 260; 11, 271; 11, 272; 11, 278; 11, 279; 11, 297; 11, 298; 11, 299; 11, 362; 11, 363; 11, 374; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:needed_in_entity; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 19, 20; 20, list:[
'label',
'type',
]; 20, 21; 20, 22; 21, string:'label'; 22, string:'type'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:options_in_entity; 26, call; 26, 27; 26, 28; 27, identifier:set; 28, argument_list; 28, 29; 29, list:[
'label',
'type',
'definition',
'comment',
'superclass',
'synonyms',
'existing_ids'
]; 29, 30; 29, 31; 29, 32; 29, 33; 29, 34; 29, 35; 29, 36; 30, string:'label'; 31, string:'type'; 32, string:'definition'; 33, string:'comment'; 34, string:'superclass'; 35, string:'synonyms'; 36, string:'existing_ids'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:prime_entity_url; 40, binary_operator:+; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:base_url; 44, string:'ilx/add'; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:add_entity_url; 48, binary_operator:+; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:base_url; 52, string:'term/add'; 53, comment; 54, comment; 55, if_statement; 55, 56; 55, 65; 55, 83; 55, 84; 56, comparison_operator:!=; 56, 57; 56, 64; 57, parenthesized_expression; 57, 58; 58, binary_operator:&; 58, 59; 58, 63; 59, call; 59, 60; 59, 61; 60, identifier:set; 61, argument_list; 61, 62; 62, identifier:entity; 63, identifier:needed_in_entity; 64, identifier:needed_in_entity; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:MissingKeyError; 71, argument_list; 71, 72; 72, binary_operator:+; 72, 73; 72, 74; 73, string:'You need key(s): '; 74, call; 74, 75; 74, 76; 75, identifier:str; 76, argument_list; 76, 77; 77, binary_operator:-; 77, 78; 77, 79; 78, identifier:needed_in_entity; 79, call; 79, 80; 79, 81; 80, identifier:set; 81, argument_list; 81, 82; 82, identifier:entity; 83, comment; 84, elif_clause; 84, 85; 84, 94; 85, comparison_operator:!=; 85, 86; 85, 93; 86, parenthesized_expression; 86, 87; 87, binary_operator:|; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:set; 90, argument_list; 90, 91; 91, identifier:entity; 92, identifier:options_in_entity; 93, identifier:options_in_entity; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:IncorrectKeyError; 100, argument_list; 100, 101; 101, binary_operator:+; 101, 102; 101, 103; 102, string:'Unexpected key(s): '; 103, call; 103, 104; 103, 105; 104, identifier:str; 105, argument_list; 105, 106; 106, binary_operator:-; 106, 107; 106, 111; 107, call; 107, 108; 107, 109; 108, identifier:set; 109, argument_list; 109, 110; 110, identifier:entity; 111, identifier:options_in_entity; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:entity; 116, string:'type'; 117, call; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:entity; 121, string:'type'; 122, identifier:lower; 123, argument_list; 124, comment; 125, if_statement; 125, 126; 125, 137; 126, comparison_operator:not; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:entity; 129, string:'type'; 130, list:['term', 'relationship', 'annotation', 'cde', 'fde', 'pde']; 130, 131; 130, 132; 130, 133; 130, 134; 130, 135; 130, 136; 131, string:'term'; 132, string:'relationship'; 133, string:'annotation'; 134, string:'cde'; 135, string:'fde'; 136, string:'pde'; 137, block; 137, 138; 138, raise_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:TypeError; 141, argument_list; 141, 142; 142, binary_operator:+; 142, 143; 142, 144; 143, string:'Entity should be one of the following: '; 144, string:'term, relationship, annotation, cde, fde, pde'; 145, if_statement; 145, 146; 145, 152; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:entity; 149, identifier:get; 150, argument_list; 150, 151; 151, string:'superclass'; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:entity; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:process_superclass; 160, argument_list; 160, 161; 161, identifier:entity; 162, if_statement; 162, 163; 162, 169; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:entity; 166, identifier:get; 167, argument_list; 167, 168; 168, string:'synonyms'; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:entity; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:process_synonyms; 177, argument_list; 177, 178; 178, identifier:entity; 179, if_statement; 179, 180; 179, 186; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:entity; 183, identifier:get; 184, argument_list; 184, 185; 185, string:'existing_ids'; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:entity; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:process_existing_ids; 194, argument_list; 194, 195; 195, identifier:entity; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:entity; 200, string:'uid'; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:user_id; 204, comment; 205, comment; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:entity; 210, string:'term'; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:entity; 214, identifier:pop; 215, argument_list; 215, 216; 216, string:'label'; 217, comment; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:ilx_data; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:post; 225, argument_list; 225, 226; 225, 229; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:url; 228, identifier:prime_entity_url; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:data; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:entity; 234, identifier:copy; 235, argument_list; 236, comment; 237, if_statement; 237, 238; 237, 244; 237, 251; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:ilx_data; 241, identifier:get; 242, argument_list; 242, 243; 243, string:'ilx'; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:ilx_id; 248, subscript; 248, 249; 248, 250; 249, identifier:ilx_data; 250, string:'ilx'; 251, else_clause; 251, 252; 252, block; 252, 253; 252, 259; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:ilx_id; 256, subscript; 256, 257; 256, 258; 257, identifier:ilx_data; 258, string:'fragment'; 259, comment; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 265; 262, subscript; 262, 263; 262, 264; 263, identifier:entity; 264, string:'label'; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:entity; 268, identifier:pop; 269, argument_list; 269, 270; 270, string:'term'; 271, comment; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:entity; 276, string:'ilx'; 277, identifier:ilx_id; 278, comment; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:output; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:post; 286, argument_list; 286, 287; 286, 290; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:url; 289, identifier:add_entity_url; 290, keyword_argument; 290, 291; 290, 292; 291, identifier:data; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:entity; 295, identifier:copy; 296, argument_list; 297, comment; 298, comment; 299, if_statement; 299, 300; 299, 306; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:output; 303, identifier:get; 304, argument_list; 304, 305; 305, string:'errormsg'; 306, block; 306, 307; 306, 354; 306, 361; 307, if_statement; 307, 308; 307, 317; 308, comparison_operator:in; 308, 309; 308, 310; 309, string:'already exists'; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, subscript; 312, 313; 312, 314; 313, identifier:output; 314, string:'errormsg'; 315, identifier:lower; 316, argument_list; 317, block; 317, 318; 317, 329; 317, 346; 317, 353; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:prexisting_data; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:self; 324, identifier:check_scicrunch_for_label; 325, argument_list; 325, 326; 326, subscript; 326, 327; 326, 328; 327, identifier:entity; 328, string:'label'; 329, if_statement; 329, 330; 329, 331; 330, identifier:prexisting_data; 331, block; 331, 332; 331, 344; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:print; 335, argument_list; 335, 336; 335, 337; 335, 340; 335, 341; 336, string:'You already added entity'; 337, subscript; 337, 338; 337, 339; 338, identifier:entity; 339, string:'label'; 340, string:'with ILX ID:'; 341, subscript; 341, 342; 341, 343; 342, identifier:prexisting_data; 343, string:'ilx'; 344, return_statement; 344, 345; 345, identifier:prexisting_data; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:Error; 351, argument_list; 351, 352; 352, identifier:output; 353, comment; 354, expression_statement; 354, 355; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:Error; 359, argument_list; 359, 360; 360, identifier:output; 361, comment; 362, comment; 363, expression_statement; 363, 364; 364, assignment; 364, 365; 364, 366; 365, identifier:output; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:self; 369, identifier:get_entity; 370, argument_list; 370, 371; 371, subscript; 371, 372; 371, 373; 372, identifier:output; 373, string:'ilx'; 374, return_statement; 374, 375; 375, identifier:output | def add_raw_entity(self, entity: dict) -> dict:
""" Adds entity if it does not already exist under your user ID.
Need to provide a list of dictionaries that have at least the key/values
for label and type. If given a key, the values provided must be in the
format shown in order for the server to except them. You can input
multiple synonyms, or existing_ids.
Entity type can be any of the following: term, pde, fde, cde, annotation, or relationship
Options Template:
entity = {
'label': '',
'type': '',
'definition': '',
'comment': '',
'superclass': {
'ilx_id': ''
},
'synonyms': [
{
'literal': ''
},
],
'existing_ids': [
{
'iri': '',
'curie': '',
},
],
}
Minimum Needed:
entity = {
'label': '',
'type': '',
}
Example:
entity = {
'label': 'brain',
'type': 'pde',
'definition': 'Part of the central nervous system',
'comment': 'Cannot live without it',
'superclass': {
'ilx_id': 'ilx_0108124', # ILX ID for Organ
},
'synonyms': [
{
'literal': 'Encephalon'
},
{
'literal': 'Cerebro'
},
],
'existing_ids': [
{
'iri': 'http://uri.neuinfo.org/nif/nifstd/birnlex_796',
'curie': 'BIRNLEX:796',
},
],
}
"""
needed_in_entity = set([
'label',
'type',
])
options_in_entity = set([
'label',
'type',
'definition',
'comment',
'superclass',
'synonyms',
'existing_ids'
])
prime_entity_url = self.base_url + 'ilx/add'
add_entity_url = self.base_url + 'term/add'
### Checking if key/value format is correct ###
# Seeing if you are missing a needed key
if (set(entity) & needed_in_entity) != needed_in_entity:
raise self.MissingKeyError(
'You need key(s): '+ str(needed_in_entity - set(entity)))
# Seeing if you have other options not included in the description
elif (set(entity) | options_in_entity) != options_in_entity:
raise self.IncorrectKeyError(
'Unexpected key(s): ' + str(set(entity) - options_in_entity))
entity['type'] = entity['type'].lower() # BUG: server only takes lowercase
if entity['type'] not in ['term', 'relationship', 'annotation', 'cde', 'fde', 'pde']:
raise TypeError(
'Entity should be one of the following: ' +
'term, relationship, annotation, cde, fde, pde')
if entity.get('superclass'):
entity = self.process_superclass(entity)
if entity.get('synonyms'):
entity = self.process_synonyms(entity)
if entity.get('existing_ids'):
entity = self.process_existing_ids(entity)
entity['uid'] = self.user_id # BUG: php lacks uid update
### Adding entity to SciCrunch ###
entity['term'] = entity.pop('label') # ilx/add nuance
ilx_data = self.post(
url = prime_entity_url,
data = entity.copy(),
) # requesting spot in server for entity
if ilx_data.get('ilx'):
ilx_id = ilx_data['ilx']
else:
ilx_id = ilx_data['fragment'] # beta.scicrunch.org
entity['label'] = entity.pop('term') # term/add nuance
entity['ilx'] = ilx_id # need entity ilx_id to place entity in db
output = self.post(
url = add_entity_url,
data = entity.copy(),
) # data represented in SciCrunch interface
### Checking if label already exisits ###
if output.get('errormsg'):
if 'already exists' in output['errormsg'].lower():
prexisting_data = self.check_scicrunch_for_label(entity['label'])
if prexisting_data:
print(
'You already added entity', entity['label'],
'with ILX ID:', prexisting_data['ilx'])
return prexisting_data
self.Error(output) # FIXME what is the correct error here?
self.Error(output) # FIXME what is the correct error here?
# BUG: server output incomplete compared to search via ilx ids
output = self.get_entity(output['ilx'])
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 1, 19; 2, function_name:delete_annotation; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 13; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:term_ilx_id; 7, type; 7, 8; 8, identifier:str; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:annotation_type_ilx_id; 11, type; 11, 12; 12, identifier:str; 13, typed_parameter; 13, 14; 13, 15; 14, identifier:annotation_value; 15, type; 15, 16; 16, identifier:str; 17, type; 17, 18; 18, identifier:dict; 19, block; 19, 20; 19, 22; 19, 31; 19, 46; 19, 55; 19, 70; 19, 81; 19, 85; 19, 139; 19, 150; 19, 165; 19, 187; 19, 201; 19, 202; 20, expression_statement; 20, 21; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:term_data; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:get_entity; 29, argument_list; 29, 30; 30, identifier:term_ilx_id; 31, if_statement; 31, 32; 31, 36; 32, not_operator; 32, 33; 33, subscript; 33, 34; 33, 35; 34, identifier:term_data; 35, string:'id'; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:exit; 40, argument_list; 40, 41; 41, binary_operator:+; 41, 42; 41, 45; 42, binary_operator:+; 42, 43; 42, 44; 43, string:'term_ilx_id: '; 44, identifier:term_ilx_id; 45, string:' does not exist'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:anno_data; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:get_entity; 53, argument_list; 53, 54; 54, identifier:annotation_type_ilx_id; 55, if_statement; 55, 56; 55, 60; 56, not_operator; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:anno_data; 59, string:'id'; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:exit; 64, argument_list; 64, 65; 65, binary_operator:+; 65, 66; 65, 69; 66, binary_operator:+; 66, 67; 66, 68; 67, string:'annotation_type_ilx_id: '; 68, identifier:annotation_type_ilx_id; 69, string:' does not exist'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:entity_annotations; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:get_annotation_via_tid; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:term_data; 80, string:'id'; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:annotation_id; 84, string:''; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:annotation; 87, identifier:entity_annotations; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 103; 90, comparison_operator:==; 90, 91; 90, 97; 91, call; 91, 92; 91, 93; 92, identifier:str; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:annotation; 96, string:'tid'; 97, call; 97, 98; 97, 99; 98, identifier:str; 99, argument_list; 99, 100; 100, subscript; 100, 101; 100, 102; 101, identifier:term_data; 102, string:'id'; 103, block; 103, 104; 104, if_statement; 104, 105; 104, 118; 105, comparison_operator:==; 105, 106; 105, 112; 106, call; 106, 107; 106, 108; 107, identifier:str; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 111; 110, identifier:annotation; 111, string:'annotation_tid'; 112, call; 112, 113; 112, 114; 113, identifier:str; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 117; 116, identifier:anno_data; 117, string:'id'; 118, block; 118, 119; 119, if_statement; 119, 120; 119, 131; 120, comparison_operator:==; 120, 121; 120, 127; 121, call; 121, 122; 121, 123; 122, identifier:str; 123, argument_list; 123, 124; 124, subscript; 124, 125; 124, 126; 125, identifier:annotation; 126, string:'value'; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:annotation_value; 131, block; 131, 132; 131, 138; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:annotation_id; 135, subscript; 135, 136; 135, 137; 136, identifier:annotation; 137, string:'id'; 138, break_statement; 139, if_statement; 139, 140; 139, 142; 140, not_operator; 140, 141; 141, identifier:annotation_id; 142, block; 142, 143; 142, 148; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:print; 146, argument_list; 146, 147; 147, string:'''WARNING: Annotation you wanted to delete does not exist '''; 148, return_statement; 148, 149; 149, None; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:url; 153, binary_operator:+; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:base_url; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, string:'term/edit-annotation/{annotation_id}'; 160, identifier:format; 161, argument_list; 161, 162; 162, keyword_argument; 162, 163; 162, 164; 163, identifier:annotation_id; 164, identifier:annotation_id; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:data; 168, dictionary; 168, 169; 168, 172; 168, 173; 168, 176; 168, 177; 168, 180; 168, 181; 168, 184; 169, pair; 169, 170; 169, 171; 170, string:'tid'; 171, string:' '; 172, comment; 173, pair; 173, 174; 173, 175; 174, string:'annotation_tid'; 175, string:' '; 176, comment; 177, pair; 177, 178; 177, 179; 178, string:'value'; 179, string:' '; 180, comment; 181, pair; 181, 182; 181, 183; 182, string:'term_version'; 183, string:' '; 184, pair; 184, 185; 184, 186; 185, string:'annotation_term_version'; 186, string:' '; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:output; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:post; 194, argument_list; 194, 195; 194, 198; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:url; 197, identifier:url; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:data; 200, identifier:data; 201, comment; 202, return_statement; 202, 203; 203, identifier:output | def delete_annotation(
self,
term_ilx_id: str,
annotation_type_ilx_id: str,
annotation_value: str) -> dict:
""" If annotation doesnt exist, add it
"""
term_data = self.get_entity(term_ilx_id)
if not term_data['id']:
exit(
'term_ilx_id: ' + term_ilx_id + ' does not exist'
)
anno_data = self.get_entity(annotation_type_ilx_id)
if not anno_data['id']:
exit(
'annotation_type_ilx_id: ' + annotation_type_ilx_id +
' does not exist'
)
entity_annotations = self.get_annotation_via_tid(term_data['id'])
annotation_id = ''
for annotation in entity_annotations:
if str(annotation['tid']) == str(term_data['id']):
if str(annotation['annotation_tid']) == str(anno_data['id']):
if str(annotation['value']) == str(annotation_value):
annotation_id = annotation['id']
break
if not annotation_id:
print('''WARNING: Annotation you wanted to delete does not exist ''')
return None
url = self.base_url + 'term/edit-annotation/{annotation_id}'.format(
annotation_id = annotation_id
)
data = {
'tid': ' ', # for delete
'annotation_tid': ' ', # for delete
'value': ' ', # for delete
'term_version': ' ',
'annotation_term_version': ' ',
}
output = self.post(
url = url,
data = data,
)
# check output
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:configfilepopulator; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 21; 5, 33; 5, 34; 5, 35; 5, 93; 5, 94; 5, 130; 5, 131; 5, 147; 5, 148; 5, 156; 5, 157; 5, 344; 5, 345; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:forwardlength; 14, attribute; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:metadata; 19, identifier:header; 20, identifier:forwardlength; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:reverselength; 26, attribute; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:metadata; 31, identifier:header; 32, identifier:reverselength; 33, comment; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:cycles; 38, list:[[1, self.forwardlength, self.runid],
[self.forwardlength + 1, self.forwardlength + 8, self.runid],
[self.forwardlength + 9, self.forwardlength + 16, self.runid],
[self.forwardlength + 17, self.forwardlength + 16 + self.reverselength, self.runid]]; 38, 39; 38, 47; 38, 61; 38, 75; 39, list:[1, self.forwardlength, self.runid]; 39, 40; 39, 41; 39, 44; 40, integer:1; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:forwardlength; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:runid; 47, list:[self.forwardlength + 1, self.forwardlength + 8, self.runid]; 47, 48; 47, 53; 47, 58; 48, binary_operator:+; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:forwardlength; 52, integer:1; 53, binary_operator:+; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:forwardlength; 57, integer:8; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:runid; 61, list:[self.forwardlength + 9, self.forwardlength + 16, self.runid]; 61, 62; 61, 67; 61, 72; 62, binary_operator:+; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:forwardlength; 66, integer:9; 67, binary_operator:+; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:forwardlength; 71, integer:16; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:runid; 75, list:[self.forwardlength + 17, self.forwardlength + 16 + self.reverselength, self.runid]; 75, 76; 75, 81; 75, 90; 76, binary_operator:+; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:forwardlength; 80, integer:17; 81, binary_operator:+; 81, 82; 81, 87; 82, binary_operator:+; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:forwardlength; 86, integer:16; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:reverselength; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:runid; 93, comment; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:parameters; 97, dictionary; 97, 98; 97, 103; 97, 116; 97, 123; 98, pair; 98, 99; 98, 100; 99, string:'RunFolder'; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:runid; 103, pair; 103, 104; 103, 105; 104, string:'RunFolderDate'; 105, call; 105, 106; 105, 113; 106, attribute; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:metadata; 111, identifier:date; 112, identifier:replace; 113, argument_list; 113, 114; 113, 115; 114, string:"-"; 115, string:""; 116, pair; 116, 117; 116, 118; 117, string:'RunFolderId'; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:metadata; 122, identifier:runnumber; 123, pair; 123, 124; 123, 125; 124, string:'RunFlowcellId'; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:metadata; 129, identifier:flowcell; 130, comment; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:config; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:ElementTree; 137, identifier:parse; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, string:"{}/config.xml"; 142, identifier:format; 143, argument_list; 143, 144; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:homepath; 147, comment; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:configroot; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:config; 154, identifier:getroot; 155, argument_list; 156, comment; 157, for_statement; 157, 158; 157, 159; 157, 160; 157, 161; 158, identifier:run; 159, identifier:configroot; 160, comment; 161, block; 161, 162; 162, for_statement; 162, 163; 162, 164; 162, 165; 162, 166; 163, identifier:child; 164, identifier:run; 165, comment; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 173; 167, 174; 167, 210; 168, comparison_operator:==; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:child; 171, identifier:tag; 172, string:'Cycles'; 173, comment; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:child; 179, identifier:attrib; 180, dictionary; 180, 181; 180, 197; 180, 207; 181, pair; 181, 182; 181, 183; 182, string:'Last'; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:'{}'; 186, identifier:format; 187, argument_list; 187, 188; 188, binary_operator:+; 188, 189; 188, 194; 189, binary_operator:+; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:forwardlength; 193, integer:16; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:reverselength; 197, pair; 197, 198; 197, 199; 198, string:'Number'; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:'{}'; 202, identifier:format; 203, argument_list; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:totalreads; 207, pair; 207, 208; 207, 209; 208, string:'First'; 209, string:'1'; 210, elif_clause; 210, 211; 210, 216; 210, 217; 211, comparison_operator:==; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:child; 214, identifier:tag; 215, string:'RunParameters'; 216, comment; 217, block; 217, 218; 217, 222; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:runparameters; 221, identifier:child; 222, for_statement; 222, 223; 222, 224; 222, 225; 222, 226; 223, identifier:runparameter; 224, identifier:runparameters; 225, comment; 226, block; 226, 227; 226, 273; 226, 274; 226, 289; 226, 290; 226, 311; 227, if_statement; 227, 228; 227, 233; 227, 234; 228, comparison_operator:in; 228, 229; 228, 230; 229, string:'Reads'; 230, attribute; 230, 231; 230, 232; 231, identifier:runparameter; 232, identifier:tag; 233, comment; 234, block; 234, 235; 235, for_statement; 235, 236; 235, 239; 235, 243; 235, 244; 235, 245; 236, pattern_list; 236, 237; 236, 238; 237, identifier:indexcount; 238, identifier:reads; 239, call; 239, 240; 239, 241; 240, identifier:enumerate; 241, argument_list; 241, 242; 242, identifier:runparameter; 243, comment; 244, comment; 245, block; 245, 246; 245, 259; 245, 260; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:index; 249, binary_operator:-; 249, 250; 249, 258; 250, call; 250, 251; 250, 252; 251, identifier:int; 252, argument_list; 252, 253; 253, subscript; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:runparameter; 256, identifier:attrib; 257, string:'Index'; 258, integer:1; 259, comment; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:reads; 264, identifier:text; 265, call; 265, 266; 265, 267; 266, identifier:str; 267, argument_list; 267, 268; 268, subscript; 268, 269; 268, 272; 269, subscript; 269, 270; 269, 271; 270, identifier:cycles; 271, identifier:index; 272, identifier:indexcount; 273, comment; 274, if_statement; 274, 275; 274, 280; 275, comparison_operator:==; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:runparameter; 278, identifier:tag; 279, string:'Instrument'; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:runparameter; 285, identifier:text; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:instrument; 289, comment; 290, for_statement; 290, 291; 290, 292; 290, 293; 290, 294; 291, identifier:parameter; 292, identifier:parameters; 293, comment; 294, block; 294, 295; 295, if_statement; 295, 296; 295, 301; 295, 302; 296, comparison_operator:==; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:runparameter; 299, identifier:tag; 300, identifier:parameter; 301, comment; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:runparameter; 307, identifier:text; 308, subscript; 308, 309; 308, 310; 309, identifier:parameters; 310, identifier:parameter; 311, if_statement; 311, 312; 311, 317; 312, comparison_operator:in; 312, 313; 312, 314; 313, string:'Barcode'; 314, attribute; 314, 315; 314, 316; 315, identifier:runparameter; 316, identifier:tag; 317, block; 317, 318; 318, for_statement; 318, 319; 318, 322; 318, 326; 318, 327; 318, 328; 319, pattern_list; 319, 320; 319, 321; 320, identifier:cycle; 321, identifier:barcode; 322, call; 322, 323; 322, 324; 323, identifier:enumerate; 324, argument_list; 324, 325; 325, identifier:runparameter; 326, comment; 327, comment; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:barcode; 333, identifier:text; 334, call; 334, 335; 334, 336; 335, identifier:str; 336, argument_list; 336, 337; 337, binary_operator:+; 337, 338; 337, 343; 338, binary_operator:+; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:self; 341, identifier:forwardlength; 342, integer:1; 343, identifier:cycle; 344, comment; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:config; 349, identifier:write; 350, argument_list; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, string:'{}Data/Intensities/BaseCalls/config.xml'; 354, identifier:format; 355, argument_list; 355, 356; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:miseqfolder | def configfilepopulator(self):
"""Populates an unpopulated config.xml file with run-specific values and creates
the file in the appropriate location"""
# Set the number of cycles for each read and index using the number of reads specified in the sample sheet
self.forwardlength = self.metadata.header.forwardlength
self.reverselength = self.metadata.header.reverselength
# Create a list of lists containing [cycle start, cycle end, and :runid] for each of forward reads, index 1
# index 2, and reverse reads
cycles = [[1, self.forwardlength, self.runid],
[self.forwardlength + 1, self.forwardlength + 8, self.runid],
[self.forwardlength + 9, self.forwardlength + 16, self.runid],
[self.forwardlength + 17, self.forwardlength + 16 + self.reverselength, self.runid]]
# A dictionary of parameters (keys) and the values to use when repopulating the config file
parameters = {'RunFolder': self.runid, 'RunFolderDate': self.metadata.date.replace("-", ""),
'RunFolderId': self.metadata.runnumber, 'RunFlowcellId': self.metadata.flowcell}
# Load the xml file using element tree
config = ElementTree.parse("{}/config.xml".format(self.homepath))
# Get the root of the tree
configroot = config.getroot()
# The run node is the only child node of the root
for run in configroot:
# Iterate through the child nodes. There are three nodes sections that must be populated
for child in run:
# Find the cycles tag
if child.tag == 'Cycles':
# Set the attributes with a dictionary containing the total reads
child.attrib = {'Last': '{}'.format(self.forwardlength + 16 + self.reverselength),
'Number': '{}'.format(self.totalreads), 'First': '1'}
elif child.tag == 'RunParameters':
# Name the child as runparameter for easier coding
runparameters = child
for runparameter in runparameters:
# This replaces data in both 'ImagingReads' and 'Reads' nodes
if 'Reads' in runparameter.tag:
# Enumerate through the run parameters
for indexcount, reads in enumerate(runparameter):
# The values for the index are 1, 2, 3, 4. Subtract one to get the index of the first
# list in cycles
index = int(runparameter.attrib['Index']) - 1
# Set the text value as the appropriate value from cycles
reads.text = str(cycles[index][indexcount])
# Populate the instrument value
if runparameter.tag == 'Instrument':
runparameter.text = self.instrument
# Iterate through the parameters in the parameter dictionary
for parameter in parameters:
# If the key is encountered
if runparameter.tag == parameter:
# Replace the text with the value
runparameter.text = parameters[parameter]
if 'Barcode' in runparameter.tag:
for cycle, barcode in enumerate(runparameter):
# Add the barcode cycles. These are the number of forward reads (+ 1 as the barcode
# starts 1 cycle after the first run) plus the current iterator
barcode.text = str(self.forwardlength + 1 + cycle)
# Write the modified config file to the desired location
config.write('{}Data/Intensities/BaseCalls/config.xml'.format(self.miseqfolder)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_check_time_format; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:labels; 6, identifier:values; 7, block; 7, 8; 7, 10; 8, expression_statement; 8, 9; 9, comment; 10, for_statement; 10, 11; 10, 14; 10, 19; 11, pattern_list; 11, 12; 11, 13; 12, identifier:label; 13, identifier:value; 14, call; 14, 15; 14, 16; 15, identifier:zip; 16, argument_list; 16, 17; 16, 18; 17, identifier:labels; 18, identifier:values; 19, block; 19, 20; 19, 26; 19, 74; 19, 98; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:==; 21, 22; 21, 23; 22, identifier:value; 23, string:"*"; 24, block; 24, 25; 25, continue_statement; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:label; 29, string:"day_of_week"; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 37; 31, 59; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:value; 36, identifier:string_types; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:not; 39, 40; 39, 41; 40, identifier:value; 41, identifier:ORDER_WEEK; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:ParseError; 46, argument_list; 46, 47; 47, binary_operator:%; 47, 48; 47, 51; 48, concatenated_string; 48, 49; 48, 50; 49, string:"'%s' is not day of the week. "; 50, string:"character is the only '%s'"; 51, tuple; 51, 52; 51, 53; 52, identifier:value; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:', '; 56, identifier:join; 57, argument_list; 57, 58; 58, identifier:ORDER_WEEK; 59, elif_clause; 59, 60; 59, 66; 60, not_operator; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:value; 65, identifier:int; 66, block; 66, 67; 67, raise_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:TypeError; 70, argument_list; 70, 71; 71, binary_operator:%; 71, 72; 71, 73; 72, string:"'%s' is not an int"; 73, identifier:value; 74, if_statement; 74, 75; 74, 82; 75, comparison_operator:in; 75, 76; 75, 77; 76, identifier:label; 77, list:["year", "month", "day", "num_of_week"]; 77, 78; 77, 79; 77, 80; 77, 81; 78, string:"year"; 79, string:"month"; 80, string:"day"; 81, string:"num_of_week"; 82, block; 82, 83; 83, if_statement; 83, 84; 83, 90; 84, not_operator; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:isinstance; 87, argument_list; 87, 88; 87, 89; 88, identifier:value; 89, identifier:int; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:TypeError; 94, argument_list; 94, 95; 95, binary_operator:%; 95, 96; 95, 97; 96, string:"'%s' is not an int"; 97, identifier:value; 98, if_statement; 98, 99; 98, 104; 99, call; 99, 100; 99, 101; 100, identifier:isinstance; 101, argument_list; 101, 102; 101, 103; 102, identifier:value; 103, identifier:int; 104, block; 104, 105; 104, 113; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, pattern_list; 107, 108; 107, 109; 108, identifier:start; 109, identifier:end; 110, subscript; 110, 111; 110, 112; 111, identifier:TIME_INFO; 112, identifier:label; 113, if_statement; 113, 114; 113, 119; 114, not_operator; 114, 115; 115, comparison_operator:<=; 115, 116; 115, 117; 115, 118; 116, identifier:start; 117, identifier:value; 118, identifier:end; 119, block; 119, 120; 120, raise_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:PeriodRangeError; 123, argument_list; 123, 124; 124, binary_operator:%; 124, 125; 124, 128; 125, concatenated_string; 125, 126; 125, 127; 126, string:"'%d' is outside the scope of the period "; 127, string:"'%s' range: '%d' to '%d'"; 128, tuple; 128, 129; 128, 130; 128, 131; 128, 132; 129, identifier:value; 130, identifier:label; 131, identifier:start; 132, identifier:end | def _check_time_format(self, labels, values):
""" To check the format of the times
:param list labels: years or months or days or number week
:param list values: number or the asterisk in the list
:rtype: None or Exception
:raises PeriodRangeError: outside the scope of the period
:raises ParseError: not parse the day of the week
:return: in the case of exception returns the exception
"""
for label, value in zip(labels, values):
if value == "*":
continue
if label == "day_of_week":
if isinstance(value, string_types):
if value not in ORDER_WEEK:
raise ParseError("'%s' is not day of the week. "
"character is the only '%s'" % (
value, ', '.join(ORDER_WEEK)))
elif not isinstance(value, int):
raise TypeError("'%s' is not an int" % value)
if label in ["year", "month", "day", "num_of_week"]:
if not isinstance(value, int):
raise TypeError("'%s' is not an int" % value)
if isinstance(value, int):
start, end = TIME_INFO[label]
if not start <= value <= end:
raise PeriodRangeError("'%d' is outside the scope of the period "
"'%s' range: '%d' to '%d'" % (
value, label, start, end)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:readlength; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 16; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:'Estimating read lengths of FASTQ files'; 15, comment; 16, for_statement; 16, 17; 16, 18; 16, 21; 17, identifier:sample; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:samples; 21, block; 21, 22; 21, 30; 21, 38; 21, 46; 21, 54; 21, 62; 21, 70; 21, 71; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:sample; 27, identifier:run; 28, identifier:Date; 29, string:'NA'; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:sample; 35, identifier:run; 36, identifier:InvestigatorName; 37, string:'NA'; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:sample; 43, identifier:run; 44, identifier:TotalClustersinRun; 45, string:'NA'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:sample; 51, identifier:run; 52, identifier:NumberofClustersPF; 53, string:'NA'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:sample; 59, identifier:run; 60, identifier:PercentOfClusters; 61, string:'NA'; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:sample; 67, identifier:run; 68, identifier:SampleProject; 69, string:'NA'; 70, comment; 71, if_statement; 71, 72; 71, 93; 71, 94; 72, boolean_operator:and; 72, 73; 72, 83; 73, not_operator; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:GenObject; 77, identifier:isattr; 78, argument_list; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:sample; 81, identifier:run; 82, string:'forwardlength'; 83, not_operator; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:GenObject; 87, identifier:isattr; 88, argument_list; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:sample; 91, identifier:run; 92, string:'reverselength'; 93, comment; 94, block; 94, 95; 94, 103; 94, 111; 94, 112; 94, 122; 94, 123; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:sample; 99, identifier:header; 100, call; 100, 101; 100, 102; 101, identifier:GenObject; 102, argument_list; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:sample; 107, identifier:commands; 108, call; 108, 109; 108, 110; 109, identifier:GenObject; 110, argument_list; 111, comment; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:devnull; 115, call; 115, 116; 115, 117; 116, identifier:open; 117, argument_list; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:os; 120, identifier:devnull; 121, string:'wb'; 122, comment; 123, if_statement; 123, 124; 123, 134; 123, 135; 124, comparison_operator:is; 124, 125; 124, 133; 125, call; 125, 126; 125, 127; 126, identifier:type; 127, argument_list; 127, 128; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:sample; 131, identifier:general; 132, identifier:fastqfiles; 133, identifier:list; 134, comment; 135, block; 135, 136; 135, 149; 135, 150; 135, 165; 135, 166; 135, 167; 135, 203; 135, 204; 135, 205; 135, 207; 135, 208; 135, 209; 135, 232; 135, 233; 135, 286; 135, 287; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:forwardfastq; 139, subscript; 139, 140; 139, 148; 140, call; 140, 141; 140, 142; 141, identifier:sorted; 142, argument_list; 142, 143; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:sample; 146, identifier:general; 147, identifier:fastqfiles; 148, integer:0; 149, comment; 150, if_statement; 150, 151; 150, 154; 150, 159; 151, comparison_operator:in; 151, 152; 151, 153; 152, string:'.gz'; 153, identifier:forwardfastq; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:command; 158, string:'zcat'; 159, else_clause; 159, 160; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:command; 164, string:'cat'; 165, comment; 166, comment; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:forwardreads; 170, call; 170, 171; 170, 202; 171, attribute; 171, 172; 171, 201; 172, subscript; 172, 173; 172, 200; 173, call; 173, 174; 173, 199; 174, attribute; 174, 175; 174, 198; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:subprocess; 178, identifier:Popen; 179, argument_list; 179, 180; 179, 187; 179, 190; 179, 195; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, string:"{} {} | head -n 1000"; 183, identifier:format; 184, argument_list; 184, 185; 184, 186; 185, identifier:command; 186, identifier:forwardfastq; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:shell; 189, True; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:stdout; 192, attribute; 192, 193; 192, 194; 193, identifier:subprocess; 194, identifier:PIPE; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:stderr; 197, identifier:devnull; 198, identifier:communicate; 199, argument_list; 200, integer:0; 201, identifier:rstrip; 202, argument_list; 203, comment; 204, comment; 205, expression_statement; 205, 206; 206, comment; 207, comment; 208, comment; 209, try_statement; 209, 210; 209, 211; 209, 221; 210, comment; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:forwardreads; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:forwardreads; 218, identifier:decode; 219, argument_list; 219, 220; 220, string:'utf-8'; 221, except_clause; 221, 222; 221, 223; 222, identifier:UnicodeDecodeError; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:sample; 229, identifier:run; 230, identifier:forwardlength; 231, integer:0; 232, comment; 233, try_statement; 233, 234; 233, 273; 234, block; 234, 235; 234, 265; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:forwardlength; 238, call; 238, 239; 238, 240; 239, identifier:max; 240, argument_list; 240, 241; 241, list_comprehension; 241, 242; 241, 246; 241, 259; 242, call; 242, 243; 242, 244; 243, identifier:len; 244, argument_list; 244, 245; 245, identifier:sequence; 246, for_in_clause; 246, 247; 246, 250; 247, pattern_list; 247, 248; 247, 249; 248, identifier:iterator; 249, identifier:sequence; 250, call; 250, 251; 250, 252; 251, identifier:enumerate; 252, argument_list; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:forwardreads; 256, identifier:split; 257, argument_list; 257, 258; 258, string:'\n'; 259, if_clause; 259, 260; 260, comparison_operator:==; 260, 261; 260, 264; 261, binary_operator:%; 261, 262; 261, 263; 262, identifier:iterator; 263, integer:4; 264, integer:1; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 272; 267, attribute; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:sample; 270, identifier:run; 271, identifier:forwardlength; 272, identifier:forwardlength; 273, except_clause; 273, 274; 273, 277; 274, tuple; 274, 275; 274, 276; 275, identifier:ValueError; 276, identifier:TypeError; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 285; 280, attribute; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:sample; 283, identifier:run; 284, identifier:forwardlength; 285, integer:0; 286, comment; 287, if_statement; 287, 288; 287, 298; 287, 419; 287, 420; 288, comparison_operator:==; 288, 289; 288, 297; 289, call; 289, 290; 289, 291; 290, identifier:len; 291, argument_list; 291, 292; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:sample; 295, identifier:general; 296, identifier:fastqfiles; 297, integer:2; 298, block; 298, 299; 298, 312; 298, 348; 298, 370; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:reversefastq; 302, subscript; 302, 303; 302, 311; 303, call; 303, 304; 303, 305; 304, identifier:sorted; 305, argument_list; 305, 306; 306, attribute; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:sample; 309, identifier:general; 310, identifier:fastqfiles; 311, integer:1; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:reversereads; 315, call; 315, 316; 315, 347; 316, attribute; 316, 317; 316, 346; 317, subscript; 317, 318; 317, 345; 318, call; 318, 319; 318, 344; 319, attribute; 319, 320; 319, 343; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:subprocess; 323, identifier:Popen; 324, argument_list; 324, 325; 324, 332; 324, 335; 324, 340; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, string:"{} {} | head -n 1000"; 328, identifier:format; 329, argument_list; 329, 330; 329, 331; 330, identifier:command; 331, identifier:reversefastq; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:shell; 334, True; 335, keyword_argument; 335, 336; 335, 337; 336, identifier:stdout; 337, attribute; 337, 338; 337, 339; 338, identifier:subprocess; 339, identifier:PIPE; 340, keyword_argument; 340, 341; 340, 342; 341, identifier:stderr; 342, identifier:devnull; 343, identifier:communicate; 344, argument_list; 345, integer:0; 346, identifier:rstrip; 347, argument_list; 348, try_statement; 348, 349; 348, 359; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 353; 352, identifier:reversereads; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:reversereads; 356, identifier:decode; 357, argument_list; 357, 358; 358, string:'utf-8'; 359, except_clause; 359, 360; 359, 361; 360, identifier:UnicodeDecodeError; 361, block; 361, 362; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 369; 364, attribute; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:sample; 367, identifier:run; 368, identifier:reverselength; 369, integer:0; 370, try_statement; 370, 371; 370, 406; 371, block; 371, 372; 372, expression_statement; 372, 373; 373, assignment; 373, 374; 373, 379; 374, attribute; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:sample; 377, identifier:run; 378, identifier:reverselength; 379, call; 379, 380; 379, 381; 380, identifier:max; 381, argument_list; 381, 382; 382, list_comprehension; 382, 383; 382, 387; 382, 400; 383, call; 383, 384; 383, 385; 384, identifier:len; 385, argument_list; 385, 386; 386, identifier:sequence; 387, for_in_clause; 387, 388; 387, 391; 388, pattern_list; 388, 389; 388, 390; 389, identifier:iterator; 390, identifier:sequence; 391, call; 391, 392; 391, 393; 392, identifier:enumerate; 393, argument_list; 393, 394; 394, call; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:reversereads; 397, identifier:split; 398, argument_list; 398, 399; 399, string:'\n'; 400, if_clause; 400, 401; 401, comparison_operator:==; 401, 402; 401, 405; 402, binary_operator:%; 402, 403; 402, 404; 403, identifier:iterator; 404, integer:4; 405, integer:1; 406, except_clause; 406, 407; 406, 410; 407, tuple; 407, 408; 407, 409; 408, identifier:ValueError; 409, identifier:TypeError; 410, block; 410, 411; 411, expression_statement; 411, 412; 412, assignment; 412, 413; 412, 418; 413, attribute; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:sample; 416, identifier:run; 417, identifier:reverselength; 418, integer:0; 419, comment; 420, else_clause; 420, 421; 421, block; 421, 422; 422, expression_statement; 422, 423; 423, assignment; 423, 424; 423, 429; 424, attribute; 424, 425; 424, 428; 425, attribute; 425, 426; 425, 427; 426, identifier:sample; 427, identifier:run; 428, identifier:reverselength; 429, integer:0 | def readlength(self):
"""Calculates the read length of the fastq files. Short reads will not be able to be assembled properly with the
default parameters used for spades."""
logging.info('Estimating read lengths of FASTQ files')
# Iterate through the samples
for sample in self.samples:
sample.run.Date = 'NA'
sample.run.InvestigatorName = 'NA'
sample.run.TotalClustersinRun = 'NA'
sample.run.NumberofClustersPF = 'NA'
sample.run.PercentOfClusters = 'NA'
sample.run.SampleProject = 'NA'
# Only perform this step if the forward and reverse lengths have not been loaded into the metadata
if not GenObject.isattr(sample.run, 'forwardlength') and not GenObject.isattr(sample.run, 'reverselength'):
# Initialise the .header attribute for each sample
sample.header = GenObject()
sample.commands = GenObject()
# Set /dev/null
devnull = open(os.devnull, 'wb')
# Only process the samples if the file type is a list
if type(sample.general.fastqfiles) is list:
# Set the forward fastq to be the first entry in the list
forwardfastq = sorted(sample.general.fastqfiles)[0]
# If the files are gzipped, then zcat must be used instead of cat
if '.gz' in forwardfastq:
command = 'zcat'
else:
command = 'cat'
# Read in the output of the (z)cat of the fastq file piped through head to read only the first 1000
# lines. Will make a string of the first 1000 lines in the file
forwardreads = subprocess.Popen("{} {} | head -n 1000".format(command, forwardfastq),
shell=True,
stdout=subprocess.PIPE,
stderr=devnull).communicate()[0].rstrip()
# Set the length of the reads as follows: the highest value (max) of the length of the sequence. The
# sequence was extracted from the rest of the lines in the fastq file. Example of first four lines:
"""
@M02466:126:000000000-AKF4P:1:1101:11875:1838 1:N:0:1
TCATAACGCAGTGAAACGCTTTAACAAAAGCGGAGACACGCCACTATTTGTCAATATTTCGTATGATACATTTTTAGAAAATCAAGAAGAGTTGCACGA
+
AA,B89C,@++B,,,,C,:BFF9,C,,,,,6+++++:,C,8C+BE,EFF9FC,6E,EFGF@F<F@9F9E<FFGGGC8,,,,CC<,,,,,,6CE,C<C,,
"""
# The line with the sequence information occurs every four lines (1, 5, 9, etc). This can be
# represented by linenumber % 4 == 1
try:
# Added due to weird 2to3 conversion issues, was coming
forwardreads = forwardreads.decode('utf-8')
except UnicodeDecodeError:
sample.run.forwardlength = 0
# up as a bytes object when we need it as a string.
try:
forwardlength = max([len(sequence) for iterator, sequence in enumerate(forwardreads.split('\n'))
if iterator % 4 == 1])
sample.run.forwardlength = forwardlength
except (ValueError, TypeError):
sample.run.forwardlength = 0
# For paired end analyses, also calculate the length of the reverse reads
if len(sample.general.fastqfiles) == 2:
reversefastq = sorted(sample.general.fastqfiles)[1]
reversereads = subprocess.Popen("{} {} | head -n 1000".format(command, reversefastq),
shell=True,
stdout=subprocess.PIPE,
stderr=devnull).communicate()[0].rstrip()
try:
reversereads = reversereads.decode('utf-8')
except UnicodeDecodeError:
sample.run.reverselength = 0
try:
sample.run.reverselength = max([len(sequence) for iterator, sequence in
enumerate(reversereads.split('\n')) if iterator % 4 == 1])
except (ValueError, TypeError):
sample.run.reverselength = 0
# Populate metadata of single end reads with 'NA'
else:
sample.run.reverselength = 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:confirm; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 15; 3, 18; 4, default_parameter; 4, 5; 4, 6; 5, identifier:prompt; 6, string:'Really?'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:color; 9, string:'warning'; 10, default_parameter; 10, 11; 10, 12; 11, identifier:yes_values; 12, tuple; 12, 13; 12, 14; 13, string:'y'; 14, string:'yes'; 15, default_parameter; 15, 16; 15, 17; 16, identifier:abort_on_unconfirmed; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:abort_options; 20, None; 21, block; 21, 22; 21, 24; 21, 36; 21, 52; 21, 67; 21, 107; 21, 108; 21, 109; 21, 132; 21, 203; 22, expression_statement; 22, 23; 23, comment; 24, if_statement; 24, 25; 24, 30; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:yes_values; 29, identifier:str; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:yes_values; 34, tuple; 34, 35; 35, identifier:yes_values; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:prompt; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, string:'{prompt} [{yes_value}/N] '; 42, identifier:format; 43, argument_list; 43, 44; 43, 47; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:prompt; 46, identifier:prompt; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:yes_value; 49, subscript; 49, 50; 49, 51; 50, identifier:yes_values; 51, integer:0; 52, if_statement; 52, 53; 52, 54; 53, identifier:color; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:prompt; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:printer; 61, identifier:colorize; 62, argument_list; 62, 63; 62, 64; 63, identifier:prompt; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:color; 66, identifier:color; 67, try_statement; 67, 68; 67, 76; 67, 87; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:answer; 72, call; 72, 73; 72, 74; 73, identifier:input; 74, argument_list; 74, 75; 75, identifier:prompt; 76, except_clause; 76, 77; 76, 78; 77, identifier:KeyboardInterrupt; 78, block; 78, 79; 78, 83; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:print; 82, argument_list; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:confirmed; 86, False; 87, else_clause; 87, 88; 88, block; 88, 89; 88, 101; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:answer; 92, call; 92, 93; 92, 100; 93, attribute; 93, 94; 93, 99; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:answer; 97, identifier:strip; 98, argument_list; 99, identifier:lower; 100, argument_list; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:confirmed; 104, comparison_operator:in; 104, 105; 104, 106; 105, identifier:answer; 106, identifier:yes_values; 107, comment; 108, comment; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:do_abort_on_unconfirmed; 112, boolean_operator:and; 112, 113; 112, 115; 113, not_operator; 113, 114; 114, identifier:confirmed; 115, parenthesized_expression; 115, 116; 115, 117; 115, 118; 116, comment; 117, comment; 118, boolean_operator:or; 118, 119; 118, 123; 118, 124; 119, call; 119, 120; 119, 121; 120, identifier:bool; 121, argument_list; 121, 122; 122, identifier:abort_on_unconfirmed; 123, comment; 124, parenthesized_expression; 124, 125; 125, boolean_operator:and; 125, 126; 125, 129; 126, comparison_operator:==; 126, 127; 126, 128; 127, identifier:abort_on_unconfirmed; 128, integer:0; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:abort_on_unconfirmed; 131, False; 132, if_statement; 132, 133; 132, 134; 133, identifier:do_abort_on_unconfirmed; 134, block; 134, 135; 134, 144; 134, 197; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:abort_options; 138, None; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:abort_options; 143, dictionary; 144, if_statement; 144, 145; 144, 148; 144, 157; 144, 172; 144, 187; 145, comparison_operator:is; 145, 146; 145, 147; 146, identifier:abort_on_unconfirmed; 147, True; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:abort_options; 153, identifier:setdefault; 154, argument_list; 154, 155; 154, 156; 155, string:'return_code'; 156, integer:0; 157, elif_clause; 157, 158; 157, 163; 158, call; 158, 159; 158, 160; 159, identifier:isinstance; 160, argument_list; 160, 161; 160, 162; 161, identifier:abort_on_unconfirmed; 162, identifier:int; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:abort_options; 168, identifier:setdefault; 169, argument_list; 169, 170; 169, 171; 170, string:'return_code'; 171, identifier:abort_on_unconfirmed; 172, elif_clause; 172, 173; 172, 178; 173, call; 173, 174; 173, 175; 174, identifier:isinstance; 175, argument_list; 175, 176; 175, 177; 176, identifier:abort_on_unconfirmed; 177, identifier:str; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:abort_options; 183, identifier:setdefault; 184, argument_list; 184, 185; 184, 186; 185, string:'message'; 186, identifier:abort_on_unconfirmed; 187, else_clause; 187, 188; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:abort_options; 193, identifier:setdefault; 194, argument_list; 194, 195; 194, 196; 195, string:'return_code'; 196, integer:0; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:abort; 200, argument_list; 200, 201; 201, dictionary_splat; 201, 202; 202, identifier:abort_options; 203, return_statement; 203, 204; 204, identifier:confirmed | def confirm(prompt='Really?', color='warning', yes_values=('y', 'yes'),
abort_on_unconfirmed=False, abort_options=None):
"""Prompt for confirmation.
Confirmation can be aborted by typing in a no value instead of one
of the yes values or with Ctrl-C.
Args:
prompt (str): Prompt to present user ["Really?"]
color (string|Color|bool) Color to print prompt string; can be
``False`` or ``None`` to print without color ["yellow"]
yes_values (list[str]): Values user must type in to confirm
[("y", "yes")]
abort_on_unconfirmed (bool|int|str): When user does *not*
confirm:
- If this is an integer, print "Aborted" to stdout if
it's 0 or to stderr if it's not 0 and then exit with
this code
- If this is a string, print it to stdout and exit with
code 0
- If this is ``True`` (or any other truthy value), print
"Aborted" to stdout and exit with code 0
abort_options (dict): Options to pass to :func:`abort` when not
confirmed (these options will override any options set via
``abort_on_unconfirmed``)
"""
if isinstance(yes_values, str):
yes_values = (yes_values,)
prompt = '{prompt} [{yes_value}/N] '.format(prompt=prompt, yes_value=yes_values[0])
if color:
prompt = printer.colorize(prompt, color=color)
try:
answer = input(prompt)
except KeyboardInterrupt:
print()
confirmed = False
else:
answer = answer.strip().lower()
confirmed = answer in yes_values
# NOTE: The abort-on-unconfirmed logic is somewhat convoluted
# because of the special case for return code 0.
do_abort_on_unconfirmed = not confirmed and (
# True, non-zero return code, non-empty string, or any other
# truthy value (in the manner of typical Python duck-typing)
bool(abort_on_unconfirmed) or
# Zero return code (special case)
(abort_on_unconfirmed == 0 and abort_on_unconfirmed is not False)
)
if do_abort_on_unconfirmed:
if abort_options is None:
abort_options = {}
if abort_on_unconfirmed is True:
abort_options.setdefault('return_code', 0)
elif isinstance(abort_on_unconfirmed, int):
abort_options.setdefault('return_code', abort_on_unconfirmed)
elif isinstance(abort_on_unconfirmed, str):
abort_options.setdefault('message', abort_on_unconfirmed)
else:
abort_options.setdefault('return_code', 0)
abort(**abort_options)
return confirmed |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:from_string; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:action_str; 6, block; 6, 7; 6, 9; 6, 13; 6, 191; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:args; 12, dictionary; 13, try_statement; 13, 14; 13, 24; 13, 34; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:mod_obj; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:ast; 21, identifier:parse; 22, argument_list; 22, 23; 23, identifier:action_str; 24, except_clause; 24, 25; 24, 31; 25, as_pattern; 25, 26; 25, 29; 26, tuple; 26, 27; 26, 28; 27, identifier:SyntaxError; 28, identifier:ValueError; 29, as_pattern_target; 29, 30; 30, identifier:e; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, identifier:e; 34, else_clause; 34, 35; 35, block; 35, 36; 35, 46; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:call_obj; 39, attribute; 39, 40; 39, 45; 40, subscript; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:mod_obj; 43, identifier:body; 44, integer:0; 45, identifier:value; 46, if_statement; 46, 47; 46, 54; 46, 55; 46, 56; 46, 71; 46, 184; 47, call; 47, 48; 47, 49; 48, identifier:isinstance; 49, argument_list; 49, 50; 49, 51; 50, identifier:call_obj; 51, attribute; 51, 52; 51, 53; 52, identifier:ast; 53, identifier:Attribute; 54, comment; 55, comment; 56, block; 56, 57; 56, 65; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:module; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:call_obj; 63, identifier:value; 64, identifier:id; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:func; 68, attribute; 68, 69; 68, 70; 69, identifier:call_obj; 70, identifier:attr; 71, elif_clause; 71, 72; 71, 79; 71, 80; 71, 81; 71, 82; 71, 83; 72, call; 72, 73; 72, 74; 73, identifier:isinstance; 74, argument_list; 74, 75; 74, 76; 75, identifier:call_obj; 76, attribute; 76, 77; 76, 78; 77, identifier:ast; 78, identifier:Call; 79, comment; 80, comment; 81, comment; 82, comment; 83, block; 83, 84; 84, try_statement; 84, 85; 84, 104; 84, 112; 85, block; 85, 86; 85, 96; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:module; 89, attribute; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:call_obj; 93, identifier:func; 94, identifier:value; 95, identifier:id; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:func; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:call_obj; 102, identifier:func; 103, identifier:attr; 104, except_clause; 104, 105; 104, 106; 105, identifier:AttributeError; 106, block; 106, 107; 107, raise_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:UnsupportedActionError; 110, argument_list; 110, 111; 111, identifier:action_str; 112, else_clause; 112, 113; 112, 114; 113, comment; 114, block; 114, 115; 115, for_statement; 115, 116; 115, 117; 115, 120; 115, 121; 116, identifier:kwarg; 117, attribute; 117, 118; 117, 119; 118, identifier:call_obj; 119, identifier:keywords; 120, comment; 121, block; 121, 122; 122, if_statement; 122, 123; 122, 132; 122, 149; 122, 176; 123, call; 123, 124; 123, 125; 124, identifier:isinstance; 125, argument_list; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:kwarg; 128, identifier:value; 129, attribute; 129, 130; 129, 131; 130, identifier:ast; 131, identifier:Num; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:args; 137, identifier:update; 138, argument_list; 138, 139; 139, dictionary; 139, 140; 140, pair; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:kwarg; 143, identifier:arg; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:kwarg; 147, identifier:value; 148, identifier:n; 149, elif_clause; 149, 150; 149, 159; 150, call; 150, 151; 150, 152; 151, identifier:isinstance; 152, argument_list; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:kwarg; 155, identifier:value; 156, attribute; 156, 157; 156, 158; 157, identifier:ast; 158, identifier:Str; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:args; 164, identifier:update; 165, argument_list; 165, 166; 166, dictionary; 166, 167; 167, pair; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:kwarg; 170, identifier:arg; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:kwarg; 174, identifier:value; 175, identifier:s; 176, else_clause; 176, 177; 177, block; 177, 178; 178, raise_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:UnsupportedActionArgumentError; 181, argument_list; 181, 182; 181, 183; 182, identifier:action_str; 183, identifier:kwarg; 184, else_clause; 184, 185; 185, block; 185, 186; 186, raise_statement; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:UnsupportedActionError; 189, argument_list; 189, 190; 190, identifier:action_str; 191, return_statement; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:cls; 194, argument_list; 194, 195; 194, 196; 194, 197; 195, identifier:module; 196, identifier:func; 197, identifier:args | def from_string(cls, action_str):
"""
Creates a new Action instance from the given string.
The given string **must** match one of those patterns:
* module.function
* module.function()
* module.function(arg1=value1, arg2=value2)
Any other form will trigger an Exception.
The function parses the given string and tries to load the function
from the given module.
Raises :class:`exceptions.SyntaxError` if the compiled source code is
invalid.
Raises :class:`exceptions.ValueError` if the given source code contains
null bytes.
Raises :class:`exceptions.UnsupportedActionError` if the given source
code can not be parsed (doesn't match one of the supported patterns).
Raises :class:`exceptions.UnsupportedActionArgumentError` if one the
given argument has an unsupported type (we only support
:class:`ast.Num` and :class:`ast.Str`).
Returns a new :class:`Action` instance.
"""
args = {}
try:
mod_obj = ast.parse(action_str)
except (SyntaxError, ValueError) as e:
raise e
else:
call_obj = mod_obj.body[0].value
if isinstance(call_obj, ast.Attribute):
# Seems like we have a simple function name
# (for example `module.function`)
module = call_obj.value.id
func = call_obj.attr
elif isinstance(call_obj, ast.Call):
# Seems like we have a function call, maybe with
# a few parameters.
# Note that we only support `module.function()` format.
# You can't use `function()`.
try:
module = call_obj.func.value.id
func = call_obj.func.attr
except AttributeError:
raise UnsupportedActionError(action_str)
else:
# If we have arguments, they MUST be named:
for kwarg in call_obj.keywords:
# We only support Strings and Numerics:
if isinstance(kwarg.value, ast.Num):
args.update({kwarg.arg: kwarg.value.n})
elif isinstance(kwarg.value, ast.Str):
args.update({kwarg.arg: kwarg.value.s})
else:
raise UnsupportedActionArgumentError(action_str,
kwarg)
else:
raise UnsupportedActionError(action_str)
return cls(module, func, args) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:epcrparsethreads; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 13; 5, 14; 5, 56; 5, 177; 6, expression_statement; 6, 7; 7, comment; 8, import_from_statement; 8, 9; 8, 11; 9, dotted_name; 9, 10; 10, identifier:Bio; 11, dotted_name; 11, 12; 12, identifier:SeqIO; 13, comment; 14, for_statement; 14, 15; 14, 16; 14, 19; 15, identifier:sample; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:metadata; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 28; 21, comparison_operator:!=; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:sample; 25, identifier:general; 26, identifier:bestassemblyfile; 27, string:'NA'; 28, block; 28, 29; 28, 43; 28, 50; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:threads; 32, call; 32, 33; 32, 34; 33, identifier:Thread; 34, argument_list; 34, 35; 34, 40; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:target; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:epcrparse; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:args; 42, tuple; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:threads; 47, identifier:setDaemon; 48, argument_list; 48, 49; 49, True; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:threads; 54, identifier:start; 55, argument_list; 56, for_statement; 56, 57; 56, 58; 56, 61; 57, identifier:sample; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:metadata; 61, block; 61, 62; 62, if_statement; 62, 63; 62, 70; 63, comparison_operator:!=; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:sample; 67, identifier:general; 68, identifier:bestassemblyfile; 69, string:'NA'; 70, block; 70, 71; 71, if_statement; 71, 72; 71, 81; 71, 82; 72, comparison_operator:!=; 72, 73; 72, 80; 73, attribute; 73, 74; 73, 79; 74, subscript; 74, 75; 74, 76; 75, identifier:sample; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:analysistype; 79, identifier:primers; 80, string:'NA'; 81, comment; 82, block; 82, 83; 82, 89; 82, 90; 82, 102; 82, 114; 82, 115; 82, 142; 82, 143; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:record; 86, call; 86, 87; 86, 88; 87, identifier:dict; 88, argument_list; 89, comment; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 99; 92, attribute; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 95; 94, identifier:sample; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:analysistype; 98, identifier:blastresults; 99, call; 99, 100; 99, 101; 100, identifier:dict; 101, argument_list; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 111; 104, attribute; 104, 105; 104, 110; 105, subscript; 105, 106; 105, 107; 106, identifier:sample; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:analysistype; 110, identifier:rawblastresults; 111, call; 111, 112; 111, 113; 112, identifier:dict; 113, argument_list; 114, comment; 115, for_statement; 115, 116; 115, 117; 115, 128; 116, identifier:rec; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:SeqIO; 120, identifier:parse; 121, argument_list; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:sample; 125, identifier:general; 126, identifier:bestassemblyfile; 127, string:'fasta'; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 136; 131, subscript; 131, 132; 131, 133; 132, identifier:record; 133, attribute; 133, 134; 133, 135; 134, identifier:rec; 135, identifier:id; 136, call; 136, 137; 136, 138; 137, identifier:str; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:rec; 141, identifier:seq; 142, comment; 143, for_statement; 143, 144; 143, 145; 143, 152; 143, 153; 143, 154; 144, identifier:line; 145, attribute; 145, 146; 145, 151; 146, subscript; 146, 147; 146, 148; 147, identifier:sample; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:analysistype; 151, identifier:epcrresults; 152, comment; 153, comment; 154, block; 154, 155; 155, if_statement; 155, 156; 155, 163; 155, 164; 156, not_operator; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:line; 160, identifier:startswith; 161, argument_list; 161, 162; 162, string:'#'; 163, comment; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:epcrparsequeue; 171, identifier:put; 172, argument_list; 172, 173; 173, tuple; 173, 174; 173, 175; 173, 176; 174, identifier:sample; 175, identifier:record; 176, identifier:line; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:epcrparsequeue; 183, identifier:join; 184, argument_list | def epcrparsethreads(self):
"""
Parse the ePCR results, and run BLAST on the parsed results
"""
from Bio import SeqIO
# Create the threads for the BLAST analysis
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
threads = Thread(target=self.epcrparse, args=())
threads.setDaemon(True)
threads.start()
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
if sample[self.analysistype].primers != 'NA':
# Initialise a dictionary to store the SeqIO records of each assembly
record = dict()
# Initialise dictionaries to store results in the object
sample[self.analysistype].blastresults = dict()
sample[self.analysistype].rawblastresults = dict()
# Load the records from the assembly into the dictionary
for rec in SeqIO.parse(sample.general.bestassemblyfile, 'fasta'):
record[rec.id] = str(rec.seq)
# Iterate through the ePCR results
for line in sample[self.analysistype].epcrresults:
# The data of interest is in the lines that do not start with a #
# TLH 2016-SEQ-0359_4_length_321195_cov_28.6354_ID_3773 + 227879 228086 0 0 208/1000-1000
if not line.startswith('#'):
# Add the variables to the queue
self.epcrparsequeue.put((sample, record, line))
self.epcrparsequeue.join() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:trimquality; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 16; 5, 408; 5, 409; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:"Trimming fastq files"; 15, comment; 16, with_statement; 16, 17; 16, 28; 17, with_clause; 17, 18; 18, with_item; 18, 19; 19, as_pattern; 19, 20; 19, 26; 20, call; 20, 21; 20, 22; 21, identifier:progressbar; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:metadata; 26, as_pattern_target; 26, 27; 27, identifier:bar; 28, block; 28, 29; 29, for_statement; 29, 30; 29, 31; 29, 32; 29, 33; 29, 34; 30, identifier:sample; 31, identifier:bar; 32, comment; 33, comment; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 46; 35, 47; 36, comparison_operator:is; 36, 37; 36, 45; 37, call; 37, 38; 37, 39; 38, identifier:type; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:sample; 43, identifier:general; 44, identifier:fastqfiles; 45, identifier:list; 46, comment; 47, block; 47, 48; 47, 59; 47, 60; 47, 68; 47, 69; 47, 88; 47, 107; 47, 108; 47, 109; 47, 147; 47, 156; 47, 157; 47, 158; 47, 162; 47, 163; 47, 328; 47, 329; 47, 350; 47, 371; 47, 372; 47, 394; 47, 395; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:fastqfiles; 51, call; 51, 52; 51, 53; 52, identifier:sorted; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:sample; 57, identifier:general; 58, identifier:fastqfiles; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:outputdir; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:sample; 66, identifier:general; 67, identifier:outputdirectory; 68, comment; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:cleanforward; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:os; 76, identifier:path; 77, identifier:join; 78, argument_list; 78, 79; 78, 80; 79, identifier:outputdir; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, string:'{}_R1_trimmed.fastq.gz'; 83, identifier:format; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:sample; 87, identifier:name; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:cleanreverse; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:os; 95, identifier:path; 96, identifier:join; 97, argument_list; 97, 98; 97, 99; 98, identifier:outputdir; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, string:'{}_R2_trimmed.fastq.gz'; 102, identifier:format; 103, argument_list; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:sample; 106, identifier:name; 107, comment; 108, comment; 109, try_statement; 109, 110; 109, 133; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:lesser_length; 114, call; 114, 115; 114, 116; 115, identifier:min; 116, argument_list; 116, 117; 116, 125; 117, call; 117, 118; 117, 119; 118, identifier:int; 119, argument_list; 119, 120; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:sample; 123, identifier:run; 124, identifier:forwardlength; 125, call; 125, 126; 125, 127; 126, identifier:int; 127, argument_list; 127, 128; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:sample; 131, identifier:run; 132, identifier:reverselength; 133, except_clause; 133, 134; 133, 135; 134, identifier:ValueError; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:lesser_length; 139, call; 139, 140; 139, 141; 140, identifier:int; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:sample; 145, identifier:run; 146, identifier:forwardlength; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:min_len; 150, conditional_expression:if; 150, 151; 150, 152; 150, 155; 151, integer:50; 152, comparison_operator:>=; 152, 153; 152, 154; 153, identifier:lesser_length; 154, integer:50; 155, identifier:lesser_length; 156, comment; 157, comment; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:trim_left; 161, integer:0; 162, comment; 163, try_statement; 163, 164; 163, 305; 164, block; 164, 165; 165, if_statement; 165, 166; 165, 171; 165, 239; 166, comparison_operator:in; 166, 167; 166, 168; 167, string:'R2'; 168, subscript; 168, 169; 168, 170; 169, identifier:fastqfiles; 170, integer:0; 171, block; 171, 172; 172, if_statement; 172, 173; 172, 182; 172, 219; 173, not_operator; 173, 174; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:os; 178, identifier:path; 179, identifier:isfile; 180, argument_list; 180, 181; 181, identifier:cleanreverse; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 191; 185, pattern_list; 185, 186; 185, 187; 185, 188; 185, 189; 185, 190; 186, identifier:out; 187, line_continuation:\; 188, identifier:err; 189, line_continuation:\; 190, identifier:bbdukcall; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:bbtools; 194, identifier:bbduk_trim; 195, argument_list; 195, 196; 195, 201; 195, 204; 195, 207; 195, 210; 195, 213; 195, 216; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:forward_in; 198, subscript; 198, 199; 198, 200; 199, identifier:fastqfiles; 200, integer:0; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:reverse_in; 203, None; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:forward_out; 206, identifier:cleanreverse; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:trimq; 209, integer:10; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:minlength; 212, identifier:min_len; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:forcetrimleft; 215, identifier:trim_left; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:returncmd; 218, True; 219, else_clause; 219, 220; 220, block; 220, 221; 220, 227; 220, 233; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:bbdukcall; 224, call; 224, 225; 224, 226; 225, identifier:str; 226, argument_list; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:out; 230, call; 230, 231; 230, 232; 231, identifier:str; 232, argument_list; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:err; 236, call; 236, 237; 236, 238; 237, identifier:str; 238, argument_list; 239, else_clause; 239, 240; 240, block; 240, 241; 241, if_statement; 241, 242; 241, 251; 241, 285; 242, not_operator; 242, 243; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:os; 247, identifier:path; 248, identifier:isfile; 249, argument_list; 249, 250; 250, identifier:cleanforward; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 260; 254, pattern_list; 254, 255; 254, 256; 254, 257; 254, 258; 254, 259; 255, identifier:out; 256, line_continuation:\; 257, identifier:err; 258, line_continuation:\; 259, identifier:bbdukcall; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:bbtools; 263, identifier:bbduk_trim; 264, argument_list; 264, 265; 264, 270; 264, 273; 264, 276; 264, 279; 264, 282; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:forward_in; 267, subscript; 267, 268; 267, 269; 268, identifier:fastqfiles; 269, integer:0; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:forward_out; 272, identifier:cleanforward; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:trimq; 275, integer:10; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:minlength; 278, identifier:min_len; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:forcetrimleft; 281, identifier:trim_left; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:returncmd; 284, True; 285, else_clause; 285, 286; 286, block; 286, 287; 286, 293; 286, 299; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:bbdukcall; 290, call; 290, 291; 290, 292; 291, identifier:str; 292, argument_list; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:out; 296, call; 296, 297; 296, 298; 297, identifier:str; 298, argument_list; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:err; 302, call; 302, 303; 302, 304; 303, identifier:str; 304, argument_list; 305, except_clause; 305, 306; 305, 309; 306, tuple; 306, 307; 306, 308; 307, identifier:IndexError; 308, identifier:CalledProcessError; 309, block; 309, 310; 309, 316; 309, 322; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:bbdukcall; 313, call; 313, 314; 313, 315; 314, identifier:str; 315, argument_list; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:out; 319, call; 319, 320; 319, 321; 320, identifier:str; 321, argument_list; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:err; 325, call; 325, 326; 325, 327; 326, identifier:str; 327, argument_list; 328, comment; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 332; 331, identifier:write_to_logfile; 332, argument_list; 332, 333; 332, 334; 332, 335; 332, 338; 332, 343; 332, 348; 332, 349; 333, identifier:bbdukcall; 334, identifier:bbdukcall; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:logfile; 338, attribute; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:sample; 341, identifier:general; 342, identifier:logout; 343, attribute; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:sample; 346, identifier:general; 347, identifier:logerr; 348, None; 349, None; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 353; 352, identifier:write_to_logfile; 353, argument_list; 353, 354; 353, 355; 353, 356; 353, 359; 353, 364; 353, 369; 353, 370; 354, identifier:out; 355, identifier:err; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:logfile; 359, attribute; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:sample; 362, identifier:general; 363, identifier:logout; 364, attribute; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:sample; 367, identifier:general; 368, identifier:logerr; 369, None; 370, None; 371, comment; 372, expression_statement; 372, 373; 373, assignment; 373, 374; 373, 375; 374, identifier:trimmedfastqfiles; 375, call; 375, 376; 375, 377; 376, identifier:sorted; 377, argument_list; 377, 378; 378, call; 378, 379; 378, 380; 379, identifier:glob; 380, argument_list; 380, 381; 381, call; 381, 382; 381, 387; 382, attribute; 382, 383; 382, 386; 383, attribute; 383, 384; 383, 385; 384, identifier:os; 385, identifier:path; 386, identifier:join; 387, argument_list; 387, 388; 387, 393; 388, attribute; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:sample; 391, identifier:general; 392, identifier:outputdirectory; 393, string:'*trimmed.fastq.gz'; 394, comment; 395, expression_statement; 395, 396; 396, assignment; 396, 397; 396, 402; 397, attribute; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:sample; 400, identifier:general; 401, identifier:trimmedfastqfiles; 402, conditional_expression:if; 402, 403; 402, 404; 402, 405; 403, identifier:trimmedfastqfiles; 404, identifier:trimmedfastqfiles; 405, call; 405, 406; 405, 407; 406, identifier:list; 407, argument_list; 408, comment; 409, expression_statement; 409, 410; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:logging; 413, identifier:info; 414, argument_list; 414, 415; 415, string:'Fastq files trimmed' | def trimquality(self):
"""Uses bbduk from the bbmap tool suite to quality and adapter trim"""
logging.info("Trimming fastq files")
# Iterate through strains with fastq files
with progressbar(self.metadata) as bar:
for sample in bar:
# As the metadata can be populated with 'NA' (string) if there are no fastq files, only process if
# :fastqfiles is a list
if type(sample.general.fastqfiles) is list:
# Check to see if the fastq files exist
fastqfiles = sorted(sample.general.fastqfiles)
# Define the output directory
outputdir = sample.general.outputdirectory
# Define the name of the trimmed fastq files
cleanforward = os.path.join(outputdir, '{}_R1_trimmed.fastq.gz'.format(sample.name))
cleanreverse = os.path.join(outputdir, '{}_R2_trimmed.fastq.gz'.format(sample.name))
# Incorporate read length into the minlength parameter - set it to 50 unless one or more of the
# reads has a lower calculated length than 50
try:
lesser_length = min(int(sample.run.forwardlength), int(sample.run.reverselength))
except ValueError:
lesser_length = int(sample.run.forwardlength)
min_len = 50 if lesser_length >= 50 else lesser_length
# Initialise a variable to store the number of bases to automatically trim from the beginning of
# each read, as these bases tend to have lower quality scores. If trimming the reads will cause
trim_left = 0
# If, for some reason, only the reverse reads are present, use the appropriate output file name
try:
if 'R2' in fastqfiles[0]:
if not os.path.isfile(cleanreverse):
out, \
err, \
bbdukcall = bbtools.bbduk_trim(forward_in=fastqfiles[0],
reverse_in=None,
forward_out=cleanreverse,
trimq=10,
minlength=min_len,
forcetrimleft=trim_left,
returncmd=True)
else:
bbdukcall = str()
out = str()
err = str()
else:
if not os.path.isfile(cleanforward):
out, \
err, \
bbdukcall = bbtools.bbduk_trim(forward_in=fastqfiles[0],
forward_out=cleanforward,
trimq=10,
minlength=min_len,
forcetrimleft=trim_left,
returncmd=True)
else:
bbdukcall = str()
out = str()
err = str()
except (IndexError, CalledProcessError):
bbdukcall = str()
out = str()
err = str()
# Write the command, stdout, and stderr to the logfile
write_to_logfile(bbdukcall, bbdukcall, self.logfile, sample.general.logout, sample.general.logerr,
None, None)
write_to_logfile(out, err, self.logfile, sample.general.logout, sample.general.logerr, None, None)
# Add the trimmed fastq files to a list
trimmedfastqfiles = sorted(glob(os.path.join(sample.general.outputdirectory, '*trimmed.fastq.gz')))
# Populate the metadata if the files exist
sample.general.trimmedfastqfiles = trimmedfastqfiles if trimmedfastqfiles else list()
# Add all the trimmed files to the metadata
logging.info('Fastq files trimmed') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:contamination_finder; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:input_path; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:report_path; 10, None; 11, block; 11, 12; 11, 14; 11, 21; 11, 38; 11, 61; 11, 74; 11, 86; 11, 87; 11, 199; 11, 200; 11, 201; 11, 219; 11, 220; 11, 410; 11, 411; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:logging; 18, identifier:info; 19, argument_list; 19, 20; 20, string:'Calculating contamination in reads'; 21, if_statement; 21, 22; 21, 25; 21, 30; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:input_path; 24, None; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:input_dir; 29, identifier:input_path; 30, else_clause; 30, 31; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:input_dir; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:path; 38, if_statement; 38, 39; 38, 42; 38, 47; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:report_path; 41, None; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:reportpath; 46, identifier:report_path; 47, else_clause; 47, 48; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:reportpath; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:os; 56, identifier:path; 57, identifier:join; 58, argument_list; 58, 59; 58, 60; 59, identifier:input_dir; 60, string:'confindr'; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:confindr_report; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:os; 68, identifier:path; 69, identifier:join; 70, argument_list; 70, 71; 70, 72; 70, 73; 71, identifier:input_dir; 72, string:'confindr'; 73, string:'confindr_report.csv'; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:pipeline_report; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:os; 81, identifier:path; 82, identifier:join; 83, argument_list; 83, 84; 83, 85; 84, identifier:reportpath; 85, string:'confindr_report.csv'; 86, comment; 87, if_statement; 87, 88; 87, 97; 87, 98; 87, 99; 88, not_operator; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:isfile; 95, argument_list; 95, 96; 96, identifier:confindr_report; 97, comment; 98, comment; 99, block; 99, 100; 99, 113; 99, 118; 99, 119; 99, 156; 99, 157; 99, 166; 99, 179; 99, 192; 100, try_statement; 100, 101; 100, 109; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:shutil; 106, identifier:rmtree; 107, argument_list; 107, 108; 108, identifier:reportpath; 109, except_clause; 109, 110; 109, 111; 110, identifier:IOError; 111, block; 111, 112; 112, pass_statement; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:make_path; 116, argument_list; 116, 117; 117, identifier:reportpath; 118, comment; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:systemcall; 122, call; 122, 123; 122, 127; 123, attribute; 123, 124; 123, 125; 123, 126; 124, string:'confindr.py -i {input_dir} -o {output_dir} -d {database_dir} -bf 0.05'; 125, line_continuation:\; 126, identifier:format; 127, argument_list; 127, 128; 127, 131; 127, 142; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:input_dir; 130, identifier:input_dir; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:output_dir; 133, call; 133, 134; 133, 139; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:os; 137, identifier:path; 138, identifier:join; 139, argument_list; 139, 140; 139, 141; 140, identifier:input_dir; 141, string:'confindr'; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:database_dir; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:os; 148, identifier:path; 149, identifier:join; 150, argument_list; 150, 151; 150, 154; 150, 155; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:reffilepath; 154, string:'ConFindr'; 155, string:'databases'; 156, comment; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, pattern_list; 159, 160; 159, 161; 160, identifier:out; 161, identifier:err; 162, call; 162, 163; 162, 164; 163, identifier:run_subprocess; 164, argument_list; 164, 165; 165, identifier:systemcall; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:write_to_logfile; 169, argument_list; 169, 170; 169, 171; 169, 172; 169, 175; 169, 176; 169, 177; 169, 178; 170, identifier:systemcall; 171, identifier:systemcall; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:logfile; 175, None; 176, None; 177, None; 178, None; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:write_to_logfile; 182, argument_list; 182, 183; 182, 184; 182, 185; 182, 188; 182, 189; 182, 190; 182, 191; 183, identifier:out; 184, identifier:err; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:logfile; 188, None; 189, None; 190, None; 191, None; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:logging; 196, identifier:info; 197, argument_list; 197, 198; 198, string:'Contamination detection complete!'; 199, comment; 200, comment; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:confindr_results; 204, call; 204, 205; 204, 218; 205, attribute; 205, 206; 205, 217; 206, attribute; 206, 207; 206, 216; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:pandas; 210, identifier:read_csv; 211, argument_list; 211, 212; 211, 213; 212, identifier:confindr_report; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:index_col; 215, integer:0; 216, identifier:T; 217, identifier:to_dict; 218, argument_list; 219, comment; 220, for_statement; 220, 221; 220, 222; 220, 225; 220, 226; 221, identifier:sample; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:metadata; 225, comment; 226, block; 226, 227; 226, 235; 226, 236; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:sample; 231, identifier:confindr; 232, call; 232, 233; 232, 234; 233, identifier:GenObject; 234, argument_list; 235, comment; 236, for_statement; 236, 237; 236, 238; 236, 239; 236, 240; 237, identifier:line; 238, identifier:confindr_results; 239, comment; 240, block; 240, 241; 241, if_statement; 241, 242; 241, 247; 241, 248; 242, comparison_operator:in; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:sample; 245, identifier:name; 246, identifier:line; 247, comment; 248, block; 248, 249; 248, 274; 248, 286; 248, 298; 248, 299; 248, 337; 248, 376; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 256; 251, attribute; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:sample; 254, identifier:confindr; 255, identifier:genus; 256, conditional_expression:if; 256, 257; 256, 262; 256, 273; 257, subscript; 257, 258; 257, 261; 258, subscript; 258, 259; 258, 260; 259, identifier:confindr_results; 260, identifier:line; 261, string:'Genus'; 262, comparison_operator:is; 262, 263; 262, 271; 262, 272; 263, call; 263, 264; 263, 265; 264, identifier:type; 265, argument_list; 265, 266; 266, subscript; 266, 267; 266, 270; 267, subscript; 267, 268; 267, 269; 268, identifier:confindr_results; 269, identifier:line; 270, string:'Genus'; 271, line_continuation:\; 272, identifier:float; 273, string:'ND'; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 281; 276, attribute; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:sample; 279, identifier:confindr; 280, identifier:num_contaminated_snvs; 281, subscript; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:confindr_results; 284, identifier:line; 285, string:'NumContamSNVs'; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 293; 288, attribute; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:sample; 291, identifier:confindr; 292, identifier:contam_status; 293, subscript; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:confindr_results; 296, identifier:line; 297, string:'ContamStatus'; 298, comment; 299, try_statement; 299, 300; 299, 326; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 308; 303, attribute; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:sample; 306, identifier:confindr; 307, identifier:percent_contam; 308, conditional_expression:if; 308, 309; 308, 314; 308, 315; 308, 325; 309, subscript; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:confindr_results; 312, identifier:line; 313, string:'PercentContam'; 314, line_continuation:\; 315, comparison_operator:!=; 315, 316; 315, 324; 316, call; 316, 317; 316, 318; 317, identifier:str; 318, argument_list; 318, 319; 319, subscript; 319, 320; 319, 323; 320, subscript; 320, 321; 320, 322; 321, identifier:confindr_results; 322, identifier:line; 323, string:'PercentContam'; 324, string:'nan'; 325, integer:0; 326, except_clause; 326, 327; 326, 328; 327, identifier:KeyError; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 336; 331, attribute; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:sample; 334, identifier:confindr; 335, identifier:percent_contam; 336, string:'ND'; 337, try_statement; 337, 338; 337, 365; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 346; 340, 347; 341, attribute; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:sample; 344, identifier:confindr; 345, identifier:percent_contam_std; 346, line_continuation:\; 347, conditional_expression:if; 347, 348; 347, 353; 347, 354; 347, 364; 348, subscript; 348, 349; 348, 352; 349, subscript; 349, 350; 349, 351; 350, identifier:confindr_results; 351, identifier:line; 352, string:'PercentContamStandardDeviation'; 353, line_continuation:\; 354, comparison_operator:!=; 354, 355; 354, 363; 355, call; 355, 356; 355, 357; 356, identifier:str; 357, argument_list; 357, 358; 358, subscript; 358, 359; 358, 362; 359, subscript; 359, 360; 359, 361; 360, identifier:confindr_results; 361, identifier:line; 362, string:'PercentContamStandardDeviation'; 363, string:'nan'; 364, integer:0; 365, except_clause; 365, 366; 365, 367; 366, identifier:KeyError; 367, block; 367, 368; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 375; 370, attribute; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:sample; 373, identifier:confindr; 374, identifier:percent_contam_std; 375, string:'ND'; 376, if_statement; 376, 377; 376, 384; 376, 393; 377, comparison_operator:is; 377, 378; 377, 383; 378, attribute; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:sample; 381, identifier:confindr; 382, identifier:contam_status; 383, True; 384, block; 384, 385; 385, expression_statement; 385, 386; 386, assignment; 386, 387; 386, 392; 387, attribute; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:sample; 390, identifier:confindr; 391, identifier:contam_status; 392, string:'Contaminated'; 393, elif_clause; 393, 394; 393, 401; 394, comparison_operator:is; 394, 395; 394, 400; 395, attribute; 395, 396; 395, 399; 396, attribute; 396, 397; 396, 398; 397, identifier:sample; 398, identifier:confindr; 399, identifier:contam_status; 400, False; 401, block; 401, 402; 402, expression_statement; 402, 403; 403, assignment; 403, 404; 403, 409; 404, attribute; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, identifier:sample; 407, identifier:confindr; 408, identifier:contam_status; 409, string:'Clean'; 410, comment; 411, with_statement; 411, 412; 411, 422; 412, with_clause; 412, 413; 413, with_item; 413, 414; 414, as_pattern; 414, 415; 414, 420; 415, call; 415, 416; 415, 417; 416, identifier:open; 417, argument_list; 417, 418; 417, 419; 418, identifier:pipeline_report; 419, string:'w'; 420, as_pattern_target; 420, 421; 421, identifier:csv; 422, block; 422, 423; 422, 427; 422, 481; 423, expression_statement; 423, 424; 424, assignment; 424, 425; 424, 426; 425, identifier:data; 426, string:'Strain,Genus,NumContamSNVs,ContamStatus,PercentContam,PercentContamSTD\n'; 427, for_statement; 427, 428; 427, 429; 427, 432; 428, identifier:sample; 429, attribute; 429, 430; 429, 431; 430, identifier:self; 431, identifier:metadata; 432, block; 432, 433; 433, expression_statement; 433, 434; 434, augmented_assignment:+=; 434, 435; 434, 436; 435, identifier:data; 436, call; 436, 437; 436, 440; 437, attribute; 437, 438; 437, 439; 438, string:'{str},{genus},{numcontamsnv},{status},{pc},{pcs}\n'; 439, identifier:format; 440, argument_list; 440, 441; 440, 446; 440, 453; 440, 460; 440, 467; 440, 474; 441, keyword_argument; 441, 442; 441, 443; 442, identifier:str; 443, attribute; 443, 444; 443, 445; 444, identifier:sample; 445, identifier:name; 446, keyword_argument; 446, 447; 446, 448; 447, identifier:genus; 448, attribute; 448, 449; 448, 452; 449, attribute; 449, 450; 449, 451; 450, identifier:sample; 451, identifier:confindr; 452, identifier:genus; 453, keyword_argument; 453, 454; 453, 455; 454, identifier:numcontamsnv; 455, attribute; 455, 456; 455, 459; 456, attribute; 456, 457; 456, 458; 457, identifier:sample; 458, identifier:confindr; 459, identifier:num_contaminated_snvs; 460, keyword_argument; 460, 461; 460, 462; 461, identifier:status; 462, attribute; 462, 463; 462, 466; 463, attribute; 463, 464; 463, 465; 464, identifier:sample; 465, identifier:confindr; 466, identifier:contam_status; 467, keyword_argument; 467, 468; 467, 469; 468, identifier:pc; 469, attribute; 469, 470; 469, 473; 470, attribute; 470, 471; 470, 472; 471, identifier:sample; 472, identifier:confindr; 473, identifier:percent_contam; 474, keyword_argument; 474, 475; 474, 476; 475, identifier:pcs; 476, attribute; 476, 477; 476, 480; 477, attribute; 477, 478; 477, 479; 478, identifier:sample; 479, identifier:confindr; 480, identifier:percent_contam_std; 481, expression_statement; 481, 482; 482, call; 482, 483; 482, 486; 483, attribute; 483, 484; 483, 485; 484, identifier:csv; 485, identifier:write; 486, argument_list; 486, 487; 487, identifier:data | def contamination_finder(self, input_path=None, report_path=None):
"""
Helper function to get confindr integrated into the assembly pipeline
"""
logging.info('Calculating contamination in reads')
if input_path is not None:
input_dir = input_path
else:
input_dir = self.path
if report_path is not None:
reportpath = report_path
else:
reportpath = os.path.join(input_dir, 'confindr')
confindr_report = os.path.join(input_dir, 'confindr', 'confindr_report.csv')
pipeline_report = os.path.join(reportpath, 'confindr_report.csv')
# Only proceed if the confindr report doesn't exist
if not os.path.isfile(confindr_report):
# # Create an object to store attributes to pass to confinder
# Clear and recreate the output folder
try:
shutil.rmtree(reportpath)
except IOError:
pass
make_path(reportpath)
# Run confindr
systemcall = 'confindr.py -i {input_dir} -o {output_dir} -d {database_dir} -bf 0.05'\
.format(input_dir=input_dir,
output_dir=os.path.join(input_dir, 'confindr'),
database_dir=os.path.join(self.reffilepath, 'ConFindr', 'databases'))
# Run the call
out, err = run_subprocess(systemcall)
write_to_logfile(systemcall, systemcall, self.logfile, None, None, None, None)
write_to_logfile(out, err, self.logfile, None, None, None, None)
logging.info('Contamination detection complete!')
# Load the confindr report into a dictionary using pandas
# https://stackoverflow.com/questions/33620982/reading-csv-file-as-dictionary-using-pandas
confindr_results = pandas.read_csv(confindr_report, index_col=0).T.to_dict()
# Find the results for each of the samples
for sample in self.metadata:
# Create a GenObject to store the results
sample.confindr = GenObject()
# Iterate through the dictionary to find the outputs for each sample
for line in confindr_results:
# If the current line corresponds to the sample of interest
if sample.name in line:
# Set the values using the appropriate keys as the attributes
sample.confindr.genus = confindr_results[line]['Genus'] if type(confindr_results[line]['Genus']) \
is not float else 'ND'
sample.confindr.num_contaminated_snvs = confindr_results[line]['NumContamSNVs']
sample.confindr.contam_status = confindr_results[line]['ContamStatus']
# Don't break parsing previous ConFindr reports that lack the percent contamination calculations
try:
sample.confindr.percent_contam = confindr_results[line]['PercentContam'] if \
str(confindr_results[line]['PercentContam']) != 'nan' else 0
except KeyError:
sample.confindr.percent_contam = 'ND'
try:
sample.confindr.percent_contam_std = \
confindr_results[line]['PercentContamStandardDeviation'] if \
str(confindr_results[line]['PercentContamStandardDeviation']) != 'nan' else 0
except KeyError:
sample.confindr.percent_contam_std = 'ND'
if sample.confindr.contam_status is True:
sample.confindr.contam_status = 'Contaminated'
elif sample.confindr.contam_status is False:
sample.confindr.contam_status = 'Clean'
# Re-write the output to be consistent with the rest of the pipeline
with open(pipeline_report, 'w') as csv:
data = 'Strain,Genus,NumContamSNVs,ContamStatus,PercentContam,PercentContamSTD\n'
for sample in self.metadata:
data += '{str},{genus},{numcontamsnv},{status},{pc},{pcs}\n'.format(
str=sample.name,
genus=sample.confindr.genus,
numcontamsnv=sample.confindr.num_contaminated_snvs,
status=sample.confindr.contam_status,
pc=sample.confindr.percent_contam,
pcs=sample.confindr.percent_contam_std
)
csv.write(data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:subclass_genesis; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:genesisclass; 6, block; 6, 7; 6, 9; 6, 478; 6, 489; 7, expression_statement; 7, 8; 8, comment; 9, class_definition; 9, 10; 9, 11; 9, 13; 10, identifier:MayaGenesisWin; 11, argument_list; 11, 12; 12, identifier:genesisclass; 13, block; 13, 14; 13, 16; 13, 31; 13, 54; 13, 69; 13, 92; 13, 160; 13, 203; 13, 268; 13, 332; 13, 384; 14, expression_statement; 14, 15; 15, comment; 16, function_definition; 16, 17; 16, 18; 16, 21; 17, function_name:open_shot; 18, parameters; 18, 19; 18, 20; 19, identifier:self; 20, identifier:taskfile; 21, block; 21, 22; 21, 24; 22, expression_statement; 22, 23; 23, comment; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:open_file; 29, argument_list; 29, 30; 30, identifier:taskfile; 31, function_definition; 31, 32; 31, 33; 31, 37; 32, function_name:save_shot; 33, parameters; 33, 34; 33, 35; 33, 36; 34, identifier:self; 35, identifier:jbfile; 36, identifier:tf; 37, block; 37, 38; 37, 40; 37, 47; 38, expression_statement; 38, 39; 39, comment; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:update_scene_node; 45, argument_list; 45, 46; 46, identifier:tf; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:save_file; 52, argument_list; 52, 53; 53, identifier:jbfile; 54, function_definition; 54, 55; 54, 56; 54, 59; 55, function_name:open_asset; 56, parameters; 56, 57; 56, 58; 57, identifier:self; 58, identifier:taskfile; 59, block; 59, 60; 59, 62; 60, expression_statement; 60, 61; 61, comment; 62, return_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:open_file; 67, argument_list; 67, 68; 68, identifier:taskfile; 69, function_definition; 69, 70; 69, 71; 69, 75; 70, function_name:save_asset; 71, parameters; 71, 72; 71, 73; 71, 74; 72, identifier:self; 73, identifier:jbfile; 74, identifier:tf; 75, block; 75, 76; 75, 78; 75, 85; 76, expression_statement; 76, 77; 77, comment; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:update_scene_node; 83, argument_list; 83, 84; 84, identifier:tf; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:save_file; 90, argument_list; 90, 91; 91, identifier:jbfile; 92, function_definition; 92, 93; 92, 94; 92, 97; 93, function_name:save_file; 94, parameters; 94, 95; 94, 96; 95, identifier:self; 96, identifier:jbfile; 97, block; 97, 98; 97, 100; 97, 108; 97, 119; 97, 123; 97, 136; 97, 145; 98, expression_statement; 98, 99; 99, comment; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:p; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:jbfile; 106, identifier:get_fullpath; 107, argument_list; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:p; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:os; 115, identifier:path; 116, identifier:expanduser; 117, argument_list; 117, 118; 118, identifier:p; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:typ; 122, string:'mayaBinary'; 123, if_statement; 123, 124; 123, 131; 124, comparison_operator:==; 124, 125; 124, 130; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:jbfile; 128, identifier:get_ext; 129, argument_list; 130, string:'ma'; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:typ; 135, string:'mayaAscii'; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:cmds; 140, identifier:file; 141, argument_list; 141, 142; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:rename; 144, identifier:p; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:cmds; 149, identifier:file; 150, argument_list; 150, 151; 150, 154; 150, 157; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:save; 153, True; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:defaultExtensions; 156, False; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:type; 159, identifier:typ; 160, function_definition; 160, 161; 160, 162; 160, 165; 161, function_name:open_file; 162, parameters; 162, 163; 162, 164; 163, identifier:self; 164, identifier:taskfile; 165, block; 165, 166; 165, 168; 165, 176; 165, 183; 165, 201; 166, expression_statement; 166, 167; 167, comment; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:r; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:check_modified; 175, argument_list; 176, if_statement; 176, 177; 176, 180; 177, comparison_operator:is; 177, 178; 177, 179; 178, identifier:r; 179, False; 180, block; 180, 181; 181, return_statement; 181, 182; 182, False; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:cmds; 187, identifier:file; 188, argument_list; 188, 189; 188, 192; 188, 195; 188, 198; 189, attribute; 189, 190; 189, 191; 190, identifier:taskfile; 191, identifier:path; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:open; 194, True; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:force; 197, True; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:ignoreVersion; 200, True; 201, return_statement; 201, 202; 202, True; 203, function_definition; 203, 204; 203, 205; 203, 207; 204, function_name:get_current_file; 205, parameters; 205, 206; 206, identifier:self; 207, block; 207, 208; 207, 210; 207, 218; 207, 223; 207, 234; 208, expression_statement; 208, 209; 209, comment; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:node; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:jbscene; 216, identifier:get_current_scene_node; 217, argument_list; 218, if_statement; 218, 219; 218, 221; 219, not_operator; 219, 220; 220, identifier:node; 221, block; 221, 222; 222, return_statement; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:tfid; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:cmds; 229, identifier:getAttr; 230, argument_list; 230, 231; 231, binary_operator:%; 231, 232; 231, 233; 232, string:'%s.taskfile_id'; 233, identifier:node; 234, try_statement; 234, 235; 234, 247; 235, block; 235, 236; 236, return_statement; 236, 237; 237, call; 237, 238; 237, 243; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:djadapter; 241, identifier:taskfiles; 242, identifier:get; 243, argument_list; 243, 244; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:id; 246, identifier:tfid; 247, except_clause; 247, 248; 247, 255; 248, attribute; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:djadapter; 252, identifier:models; 253, identifier:TaskFile; 254, identifier:DoesNotExist; 255, block; 255, 256; 255, 267; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:log; 260, identifier:error; 261, argument_list; 261, 262; 262, binary_operator:%; 262, 263; 262, 264; 263, string:"No taskfile with id %s was found. Get current scene failed. Check your jb_sceneNode \'%s\'."; 264, tuple; 264, 265; 264, 266; 265, identifier:tfid; 266, identifier:node; 267, return_statement; 268, function_definition; 268, 269; 268, 270; 268, 272; 269, function_name:get_scene_node; 270, parameters; 270, 271; 271, identifier:self; 272, block; 272, 273; 272, 275; 272, 284; 272, 299; 272, 307; 272, 330; 273, expression_statement; 273, 274; 274, comment; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:scenenodes; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:cmds; 281, identifier:ls; 282, argument_list; 282, 283; 283, string:':jb_sceneNode*'; 284, if_statement; 284, 285; 284, 291; 285, comparison_operator:>; 285, 286; 285, 290; 286, call; 286, 287; 286, 288; 287, identifier:len; 288, argument_list; 288, 289; 289, identifier:scenenodes; 290, integer:1; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:cmds; 296, identifier:delete; 297, argument_list; 297, 298; 298, identifier:scenenodes; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:node; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:jbscene; 305, identifier:get_current_scene_node; 306, argument_list; 307, if_statement; 307, 308; 307, 311; 308, comparison_operator:is; 308, 309; 308, 310; 309, identifier:node; 310, None; 311, block; 311, 312; 311, 321; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:cmds; 316, identifier:namespace; 317, argument_list; 317, 318; 318, keyword_argument; 318, 319; 318, 320; 319, identifier:set; 320, string:':'; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:node; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:cmds; 327, identifier:createNode; 328, argument_list; 328, 329; 329, string:'jb_sceneNode'; 330, return_statement; 330, 331; 331, identifier:node; 332, function_definition; 332, 333; 332, 334; 332, 337; 333, function_name:update_scene_node; 334, parameters; 334, 335; 334, 336; 335, identifier:self; 336, identifier:tf; 337, block; 337, 338; 337, 340; 337, 348; 337, 360; 337, 372; 338, expression_statement; 338, 339; 339, comment; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:node; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:self; 346, identifier:get_scene_node; 347, argument_list; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:cmds; 352, identifier:setAttr; 353, argument_list; 353, 354; 353, 357; 354, binary_operator:%; 354, 355; 354, 356; 355, string:'%s.taskfile_id'; 356, identifier:node; 357, keyword_argument; 357, 358; 357, 359; 358, identifier:lock; 359, False; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:cmds; 364, identifier:setAttr; 365, argument_list; 365, 366; 365, 369; 366, binary_operator:%; 366, 367; 366, 368; 367, string:'%s.taskfile_id'; 368, identifier:node; 369, attribute; 369, 370; 369, 371; 370, identifier:tf; 371, identifier:id; 372, expression_statement; 372, 373; 373, call; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:cmds; 376, identifier:setAttr; 377, argument_list; 377, 378; 377, 381; 378, binary_operator:%; 378, 379; 378, 380; 379, string:'%s.taskfile_id'; 380, identifier:node; 381, keyword_argument; 381, 382; 381, 383; 382, identifier:lock; 383, True; 384, function_definition; 384, 385; 384, 386; 384, 388; 385, function_name:check_modified; 386, parameters; 386, 387; 387, identifier:self; 388, block; 388, 389; 388, 391; 388, 407; 388, 421; 388, 452; 388, 459; 388, 476; 389, expression_statement; 389, 390; 390, comment; 391, if_statement; 391, 392; 391, 404; 392, not_operator; 392, 393; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:cmds; 396, identifier:file; 397, argument_list; 397, 398; 397, 401; 398, keyword_argument; 398, 399; 398, 400; 399, identifier:q; 400, integer:1; 401, keyword_argument; 401, 402; 401, 403; 402, identifier:modified; 403, integer:1; 404, block; 404, 405; 405, return_statement; 405, 406; 406, True; 407, expression_statement; 407, 408; 408, assignment; 408, 409; 408, 410; 409, identifier:curfile; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:cmds; 413, identifier:file; 414, argument_list; 414, 415; 414, 418; 415, keyword_argument; 415, 416; 415, 417; 416, identifier:q; 417, integer:1; 418, keyword_argument; 418, 419; 418, 420; 419, identifier:sceneName; 420, integer:1; 421, expression_statement; 421, 422; 422, assignment; 422, 423; 422, 424; 423, identifier:r; 424, call; 424, 425; 424, 428; 425, attribute; 425, 426; 425, 427; 426, identifier:cmds; 427, identifier:confirmDialog; 428, argument_list; 428, 429; 428, 432; 428, 437; 428, 443; 428, 446; 428, 449; 429, keyword_argument; 429, 430; 429, 431; 430, identifier:title; 431, string:'Save Changes'; 432, keyword_argument; 432, 433; 432, 434; 433, identifier:message; 434, binary_operator:%; 434, 435; 434, 436; 435, string:'Save changes to %s?'; 436, identifier:curfile; 437, keyword_argument; 437, 438; 437, 439; 438, identifier:button; 439, list:['Save', 'Don\'t Save' ,'Cancel']; 439, 440; 439, 441; 439, 442; 440, string:'Save'; 441, string:'Don\'t Save'; 442, string:'Cancel'; 443, keyword_argument; 443, 444; 443, 445; 444, identifier:defaultButton; 445, string:'Save'; 446, keyword_argument; 446, 447; 446, 448; 447, identifier:cancelButton; 448, string:'Cancel'; 449, keyword_argument; 449, 450; 449, 451; 450, identifier:dismissString; 451, string:'Cancel'; 452, if_statement; 452, 453; 452, 456; 453, comparison_operator:==; 453, 454; 453, 455; 454, identifier:r; 455, string:'Cancel'; 456, block; 456, 457; 457, return_statement; 457, 458; 458, False; 459, if_statement; 459, 460; 459, 463; 460, comparison_operator:==; 460, 461; 460, 462; 461, identifier:r; 462, string:'Save'; 463, block; 463, 464; 464, expression_statement; 464, 465; 465, call; 465, 466; 465, 469; 466, attribute; 466, 467; 466, 468; 467, identifier:cmds; 468, identifier:file; 469, argument_list; 469, 470; 469, 473; 470, keyword_argument; 470, 471; 470, 472; 471, identifier:save; 472, True; 473, keyword_argument; 473, 474; 473, 475; 474, identifier:force; 475, True; 476, return_statement; 476, 477; 477, True; 478, expression_statement; 478, 479; 479, call; 479, 480; 479, 483; 480, attribute; 480, 481; 480, 482; 481, identifier:MayaGenesisWin; 482, identifier:set_filetype; 483, argument_list; 483, 484; 484, subscript; 484, 485; 484, 488; 485, attribute; 485, 486; 485, 487; 486, identifier:djadapter; 487, identifier:FILETYPES; 488, string:'mayamainscene'; 489, return_statement; 489, 490; 490, identifier:MayaGenesisWin | def subclass_genesis(self, genesisclass):
"""Subclass the given genesis class and implement all abstract methods
:param genesisclass: the GenesisWin class to subclass
:type genesisclass: :class:`GenesisWin`
:returns: the subclass
:rtype: subclass of :class:`GenesisWin`
:raises: None
"""
class MayaGenesisWin(genesisclass):
"""Implementation of Genesis for maya
"""
def open_shot(self, taskfile):
"""Open the given taskfile
:param taskfile: the taskfile for the shot
:type taskfile: :class:`djadapter.models.TaskFile`
:returns: True if opening was successful
:rtype: bool
:raises: none
"""
return self.open_file(taskfile)
def save_shot(self, jbfile, tf):
"""Save the shot to the location of jbfile
:param jbfile: the jbfile that can be used to query the location
:type jbfile: :class:`jukebox.core.filesys.JB_File`
:param tf: the taskfile that is saved
:type tf: :class:`djadapter.models.TaskFile`
:returns: None
:rtype: None
:raises: None
"""
self.update_scene_node(tf)
self.save_file(jbfile)
def open_asset(self, taskfile):
"""Open the given taskfile
:param taskfile: the taskfile for the asset
:type taskfile: :class:`djadapter.models.TaskFile`
:returns: True if opening was successful
:rtype: bool
:raises: None
"""
return self.open_file(taskfile)
def save_asset(self, jbfile, tf):
"""Save the asset to the location of jbfile
:param jbfile: the jbfile that can be used to query the location
:type jbfile: :class:`jukebox.core.filesys.JB_File`
:param tf: the taskfile that is saved
:type tf: :class:`djadapter.models.TaskFile`
:returns: None
:rtype: None
:raises: NotImplementedError
"""
self.update_scene_node(tf)
self.save_file(jbfile)
def save_file(self, jbfile):
"""Physically save current scene to jbfile\'s location
:param jbfile: the jbfile that can be used to query the location
:type jbfile: :class:`jukebox.core.filesys.JB_File`
:returns: None
:rtype: None
:raises: None
"""
p = jbfile.get_fullpath()
p = os.path.expanduser(p)
typ = 'mayaBinary'
if jbfile.get_ext() == 'ma':
typ = 'mayaAscii'
cmds.file(rename = p)
cmds.file(save=True, defaultExtensions=False, type=typ)
def open_file(self, taskfile):
"""Open the given jbfile in maya
:param taskfile: the taskfile for the asset
:type taskfile: :class:`djadapter.models.TaskFile`
:returns: True if opening was successful
:rtype: bool
:raises: None
"""
r = self.check_modified()
if r is False:
return False
cmds.file(taskfile.path, open=True, force=True, ignoreVersion=True)
return True
def get_current_file(self, ):
"""Return the taskfile that is currently open or None if no taskfile is open
:returns: the open taskfile or None if no taskfile is open
:rtype: :class:`djadapter.models.TaskFile` | None
:raises: None
"""
node = jbscene.get_current_scene_node()
if not node:
return
tfid = cmds.getAttr('%s.taskfile_id' % node)
try:
return djadapter.taskfiles.get(id=tfid)
except djadapter.models.TaskFile.DoesNotExist:
log.error("No taskfile with id %s was found. Get current scene failed. Check your jb_sceneNode \'%s\'." % (tfid, node))
return
def get_scene_node(self, ):
"""Return the current scenen node or create one if it does not exist
:returns: Name of the scene node
:rtype: str
:raises: None
"""
scenenodes = cmds.ls(':jb_sceneNode*')
if len(scenenodes) > 1:
cmds.delete(scenenodes)
node = jbscene.get_current_scene_node()
if node is None:
cmds.namespace(set=':')
node = cmds.createNode('jb_sceneNode')
return node
def update_scene_node(self, tf):
"""Update the current scene node
:param tf: the taskfile that is saved
:type tf: :class:`djadapter.models.TaskFile`
:returns: None
:rtype: None
:raises: None
"""
node = self.get_scene_node()
cmds.setAttr('%s.taskfile_id' % node, lock=False)
cmds.setAttr('%s.taskfile_id' % node, tf.id)
cmds.setAttr('%s.taskfile_id' % node, lock=True)
def check_modified(self, ):
"""Check if the current scene was modified and ask the user to continue
This might save the scene if the user accepts to save before continuing.
:returns: True if the user accepted to continue.
:rtype: bool
:raises: None
"""
if not cmds.file(q=1, modified=1):
return True
curfile = cmds.file(q=1, sceneName=1)
r = cmds.confirmDialog( title='Save Changes', message='Save changes to %s?' % curfile,
button=['Save', 'Don\'t Save' ,'Cancel'],
defaultButton='Save', cancelButton='Cancel',
dismissString='Cancel')
if r == 'Cancel':
return False
if r == 'Save':
cmds.file(save=True, force=True)
return True
MayaGenesisWin.set_filetype(djadapter.FILETYPES['mayamainscene'],)
return MayaGenesisWin |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 1, 37; 2, function_name:override_options; 3, parameters; 3, 4; 3, 8; 3, 18; 3, 30; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:config; 6, type; 6, 7; 7, identifier:DictLike; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:selected_options; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:Tuple; 13, type_parameter; 13, 14; 13, 16; 14, type; 14, 15; 15, identifier:Any; 16, type; 16, 17; 17, ellipsis:...; 18, typed_parameter; 18, 19; 18, 20; 19, identifier:set_of_possible_options; 20, type; 20, 21; 21, generic_type; 21, 22; 21, 23; 22, identifier:Tuple; 23, type_parameter; 23, 24; 23, 28; 24, type; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:enum; 27, identifier:Enum; 28, type; 28, 29; 29, ellipsis:...; 30, typed_default_parameter; 30, 31; 30, 32; 30, 34; 31, identifier:config_containing_override; 32, type; 32, 33; 33, identifier:DictLike; 34, None; 35, type; 35, 36; 36, identifier:DictLike; 37, block; 37, 38; 37, 40; 37, 49; 37, 58; 37, 67; 37, 74; 37, 75; 37, 76; 37, 255; 38, expression_statement; 38, 39; 39, comment; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:config_containing_override; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:config_containing_override; 48, identifier:config; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:override_opts; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:config_containing_override; 55, identifier:pop; 56, argument_list; 56, 57; 57, string:"override"; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:override_dict; 61, call; 61, 62; 61, 63; 62, identifier:determine_override_options; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, identifier:selected_options; 65, identifier:override_opts; 66, identifier:set_of_possible_options; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:logger; 71, identifier:debug; 72, argument_list; 72, 73; 73, string:f"override_dict: {override_dict}"; 74, comment; 75, comment; 76, for_statement; 76, 77; 76, 80; 76, 85; 76, 86; 77, pattern_list; 77, 78; 77, 79; 78, identifier:k; 79, identifier:v; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:override_dict; 83, identifier:items; 84, argument_list; 85, comment; 86, block; 86, 87; 87, if_statement; 87, 88; 87, 91; 87, 247; 88, comparison_operator:in; 88, 89; 88, 90; 89, identifier:k; 90, identifier:config; 91, block; 91, 92; 92, try_statement; 92, 93; 92, 94; 92, 95; 92, 96; 92, 97; 92, 237; 93, comment; 94, comment; 95, comment; 96, comment; 97, block; 97, 98; 97, 104; 97, 111; 98, expression_statement; 98, 99; 99, attribute; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:config; 102, identifier:k; 103, identifier:anchor; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:logger; 108, identifier:debug; 109, argument_list; 109, 110; 110, string:f"type: {type(config[k])}, k: {k}"; 111, if_statement; 111, 112; 111, 119; 111, 120; 111, 172; 111, 202; 111, 229; 112, call; 112, 113; 112, 114; 113, identifier:isinstance; 114, argument_list; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:config; 117, identifier:k; 118, identifier:list; 119, comment; 120, block; 120, 121; 120, 128; 121, delete_statement; 121, 122; 122, subscript; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:config; 125, identifier:k; 126, slice; 126, 127; 127, colon; 128, if_statement; 128, 129; 128, 140; 128, 141; 128, 142; 128, 143; 128, 144; 128, 145; 128, 146; 128, 158; 129, call; 129, 130; 129, 131; 130, identifier:isinstance; 131, argument_list; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:override_dict; 134, identifier:k; 135, tuple; 135, 136; 135, 137; 135, 138; 135, 139; 136, identifier:str; 137, identifier:int; 138, identifier:float; 139, identifier:bool; 140, comment; 141, comment; 142, comment; 143, comment; 144, comment; 145, comment; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:config; 152, identifier:k; 153, identifier:append; 154, argument_list; 154, 155; 155, subscript; 155, 156; 155, 157; 156, identifier:override_dict; 157, identifier:k; 158, else_clause; 158, 159; 158, 160; 159, comment; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:config; 166, identifier:k; 167, identifier:extend; 168, argument_list; 168, 169; 169, subscript; 169, 170; 169, 171; 170, identifier:override_dict; 171, identifier:k; 172, elif_clause; 172, 173; 172, 180; 172, 181; 172, 182; 173, call; 173, 174; 173, 175; 174, identifier:isinstance; 175, argument_list; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:config; 178, identifier:k; 179, identifier:dict; 180, comment; 181, comment; 182, block; 182, 183; 182, 191; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:config; 188, identifier:k; 189, identifier:clear; 190, argument_list; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:config; 196, identifier:k; 197, identifier:update; 198, argument_list; 198, 199; 199, subscript; 199, 200; 199, 201; 200, identifier:override_dict; 201, identifier:k; 202, elif_clause; 202, 203; 202, 213; 202, 214; 202, 215; 203, call; 203, 204; 203, 205; 204, identifier:isinstance; 205, argument_list; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:config; 208, identifier:k; 209, tuple; 209, 210; 209, 211; 209, 212; 210, identifier:int; 211, identifier:float; 212, identifier:bool; 213, comment; 214, comment; 215, block; 215, 216; 215, 223; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:logger; 220, identifier:debug; 221, argument_list; 221, 222; 222, string:"Overwriting YAML anchor object. It is currently unclear how to reassign this value."; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:config; 227, identifier:k; 228, identifier:v; 229, else_clause; 229, 230; 229, 231; 230, comment; 231, block; 231, 232; 232, raise_statement; 232, 233; 233, call; 233, 234; 233, 235; 234, identifier:ValueError; 235, argument_list; 235, 236; 236, string:f"Object {k} (type {type(config[k])}) somehow has an anchor, but is something other than a list or dict. Attempting to assign directly to it."; 237, except_clause; 237, 238; 237, 239; 237, 240; 238, identifier:AttributeError; 239, comment; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:config; 245, identifier:k; 246, identifier:v; 247, else_clause; 247, 248; 248, block; 248, 249; 249, raise_statement; 249, 250; 250, call; 250, 251; 250, 252; 251, identifier:KeyError; 252, argument_list; 252, 253; 252, 254; 253, identifier:k; 254, string:f"Trying to override key \"{k}\" that it is not in the config."; 255, return_statement; 255, 256; 256, identifier:config | def override_options(config: DictLike, selected_options: Tuple[Any, ...], set_of_possible_options: Tuple[enum.Enum, ...], config_containing_override: DictLike = None) -> DictLike:
""" Determine override options for a particular configuration.
The options are determined by searching following the order specified in selected_options.
For the example config,
.. code-block:: yaml
config:
value: 3
override:
2.76:
track:
value: 5
value will be assigned the value 5 if we are at 2.76 TeV with a track bias, regardless of the event
activity or leading hadron bias. The order of this configuration is specified by the order of the
selected_options passed. The above example configuration is from the jet-hadron analysis.
Since anchors aren't kept for scalar values, if you want to override an anchored value, you need to
specify it as a single value in a list (or dict, but list is easier). After the anchor values propagate,
single element lists can be converted into scalar values using ``simplify_data_representations()``.
Args:
config: The dict-like configuration from ruamel.yaml which should be overridden.
selected_options: The selected analysis options. They will be checked in the order with which
they are passed, so make certain that it matches the order in the configuration file!
set_of_possible_options (tuple of enums): Possible options for the override value categories.
config_containing_override: The dict-like config containing the override options in a map called
"override". If it is not specified, it will look for it in the main config.
Returns:
dict-like object: The updated configuration
"""
if config_containing_override is None:
config_containing_override = config
override_opts = config_containing_override.pop("override")
override_dict = determine_override_options(selected_options, override_opts, set_of_possible_options)
logger.debug(f"override_dict: {override_dict}")
# Set the configuration values to those specified in the override options
# Cannot just use update() on config because we need to maintain the anchors.
for k, v in override_dict.items():
# Check if key is there and if it is not None! (The second part is important)
if k in config:
try:
# If it has an anchor, we know that we want to preserve the type. So we check for the anchor
# by trying to access it (Note that we don't actually care what the value is - just that it
# exists). If it fails with an AttributeError, then we know we can just assign the value. If it
# has an anchor, then we want to preserve the anchor information.
config[k].anchor
logger.debug(f"type: {type(config[k])}, k: {k}")
if isinstance(config[k], list):
# Clear out the existing list entries
del config[k][:]
if isinstance(override_dict[k], (str, int, float, bool)):
# We have to treat str carefully because it is an iterable, but it will be expanded as
# individual characters if it's treated the same as a list, which is not the desired
# behavior! If we wrap it in [], then it will be treated as the only entry in the list
# NOTE: We also treat the basic types this way because they will be passed this way if
# overriding indirectly with anchors (since the basic scalar types don't yet support
# reassignment while maintaining their anchors).
config[k].append(override_dict[k])
else:
# Here we just assign all entries of the list to all entries of override_dict[k]
config[k].extend(override_dict[k])
elif isinstance(config[k], dict):
# Clear out the existing entries because we are trying to replace everything
# Then we can simply update the dict with our new values
config[k].clear()
config[k].update(override_dict[k])
elif isinstance(config[k], (int, float, bool)):
# This isn't really very good (since we lose information), but there's nothing that can be done
# about it at the moment (Dec 2018)
logger.debug("Overwriting YAML anchor object. It is currently unclear how to reassign this value.")
config[k] = v
else:
# Raise a value error on all of the cases that we aren't already aware of.
raise ValueError(f"Object {k} (type {type(config[k])}) somehow has an anchor, but is something other than a list or dict. Attempting to assign directly to it.")
except AttributeError:
# If no anchor, just overwrite the value at this key
config[k] = v
else:
raise KeyError(k, f"Trying to override key \"{k}\" that it is not in the config.")
return config |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 1, 36; 2, function_name:determine_selection_of_iterable_values_from_config; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:config; 6, type; 6, 7; 7, identifier:DictLike; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:possible_iterables; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:Mapping; 13, type_parameter; 13, 14; 13, 16; 14, type; 14, 15; 15, identifier:str; 16, type; 16, 17; 17, generic_type; 17, 18; 17, 19; 18, identifier:Type; 19, type_parameter; 19, 20; 20, type; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:enum; 23, identifier:Enum; 24, type; 24, 25; 25, generic_type; 25, 26; 25, 27; 26, identifier:Dict; 27, type_parameter; 27, 28; 27, 30; 28, type; 28, 29; 29, identifier:str; 30, type; 30, 31; 31, generic_type; 31, 32; 31, 33; 32, identifier:List; 33, type_parameter; 33, 34; 34, type; 34, 35; 35, identifier:Any; 36, block; 36, 37; 36, 39; 36, 43; 36, 49; 36, 169; 37, expression_statement; 37, 38; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:iterables; 42, dictionary; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:requested_iterables; 46, subscript; 46, 47; 46, 48; 47, identifier:config; 48, string:"iterables"; 49, for_statement; 49, 50; 49, 53; 49, 58; 50, pattern_list; 50, 51; 50, 52; 51, identifier:k; 52, identifier:v; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:requested_iterables; 56, identifier:items; 57, argument_list; 58, block; 58, 59; 58, 70; 58, 77; 58, 87; 58, 93; 58, 94; 58, 110; 58, 111; 58, 162; 58, 163; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:not; 60, 61; 60, 62; 61, identifier:k; 62, identifier:possible_iterables; 63, block; 63, 64; 64, raise_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:KeyError; 67, argument_list; 67, 68; 67, 69; 68, identifier:k; 69, string:f"Cannot find requested iterable in possible_iterables: {possible_iterables}"; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger; 74, identifier:debug; 75, argument_list; 75, 76; 76, string:f"k: {k}, v: {v}"; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 78, 86; 79, identifier:additional_iterable; 80, type; 80, 81; 81, generic_type; 81, 82; 81, 83; 82, identifier:List; 83, type_parameter; 83, 84; 84, type; 84, 85; 85, identifier:Any; 86, list:[]; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:enum_values; 90, subscript; 90, 91; 90, 92; 91, identifier:possible_iterables; 92, identifier:k; 93, comment; 94, if_statement; 94, 95; 94, 100; 95, call; 95, 96; 95, 97; 96, identifier:isinstance; 97, argument_list; 97, 98; 97, 99; 98, identifier:v; 99, identifier:str; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:TypeError; 104, argument_list; 104, 105; 104, 109; 105, call; 105, 106; 105, 107; 106, identifier:type; 107, argument_list; 107, 108; 108, identifier:v; 109, string:f"Passed string {v} when must be either bool or list"; 110, comment; 111, if_statement; 111, 112; 111, 115; 111, 117; 111, 118; 111, 130; 112, comparison_operator:is; 112, 113; 112, 114; 113, identifier:v; 114, False; 115, block; 115, 116; 116, continue_statement; 117, comment; 118, elif_clause; 118, 119; 118, 122; 119, comparison_operator:is; 119, 120; 119, 121; 120, identifier:v; 121, True; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:additional_iterable; 126, call; 126, 127; 126, 128; 127, identifier:list; 128, argument_list; 128, 129; 129, identifier:enum_values; 130, else_clause; 130, 131; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 136; 132, 137; 132, 138; 132, 146; 133, comparison_operator:is; 133, 134; 133, 135; 134, identifier:enum_values; 135, None; 136, comment; 137, comment; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:additional_iterable; 142, call; 142, 143; 142, 144; 143, identifier:list; 144, argument_list; 144, 145; 145, identifier:v; 146, else_clause; 146, 147; 146, 148; 147, comment; 148, block; 148, 149; 149, for_statement; 149, 150; 149, 151; 149, 152; 150, identifier:el; 151, identifier:v; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:additional_iterable; 157, identifier:append; 158, argument_list; 158, 159; 159, subscript; 159, 160; 159, 161; 160, identifier:enum_values; 161, identifier:el; 162, comment; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:iterables; 167, identifier:k; 168, identifier:additional_iterable; 169, return_statement; 169, 170; 170, identifier:iterables | def determine_selection_of_iterable_values_from_config(config: DictLike, possible_iterables: Mapping[str, Type[enum.Enum]]) -> Dict[str, List[Any]]:
""" Determine iterable values to use to create objects for a given configuration.
All values of an iterable can be included be setting the value to ``True`` (Not as a single value list,
but as the only value.). Alternatively, an iterator can be disabled by setting the value to ``False``.
Args:
config: The dict-like configuration from ruamel.yaml which should be overridden.
possible_iterables: Key value pairs of names of enumerations and their values.
Returns:
dict: Iterables values that were requested in the config.
"""
iterables = {}
requested_iterables = config["iterables"]
for k, v in requested_iterables.items():
if k not in possible_iterables:
raise KeyError(k, f"Cannot find requested iterable in possible_iterables: {possible_iterables}")
logger.debug(f"k: {k}, v: {v}")
additional_iterable: List[Any] = []
enum_values = possible_iterables[k]
# Check for a string. This is wrong, and the user should be notified.
if isinstance(v, str):
raise TypeError(type(v), f"Passed string {v} when must be either bool or list")
# Allow the possibility to skip
if v is False:
continue
# Allow the possibility to including all possible values in the enum.
elif v is True:
additional_iterable = list(enum_values)
else:
if enum_values is None:
# The enumeration values are none, which means that we want to take
# all of the values defined in the config.
additional_iterable = list(v)
else:
# Otherwise, only take the requested values.
for el in v:
additional_iterable.append(enum_values[el])
# Store for later
iterables[k] = additional_iterable
return iterables |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 1, 20; 2, function_name:create_key_index_object; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:key_index_name; 6, type; 6, 7; 7, identifier:str; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:iterables; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:Dict; 13, type_parameter; 13, 14; 13, 16; 14, type; 14, 15; 15, identifier:str; 16, type; 16, 17; 17, identifier:Any; 18, type; 18, 19; 19, identifier:Any; 20, block; 20, 21; 20, 23; 20, 24; 20, 25; 20, 26; 20, 27; 20, 28; 20, 56; 20, 57; 20, 58; 20, 59; 20, 60; 20, 61; 20, 62; 20, 87; 20, 100; 20, 101; 20, 107; 21, expression_statement; 21, 22; 22, comment; 23, comment; 24, comment; 25, comment; 26, comment; 27, comment; 28, for_statement; 28, 29; 28, 32; 28, 37; 29, pattern_list; 29, 30; 29, 31; 30, identifier:name; 31, identifier:iterable; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:iterables; 35, identifier:items; 36, argument_list; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 48; 39, comparison_operator:==; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:iter; 42, argument_list; 42, 43; 43, identifier:iterable; 44, call; 44, 45; 44, 46; 45, identifier:iter; 46, argument_list; 46, 47; 47, identifier:iterable; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:TypeError; 52, argument_list; 52, 53; 53, concatenated_string; 53, 54; 53, 55; 54, string:f"Iterable {name} is in iterator which can be exhausted. Please pass the iterable"; 55, string:f" in a container that can recreate the iterable. See the comments here for more info."; 56, comment; 57, comment; 58, comment; 59, comment; 60, comment; 61, comment; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:fields; 65, list_comprehension; 65, 66; 65, 78; 66, tuple; 66, 67; 66, 68; 67, identifier:name; 68, call; 68, 69; 68, 70; 69, identifier:type; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:next; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:iter; 76, argument_list; 76, 77; 77, identifier:iterable; 78, for_in_clause; 78, 79; 78, 82; 79, pattern_list; 79, 80; 79, 81; 80, identifier:name; 81, identifier:iterable; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:iterables; 85, identifier:items; 86, argument_list; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:KeyIndex; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:dataclasses; 93, identifier:make_dataclass; 94, argument_list; 94, 95; 94, 96; 94, 97; 95, identifier:key_index_name; 96, identifier:fields; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:frozen; 99, True; 100, comment; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:KeyIndex; 105, identifier:__iter__; 106, identifier:_key_index_iter; 107, return_statement; 107, 108; 108, identifier:KeyIndex | def create_key_index_object(key_index_name: str, iterables: Dict[str, Any]) -> Any:
""" Create a ``KeyIndex`` class based on the passed attributes.
This is wrapped into a helper function to allow for the ``__itter__`` to be specified for the object.
Further, this allows it to be called outside the package when it is needed in analysis tasks..
Args:
key_index_name: Name of the iterable key index.
iterables: Iterables which will be specified by this ``KeyIndex``. The keys should be the names of
the values, while the values should be the iterables themselves.
Returns:
A ``KeyIndex`` class which can be used to specify an object. The keys and values will be iterable.
Raises:
TypeError: If one of the iterables which is passed is an iterator that can be exhausted. The iterables
must all be passed within containers which can recreate the iterator each time it is called to
iterate.
"""
# Validation
# We are going to use the iterators when determining the fields, so we need to notify if an iterator was
# passed, as this will cause a problem later. Instead of passing an iterator, a iterable should be passed,
# which can recreate the iter.
# See: https://effectivepython.com/2015/01/03/be-defensive-when-iterating-over-arguments/
for name, iterable in iterables.items():
if iter(iterable) == iter(iterable):
raise TypeError(
f"Iterable {name} is in iterator which can be exhausted. Please pass the iterable"
f" in a container that can recreate the iterable. See the comments here for more info."
)
# We need the types of the fields to create the dataclass. However, we are provided with iterables
# in the values of the iterables dict. Thus, we need to look at one value of each iterable, and use
# that to determine the type of that particular iterable. This is safe to do because the iterables
# must always have at least one entry (or else they wouldn't be one of the iterables).
# NOTE: The order here matters when we create the ``KeyIndex`` later, so we cannot just take all
# objects from the iterables and blindly use set because set won't preserve the order.
fields = [(name, type(next(iter(iterable)))) for name, iterable in iterables.items()]
KeyIndex = dataclasses.make_dataclass(
key_index_name,
fields,
frozen = True
)
# Allow for iteration over the key index values
KeyIndex.__iter__ = _key_index_iter
return KeyIndex |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 1, 50; 2, function_name:create_objects_from_iterables; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 19; 3, 29; 4, identifier:obj; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:args; 7, type; 7, 8; 8, identifier:dict; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:iterables; 11, type; 11, 12; 12, generic_type; 12, 13; 12, 14; 13, identifier:Dict; 14, type_parameter; 14, 15; 14, 17; 15, type; 15, 16; 16, identifier:str; 17, type; 17, 18; 18, identifier:Any; 19, typed_parameter; 19, 20; 19, 21; 20, identifier:formatting_options; 21, type; 21, 22; 22, generic_type; 22, 23; 22, 24; 23, identifier:Dict; 24, type_parameter; 24, 25; 24, 27; 25, type; 25, 26; 26, identifier:str; 27, type; 27, 28; 28, identifier:Any; 29, typed_default_parameter; 29, 30; 29, 31; 29, 33; 30, identifier:key_index_name; 31, type; 31, 32; 32, identifier:str; 33, string:"KeyIndex"; 34, type; 34, 35; 35, generic_type; 35, 36; 35, 37; 36, identifier:Tuple; 37, type_parameter; 37, 38; 37, 40; 37, 48; 38, type; 38, 39; 39, identifier:Any; 40, type; 40, 41; 41, generic_type; 41, 42; 41, 43; 42, identifier:Dict; 43, type_parameter; 43, 44; 43, 46; 44, type; 44, 45; 45, identifier:str; 46, type; 46, 47; 47, identifier:Any; 48, type; 48, 49; 49, identifier:dict; 50, block; 50, 51; 50, 53; 50, 54; 50, 58; 50, 65; 50, 72; 50, 73; 50, 85; 50, 86; 50, 87; 50, 88; 50, 225; 50, 226; 50, 227; 50, 237; 51, expression_statement; 51, 52; 52, comment; 53, comment; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:objects; 57, dictionary; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:names; 61, call; 61, 62; 61, 63; 62, identifier:list; 63, argument_list; 63, 64; 64, identifier:iterables; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:logger; 69, identifier:debug; 70, argument_list; 70, 71; 71, string:f"iterables: {iterables}"; 72, comment; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:KeyIndex; 76, call; 76, 77; 76, 78; 77, identifier:create_key_index_object; 78, argument_list; 78, 79; 78, 82; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:key_index_name; 81, identifier:key_index_name; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:iterables; 84, identifier:iterables; 85, comment; 86, comment; 87, comment; 88, for_statement; 88, 89; 88, 90; 88, 101; 89, identifier:values; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:itertools; 93, identifier:product; 94, argument_list; 94, 95; 95, list_splat; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:iterables; 99, identifier:values; 100, argument_list; 101, block; 101, 102; 101, 109; 101, 110; 101, 115; 101, 116; 101, 117; 101, 118; 101, 145; 101, 146; 101, 147; 101, 148; 101, 149; 101, 150; 101, 151; 101, 160; 101, 167; 101, 175; 101, 176; 101, 177; 101, 197; 101, 203; 101, 210; 101, 211; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logger; 106, identifier:debug; 107, argument_list; 107, 108; 108, string:f"Values: {values}"; 109, comment; 110, if_statement; 110, 111; 110, 113; 111, not_operator; 111, 112; 112, identifier:values; 113, block; 113, 114; 114, continue_statement; 115, comment; 116, comment; 117, comment; 118, for_statement; 118, 119; 118, 122; 118, 127; 118, 128; 119, pattern_list; 119, 120; 119, 121; 120, identifier:name; 121, identifier:val; 122, call; 122, 123; 122, 124; 123, identifier:zip; 124, argument_list; 124, 125; 124, 126; 125, identifier:names; 126, identifier:values; 127, comment; 128, block; 128, 129; 128, 135; 128, 136; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:args; 133, identifier:name; 134, identifier:val; 135, comment; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:formatting_options; 140, identifier:name; 141, call; 141, 142; 141, 143; 142, identifier:str; 143, argument_list; 143, 144; 144, identifier:val; 145, comment; 146, comment; 147, comment; 148, comment; 149, comment; 150, comment; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:object_args; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:copy; 157, identifier:copy; 158, argument_list; 158, 159; 159, identifier:args; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:logger; 164, identifier:debug; 165, argument_list; 165, 166; 166, string:f"object_args pre format: {object_args}"; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:object_args; 170, call; 170, 171; 170, 172; 171, identifier:apply_formatting_dict; 172, argument_list; 172, 173; 172, 174; 173, identifier:object_args; 174, identifier:formatting_options; 175, comment; 176, comment; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:print_args; 180, dictionary_comprehension; 180, 181; 180, 184; 180, 193; 181, pair; 181, 182; 181, 183; 182, identifier:k; 183, identifier:v; 184, for_in_clause; 184, 185; 184, 188; 185, pattern_list; 185, 186; 185, 187; 186, identifier:k; 187, identifier:v; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:object_args; 191, identifier:items; 192, argument_list; 193, if_clause; 193, 194; 194, comparison_operator:!=; 194, 195; 194, 196; 195, identifier:k; 196, string:"config"; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:print_args; 201, string:"config"; 202, string:"..."; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:logger; 207, identifier:debug; 208, argument_list; 208, 209; 209, string:f"Constructing obj \"{obj}\" with args: \"{print_args}\""; 210, comment; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 220; 213, subscript; 213, 214; 213, 215; 214, identifier:objects; 215, call; 215, 216; 215, 217; 216, identifier:KeyIndex; 217, argument_list; 217, 218; 218, list_splat; 218, 219; 219, identifier:values; 220, call; 220, 221; 220, 222; 221, identifier:obj; 222, argument_list; 222, 223; 223, dictionary_splat; 223, 224; 224, identifier:object_args; 225, comment; 226, comment; 227, if_statement; 227, 228; 227, 230; 228, not_operator; 228, 229; 229, identifier:objects; 230, block; 230, 231; 231, raise_statement; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:ValueError; 234, argument_list; 234, 235; 234, 236; 235, identifier:iterables; 236, string:"There appear to be no iterables to use in creating objects."; 237, return_statement; 237, 238; 238, tuple; 238, 239; 238, 240; 238, 241; 239, identifier:KeyIndex; 240, identifier:iterables; 241, identifier:objects | def create_objects_from_iterables(obj, args: dict, iterables: Dict[str, Any], formatting_options: Dict[str, Any], key_index_name: str = "KeyIndex") -> Tuple[Any, Dict[str, Any], dict]:
""" Create objects for each set of values based on the given arguments.
The iterable values are available under a key index ``dataclass`` which is used to index the returned
dictionary. The names of the fields are determined by the keys of iterables dictionary. The values are
the newly created object. Note that the iterable values must be convertible to a str() so they can be
included in the formatting dictionary.
Each set of values is also included in the object args.
As a basic example,
.. code-block:: python
>>> create_objects_from_iterables(
... obj = obj,
... args = {},
... iterables = {"a" : ["a1","a2"], "b" : ["b1", "b2"]},
... formatting_options = {}
... )
(
KeyIndex,
{"a": ["a1", "a2"], "b": ["b1", "b2"]}
{
KeyIndex(a = "a1", b = "b1"): obj(a = "a1", b = "b1"),
KeyIndex(a = "a1", b = "b2"): obj(a = "a1", b = "b2"),
KeyIndex(a = "a2", b = "b1"): obj(a = "a2", b = "b1"),
KeyIndex(a = "a2", b = "b2"): obj(a = "a2", b = "b2"),
}
)
Args:
obj (object): The object to be constructed.
args: Arguments to be passed to the object to create it.
iterables: Iterables to be used to create the objects, with entries of the form
``"name_of_iterable": iterable``.
formatting_options: Values to be used in formatting strings in the arguments.
key_index_name: Name of the iterable key index.
Returns:
(object, list, dict, dict): Roughly, (KeyIndex, iterables, objects). Specifically, the
key_index is a new dataclass which defines the parameters used to create the object, iterables
are the iterables used to create the objects, which names as keys and the iterables as values.
The objects dictionary keys are KeyIndex objects which describe the iterable arguments passed to the
object, while the values are the newly constructed arguments. See the example above.
"""
# Setup
objects = {}
names = list(iterables)
logger.debug(f"iterables: {iterables}")
# Create the key index object, where the name of each field is the name of each iterable.
KeyIndex = create_key_index_object(
key_index_name = key_index_name,
iterables = iterables,
)
# ``itertools.product`` produces all possible permutations of the iterables values.
# NOTE: Product preserves the order of the iterables values, which is important for properly
# assigning the values to the ``KeyIndex``.
for values in itertools.product(*iterables.values()):
logger.debug(f"Values: {values}")
# Skip if we don't have a sufficient set of values to create an object.
if not values:
continue
# Add in the values into the arguments and formatting options.
# NOTE: We don't need a deep copy for the iterable values in the args and formatting options
# because the values will be overwritten for each object.
for name, val in zip(names, values):
# We want to keep the original value for the arguments.
args[name] = val
# Here, we convert the value, regardless of type, into a string that can be displayed.
formatting_options[name] = str(val)
# Apply formatting options
# If we formatted in place, we would need to deepcopy the args to ensure that the iterable dependent
# values in the formatted values are properly set for each iterable object individually.
# However, by formatting into new variables, we can avoid a deepcopy, which greatly improves performance!
# NOTE: We don't need a deep copy do this for iterable value names themselves because they will be overwritten
# for each object. They are set in the block above.
object_args = copy.copy(args)
logger.debug(f"object_args pre format: {object_args}")
object_args = apply_formatting_dict(object_args, formatting_options)
# Print our results for debugging purposes. However, we skip printing the full
# config because it is quite long
print_args = {k: v for k, v in object_args.items() if k != "config"}
print_args["config"] = "..."
logger.debug(f"Constructing obj \"{obj}\" with args: \"{print_args}\"")
# Finally create the object.
objects[KeyIndex(*values)] = obj(**object_args)
# If nothing has been created at this point, then we are didn't iterating over anything and something
# has gone wrong.
if not objects:
raise ValueError(iterables, "There appear to be no iterables to use in creating objects.")
return (KeyIndex, iterables, objects) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 42; 1, 58; 2, function_name:iterate_with_selected_objects_in_order; 3, parameters; 3, 4; 3, 14; 3, 28; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:analysis_objects; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Mapping; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:Any; 12, type; 12, 13; 13, identifier:Any; 14, typed_parameter; 14, 15; 14, 16; 15, identifier:analysis_iterables; 16, type; 16, 17; 17, generic_type; 17, 18; 17, 19; 18, identifier:Dict; 19, type_parameter; 19, 20; 19, 22; 20, type; 20, 21; 21, identifier:str; 22, type; 22, 23; 23, generic_type; 23, 24; 23, 25; 24, identifier:Sequence; 25, type_parameter; 25, 26; 26, type; 26, 27; 27, identifier:Any; 28, typed_parameter; 28, 29; 28, 30; 29, identifier:selection; 30, type; 30, 31; 31, generic_type; 31, 32; 31, 33; 32, identifier:Union; 33, type_parameter; 33, 34; 33, 36; 34, type; 34, 35; 35, identifier:str; 36, type; 36, 37; 37, generic_type; 37, 38; 37, 39; 38, identifier:Sequence; 39, type_parameter; 39, 40; 40, type; 40, 41; 41, identifier:str; 42, type; 42, 43; 43, generic_type; 43, 44; 43, 45; 44, identifier:Iterator; 45, type_parameter; 45, 46; 46, type; 46, 47; 47, generic_type; 47, 48; 47, 49; 48, identifier:List; 49, type_parameter; 49, 50; 50, type; 50, 51; 51, generic_type; 51, 52; 51, 53; 52, identifier:Tuple; 53, type_parameter; 53, 54; 53, 56; 54, type; 54, 55; 55, identifier:Any; 56, type; 56, 57; 57, identifier:Any; 58, block; 58, 59; 58, 61; 58, 62; 58, 74; 58, 75; 58, 82; 58, 83; 58, 92; 58, 93; 58, 94; 58, 95; 58, 99; 58, 114; 58, 121; 58, 128; 58, 129; 58, 130; 58, 131; 58, 151; 58, 152; 58, 172; 58, 173; 58, 180; 58, 187; 58, 188; 58, 189; 58, 190; 59, expression_statement; 59, 60; 60, comment; 61, comment; 62, if_statement; 62, 63; 62, 68; 63, call; 63, 64; 63, 65; 64, identifier:isinstance; 65, argument_list; 65, 66; 65, 67; 66, identifier:selection; 67, identifier:str; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:selection; 72, list:[selection]; 72, 73; 73, identifier:selection; 74, comment; 75, assert_statement; 75, 76; 76, not_operator; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:isinstance; 79, argument_list; 79, 80; 79, 81; 80, identifier:selection; 81, identifier:str; 82, comment; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:analysis_iterables; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:copy; 89, identifier:copy; 90, argument_list; 90, 91; 91, identifier:analysis_iterables; 92, comment; 93, comment; 94, comment; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:selected_iterators; 98, dictionary; 99, for_statement; 99, 100; 99, 101; 99, 102; 100, identifier:s; 101, identifier:selection; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:selected_iterators; 107, identifier:s; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:analysis_iterables; 111, identifier:pop; 112, argument_list; 112, 113; 113, identifier:s; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:logger; 118, identifier:debug; 119, argument_list; 119, 120; 120, string:f"Initial analysis_iterables: {analysis_iterables}"; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:logger; 125, identifier:debug; 126, argument_list; 126, 127; 127, string:f"Initial selected_iterators: {selected_iterators}"; 128, comment; 129, comment; 130, comment; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:selected_iterators; 134, list_comprehension; 134, 135; 134, 142; 135, list_comprehension; 135, 136; 135, 139; 136, tuple; 136, 137; 136, 138; 137, identifier:k; 138, identifier:v; 139, for_in_clause; 139, 140; 139, 141; 140, identifier:v; 141, identifier:values; 142, for_in_clause; 142, 143; 142, 146; 143, pattern_list; 143, 144; 143, 145; 144, identifier:k; 145, identifier:values; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:selected_iterators; 149, identifier:items; 150, argument_list; 151, comment; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:analysis_iterables; 155, list_comprehension; 155, 156; 155, 163; 156, list_comprehension; 156, 157; 156, 160; 157, tuple; 157, 158; 157, 159; 158, identifier:k; 159, identifier:v; 160, for_in_clause; 160, 161; 160, 162; 161, identifier:v; 162, identifier:values; 163, for_in_clause; 163, 164; 163, 167; 164, pattern_list; 164, 165; 164, 166; 165, identifier:k; 166, identifier:values; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:analysis_iterables; 170, identifier:items; 171, argument_list; 172, comment; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:logger; 177, identifier:debug; 178, argument_list; 178, 179; 179, string:f"Final analysis_iterables: {analysis_iterables}"; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:logger; 184, identifier:debug; 185, argument_list; 185, 186; 186, string:f"Final selected_iterators: {selected_iterators}"; 187, comment; 188, comment; 189, comment; 190, for_statement; 190, 191; 190, 192; 190, 199; 191, identifier:values; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:itertools; 195, identifier:product; 196, argument_list; 196, 197; 197, list_splat; 197, 198; 198, identifier:analysis_iterables; 199, block; 199, 200; 199, 204; 199, 278; 199, 285; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:selected_analysis_objects; 203, list:[]; 204, for_statement; 204, 205; 204, 206; 204, 213; 205, identifier:selected_values; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:itertools; 209, identifier:product; 210, argument_list; 210, 211; 211, list_splat; 211, 212; 212, identifier:selected_iterators; 213, block; 213, 214; 214, for_statement; 214, 215; 214, 218; 214, 223; 215, pattern_list; 215, 216; 215, 217; 216, identifier:key_index; 217, identifier:obj; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:analysis_objects; 221, identifier:items; 222, argument_list; 223, block; 223, 224; 223, 242; 223, 260; 223, 266; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:selected_via_analysis_iterables; 227, call; 227, 228; 227, 229; 228, identifier:all; 229, generator_expression; 229, 230; 229, 237; 230, comparison_operator:==; 230, 231; 230, 236; 231, call; 231, 232; 231, 233; 232, identifier:getattr; 233, argument_list; 233, 234; 233, 235; 234, identifier:key_index; 235, identifier:k; 236, identifier:v; 237, for_in_clause; 237, 238; 237, 241; 238, pattern_list; 238, 239; 238, 240; 239, identifier:k; 240, identifier:v; 241, identifier:values; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:selected_via_selected_iterators; 245, call; 245, 246; 245, 247; 246, identifier:all; 247, generator_expression; 247, 248; 247, 255; 248, comparison_operator:==; 248, 249; 248, 254; 249, call; 249, 250; 249, 251; 250, identifier:getattr; 251, argument_list; 251, 252; 251, 253; 252, identifier:key_index; 253, identifier:k; 254, identifier:v; 255, for_in_clause; 255, 256; 255, 259; 256, pattern_list; 256, 257; 256, 258; 257, identifier:k; 258, identifier:v; 259, identifier:selected_values; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:selected_obj; 263, boolean_operator:and; 263, 264; 263, 265; 264, identifier:selected_via_analysis_iterables; 265, identifier:selected_via_selected_iterators; 266, if_statement; 266, 267; 266, 268; 267, identifier:selected_obj; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:selected_analysis_objects; 273, identifier:append; 274, argument_list; 274, 275; 275, tuple; 275, 276; 275, 277; 276, identifier:key_index; 277, identifier:obj; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:logger; 282, identifier:debug; 283, argument_list; 283, 284; 284, string:f"Yielding: {selected_analysis_objects}"; 285, expression_statement; 285, 286; 286, yield; 286, 287; 287, identifier:selected_analysis_objects | def iterate_with_selected_objects_in_order(analysis_objects: Mapping[Any, Any],
analysis_iterables: Dict[str, Sequence[Any]],
selection: Union[str, Sequence[str]]) -> Iterator[List[Tuple[Any, Any]]]:
""" Iterate over an analysis dictionary, yielding the selected attributes in order.
So if there are three iterables, a, b, and c, if we selected c, then we iterate over a and b,
and return c in the same order each time for each set of values of a and b. As an example, consider
the set of iterables:
.. code-block:: python
>>> a = ["a1", "a2"]
>>> b = ["b1", "b2"]
>>> c = ["c1", "c2"]
then it will effectively return:
.. code-block:: python
>>> for a_val in a:
... for b_val in b:
... for c_val in c:
... obj(a_val, b_val, c_val)
This will yield:
.. code-block:: python
>>> output = list(iterate_with_selected_objects_in_order(..., selection = ["a"]))
[[("a1", "b1", "c1"), ("a2", "b1", "c1")], [("a1", "b2", "c1"), ("a2", "b2", "c1")], ...]
This is particularly nice because we can then select on a set of iterables to be returned without
having to specify the rest of the iterables that we don't really care about.
Args:
analysis_objects: Analysis objects dictionary.
analysis_iterables: Iterables used in constructing the analysis objects.
selection: Selection of analysis selections to return. Can be either a string or a sequence of
selections.
Yields:
object: Matching analysis object.
"""
# Validation
if isinstance(selection, str):
selection = [selection]
# Help out mypy. We don't check if it is a list to allow for other sequences.
assert not isinstance(selection, str)
# We don't want to impact the original analysis iterables when we pop some values below.
analysis_iterables = copy.copy(analysis_iterables)
# Extract the selected iterators from the possible iterators so we can select on them later.
# First, we want want each set of iterators to be of the form:
# {"selection1": [value1, value2, ...], "selection2": [value3, value4, ...]}
selected_iterators = {}
for s in selection:
selected_iterators[s] = analysis_iterables.pop(s)
logger.debug(f"Initial analysis_iterables: {analysis_iterables}")
logger.debug(f"Initial selected_iterators: {selected_iterators}")
# Now, we convert them to the form:
# [[("selection1", value1), ("selection1", value2)], [("selection2", value3), ("selection2", value4)]]
# This allows them to iterated over conveniently via itertools.product(...)
selected_iterators = [[(k, v) for v in values] for k, values in selected_iterators.items()] # type: ignore
analysis_iterables = [[(k, v) for v in values] for k, values in analysis_iterables.items()] # type: ignore
logger.debug(f"Final analysis_iterables: {analysis_iterables}")
logger.debug(f"Final selected_iterators: {selected_iterators}")
# Useful debug information, but too verbose for standard usage.
#logger.debug(f"analysis_iterables product: {list(itertools.product(*analysis_iterables))}")
#logger.debug(f"selected_iterators product: {list(itertools.product(*selected_iterators))}")
for values in itertools.product(*analysis_iterables):
selected_analysis_objects = []
for selected_values in itertools.product(*selected_iterators):
for key_index, obj in analysis_objects.items():
selected_via_analysis_iterables = all(
getattr(key_index, k) == v for k, v in values
)
selected_via_selected_iterators = all(
getattr(key_index, k) == v for k, v in selected_values
)
selected_obj = selected_via_analysis_iterables and selected_via_selected_iterators
if selected_obj:
selected_analysis_objects.append((key_index, obj))
logger.debug(f"Yielding: {selected_analysis_objects}")
yield selected_analysis_objects |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:phenotypes_to_scored; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:phenotypes; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:overwrite; 10, False; 11, block; 11, 12; 11, 14; 11, 27; 11, 50; 11, 125; 11, 133; 11, 158; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 21; 15, not_operator; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:is_uniform; 20, argument_list; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ValueError; 25, argument_list; 25, 26; 26, string:"inconsistent phenotypes"; 27, if_statement; 27, 28; 27, 31; 27, 38; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:phenotypes; 30, None; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:phenotypes; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:phenotypes; 38, elif_clause; 38, 39; 38, 44; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 43; 42, identifier:phenotypes; 43, identifier:str; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:phenotypes; 48, list:[phenotypes]; 48, 49; 49, identifier:phenotypes; 50, function_definition; 50, 51; 50, 52; 50, 57; 51, function_name:_post; 52, parameters; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:binary; 54, identifier:phenotype_label; 55, identifier:phenotypes; 56, identifier:overwrite; 57, block; 57, 58; 57, 66; 57, 98; 57, 108; 57, 123; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:d; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:binary; 64, identifier:copy; 65, argument_list; 66, if_statement; 66, 67; 66, 92; 67, boolean_operator:and; 67, 68; 67, 89; 68, comparison_operator:>; 68, 69; 68, 88; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, binary_operator:&; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:set; 75, argument_list; 75, 76; 76, identifier:phenotypes; 77, call; 77, 78; 77, 79; 78, identifier:set; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:list; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:binary; 86, identifier:keys; 87, argument_list; 88, integer:0; 89, comparison_operator:==; 89, 90; 89, 91; 90, identifier:overwrite; 91, False; 92, block; 92, 93; 93, raise_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:ValueError; 96, argument_list; 96, 97; 97, string:"Error, phenotype already exists as a scored type"; 98, for_statement; 98, 99; 98, 100; 98, 101; 99, identifier:label; 100, identifier:phenotypes; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:d; 106, identifier:label; 107, integer:0; 108, if_statement; 108, 109; 108, 116; 109, boolean_operator:and; 109, 110; 109, 113; 110, comparison_operator:==; 110, 111; 110, 112; 111, identifier:phenotype_label; 112, identifier:phenotype_label; 113, comparison_operator:in; 113, 114; 113, 115; 114, identifier:phenotype_label; 115, identifier:phenotypes; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:d; 121, identifier:phenotype_label; 122, integer:1; 123, return_statement; 123, 124; 124, identifier:d; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:output; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:copy; 132, argument_list; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:output; 137, string:'scored_calls'; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:output; 141, identifier:apply; 142, argument_list; 142, 143; 142, 157; 143, lambda; 143, 144; 143, 146; 144, lambda_parameters; 144, 145; 145, identifier:x; 146, call; 146, 147; 146, 148; 147, identifier:_post; 148, argument_list; 148, 149; 148, 152; 148, 155; 148, 156; 149, subscript; 149, 150; 149, 151; 150, identifier:x; 151, string:'scored_calls'; 152, subscript; 152, 153; 152, 154; 153, identifier:x; 154, string:'phenotype_label'; 155, identifier:phenotypes; 156, identifier:overwrite; 157, integer:1; 158, return_statement; 158, 159; 159, identifier:output | def phenotypes_to_scored(self,phenotypes=None,overwrite=False):
"""
Add mutually exclusive phenotypes to the scored calls
Args:
phenotypes (list): a list of phenotypes to add to scored calls. if none or not set, add them all
overwrite (bool): if True allow the overwrite of a phenotype, if False, the phenotype must not exist in the scored calls
Returns:
CellDataFrame
"""
if not self.is_uniform(): raise ValueError("inconsistent phenotypes")
if phenotypes is None:
phenotypes = self.phenotypes
elif isinstance(phenotypes,str):
phenotypes = [phenotypes]
def _post(binary,phenotype_label,phenotypes,overwrite):
d = binary.copy()
if len(set(phenotypes)&set(list(binary.keys()))) > 0 and overwrite==False:
raise ValueError("Error, phenotype already exists as a scored type")
for label in phenotypes: d[label] = 0
if phenotype_label == phenotype_label and phenotype_label in phenotypes:
d[phenotype_label] = 1
return d
output = self.copy()
output['scored_calls'] = output.apply(lambda x:
_post(x['scored_calls'],x['phenotype_label'],phenotypes,overwrite)
,1)
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:subset; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:logic; 6, default_parameter; 6, 7; 6, 8; 7, identifier:update; 8, False; 9, block; 9, 10; 9, 12; 9, 18; 9, 24; 9, 32; 9, 36; 9, 42; 9, 54; 9, 68; 9, 167; 9, 176; 9, 229; 9, 237; 9, 261; 9, 270; 9, 278; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:pnames; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:phenotypes; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:snames; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:scored_names; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:data; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:copy; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:values; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:phenotypes; 39, attribute; 39, 40; 39, 41; 40, identifier:logic; 41, identifier:phenotypes; 42, if_statement; 42, 43; 42, 49; 43, comparison_operator:==; 43, 44; 43, 48; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:phenotypes; 48, integer:0; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:phenotypes; 53, identifier:pnames; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:removing; 57, binary_operator:-; 57, 58; 57, 64; 58, call; 58, 59; 58, 60; 59, identifier:set; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:phenotypes; 64, call; 64, 65; 64, 66; 65, identifier:set; 66, argument_list; 66, 67; 67, identifier:phenotypes; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:k; 70, identifier:phenotypes; 71, block; 71, 72; 71, 82; 71, 108; 71, 160; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:not; 73, 74; 73, 75; 74, identifier:k; 75, identifier:pnames; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:ValueError; 80, argument_list; 80, 81; 81, string:"phenotype must exist in defined"; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:temp; 85, call; 85, 86; 85, 107; 86, attribute; 86, 87; 86, 106; 87, subscript; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:data; 90, identifier:loc; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:data; 95, string:'phenotype_calls'; 96, identifier:apply; 97, argument_list; 97, 98; 98, lambda; 98, 99; 98, 101; 99, lambda_parameters; 99, 100; 100, identifier:x; 101, comparison_operator:==; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:x; 104, identifier:k; 105, integer:1; 106, identifier:copy; 107, argument_list; 108, if_statement; 108, 109; 108, 123; 109, boolean_operator:and; 109, 110; 109, 116; 110, comparison_operator:>; 110, 111; 110, 115; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, identifier:removing; 115, integer:0; 116, comparison_operator:>; 116, 117; 116, 122; 117, subscript; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:temp; 120, identifier:shape; 121, integer:0; 122, integer:0; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:temp; 128, string:'phenotype_calls'; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:temp; 132, identifier:apply; 133, argument_list; 133, 134; 133, 159; 134, lambda; 134, 135; 134, 137; 135, lambda_parameters; 135, 136; 136, identifier:x; 137, call; 137, 138; 137, 139; 138, identifier:dict; 139, argument_list; 139, 140; 140, list_comprehension; 140, 141; 140, 144; 140, 155; 141, tuple; 141, 142; 141, 143; 142, identifier:k; 143, identifier:v; 144, for_in_clause; 144, 145; 144, 148; 145, pattern_list; 145, 146; 145, 147; 146, identifier:k; 147, identifier:v; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:x; 152, string:'phenotype_calls'; 153, identifier:items; 154, argument_list; 155, if_clause; 155, 156; 156, comparison_operator:not; 156, 157; 156, 158; 157, identifier:k; 158, identifier:removing; 159, integer:1; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:values; 164, identifier:append; 165, argument_list; 165, 166; 166, identifier:temp; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:data; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:pd; 173, identifier:concat; 174, argument_list; 174, 175; 175, identifier:values; 176, for_statement; 176, 177; 176, 180; 176, 187; 177, pattern_list; 177, 178; 177, 179; 178, identifier:k; 179, identifier:v; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:logic; 184, identifier:scored_calls; 185, identifier:items; 186, argument_list; 187, block; 187, 188; 187, 198; 187, 207; 188, if_statement; 188, 189; 188, 192; 189, comparison_operator:not; 189, 190; 189, 191; 190, identifier:k; 191, identifier:snames; 192, block; 192, 193; 193, raise_statement; 193, 194; 194, call; 194, 195; 194, 196; 195, identifier:ValueError; 196, argument_list; 196, 197; 197, string:"Scored name must exist in defined"; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:myfilter; 201, conditional_expression:if; 201, 202; 201, 203; 201, 206; 202, integer:0; 203, comparison_operator:==; 203, 204; 203, 205; 204, identifier:v; 205, string:'-'; 206, integer:1; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:data; 210, subscript; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:data; 213, identifier:loc; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:data; 218, string:'scored_calls'; 219, identifier:apply; 220, argument_list; 220, 221; 221, lambda; 221, 222; 221, 224; 222, lambda_parameters; 222, 223; 223, identifier:x; 224, comparison_operator:==; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:x; 227, identifier:k; 228, identifier:myfilter; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:data; 233, identifier:microns_per_pixel; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:microns_per_pixel; 237, if_statement; 237, 238; 237, 239; 238, identifier:update; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:data; 244, string:'phenotype_calls'; 245, call; 245, 246; 245, 251; 246, attribute; 246, 247; 246, 250; 247, subscript; 247, 248; 247, 249; 248, identifier:data; 249, string:'phenotype_calls'; 250, identifier:apply; 251, argument_list; 251, 252; 252, lambda; 252, 253; 252, 255; 253, lambda_parameters; 253, 254; 254, identifier:x; 255, dictionary; 255, 256; 256, pair; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:logic; 259, identifier:label; 260, integer:1; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:data; 265, identifier:fill_phenotype_label; 266, argument_list; 266, 267; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:inplace; 269, True; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:data; 274, identifier:db; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:db; 278, return_statement; 278, 279; 279, identifier:data | def subset(self,logic,update=False):
"""
subset create a specific phenotype based on a logic,
logic is a 'SubsetLogic' class,
take union of all the phenotypes listed. If none are listed use all phenotypes.
take the intersection of all the scored calls.
Args:
logic (SubsetLogic): A subsetlogic object to slice on
update (bool): (default False) change the name of the phenotype according to the label in the subset logic
Returns:
CellDataFrame: The CellDataFrame modified.
"""
pnames = self.phenotypes
snames = self.scored_names
data = self.copy()
values = []
phenotypes = logic.phenotypes
if len(phenotypes)==0: phenotypes = pnames
removing = set(self.phenotypes)-set(phenotypes)
for k in phenotypes:
if k not in pnames: raise ValueError("phenotype must exist in defined")
temp = data.loc[data['phenotype_calls'].apply(lambda x: x[k]==1)].copy()
if len(removing) > 0 and temp.shape[0] > 0:
temp['phenotype_calls'] = temp.apply(lambda x:
dict([(k,v) for k,v in x['phenotype_calls'].items() if k not in removing])
,1)
values.append(temp)
data = pd.concat(values)
for k,v in logic.scored_calls.items():
if k not in snames: raise ValueError("Scored name must exist in defined")
myfilter = 0 if v == '-' else 1
data = data.loc[data['scored_calls'].apply(lambda x: x[k]==myfilter)]
data.microns_per_pixel = self.microns_per_pixel
if update:
data['phenotype_calls'] = data['phenotype_calls'].apply(lambda x: {logic.label:1})
data.fill_phenotype_label(inplace=True)
data.db = self.db
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:collapse_phenotypes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:input_phenotype_labels; 6, identifier:output_phenotype_label; 7, default_parameter; 7, 8; 7, 9; 8, identifier:verbose; 9, True; 10, block; 10, 11; 10, 13; 10, 25; 10, 39; 10, 59; 10, 67; 10, 77; 10, 153; 10, 175; 10, 212; 10, 232; 11, expression_statement; 11, 12; 12, comment; 13, if_statement; 13, 14; 13, 19; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:input_phenotype_labels; 18, identifier:str; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:input_phenotype_labels; 23, list:[input_phenotype_labels]; 23, 24; 24, identifier:input_phenotype_labels; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:bad_phenotypes; 28, binary_operator:-; 28, 29; 28, 33; 29, call; 29, 30; 29, 31; 30, identifier:set; 31, argument_list; 31, 32; 32, identifier:input_phenotype_labels; 33, call; 33, 34; 33, 35; 34, identifier:set; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:phenotypes; 39, if_statement; 39, 40; 39, 46; 40, comparison_operator:>; 40, 41; 40, 45; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:bad_phenotypes; 45, integer:0; 46, block; 46, 47; 47, raise_statement; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:ValueError; 50, argument_list; 50, 51; 51, binary_operator:+; 51, 52; 51, 58; 52, binary_operator:+; 52, 53; 52, 54; 53, string:"Error phenotype(s) "; 54, call; 54, 55; 54, 56; 55, identifier:str; 56, argument_list; 56, 57; 57, identifier:bad_phenotypes; 58, string:" are not in the data."; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:data; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:copy; 66, argument_list; 67, if_statement; 67, 68; 67, 74; 68, comparison_operator:==; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:input_phenotype_labels; 73, integer:0; 74, block; 74, 75; 75, return_statement; 75, 76; 76, identifier:data; 77, function_definition; 77, 78; 77, 79; 77, 83; 77, 84; 78, function_name:_swap_in; 79, parameters; 79, 80; 79, 81; 79, 82; 80, identifier:d; 81, identifier:inputs; 82, identifier:output; 83, comment; 84, block; 84, 85; 84, 101; 84, 102; 84, 112; 84, 132; 84, 133; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:overlap; 88, call; 88, 89; 88, 99; 89, attribute; 89, 90; 89, 98; 90, call; 90, 91; 90, 92; 91, identifier:set; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:d; 96, identifier:keys; 97, argument_list; 98, identifier:intersection; 99, argument_list; 99, 100; 100, identifier:inputs; 101, comment; 102, if_statement; 102, 103; 102, 109; 103, comparison_operator:==; 103, 104; 103, 108; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:overlap; 108, integer:0; 109, block; 109, 110; 110, return_statement; 110, 111; 111, identifier:d; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:keepers; 115, list_comprehension; 115, 116; 115, 119; 115, 128; 116, tuple; 116, 117; 116, 118; 117, identifier:k; 118, identifier:v; 119, for_in_clause; 119, 120; 119, 123; 120, pattern_list; 120, 121; 120, 122; 121, identifier:k; 122, identifier:v; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:d; 126, identifier:items; 127, argument_list; 128, if_clause; 128, 129; 129, comparison_operator:not; 129, 130; 129, 131; 130, identifier:k; 131, identifier:inputs; 132, comment; 133, return_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:dict; 136, argument_list; 136, 137; 137, binary_operator:+; 137, 138; 137, 139; 137, 140; 138, identifier:keepers; 139, line_continuation:\; 140, list:[(output_phenotype_label,max([d[x] for x in overlap]))]; 140, 141; 141, tuple; 141, 142; 141, 143; 142, identifier:output_phenotype_label; 143, call; 143, 144; 143, 145; 144, identifier:max; 145, argument_list; 145, 146; 146, list_comprehension; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:d; 149, identifier:x; 150, for_in_clause; 150, 151; 150, 152; 151, identifier:x; 152, identifier:overlap; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:data; 157, string:'phenotype_calls'; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:data; 161, identifier:apply; 162, argument_list; 162, 163; 162, 174; 163, lambda; 163, 164; 163, 166; 164, lambda_parameters; 164, 165; 165, identifier:x; 166, call; 166, 167; 166, 168; 167, identifier:_swap_in; 168, argument_list; 168, 169; 168, 172; 168, 173; 169, subscript; 169, 170; 169, 171; 170, identifier:x; 171, string:'phenotype_calls'; 172, identifier:input_phenotype_labels; 173, identifier:output_phenotype_label; 174, integer:1; 175, function_definition; 175, 176; 175, 177; 175, 179; 176, function_name:_set_label; 177, parameters; 177, 178; 178, identifier:d; 179, block; 179, 180; 179, 198; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:vals; 183, list_comprehension; 183, 184; 183, 185; 183, 194; 184, identifier:k; 185, for_in_clause; 185, 186; 185, 189; 186, pattern_list; 186, 187; 186, 188; 187, identifier:k; 188, identifier:v; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:d; 192, identifier:items; 193, argument_list; 194, if_clause; 194, 195; 195, comparison_operator:==; 195, 196; 195, 197; 196, identifier:v; 197, integer:1; 198, return_statement; 198, 199; 199, conditional_expression:if; 199, 200; 199, 203; 199, 209; 200, attribute; 200, 201; 200, 202; 201, identifier:np; 202, identifier:nan; 203, comparison_operator:==; 203, 204; 203, 208; 204, call; 204, 205; 204, 206; 205, identifier:len; 206, argument_list; 206, 207; 207, identifier:vals; 208, integer:0; 209, subscript; 209, 210; 209, 211; 210, identifier:vals; 211, integer:0; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, subscript; 214, 215; 214, 216; 215, identifier:data; 216, string:'phenotype_label'; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:data; 220, identifier:apply; 221, argument_list; 221, 222; 221, 231; 222, lambda; 222, 223; 222, 225; 223, lambda_parameters; 223, 224; 224, identifier:x; 225, call; 225, 226; 225, 227; 226, identifier:_set_label; 227, argument_list; 227, 228; 228, subscript; 228, 229; 228, 230; 229, identifier:x; 230, string:'phenotype_calls'; 231, integer:1; 232, return_statement; 232, 233; 233, identifier:data | def collapse_phenotypes(self,input_phenotype_labels,output_phenotype_label,verbose=True):
"""
Rename one or more input phenotypes to a single output phenotype
Args:
input_phenotype_labels (list): A str name or list of names to combine
output_phenotype_label (list): A str name to change the phenotype names to
verbose (bool): output more details
Returns:
CellDataFrame: The CellDataFrame modified.
"""
if isinstance(input_phenotype_labels,str): input_phenotype_labels = [input_phenotype_labels]
bad_phenotypes = set(input_phenotype_labels)-set(self.phenotypes)
if len(bad_phenotypes) > 0: raise ValueError("Error phenotype(s) "+str(bad_phenotypes)+" are not in the data.")
data = self.copy()
if len(input_phenotype_labels) == 0: return data
def _swap_in(d,inputs,output):
# Get the keys we need to merge together
overlap = set(d.keys()).intersection(inputs)
# if there are none to merge we're done already
if len(overlap) == 0: return d
keepers = [(k,v) for k,v in d.items() if k not in inputs]
# combine anything thats not a keeper
return dict(keepers+\
[(output_phenotype_label,max([d[x] for x in overlap]))])
data['phenotype_calls'] = data.apply(lambda x:
_swap_in(x['phenotype_calls'],input_phenotype_labels,output_phenotype_label)
,1)
def _set_label(d):
vals = [k for k,v in d.items() if v==1]
return np.nan if len(vals) == 0 else vals[0]
data['phenotype_label'] = data.apply(lambda x:
_set_label(x['phenotype_calls']),1)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:scored_to_phenotype; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:phenotypes; 6, block; 6, 7; 6, 9; 6, 87; 6, 95; 6, 116; 6, 117; 6, 148; 7, expression_statement; 7, 8; 8, comment; 9, function_definition; 9, 10; 9, 11; 9, 14; 10, function_name:_apply_score; 11, parameters; 11, 12; 11, 13; 12, identifier:scored_calls; 13, identifier:phenotypes; 14, block; 14, 15; 14, 37; 14, 50; 14, 60; 14, 69; 14, 82; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:present; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:list; 23, argument_list; 23, 24; 24, binary_operator:&; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, identifier:phenotypes; 29, call; 29, 30; 29, 31; 30, identifier:set; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:scored_calls; 35, identifier:keys; 36, argument_list; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:total; 40, call; 40, 41; 40, 42; 41, identifier:sum; 42, argument_list; 42, 43; 43, list_comprehension; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:scored_calls; 46, identifier:x; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:x; 49, identifier:present; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:>; 51, 52; 51, 53; 52, identifier:total; 53, integer:1; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:ValueError; 58, argument_list; 58, 59; 59, string:"You cant extract phenotypes from scores if they are not mutually exclusive"; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:==; 61, 62; 61, 63; 62, identifier:total; 63, integer:0; 64, block; 64, 65; 65, return_statement; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:np; 68, identifier:nan; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:label; 71, identifier:present; 72, block; 72, 73; 73, if_statement; 73, 74; 73, 79; 74, comparison_operator:==; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:scored_calls; 77, identifier:label; 78, integer:1; 79, block; 79, 80; 80, return_statement; 80, 81; 81, identifier:label; 82, raise_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:ValueError; 85, argument_list; 85, 86; 86, string:"Should have hit an exit criteria already"; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:output; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:copy; 94, argument_list; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:output; 99, string:'phenotype_label'; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:output; 103, identifier:apply; 104, argument_list; 104, 105; 104, 115; 105, lambda; 105, 106; 105, 108; 106, lambda_parameters; 106, 107; 107, identifier:x; 108, call; 108, 109; 108, 110; 109, identifier:_apply_score; 110, argument_list; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:x; 113, string:'scored_calls'; 114, identifier:phenotypes; 115, integer:1; 116, comment; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:output; 121, string:'phenotype_calls'; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:output; 125, identifier:apply; 126, argument_list; 126, 127; 126, 147; 127, lambda; 127, 128; 127, 130; 128, lambda_parameters; 128, 129; 129, identifier:x; 130, call; 130, 131; 130, 132; 131, identifier:dict; 132, argument_list; 132, 133; 133, list_comprehension; 133, 134; 133, 144; 134, tuple; 134, 135; 134, 136; 135, identifier:y; 136, conditional_expression:if; 136, 137; 136, 138; 136, 143; 137, integer:1; 138, comparison_operator:==; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:x; 141, string:'phenotype_label'; 142, identifier:y; 143, integer:0; 144, for_in_clause; 144, 145; 144, 146; 145, identifier:y; 146, identifier:phenotypes; 147, integer:1; 148, return_statement; 148, 149; 149, identifier:output | def scored_to_phenotype(self,phenotypes):
"""
Convert binary pehnotypes to mutually exclusive phenotypes.
If none of the phenotypes are set, then phenotype_label becomes nan
If any of the phenotypes are multiply set then it throws a fatal error.
Args:
phenotypes (list): a list of scored_names to convert to phenotypes
Returns:
CellDataFrame
"""
def _apply_score(scored_calls,phenotypes):
present = sorted(list(set(phenotypes)&set(scored_calls.keys())))
total = sum([scored_calls[x] for x in present])
if total > 1:
raise ValueError("You cant extract phenotypes from scores if they are not mutually exclusive")
if total == 0: return np.nan
for label in present:
if scored_calls[label] == 1: return label
raise ValueError("Should have hit an exit criteria already")
output = self.copy()
output['phenotype_label'] = output.apply(lambda x: _apply_score(x['scored_calls'],phenotypes),1)
# now update the phenotypes with these
output['phenotype_calls'] = output.apply(lambda x:
dict([(y,1 if x['phenotype_label']==y else 0) for y in phenotypes])
,1)
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:spike_times; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:signal; 5, identifier:threshold; 6, identifier:fs; 7, default_parameter; 7, 8; 7, 9; 8, identifier:absval; 9, True; 10, block; 10, 11; 10, 13; 10, 17; 10, 29; 10, 41; 10, 58; 10, 304; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:times; 16, list:[]; 17, if_statement; 17, 18; 17, 19; 18, identifier:absval; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:signal; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:np; 26, identifier:abs; 27, argument_list; 27, 28; 28, identifier:signal; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 33; 31, pattern_list; 31, 32; 32, identifier:over; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:where; 37, argument_list; 37, 38; 38, comparison_operator:>; 38, 39; 38, 40; 39, identifier:signal; 40, identifier:threshold; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 45; 43, pattern_list; 43, 44; 44, identifier:segments; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:np; 48, identifier:where; 49, argument_list; 49, 50; 50, comparison_operator:>; 50, 51; 50, 57; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:np; 54, identifier:diff; 55, argument_list; 55, 56; 56, identifier:over; 57, integer:1; 58, if_statement; 58, 59; 58, 65; 58, 282; 59, comparison_operator:>; 59, 60; 59, 64; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:over; 64, integer:1; 65, block; 65, 66; 65, 188; 66, if_statement; 66, 67; 66, 73; 66, 85; 67, comparison_operator:==; 67, 68; 67, 72; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:segments; 72, integer:0; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:segments; 77, list:[0, len(over)-1]; 77, 78; 77, 79; 78, integer:0; 79, binary_operator:-; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:over; 84, integer:1; 85, else_clause; 85, 86; 85, 87; 86, comment; 87, block; 87, 88; 87, 137; 88, if_statement; 88, 89; 88, 94; 88, 108; 89, comparison_operator:!=; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:segments; 92, integer:0; 93, integer:0; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:segments; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:insert; 102, argument_list; 102, 103; 102, 104; 102, 106; 103, identifier:segments; 104, list:[0]; 104, 105; 105, integer:0; 106, list:[0]; 106, 107; 107, integer:0; 108, else_clause; 108, 109; 108, 110; 109, comment; 110, block; 110, 111; 110, 125; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:times; 115, identifier:append; 116, argument_list; 116, 117; 117, binary_operator:/; 117, 118; 117, 124; 118, call; 118, 119; 118, 120; 119, identifier:float; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:over; 123, integer:0; 124, identifier:fs; 125, if_statement; 125, 126; 125, 129; 125, 130; 126, comparison_operator:not; 126, 127; 126, 128; 127, integer:1; 128, identifier:segments; 129, comment; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:segments; 135, integer:0; 136, integer:1; 137, if_statement; 137, 138; 137, 149; 137, 171; 138, comparison_operator:!=; 138, 139; 138, 143; 139, subscript; 139, 140; 139, 141; 140, identifier:segments; 141, unary_operator:-; 141, 142; 142, integer:1; 143, binary_operator:-; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:over; 148, integer:1; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:segments; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:np; 156, identifier:insert; 157, argument_list; 157, 158; 157, 159; 157, 164; 158, identifier:segments; 159, list:[len(segments)]; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:segments; 164, list:[len(over)-1]; 164, 165; 165, binary_operator:-; 165, 166; 165, 170; 166, call; 166, 167; 166, 168; 167, identifier:len; 168, argument_list; 168, 169; 169, identifier:over; 170, integer:1; 171, else_clause; 171, 172; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:times; 177, identifier:append; 178, argument_list; 178, 179; 179, binary_operator:/; 179, 180; 179, 187; 180, call; 180, 181; 180, 182; 181, identifier:float; 182, argument_list; 182, 183; 183, subscript; 183, 184; 183, 185; 184, identifier:over; 185, unary_operator:-; 185, 186; 186, integer:1; 187, identifier:fs; 188, for_statement; 188, 189; 188, 190; 188, 198; 189, identifier:iseg; 190, call; 190, 191; 190, 192; 191, identifier:range; 192, argument_list; 192, 193; 192, 194; 193, integer:1; 194, call; 194, 195; 194, 196; 195, identifier:len; 196, argument_list; 196, 197; 197, identifier:segments; 198, block; 198, 199; 198, 270; 199, if_statement; 199, 200; 199, 211; 199, 212; 199, 221; 200, comparison_operator:==; 200, 201; 200, 210; 201, binary_operator:-; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:segments; 204, identifier:iseg; 205, subscript; 205, 206; 205, 207; 206, identifier:segments; 207, binary_operator:-; 207, 208; 207, 209; 208, identifier:iseg; 209, integer:1; 210, integer:1; 211, comment; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:idx; 216, subscript; 216, 217; 216, 218; 217, identifier:over; 218, subscript; 218, 219; 218, 220; 219, identifier:segments; 220, identifier:iseg; 221, else_clause; 221, 222; 222, block; 222, 223; 222, 233; 222, 234; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:segments; 227, integer:0; 228, binary_operator:-; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:segments; 231, integer:0; 232, integer:1; 233, comment; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:idx; 237, binary_operator:+; 237, 238; 237, 247; 238, subscript; 238, 239; 238, 240; 239, identifier:over; 240, binary_operator:+; 240, 241; 240, 246; 241, subscript; 241, 242; 241, 243; 242, identifier:segments; 243, binary_operator:-; 243, 244; 243, 245; 244, identifier:iseg; 245, integer:1; 246, integer:1; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:np; 250, identifier:argmax; 251, argument_list; 251, 252; 252, subscript; 252, 253; 252, 254; 253, identifier:signal; 254, slice; 254, 255; 254, 264; 254, 265; 255, subscript; 255, 256; 255, 257; 256, identifier:over; 257, binary_operator:+; 257, 258; 257, 263; 258, subscript; 258, 259; 258, 260; 259, identifier:segments; 260, binary_operator:-; 260, 261; 260, 262; 261, identifier:iseg; 262, integer:1; 263, integer:1; 264, colon; 265, subscript; 265, 266; 265, 267; 266, identifier:over; 267, subscript; 267, 268; 267, 269; 268, identifier:segments; 269, identifier:iseg; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:times; 274, identifier:append; 275, argument_list; 275, 276; 276, binary_operator:/; 276, 277; 276, 281; 277, call; 277, 278; 277, 279; 278, identifier:float; 279, argument_list; 279, 280; 280, identifier:idx; 281, identifier:fs; 282, elif_clause; 282, 283; 282, 289; 283, comparison_operator:==; 283, 284; 283, 288; 284, call; 284, 285; 284, 286; 285, identifier:len; 286, argument_list; 286, 287; 287, identifier:over; 288, integer:1; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:times; 294, identifier:append; 295, argument_list; 295, 296; 296, binary_operator:/; 296, 297; 296, 303; 297, call; 297, 298; 297, 299; 298, identifier:float; 299, argument_list; 299, 300; 300, subscript; 300, 301; 300, 302; 301, identifier:over; 302, integer:0; 303, identifier:fs; 304, if_statement; 304, 305; 304, 311; 304, 317; 305, comparison_operator:>; 305, 306; 305, 310; 306, call; 306, 307; 306, 308; 307, identifier:len; 308, argument_list; 308, 309; 309, identifier:times; 310, integer:0; 311, block; 311, 312; 312, return_statement; 312, 313; 313, call; 313, 314; 313, 315; 314, identifier:refractory; 315, argument_list; 315, 316; 316, identifier:times; 317, else_clause; 317, 318; 318, block; 318, 319; 319, return_statement; 319, 320; 320, identifier:times | def spike_times(signal, threshold, fs, absval=True):
"""Detect spikes from a given signal
:param signal: Spike trace recording (vector)
:type signal: numpy array
:param threshold: Threshold value to determine spikes
:type threshold: float
:param absval: Whether to apply absolute value to signal before thresholding
:type absval: bool
:returns: list(float) of spike times in seconds
For every continuous set of points over given threshold,
returns the time of the maximum"""
times = []
if absval:
signal = np.abs(signal)
over, = np.where(signal>threshold)
segments, = np.where(np.diff(over) > 1)
if len(over) > 1:
if len(segments) == 0:
segments = [0, len(over)-1]
else:
# add end points to sections for looping
if segments[0] != 0:
segments = np.insert(segments, [0], [0])
else:
#first point in singleton
times.append(float(over[0])/fs)
if 1 not in segments:
# make sure that first point is in there
segments[0] = 1
if segments[-1] != len(over)-1:
segments = np.insert(segments, [len(segments)], [len(over)-1])
else:
times.append(float(over[-1])/fs)
for iseg in range(1,len(segments)):
if segments[iseg] - segments[iseg-1] == 1:
# only single point over threshold
idx = over[segments[iseg]]
else:
segments[0] = segments[0]-1
# find maximum of continuous set over max
idx = over[segments[iseg-1]+1] + np.argmax(signal[over[segments[iseg-1]+1]:over[segments[iseg]]])
times.append(float(idx)/fs)
elif len(over) == 1:
times.append(float(over[0])/fs)
if len(times)>0:
return refractory(times)
else:
return times |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:bin_spikes; 3, parameters; 3, 4; 3, 5; 4, identifier:spike_times; 5, identifier:binsz; 6, block; 6, 7; 6, 9; 6, 25; 6, 54; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:bins; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:empty; 16, argument_list; 16, 17; 16, 22; 17, tuple; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, identifier:spike_times; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:dtype; 24, identifier:int; 25, for_statement; 25, 26; 25, 29; 25, 33; 25, 34; 26, pattern_list; 26, 27; 26, 28; 27, identifier:i; 28, identifier:stime; 29, call; 29, 30; 29, 31; 30, identifier:enumerate; 31, argument_list; 31, 32; 32, identifier:spike_times; 33, comment; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:bins; 39, identifier:i; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:np; 43, identifier:floor; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:np; 48, identifier:around; 49, argument_list; 49, 50; 49, 53; 50, binary_operator:/; 50, 51; 50, 52; 51, identifier:stime; 52, identifier:binsz; 53, integer:5; 54, return_statement; 54, 55; 55, identifier:bins | def bin_spikes(spike_times, binsz):
"""Sort spike times into bins
:param spike_times: times of spike instances
:type spike_times: list
:param binsz: length of time bin to use
:type binsz: float
:returns: list of bin indicies, one for each element in spike_times
"""
bins = np.empty((len(spike_times),), dtype=int)
for i, stime in enumerate(spike_times):
# around to fix rounding errors
bins[i] = np.floor(np.around(stime/binsz, 5))
return bins |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:corewriter; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 257; 5, 258; 5, 304; 5, 305; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:printtime; 11, argument_list; 11, 12; 11, 13; 12, string:'Creating core allele files'; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:start; 16, for_statement; 16, 17; 16, 18; 16, 24; 17, identifier:gene; 18, call; 18, 19; 18, 20; 19, identifier:sorted; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:genesequence; 24, block; 24, 25; 24, 34; 24, 35; 24, 54; 24, 55; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:geneset; 31, identifier:add; 32, argument_list; 32, 33; 33, identifier:gene; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:genefile; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:path; 43, identifier:join; 44, argument_list; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:coregenelocation; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, string:'{}.fasta'; 51, identifier:format; 52, argument_list; 52, 53; 53, identifier:gene; 54, comment; 55, if_statement; 55, 56; 55, 65; 55, 188; 56, not_operator; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:os; 61, identifier:path; 62, identifier:isfile; 63, argument_list; 63, 64; 64, identifier:genefile; 65, block; 65, 66; 66, with_statement; 66, 67; 66, 77; 67, with_clause; 67, 68; 68, with_item; 68, 69; 69, as_pattern; 69, 70; 69, 75; 70, call; 70, 71; 70, 72; 71, identifier:open; 72, argument_list; 72, 73; 72, 74; 73, identifier:genefile; 74, string:'w'; 75, as_pattern_target; 75, 76; 76, identifier:core; 77, block; 77, 78; 78, for_statement; 78, 79; 78, 82; 78, 90; 78, 91; 78, 92; 79, pattern_list; 79, 80; 79, 81; 80, identifier:count; 81, identifier:sequence; 82, call; 82, 83; 82, 84; 83, identifier:enumerate; 84, argument_list; 84, 85; 85, subscript; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:genesequence; 89, identifier:gene; 90, comment; 91, comment; 92, block; 92, 93; 92, 105; 92, 106; 92, 124; 92, 125; 92, 134; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:definitionline; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:'{}-{}'; 99, identifier:format; 100, argument_list; 100, 101; 100, 102; 101, identifier:gene; 102, binary_operator:+; 102, 103; 102, 104; 103, identifier:count; 104, integer:1; 105, comment; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:fasta; 109, call; 109, 110; 109, 111; 110, identifier:SeqRecord; 111, argument_list; 111, 112; 111, 116; 111, 117; 111, 120; 111, 121; 112, call; 112, 113; 112, 114; 113, identifier:Seq; 114, argument_list; 114, 115; 115, identifier:sequence; 116, comment; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:description; 119, string:''; 120, comment; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:id; 123, identifier:definitionline; 124, comment; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:SeqIO; 129, identifier:write; 130, argument_list; 130, 131; 130, 132; 130, 133; 131, identifier:fasta; 132, identifier:core; 133, string:'fasta'; 134, for_statement; 134, 135; 134, 136; 134, 141; 134, 142; 134, 143; 135, identifier:strain; 136, subscript; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:coresequence; 140, identifier:sequence; 141, comment; 142, comment; 143, block; 143, 144; 144, try_statement; 144, 145; 144, 167; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 160; 148, attribute; 148, 149; 148, 159; 149, subscript; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:corealleles; 153, subscript; 153, 154; 153, 155; 154, identifier:strain; 155, slice; 155, 156; 155, 157; 156, colon; 157, unary_operator:-; 157, 158; 158, integer:6; 159, identifier:update; 160, argument_list; 160, 161; 161, dictionary; 161, 162; 162, pair; 162, 163; 162, 164; 163, identifier:gene; 164, binary_operator:+; 164, 165; 164, 166; 165, identifier:count; 166, integer:1; 167, except_clause; 167, 168; 167, 169; 168, identifier:KeyError; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 182; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:corealleles; 176, subscript; 176, 177; 176, 178; 177, identifier:strain; 178, slice; 178, 179; 178, 180; 179, colon; 180, unary_operator:-; 180, 181; 181, integer:6; 182, dictionary; 182, 183; 183, pair; 183, 184; 183, 185; 184, identifier:gene; 185, binary_operator:+; 185, 186; 185, 187; 186, identifier:count; 187, integer:1; 188, else_clause; 188, 189; 188, 190; 189, comment; 190, block; 190, 191; 191, for_statement; 191, 192; 191, 195; 191, 203; 192, pattern_list; 192, 193; 192, 194; 193, identifier:count; 194, identifier:sequence; 195, call; 195, 196; 195, 197; 196, identifier:enumerate; 197, argument_list; 197, 198; 198, subscript; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:genesequence; 202, identifier:gene; 203, block; 203, 204; 204, for_statement; 204, 205; 204, 206; 204, 211; 204, 212; 205, identifier:strain; 206, subscript; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:coresequence; 210, identifier:sequence; 211, comment; 212, block; 212, 213; 213, try_statement; 213, 214; 213, 236; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 229; 217, attribute; 217, 218; 217, 228; 218, subscript; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:corealleles; 222, subscript; 222, 223; 222, 224; 223, identifier:strain; 224, slice; 224, 225; 224, 226; 225, colon; 226, unary_operator:-; 226, 227; 227, integer:6; 228, identifier:update; 229, argument_list; 229, 230; 230, dictionary; 230, 231; 231, pair; 231, 232; 231, 233; 232, identifier:gene; 233, binary_operator:+; 233, 234; 233, 235; 234, identifier:count; 235, integer:1; 236, except_clause; 236, 237; 236, 238; 237, identifier:KeyError; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 251; 241, subscript; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:corealleles; 245, subscript; 245, 246; 245, 247; 246, identifier:strain; 247, slice; 247, 248; 247, 249; 248, colon; 249, unary_operator:-; 249, 250; 250, integer:6; 251, dictionary; 251, 252; 252, pair; 252, 253; 252, 254; 253, identifier:gene; 254, binary_operator:+; 254, 255; 254, 256; 255, identifier:count; 256, integer:1; 257, comment; 258, if_statement; 258, 259; 258, 278; 259, not_operator; 259, 260; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:os; 264, identifier:path; 265, identifier:isfile; 266, argument_list; 266, 267; 267, call; 267, 268; 267, 273; 268, attribute; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:os; 271, identifier:path; 272, identifier:join; 273, argument_list; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:coregenelocation; 277, string:'core_combined.fasta'; 278, block; 278, 279; 278, 296; 278, 297; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:fastafiles; 282, call; 282, 283; 282, 284; 283, identifier:glob; 284, argument_list; 284, 285; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:os; 289, identifier:path; 290, identifier:join; 291, argument_list; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:coregenelocation; 295, string:'*.fasta'; 296, comment; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:combinealleles; 302, argument_list; 302, 303; 303, identifier:fastafiles; 304, comment; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:self; 309, identifier:profiler; 310, argument_list | def corewriter(self):
"""
Creates .fasta files containing all alleles for each gene
"""
printtime('Creating core allele files', self.start)
for gene in sorted(self.genesequence):
self.geneset.add(gene)
# Set the name of the allele file
genefile = os.path.join(self.coregenelocation, '{}.fasta'.format(gene))
# If the file doesn't exist, create it
if not os.path.isfile(genefile):
with open(genefile, 'w') as core:
for count, sequence in enumerate(self.genesequence[gene]):
# The definition line is the gene name, and the allele number (count (+ 1 to compensate for
# base zero))
definitionline = '{}-{}'.format(gene, count + 1)
# Create a sequence record using BioPython
fasta = SeqRecord(Seq(sequence),
# Without this, the header will be improperly formatted
description='',
# Use >:definitionline as the header
id=definitionline)
# Use the SeqIO module to properly format the new sequence record
SeqIO.write(fasta, core, 'fasta')
for strain in self.coresequence[sequence]:
# Record the strain name, the gene name, and the allele number.
# [:-6] removes the contig number: 2014-SEQ-0276_00001 becomes 2014-SEQ-0276
try:
self.corealleles[strain[:-6]].update({gene: count + 1})
except KeyError:
self.corealleles[strain[:-6]] = {gene: count + 1}
else:
# If the file exists, don't recreate it; only iterate through the dictionary of gene sequences
for count, sequence in enumerate(self.genesequence[gene]):
for strain in self.coresequence[sequence]:
# Populate the dictionary as above
try:
self.corealleles[strain[:-6]].update({gene: count + 1})
except KeyError:
self.corealleles[strain[:-6]] = {gene: count + 1}
# Create a combined file of all the core genes to be used in typing strain(s) of interest
if not os.path.isfile(os.path.join(self.coregenelocation, 'core_combined.fasta')):
fastafiles = glob(os.path.join(self.coregenelocation, '*.fasta'))
# Run the method for each allele
self.combinealleles(fastafiles)
# Run the profiler
self.profiler() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:profiler; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 17; 5, 18; 5, 48; 5, 49; 5, 68; 5, 72; 5, 158; 5, 159; 5, 195; 5, 196; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:printtime; 11, argument_list; 11, 12; 11, 13; 12, string:'Calculating core profiles'; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:start; 16, comment; 17, comment; 18, for_statement; 18, 19; 18, 20; 18, 23; 18, 24; 19, identifier:strain; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:corealleles; 23, comment; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:coreset; 31, identifier:add; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:tuple; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:sorted; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 47; 40, attribute; 40, 41; 40, 46; 41, subscript; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:corealleles; 45, identifier:strain; 46, identifier:items; 47, argument_list; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:header; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, string:'ST,{}\n'; 55, identifier:format; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, string:','; 60, identifier:join; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:geneset; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:data; 71, string:''; 72, for_statement; 72, 73; 72, 76; 72, 85; 72, 86; 73, pattern_list; 73, 74; 73, 75; 74, identifier:count; 75, identifier:core; 76, call; 76, 77; 76, 78; 77, identifier:sorted; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:enumerate; 81, argument_list; 81, 82; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:coreset; 85, comment; 86, block; 86, 87; 86, 91; 86, 92; 86, 101; 86, 102; 86, 135; 86, 136; 86, 154; 87, expression_statement; 87, 88; 88, augmented_assignment:+=; 88, 89; 88, 90; 89, identifier:count; 90, integer:1; 91, comment; 92, expression_statement; 92, 93; 93, augmented_assignment:+=; 93, 94; 93, 95; 94, identifier:data; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, string:'{}'; 98, identifier:format; 99, argument_list; 99, 100; 100, identifier:count; 101, comment; 102, for_statement; 102, 103; 102, 104; 102, 107; 103, identifier:strain; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:corealleles; 107, block; 107, 108; 108, if_statement; 108, 109; 108, 126; 109, comparison_operator:==; 109, 110; 109, 125; 110, call; 110, 111; 110, 112; 111, identifier:tuple; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:sorted; 115, argument_list; 115, 116; 116, call; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:corealleles; 122, identifier:strain; 123, identifier:items; 124, argument_list; 125, identifier:core; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:profiles; 133, identifier:strain; 134, identifier:count; 135, comment; 136, for_statement; 136, 137; 136, 138; 136, 142; 137, identifier:gene; 138, call; 138, 139; 138, 140; 139, identifier:sorted; 140, argument_list; 140, 141; 141, identifier:core; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, augmented_assignment:+=; 144, 145; 144, 146; 145, identifier:data; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, string:',{}'; 149, identifier:format; 150, argument_list; 150, 151; 151, subscript; 151, 152; 151, 153; 152, identifier:gene; 153, integer:1; 154, expression_statement; 154, 155; 155, augmented_assignment:+=; 155, 156; 155, 157; 156, identifier:data; 157, string:'\n'; 158, comment; 159, with_statement; 159, 160; 159, 180; 160, with_clause; 160, 161; 161, with_item; 161, 162; 162, as_pattern; 162, 163; 162, 178; 163, call; 163, 164; 163, 165; 164, identifier:open; 165, argument_list; 165, 166; 165, 177; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:os; 170, identifier:path; 171, identifier:join; 172, argument_list; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:profilelocation; 176, string:'profile.txt'; 177, string:'w'; 178, as_pattern_target; 178, 179; 179, identifier:profile; 180, block; 180, 181; 180, 188; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:profile; 185, identifier:write; 186, argument_list; 186, 187; 187, identifier:header; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:profile; 192, identifier:write; 193, argument_list; 193, 194; 194, identifier:data; 195, comment; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:linker; 201, argument_list | def profiler(self):
"""
Calculates the core profile for each strain
"""
printtime('Calculating core profiles', self.start)
# Only create the profile if it doesn't exist already
# if not os.path.isfile('{}/profile.txt'.format(self.profilelocation)):
for strain in self.corealleles:
# Add the gene name and allele number pair for each core gene in each strain
self.coreset.add(tuple(sorted(self.corealleles[strain].items())))
# Set the header to be similar to an MLST profile - ST,gene1,gene2,etc
header = 'ST,{}\n'.format(','.join(sorted(self.geneset)))
data = ''
for count, core in sorted(enumerate(self.coreset)):
# Increment count now to account for 0-based numbering
count += 1
# Add the sequence type number to the profile
data += '{}'.format(count)
# Store the sequence type for each strain
for strain in self.corealleles:
if tuple(sorted(self.corealleles[strain].items())) == core:
self.profiles[strain] = count
# Add the allele number for each gene
for gene in sorted(core):
data += ',{}'.format(gene[1])
data += '\n'
# Write the profile
with open(os.path.join(self.profilelocation, 'profile.txt'), 'w') as profile:
profile.write(header)
profile.write(data)
# Create a list of which strains correspond to the sequence types
self.linker() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:row2dict; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:row; 5, default_parameter; 5, 6; 5, 7; 6, identifier:depth; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:exclude; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:exclude_pk; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:exclude_underscore; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:only; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:fk_suffix; 22, None; 23, block; 23, 24; 23, 26; 23, 33; 23, 44; 23, 66; 23, 80; 23, 94; 23, 108; 23, 122; 23, 136; 23, 194; 23, 308; 24, expression_statement; 24, 25; 25, comment; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:depth; 29, integer:0; 30, block; 30, 31; 31, return_statement; 31, 32; 32, None; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, pattern_list; 35, 36; 35, 37; 36, identifier:d; 37, identifier:mapper; 38, expression_list; 38, 39; 38, 40; 39, dictionary; 40, call; 40, 41; 40, 42; 41, identifier:get_mapper; 42, argument_list; 42, 43; 43, identifier:row; 44, if_statement; 44, 45; 44, 48; 44, 60; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:depth; 47, None; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:depth; 52, binary_operator:-; 52, 53; 52, 59; 53, call; 53, 54; 53, 55; 54, identifier:getattr; 55, argument_list; 55, 56; 55, 57; 55, 58; 56, identifier:row; 57, identifier:ATTR_DEPTH; 58, identifier:DEFAULT_DEPTH; 59, integer:1; 60, else_clause; 60, 61; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, augmented_assignment:-=; 63, 64; 63, 65; 64, identifier:depth; 65, integer:1; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:exclude; 69, None; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:exclude; 74, call; 74, 75; 74, 76; 75, identifier:getattr; 76, argument_list; 76, 77; 76, 78; 76, 79; 77, identifier:row; 78, identifier:ATTR_EXCLUDE; 79, identifier:DEFAULT_EXCLUDE; 80, if_statement; 80, 81; 80, 84; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:exclude_pk; 83, None; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:exclude_pk; 88, call; 88, 89; 88, 90; 89, identifier:getattr; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:row; 92, identifier:ATTR_EXCLUDE_PK; 93, identifier:DEFAULT_EXCLUDE_PK; 94, if_statement; 94, 95; 94, 98; 95, comparison_operator:is; 95, 96; 95, 97; 96, identifier:exclude_underscore; 97, None; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:exclude_underscore; 102, call; 102, 103; 102, 104; 103, identifier:getattr; 104, argument_list; 104, 105; 104, 106; 104, 107; 105, identifier:row; 106, identifier:ATTR_EXCLUDE_UNDERSCORE; 107, identifier:DEFAULT_EXCLUDE_UNDERSCORE; 108, if_statement; 108, 109; 108, 112; 109, comparison_operator:is; 109, 110; 109, 111; 110, identifier:only; 111, None; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:only; 116, call; 116, 117; 116, 118; 117, identifier:getattr; 118, argument_list; 118, 119; 118, 120; 118, 121; 119, identifier:row; 120, identifier:ATTR_ONLY; 121, identifier:DEFAULT_ONLY; 122, if_statement; 122, 123; 122, 126; 123, comparison_operator:is; 123, 124; 123, 125; 124, identifier:fk_suffix; 125, None; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:fk_suffix; 130, call; 130, 131; 130, 132; 131, identifier:getattr; 132, argument_list; 132, 133; 132, 134; 132, 135; 133, identifier:row; 134, identifier:ATTR_FK_SUFFIX; 135, identifier:DEFAULT_FK_SUFFIX; 136, for_statement; 136, 137; 136, 138; 136, 153; 137, identifier:c; 138, binary_operator:+; 138, 139; 138, 146; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:mapper; 143, identifier:columns; 144, identifier:keys; 145, argument_list; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:mapper; 150, identifier:synonyms; 151, identifier:keys; 152, argument_list; 153, block; 153, 154; 153, 184; 154, if_statement; 154, 155; 154, 182; 155, boolean_operator:or; 155, 156; 155, 176; 155, 177; 156, boolean_operator:or; 156, 157; 156, 170; 156, 171; 157, boolean_operator:or; 157, 158; 157, 161; 157, 162; 158, comparison_operator:in; 158, 159; 158, 160; 159, identifier:c; 160, identifier:exclude; 161, line_continuation:\; 162, call; 162, 163; 162, 164; 163, identifier:check_exclude_pk; 164, argument_list; 164, 165; 164, 166; 164, 167; 165, identifier:c; 166, identifier:exclude_pk; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:fk_suffix; 169, identifier:fk_suffix; 170, line_continuation:\; 171, call; 171, 172; 171, 173; 172, identifier:check_exclude_underscore; 173, argument_list; 173, 174; 173, 175; 174, identifier:c; 175, identifier:exclude_underscore; 176, line_continuation:\; 177, call; 177, 178; 177, 179; 178, identifier:check_only; 179, argument_list; 179, 180; 179, 181; 180, identifier:c; 181, identifier:only; 182, block; 182, 183; 183, continue_statement; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:d; 188, identifier:c; 189, call; 189, 190; 189, 191; 190, identifier:getattr; 191, argument_list; 191, 192; 191, 193; 192, identifier:row; 193, identifier:c; 194, for_statement; 194, 195; 194, 196; 194, 203; 195, identifier:r; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:mapper; 200, identifier:relationships; 201, identifier:keys; 202, argument_list; 203, block; 203, 204; 203, 216; 203, 224; 203, 235; 203, 245; 203, 269; 204, if_statement; 204, 205; 204, 214; 205, boolean_operator:or; 205, 206; 205, 209; 206, comparison_operator:in; 206, 207; 206, 208; 207, identifier:r; 208, identifier:exclude; 209, call; 209, 210; 209, 211; 210, identifier:check_only; 211, argument_list; 211, 212; 211, 213; 212, identifier:r; 213, identifier:only; 214, block; 214, 215; 215, continue_statement; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:attr; 219, call; 219, 220; 219, 221; 220, identifier:getattr; 221, argument_list; 221, 222; 221, 223; 222, identifier:row; 223, identifier:r; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:backref; 227, call; 227, 228; 227, 229; 228, identifier:get_backref; 229, argument_list; 229, 230; 230, subscript; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:mapper; 233, identifier:relationships; 234, identifier:r; 235, if_statement; 235, 236; 235, 237; 236, identifier:backref; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:exclude; 242, identifier:add; 243, argument_list; 243, 244; 244, identifier:backref; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:kwargs; 248, call; 248, 249; 248, 250; 249, identifier:dict; 250, argument_list; 250, 251; 250, 254; 250, 257; 250, 260; 250, 263; 250, 266; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:depth; 253, identifier:depth; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:exclude; 256, identifier:exclude; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:exclude_pk; 259, identifier:exclude_pk; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:exclude_underscore; 262, identifier:exclude_underscore; 263, keyword_argument; 263, 264; 263, 265; 264, identifier:only; 265, identifier:only; 266, keyword_argument; 266, 267; 266, 268; 267, identifier:fk_suffix; 268, identifier:fk_suffix; 269, if_statement; 269, 270; 269, 277; 269, 295; 270, call; 270, 271; 270, 272; 271, identifier:isinstance; 272, argument_list; 272, 273; 272, 274; 273, identifier:attr; 274, attribute; 274, 275; 274, 276; 275, identifier:collections; 276, identifier:InstrumentedList; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:d; 282, identifier:r; 283, list_comprehension; 283, 284; 283, 290; 283, 293; 284, call; 284, 285; 284, 286; 285, identifier:row2dict; 286, argument_list; 286, 287; 286, 288; 287, identifier:i; 288, dictionary_splat; 288, 289; 289, identifier:kwargs; 290, for_in_clause; 290, 291; 290, 292; 291, identifier:i; 292, identifier:attr; 293, if_clause; 293, 294; 294, identifier:depth; 295, else_clause; 295, 296; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, subscript; 299, 300; 299, 301; 300, identifier:d; 301, identifier:r; 302, call; 302, 303; 302, 304; 303, identifier:row2dict; 304, argument_list; 304, 305; 304, 306; 305, identifier:attr; 306, dictionary_splat; 306, 307; 307, identifier:kwargs; 308, return_statement; 308, 309; 309, identifier:d | def row2dict(row, depth=None, exclude=None, exclude_pk=None,
exclude_underscore=None, only=None, fk_suffix=None):
"""
Recursively walk row attributes to serialize ones into a dict.
:param row: instance of the declarative base class
:param depth: number that represent the depth of related relationships
:param exclude: set of attributes names to exclude
:param exclude_pk: are foreign keys (e.g. fk_name_id) excluded
:param exclude_underscore: are private and protected attributes excluded
:param only: set of attributes names to include
:param fk_suffix: str that represent a foreign key suffix
:return: dict with attributes of current depth level
"""
if depth == 0:
return None
d, mapper = {}, get_mapper(row)
if depth is None:
depth = getattr(row, ATTR_DEPTH, DEFAULT_DEPTH) - 1
else:
depth -= 1
if exclude is None:
exclude = getattr(row, ATTR_EXCLUDE, DEFAULT_EXCLUDE)
if exclude_pk is None:
exclude_pk = getattr(row, ATTR_EXCLUDE_PK, DEFAULT_EXCLUDE_PK)
if exclude_underscore is None:
exclude_underscore = getattr(row, ATTR_EXCLUDE_UNDERSCORE,
DEFAULT_EXCLUDE_UNDERSCORE)
if only is None:
only = getattr(row, ATTR_ONLY, DEFAULT_ONLY)
if fk_suffix is None:
fk_suffix = getattr(row, ATTR_FK_SUFFIX, DEFAULT_FK_SUFFIX)
for c in mapper.columns.keys() + mapper.synonyms.keys():
if c in exclude or \
check_exclude_pk(c, exclude_pk, fk_suffix=fk_suffix) or \
check_exclude_underscore(c, exclude_underscore) or \
check_only(c, only):
continue
d[c] = getattr(row, c)
for r in mapper.relationships.keys():
if r in exclude or check_only(r, only):
continue
attr = getattr(row, r)
backref = get_backref(mapper.relationships[r])
if backref:
exclude.add(backref)
kwargs = dict(depth=depth, exclude=exclude, exclude_pk=exclude_pk,
exclude_underscore=exclude_underscore, only=only,
fk_suffix=fk_suffix)
if isinstance(attr, collections.InstrumentedList):
d[r] = [row2dict(i, **kwargs) for i in attr if depth]
else:
d[r] = row2dict(attr, **kwargs)
return d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:dict2row; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 4, identifier:d; 5, identifier:model; 6, default_parameter; 6, 7; 6, 8; 7, identifier:rel; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:exclude; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:exclude_pk; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:exclude_underscore; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:only; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:fk_suffix; 23, None; 24, block; 24, 25; 24, 27; 24, 47; 24, 53; 24, 60; 24, 74; 24, 88; 24, 102; 24, 116; 24, 130; 24, 144; 24, 205; 24, 352; 25, expression_statement; 25, 26; 26, comment; 27, if_statement; 27, 28; 27, 34; 28, not_operator; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:d; 33, identifier:dict; 34, block; 34, 35; 35, raise_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:TypeError; 38, argument_list; 38, 39; 39, binary_operator:%; 39, 40; 39, 41; 40, string:'Source must be instance of dict, got %s instead'; 41, attribute; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:type; 44, argument_list; 44, 45; 45, identifier:d; 46, identifier:__name__; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:row; 50, call; 50, 51; 50, 52; 51, identifier:model; 52, argument_list; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:mapper; 56, call; 56, 57; 56, 58; 57, identifier:get_mapper; 58, argument_list; 58, 59; 59, identifier:row; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:rel; 63, None; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:rel; 68, call; 68, 69; 68, 70; 69, identifier:getattr; 70, argument_list; 70, 71; 70, 72; 70, 73; 71, identifier:row; 72, identifier:ATTR_REL; 73, identifier:DEFAULT_REL; 74, if_statement; 74, 75; 74, 78; 75, comparison_operator:is; 75, 76; 75, 77; 76, identifier:exclude; 77, None; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:exclude; 82, call; 82, 83; 82, 84; 83, identifier:getattr; 84, argument_list; 84, 85; 84, 86; 84, 87; 85, identifier:row; 86, identifier:ATTR_EXCLUDE; 87, identifier:DEFAULT_EXCLUDE; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:exclude_pk; 91, None; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:exclude_pk; 96, call; 96, 97; 96, 98; 97, identifier:getattr; 98, argument_list; 98, 99; 98, 100; 98, 101; 99, identifier:row; 100, identifier:ATTR_EXCLUDE_PK; 101, identifier:DEFAULT_EXCLUDE_PK; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:exclude_underscore; 105, None; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:exclude_underscore; 110, call; 110, 111; 110, 112; 111, identifier:getattr; 112, argument_list; 112, 113; 112, 114; 112, 115; 113, identifier:row; 114, identifier:ATTR_EXCLUDE_UNDERSCORE; 115, identifier:DEFAULT_EXCLUDE_UNDERSCORE; 116, if_statement; 116, 117; 116, 120; 117, comparison_operator:is; 117, 118; 117, 119; 118, identifier:only; 119, None; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:only; 124, call; 124, 125; 124, 126; 125, identifier:getattr; 126, argument_list; 126, 127; 126, 128; 126, 129; 127, identifier:row; 128, identifier:ATTR_ONLY; 129, identifier:DEFAULT_ONLY; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:is; 131, 132; 131, 133; 132, identifier:fk_suffix; 133, None; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:fk_suffix; 138, call; 138, 139; 138, 140; 139, identifier:getattr; 140, argument_list; 140, 141; 140, 142; 140, 143; 141, identifier:row; 142, identifier:ATTR_FK_SUFFIX; 143, identifier:DEFAULT_FK_SUFFIX; 144, for_statement; 144, 145; 144, 146; 144, 161; 145, identifier:c; 146, binary_operator:+; 146, 147; 146, 154; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:mapper; 151, identifier:columns; 152, identifier:keys; 153, argument_list; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:mapper; 158, identifier:synonyms; 159, identifier:keys; 160, argument_list; 161, block; 161, 162; 161, 196; 162, if_statement; 162, 163; 162, 194; 163, boolean_operator:or; 163, 164; 163, 188; 163, 189; 164, boolean_operator:or; 164, 165; 164, 182; 164, 183; 165, boolean_operator:or; 165, 166; 165, 173; 165, 174; 166, boolean_operator:or; 166, 167; 166, 170; 167, comparison_operator:not; 167, 168; 167, 169; 168, identifier:c; 169, identifier:d; 170, comparison_operator:in; 170, 171; 170, 172; 171, identifier:c; 172, identifier:exclude; 173, line_continuation:\; 174, call; 174, 175; 174, 176; 175, identifier:check_exclude_pk; 176, argument_list; 176, 177; 176, 178; 176, 179; 177, identifier:c; 178, identifier:exclude_pk; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:fk_suffix; 181, identifier:fk_suffix; 182, line_continuation:\; 183, call; 183, 184; 183, 185; 184, identifier:check_exclude_underscore; 185, argument_list; 185, 186; 185, 187; 186, identifier:c; 187, identifier:exclude_underscore; 188, line_continuation:\; 189, call; 189, 190; 189, 191; 190, identifier:check_only; 191, argument_list; 191, 192; 191, 193; 192, identifier:c; 193, identifier:only; 194, block; 194, 195; 195, continue_statement; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:setattr; 199, argument_list; 199, 200; 199, 201; 199, 202; 200, identifier:row; 201, identifier:c; 202, subscript; 202, 203; 202, 204; 203, identifier:d; 204, identifier:c; 205, for_statement; 205, 206; 205, 207; 205, 214; 206, identifier:r; 207, call; 207, 208; 207, 213; 208, attribute; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:mapper; 211, identifier:relationships; 212, identifier:keys; 213, argument_list; 214, block; 214, 215; 214, 231; 214, 255; 215, if_statement; 215, 216; 215, 229; 216, boolean_operator:or; 216, 217; 216, 224; 217, boolean_operator:or; 217, 218; 217, 221; 218, comparison_operator:not; 218, 219; 218, 220; 219, identifier:r; 220, identifier:d; 221, comparison_operator:not; 221, 222; 221, 223; 222, identifier:r; 223, identifier:rel; 224, call; 224, 225; 224, 226; 225, identifier:check_only; 226, argument_list; 226, 227; 226, 228; 227, identifier:r; 228, identifier:only; 229, block; 229, 230; 230, continue_statement; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:kwargs; 234, call; 234, 235; 234, 236; 235, identifier:dict; 236, argument_list; 236, 237; 236, 240; 236, 243; 236, 246; 236, 249; 236, 252; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:rel; 239, identifier:rel; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:exclude; 242, identifier:exclude; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:exclude_pk; 245, identifier:exclude_pk; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:exclude_underscore; 248, identifier:exclude_underscore; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:only; 251, identifier:only; 252, keyword_argument; 252, 253; 252, 254; 253, identifier:fk_suffix; 254, identifier:fk_suffix; 255, if_statement; 255, 256; 255, 263; 255, 300; 256, call; 256, 257; 256, 258; 257, identifier:isinstance; 258, argument_list; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:d; 261, identifier:r; 262, identifier:list; 263, block; 263, 264; 263, 275; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:setattr; 267, argument_list; 267, 268; 267, 269; 267, 270; 268, identifier:row; 269, identifier:r; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:collections; 273, identifier:InstrumentedList; 274, argument_list; 275, for_statement; 275, 276; 275, 277; 275, 280; 276, identifier:i; 277, subscript; 277, 278; 277, 279; 278, identifier:d; 279, identifier:r; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 290; 283, attribute; 283, 284; 283, 289; 284, call; 284, 285; 284, 286; 285, identifier:getattr; 286, argument_list; 286, 287; 286, 288; 287, identifier:row; 288, identifier:r; 289, identifier:append; 290, argument_list; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:dict2row; 293, argument_list; 293, 294; 293, 295; 293, 298; 294, identifier:i; 295, subscript; 295, 296; 295, 297; 296, identifier:rel; 297, identifier:r; 298, dictionary_splat; 298, 299; 299, identifier:kwargs; 300, else_clause; 300, 301; 301, block; 301, 302; 301, 335; 302, if_statement; 302, 303; 302, 305; 303, not_operator; 303, 304; 304, identifier:exclude_pk; 305, block; 305, 306; 305, 326; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:rpk; 309, conditional_expression:if; 309, 310; 309, 318; 309, 325; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, subscript; 312, 313; 312, 314; 313, identifier:d; 314, identifier:r; 315, identifier:get; 316, argument_list; 316, 317; 317, string:'id'; 318, call; 318, 319; 318, 320; 319, identifier:isinstance; 320, argument_list; 320, 321; 320, 324; 321, subscript; 321, 322; 321, 323; 322, identifier:d; 323, identifier:r; 324, identifier:dict; 325, None; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 329; 328, identifier:setattr; 329, argument_list; 329, 330; 329, 331; 329, 334; 330, identifier:row; 331, binary_operator:+; 331, 332; 331, 333; 332, identifier:r; 333, identifier:fk_suffix; 334, identifier:rpk; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:setattr; 338, argument_list; 338, 339; 338, 340; 338, 341; 339, identifier:row; 340, identifier:r; 341, call; 341, 342; 341, 343; 342, identifier:dict2row; 343, argument_list; 343, 344; 343, 347; 343, 350; 344, subscript; 344, 345; 344, 346; 345, identifier:d; 346, identifier:r; 347, subscript; 347, 348; 347, 349; 348, identifier:rel; 349, identifier:r; 350, dictionary_splat; 350, 351; 351, identifier:kwargs; 352, return_statement; 352, 353; 353, identifier:row | def dict2row(d, model, rel=None, exclude=None, exclude_pk=None,
exclude_underscore=None, only=None, fk_suffix=None):
"""
Recursively walk dict attributes to serialize ones into a row.
:param d: dict that represent a serialized row
:param model: class nested from the declarative base class
:param rel: dict of key (relationship name) -value (class) pairs
:param exclude: set of attributes names to exclude
:param exclude_pk: are foreign keys (e.g. fk_name_id) excluded
:param exclude_underscore: are private and protected attributes excluded
:param only: set of attributes names to include
:param fk_suffix: str that represent a foreign key suffix
:return: instance of the declarative base class
"""
if not isinstance(d, dict):
raise TypeError('Source must be instance of dict, got %s instead' %
type(d).__name__)
row = model()
mapper = get_mapper(row)
if rel is None:
rel = getattr(row, ATTR_REL, DEFAULT_REL)
if exclude is None:
exclude = getattr(row, ATTR_EXCLUDE, DEFAULT_EXCLUDE)
if exclude_pk is None:
exclude_pk = getattr(row, ATTR_EXCLUDE_PK, DEFAULT_EXCLUDE_PK)
if exclude_underscore is None:
exclude_underscore = getattr(row, ATTR_EXCLUDE_UNDERSCORE,
DEFAULT_EXCLUDE_UNDERSCORE)
if only is None:
only = getattr(row, ATTR_ONLY, DEFAULT_ONLY)
if fk_suffix is None:
fk_suffix = getattr(row, ATTR_FK_SUFFIX, DEFAULT_FK_SUFFIX)
for c in mapper.columns.keys() + mapper.synonyms.keys():
if c not in d or c in exclude or \
check_exclude_pk(c, exclude_pk, fk_suffix=fk_suffix) or \
check_exclude_underscore(c, exclude_underscore) or \
check_only(c, only):
continue
setattr(row, c, d[c])
for r in mapper.relationships.keys():
if r not in d or r not in rel or check_only(r, only):
continue
kwargs = dict(rel=rel, exclude=exclude, exclude_pk=exclude_pk,
exclude_underscore=exclude_underscore, only=only,
fk_suffix=fk_suffix)
if isinstance(d[r], list):
setattr(row, r, collections.InstrumentedList())
for i in d[r]:
getattr(row, r).append(dict2row(i, rel[r], **kwargs))
else:
if not exclude_pk:
rpk = d[r].get('id') if isinstance(d[r], dict) else None
setattr(row, r + fk_suffix, rpk)
setattr(row, r, dict2row(d[r], rel[r], **kwargs))
return row |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 75; 1, 77; 2, function_name:remote; 3, parameters; 3, 4; 3, 13; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 42; 3, 45; 3, 46; 3, 56; 3, 66; 3, 69; 3, 72; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:cmd; 6, type; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:arg; 9, argument_list; 9, 10; 10, keyword_argument; 10, 11; 10, 12; 11, identifier:container; 12, identifier:list; 13, identifier:host; 14, default_parameter; 14, 15; 14, 16; 15, identifier:user; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:port; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:sudo; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:run_as; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:shell; 28, string:'/bin/sh'; 29, default_parameter; 29, 30; 29, 31; 30, identifier:cd; 31, None; 32, typed_default_parameter; 32, 33; 32, 34; 32, 41; 33, identifier:environ; 34, type; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:arg; 37, argument_list; 37, 38; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:container; 40, identifier:dict; 41, None; 42, default_parameter; 42, 43; 42, 44; 43, identifier:paths; 44, tuple; 45, comment; 46, typed_default_parameter; 46, 47; 46, 48; 46, 55; 47, identifier:stdout; 48, type; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:arg; 51, argument_list; 51, 52; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:type; 54, identifier:StreamOptions; 55, None; 56, typed_default_parameter; 56, 57; 56, 58; 56, 65; 57, identifier:stderr; 58, type; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:arg; 61, argument_list; 61, 62; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:type; 64, identifier:StreamOptions; 65, None; 66, default_parameter; 66, 67; 66, 68; 67, identifier:echo; 68, False; 69, default_parameter; 69, 70; 69, 71; 70, identifier:raise_on_error; 71, True; 72, default_parameter; 72, 73; 72, 74; 73, identifier:dry_run; 74, False; 75, type; 75, 76; 76, identifier:Result; 77, block; 77, 78; 77, 80; 77, 98; 77, 103; 77, 118; 77, 132; 77, 146; 77, 150; 77, 176; 77, 185; 77, 189; 77, 206; 77, 232; 77, 254; 77, 261; 77, 270; 77, 281; 77, 290; 77, 297; 77, 306; 77, 314; 78, expression_statement; 78, 79; 79, comment; 80, if_statement; 80, 81; 80, 87; 81, not_operator; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:isinstance; 84, argument_list; 84, 85; 84, 86; 85, identifier:cmd; 86, identifier:str; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:cmd; 91, call; 91, 92; 91, 93; 92, identifier:flatten_args; 93, argument_list; 93, 94; 93, 95; 94, identifier:cmd; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:join; 97, True; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:ssh_options; 101, list:['-q']; 101, 102; 102, string:'-q'; 103, if_statement; 103, 104; 103, 110; 104, call; 104, 105; 104, 106; 105, identifier:isatty; 106, argument_list; 106, 107; 107, attribute; 107, 108; 107, 109; 108, identifier:sys; 109, identifier:stdin; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:ssh_options; 115, identifier:append; 116, argument_list; 116, 117; 117, string:'-t'; 118, if_statement; 118, 119; 118, 122; 119, comparison_operator:is; 119, 120; 119, 121; 120, identifier:port; 121, None; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:ssh_options; 127, identifier:extend; 128, argument_list; 128, 129; 129, tuple; 129, 130; 129, 131; 130, string:'-p'; 131, identifier:port; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:ssh_connection_str; 135, conditional_expression:if; 135, 136; 135, 144; 135, 145; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, string:'{user}@{host}'; 139, identifier:format_map; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:locals; 143, argument_list; 144, identifier:user; 145, identifier:host; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:remote_cmd; 149, list:[]; 150, if_statement; 150, 151; 150, 152; 150, 162; 151, identifier:sudo; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:remote_cmd; 157, identifier:extend; 158, argument_list; 158, 159; 159, tuple; 159, 160; 159, 161; 160, string:'sudo'; 161, string:'-H'; 162, elif_clause; 162, 163; 162, 164; 163, identifier:run_as; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:remote_cmd; 169, identifier:extend; 170, argument_list; 170, 171; 171, tuple; 171, 172; 171, 173; 171, 174; 171, 175; 172, string:'sudo'; 173, string:'-H'; 174, string:'-u'; 175, identifier:run_as; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:remote_cmd; 180, identifier:extend; 181, argument_list; 181, 182; 182, tuple; 182, 183; 182, 184; 183, identifier:shell; 184, string:'-c'; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:inner_cmd; 188, list:[]; 189, if_statement; 189, 190; 189, 191; 190, identifier:cd; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:inner_cmd; 196, identifier:append; 197, argument_list; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, string:'cd {cd}'; 201, identifier:format_map; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:locals; 205, argument_list; 206, if_statement; 206, 207; 206, 208; 207, identifier:environ; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:inner_cmd; 213, identifier:extend; 214, generator_expression; 214, 215; 214, 223; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, string:'export {k}="{v}"'; 218, identifier:format_map; 219, argument_list; 219, 220; 220, call; 220, 221; 220, 222; 221, identifier:locals; 222, argument_list; 223, for_in_clause; 223, 224; 223, 227; 224, pattern_list; 224, 225; 224, 226; 225, identifier:k; 226, identifier:v; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:environ; 230, identifier:items; 231, argument_list; 232, if_statement; 232, 233; 232, 234; 233, identifier:paths; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:inner_cmd; 239, identifier:append; 240, argument_list; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, string:'export PATH="{path}:$PATH"'; 244, identifier:format; 245, argument_list; 245, 246; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:path; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, string:':'; 251, identifier:join; 252, argument_list; 252, 253; 253, identifier:paths; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:inner_cmd; 258, identifier:append; 259, argument_list; 259, 260; 260, identifier:cmd; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:inner_cmd; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, string:' &&\n '; 267, identifier:join; 268, argument_list; 268, 269; 269, identifier:inner_cmd; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:inner_cmd; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, string:'\n {inner_cmd}\n'; 276, identifier:format_map; 277, argument_list; 277, 278; 278, call; 278, 279; 278, 280; 279, identifier:locals; 280, argument_list; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:inner_cmd; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:shlex; 287, identifier:quote; 288, argument_list; 288, 289; 289, identifier:inner_cmd; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:remote_cmd; 294, identifier:append; 295, argument_list; 295, 296; 296, identifier:inner_cmd; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:remote_cmd; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, string:' '; 303, identifier:join; 304, argument_list; 304, 305; 305, identifier:remote_cmd; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:args; 309, tuple; 309, 310; 309, 311; 309, 312; 309, 313; 310, string:'ssh'; 311, identifier:ssh_options; 312, identifier:ssh_connection_str; 313, identifier:remote_cmd; 314, return_statement; 314, 315; 315, call; 315, 316; 315, 317; 316, identifier:local; 317, argument_list; 317, 318; 317, 319; 317, 322; 317, 325; 317, 328; 317, 331; 318, identifier:args; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:stdout; 321, identifier:stdout; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:stderr; 324, identifier:stderr; 325, keyword_argument; 325, 326; 325, 327; 326, identifier:echo; 327, identifier:echo; 328, keyword_argument; 328, 329; 328, 330; 329, identifier:raise_on_error; 330, identifier:raise_on_error; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:dry_run; 333, identifier:dry_run | def remote(cmd: arg(container=list),
host,
user=None,
port=None,
sudo=False,
run_as=None,
shell='/bin/sh',
cd=None,
environ: arg(container=dict) = None,
paths=(),
# Args passed through to local command:
stdout: arg(type=StreamOptions) = None,
stderr: arg(type=StreamOptions) = None,
echo=False,
raise_on_error=True,
dry_run=False,
) -> Result:
"""Run a remote command via SSH.
Runs a remote shell command using ``ssh`` in a subprocess like so:
ssh -q [-t] [<user>@]<host> [sudo [-u <run_as>] -H] /bin/sh -c '
[cd <cd> &&]
[export XYZ="xyz" &&]
[export PATH="<path>" &&]
<cmd>
'
Args:
cmd (list|str): The command to run. If this is a list, it will
be flattened into a string.
host (str): Remote host to SSH into.
user (str): Remote user to log in as (defaults to current local
user).
port (int): SSH port on remote host.
sudo (bool): Run the remote command as root using ``sudo``.
run_as (str): Run the remote command as a different user using
``sudo -u <run_as>``.
shell (str): The remote user's default shell will be used to run
the remote command unless this is set to a different shell.
cd (str): Where to run the command on the remote host.
environ (dict): Extra environment variables to set on the remote
host.
paths (list): Additional paths to prepend to the remote
``$PATH``.
stdout: See :func:`local`.
stderr: See :func:`local`.
echo: See :func:`local`.
raise_on_error: See :func:`local`.
dry_run: See :func:`local`.
"""
if not isinstance(cmd, str):
cmd = flatten_args(cmd, join=True)
ssh_options = ['-q']
if isatty(sys.stdin):
ssh_options.append('-t')
if port is not None:
ssh_options.extend(('-p', port))
ssh_connection_str = '{user}@{host}'.format_map(locals()) if user else host
remote_cmd = []
if sudo:
remote_cmd.extend(('sudo', '-H'))
elif run_as:
remote_cmd.extend(('sudo', '-H', '-u', run_as))
remote_cmd.extend((shell, '-c'))
inner_cmd = []
if cd:
inner_cmd.append('cd {cd}'.format_map(locals()))
if environ:
inner_cmd.extend('export {k}="{v}"'.format_map(locals()) for k, v in environ.items())
if paths:
inner_cmd.append('export PATH="{path}:$PATH"'.format(path=':'.join(paths)))
inner_cmd.append(cmd)
inner_cmd = ' &&\n '.join(inner_cmd)
inner_cmd = '\n {inner_cmd}\n'.format_map(locals())
inner_cmd = shlex.quote(inner_cmd)
remote_cmd.append(inner_cmd)
remote_cmd = ' '.join(remote_cmd)
args = ('ssh', ssh_options, ssh_connection_str, remote_cmd)
return local(
args, stdout=stdout, stderr=stderr, echo=echo, raise_on_error=raise_on_error,
dry_run=dry_run) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 70; 1, 72; 2, function_name:sync; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 3, 40; 3, 43; 3, 44; 3, 54; 3, 64; 3, 67; 4, identifier:source; 5, identifier:destination; 6, identifier:host; 7, default_parameter; 7, 8; 7, 9; 8, identifier:user; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sudo; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:run_as; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:options; 18, tuple; 18, 19; 18, 20; 18, 21; 19, string:'-rltvz'; 20, string:'--no-perms'; 21, string:'--no-group'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:excludes; 24, tuple; 25, default_parameter; 25, 26; 25, 27; 26, identifier:exclude_from; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:delete; 30, False; 31, default_parameter; 31, 32; 31, 33; 32, identifier:dry_run; 33, False; 34, default_parameter; 34, 35; 34, 36; 35, identifier:mode; 36, string:'u=rwX,g=rwX,o='; 37, default_parameter; 37, 38; 37, 39; 38, identifier:quiet; 39, True; 40, default_parameter; 40, 41; 40, 42; 41, identifier:pull; 42, False; 43, comment; 44, typed_default_parameter; 44, 45; 44, 46; 44, 53; 45, identifier:stdout; 46, type; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:arg; 49, argument_list; 49, 50; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:type; 52, identifier:StreamOptions; 53, None; 54, typed_default_parameter; 54, 55; 54, 56; 54, 63; 55, identifier:stderr; 56, type; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:arg; 59, argument_list; 59, 60; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:type; 62, identifier:StreamOptions; 63, None; 64, default_parameter; 64, 65; 64, 66; 65, identifier:echo; 66, False; 67, default_parameter; 67, 68; 67, 69; 68, identifier:raise_on_error; 69, True; 70, type; 70, 71; 71, identifier:Result; 72, block; 72, 73; 72, 75; 72, 85; 72, 95; 72, 109; 72, 114; 72, 145; 72, 172; 72, 214; 73, expression_statement; 73, 74; 74, comment; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:source; 78, call; 78, 79; 78, 80; 79, identifier:abs_path; 80, argument_list; 80, 81; 80, 82; 81, identifier:source; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:keep_slash; 84, True; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:destination; 88, call; 88, 89; 88, 90; 89, identifier:abs_path; 90, argument_list; 90, 91; 90, 92; 91, identifier:destination; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:keep_slash; 94, True; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:connection_str; 98, conditional_expression:if; 98, 99; 98, 107; 98, 108; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, string:'{user}@{host}'; 102, identifier:format_map; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:locals; 106, argument_list; 107, identifier:user; 108, identifier:host; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:push; 112, not_operator; 112, 113; 113, identifier:pull; 114, if_statement; 114, 115; 114, 116; 114, 123; 114, 139; 115, identifier:sudo; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:rsync_path; 120, tuple; 120, 121; 120, 122; 121, string:'--rsync-path'; 122, string:'sudo rsync'; 123, elif_clause; 123, 124; 123, 125; 124, identifier:run_as; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:rsync_path; 129, tuple; 129, 130; 129, 131; 130, string:'--rsync-path'; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, string:'sudo -u {run_as} rsync'; 134, identifier:format_map; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:locals; 138, argument_list; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:rsync_path; 144, None; 145, if_statement; 145, 146; 145, 147; 145, 159; 146, identifier:push; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:destination; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, string:'{connection_str}:{destination}'; 154, identifier:format_map; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:locals; 158, argument_list; 159, else_clause; 159, 160; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:source; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, string:'{connection_str}:{source}'; 167, identifier:format_map; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:locals; 171, argument_list; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:args; 175, tuple; 175, 176; 175, 177; 175, 178; 175, 179; 175, 185; 175, 194; 175, 200; 175, 204; 175, 208; 175, 212; 175, 213; 176, string:'rsync'; 177, identifier:rsync_path; 178, identifier:options; 179, conditional_expression:if; 179, 180; 179, 183; 179, 184; 180, tuple; 180, 181; 180, 182; 181, string:'--chmod'; 182, identifier:mode; 183, identifier:mode; 184, None; 185, call; 185, 186; 185, 187; 186, identifier:tuple; 187, generator_expression; 187, 188; 187, 191; 188, tuple; 188, 189; 188, 190; 189, string:'--exclude'; 190, identifier:exclude; 191, for_in_clause; 191, 192; 191, 193; 192, identifier:exclude; 193, identifier:excludes; 194, conditional_expression:if; 194, 195; 194, 198; 194, 199; 195, tuple; 195, 196; 195, 197; 196, string:'--exclude-from'; 197, identifier:exclude_from; 198, identifier:exclude_from; 199, None; 200, conditional_expression:if; 200, 201; 200, 202; 200, 203; 201, string:'--delete'; 202, identifier:delete; 203, None; 204, conditional_expression:if; 204, 205; 204, 206; 204, 207; 205, string:'--dry-run'; 206, identifier:dry_run; 207, None; 208, conditional_expression:if; 208, 209; 208, 210; 208, 211; 209, string:'--quiet'; 210, identifier:quiet; 211, None; 212, identifier:source; 213, identifier:destination; 214, return_statement; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:local; 217, argument_list; 217, 218; 217, 219; 217, 222; 217, 225; 217, 228; 218, identifier:args; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:stdout; 221, identifier:stdout; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:stderr; 224, identifier:stderr; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:echo; 227, identifier:echo; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:raise_on_error; 230, identifier:raise_on_error | def sync(source,
destination,
host,
user=None,
sudo=False,
run_as=None,
options=('-rltvz', '--no-perms', '--no-group'),
excludes=(),
exclude_from=None,
delete=False,
dry_run=False,
mode='u=rwX,g=rwX,o=',
quiet=True,
pull=False,
# Args passed through to local command:
stdout: arg(type=StreamOptions) = None,
stderr: arg(type=StreamOptions) = None,
echo=False,
raise_on_error=True,
) -> Result:
"""Sync files using rsync.
By default, a local ``source`` is pushed to a remote
``destination``. To pull from a remote ``source`` to a local
``destination`` instead, pass ``pull=True``.
"""
source = abs_path(source, keep_slash=True)
destination = abs_path(destination, keep_slash=True)
connection_str = '{user}@{host}'.format_map(locals()) if user else host
push = not pull
if sudo:
rsync_path = ('--rsync-path', 'sudo rsync')
elif run_as:
rsync_path = ('--rsync-path', 'sudo -u {run_as} rsync'.format_map(locals()))
else:
rsync_path = None
if push:
destination = '{connection_str}:{destination}'.format_map(locals())
else:
source = '{connection_str}:{source}'.format_map(locals())
args = (
'rsync',
rsync_path,
options,
('--chmod', mode) if mode else None,
tuple(('--exclude', exclude) for exclude in excludes),
('--exclude-from', exclude_from) if exclude_from else None,
'--delete' if delete else None,
'--dry-run' if dry_run else None,
'--quiet' if quiet else None,
source,
destination,
)
return local(args, stdout=stdout, stderr=stderr, echo=echo, raise_on_error=raise_on_error) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 1, 24; 2, function_name:_determine_outliers_for_moving_average; 3, parameters; 3, 4; 3, 10; 3, 14; 3, 18; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:moving_average; 6, type; 6, 7; 7, attribute; 7, 8; 7, 9; 8, identifier:np; 9, identifier:ndarray; 10, typed_parameter; 10, 11; 10, 12; 11, identifier:moving_average_threshold; 12, type; 12, 13; 13, identifier:float; 14, typed_parameter; 14, 15; 14, 16; 15, identifier:number_of_values_to_search_ahead; 16, type; 16, 17; 17, identifier:int; 18, typed_parameter; 18, 19; 18, 20; 19, identifier:limit_of_number_of_values_below_threshold; 20, type; 20, 21; 21, identifier:int; 22, type; 22, 23; 23, identifier:int; 24, block; 24, 25; 24, 27; 24, 33; 24, 34; 24, 35; 24, 39; 24, 68; 24, 69; 24, 70; 24, 71; 24, 72; 24, 76; 24, 77; 24, 82; 24, 83; 24, 163; 25, expression_statement; 25, 26; 26, comment; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:below_threshold; 30, comparison_operator:<; 30, 31; 30, 32; 31, identifier:moving_average; 32, identifier:moving_average_threshold; 33, comment; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:values_to_check; 38, list:[]; 39, for_statement; 39, 40; 39, 41; 39, 45; 39, 46; 39, 47; 40, identifier:i; 41, call; 41, 42; 41, 43; 42, identifier:range; 43, argument_list; 43, 44; 44, identifier:limit_of_number_of_values_below_threshold; 45, comment; 46, comment; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:values_to_check; 52, identifier:append; 53, argument_list; 53, 54; 54, subscript; 54, 55; 54, 56; 55, identifier:below_threshold; 56, slice; 56, 57; 56, 58; 56, 59; 57, identifier:i; 58, colon; 59, boolean_operator:or; 59, 60; 59, 67; 60, unary_operator:-; 60, 61; 61, parenthesized_expression; 61, 62; 62, binary_operator:-; 62, 63; 62, 66; 63, binary_operator:-; 63, 64; 63, 65; 64, identifier:limit_of_number_of_values_below_threshold; 65, integer:1; 66, identifier:i; 67, None; 68, comment; 69, comment; 70, comment; 71, comment; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:found_at_least_one_bin_above_threshold; 75, False; 76, comment; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:cut_index; 80, unary_operator:-; 80, 81; 81, integer:1; 82, comment; 83, for_statement; 83, 84; 83, 87; 83, 95; 83, 96; 83, 97; 83, 98; 83, 99; 84, pattern_list; 84, 85; 84, 86; 85, identifier:i; 86, identifier:values; 87, call; 87, 88; 87, 89; 88, identifier:enumerate; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:zip; 92, argument_list; 92, 93; 93, list_splat; 93, 94; 94, identifier:values_to_check; 95, comment; 96, comment; 97, comment; 98, comment; 99, block; 99, 100; 99, 106; 99, 107; 99, 116; 99, 117; 99, 128; 99, 129; 99, 130; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:==; 101, 102; 101, 103; 102, identifier:i; 103, integer:0; 104, block; 104, 105; 105, continue_statement; 106, comment; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:above_threshold; 110, list_comprehension; 110, 111; 110, 113; 111, not_operator; 111, 112; 112, identifier:value; 113, for_in_clause; 113, 114; 113, 115; 114, identifier:value; 115, identifier:values; 116, comment; 117, if_statement; 117, 118; 117, 122; 117, 123; 118, call; 118, 119; 118, 120; 119, identifier:any; 120, argument_list; 120, 121; 121, identifier:above_threshold; 122, comment; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:found_at_least_one_bin_above_threshold; 127, True; 128, comment; 129, comment; 130, if_statement; 130, 131; 130, 142; 130, 143; 130, 144; 130, 145; 130, 146; 131, boolean_operator:and; 131, 132; 131, 133; 132, identifier:found_at_least_one_bin_above_threshold; 133, call; 133, 134; 133, 135; 134, identifier:all; 135, argument_list; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:invert; 140, argument_list; 140, 141; 141, identifier:above_threshold; 142, comment; 143, comment; 144, comment; 145, comment; 146, block; 146, 147; 146, 154; 146, 162; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:logger; 151, identifier:debug; 152, argument_list; 152, 153; 153, string:f"i at found cut_index: {i} with moving_average: {moving_average[i]}"; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:cut_index; 157, binary_operator:+; 157, 158; 157, 159; 158, identifier:i; 159, binary_operator://; 159, 160; 159, 161; 160, identifier:limit_of_number_of_values_below_threshold; 161, integer:2; 162, break_statement; 163, return_statement; 163, 164; 164, identifier:cut_index | def _determine_outliers_for_moving_average(moving_average: np.ndarray,
moving_average_threshold: float,
number_of_values_to_search_ahead: int,
limit_of_number_of_values_below_threshold: int) -> int:
""" Determine outliers to remove from a given moving average.
Note:
The index returned is when the moving average first drops below the threshold for a moving average
calculated with that bin at the center. This is somewhat different from a standard moving average
calculation which would only look forward in the array.
Args:
moving_average: Moving average.
moving_average_threshold: Value of moving average under which we consider the moving average
to be 0. Default: 2.
number_of_values_to_search_ahead: Number of values to search ahead in the array when calculating
the moving average. Default: 5.
limit_of_number_of_values_below_threshold: Number of consecutive bins below the threshold to be considered
the beginning of outliers. Default: None, which will correspond to number_of_values_to_search_ahead - 1.
Returns:
0-indexed index of the histogram axes where the outliers begin.
"""
below_threshold = moving_average < moving_average_threshold
# Build up a list of values to check if they are below threshold. This list allows us to easily look
# forward in the below_threshold array.
values_to_check = []
for i in range(limit_of_number_of_values_below_threshold):
# Basically, this gives us (for limit_of_number_of_values_below_threshold = 4):
# below_threshold[0:-3], below_threshold[1:-2], below_threshold[2:-1], below_threshold[3:None]
values_to_check.append(
below_threshold[i:-(limit_of_number_of_values_below_threshold - 1 - i) or None]
)
# Some helpful logging information.
#logger.debug(f"values_to_check: {values_to_check}")
#logger.debug(f"moving avg length: {len(moving_average)}, length of values_to_check entries: {[len(v) for v in values_to_check]}")
# Must have at least one bin above the specified threshold.
found_at_least_one_bin_above_threshold = False
# Index we will search for from which outliers will be cut.
cut_index = -1
# Determine the index where the limit_of_number_of_values_below_threshold bins are consequentially below the threshold.
for i, values in enumerate(zip(*values_to_check)):
# Skip the first bin because some old pt hard bin trains had a large number of erroneous entries
# in the first bin (regardless of the actual pt hard bin). This should be resolved in the embedding
# helper now. In any case, it doesn't make sense to encounter outliers in the first bin, so this is a
# fine bin to skip.
if i == 0:
continue
# True if below threshold, so check if not True.
above_threshold = [not value for value in values]
# We require the values to go above the moving average threshold at least once.
if any(above_threshold):
#logger.debug(f"Found bin i {i} above threshold with moving average: {moving_average[i]}")
found_at_least_one_bin_above_threshold = True
# All values from which we are looking ahead must be below the threshold to consider the index
# as below threshold.
if found_at_least_one_bin_above_threshold and all(np.invert(above_threshold)):
# The previous outlier removal implementation used a moving average centered on a value
# (ie. it checked ``arr[-2 + current_index:current_index + 3]``). Thus, we need to
# shift the cut_index that we assign by limit_of_number_of_values_below_threshold // 2 for
# the index where we have found all values below the threshold.
logger.debug(f"i at found cut_index: {i} with moving_average: {moving_average[i]}")
cut_index = i + limit_of_number_of_values_below_threshold // 2
break
return cut_index |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:make_dynamic_class; 3, parameters; 3, 4; 3, 5; 4, identifier:typename; 5, identifier:field_names; 6, block; 6, 7; 6, 9; 6, 30; 6, 38; 6, 46; 6, 67; 6, 73; 6, 79; 6, 85; 6, 102; 6, 108; 6, 122; 6, 158; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 15; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:field_names; 14, identifier:basestring; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:field_names; 19, call; 19, 20; 19, 29; 20, attribute; 20, 21; 20, 28; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:field_names; 24, identifier:replace; 25, argument_list; 25, 26; 25, 27; 26, string:","; 27, string:" "; 28, identifier:split; 29, argument_list; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:field_names; 33, call; 33, 34; 33, 35; 34, identifier:map; 35, argument_list; 35, 36; 35, 37; 36, identifier:str; 37, identifier:field_names; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:safe_fields_names; 41, call; 41, 42; 41, 43; 42, identifier:map; 43, argument_list; 43, 44; 43, 45; 44, identifier:_encode_property_name; 45, identifier:field_names; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:attr; 49, call; 49, 50; 49, 51; 50, identifier:dict; 51, generator_expression; 51, 52; 51, 58; 52, tuple; 52, 53; 52, 54; 53, identifier:safe_name; 54, call; 54, 55; 54, 56; 55, identifier:_property; 56, argument_list; 56, 57; 57, identifier:name; 58, for_in_clause; 58, 59; 58, 62; 59, pattern_list; 59, 60; 59, 61; 60, identifier:name; 61, identifier:safe_name; 62, call; 62, 63; 62, 64; 63, identifier:zip; 64, argument_list; 64, 65; 64, 66; 65, identifier:field_names; 66, identifier:safe_fields_names; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:attr; 71, string:'__doc__'; 72, identifier:typename; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:attr; 77, string:'__identifier__'; 78, string:"dolphin"; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:attr; 83, string:'__init__'; 84, identifier:_dynamic__init; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:attr; 89, string:'__getitem__'; 90, lambda; 90, 91; 90, 94; 91, lambda_parameters; 91, 92; 91, 93; 92, identifier:self; 93, identifier:key; 94, call; 94, 95; 94, 100; 95, attribute; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:__dict__; 99, identifier:get; 100, argument_list; 100, 101; 101, identifier:key; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:attr; 106, string:'__setitem__'; 107, identifier:_dynamic__setitem; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:attr; 112, string:'__iter__'; 113, lambda; 113, 114; 113, 116; 114, lambda_parameters; 114, 115; 115, identifier:self; 116, call; 116, 117; 116, 118; 117, identifier:iter; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:__dict__; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:attr; 126, string:'__repr__'; 127, lambda; 127, 128; 127, 130; 128, lambda_parameters; 128, 129; 129, identifier:self; 130, binary_operator:%; 130, 131; 130, 132; 131, string:"{%s}"; 132, parenthesized_expression; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:', '; 136, identifier:join; 137, argument_list; 137, 138; 138, list_comprehension; 138, 139; 138, 146; 139, binary_operator:%; 139, 140; 139, 141; 140, string:"%s=%r"; 141, tuple; 141, 142; 141, 143; 142, identifier:key; 143, subscript; 143, 144; 143, 145; 144, identifier:self; 145, identifier:key; 146, for_in_clause; 146, 147; 146, 148; 147, identifier:key; 148, call; 148, 149; 148, 150; 149, identifier:sorted; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:__dict__; 156, identifier:keys; 157, argument_list; 158, return_statement; 158, 159; 159, call; 159, 160; 159, 161; 160, identifier:type; 161, argument_list; 161, 162; 161, 163; 161, 165; 162, identifier:typename; 163, tuple; 163, 164; 164, identifier:object; 165, identifier:attr | def make_dynamic_class(typename, field_names):
"""a factory function to create type dynamically
The factory function is used by :func:`objson.load` and :func:`objson.loads`.
Creating the object deserialize from json string. The inspiration come from
:func:`collections.namedtuple`. the difference is that I don't your the class
template to define a dynamic class, instead of, I use the :func:`type` factory
function.
Class prototype definition ::
class JsonObject(object):
__identifier__ = "dolphin"
def __init__(self, kv=None):
if kv is None:
kv = dict()
self.__dict__.update(kv)
def __getitem__(self, key):
return self.__dict__.get(key)
def __setitem__(self, key, value):
self.__dict__[key] = value
def __iter__(self):
return iter(self.__dict__)
def __repr__(self):
keys = sorted(self.__dict__.keys())
text = ', '.join(["%s=%r" % (key, self[key]) for key in keys])
return '{%s}' % text
name=_property('name')
Basic Usage ::
from objson import make_dynamic_class, dumps
Entity = make_dynamic_class('Entity', 'name, sex, age')
entity = Entity()
entity.name, entity.sex, entity.age = 'benjamin', 'male', 21
dumps(entity)
:param typename: dynamic class's name
:param field_names: a string :class:`list` and a field name string which separated by comma,
``['name', 'sex']`` or ``"name,sex"``
:return: a class type
"""
if isinstance(field_names, basestring):
field_names = field_names.replace(",", " ").split()
field_names = map(str, field_names)
safe_fields_names = map(_encode_property_name, field_names)
attr = dict((safe_name, _property(name)) for name, safe_name in zip(field_names, safe_fields_names))
attr['__doc__'] = typename
attr['__identifier__'] = "dolphin"
attr['__init__'] = _dynamic__init
attr['__getitem__'] = lambda self, key: self.__dict__.get(key)
attr['__setitem__'] = _dynamic__setitem
attr['__iter__'] = lambda self: iter(self.__dict__)
attr['__repr__'] = lambda self: "{%s}" % (', '.join([
"%s=%r" % (key, self[key]) for key in
sorted(self.__dict__.keys())
]))
return type(typename, (object,), attr) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:verifyInputs; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:mode; 6, block; 6, 7; 6, 9; 6, 36; 6, 444; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 18; 10, comparison_operator:<; 10, 11; 10, 17; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_aichans; 17, integer:1; 18, block; 18, 19; 18, 23; 18, 34; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:failmsg; 22, string:"Must have at least one input channel selected"; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:QtGui; 28, identifier:QMessageBox; 29, identifier:warning; 30, argument_list; 30, 31; 30, 32; 30, 33; 31, identifier:self; 32, string:"Invalid Setting"; 33, identifier:failmsg; 34, return_statement; 34, 35; 35, False; 36, if_statement; 36, 37; 36, 40; 36, 71; 37, comparison_operator:==; 37, 38; 37, 39; 38, identifier:mode; 39, string:'chart'; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 57; 42, comparison_operator:>; 42, 43; 42, 56; 43, binary_operator:*; 43, 44; 43, 53; 44, call; 44, 45; 44, 52; 45, attribute; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:ui; 50, identifier:aifsSpnbx; 51, identifier:value; 52, argument_list; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:fscale; 56, integer:100000; 57, block; 57, 58; 57, 69; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:QtGui; 63, identifier:QMessageBox; 64, identifier:warning; 65, argument_list; 65, 66; 65, 67; 65, 68; 66, identifier:self; 67, string:"Invalid Input"; 68, string:"Recording samplerate cannot exceed 100kHz for chart acquisition"; 69, return_statement; 69, 70; 70, False; 71, elif_clause; 71, 72; 71, 75; 71, 76; 71, 77; 71, 78; 72, comparison_operator:is; 72, 73; 72, 74; 73, identifier:mode; 74, None; 75, comment; 76, comment; 77, comment; 78, block; 78, 79; 78, 411; 79, if_statement; 79, 80; 79, 95; 79, 96; 79, 148; 79, 212; 80, comparison_operator:==; 80, 81; 80, 94; 81, call; 81, 82; 81, 93; 82, attribute; 82, 83; 82, 92; 83, call; 83, 84; 83, 91; 84, attribute; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:ui; 89, identifier:tabGroup; 90, identifier:currentWidget; 91, argument_list; 92, identifier:objectName; 93, argument_list; 94, string:'tabExplore'; 95, comment; 96, block; 96, 97; 96, 107; 96, 128; 96, 144; 96, 145; 96, 146; 96, 147; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 106; 99, attribute; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:ui; 104, identifier:exploreStimEditor; 105, identifier:saveToObject; 106, argument_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:failmsg; 110, call; 110, 111; 110, 118; 111, attribute; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:ui; 116, identifier:exploreStimEditor; 117, identifier:verify; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 127; 120, attribute; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:ui; 125, identifier:windowszSpnbx; 126, identifier:value; 127, argument_list; 128, if_statement; 128, 129; 128, 130; 129, identifier:failmsg; 130, block; 130, 131; 130, 142; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:QtGui; 136, identifier:QMessageBox; 137, identifier:warning; 138, argument_list; 138, 139; 138, 140; 138, 141; 139, identifier:self; 140, string:"Invalid Input"; 141, identifier:failmsg; 142, return_statement; 142, 143; 143, False; 144, comment; 145, comment; 146, comment; 147, comment; 148, elif_clause; 148, 149; 148, 164; 149, comparison_operator:==; 149, 150; 149, 163; 150, call; 150, 151; 150, 162; 151, attribute; 151, 152; 151, 161; 152, call; 152, 153; 152, 160; 153, attribute; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:ui; 158, identifier:tabGroup; 159, identifier:currentWidget; 160, argument_list; 161, identifier:objectName; 162, argument_list; 163, string:'tabProtocol'; 164, block; 164, 165; 164, 175; 164, 176; 164, 196; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:protocol_model; 168, call; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:acqmodel; 173, identifier:protocol_model; 174, argument_list; 175, comment; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:failure; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:protocol_model; 182, identifier:verify; 183, argument_list; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:float; 186, argument_list; 186, 187; 187, call; 187, 188; 187, 195; 188, attribute; 188, 189; 188, 194; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:ui; 193, identifier:windowszSpnbx; 194, identifier:value; 195, argument_list; 196, if_statement; 196, 197; 196, 198; 197, identifier:failure; 198, block; 198, 199; 198, 210; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:QtGui; 204, identifier:QMessageBox; 205, identifier:warning; 206, argument_list; 206, 207; 206, 208; 206, 209; 207, identifier:self; 208, string:"Invalid Input"; 209, identifier:failure; 210, return_statement; 210, 211; 211, False; 212, elif_clause; 212, 213; 212, 228; 213, comparison_operator:==; 213, 214; 213, 227; 214, call; 214, 215; 214, 226; 215, attribute; 215, 216; 215, 225; 216, call; 216, 217; 216, 224; 217, attribute; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:ui; 222, identifier:tabGroup; 223, identifier:currentWidget; 224, argument_list; 225, identifier:objectName; 226, argument_list; 227, string:'tabCalibrate'; 228, block; 228, 229; 228, 266; 228, 267; 228, 329; 228, 349; 228, 365; 228, 366; 228, 385; 229, if_statement; 229, 230; 229, 238; 230, comparison_operator:>; 230, 231; 230, 237; 231, call; 231, 232; 231, 233; 232, identifier:len; 233, argument_list; 233, 234; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:_aichans; 237, integer:1; 238, block; 238, 239; 238, 253; 238, 264; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:failmsg; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, string:"Speaker calibration only supported for single channel, currently {} channels selected; select 1 input channel."; 245, identifier:format; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:len; 249, argument_list; 249, 250; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:_aichans; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:QtGui; 258, identifier:QMessageBox; 259, identifier:warning; 260, argument_list; 260, 261; 260, 262; 260, 263; 261, identifier:self; 262, string:"Invalid Setting"; 263, identifier:failmsg; 264, return_statement; 264, 265; 265, False; 266, comment; 267, if_statement; 267, 268; 267, 294; 267, 316; 268, boolean_operator:or; 268, 269; 268, 282; 269, call; 269, 270; 269, 281; 270, attribute; 270, 271; 270, 280; 271, attribute; 271, 272; 271, 279; 272, attribute; 272, 273; 272, 278; 273, attribute; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:ui; 277, identifier:calibrationWidget; 278, identifier:ui; 279, identifier:savecalCkbx; 280, identifier:isChecked; 281, argument_list; 282, not_operator; 282, 283; 283, comparison_operator:==; 283, 284; 283, 293; 284, call; 284, 285; 284, 292; 285, attribute; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:ui; 290, identifier:calibrationWidget; 291, identifier:currentSelection; 292, argument_list; 293, string:'Tone Curve'; 294, block; 294, 295; 294, 306; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:calibration_stimulus; 298, call; 298, 299; 298, 304; 299, attribute; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:acqmodel; 303, identifier:calibration_stimulus; 304, argument_list; 304, 305; 305, string:'noise'; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 315; 308, attribute; 308, 309; 308, 314; 309, attribute; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:self; 312, identifier:ui; 313, identifier:calibrationWidget; 314, identifier:saveToObject; 315, argument_list; 316, else_clause; 316, 317; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:calibration_stimulus; 321, call; 321, 322; 321, 327; 322, attribute; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:acqmodel; 326, identifier:calibration_stimulus; 327, argument_list; 327, 328; 328, string:'tone'; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:failmsg; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:calibration_stimulus; 335, identifier:verify; 336, argument_list; 336, 337; 337, call; 337, 338; 337, 339; 338, identifier:float; 339, argument_list; 339, 340; 340, call; 340, 341; 340, 348; 341, attribute; 341, 342; 341, 347; 342, attribute; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:self; 345, identifier:ui; 346, identifier:windowszSpnbx; 347, identifier:value; 348, argument_list; 349, if_statement; 349, 350; 349, 351; 350, identifier:failmsg; 351, block; 351, 352; 351, 363; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 359; 354, attribute; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:QtGui; 357, identifier:QMessageBox; 358, identifier:warning; 359, argument_list; 359, 360; 359, 361; 359, 362; 360, identifier:self; 361, string:"Invalid Input"; 362, identifier:failmsg; 363, return_statement; 363, 364; 364, False; 365, comment; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 369; 368, identifier:failmsg; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:calibration_stimulus; 372, identifier:verifyExpanded; 373, argument_list; 373, 374; 374, keyword_argument; 374, 375; 374, 376; 375, identifier:samplerate; 376, call; 376, 377; 376, 384; 377, attribute; 377, 378; 377, 383; 378, attribute; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:self; 381, identifier:ui; 382, identifier:aifsSpnbx; 383, identifier:value; 384, argument_list; 385, if_statement; 385, 386; 385, 387; 386, identifier:failmsg; 387, block; 387, 388; 387, 398; 387, 409; 388, expression_statement; 388, 389; 389, assignment; 389, 390; 389, 391; 390, identifier:failmsg; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:failmsg; 394, identifier:replace; 395, argument_list; 395, 396; 395, 397; 396, string:'Generation'; 397, string:'Recording'; 398, expression_statement; 398, 399; 399, call; 399, 400; 399, 405; 400, attribute; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:QtGui; 403, identifier:QMessageBox; 404, identifier:warning; 405, argument_list; 405, 406; 405, 407; 405, 408; 406, identifier:self; 407, string:"Invalid Input"; 408, identifier:failmsg; 409, return_statement; 409, 410; 410, False; 411, if_statement; 411, 412; 411, 426; 412, boolean_operator:and; 412, 413; 412, 418; 413, subscript; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:self; 416, identifier:advanced_options; 417, string:'use_attenuator'; 418, not_operator; 418, 419; 419, call; 419, 420; 419, 425; 420, attribute; 420, 421; 420, 424; 421, attribute; 421, 422; 421, 423; 422, identifier:self; 423, identifier:acqmodel; 424, identifier:attenuator_connection; 425, argument_list; 426, block; 426, 427; 426, 431; 426, 442; 427, expression_statement; 427, 428; 428, assignment; 428, 429; 428, 430; 429, identifier:failmsg; 430, string:"Error Connection to attenuator, make sure it it turned on and connected, and try again"; 431, expression_statement; 431, 432; 432, call; 432, 433; 432, 438; 433, attribute; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, identifier:QtGui; 436, identifier:QMessageBox; 437, identifier:warning; 438, argument_list; 438, 439; 438, 440; 438, 441; 439, identifier:self; 440, string:"Connection Error"; 441, identifier:failmsg; 442, return_statement; 442, 443; 443, False; 444, return_statement; 444, 445; 445, True | def verifyInputs(self, mode):
"""Goes through and checks all stimuli and input settings are valid
and consistent. Prompts user with a message if there is a condition
that would prevent acquisition.
:param mode: The mode of acquisition trying to be run. Options are
'chart', or anthing else ('explore', 'protocol', 'calibration')
:type mode: str
:returns: bool -- Whether all inputs and stimuli are valid
"""
if len(self._aichans) < 1:
failmsg = "Must have at least one input channel selected"
QtGui.QMessageBox.warning(self, "Invalid Setting", failmsg)
return False
if mode == 'chart':
if self.ui.aifsSpnbx.value()*self.fscale > 100000:
QtGui.QMessageBox.warning(self, "Invalid Input", "Recording samplerate cannot exceed 100kHz for chart acquisition")
return False
elif mode is not None:
# if (1./self.ui.reprateSpnbx.value()) < self.ui.windowszSpnbx.value()*self.tscale + 0.05:
# QtGui.QMessageBox.warning(self, "Invalid Input", "A minimum of 50ms time between repetitions required. Current interval {}, required {}".format((1./self.ui.reprateSpnbx.value()), self.ui.windowszSpnbx.value()*self.tscale + 0.05))
# return False
if self.ui.tabGroup.currentWidget().objectName() == 'tabExplore':
# each widget should be in charge of putting its own stimulus together
self.ui.exploreStimEditor.saveToObject()
failmsg = self.ui.exploreStimEditor.verify(self.ui.windowszSpnbx.value())
if failmsg:
QtGui.QMessageBox.warning(self, "Invalid Input", failmsg)
return False
# if selectedStim.intensity() > self.calvals['caldb']:
# QtGui.QMessageBox.warning(self, "Invalid Input",
# "Intensity must be below calibrated maximum {}dB SPL".format(self.calvals['caldb']))
# return False
elif self.ui.tabGroup.currentWidget().objectName() == 'tabProtocol':
protocol_model = self.acqmodel.protocol_model()
# protocol delegates to each test to verify itself and report
failure = protocol_model.verify(float(self.ui.windowszSpnbx.value()))
if failure:
QtGui.QMessageBox.warning(self, "Invalid Input", failure)
return False
elif self.ui.tabGroup.currentWidget().objectName() == 'tabCalibrate':
if len(self._aichans) > 1:
failmsg = "Speaker calibration only supported for single channel, currently {} channels selected; select 1 input channel.".format(len(self._aichans))
QtGui.QMessageBox.warning(self, "Invalid Setting", failmsg)
return False
# get what stimulus is about to be presented
if self.ui.calibrationWidget.ui.savecalCkbx.isChecked() or not self.ui.calibrationWidget.currentSelection() == 'Tone Curve':
calibration_stimulus = self.acqmodel.calibration_stimulus('noise')
self.ui.calibrationWidget.saveToObject()
else:
calibration_stimulus = self.acqmodel.calibration_stimulus('tone')
failmsg = calibration_stimulus.verify(float(self.ui.windowszSpnbx.value()))
if failmsg:
QtGui.QMessageBox.warning(self, "Invalid Input", failmsg)
return False
# also check that the recording samplerate is high enough in this case
failmsg = calibration_stimulus.verifyExpanded(samplerate=self.ui.aifsSpnbx.value())
if failmsg:
failmsg = failmsg.replace('Generation', 'Recording')
QtGui.QMessageBox.warning(self, "Invalid Input", failmsg)
return False
if self.advanced_options['use_attenuator'] and not self.acqmodel.attenuator_connection():
failmsg = "Error Connection to attenuator, make sure it it turned on and connected, and try again"
QtGui.QMessageBox.warning(self, "Connection Error", failmsg)
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:complete; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:command_line; 5, identifier:current_token; 6, identifier:position; 7, typed_parameter; 7, 8; 7, 9; 8, identifier:shell; 9, type; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:arg; 12, argument_list; 12, 13; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:choices; 15, tuple; 15, 16; 15, 17; 16, string:'bash'; 17, string:'fish'; 18, block; 18, 19; 18, 21; 18, 28; 18, 41; 18, 57; 18, 66; 18, 75; 18, 81; 18, 88; 18, 106; 18, 116; 19, expression_statement; 19, 20; 20, comment; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:position; 24, call; 24, 25; 24, 26; 25, identifier:int; 26, argument_list; 26, 27; 27, identifier:position; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:tokens; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:shlex; 34, identifier:split; 35, argument_list; 35, 36; 36, subscript; 36, 37; 36, 38; 37, identifier:command_line; 38, slice; 38, 39; 38, 40; 39, colon; 40, identifier:position; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 47; 43, pattern_list; 43, 44; 43, 45; 43, 46; 44, identifier:all_argv; 45, identifier:run_argv; 46, identifier:command_argv; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:run; 50, identifier:partition_argv; 51, argument_list; 51, 52; 52, subscript; 52, 53; 52, 54; 53, identifier:tokens; 54, slice; 54, 55; 54, 56; 55, integer:1; 56, colon; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:run_args; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:run; 63, identifier:parse_args; 64, argument_list; 64, 65; 65, identifier:run_argv; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:module; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:run_args; 72, identifier:get; 73, argument_list; 73, 74; 74, string:'commands_module'; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:module; 78, boolean_operator:or; 78, 79; 78, 80; 79, identifier:module; 80, identifier:DEFAULT_COMMANDS_MODULE; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:module; 84, call; 84, 85; 84, 86; 85, identifier:normalize_path; 86, argument_list; 86, 87; 87, identifier:module; 88, try_statement; 88, 89; 88, 99; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:collection; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:Collection; 96, identifier:load_from_module; 97, argument_list; 97, 98; 98, identifier:module; 99, except_clause; 99, 100; 99, 101; 100, identifier:Exception; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:collection; 105, dictionary; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:found_command; 109, boolean_operator:or; 109, 110; 109, 115; 110, call; 110, 111; 110, 112; 111, identifier:find_command; 112, argument_list; 112, 113; 112, 114; 113, identifier:collection; 114, identifier:tokens; 115, identifier:run; 116, if_statement; 116, 117; 116, 118; 116, 119; 116, 213; 117, identifier:current_token; 118, comment; 119, block; 119, 120; 120, if_statement; 120, 121; 120, 127; 120, 141; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:current_token; 124, identifier:startswith; 125, argument_list; 125, 126; 126, string:'-'; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 134; 129, comparison_operator:not; 129, 130; 129, 131; 130, identifier:current_token; 131, attribute; 131, 132; 131, 133; 132, identifier:found_command; 133, identifier:option_map; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:print_command_options; 138, argument_list; 138, 139; 138, 140; 139, identifier:found_command; 140, identifier:current_token; 141, else_clause; 141, 142; 142, block; 142, 143; 142, 149; 142, 160; 142, 171; 142, 182; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:print_commands; 146, argument_list; 146, 147; 146, 148; 147, identifier:collection; 148, identifier:shell; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:path; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:os; 156, identifier:path; 157, identifier:expanduser; 158, argument_list; 158, 159; 159, identifier:current_token; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:path; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:os; 167, identifier:path; 168, identifier:expandvars; 169, argument_list; 169, 170; 170, identifier:path; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:paths; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:glob; 177, identifier:glob; 178, argument_list; 178, 179; 179, binary_operator:%; 179, 180; 179, 181; 180, string:'%s*'; 181, identifier:path; 182, if_statement; 182, 183; 182, 184; 183, identifier:paths; 184, block; 184, 185; 185, for_statement; 185, 186; 185, 187; 185, 188; 186, identifier:entry; 187, identifier:paths; 188, block; 188, 189; 189, if_statement; 189, 190; 189, 198; 189, 206; 190, call; 190, 191; 190, 196; 191, attribute; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:os; 194, identifier:path; 195, identifier:isdir; 196, argument_list; 196, 197; 197, identifier:entry; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:print; 202, argument_list; 202, 203; 203, binary_operator:%; 203, 204; 203, 205; 204, string:'%s/'; 205, identifier:entry; 206, else_clause; 206, 207; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:print; 211, argument_list; 211, 212; 212, identifier:entry; 213, else_clause; 213, 214; 213, 215; 213, 216; 213, 217; 214, comment; 215, comment; 216, comment; 217, block; 217, 218; 217, 232; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:option; 221, call; 221, 222; 221, 227; 222, attribute; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:found_command; 225, identifier:option_map; 226, identifier:get; 227, argument_list; 227, 228; 228, subscript; 228, 229; 228, 230; 229, identifier:tokens; 230, unary_operator:-; 230, 231; 231, integer:1; 232, if_statement; 232, 233; 232, 238; 232, 289; 233, boolean_operator:and; 233, 234; 233, 235; 234, identifier:option; 235, attribute; 235, 236; 235, 237; 236, identifier:option; 237, identifier:takes_value; 238, block; 238, 239; 239, if_statement; 239, 240; 239, 243; 239, 255; 240, attribute; 240, 241; 240, 242; 241, identifier:option; 242, identifier:choices; 243, block; 243, 244; 244, for_statement; 244, 245; 244, 246; 244, 249; 245, identifier:choice; 246, attribute; 246, 247; 246, 248; 247, identifier:option; 248, identifier:choices; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 253; 252, identifier:print; 253, argument_list; 253, 254; 254, identifier:choice; 255, else_clause; 255, 256; 256, block; 256, 257; 257, for_statement; 257, 258; 257, 259; 257, 264; 258, identifier:entry; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:os; 262, identifier:listdir; 263, argument_list; 264, block; 264, 265; 265, if_statement; 265, 266; 265, 274; 265, 282; 266, call; 266, 267; 266, 272; 267, attribute; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:os; 270, identifier:path; 271, identifier:isdir; 272, argument_list; 272, 273; 273, identifier:entry; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 278; 277, identifier:print; 278, argument_list; 278, 279; 279, binary_operator:%; 279, 280; 279, 281; 280, string:'%s/'; 281, identifier:entry; 282, else_clause; 282, 283; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 287; 286, identifier:print; 287, argument_list; 287, 288; 288, identifier:entry; 289, else_clause; 289, 290; 290, block; 290, 291; 290, 296; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:print_command_options; 294, argument_list; 294, 295; 295, identifier:found_command; 296, expression_statement; 296, 297; 297, call; 297, 298; 297, 299; 298, identifier:print_commands; 299, argument_list; 299, 300; 299, 301; 300, identifier:collection; 301, identifier:shell | def complete(command_line,
current_token,
position,
shell: arg(choices=('bash', 'fish'))):
"""Find completions for current command.
This assumes that we'll handle all completion logic here and that
the shell's automatic file name completion is disabled.
Args:
command_line: Command line
current_token: Token at cursor
position: Current cursor position
shell: Name of shell
"""
position = int(position)
tokens = shlex.split(command_line[:position])
all_argv, run_argv, command_argv = run.partition_argv(tokens[1:])
run_args = run.parse_args(run_argv)
module = run_args.get('commands_module')
module = module or DEFAULT_COMMANDS_MODULE
module = normalize_path(module)
try:
collection = Collection.load_from_module(module)
except Exception:
collection = {}
found_command = find_command(collection, tokens) or run
if current_token:
# Completing either a command name, option name, or path.
if current_token.startswith('-'):
if current_token not in found_command.option_map:
print_command_options(found_command, current_token)
else:
print_commands(collection, shell)
path = os.path.expanduser(current_token)
path = os.path.expandvars(path)
paths = glob.glob('%s*' % path)
if paths:
for entry in paths:
if os.path.isdir(entry):
print('%s/' % entry)
else:
print(entry)
else:
# Completing option value. If a value isn't expected, show the
# options for the current command and the list of commands
# instead.
option = found_command.option_map.get(tokens[-1])
if option and option.takes_value:
if option.choices:
for choice in option.choices:
print(choice)
else:
for entry in os.listdir():
if os.path.isdir(entry):
print('%s/' % entry)
else:
print(entry)
else:
print_command_options(found_command)
print_commands(collection, shell) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:export; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:context; 5, identifier:keywords; 6, identifier:module; 7, identifier:update; 8, block; 8, 9; 8, 11; 8, 21; 8, 29; 8, 33; 8, 199; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logging; 15, identifier:info; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:_; 19, argument_list; 19, 20; 20, string:'Export Mode'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:database; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:context; 27, identifier:obj; 28, string:'sense'; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:none; 32, True; 33, if_statement; 33, 34; 33, 35; 33, 106; 33, 156; 34, identifier:update; 35, block; 35, 36; 35, 42; 35, 50; 35, 95; 35, 102; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:exports; 39, call; 39, 40; 39, 41; 40, identifier:OrderedDict; 41, argument_list; 42, import_from_statement; 42, 43; 42, 48; 43, relative_import; 43, 44; 43, 45; 44, import_prefix; 45, dotted_name; 45, 46; 45, 47; 46, identifier:executables; 47, identifier:pe; 48, dotted_name; 48, 49; 49, identifier:PE; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:filename; 52, identifier:keywords; 53, block; 53, 54; 53, 66; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:module; 57, subscript; 57, 58; 57, 65; 58, call; 58, 59; 58, 60; 59, identifier:split_ext; 60, argument_list; 60, 61; 60, 62; 61, identifier:filename; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:basename; 64, True; 65, integer:0; 66, with_statement; 66, 67; 66, 77; 67, with_clause; 67, 68; 68, with_item; 68, 69; 69, as_pattern; 69, 70; 69, 75; 70, call; 70, 71; 70, 72; 71, identifier:open; 72, argument_list; 72, 73; 72, 74; 73, identifier:filename; 74, string:'rb'; 75, as_pattern_target; 75, 76; 76, identifier:stream; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:exports; 82, identifier:update; 83, argument_list; 83, 84; 84, dictionary; 84, 85; 85, pair; 85, 86; 85, 87; 86, identifier:module; 87, call; 87, 88; 87, 94; 88, attribute; 88, 89; 88, 93; 89, call; 89, 90; 89, 91; 90, identifier:PE; 91, argument_list; 91, 92; 92, identifier:stream; 93, identifier:get_export_table; 94, argument_list; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:database; 99, identifier:make_export; 100, argument_list; 100, 101; 101, identifier:exports; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:none; 105, False; 106, elif_clause; 106, 107; 106, 108; 107, identifier:module; 108, block; 108, 109; 109, for_statement; 109, 110; 109, 111; 109, 112; 110, identifier:module_name; 111, identifier:keywords; 112, block; 112, 113; 112, 122; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:funcs; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:database; 119, identifier:query_module_funcs; 120, argument_list; 120, 121; 121, identifier:module_name; 122, if_statement; 122, 123; 122, 124; 122, 143; 123, identifier:funcs; 124, block; 124, 125; 124, 129; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:none; 128, False; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:print; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:', '; 136, identifier:join; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:map; 140, argument_list; 140, 141; 140, 142; 141, identifier:str; 142, identifier:funcs; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:logging; 149, identifier:warning; 150, argument_list; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:_; 153, argument_list; 153, 154; 154, string:'No function for module: %s'; 155, identifier:module_name; 156, else_clause; 156, 157; 157, block; 157, 158; 158, for_statement; 158, 159; 158, 160; 158, 161; 159, identifier:func_name; 160, identifier:keywords; 161, block; 161, 162; 161, 171; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:module_name; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:database; 168, identifier:query_func_module; 169, argument_list; 169, 170; 170, identifier:func_name; 171, if_statement; 171, 172; 171, 173; 171, 186; 172, identifier:module_name; 173, block; 173, 174; 173, 178; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:none; 177, False; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:print; 181, argument_list; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:repr; 184, argument_list; 184, 185; 185, identifier:module_name; 186, else_clause; 186, 187; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:logging; 192, identifier:warning; 193, argument_list; 193, 194; 193, 198; 194, call; 194, 195; 194, 196; 195, identifier:_; 196, argument_list; 196, 197; 197, string:'No module for function: %s'; 198, identifier:func_name; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:sys; 203, identifier:exit; 204, argument_list; 204, 205; 205, conditional_expression:if; 205, 206; 205, 207; 205, 208; 206, integer:1; 207, identifier:none; 208, integer:0 | def export(context, keywords, module, update):
"""Operate on libraries and exported functions.
Query the module name containing the function by default.
Windows database must be prepared before using this.
"""
logging.info(_('Export Mode'))
database = context.obj['sense']
none = True
if update:
exports = OrderedDict()
from .executables.pe import PE
for filename in keywords:
module = split_ext(filename, basename=True)[0]
with open(filename, 'rb') as stream:
exports.update(
{module: PE(stream).get_export_table()})
database.make_export(exports)
none = False
elif module:
for module_name in keywords:
funcs = database.query_module_funcs(module_name)
if funcs:
none = False
print(', '.join(map(str, funcs)))
else:
logging.warning(_('No function for module: %s'),
module_name)
else:
for func_name in keywords:
module_name = database.query_func_module(func_name)
if module_name:
none = False
print(repr(module_name))
else:
logging.warning(_('No module for function: %s'),
func_name)
sys.exit(1 if none else 0) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_source; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:label; 5, identifier:source_type; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 29; 8, 55; 8, 56; 8, 57; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 17; 12, comparison_operator:not; 12, 13; 12, 14; 13, identifier:source_type; 14, attribute; 14, 15; 14, 16; 15, identifier:yapconf; 16, identifier:ALL_SUPPORTED_SOURCES; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:YapconfSourceError; 21, argument_list; 21, 22; 22, binary_operator:%; 22, 23; 22, 24; 23, string:'Invalid source type %s. Supported types are %s.'; 24, tuple; 24, 25; 24, 26; 25, identifier:source_type; 26, attribute; 26, 27; 26, 28; 27, identifier:yapconf; 28, identifier:ALL_SUPPORTED_SOURCES; 29, if_statement; 29, 30; 29, 35; 30, comparison_operator:not; 30, 31; 30, 32; 31, identifier:source_type; 32, attribute; 32, 33; 32, 34; 33, identifier:yapconf; 34, identifier:SUPPORTED_SOURCES; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:YapconfSourceError; 39, argument_list; 39, 40; 40, binary_operator:%; 40, 41; 40, 46; 41, concatenated_string; 41, 42; 41, 43; 41, 44; 41, 45; 42, string:'Unsupported source type "%s". If you want to use this type, you '; 43, string:'will need to install the correct client for it (try `pip install '; 44, string:'yapconf[%s]. Currently supported types are %s. All supported '; 45, string:'types are %s'; 46, tuple; 46, 47; 46, 48; 46, 49; 46, 52; 47, identifier:source_type; 48, identifier:source_type; 49, attribute; 49, 50; 49, 51; 50, identifier:yapconf; 51, identifier:SUPPORTED_SOURCES; 52, attribute; 52, 53; 52, 54; 53, identifier:yapconf; 54, identifier:ALL_SUPPORTED_SOURCES; 55, comment; 56, comment; 57, if_statement; 57, 58; 57, 61; 57, 75; 57, 87; 57, 121; 57, 131; 57, 154; 57, 210; 58, comparison_operator:==; 58, 59; 58, 60; 59, identifier:source_type; 60, string:'dict'; 61, block; 61, 62; 62, return_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:DictConfigSource; 65, argument_list; 65, 66; 65, 67; 66, identifier:label; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:data; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:kwargs; 72, identifier:get; 73, argument_list; 73, 74; 74, string:'data'; 75, elif_clause; 75, 76; 75, 79; 76, comparison_operator:==; 76, 77; 76, 78; 77, identifier:source_type; 78, string:'json'; 79, block; 79, 80; 80, return_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:JsonConfigSource; 83, argument_list; 83, 84; 83, 85; 84, identifier:label; 85, dictionary_splat; 85, 86; 86, identifier:kwargs; 87, elif_clause; 87, 88; 87, 91; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:source_type; 90, string:'yaml'; 91, block; 91, 92; 91, 101; 91, 113; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:filename; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:kwargs; 98, identifier:get; 99, argument_list; 99, 100; 100, string:'filename'; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:in; 102, 103; 102, 104; 103, string:'filename'; 104, identifier:kwargs; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:kwargs; 110, identifier:pop; 111, argument_list; 111, 112; 112, string:'filename'; 113, return_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:YamlConfigSource; 116, argument_list; 116, 117; 116, 118; 116, 119; 117, identifier:label; 118, identifier:filename; 119, dictionary_splat; 119, 120; 120, identifier:kwargs; 121, elif_clause; 121, 122; 121, 125; 122, comparison_operator:==; 122, 123; 122, 124; 123, identifier:source_type; 124, string:'environment'; 125, block; 125, 126; 126, return_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:EnvironmentConfigSource; 129, argument_list; 129, 130; 130, identifier:label; 131, elif_clause; 131, 132; 131, 135; 132, comparison_operator:==; 132, 133; 132, 134; 133, identifier:source_type; 134, string:'etcd'; 135, block; 135, 136; 136, return_statement; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:EtcdConfigSource; 139, argument_list; 139, 140; 139, 141; 139, 147; 140, identifier:label; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:kwargs; 144, identifier:get; 145, argument_list; 145, 146; 146, string:'client'; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:kwargs; 150, identifier:get; 151, argument_list; 151, 152; 151, 153; 152, string:'key'; 153, string:'/'; 154, elif_clause; 154, 155; 154, 158; 155, comparison_operator:==; 155, 156; 155, 157; 156, identifier:source_type; 157, string:'kubernetes'; 158, block; 158, 159; 158, 168; 158, 180; 158, 189; 158, 201; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:name; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:kwargs; 165, identifier:get; 166, argument_list; 166, 167; 167, string:'name'; 168, if_statement; 168, 169; 168, 172; 169, comparison_operator:in; 169, 170; 169, 171; 170, string:'name'; 171, identifier:kwargs; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:kwargs; 177, identifier:pop; 178, argument_list; 178, 179; 179, string:'name'; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:client; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:kwargs; 186, identifier:get; 187, argument_list; 187, 188; 188, string:'client'; 189, if_statement; 189, 190; 189, 193; 190, comparison_operator:in; 190, 191; 190, 192; 191, string:'client'; 192, identifier:kwargs; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:kwargs; 198, identifier:pop; 199, argument_list; 199, 200; 200, string:'client'; 201, return_statement; 201, 202; 202, call; 202, 203; 202, 204; 203, identifier:KubernetesConfigSource; 204, argument_list; 204, 205; 204, 206; 204, 207; 204, 208; 205, identifier:label; 206, identifier:client; 207, identifier:name; 208, dictionary_splat; 208, 209; 209, identifier:kwargs; 210, else_clause; 210, 211; 211, block; 211, 212; 212, raise_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:NotImplementedError; 215, argument_list; 215, 216; 216, binary_operator:%; 216, 217; 216, 218; 217, string:'No implementation for source type %s'; 218, identifier:source_type | def get_source(label, source_type, **kwargs):
"""Get a config source based on type and keyword args.
This is meant to be used internally by the spec via ``add_source``.
Args:
label (str): The label for this source.
source_type: The type of source. See ``yapconf.SUPPORTED_SOURCES``
Keyword Args:
The keyword arguments are based on the source_type. Please see the
documentation of the individual sources for a detailed list of all
possible arguments.
Returns (yapconf.sources.ConfigSource):
A valid config source which can be used for generating an override.
Raises:
YapconfSourceError: If there is some kind of error with this source
definition.
"""
if source_type not in yapconf.ALL_SUPPORTED_SOURCES:
raise YapconfSourceError(
'Invalid source type %s. Supported types are %s.' %
(source_type, yapconf.ALL_SUPPORTED_SOURCES)
)
if source_type not in yapconf.SUPPORTED_SOURCES:
raise YapconfSourceError(
'Unsupported source type "%s". If you want to use this type, you '
'will need to install the correct client for it (try `pip install '
'yapconf[%s]. Currently supported types are %s. All supported '
'types are %s' %
(source_type, source_type, yapconf.SUPPORTED_SOURCES,
yapconf.ALL_SUPPORTED_SOURCES)
)
# We pop arguments from kwargs because the individual config sources
# have better error messages if a keyword argument is missed.
if source_type == 'dict':
return DictConfigSource(label, data=kwargs.get('data'))
elif source_type == 'json':
return JsonConfigSource(label, **kwargs)
elif source_type == 'yaml':
filename = kwargs.get('filename')
if 'filename' in kwargs:
kwargs.pop('filename')
return YamlConfigSource(label, filename, **kwargs)
elif source_type == 'environment':
return EnvironmentConfigSource(label)
elif source_type == 'etcd':
return EtcdConfigSource(
label, kwargs.get('client'), kwargs.get('key', '/')
)
elif source_type == 'kubernetes':
name = kwargs.get('name')
if 'name' in kwargs:
kwargs.pop('name')
client = kwargs.get('client')
if 'client' in kwargs:
kwargs.pop('client')
return KubernetesConfigSource(label, client, name, **kwargs)
else:
raise NotImplementedError(
'No implementation for source type %s' % source_type
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 37; 1, 39; 2, function_name:_project_observable; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 13; 3, 24; 3, 35; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:input_key; 7, type; 7, 8; 8, identifier:str; 9, typed_parameter; 9, 10; 9, 11; 10, identifier:input_observable; 11, type; 11, 12; 12, identifier:Any; 13, typed_default_parameter; 13, 14; 13, 15; 13, 23; 14, identifier:get_hist_args; 15, type; 15, 16; 16, generic_type; 16, 17; 16, 18; 17, identifier:Dict; 18, type_parameter; 18, 19; 18, 21; 19, type; 19, 20; 20, identifier:str; 21, type; 21, 22; 22, identifier:Any; 23, None; 24, typed_default_parameter; 24, 25; 24, 26; 24, 34; 25, identifier:projection_name_args; 26, type; 26, 27; 27, generic_type; 27, 28; 27, 29; 28, identifier:Dict; 29, type_parameter; 29, 30; 29, 32; 30, type; 30, 31; 31, identifier:str; 32, type; 32, 33; 33, identifier:Any; 34, None; 35, dictionary_splat_pattern; 35, 36; 36, identifier:kwargs; 37, type; 37, 38; 38, identifier:Hist; 39, block; 39, 40; 39, 42; 39, 43; 39, 57; 39, 71; 39, 72; 39, 73; 39, 74; 39, 84; 39, 94; 39, 95; 39, 104; 39, 105; 39, 106; 39, 113; 39, 114; 39, 131; 39, 141; 39, 142; 39, 143; 39, 150; 39, 170; 39, 171; 39, 187; 39, 188; 39, 189; 39, 215; 39, 226; 39, 227; 39, 231; 39, 297; 39, 298; 39, 310; 39, 311; 39, 317; 39, 332; 39, 333; 39, 340; 39, 341; 39, 342; 39, 349; 40, expression_statement; 40, 41; 41, comment; 42, comment; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:is; 44, 45; 44, 46; 45, identifier:get_hist_args; 46, None; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:get_hist_args; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:copy; 54, identifier:deepcopy; 55, argument_list; 55, 56; 56, identifier:kwargs; 57, if_statement; 57, 58; 57, 61; 58, comparison_operator:is; 58, 59; 58, 60; 59, identifier:projection_name_args; 60, None; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:projection_name_args; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:copy; 68, identifier:deepcopy; 69, argument_list; 69, 70; 70, identifier:kwargs; 71, comment; 72, comment; 73, comment; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:get_hist_args; 78, identifier:update; 79, argument_list; 79, 80; 80, dictionary; 80, 81; 81, pair; 81, 82; 81, 83; 82, string:"observable"; 83, identifier:input_observable; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:hist; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:get_hist; 91, argument_list; 91, 92; 92, dictionary_splat; 92, 93; 93, identifier:get_hist_args; 94, comment; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:projection_name_args; 99, identifier:update; 100, argument_list; 100, 101; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:projection_information; 104, comment; 105, comment; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:projection_name_args; 110, identifier:update; 111, argument_list; 111, 112; 112, identifier:kwargs; 113, comment; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:projection_name_args; 118, identifier:update; 119, argument_list; 119, 120; 120, dictionary; 120, 121; 120, 122; 120, 125; 120, 128; 121, comment; 122, pair; 122, 123; 122, 124; 123, string:"input_key"; 124, identifier:input_key; 125, pair; 125, 126; 125, 127; 126, string:"input_observable"; 127, identifier:input_observable; 128, pair; 128, 129; 128, 130; 129, string:"input_hist"; 130, identifier:hist; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:projection_name; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:projection_name; 138, argument_list; 138, 139; 139, dictionary_splat; 139, 140; 140, identifier:projection_name_args; 141, comment; 142, comment; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:logger; 147, identifier:debug; 148, argument_list; 148, 149; 149, string:f"hist: {hist}"; 150, for_statement; 150, 151; 150, 152; 150, 155; 151, identifier:axis; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:additional_axis_cuts; 155, block; 155, 156; 155, 163; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:logger; 160, identifier:debug; 161, argument_list; 161, 162; 162, string:f"Apply additional axis hist range: {axis.name}"; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:axis; 167, identifier:apply_range_set; 168, argument_list; 168, 169; 169, identifier:hist; 170, comment; 171, if_statement; 171, 172; 171, 177; 172, comparison_operator:==; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:projection_dependent_cut_axes; 176, list:[]; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:projection_dependent_cut_axes; 184, identifier:append; 185, argument_list; 185, 186; 186, list:[]; 187, comment; 188, comment; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:duplicated_axes; 192, list_comprehension; 192, 193; 192, 194; 192, 199; 192, 204; 192, 207; 193, identifier:PDCA; 194, for_in_clause; 194, 195; 194, 196; 195, identifier:PA; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:projection_axes; 199, for_in_clause; 199, 200; 199, 201; 200, identifier:PDCA_group; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:projection_dependent_cut_axes; 204, for_in_clause; 204, 205; 204, 206; 205, identifier:PDCA; 206, identifier:PDCA_group; 207, if_clause; 207, 208; 208, comparison_operator:==; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:PDCA; 211, identifier:axis_type; 212, attribute; 212, 213; 212, 214; 213, identifier:PA; 214, identifier:axis_type; 215, if_statement; 215, 216; 215, 217; 216, identifier:duplicated_axes; 217, block; 217, 218; 218, raise_statement; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:ValueError; 221, argument_list; 221, 222; 222, concatenated_string; 222, 223; 222, 224; 222, 225; 223, string:f"Axis {duplicated_axes} is in the projection axes and the projection dependent cut axes."; 224, string:" This configuration is not allowed, as the range in the PDCA will be overwritten by the projection axes!"; 225, string:" Please revise your configuration."; 226, comment; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:hists; 230, list:[]; 231, for_statement; 231, 232; 231, 235; 231, 241; 231, 242; 232, pattern_list; 232, 233; 232, 234; 233, identifier:i; 234, identifier:axes; 235, call; 235, 236; 235, 237; 236, identifier:enumerate; 237, argument_list; 237, 238; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:projection_dependent_cut_axes; 241, comment; 242, block; 242, 243; 242, 261; 242, 262; 242, 271; 242, 278; 242, 285; 242, 286; 242, 287; 243, for_statement; 243, 244; 243, 245; 243, 246; 244, identifier:axis; 245, identifier:axes; 246, block; 246, 247; 246, 254; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:logger; 251, identifier:debug; 252, argument_list; 252, 253; 253, string:f"Apply projection dependent hist range: {axis.name}"; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:axis; 258, identifier:apply_range_set; 259, argument_list; 259, 260; 260, identifier:hist; 261, comment; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:projected_hist; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:call_projection_function; 269, argument_list; 269, 270; 270, identifier:hist; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:projected_hist; 275, identifier:SetName; 276, argument_list; 276, 277; 277, string:f"{projection_name}_{i}"; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:hists; 282, identifier:append; 283, argument_list; 283, 284; 284, identifier:projected_hist; 285, comment; 286, comment; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:cleanup_cuts; 292, argument_list; 292, 293; 292, 294; 293, identifier:hist; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:cut_axes; 296, identifier:axes; 297, comment; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:cleanup_cuts; 303, argument_list; 303, 304; 303, 305; 304, identifier:hist; 305, keyword_argument; 305, 306; 305, 307; 306, identifier:cut_axes; 307, attribute; 307, 308; 307, 309; 308, identifier:self; 309, identifier:additional_axis_cuts; 310, comment; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:output_hist; 314, subscript; 314, 315; 314, 316; 315, identifier:hists; 316, integer:0; 317, for_statement; 317, 318; 317, 319; 317, 324; 318, identifier:temp_hist; 319, subscript; 319, 320; 319, 321; 320, identifier:hists; 321, slice; 321, 322; 321, 323; 322, integer:1; 323, colon; 324, block; 324, 325; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:output_hist; 329, identifier:Add; 330, argument_list; 330, 331; 331, identifier:temp_hist; 332, comment; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:output_hist; 337, identifier:SetName; 338, argument_list; 338, 339; 339, identifier:projection_name; 340, comment; 341, comment; 342, expression_statement; 342, 343; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:output_hist; 346, identifier:SetDirectory; 347, argument_list; 347, 348; 348, integer:0; 349, return_statement; 349, 350; 350, expression_list; 350, 351; 350, 352; 350, 353; 351, identifier:output_hist; 352, identifier:projection_name; 353, identifier:projection_name_args | def _project_observable(self, input_key: str,
input_observable: Any,
get_hist_args: Dict[str, Any] = None,
projection_name_args: Dict[str, Any] = None,
**kwargs) -> Hist:
""" Perform a projection for a single observable.
Note:
All cuts on the original histograms will be reset when this function is completed.
Args:
input_key: Key to describe the input observable.
input_observable: Observable to project from.
get_hist_args: Arguments to pass to ``get_hist(...)``. Made available so the args can be cached
to avoid a ``deepcopy`` when looping. Default: None. In this case, they will be retrieved
automatically.
projection_name_args: Arguments to pass to ``projection_name(...)``. Made available so the args
can be cached to avoid a ``deepcopy`` when looping. Default: None. In this case, they will be
retrieved automatically.
kwargs: Additional named args to be passed to projection_name(...) and output_key_name(...).
Returns:
The projected histogram.
"""
# Validation of other optional arguments.
if get_hist_args is None:
get_hist_args = copy.deepcopy(kwargs)
if projection_name_args is None:
projection_name_args = copy.deepcopy(kwargs)
# Retrieve histogram
# We update ``input_observable`` in ``get_hist_args`` every loop, so we don't have to worry
# about passing the wrong observable.
get_hist_args.update({"observable": input_observable})
hist = self.get_hist(**get_hist_args)
# Define projection name
projection_name_args.update(self.projection_information)
# In principle, we could have overwritten one of the kwargs, so we ensure with one of the other
# updates, so we update it again to be certain.
projection_name_args.update(kwargs)
# Put the values included by default last to ensure nothing overwrites these values
projection_name_args.update({ # type: ignore
"input_key": input_key,
"input_observable": input_observable,
"input_hist": hist
})
projection_name = self.projection_name(**projection_name_args)
# First apply the cuts
# Restricting the range with SetRange(User) works properly for both THn and TH1.
logger.debug(f"hist: {hist}")
for axis in self.additional_axis_cuts:
logger.debug(f"Apply additional axis hist range: {axis.name}")
axis.apply_range_set(hist)
# We need to ensure that it isn't empty so at least one project occurs
if self.projection_dependent_cut_axes == []:
self.projection_dependent_cut_axes.append([])
# Validate the projection dependent cut axes
# It is invalid to have PDCA on the same axes as the projection axes.
duplicated_axes = [
PDCA
for PA in self.projection_axes
for PDCA_group in self.projection_dependent_cut_axes
for PDCA in PDCA_group
if PDCA.axis_type == PA.axis_type
]
if duplicated_axes:
raise ValueError(
f"Axis {duplicated_axes} is in the projection axes and the projection dependent cut axes."
" This configuration is not allowed, as the range in the PDCA will be overwritten by the projection axes!"
" Please revise your configuration."
)
# Perform the projections
hists = []
for i, axes in enumerate(self.projection_dependent_cut_axes):
# Projection dependent range set
for axis in axes:
logger.debug(f"Apply projection dependent hist range: {axis.name}")
axis.apply_range_set(hist)
# Do the projection
projected_hist = self.call_projection_function(hist)
projected_hist.SetName(f"{projection_name}_{i}")
hists.append(projected_hist)
# Cleanup projection dependent cuts (although they should be set again on the next
# iteration of the loop)
self.cleanup_cuts(hist, cut_axes = axes)
# Cleanup the rest of the cuts
self.cleanup_cuts(hist, cut_axes = self.additional_axis_cuts)
# Combine all of the projections together
output_hist = hists[0]
for temp_hist in hists[1:]:
output_hist.Add(temp_hist)
# Final settings
output_hist.SetName(projection_name)
# Ensure that the hist doesn't get deleted by ROOT
# A reference to the histogram within python may not be enough
output_hist.SetDirectory(0)
return output_hist, projection_name, projection_name_args |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:getrruleset; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:addRDate; 7, False; 8, block; 8, 9; 8, 11; 8, 15; 8, 499; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:rruleset; 14, None; 15, for_statement; 15, 16; 15, 17; 15, 18; 16, identifier:name; 17, identifier:DATESANDRULES; 18, block; 18, 19; 18, 23; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:addfunc; 22, None; 23, for_statement; 23, 24; 23, 25; 23, 34; 23, 35; 24, identifier:line; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:contents; 30, identifier:get; 31, argument_list; 31, 32; 31, 33; 32, identifier:name; 33, tuple; 34, comment; 35, block; 35, 36; 35, 49; 35, 62; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:rruleset; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:rruleset; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:rrule; 47, identifier:rruleset; 48, argument_list; 49, if_statement; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:addfunc; 52, None; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:addfunc; 57, call; 57, 58; 57, 59; 58, identifier:getattr; 59, argument_list; 59, 60; 59, 61; 60, identifier:rruleset; 61, identifier:name; 62, if_statement; 62, 63; 62, 66; 62, 131; 63, comparison_operator:in; 63, 64; 63, 65; 64, identifier:name; 65, identifier:DATENAMES; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 80; 67, 89; 67, 127; 68, comparison_operator:==; 68, 69; 68, 77; 69, call; 69, 70; 69, 71; 70, identifier:type; 71, argument_list; 71, 72; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:line; 75, identifier:value; 76, integer:0; 77, attribute; 77, 78; 77, 79; 78, identifier:datetime; 79, identifier:datetime; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:map; 84, argument_list; 84, 85; 84, 86; 85, identifier:addfunc; 86, attribute; 86, 87; 86, 88; 87, identifier:line; 88, identifier:value; 89, elif_clause; 89, 90; 89, 102; 90, comparison_operator:==; 90, 91; 90, 99; 91, call; 91, 92; 91, 93; 92, identifier:type; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:line; 97, identifier:value; 98, integer:0; 99, attribute; 99, 100; 99, 101; 100, identifier:datetime; 101, identifier:date; 102, block; 102, 103; 103, for_statement; 103, 104; 103, 105; 103, 108; 104, identifier:dt; 105, attribute; 105, 106; 105, 107; 106, identifier:line; 107, identifier:value; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:addfunc; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:datetime; 116, identifier:datetime; 117, argument_list; 117, 118; 117, 121; 117, 124; 118, attribute; 118, 119; 118, 120; 119, identifier:dt; 120, identifier:year; 121, attribute; 121, 122; 121, 123; 122, identifier:dt; 123, identifier:month; 124, attribute; 124, 125; 124, 126; 125, identifier:dt; 126, identifier:day; 127, else_clause; 127, 128; 127, 129; 128, comment; 129, block; 129, 130; 130, pass_statement; 131, elif_clause; 131, 132; 131, 135; 132, comparison_operator:in; 132, 133; 132, 134; 133, identifier:name; 134, identifier:RULENAMES; 135, block; 135, 136; 135, 192; 135, 193; 135, 194; 135, 209; 135, 221; 135, 227; 135, 388; 135, 389; 135, 394; 136, try_statement; 136, 137; 136, 146; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:dtstart; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:dtstart; 145, identifier:value; 146, except_clause; 146, 147; 146, 150; 146, 151; 147, tuple; 147, 148; 147, 149; 148, identifier:AttributeError; 149, identifier:KeyError; 150, comment; 151, block; 151, 152; 152, try_statement; 152, 153; 152, 179; 153, block; 153, 154; 154, if_statement; 154, 155; 154, 160; 154, 169; 155, comparison_operator:==; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:name; 159, string:"VTODO"; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:dtstart; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:due; 168, identifier:value; 169, else_clause; 169, 170; 169, 171; 170, comment; 171, block; 171, 172; 171, 177; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:print; 175, argument_list; 175, 176; 176, string:'failed to get dtstart with VTODO'; 177, return_statement; 177, 178; 178, None; 179, except_clause; 179, 180; 179, 183; 179, 184; 180, tuple; 180, 181; 180, 182; 181, identifier:AttributeError; 182, identifier:KeyError; 183, comment; 184, block; 184, 185; 184, 190; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:print; 188, argument_list; 188, 189; 189, string:'failed to find DUE at all.'; 190, return_statement; 190, 191; 191, None; 192, comment; 193, comment; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:value; 197, call; 197, 198; 197, 206; 198, attribute; 198, 199; 198, 205; 199, call; 199, 200; 199, 201; 200, identifier:str_; 201, argument_list; 201, 202; 202, attribute; 202, 203; 202, 204; 203, identifier:line; 204, identifier:value; 205, identifier:replace; 206, argument_list; 206, 207; 206, 208; 207, string:'\\'; 208, string:''; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:rule; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:rrule; 215, identifier:rrulestr; 216, argument_list; 216, 217; 216, 218; 217, identifier:value; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:dtstart; 220, identifier:dtstart; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:until; 224, attribute; 224, 225; 224, 226; 225, identifier:rule; 226, identifier:_until; 227, if_statement; 227, 228; 227, 249; 227, 250; 227, 251; 228, boolean_operator:and; 228, 229; 228, 240; 228, 241; 229, boolean_operator:and; 229, 230; 229, 233; 230, comparison_operator:is; 230, 231; 230, 232; 231, identifier:until; 232, None; 233, call; 233, 234; 233, 235; 234, identifier:isinstance; 235, argument_list; 235, 236; 235, 237; 236, identifier:dtstart; 237, attribute; 237, 238; 237, 239; 238, identifier:datetime; 239, identifier:datetime; 240, line_continuation:\; 241, parenthesized_expression; 241, 242; 242, comparison_operator:!=; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:until; 245, identifier:tzinfo; 246, attribute; 246, 247; 246, 248; 247, identifier:dtstart; 248, identifier:tzinfo; 249, comment; 250, comment; 251, block; 251, 252; 251, 278; 251, 312; 251, 313; 251, 314; 251, 315; 251, 316; 251, 317; 251, 337; 251, 355; 251, 356; 251, 357; 251, 358; 251, 359; 251, 360; 251, 361; 251, 362; 251, 363; 251, 364; 251, 382; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:vals; 255, call; 255, 256; 255, 257; 256, identifier:dict; 257, generator_expression; 257, 258; 257, 264; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:pair; 261, identifier:split; 262, argument_list; 262, 263; 263, string:'='; 264, for_in_clause; 264, 265; 264, 266; 265, identifier:pair; 266, call; 266, 267; 266, 276; 267, attribute; 267, 268; 267, 275; 268, call; 268, 269; 268, 274; 269, attribute; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:line; 272, identifier:value; 273, identifier:upper; 274, argument_list; 275, identifier:split; 276, argument_list; 276, 277; 277, string:';'; 278, if_statement; 278, 279; 278, 291; 279, comparison_operator:==; 279, 280; 279, 290; 280, call; 280, 281; 280, 282; 281, identifier:len; 282, argument_list; 282, 283; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:vals; 286, identifier:get; 287, argument_list; 287, 288; 287, 289; 288, string:'UNTIL'; 289, string:''; 290, integer:8; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:until; 295, call; 295, 296; 295, 301; 296, attribute; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:datetime; 299, identifier:datetime; 300, identifier:combine; 301, argument_list; 301, 302; 301, 307; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:until; 305, identifier:date; 306, argument_list; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:dtstart; 310, identifier:time; 311, argument_list; 312, comment; 313, comment; 314, comment; 315, comment; 316, comment; 317, if_statement; 317, 318; 317, 323; 318, comparison_operator:is; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:until; 321, identifier:tzinfo; 322, None; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:until; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:until; 330, identifier:replace; 331, argument_list; 331, 332; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:tzinfo; 334, attribute; 334, 335; 334, 336; 335, identifier:dtstart; 336, identifier:tzinfo; 337, if_statement; 337, 338; 337, 343; 338, comparison_operator:is; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:dtstart; 341, identifier:tzinfo; 342, None; 343, block; 343, 344; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:until; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:until; 350, identifier:astimezone; 351, argument_list; 351, 352; 352, attribute; 352, 353; 352, 354; 353, identifier:dtstart; 354, identifier:tzinfo; 355, comment; 356, comment; 357, comment; 358, comment; 359, comment; 360, comment; 361, comment; 362, comment; 363, comment; 364, if_statement; 364, 365; 364, 370; 365, comparison_operator:is; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:dtstart; 368, identifier:tzinfo; 369, None; 370, block; 370, 371; 371, expression_statement; 371, 372; 372, assignment; 372, 373; 372, 374; 373, identifier:until; 374, call; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:until; 377, identifier:replace; 378, argument_list; 378, 379; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:tzinfo; 381, None; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:rule; 386, identifier:_until; 387, identifier:until; 388, comment; 389, expression_statement; 389, 390; 390, call; 390, 391; 390, 392; 391, identifier:addfunc; 392, argument_list; 392, 393; 393, identifier:rule; 394, if_statement; 394, 395; 394, 400; 395, boolean_operator:and; 395, 396; 395, 399; 396, comparison_operator:==; 396, 397; 396, 398; 397, identifier:name; 398, string:'rrule'; 399, identifier:addRDate; 400, block; 400, 401; 400, 474; 401, try_statement; 401, 402; 401, 403; 401, 404; 401, 405; 401, 466; 402, comment; 403, comment; 404, comment; 405, block; 405, 406; 405, 437; 406, if_statement; 406, 407; 406, 415; 406, 431; 407, not_operator; 407, 408; 408, call; 408, 409; 408, 410; 409, identifier:isinstance; 410, argument_list; 410, 411; 410, 412; 411, identifier:dtstart; 412, attribute; 412, 413; 412, 414; 413, identifier:datetime; 414, identifier:datetime; 415, block; 415, 416; 416, expression_statement; 416, 417; 417, assignment; 417, 418; 417, 419; 418, identifier:adddtstart; 419, call; 419, 420; 419, 425; 420, attribute; 420, 421; 420, 424; 421, attribute; 421, 422; 421, 423; 422, identifier:datetime; 423, identifier:datetime; 424, identifier:fromordinal; 425, argument_list; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:dtstart; 429, identifier:toordinal; 430, argument_list; 431, else_clause; 431, 432; 432, block; 432, 433; 433, expression_statement; 433, 434; 434, assignment; 434, 435; 434, 436; 435, identifier:adddtstart; 436, identifier:dtstart; 437, if_statement; 437, 438; 437, 448; 437, 460; 438, comparison_operator:!=; 438, 439; 438, 447; 439, subscript; 439, 440; 439, 446; 440, subscript; 440, 441; 440, 444; 441, attribute; 441, 442; 441, 443; 442, identifier:rruleset; 443, identifier:_rrule; 444, unary_operator:-; 444, 445; 445, integer:1; 446, integer:0; 447, identifier:adddtstart; 448, block; 448, 449; 448, 456; 449, expression_statement; 449, 450; 450, call; 450, 451; 450, 454; 451, attribute; 451, 452; 451, 453; 452, identifier:rruleset; 453, identifier:rdate; 454, argument_list; 454, 455; 455, identifier:adddtstart; 456, expression_statement; 456, 457; 457, assignment; 457, 458; 457, 459; 458, identifier:added; 459, True; 460, else_clause; 460, 461; 461, block; 461, 462; 462, expression_statement; 462, 463; 463, assignment; 463, 464; 463, 465; 464, identifier:added; 465, False; 466, except_clause; 466, 467; 466, 468; 466, 469; 467, identifier:IndexError; 468, comment; 469, block; 469, 470; 470, expression_statement; 470, 471; 471, assignment; 471, 472; 471, 473; 472, identifier:added; 473, False; 474, if_statement; 474, 475; 474, 487; 475, boolean_operator:and; 475, 476; 475, 477; 476, identifier:added; 477, comparison_operator:is; 477, 478; 477, 486; 478, attribute; 478, 479; 478, 485; 479, subscript; 479, 480; 479, 483; 480, attribute; 480, 481; 480, 482; 481, identifier:rruleset; 482, identifier:_rrule; 483, unary_operator:-; 483, 484; 484, integer:1; 485, identifier:_count; 486, None; 487, block; 487, 488; 488, expression_statement; 488, 489; 489, augmented_assignment:-=; 489, 490; 489, 498; 490, attribute; 490, 491; 490, 497; 491, subscript; 491, 492; 491, 495; 492, attribute; 492, 493; 492, 494; 493, identifier:rruleset; 494, identifier:_rrule; 495, unary_operator:-; 495, 496; 496, integer:1; 497, identifier:_count; 498, integer:1; 499, return_statement; 499, 500; 500, identifier:rruleset | def getrruleset(self, addRDate=False):
"""
Get an rruleset created from self.
If addRDate is True, add an RDATE for dtstart if it's not included in
an RRULE, and count is decremented if it exists.
Note that for rules which don't match DTSTART, DTSTART may not appear
in list(rruleset), although it should. By default, an RDATE is not
created in these cases, and count isn't updated, so dateutil may list
a spurious occurrence.
"""
rruleset = None
for name in DATESANDRULES:
addfunc = None
for line in self.contents.get(name, ()):
# don't bother creating a rruleset unless there's a rule
if rruleset is None:
rruleset = rrule.rruleset()
if addfunc is None:
addfunc = getattr(rruleset, name)
if name in DATENAMES:
if type(line.value[0]) == datetime.datetime:
map(addfunc, line.value)
elif type(line.value[0]) == datetime.date:
for dt in line.value:
addfunc(datetime.datetime(dt.year, dt.month, dt.day))
else:
# ignore RDATEs with PERIOD values for now
pass
elif name in RULENAMES:
try:
dtstart = self.dtstart.value
except (AttributeError, KeyError):
# Special for VTODO - try DUE property instead
try:
if self.name == "VTODO":
dtstart = self.due.value
else:
# if there's no dtstart, just return None
print('failed to get dtstart with VTODO')
return None
except (AttributeError, KeyError):
# if there's no due, just return None
print('failed to find DUE at all.')
return None
# a Ruby iCalendar library escapes semi-colons in rrules,
# so also remove any backslashes
value = str_(line.value).replace('\\', '')
rule = rrule.rrulestr(value, dtstart=dtstart)
until = rule._until
if until is not None and isinstance(dtstart, datetime.datetime) and \
(until.tzinfo != dtstart.tzinfo):
# dateutil converts the UNTIL date to a datetime,
# check to see if the UNTIL parameter value was a date
vals = dict(pair.split('=') for pair in
line.value.upper().split(';'))
if len(vals.get('UNTIL', '')) == 8:
until = datetime.datetime.combine(until.date(), dtstart.time())
# While RFC2445 says UNTIL MUST be UTC, Chandler allows
# floating recurring events, and uses floating UNTIL values.
# Also, some odd floating UNTIL but timezoned DTSTART values
# have shown up in the wild, so put floating UNTIL values
# DTSTART's timezone
if until.tzinfo is None:
until = until.replace(tzinfo=dtstart.tzinfo)
if dtstart.tzinfo is not None:
until = until.astimezone(dtstart.tzinfo)
# RFC2445 actually states that UNTIL must be a UTC value. Whilst the
# changes above work OK, one problem case is if DTSTART is floating but
# UNTIL is properly specified as UTC (or with a TZID). In that case dateutil
# will fail datetime comparisons. There is no easy solution to this as
# there is no obvious timezone (at this point) to do proper floating time
# offset compisons. The best we can do is treat the UNTIL value as floating.
# This could mean incorrect determination of the last instance. The better
# solution here is to encourage clients to use COUNT rather than UNTIL
# when DTSTART is floating.
if dtstart.tzinfo is None:
until = until.replace(tzinfo=None)
rule._until = until
# add the rrule or exrule to the rruleset
addfunc(rule)
if name == 'rrule' and addRDate:
try:
# dateutils does not work with all-day (datetime.date) items
# so we need to convert to a datetime.datetime
# (which is what dateutils does internally)
if not isinstance(dtstart, datetime.datetime):
adddtstart = datetime.datetime.fromordinal(dtstart.toordinal())
else:
adddtstart = dtstart
if rruleset._rrule[-1][0] != adddtstart:
rruleset.rdate(adddtstart)
added = True
else:
added = False
except IndexError:
# it's conceivable that an rrule might have 0 datetimes
added = False
if added and rruleset._rrule[-1]._count is not None:
rruleset._rrule[-1]._count -= 1
return rruleset |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:list_processed_parameter_group_histogram; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:group; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stop; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:merge_time; 16, integer:20; 17, block; 17, 18; 17, 20; 17, 24; 17, 35; 17, 49; 17, 63; 17, 79; 18, expression_statement; 18, 19; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:params; 23, dictionary; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:group; 27, None; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:params; 33, string:'group'; 34, identifier:group; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:start; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:params; 44, string:'start'; 45, call; 45, 46; 45, 47; 46, identifier:to_isostring; 47, argument_list; 47, 48; 48, identifier:start; 49, if_statement; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:stop; 52, None; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:params; 58, string:'stop'; 59, call; 59, 60; 59, 61; 60, identifier:to_isostring; 61, argument_list; 61, 62; 62, identifier:stop; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:merge_time; 66, None; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:params; 72, string:'mergeTime'; 73, call; 73, 74; 73, 75; 74, identifier:int; 75, argument_list; 75, 76; 76, binary_operator:*; 76, 77; 76, 78; 77, identifier:merge_time; 78, integer:1000; 79, return_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:pagination; 83, identifier:Iterator; 84, argument_list; 84, 85; 84, 90; 84, 100; 84, 103; 84, 108; 84, 111; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:client; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_client; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:path; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:'/archive/{}/parameter-index'; 95, identifier:format; 96, argument_list; 96, 97; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_instance; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:params; 102, identifier:params; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:response_class; 105, attribute; 105, 106; 105, 107; 106, identifier:archive_pb2; 107, identifier:IndexResponse; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:items_key; 110, string:'group'; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:item_mapper; 113, identifier:IndexGroup | def list_processed_parameter_group_histogram(self, group=None, start=None, stop=None, merge_time=20):
"""
Reads index records related to processed parameter groups between the
specified start and stop time.
Each iteration returns a chunk of chronologically-sorted records.
:param float merge_time: Maximum gap in seconds before two consecutive index records are merged together.
:rtype: ~collections.Iterable[.IndexGroup]
"""
params = {}
if group is not None:
params['group'] = group
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
if merge_time is not None:
params['mergeTime'] = int(merge_time * 1000)
return pagination.Iterator(
client=self._client,
path='/archive/{}/parameter-index'.format(self._instance),
params=params,
response_class=archive_pb2.IndexResponse,
items_key='group',
item_mapper=IndexGroup,
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:list_completeness_index; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:start; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:stop; 10, None; 11, block; 11, 12; 11, 14; 11, 18; 11, 32; 11, 46; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:params; 17, dictionary; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:start; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:params; 27, string:'start'; 28, call; 28, 29; 28, 30; 29, identifier:to_isostring; 30, argument_list; 30, 31; 31, identifier:start; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:stop; 35, None; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:params; 41, string:'stop'; 42, call; 42, 43; 42, 44; 43, identifier:to_isostring; 44, argument_list; 44, 45; 45, identifier:stop; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:pagination; 50, identifier:Iterator; 51, argument_list; 51, 52; 51, 57; 51, 67; 51, 70; 51, 75; 51, 78; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:client; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_client; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:path; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, string:'/archive/{}/completeness-index'; 62, identifier:format; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_instance; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:params; 69, identifier:params; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:response_class; 72, attribute; 72, 73; 72, 74; 73, identifier:archive_pb2; 74, identifier:IndexResponse; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:items_key; 77, string:'group'; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:item_mapper; 80, identifier:IndexGroup | def list_completeness_index(self, start=None, stop=None):
"""
Reads completeness index records between the specified start and stop
time.
Each iteration returns a chunk of chronologically-sorted records.
:rtype: ~collections.Iterable[.IndexGroup]
"""
params = {}
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
return pagination.Iterator(
client=self._client,
path='/archive/{}/completeness-index'.format(self._instance),
params=params,
response_class=archive_pb2.IndexResponse,
items_key='group',
item_mapper=IndexGroup,
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:list_packets; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stop; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:page_size; 16, integer:500; 17, default_parameter; 17, 18; 17, 19; 18, identifier:descending; 19, False; 20, block; 20, 21; 20, 23; 20, 33; 20, 44; 20, 55; 20, 69; 20, 83; 21, expression_statement; 21, 22; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:params; 26, dictionary; 26, 27; 27, pair; 27, 28; 27, 29; 28, string:'order'; 29, conditional_expression:if; 29, 30; 29, 31; 29, 32; 30, string:'desc'; 31, identifier:descending; 32, string:'asc'; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:name; 36, None; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:params; 42, string:'name'; 43, identifier:name; 44, if_statement; 44, 45; 44, 48; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:page_size; 47, None; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:params; 53, string:'limit'; 54, identifier:page_size; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:start; 58, None; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:params; 64, string:'start'; 65, call; 65, 66; 65, 67; 66, identifier:to_isostring; 67, argument_list; 67, 68; 68, identifier:start; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:stop; 72, None; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:params; 78, string:'stop'; 79, call; 79, 80; 79, 81; 80, identifier:to_isostring; 81, argument_list; 81, 82; 82, identifier:stop; 83, return_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:pagination; 87, identifier:Iterator; 88, argument_list; 88, 89; 88, 94; 88, 104; 88, 107; 88, 112; 88, 115; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:client; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:_client; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:path; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:'/archive/{}/packets'; 99, identifier:format; 100, argument_list; 100, 101; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:_instance; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:params; 106, identifier:params; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:response_class; 109, attribute; 109, 110; 109, 111; 110, identifier:rest_pb2; 111, identifier:ListPacketsResponse; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:items_key; 114, string:'packet'; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:item_mapper; 117, identifier:Packet | def list_packets(self, name=None, start=None, stop=None, page_size=500, descending=False):
"""
Reads packet information between the specified start and stop
time.
Packets are sorted by generation time and sequence number.
:param ~datetime.datetime start: Minimum generation time of the returned
packets (inclusive)
:param ~datetime.datetime stop: Maximum genreation time of the returned
packets (exclusive)
:param int page_size: Page size of underlying requests. Higher values imply
less overhead, but risk hitting the maximum message size limit.
:param bool descending: If set to ``True`` packets are fetched in reverse
order (most recent first).
:rtype: ~collections.Iterable[.Packet]
"""
params = {
'order': 'desc' if descending else 'asc',
}
if name is not None:
params['name'] = name
if page_size is not None:
params['limit'] = page_size
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
return pagination.Iterator(
client=self._client,
path='/archive/{}/packets'.format(self._instance),
params=params,
response_class=rest_pb2.ListPacketsResponse,
items_key='packet',
item_mapper=Packet,
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:list_events; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:source; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:severity; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:text_filter; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:start; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:stop; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:page_size; 22, integer:500; 23, default_parameter; 23, 24; 23, 25; 24, identifier:descending; 25, False; 26, block; 26, 27; 26, 29; 26, 39; 26, 50; 26, 61; 26, 72; 26, 86; 26, 100; 26, 111; 27, expression_statement; 27, 28; 28, comment; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:params; 32, dictionary; 32, 33; 33, pair; 33, 34; 33, 35; 34, string:'order'; 35, conditional_expression:if; 35, 36; 35, 37; 35, 38; 36, string:'desc'; 37, identifier:descending; 38, string:'asc'; 39, if_statement; 39, 40; 39, 43; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:source; 42, None; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:params; 48, string:'source'; 49, identifier:source; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:is; 51, 52; 51, 53; 52, identifier:page_size; 53, None; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:params; 59, string:'limit'; 60, identifier:page_size; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:severity; 64, None; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:params; 70, string:'severity'; 71, identifier:severity; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:start; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:params; 81, string:'start'; 82, call; 82, 83; 82, 84; 83, identifier:to_isostring; 84, argument_list; 84, 85; 85, identifier:start; 86, if_statement; 86, 87; 86, 90; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:stop; 89, None; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:params; 95, string:'stop'; 96, call; 96, 97; 96, 98; 97, identifier:to_isostring; 98, argument_list; 98, 99; 99, identifier:stop; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:is; 101, 102; 101, 103; 102, identifier:text_filter; 103, None; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:params; 109, string:'q'; 110, identifier:text_filter; 111, return_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:pagination; 115, identifier:Iterator; 116, argument_list; 116, 117; 116, 122; 116, 132; 116, 135; 116, 140; 116, 143; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:client; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:_client; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:path; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, string:'/archive/{}/events'; 127, identifier:format; 128, argument_list; 128, 129; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_instance; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:params; 134, identifier:params; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:response_class; 137, attribute; 137, 138; 137, 139; 138, identifier:rest_pb2; 139, identifier:ListEventsResponse; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:items_key; 142, string:'event'; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:item_mapper; 145, identifier:Event | def list_events(self, source=None, severity=None, text_filter=None,
start=None, stop=None, page_size=500, descending=False):
"""
Reads events between the specified start and stop time.
Events are sorted by generation time, source, then sequence number.
:param str source: The source of the returned events.
:param str severity: The minimum severity level of the returned events.
One of ``INFO``, ``WATCH``, ``WARNING``, ``DISTRESS``,
``CRITICAL`` or ``SEVERE``.
:param str text_filter: Filter the text message of the returned events
:param ~datetime.datetime start: Minimum start date of the returned events (inclusive)
:param ~datetime.datetime stop: Maximum start date of the returned events (exclusive)
:param int page_size: Page size of underlying requests. Higher values imply
less overhead, but risk hitting the maximum message size limit.
:param bool descending: If set to ``True`` events are fetched in reverse
order (most recent first).
:rtype: ~collections.Iterable[.Event]
"""
params = {
'order': 'desc' if descending else 'asc',
}
if source is not None:
params['source'] = source
if page_size is not None:
params['limit'] = page_size
if severity is not None:
params['severity'] = severity
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
if text_filter is not None:
params['q'] = text_filter
return pagination.Iterator(
client=self._client,
path='/archive/{}/events'.format(self._instance),
params=params,
response_class=rest_pb2.ListEventsResponse,
items_key='event',
item_mapper=Event,
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:list_parameter_ranges; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:parameter; 6, default_parameter; 6, 7; 6, 8; 7, identifier:start; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:stop; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:min_gap; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:max_gap; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:parameter_cache; 20, string:'realtime'; 21, block; 21, 22; 21, 24; 21, 36; 21, 40; 21, 54; 21, 68; 21, 84; 21, 100; 21, 117; 21, 133; 21, 141; 21, 150; 21, 158; 22, expression_statement; 22, 23; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:path; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:'/archive/{}/parameters{}/ranges'; 30, identifier:format; 31, argument_list; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_instance; 35, identifier:parameter; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:params; 39, dictionary; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:start; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:params; 49, string:'start'; 50, call; 50, 51; 50, 52; 51, identifier:to_isostring; 52, argument_list; 52, 53; 53, identifier:start; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:is; 55, 56; 55, 57; 56, identifier:stop; 57, None; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:params; 63, string:'stop'; 64, call; 64, 65; 64, 66; 65, identifier:to_isostring; 66, argument_list; 66, 67; 67, identifier:stop; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:min_gap; 71, None; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:params; 77, string:'minGap'; 78, call; 78, 79; 78, 80; 79, identifier:int; 80, argument_list; 80, 81; 81, binary_operator:*; 81, 82; 81, 83; 82, identifier:min_gap; 83, integer:1000; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:is; 85, 86; 85, 87; 86, identifier:max_gap; 87, None; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:params; 93, string:'maxGap'; 94, call; 94, 95; 94, 96; 95, identifier:int; 96, argument_list; 96, 97; 97, binary_operator:*; 97, 98; 97, 99; 98, identifier:max_gap; 99, integer:1000; 100, if_statement; 100, 101; 100, 102; 100, 109; 101, identifier:parameter_cache; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:params; 107, string:'processor'; 108, identifier:parameter_cache; 109, else_clause; 109, 110; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:params; 115, string:'norealtime'; 116, True; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:response; 120, call; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_client; 125, identifier:get_proto; 126, argument_list; 126, 127; 126, 130; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:path; 129, identifier:path; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:params; 132, identifier:params; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:message; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:pvalue_pb2; 139, identifier:Ranges; 140, argument_list; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:message; 145, identifier:ParseFromString; 146, argument_list; 146, 147; 147, attribute; 147, 148; 147, 149; 148, identifier:response; 149, identifier:content; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:ranges; 153, call; 153, 154; 153, 155; 154, identifier:getattr; 155, argument_list; 155, 156; 155, 157; 156, identifier:message; 157, string:'range'; 158, return_statement; 158, 159; 159, list_comprehension; 159, 160; 159, 164; 160, call; 160, 161; 160, 162; 161, identifier:ParameterRange; 162, argument_list; 162, 163; 163, identifier:r; 164, for_in_clause; 164, 165; 164, 166; 165, identifier:r; 166, identifier:ranges | def list_parameter_ranges(self, parameter, start=None, stop=None,
min_gap=None, max_gap=None,
parameter_cache='realtime'):
"""
Returns parameter ranges between the specified start and stop time.
Each range indicates an interval during which this parameter's
value was uninterrupted and unchanged.
Ranges are a good fit for retrieving the value of a parameter
that does not change frequently. For example an on/off indicator
or some operational status. Querying ranges will then induce
much less overhead than manually processing the output of
:meth:`list_parameter_values` would.
The maximum number of returned ranges is limited to 500.
:param str parameter: Either a fully-qualified XTCE name or an alias in the
format ``NAMESPACE/NAME``.
:param ~datetime.datetime start: Minimum generation time of the considered
values (inclusive)
:param ~datetime.datetime stop: Maximum generation time of the considered
values (exclusive)
:param float min_gap: Time in seconds. Any gap (detected based on parameter
expiration) smaller than this will be ignored.
However if the parameter changes value, the ranges
will still be split.
:param float max_gap: Time in seconds. If the distance between two
subsequent parameter values is bigger than
this value (but smaller than the parameter
expiration), then an artificial gap is
created. This also applies if there is no
expiration defined for the parameter.
:param str parameter_cache: Specify the name of the processor who's
parameter cache is merged with already
archived values. To disable results from
the parameter cache, set this to ``None``.
:rtype: .ParameterRange[]
"""
path = '/archive/{}/parameters{}/ranges'.format(
self._instance, parameter)
params = {}
if start is not None:
params['start'] = to_isostring(start)
if stop is not None:
params['stop'] = to_isostring(stop)
if min_gap is not None:
params['minGap'] = int(min_gap * 1000)
if max_gap is not None:
params['maxGap'] = int(max_gap * 1000)
if parameter_cache:
params['processor'] = parameter_cache
else:
params['norealtime'] = True
response = self._client.get_proto(path=path, params=params)
message = pvalue_pb2.Ranges()
message.ParseFromString(response.content)
ranges = getattr(message, 'range')
return [ParameterRange(r) for r in ranges] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:copy_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:source; 5, identifier:destination; 6, default_parameter; 6, 7; 6, 8; 7, identifier:unique; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:case_sensitive; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:create_path; 17, False; 18, block; 18, 19; 18, 21; 19, expression_statement; 19, 20; 20, comment; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:_File; 25, identifier:copy; 26, argument_list; 26, 27; 26, 28; 26, 29; 26, 30; 26, 31; 26, 32; 27, identifier:source; 28, identifier:destination; 29, identifier:unique; 30, identifier:sort; 31, identifier:case_sensitive; 32, identifier:create_path | def copy_file(source, destination, unique=False, sort=False, case_sensitive=True, create_path=False):
"""
Python utility to create file
Args:
source: absolute/relative path of source file
destination: absolute/relative path of destination file.
Use same as source for replacing the content of existing file.
unique: Copy only unique lines from file
sort: Sort the content of file
case_sensitive: unique/sort operations to be performed case-sensitive string
create_path: Recursively create the path to destination directory in case not found
Returns: None
"""
_File.copy(source, destination, unique, sort, case_sensitive, create_path) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:tree; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:node; 5, default_parameter; 5, 6; 5, 7; 6, identifier:formatter; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:prefix; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:postfix; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:_depth; 16, integer:1; 17, block; 17, 18; 17, 20; 17, 24; 17, 35; 17, 39; 17, 43; 18, expression_statement; 18, 19; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:current; 23, integer:0; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:length; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:node; 33, identifier:keys; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:tee_joint; 38, string:'\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:elbow_joint; 42, string:'\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80'; 43, for_statement; 43, 44; 43, 47; 43, 52; 44, pattern_list; 44, 45; 44, 46; 45, identifier:key; 46, identifier:value; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:node; 50, identifier:iteritems; 51, argument_list; 52, block; 52, 53; 52, 57; 52, 67; 52, 77; 52, 87; 52, 96; 52, 115; 53, expression_statement; 53, 54; 54, augmented_assignment:+=; 54, 55; 54, 56; 55, identifier:current; 56, integer:1; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:k; 60, conditional_expression:if; 60, 61; 60, 65; 60, 66; 61, call; 61, 62; 61, 63; 62, identifier:formatter; 63, argument_list; 63, 64; 64, identifier:key; 65, identifier:formatter; 66, identifier:key; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:pre; 70, conditional_expression:if; 70, 71; 70, 75; 70, 76; 71, call; 71, 72; 71, 73; 72, identifier:prefix; 73, argument_list; 73, 74; 74, identifier:key; 75, identifier:prefix; 76, string:''; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:post; 80, conditional_expression:if; 80, 81; 80, 85; 80, 86; 81, call; 81, 82; 81, 83; 82, identifier:postfix; 83, argument_list; 83, 84; 84, identifier:key; 85, identifier:postfix; 86, string:''; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:space; 90, conditional_expression:if; 90, 91; 90, 92; 90, 95; 91, identifier:elbow_joint; 92, comparison_operator:==; 92, 93; 92, 94; 93, identifier:current; 94, identifier:length; 95, identifier:tee_joint; 96, expression_statement; 96, 97; 97, yield; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, string:' {space} {prefix}{key}{postfix}'; 101, identifier:format; 102, argument_list; 102, 103; 102, 106; 102, 109; 102, 112; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:space; 105, identifier:space; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:key; 108, identifier:k; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:prefix; 111, identifier:pre; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:postfix; 114, identifier:post; 115, if_statement; 115, 116; 115, 117; 116, identifier:value; 117, block; 117, 118; 118, for_statement; 118, 119; 118, 120; 118, 138; 119, identifier:e; 120, call; 120, 121; 120, 122; 121, identifier:tree; 122, argument_list; 122, 123; 122, 124; 122, 127; 122, 130; 122, 133; 123, identifier:value; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:formatter; 126, identifier:formatter; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:prefix; 129, identifier:prefix; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:postfix; 132, identifier:postfix; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:_depth; 135, binary_operator:+; 135, 136; 135, 137; 136, identifier:_depth; 137, integer:1; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, yield; 140, 141; 141, binary_operator:+; 141, 142; 141, 149; 142, parenthesized_expression; 142, 143; 143, conditional_expression:if; 143, 144; 143, 145; 143, 148; 144, string:' | '; 145, comparison_operator:!=; 145, 146; 145, 147; 146, identifier:current; 147, identifier:length; 148, string:' '; 149, identifier:e | def tree(node, formatter=None, prefix=None, postfix=None, _depth=1):
"""Print a tree.
Sometimes it's useful to print datastructures as a tree. This function prints
out a pretty tree with root `node`. A tree is represented as a :class:`dict`,
whose keys are node names and values are :class:`dict` objects for sub-trees
and :class:`None` for terminals.
:param dict node: The root of the tree to print.
:param callable formatter: A callable that takes a single argument, the key,
that formats the key in the tree.
:param callable prefix: A callable that takes a single argument, the key,
that adds any additional text before the formatted key.
:param callable postfix: A callable that takes a single argument, the key,
that adds any additional text after the formatted key.
"""
current = 0
length = len(node.keys())
tee_joint = '\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80'
elbow_joint = '\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80'
for key, value in node.iteritems():
current += 1
k = formatter(key) if formatter else key
pre = prefix(key) if prefix else ''
post = postfix(key) if postfix else ''
space = elbow_joint if current == length else tee_joint
yield ' {space} {prefix}{key}{postfix}'.format(space=space, key=k, prefix=pre, postfix=post)
if value:
for e in tree(value, formatter=formatter, prefix=prefix, postfix=postfix, _depth=_depth + 1):
yield (' | ' if current != length else ' ') + e |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:run; 3, parameters; 4, block; 4, 5; 4, 7; 4, 13; 4, 22; 4, 28; 4, 29; 4, 38; 4, 39; 4, 48; 4, 49; 4, 50; 4, 51; 4, 52; 4, 53; 4, 54; 4, 92; 4, 93; 4, 94; 4, 100; 4, 112; 4, 151; 4, 163; 4, 178; 4, 190; 4, 192; 4, 210; 4, 221; 4, 235; 4, 239; 4, 255; 4, 309; 4, 333; 4, 334; 4, 366; 4, 370; 4, 371; 4, 405; 4, 409; 4, 427; 4, 452; 5, expression_statement; 5, 6; 6, comment; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:args; 10, call; 10, 11; 10, 12; 11, identifier:parse_args; 12, argument_list; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:codetools; 17, identifier:setup_logging; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:args; 21, identifier:debug; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:git_tag; 25, attribute; 25, 26; 25, 27; 26, identifier:args; 27, identifier:tag; 28, comment; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:git_email; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:codetools; 35, identifier:lookup_email; 36, argument_list; 36, 37; 37, identifier:args; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:git_user; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:codetools; 45, identifier:lookup_user; 46, argument_list; 46, 47; 47, identifier:args; 48, comment; 49, comment; 50, comment; 51, comment; 52, comment; 53, comment; 54, if_statement; 54, 55; 54, 59; 55, not_operator; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:args; 58, identifier:manifest_only; 59, block; 59, 60; 59, 66; 59, 80; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:eups_tag; 63, attribute; 63, 64; 63, 65; 64, identifier:args; 65, identifier:eups_tag; 66, if_statement; 66, 67; 66, 69; 66, 70; 67, not_operator; 67, 68; 68, identifier:eups_tag; 69, comment; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:eups_tag; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:eups; 77, identifier:git_tag2eups_tag; 78, argument_list; 78, 79; 79, identifier:git_tag; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:debug; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, string:"using eups tag: {eups_tag}"; 87, identifier:format; 88, argument_list; 88, 89; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:eups_tag; 91, identifier:eups_tag; 92, comment; 93, comment; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:manifest; 97, attribute; 97, 98; 97, 99; 98, identifier:args; 99, identifier:manifest; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:debug; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, string:"using manifest: {manifest}"; 107, identifier:format; 108, argument_list; 108, 109; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:manifest; 111, identifier:manifest; 112, if_statement; 112, 113; 112, 117; 112, 118; 112, 135; 113, not_operator; 113, 114; 114, attribute; 114, 115; 114, 116; 115, identifier:args; 116, identifier:manifest_only; 117, comment; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:message_template; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, concatenated_string; 124, 125; 124, 126; 125, string:"Version {{git_tag}}"; 126, string:" release from {eups_tag}/{manifest}"; 127, identifier:format; 128, argument_list; 128, 129; 128, 132; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:eups_tag; 131, identifier:eups_tag; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:manifest; 134, identifier:manifest; 135, else_clause; 135, 136; 135, 137; 136, comment; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:message_template; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, concatenated_string; 143, 144; 143, 145; 144, string:"Version {{git_tag}}"; 145, string:" release from manifest {manifest}"; 146, identifier:format; 147, argument_list; 147, 148; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:manifest; 150, identifier:manifest; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:debug; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, string:"using tag message: {msg}"; 158, identifier:format; 159, argument_list; 159, 160; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:msg; 162, identifier:message_template; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:tagger; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:github; 169, identifier:InputGitAuthor; 170, argument_list; 170, 171; 170, 172; 170, 173; 171, identifier:git_user; 172, identifier:git_email; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:codetools; 176, identifier:current_timestamp; 177, argument_list; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:debug; 181, argument_list; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, string:"using taggger: {tagger}"; 185, identifier:format; 186, argument_list; 186, 187; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:tagger; 189, identifier:tagger; 190, global_statement; 190, 191; 191, identifier:g; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:g; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:pygithub; 198, identifier:login_github; 199, argument_list; 199, 200; 199, 205; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:token_path; 202, attribute; 202, 203; 202, 204; 203, identifier:args; 204, identifier:token_path; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:token; 207, attribute; 207, 208; 207, 209; 208, identifier:args; 209, identifier:token; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:org; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:g; 216, identifier:get_organization; 217, argument_list; 217, 218; 218, attribute; 218, 219; 218, 220; 219, identifier:args; 220, identifier:org; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:info; 224, argument_list; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, string:"tagging repos in org: {org}"; 228, identifier:format; 229, argument_list; 229, 230; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:org; 232, attribute; 232, 233; 232, 234; 233, identifier:org; 234, identifier:login; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:problems; 238, list:[]; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:manifest_products; 242, attribute; 242, 243; 242, 254; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:versiondb; 246, identifier:Manifest; 247, argument_list; 247, 248; 247, 249; 248, identifier:manifest; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:base_url; 251, attribute; 251, 252; 251, 253; 252, identifier:args; 253, identifier:versiondb_base_url; 254, identifier:products; 255, if_statement; 255, 256; 255, 260; 255, 261; 255, 301; 256, not_operator; 256, 257; 257, attribute; 257, 258; 257, 259; 258, identifier:args; 259, identifier:manifest_only; 260, comment; 261, block; 261, 262; 261, 278; 261, 279; 261, 297; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:eups_products; 265, attribute; 265, 266; 265, 277; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:eups; 269, identifier:EupsTag; 270, argument_list; 270, 271; 270, 272; 271, identifier:eups_tag; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:base_url; 274, attribute; 274, 275; 274, 276; 275, identifier:args; 276, identifier:eupstag_base_url; 277, identifier:products; 278, comment; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 284; 281, pattern_list; 281, 282; 281, 283; 282, identifier:products; 283, identifier:err; 284, call; 284, 285; 284, 286; 285, identifier:cross_reference_products; 286, argument_list; 286, 287; 286, 288; 286, 289; 286, 294; 287, identifier:eups_products; 288, identifier:manifest_products; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:ignore_manifest_versions; 291, attribute; 291, 292; 291, 293; 292, identifier:args; 293, identifier:ignore_manifest_versions; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:fail_fast; 296, False; 297, expression_statement; 297, 298; 298, augmented_assignment:+=; 298, 299; 298, 300; 299, identifier:problems; 300, identifier:err; 301, else_clause; 301, 302; 301, 303; 301, 304; 302, comment; 303, comment; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:products; 308, identifier:manifest_products; 309, if_statement; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:args; 312, identifier:limit; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:products; 317, call; 317, 318; 317, 319; 318, identifier:dict; 319, argument_list; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:itertools; 323, identifier:islice; 324, argument_list; 324, 325; 324, 330; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:products; 328, identifier:items; 329, argument_list; 330, attribute; 330, 331; 330, 332; 331, identifier:args; 332, identifier:limit; 333, comment; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 339; 336, pattern_list; 336, 337; 336, 338; 337, identifier:products; 338, identifier:err; 339, call; 339, 340; 339, 341; 340, identifier:get_repo_for_products; 341, argument_list; 341, 342; 341, 345; 341, 348; 341, 353; 341, 358; 341, 363; 342, keyword_argument; 342, 343; 342, 344; 343, identifier:org; 344, identifier:org; 345, keyword_argument; 345, 346; 345, 347; 346, identifier:products; 347, identifier:products; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:allow_teams; 350, attribute; 350, 351; 350, 352; 351, identifier:args; 352, identifier:allow_team; 353, keyword_argument; 353, 354; 353, 355; 354, identifier:ext_teams; 355, attribute; 355, 356; 355, 357; 356, identifier:args; 357, identifier:external_team; 358, keyword_argument; 358, 359; 358, 360; 359, identifier:deny_teams; 360, attribute; 360, 361; 360, 362; 361, identifier:args; 362, identifier:deny_team; 363, keyword_argument; 363, 364; 363, 365; 364, identifier:fail_fast; 365, False; 366, expression_statement; 366, 367; 367, augmented_assignment:+=; 367, 368; 367, 369; 368, identifier:problems; 369, identifier:err; 370, comment; 371, expression_statement; 371, 372; 372, assignment; 372, 373; 372, 376; 373, pattern_list; 373, 374; 373, 375; 374, identifier:products_to_tag; 375, identifier:err; 376, call; 376, 377; 376, 378; 377, identifier:check_product_tags; 378, argument_list; 378, 379; 378, 380; 378, 381; 378, 384; 378, 387; 378, 392; 378, 395; 378, 400; 379, identifier:products; 380, identifier:git_tag; 381, keyword_argument; 381, 382; 381, 383; 382, identifier:tag_message_template; 383, identifier:message_template; 384, keyword_argument; 384, 385; 384, 386; 385, identifier:tagger; 386, identifier:tagger; 387, keyword_argument; 387, 388; 387, 389; 388, identifier:force_tag; 389, attribute; 389, 390; 389, 391; 390, identifier:args; 391, identifier:force_tag; 392, keyword_argument; 392, 393; 392, 394; 393, identifier:fail_fast; 394, False; 395, keyword_argument; 395, 396; 395, 397; 396, identifier:ignore_git_message; 397, attribute; 397, 398; 397, 399; 398, identifier:args; 399, identifier:ignore_git_message; 400, keyword_argument; 400, 401; 400, 402; 401, identifier:ignore_git_tagger; 402, attribute; 402, 403; 402, 404; 403, identifier:args; 404, identifier:ignore_git_tagger; 405, expression_statement; 405, 406; 406, augmented_assignment:+=; 406, 407; 406, 408; 407, identifier:problems; 408, identifier:err; 409, if_statement; 409, 410; 409, 413; 409, 414; 409, 415; 410, attribute; 410, 411; 410, 412; 411, identifier:args; 412, identifier:verify; 413, comment; 414, comment; 415, block; 415, 416; 415, 423; 416, expression_statement; 416, 417; 417, assignment; 417, 418; 417, 419; 418, identifier:err; 419, call; 419, 420; 419, 421; 420, identifier:identify_products_missing_tags; 421, argument_list; 421, 422; 422, identifier:products_to_tag; 423, expression_statement; 423, 424; 424, augmented_assignment:+=; 424, 425; 424, 426; 425, identifier:problems; 426, identifier:err; 427, if_statement; 427, 428; 427, 429; 428, identifier:problems; 429, block; 429, 430; 429, 444; 430, expression_statement; 430, 431; 431, assignment; 431, 432; 431, 433; 432, identifier:msg; 433, call; 433, 434; 433, 437; 434, attribute; 434, 435; 434, 436; 435, string:"{n} pre-flight error(s)"; 436, identifier:format; 437, argument_list; 437, 438; 438, keyword_argument; 438, 439; 438, 440; 439, identifier:n; 440, call; 440, 441; 440, 442; 441, identifier:len; 442, argument_list; 442, 443; 443, identifier:problems; 444, raise_statement; 444, 445; 445, call; 445, 446; 445, 449; 446, attribute; 446, 447; 446, 448; 447, identifier:codetools; 448, identifier:DogpileError; 449, argument_list; 449, 450; 449, 451; 450, identifier:problems; 451, identifier:msg; 452, expression_statement; 452, 453; 453, call; 453, 454; 453, 455; 454, identifier:tag_products; 455, argument_list; 455, 456; 455, 457; 455, 462; 456, identifier:products_to_tag; 457, keyword_argument; 457, 458; 457, 459; 458, identifier:fail_fast; 459, attribute; 459, 460; 459, 461; 460, identifier:args; 461, identifier:fail_fast; 462, keyword_argument; 462, 463; 462, 464; 463, identifier:dry_run; 464, attribute; 464, 465; 464, 466; 465, identifier:args; 466, identifier:dry_run | def run():
"""Create the tag"""
args = parse_args()
codetools.setup_logging(args.debug)
git_tag = args.tag
# if email not specified, try getting it from the gitconfig
git_email = codetools.lookup_email(args)
# ditto for the name of the git user
git_user = codetools.lookup_user(args)
# The default eups tag is derived from the git tag, otherwise specified
# with the --eups-tag option. The reason to currently do this is that for
# weeklies and other internal builds, it's okay to eups publish the weekly
# and git tag post-facto. However for official releases, we don't want to
# publish until the git tag goes down, because we want to eups publish the
# build that has the official versions in the eups ref.
if not args.manifest_only:
eups_tag = args.eups_tag
if not eups_tag:
# generate eups-style version
eups_tag = eups.git_tag2eups_tag(git_tag)
debug("using eups tag: {eups_tag}".format(eups_tag=eups_tag))
# sadly we need to "just" know this
# XXX this can be parsed from the eups tag file post d_2018_05_08
manifest = args.manifest
debug("using manifest: {manifest}".format(manifest=manifest))
if not args.manifest_only:
# release from eups tag
message_template = "Version {{git_tag}}"\
" release from {eups_tag}/{manifest}".format(
eups_tag=eups_tag,
manifest=manifest,
)
else:
# release from manifest only
message_template = "Version {{git_tag}}"\
" release from manifest {manifest}".format(
manifest=manifest,
)
debug("using tag message: {msg}".format(msg=message_template))
tagger = github.InputGitAuthor(
git_user,
git_email,
codetools.current_timestamp(),
)
debug("using taggger: {tagger}".format(tagger=tagger))
global g
g = pygithub.login_github(token_path=args.token_path, token=args.token)
org = g.get_organization(args.org)
info("tagging repos in org: {org}".format(org=org.login))
problems = []
manifest_products = versiondb.Manifest(
manifest,
base_url=args.versiondb_base_url).products
if not args.manifest_only:
# cross-reference eups tag version strings with manifest
eups_products = eups.EupsTag(
eups_tag,
base_url=args.eupstag_base_url).products
# do not fail-fast on non-write operations
products, err = cross_reference_products(
eups_products,
manifest_products,
ignore_manifest_versions=args.ignore_manifest_versions,
fail_fast=False,
)
problems += err
else:
# no eups tag; use manifest products without sanity check against eups
# tag version strings
products = manifest_products
if args.limit:
products = dict(itertools.islice(products.items(), args.limit))
# do not fail-fast on non-write operations
products, err = get_repo_for_products(
org=org,
products=products,
allow_teams=args.allow_team,
ext_teams=args.external_team,
deny_teams=args.deny_team,
fail_fast=False,
)
problems += err
# do not fail-fast on non-write operations
products_to_tag, err = check_product_tags(
products,
git_tag,
tag_message_template=message_template,
tagger=tagger,
force_tag=args.force_tag,
fail_fast=False,
ignore_git_message=args.ignore_git_message,
ignore_git_tagger=args.ignore_git_tagger,
)
problems += err
if args.verify:
# in verify mode, it is an error if there are products that need to be
# tagged.
err = identify_products_missing_tags(products_to_tag)
problems += err
if problems:
msg = "{n} pre-flight error(s)".format(n=len(problems))
raise codetools.DogpileError(problems, msg)
tag_products(
products_to_tag,
fail_fast=args.fail_fast,
dry_run=args.dry_run,
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:filter_seq; 3, parameters; 3, 4; 4, identifier:seq; 5, block; 5, 6; 5, 8; 5, 15; 5, 26; 5, 38; 5, 44; 5, 45; 5, 56; 5, 67; 5, 78; 5, 90; 5, 91; 5, 120; 5, 134; 5, 135; 5, 148; 6, expression_statement; 6, 7; 7, string:'''Examines unreserved sequences to see if they are prone to mutation. This
currently ignores solely-power-of-2 guides with b > 3'''; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:seq; 11, identifier:res; 12, block; 12, 13; 13, return_statement; 13, 14; 14, None; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:n; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:nt; 21, identifier:Factors; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:seq; 25, identifier:factors; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 32; 28, pattern_list; 28, 29; 28, 30; 28, 31; 29, identifier:guide; 30, identifier:s; 31, identifier:t; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:aq; 35, identifier:canonical_form; 36, argument_list; 36, 37; 37, identifier:n; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:seq; 42, identifier:guide; 43, identifier:guide; 44, comment; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:cls; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:aq; 51, identifier:get_class; 52, argument_list; 52, 53; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:guide; 55, identifier:guide; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:num_larges; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:seq; 63, identifier:factors; 64, identifier:count; 65, argument_list; 65, 66; 66, string:'P'; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:upper_bound_tau; 70, binary_operator:-; 70, 71; 70, 74; 71, binary_operator:-; 71, 72; 71, 73; 72, identifier:cls; 73, identifier:num_larges; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, identifier:t; 78, if_statement; 78, 79; 78, 86; 78, 87; 79, boolean_operator:or; 79, 80; 79, 83; 80, comparison_operator:<; 80, 81; 80, 82; 81, identifier:cls; 82, integer:2; 83, comparison_operator:<; 83, 84; 83, 85; 84, identifier:upper_bound_tau; 85, integer:2; 86, comment; 87, block; 87, 88; 88, return_statement; 88, 89; 89, None; 90, comment; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:v; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:nt; 97, identifier:Factors; 98, argument_list; 98, 99; 99, dictionary_comprehension; 99, 100; 99, 103; 99, 112; 100, pair; 100, 101; 100, 102; 101, identifier:p; 102, identifier:a; 103, for_in_clause; 103, 104; 103, 107; 104, pattern_list; 104, 105; 104, 106; 105, identifier:p; 106, identifier:a; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:guide; 110, identifier:items; 111, argument_list; 112, if_clause; 112, 113; 113, boolean_operator:and; 113, 114; 113, 117; 114, comparison_operator:!=; 114, 115; 114, 116; 115, identifier:p; 116, integer:2; 117, comparison_operator:>; 117, 118; 117, 119; 118, identifier:a; 119, integer:0; 120, if_statement; 120, 121; 120, 131; 121, boolean_operator:and; 121, 122; 121, 128; 122, comparison_operator:==; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:int; 125, argument_list; 125, 126; 126, identifier:v; 127, integer:1; 128, comparison_operator:>; 128, 129; 128, 130; 129, identifier:cls; 130, integer:3; 131, block; 131, 132; 132, return_statement; 132, 133; 133, None; 134, comment; 135, if_statement; 135, 136; 135, 145; 136, not_operator; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:aq; 140, identifier:is_driver; 141, argument_list; 141, 142; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:guide; 144, identifier:guide; 145, block; 145, 146; 146, return_statement; 146, 147; 147, None; 148, return_statement; 148, 149; 149, expression_list; 149, 150; 149, 151; 150, identifier:n; 151, identifier:guide | def filter_seq(seq):
'''Examines unreserved sequences to see if they are prone to mutation. This
currently ignores solely-power-of-2 guides with b > 3'''
if seq.res:
return None
n = nt.Factors(seq.factors)
guide, s, t = aq.canonical_form(n)
seq.guide = guide
# The target_tau for the composite is at most the class minus extant prime factor count
cls = aq.get_class(guide=guide)
num_larges = seq.factors.count('P')
upper_bound_tau = cls - num_larges - len(t)
if cls < 2 or upper_bound_tau < 2: # Cheap tests to eliminate almost all sequences
return None
# Next we ignore sequences whose guide is solely a power of 2 greater than 3
v = nt.Factors({p: a for p, a in guide.items() if p != 2 and a > 0})
if int(v) == 1 and cls > 3:
return None
# This condition greatly reduces fdb load, but excludes a lot of sequences
if not aq.is_driver(guide=guide):
return None
return n, guide |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_data; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:filenames; 6, block; 6, 7; 6, 9; 6, 58; 6, 122; 6, 173; 6, 214; 6, 355; 7, expression_statement; 7, 8; 8, comment; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:_parse_table; 11, parameters; 11, 12; 12, identifier:table; 13, block; 13, 14; 13, 26; 13, 49; 14, function_definition; 14, 15; 14, 16; 14, 18; 15, function_name:_parse_line; 16, parameters; 16, 17; 17, identifier:line; 18, block; 18, 19; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:line; 23, identifier:split; 24, argument_list; 24, 25; 25, string:'\t'; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:lines; 29, generator_expression; 29, 30; 29, 34; 29, 41; 30, call; 30, 31; 30, 32; 31, identifier:_parse_line; 32, argument_list; 32, 33; 33, identifier:one; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:one; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:table; 39, identifier:splitlines; 40, argument_list; 41, if_clause; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:re; 45, identifier:match; 46, argument_list; 46, 47; 46, 48; 47, string:r'^\d'; 48, identifier:one; 49, return_statement; 49, 50; 50, generator_expression; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:remove_false; 53, argument_list; 53, 54; 54, identifier:one; 55, for_in_clause; 55, 56; 55, 57; 56, identifier:one; 57, identifier:lines; 58, function_definition; 58, 59; 58, 60; 58, 62; 59, function_name:_parse_decl; 60, parameters; 60, 61; 61, identifier:decl; 62, block; 62, 63; 62, 70; 62, 76; 62, 97; 62, 103; 62, 104; 62, 117; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:index; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, string:'SYSCALL_DEFINE'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:argc; 73, subscript; 73, 74; 73, 75; 74, identifier:decl; 75, identifier:index; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:rest; 79, call; 79, 80; 79, 95; 80, attribute; 80, 81; 80, 94; 81, subscript; 81, 82; 81, 89; 82, subscript; 82, 83; 82, 84; 83, identifier:decl; 84, slice; 84, 85; 84, 88; 85, binary_operator:+; 85, 86; 85, 87; 86, identifier:index; 87, integer:1; 88, colon; 89, slice; 89, 90; 89, 91; 89, 92; 90, integer:1; 91, colon; 92, unary_operator:-; 92, 93; 93, integer:1; 94, identifier:split; 95, argument_list; 95, 96; 96, string:','; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:name; 100, subscript; 100, 101; 100, 102; 101, identifier:rest; 102, integer:0; 103, comment; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:args; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:','; 110, identifier:join; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:rest; 114, slice; 114, 115; 114, 116; 115, integer:1; 116, colon; 117, return_statement; 117, 118; 118, expression_list; 118, 119; 118, 120; 118, 121; 119, identifier:name; 120, identifier:argc; 121, identifier:args; 122, function_definition; 122, 123; 122, 124; 122, 126; 123, function_name:_parse_line; 124, parameters; 124, 125; 125, identifier:line; 126, block; 126, 127; 126, 136; 126, 148; 126, 156; 126, 166; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:index; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:line; 133, identifier:find; 134, argument_list; 134, 135; 135, string:':'; 136, if_statement; 136, 137; 136, 141; 137, comparison_operator:==; 137, 138; 137, 139; 138, identifier:index; 139, unary_operator:-; 139, 140; 140, integer:1; 141, block; 141, 142; 142, raise_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:RuntimeError; 145, argument_list; 145, 146; 145, 147; 146, string:'This is unexpected: %s'; 147, identifier:line; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:filename; 151, subscript; 151, 152; 151, 153; 152, identifier:line; 153, slice; 153, 154; 153, 155; 154, colon; 155, identifier:index; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:decl; 159, subscript; 159, 160; 159, 161; 160, identifier:line; 161, slice; 161, 162; 161, 165; 162, binary_operator:+; 162, 163; 162, 164; 163, identifier:index; 164, integer:1; 165, colon; 166, return_statement; 166, 167; 167, expression_list; 167, 168; 167, 169; 168, identifier:filename; 169, call; 169, 170; 169, 171; 170, identifier:_parse_decl; 171, argument_list; 171, 172; 172, identifier:decl; 173, function_definition; 173, 174; 173, 175; 173, 177; 174, function_name:_split_into_lines; 175, parameters; 175, 176; 176, identifier:grep_output; 177, block; 177, 178; 177, 188; 177, 204; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:lines; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:grep_output; 184, identifier:replace; 185, argument_list; 185, 186; 185, 187; 186, string:'\n\n'; 187, string:'\n'; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:lines; 191, call; 191, 192; 191, 201; 192, attribute; 192, 193; 192, 200; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:lines; 196, identifier:replace; 197, argument_list; 197, 198; 197, 199; 198, string:'\n\t'; 199, string:''; 200, identifier:replace; 201, argument_list; 201, 202; 201, 203; 202, string:'\t'; 203, string:' '; 204, return_statement; 204, 205; 205, call; 205, 206; 205, 213; 206, attribute; 206, 207; 206, 212; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:lines; 210, identifier:strip; 211, argument_list; 212, identifier:splitlines; 213, argument_list; 214, for_statement; 214, 215; 214, 216; 214, 217; 215, identifier:one; 216, identifier:filenames; 217, block; 217, 218; 218, if_statement; 218, 219; 218, 227; 218, 303; 219, call; 219, 220; 219, 225; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:one; 223, identifier:name; 224, identifier:endswith; 225, argument_list; 225, 226; 226, string:'.tbl'; 227, block; 227, 228; 228, for_statement; 228, 229; 228, 230; 228, 238; 229, identifier:item; 230, call; 230, 231; 230, 232; 231, identifier:_parse_table; 232, argument_list; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:one; 236, identifier:read; 237, argument_list; 238, block; 238, 239; 238, 246; 238, 267; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:args; 242, call; 242, 243; 242, 244; 243, identifier:list; 244, argument_list; 244, 245; 245, identifier:item; 246, if_statement; 246, 247; 246, 253; 247, comparison_operator:!=; 247, 248; 247, 252; 248, call; 248, 249; 248, 250; 249, identifier:len; 250, argument_list; 250, 251; 251, identifier:args; 252, integer:5; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, augmented_assignment:+=; 255, 256; 255, 257; 256, identifier:args; 257, binary_operator:*; 257, 258; 257, 260; 258, list:['']; 258, 259; 259, string:''; 260, parenthesized_expression; 260, 261; 261, binary_operator:-; 261, 262; 261, 263; 262, integer:5; 263, call; 263, 264; 263, 265; 264, identifier:len; 265, argument_list; 265, 266; 266, identifier:args; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 274; 269, attribute; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:session; 273, identifier:add; 274, argument_list; 274, 275; 275, call; 275, 276; 275, 277; 276, identifier:Item; 277, argument_list; 277, 278; 277, 283; 277, 288; 277, 293; 277, 298; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:name; 280, subscript; 280, 281; 280, 282; 281, identifier:args; 282, integer:2; 283, keyword_argument; 283, 284; 283, 285; 284, identifier:abi; 285, subscript; 285, 286; 285, 287; 286, identifier:args; 287, integer:1; 288, keyword_argument; 288, 289; 288, 290; 289, identifier:number; 290, subscript; 290, 291; 290, 292; 291, identifier:args; 292, integer:0; 293, keyword_argument; 293, 294; 293, 295; 294, identifier:entry; 295, subscript; 295, 296; 295, 297; 296, identifier:args; 297, integer:3; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:compat; 300, subscript; 300, 301; 300, 302; 301, identifier:args; 302, integer:4; 303, else_clause; 303, 304; 304, block; 304, 305; 305, for_statement; 305, 306; 305, 307; 305, 315; 306, identifier:line; 307, call; 307, 308; 307, 309; 308, identifier:_split_into_lines; 309, argument_list; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:one; 313, identifier:read; 314, argument_list; 315, block; 315, 316; 315, 326; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 321; 318, pattern_list; 318, 319; 318, 320; 319, identifier:filename; 320, identifier:rest; 321, parenthesized_expression; 321, 322; 322, call; 322, 323; 322, 324; 323, identifier:_parse_line; 324, argument_list; 324, 325; 325, identifier:line; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 333; 328, attribute; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:session; 332, identifier:add; 333, argument_list; 333, 334; 334, call; 334, 335; 334, 336; 335, identifier:Decl; 336, argument_list; 336, 337; 336, 342; 336, 345; 336, 350; 337, keyword_argument; 337, 338; 337, 339; 338, identifier:name; 339, subscript; 339, 340; 339, 341; 340, identifier:rest; 341, integer:0; 342, keyword_argument; 342, 343; 342, 344; 343, identifier:filename; 344, identifier:filename; 345, keyword_argument; 345, 346; 345, 347; 346, identifier:argc; 347, subscript; 347, 348; 347, 349; 348, identifier:rest; 349, integer:1; 350, keyword_argument; 350, 351; 350, 352; 351, identifier:args; 352, subscript; 352, 353; 352, 354; 353, identifier:rest; 354, integer:2; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 362; 357, attribute; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:self; 360, identifier:session; 361, identifier:commit; 362, argument_list | def add_data(self, filenames):
"""Add data."""
def _parse_table(table):
def _parse_line(line):
return line.split('\t')
lines = (_parse_line(one) for one in table.splitlines()
if re.match(r'^\d', one))
return (remove_false(one) for one in lines)
def _parse_decl(decl):
index = len('SYSCALL_DEFINE')
argc = decl[index]
rest = decl[index + 1:][1:-1].split(',')
name = rest[0]
# args = [one.strip() for one in rest[1:]]
args = ','.join(rest[1:])
return name, argc, args
def _parse_line(line):
index = line.find(':')
if index == -1:
raise RuntimeError('This is unexpected: %s', line)
filename = line[:index]
decl = line[index + 1:]
return filename, _parse_decl(decl)
def _split_into_lines(grep_output):
lines = grep_output.replace('\n\n', '\n')
lines = lines.replace('\n\t', '').replace('\t', ' ')
return lines.strip().splitlines()
for one in filenames:
if one.name.endswith('.tbl'):
for item in _parse_table(one.read()):
args = list(item)
if len(args) != 5:
args += [''] * (5 - len(args))
self.session.add(
Item(name=args[2], abi=args[1],
number=args[0], entry=args[3],
compat=args[4]))
else:
for line in _split_into_lines(one.read()):
filename, rest = (_parse_line(line))
self.session.add(
Decl(name=rest[0], filename=filename,
argc=rest[1], args=rest[2]))
self.session.commit() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:check_tags; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:repos; 5, identifier:tags; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ignore_existing; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:fail_fast; 11, False; 12, block; 12, 13; 12, 15; 12, 30; 12, 46; 12, 61; 12, 79; 12, 80; 12, 84; 12, 88; 12, 92; 12, 204; 12, 236; 13, expression_statement; 13, 14; 14, comment; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:debug; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, string:"looking for {n} tag(s):"; 22, identifier:format; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:n; 26, call; 26, 27; 26, 28; 27, identifier:len; 28, argument_list; 28, 29; 29, identifier:tags; 30, expression_statement; 30, 31; 31, list_comprehension; 31, 32; 31, 43; 32, call; 32, 33; 32, 34; 33, identifier:debug; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:" {t}"; 38, identifier:format; 39, argument_list; 39, 40; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:t; 42, identifier:t; 43, for_in_clause; 43, 44; 43, 45; 44, identifier:t; 45, identifier:tags; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:debug; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, string:"in {n} repo(s):"; 53, identifier:format; 54, argument_list; 54, 55; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:n; 57, call; 57, 58; 57, 59; 58, identifier:len; 59, argument_list; 59, 60; 60, identifier:repos; 61, expression_statement; 61, 62; 62, list_comprehension; 62, 63; 62, 76; 63, call; 63, 64; 63, 65; 64, identifier:debug; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:" {r}"; 69, identifier:format; 70, argument_list; 70, 71; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:r; 73, attribute; 73, 74; 73, 75; 74, identifier:r; 75, identifier:full_name; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:r; 78, identifier:repos; 79, comment; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:present_tags; 83, dictionary; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:absent_tags; 87, dictionary; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:problems; 91, list:[]; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:r; 94, identifier:repos; 95, block; 95, 96; 95, 104; 95, 175; 95, 187; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:has_tags; 99, call; 99, 100; 99, 101; 100, identifier:find_tags_in_repo; 101, argument_list; 101, 102; 101, 103; 102, identifier:r; 103, identifier:tags; 104, if_statement; 104, 105; 104, 106; 105, identifier:has_tags; 106, block; 106, 107; 106, 154; 107, if_statement; 107, 108; 107, 110; 108, not_operator; 108, 109; 109, identifier:ignore_existing; 110, block; 110, 111; 110, 137; 110, 142; 110, 149; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:yikes; 114, call; 114, 115; 114, 116; 115, identifier:GitTagExistsError; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:"tag(s) {tag} already exists in repos {r}"; 120, identifier:format; 121, argument_list; 121, 122; 121, 132; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:tag; 124, call; 124, 125; 124, 126; 125, identifier:list; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:has_tags; 130, identifier:keys; 131, argument_list; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:r; 134, attribute; 134, 135; 134, 136; 135, identifier:r; 136, identifier:full_name; 137, if_statement; 137, 138; 137, 139; 138, identifier:fail_fast; 139, block; 139, 140; 140, raise_statement; 140, 141; 141, identifier:yikes; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:problems; 146, identifier:append; 147, argument_list; 147, 148; 148, identifier:yikes; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:error; 152, argument_list; 152, 153; 153, identifier:yikes; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 161; 156, subscript; 156, 157; 156, 158; 157, identifier:present_tags; 158, attribute; 158, 159; 158, 160; 159, identifier:r; 160, identifier:full_name; 161, dictionary; 161, 162; 161, 165; 162, pair; 162, 163; 162, 164; 163, string:'repo'; 164, identifier:r; 165, pair; 165, 166; 165, 167; 166, string:'tags'; 167, call; 167, 168; 167, 169; 168, identifier:list; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:has_tags; 173, identifier:values; 174, argument_list; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:missing_tags; 178, list_comprehension; 178, 179; 178, 180; 178, 183; 179, identifier:x; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:x; 182, identifier:tags; 183, if_clause; 183, 184; 184, comparison_operator:not; 184, 185; 184, 186; 185, identifier:x; 186, identifier:has_tags; 187, if_statement; 187, 188; 187, 189; 188, identifier:missing_tags; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 197; 192, subscript; 192, 193; 192, 194; 193, identifier:absent_tags; 194, attribute; 194, 195; 194, 196; 195, identifier:r; 196, identifier:full_name; 197, dictionary; 197, 198; 197, 201; 198, pair; 198, 199; 198, 200; 199, string:'repo'; 200, identifier:r; 201, pair; 201, 202; 201, 203; 202, string:'need_tags'; 203, identifier:missing_tags; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:debug; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 217; 209, attribute; 209, 210; 209, 216; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:textwrap; 213, identifier:dedent; 214, argument_list; 214, 215; 215, comment; 216, identifier:format; 217, argument_list; 217, 218; 217, 224; 217, 230; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:n_with; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, identifier:present_tags; 224, keyword_argument; 224, 225; 224, 226; 225, identifier:n_none; 226, call; 226, 227; 226, 228; 227, identifier:len; 228, argument_list; 228, 229; 229, identifier:absent_tags; 230, keyword_argument; 230, 231; 230, 232; 231, identifier:errors; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, identifier:problems; 236, return_statement; 236, 237; 237, expression_list; 237, 238; 237, 239; 237, 240; 238, identifier:present_tags; 239, identifier:absent_tags; 240, identifier:problems | def check_tags(repos, tags, ignore_existing=False, fail_fast=False):
""" check if tags already exist in repos"""
debug("looking for {n} tag(s):".format(n=len(tags)))
[debug(" {t}".format(t=t)) for t in tags]
debug("in {n} repo(s):".format(n=len(repos)))
[debug(" {r}".format(r=r.full_name)) for r in repos]
# present/missing tags by repo name
present_tags = {}
absent_tags = {}
problems = []
for r in repos:
has_tags = find_tags_in_repo(r, tags)
if has_tags:
if not ignore_existing:
yikes = GitTagExistsError(
"tag(s) {tag} already exists in repos {r}".format(
tag=list(has_tags.keys()),
r=r.full_name
))
if fail_fast:
raise yikes
problems.append(yikes)
error(yikes)
present_tags[r.full_name] = {
'repo': r,
'tags': list(has_tags.values()),
}
missing_tags = [x for x in tags if x not in has_tags]
if missing_tags:
absent_tags[r.full_name] = {
'repo': r,
'need_tags': missing_tags,
}
debug(textwrap.dedent("""\
found:
{n_with:>4} repos with tag(s)
{n_none:>4} repos with no tag(s)
{errors:>4} repos with error(s)\
""").format(
n_with=len(present_tags),
n_none=len(absent_tags),
errors=len(problems),
))
return present_tags, absent_tags, problems |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:getmlsthelper; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:referencefilepath; 5, identifier:start; 6, identifier:organism; 7, identifier:update; 8, block; 8, 9; 8, 11; 8, 17; 8, 18; 8, 24; 8, 25; 8, 34; 8, 35; 8, 60; 8, 61; 8, 83; 9, expression_statement; 9, 10; 10, comment; 11, import_from_statement; 11, 12; 11, 15; 12, dotted_name; 12, 13; 12, 14; 13, identifier:accessoryFunctions; 14, identifier:accessoryFunctions; 15, dotted_name; 15, 16; 16, identifier:GenObject; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:organismset; 21, call; 21, 22; 21, 23; 22, identifier:set; 23, argument_list; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:organism; 28, conditional_expression:if; 28, 29; 28, 30; 28, 33; 29, identifier:organism; 30, comparison_operator:!=; 30, 31; 30, 32; 31, identifier:organism; 32, string:'Shigella'; 33, string:'Escherichia'; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:organismdictionary; 38, dictionary; 38, 39; 38, 42; 38, 45; 38, 48; 38, 51; 38, 54; 38, 57; 39, pair; 39, 40; 39, 41; 40, string:'Escherichia'; 41, string:'Escherichia coli#1'; 42, pair; 42, 43; 42, 44; 43, string:'Shigella'; 44, string:'Escherichia coli#1'; 45, pair; 45, 46; 45, 47; 46, string:'Vibrio'; 47, string:'Vibrio parahaemolyticus'; 48, pair; 48, 49; 48, 50; 49, string:'Campylobacter'; 50, string:'Campylobacter jejuni'; 51, pair; 51, 52; 51, 53; 52, string:'Listeria'; 53, string:'Listeria monocytogenes'; 54, pair; 54, 55; 54, 56; 55, string:'Bacillus'; 56, string:'Bacillus cereus'; 57, pair; 57, 58; 57, 59; 58, string:'Klebsiella'; 59, string:'Klebsiella pneumoniae'; 60, comment; 61, try_statement; 61, 62; 61, 72; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:organismset; 67, identifier:add; 68, argument_list; 68, 69; 69, subscript; 69, 70; 69, 71; 70, identifier:organismdictionary; 71, identifier:organism; 72, except_clause; 72, 73; 72, 74; 72, 75; 73, identifier:KeyError; 74, comment; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:organismset; 80, identifier:add; 81, argument_list; 81, 82; 82, identifier:organism; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:scheme; 85, identifier:organismset; 86, block; 86, 87; 86, 100; 86, 101; 86, 133; 86, 134; 86, 144; 86, 145; 86, 155; 86, 298; 86, 352; 86, 353; 86, 397; 86, 398; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:organismpath; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:os; 94, identifier:path; 95, identifier:join; 96, argument_list; 96, 97; 96, 98; 96, 99; 97, identifier:referencefilepath; 98, string:'MLST'; 99, identifier:organism; 100, comment; 101, try_statement; 101, 102; 101, 126; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:lastfolder; 106, call; 106, 107; 106, 124; 107, attribute; 107, 108; 107, 123; 108, subscript; 108, 109; 108, 121; 109, call; 109, 110; 109, 111; 110, identifier:sorted; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:glob; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:'{}/*/'; 118, identifier:format; 119, argument_list; 119, 120; 120, identifier:organismpath; 121, unary_operator:-; 121, 122; 122, integer:1; 123, identifier:rstrip; 124, argument_list; 124, 125; 125, string:'/'; 126, except_clause; 126, 127; 126, 128; 127, identifier:IndexError; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:lastfolder; 132, list:[]; 133, comment; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 140; 136, pattern_list; 136, 137; 136, 138; 136, 139; 137, identifier:delta; 138, identifier:foldersize; 139, identifier:d1; 140, call; 140, 141; 140, 142; 141, identifier:schemedate; 142, argument_list; 142, 143; 143, identifier:lastfolder; 144, comment; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:newfolder; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, string:'{}/{}'; 151, identifier:format; 152, argument_list; 152, 153; 152, 154; 153, identifier:organismpath; 154, identifier:d1; 155, if_statement; 155, 156; 155, 157; 155, 289; 155, 290; 156, identifier:update; 157, block; 157, 158; 158, if_statement; 158, 159; 158, 168; 158, 282; 158, 283; 159, boolean_operator:or; 159, 160; 159, 165; 160, comparison_operator:>; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:delta; 163, identifier:days; 164, integer:7; 165, comparison_operator:<; 165, 166; 165, 167; 166, identifier:foldersize; 167, integer:100; 168, block; 168, 169; 168, 180; 168, 181; 168, 187; 168, 193; 168, 199; 168, 205; 168, 211; 168, 212; 168, 219; 168, 226; 168, 227; 168, 228; 168, 229; 168, 259; 168, 260; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:printtime; 172, argument_list; 172, 173; 172, 179; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, string:'Downloading {} MLST scheme from pubmlst.org'; 176, identifier:format; 177, argument_list; 177, 178; 178, identifier:organism; 179, identifier:start; 180, comment; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:getmlstargs; 184, call; 184, 185; 184, 186; 185, identifier:GenObject; 186, argument_list; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:getmlstargs; 191, identifier:species; 192, identifier:scheme; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:getmlstargs; 197, identifier:repository_url; 198, string:'http://pubmlst.org/data/dbases.xml'; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:getmlstargs; 203, identifier:force_scheme_name; 204, False; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:getmlstargs; 209, identifier:path; 210, identifier:newfolder; 211, comment; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 215; 214, identifier:make_path; 215, argument_list; 215, 216; 216, attribute; 216, 217; 216, 218; 217, identifier:getmlstargs; 218, identifier:path; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:getmlst; 223, identifier:main; 224, argument_list; 224, 225; 225, identifier:getmlstargs; 226, comment; 227, comment; 228, comment; 229, try_statement; 229, 230; 229, 252; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:profilestart; 234, call; 234, 235; 234, 251; 235, attribute; 235, 236; 235, 250; 236, call; 236, 237; 236, 238; 237, identifier:open; 238, argument_list; 238, 239; 239, subscript; 239, 240; 239, 249; 240, call; 240, 241; 240, 242; 241, identifier:glob; 242, argument_list; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, string:'{}/*.txt'; 246, identifier:format; 247, argument_list; 247, 248; 248, identifier:newfolder; 249, integer:0; 250, identifier:readline; 251, argument_list; 252, except_clause; 252, 253; 252, 254; 253, identifier:IndexError; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:profilestart; 258, list:[]; 259, comment; 260, if_statement; 260, 261; 260, 269; 260, 270; 261, boolean_operator:or; 261, 262; 261, 264; 262, not_operator; 262, 263; 263, identifier:profilestart; 264, comparison_operator:==; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:profilestart; 267, integer:0; 268, string:'<'; 269, comment; 270, block; 270, 271; 270, 278; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:shutil; 275, identifier:rmtree; 276, argument_list; 276, 277; 277, identifier:newfolder; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:newfolder; 281, identifier:lastfolder; 282, comment; 283, else_clause; 283, 284; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:newfolder; 288, identifier:lastfolder; 289, comment; 290, else_clause; 290, 291; 291, block; 291, 292; 291, 296; 291, 297; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:newfolder; 295, identifier:lastfolder; 296, comment; 297, comment; 298, try_statement; 298, 299; 298, 343; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:newfoldersize; 303, call; 303, 304; 303, 305; 304, identifier:sum; 305, generator_expression; 305, 306; 305, 320; 305, 328; 306, call; 306, 307; 306, 312; 307, attribute; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:os; 310, identifier:path; 311, identifier:getsize; 312, argument_list; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, string:'{}/{}'; 316, identifier:format; 317, argument_list; 317, 318; 317, 319; 318, identifier:newfolder; 319, identifier:f; 320, for_in_clause; 320, 321; 320, 322; 321, identifier:f; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:os; 325, identifier:listdir; 326, argument_list; 326, 327; 327, identifier:newfolder; 328, if_clause; 328, 329; 329, call; 329, 330; 329, 335; 330, attribute; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:os; 333, identifier:path; 334, identifier:isfile; 335, argument_list; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, string:'{}/{}'; 339, identifier:format; 340, argument_list; 340, 341; 340, 342; 341, identifier:newfolder; 342, identifier:f; 343, except_clause; 343, 344; 343, 347; 344, tuple; 344, 345; 344, 346; 345, identifier:OSError; 346, identifier:TypeError; 347, block; 347, 348; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 351; 350, identifier:newfoldersize; 351, integer:100; 352, comment; 353, if_statement; 353, 354; 353, 357; 354, comparison_operator:<; 354, 355; 354, 356; 355, identifier:newfoldersize; 356, integer:100; 357, block; 357, 358; 357, 365; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:shutil; 362, identifier:rmtree; 363, argument_list; 363, 364; 364, identifier:newfolder; 365, try_statement; 365, 366; 365, 390; 366, block; 366, 367; 367, expression_statement; 367, 368; 368, assignment; 368, 369; 368, 370; 369, identifier:newfolder; 370, call; 370, 371; 370, 388; 371, attribute; 371, 372; 371, 387; 372, subscript; 372, 373; 372, 385; 373, call; 373, 374; 373, 375; 374, identifier:sorted; 375, argument_list; 375, 376; 376, call; 376, 377; 376, 378; 377, identifier:glob; 378, argument_list; 378, 379; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, string:'{}/*/'; 382, identifier:format; 383, argument_list; 383, 384; 384, identifier:organismpath; 385, unary_operator:-; 385, 386; 386, integer:1; 387, identifier:rstrip; 388, argument_list; 388, 389; 389, string:'/'; 390, except_clause; 390, 391; 390, 392; 391, identifier:IndexError; 392, block; 392, 393; 393, expression_statement; 393, 394; 394, assignment; 394, 395; 394, 396; 395, identifier:newfolder; 396, identifier:organismpath; 397, comment; 398, return_statement; 398, 399; 399, identifier:newfolder | def getmlsthelper(referencefilepath, start, organism, update):
"""Prepares to run the getmlst.py script provided in SRST2"""
from accessoryFunctions.accessoryFunctions import GenObject
# Initialise a set to for the organism(s) for which new alleles and profiles are desired
organismset = set()
# Allow for Shigella to use the Escherichia MLST profile/alleles
organism = organism if organism != 'Shigella' else 'Escherichia'
# As there are multiple profiles for certain organisms, this dictionary has the schemes I use as values
organismdictionary = {'Escherichia': 'Escherichia coli#1',
'Shigella': 'Escherichia coli#1',
'Vibrio': 'Vibrio parahaemolyticus',
'Campylobacter': 'Campylobacter jejuni',
'Listeria': 'Listeria monocytogenes',
'Bacillus': 'Bacillus cereus',
'Klebsiella': 'Klebsiella pneumoniae'}
# Allow for a genus not in the dictionary being specified
try:
organismset.add(organismdictionary[organism])
except KeyError:
# Add the organism to the set
organismset.add(organism)
for scheme in organismset:
organismpath = os.path.join(referencefilepath, 'MLST', organism)
# Find all folders (with the trailing / in the glob search) and remove the trailing /
try:
lastfolder = sorted(glob('{}/*/'.format(organismpath)))[-1].rstrip('/')
except IndexError:
lastfolder = []
# Run the method to determine the most recent folder, and how recently it was updated
delta, foldersize, d1 = schemedate(lastfolder)
# Set the path/name of the folder to contain the new alleles and profile
newfolder = '{}/{}'.format(organismpath, d1)
if update:
if delta.days > 7 or foldersize < 100:
printtime('Downloading {} MLST scheme from pubmlst.org'.format(organism), start)
# Create the object to store the argument attributes to feed to getmlst
getmlstargs = GenObject()
getmlstargs.species = scheme
getmlstargs.repository_url = 'http://pubmlst.org/data/dbases.xml'
getmlstargs.force_scheme_name = False
getmlstargs.path = newfolder
# Create the path to store the downloaded
make_path(getmlstargs.path)
getmlst.main(getmlstargs)
# Even if there is an issue contacting the database, files are created, however, they are populated
# with XML strings indicating that the download failed
# Read the first character in the file
try:
profilestart = open(glob('{}/*.txt'.format(newfolder))[0]).readline()
except IndexError:
profilestart = []
# If it is a <, then the download failed
if not profilestart or profilestart[0] == '<':
# Delete the folder, and use the previous definitions instead
shutil.rmtree(newfolder)
newfolder = lastfolder
# If the profile and alleles are up-to-date, set :newfolder to :lastfolder
else:
newfolder = lastfolder
# If update isn't specified, don't update
else:
newfolder = lastfolder
# Ensure that the profile/alleles updated successfully
# Calculate the size of the folder by adding the sizes of all the files within the folder together
try:
newfoldersize = sum(os.path.getsize('{}/{}'.format(newfolder, f)) for f in os.listdir(newfolder)
if os.path.isfile('{}/{}'.format(newfolder, f)))
except (OSError, TypeError):
newfoldersize = 100
# If the profile/allele failed, remove the folder, and use the most recent update
if newfoldersize < 100:
shutil.rmtree(newfolder)
try:
newfolder = sorted(glob('{}/*/'.format(organismpath)))[-1].rstrip('/')
except IndexError:
newfolder = organismpath
# Return the name/path of the allele-containing folder
return newfolder |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:set; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 18; 7, 34; 7, 58; 7, 117; 7, 133; 7, 141; 7, 154; 7, 167; 7, 180; 7, 193; 7, 206; 7, 219; 7, 232; 7, 247; 7, 260; 7, 273; 7, 286; 7, 299; 7, 312; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:player_lock; 16, identifier:acquire; 17, argument_list; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:in; 19, 20; 19, 21; 20, string:'acqtime'; 21, identifier:kwargs; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:player; 29, identifier:set_aidur; 30, argument_list; 30, 31; 31, subscript; 31, 32; 31, 33; 32, identifier:kwargs; 33, string:'acqtime'; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:in; 35, 36; 35, 37; 36, string:'aifs'; 37, identifier:kwargs; 38, block; 38, 39; 38, 50; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:player; 45, identifier:set_aifs; 46, argument_list; 46, 47; 47, subscript; 47, 48; 47, 49; 48, identifier:kwargs; 49, string:'aifs'; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:aifs; 55, subscript; 55, 56; 55, 57; 56, identifier:kwargs; 57, string:'aifs'; 58, if_statement; 58, 59; 58, 66; 59, boolean_operator:or; 59, 60; 59, 63; 60, comparison_operator:in; 60, 61; 60, 62; 61, string:'aifs'; 62, identifier:kwargs; 63, comparison_operator:in; 63, 64; 63, 65; 64, string:'acqtime'; 65, identifier:kwargs; 66, block; 66, 67; 66, 83; 66, 104; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:t; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:kwargs; 73, identifier:get; 74, argument_list; 74, 75; 74, 76; 75, string:'acqtime'; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:player; 81, identifier:get_aidur; 82, argument_list; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:npoints; 86, binary_operator:*; 86, 87; 86, 88; 87, identifier:t; 88, call; 88, 89; 88, 90; 89, identifier:float; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:kwargs; 94, identifier:get; 95, argument_list; 95, 96; 95, 97; 96, string:'aifs'; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:player; 102, identifier:get_aifs; 103, argument_list; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:aitimes; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:np; 112, identifier:linspace; 113, argument_list; 113, 114; 113, 115; 113, 116; 114, integer:0; 115, identifier:t; 116, identifier:npoints; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:in; 118, 119; 118, 120; 119, string:'trigger'; 120, identifier:kwargs; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:player; 128, identifier:set_trigger; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 132; 131, identifier:kwargs; 132, string:'trigger'; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:player_lock; 139, identifier:release; 140, argument_list; 141, if_statement; 141, 142; 141, 145; 142, comparison_operator:in; 142, 143; 142, 144; 143, string:'aochan'; 144, identifier:kwargs; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:aochan; 151, subscript; 151, 152; 151, 153; 152, identifier:kwargs; 153, string:'aochan'; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:in; 155, 156; 155, 157; 156, string:'aichan'; 157, identifier:kwargs; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:aichan; 164, subscript; 164, 165; 164, 166; 165, identifier:kwargs; 166, string:'aichan'; 167, if_statement; 167, 168; 167, 171; 168, comparison_operator:in; 168, 169; 168, 170; 169, string:'binsz'; 170, identifier:kwargs; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:binsz; 177, subscript; 177, 178; 177, 179; 178, identifier:kwargs; 179, string:'binsz'; 180, if_statement; 180, 181; 180, 184; 181, comparison_operator:in; 181, 182; 181, 183; 182, string:'save'; 183, identifier:kwargs; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:save_data; 190, subscript; 190, 191; 190, 192; 191, identifier:kwargs; 192, string:'save'; 193, if_statement; 193, 194; 193, 197; 194, comparison_operator:in; 194, 195; 194, 196; 195, string:'caldb'; 196, identifier:kwargs; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:caldb; 203, subscript; 203, 204; 203, 205; 204, identifier:kwargs; 205, string:'caldb'; 206, if_statement; 206, 207; 206, 210; 207, comparison_operator:in; 207, 208; 207, 209; 208, string:'calv'; 209, identifier:kwargs; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:calv; 216, subscript; 216, 217; 216, 218; 217, identifier:kwargs; 218, string:'calv'; 219, if_statement; 219, 220; 219, 223; 220, comparison_operator:in; 220, 221; 220, 222; 221, string:'calf'; 222, identifier:kwargs; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:calf; 229, subscript; 229, 230; 229, 231; 230, identifier:kwargs; 231, string:'calf'; 232, if_statement; 232, 233; 232, 240; 233, boolean_operator:or; 233, 234; 233, 237; 234, comparison_operator:in; 234, 235; 234, 236; 235, string:'caldb'; 236, identifier:kwargs; 237, comparison_operator:in; 237, 238; 237, 239; 238, string:'calv'; 239, identifier:kwargs; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:update_reference_voltage; 246, argument_list; 247, if_statement; 247, 248; 247, 251; 248, comparison_operator:in; 248, 249; 248, 250; 249, string:'datafile'; 250, identifier:kwargs; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:datafile; 257, subscript; 257, 258; 257, 259; 258, identifier:kwargs; 259, string:'datafile'; 260, if_statement; 260, 261; 260, 264; 261, comparison_operator:in; 261, 262; 261, 263; 262, string:'reprate'; 263, identifier:kwargs; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:reprate; 270, subscript; 270, 271; 270, 272; 271, identifier:kwargs; 272, string:'reprate'; 273, if_statement; 273, 274; 273, 277; 274, comparison_operator:in; 274, 275; 274, 276; 275, string:'save'; 276, identifier:kwargs; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:self; 282, identifier:save_data; 283, subscript; 283, 284; 283, 285; 284, identifier:kwargs; 285, string:'save'; 286, if_statement; 286, 287; 286, 290; 287, comparison_operator:in; 287, 288; 287, 289; 288, string:'average'; 289, identifier:kwargs; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:average; 296, subscript; 296, 297; 296, 298; 297, identifier:kwargs; 298, string:'average'; 299, if_statement; 299, 300; 299, 303; 300, comparison_operator:in; 300, 301; 300, 302; 301, string:'reject'; 302, identifier:kwargs; 303, block; 303, 304; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:reject; 309, subscript; 309, 310; 309, 311; 310, identifier:kwargs; 311, string:'reject'; 312, if_statement; 312, 313; 312, 316; 313, comparison_operator:in; 313, 314; 313, 315; 314, string:'rejectrate'; 315, identifier:kwargs; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:self; 321, identifier:rejectrate; 322, subscript; 322, 323; 322, 324; 323, identifier:kwargs; 324, string:'rejectrate' | def set(self, **kwargs):
"""Sets an internal setting for acquistion, using keywords.
Available parameters to set:
:param acqtime: duration of recording (input) window (seconds)
:type acqtime: float
:param aifs: sample rate of the recording (input) operation (Hz)
:type aifs: int
:param aochan: AO (generation) channel name
:type aochan: str
:param aichan: AI (recording) channel name
:type aichan: str
:param nreps: number of repetitions for each unique stimulus
:type nreps: int
:param binsz: time bin duration for spike sorting (seconds)
:type binsz: float
:param caldb: See :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setReferenceVoltage>`
:type caldb: float
:param calv: See :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setReferenceVoltage>`
:type calv: float
:param datafile: a reference to an open file to save data to
:type datafile: :class:`AcquisitionData<sparkle.data.dataobjects.AcquisitionData>`
:param average: whether to average repetitions of a trace, saving only the averaged signal
:type average: bool
:param reject: whether to reject values higher than a defined threshold. Only used while average is true
:type reject: bool
:param rejectrate: the value to base artifact rejection on
:type rejectrate: float
"""
self.player_lock.acquire()
if 'acqtime' in kwargs:
self.player.set_aidur(kwargs['acqtime'])
if 'aifs' in kwargs:
self.player.set_aifs(kwargs['aifs'])
self.aifs = kwargs['aifs']
if 'aifs' in kwargs or 'acqtime' in kwargs:
t = kwargs.get('acqtime', self.player.get_aidur())
npoints = t*float(kwargs.get('aifs', self.player.get_aifs()))
self.aitimes = np.linspace(0, t, npoints)
if 'trigger' in kwargs:
self.player.set_trigger(kwargs['trigger'])
self.player_lock.release()
if 'aochan' in kwargs:
self.aochan = kwargs['aochan']
if 'aichan' in kwargs:
self.aichan = kwargs['aichan']
if 'binsz' in kwargs:
self.binsz = kwargs['binsz']
if 'save' in kwargs:
self.save_data = kwargs['save']
if 'caldb' in kwargs:
self.caldb = kwargs['caldb']
if 'calv' in kwargs:
self.calv = kwargs['calv']
if 'calf' in kwargs:
self.calf = kwargs['calf']
if 'caldb' in kwargs or 'calv' in kwargs:
self.update_reference_voltage()
if 'datafile' in kwargs:
self.datafile = kwargs['datafile']
if 'reprate' in kwargs:
self.reprate = kwargs['reprate']
if 'save' in kwargs:
self.save_data = kwargs['save']
if 'average' in kwargs:
self.average = kwargs['average']
if 'reject' in kwargs:
self.reject = kwargs['reject']
if 'rejectrate' in kwargs:
self.rejectrate = kwargs['rejectrate'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:readlist; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 17; 5, 56; 5, 73; 5, 81; 5, 82; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:printtime; 11, argument_list; 11, 12; 11, 13; 12, string:'Sorting reads'; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:start; 16, comment; 17, for_statement; 17, 18; 17, 19; 17, 25; 17, 26; 18, identifier:i; 19, call; 19, 20; 19, 21; 20, identifier:range; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:cpus; 25, comment; 26, block; 26, 27; 26, 41; 26, 42; 26, 49; 26, 50; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:threads; 30, call; 30, 31; 30, 32; 31, identifier:Thread; 32, argument_list; 32, 33; 32, 38; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:target; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:listread; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:args; 40, tuple; 41, comment; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:threads; 46, identifier:setDaemon; 47, argument_list; 47, 48; 48, True; 49, comment; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:threads; 54, identifier:start; 55, argument_list; 56, for_statement; 56, 57; 56, 58; 56, 63; 57, identifier:sample; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:runmetadata; 62, identifier:samples; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:listqueue; 70, identifier:put; 71, argument_list; 71, 72; 72, identifier:sample; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:listqueue; 79, identifier:join; 80, argument_list; 81, comment; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:fastqfilter; 87, argument_list | def readlist(self):
"""Sort the reads, and create lists to be used in creating sorted .fastq files"""
printtime('Sorting reads', self.start)
# Create and start threads
for i in range(self.cpus):
# Send the threads to the appropriate destination function
threads = Thread(target=self.listread, args=())
# Set the daemon to true - something to do with thread management
threads.setDaemon(True)
# Start the threading
threads.start()
for sample in self.runmetadata.samples:
self.listqueue.put(sample)
self.listqueue.join()
# Create
self.fastqfilter() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:has_change_permission; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:page; 6, identifier:lang; 7, default_parameter; 7, 8; 7, 9; 8, identifier:method; 9, None; 10, block; 10, 11; 10, 13; 10, 14; 10, 15; 10, 22; 10, 23; 10, 32; 10, 79; 10, 80; 10, 88; 10, 114; 10, 115; 11, expression_statement; 11, 12; 12, comment; 13, comment; 14, comment; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:!=; 16, 17; 16, 18; 17, identifier:method; 18, string:'POST'; 19, block; 19, 20; 20, return_statement; 20, 21; 21, True; 22, comment; 23, if_statement; 23, 24; 23, 29; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:change_page; 28, argument_list; 29, block; 29, 30; 30, return_statement; 30, 31; 31, True; 32, if_statement; 32, 33; 32, 34; 32, 35; 33, identifier:lang; 34, comment; 35, block; 35, 36; 35, 55; 35, 60; 35, 61; 35, 71; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:perm; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:user; 44, identifier:has_perm; 45, argument_list; 45, 46; 46, binary_operator:%; 46, 47; 46, 48; 47, string:'pages.can_manage_%s'; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:lang; 51, identifier:replace; 52, argument_list; 52, 53; 52, 54; 53, string:'-'; 54, string:'_'; 55, if_statement; 55, 56; 55, 57; 56, identifier:perm; 57, block; 57, 58; 58, return_statement; 58, 59; 59, True; 60, comment; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:perm_func; 64, call; 64, 65; 64, 66; 65, identifier:getattr; 66, argument_list; 66, 67; 66, 68; 67, identifier:self; 68, binary_operator:%; 68, 69; 68, 70; 69, string:'manage (%s)_page'; 70, identifier:lang; 71, if_statement; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:perm_func; 74, argument_list; 74, 75; 75, identifier:page; 76, block; 76, 77; 77, return_statement; 77, 78; 78, True; 79, comment; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:perm_func; 83, call; 83, 84; 83, 85; 84, identifier:getattr; 85, argument_list; 85, 86; 85, 87; 86, identifier:self; 87, string:'manage hierarchy_page'; 88, if_statement; 88, 89; 88, 93; 88, 96; 89, call; 89, 90; 89, 91; 90, identifier:perm_func; 91, argument_list; 91, 92; 92, identifier:page; 93, block; 93, 94; 94, return_statement; 94, 95; 95, True; 96, else_clause; 96, 97; 97, block; 97, 98; 98, for_statement; 98, 99; 98, 100; 98, 105; 99, identifier:ancestor; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:page; 103, identifier:get_ancestors; 104, argument_list; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 111; 107, call; 107, 108; 107, 109; 108, identifier:perm_func; 109, argument_list; 109, 110; 110, identifier:ancestor; 111, block; 111, 112; 112, return_statement; 112, 113; 113, True; 114, comment; 115, return_statement; 115, 116; 116, False | def has_change_permission(self, page, lang, method=None):
"""Return ``True`` if the current user has permission to
change the page."""
# the user has always the right to look at a page content
# if he doesn't try to modify it.
if method != 'POST':
return True
# right to change all the pages
if self.change_page():
return True
if lang:
# try the global language permission first
perm = self.user.has_perm(
'pages.can_manage_%s' % lang.replace('-', '_')
)
if perm:
return True
# then per object permission
perm_func = getattr(self, 'manage (%s)_page' % lang)
if perm_func(page):
return True
# last hierarchic permissions because it's more expensive
perm_func = getattr(self, 'manage hierarchy_page')
if perm_func(page):
return True
else:
for ancestor in page.get_ancestors():
if perm_func(ancestor):
return True
# everything else failed, no permissions
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:args; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 20; 5, 21; 5, 22; 5, 33; 5, 39; 5, 45; 5, 51; 5, 57; 5, 63; 5, 74; 5, 80; 5, 111; 5, 331; 5, 337; 5, 368; 5, 423; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:params; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:parameters; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:args; 17, call; 17, 18; 17, 19; 18, identifier:OrderedDict; 19, argument_list; 20, comment; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, subscript; 24, 25; 24, 26; 25, identifier:args; 26, string:'help'; 27, call; 27, 28; 27, 29; 28, identifier:HelpArg; 29, argument_list; 29, 30; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:command; 32, identifier:self; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:normalize_name; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:normalize_name; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:get_arg_config; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:get_arg_config; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:get_short_option; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:get_short_option_for_arg; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:get_long_option; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:get_long_option_for_arg; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:get_inverse_option; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:get_inverse_option_for_arg; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:names; 66, set_comprehension; 66, 67; 66, 71; 67, call; 67, 68; 67, 69; 68, identifier:normalize_name; 69, argument_list; 69, 70; 70, identifier:name; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:name; 73, identifier:params; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:used_short_options; 77, call; 77, 78; 77, 79; 78, identifier:set; 79, argument_list; 80, for_statement; 80, 81; 80, 82; 80, 87; 81, identifier:param; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:params; 85, identifier:values; 86, argument_list; 87, block; 87, 88; 87, 95; 87, 101; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:annotation; 91, call; 91, 92; 91, 93; 92, identifier:get_arg_config; 93, argument_list; 93, 94; 94, identifier:param; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:short_option; 98, attribute; 98, 99; 98, 100; 99, identifier:annotation; 100, identifier:short_option; 101, if_statement; 101, 102; 101, 103; 102, identifier:short_option; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:used_short_options; 108, identifier:add; 109, argument_list; 109, 110; 110, identifier:short_option; 111, for_statement; 111, 112; 111, 115; 111, 120; 112, pattern_list; 112, 113; 112, 114; 113, identifier:name; 114, identifier:param; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:params; 118, identifier:items; 119, argument_list; 120, block; 120, 121; 120, 128; 120, 154; 120, 158; 120, 165; 120, 171; 120, 177; 120, 183; 120, 189; 120, 195; 120, 201; 120, 207; 120, 213; 120, 219; 120, 225; 120, 231; 120, 281; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:name; 124, call; 124, 125; 124, 126; 125, identifier:normalize_name; 126, argument_list; 126, 127; 127, identifier:name; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:skip; 131, parenthesized_expression; 131, 132; 132, boolean_operator:or; 132, 133; 132, 147; 133, boolean_operator:or; 133, 134; 133, 140; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:name; 137, identifier:startswith; 138, argument_list; 138, 139; 139, string:'_'; 140, comparison_operator:is; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:param; 143, identifier:kind; 144, attribute; 144, 145; 144, 146; 145, identifier:param; 146, identifier:VAR_KEYWORD; 147, comparison_operator:is; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:param; 150, identifier:kind; 151, attribute; 151, 152; 151, 153; 152, identifier:param; 153, identifier:KEYWORD_ONLY; 154, if_statement; 154, 155; 154, 156; 155, identifier:skip; 156, block; 156, 157; 157, continue_statement; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:annotation; 161, call; 161, 162; 161, 163; 162, identifier:get_arg_config; 163, argument_list; 163, 164; 164, identifier:param; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:container; 168, attribute; 168, 169; 168, 170; 169, identifier:annotation; 170, identifier:container; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:type; 174, attribute; 174, 175; 174, 176; 175, identifier:annotation; 176, identifier:type; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:choices; 180, attribute; 180, 181; 180, 182; 181, identifier:annotation; 182, identifier:choices; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:help; 186, attribute; 186, 187; 186, 188; 187, identifier:annotation; 188, identifier:help; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:inverse_help; 192, attribute; 192, 193; 192, 194; 193, identifier:annotation; 194, identifier:inverse_help; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:short_option; 198, attribute; 198, 199; 198, 200; 199, identifier:annotation; 200, identifier:short_option; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:long_option; 204, attribute; 204, 205; 204, 206; 205, identifier:annotation; 206, identifier:long_option; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:inverse_option; 210, attribute; 210, 211; 210, 212; 211, identifier:annotation; 212, identifier:inverse_option; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:action; 216, attribute; 216, 217; 216, 218; 217, identifier:annotation; 218, identifier:action; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:nargs; 222, attribute; 222, 223; 222, 224; 223, identifier:annotation; 224, identifier:nargs; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:default; 228, attribute; 228, 229; 228, 230; 229, identifier:param; 230, identifier:default; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:is; 232, 233; 232, 234; 233, identifier:default; 234, attribute; 234, 235; 234, 236; 235, identifier:param; 236, identifier:empty; 237, block; 237, 238; 237, 258; 237, 269; 238, if_statement; 238, 239; 238, 241; 239, not_operator; 239, 240; 240, identifier:short_option; 241, block; 241, 242; 241, 251; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:short_option; 245, call; 245, 246; 245, 247; 246, identifier:get_short_option; 247, argument_list; 247, 248; 247, 249; 247, 250; 248, identifier:name; 249, identifier:names; 250, identifier:used_short_options; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:used_short_options; 255, identifier:add; 256, argument_list; 256, 257; 257, identifier:short_option; 258, if_statement; 258, 259; 258, 261; 259, not_operator; 259, 260; 260, identifier:long_option; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:long_option; 265, call; 265, 266; 265, 267; 266, identifier:get_long_option; 267, argument_list; 267, 268; 268, identifier:name; 269, if_statement; 269, 270; 269, 272; 269, 273; 270, not_operator; 270, 271; 271, identifier:inverse_option; 272, comment; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:inverse_option; 277, call; 277, 278; 277, 279; 278, identifier:get_inverse_option; 279, argument_list; 279, 280; 280, identifier:long_option; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 286; 283, subscript; 283, 284; 283, 285; 284, identifier:args; 285, identifier:name; 286, call; 286, 287; 286, 288; 287, identifier:Arg; 288, argument_list; 288, 289; 288, 292; 288, 295; 288, 298; 288, 301; 288, 304; 288, 307; 288, 310; 288, 313; 288, 316; 288, 319; 288, 322; 288, 325; 288, 328; 289, keyword_argument; 289, 290; 289, 291; 290, identifier:command; 291, identifier:self; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:parameter; 294, identifier:param; 295, keyword_argument; 295, 296; 295, 297; 296, identifier:name; 297, identifier:name; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:container; 300, identifier:container; 301, keyword_argument; 301, 302; 301, 303; 302, identifier:type; 303, identifier:type; 304, keyword_argument; 304, 305; 304, 306; 305, identifier:default; 306, identifier:default; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:choices; 309, identifier:choices; 310, keyword_argument; 310, 311; 310, 312; 311, identifier:help; 312, identifier:help; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:inverse_help; 315, identifier:inverse_help; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:short_option; 318, identifier:short_option; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:long_option; 321, identifier:long_option; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:inverse_option; 324, identifier:inverse_option; 325, keyword_argument; 325, 326; 325, 327; 326, identifier:action; 327, identifier:action; 328, keyword_argument; 328, 329; 328, 330; 329, identifier:nargs; 330, identifier:nargs; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:option_map; 334, call; 334, 335; 334, 336; 335, identifier:OrderedDict; 336, argument_list; 337, for_statement; 337, 338; 337, 339; 337, 344; 338, identifier:arg; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:args; 342, identifier:values; 343, argument_list; 344, block; 344, 345; 345, for_statement; 345, 346; 345, 347; 345, 350; 346, identifier:option; 347, attribute; 347, 348; 347, 349; 348, identifier:arg; 349, identifier:options; 350, block; 350, 351; 350, 359; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:option_map; 355, identifier:setdefault; 356, argument_list; 356, 357; 356, 358; 357, identifier:option; 358, list:[]; 359, expression_statement; 359, 360; 360, call; 360, 361; 360, 366; 361, attribute; 361, 362; 361, 365; 362, subscript; 362, 363; 362, 364; 363, identifier:option_map; 364, identifier:option; 365, identifier:append; 366, argument_list; 366, 367; 367, identifier:arg; 368, for_statement; 368, 369; 368, 372; 368, 377; 369, pattern_list; 369, 370; 369, 371; 370, identifier:option; 371, identifier:option_args; 372, call; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:option_map; 375, identifier:items; 376, argument_list; 377, block; 377, 378; 378, if_statement; 378, 379; 378, 385; 379, comparison_operator:>; 379, 380; 379, 384; 380, call; 380, 381; 380, 382; 381, identifier:len; 382, argument_list; 382, 383; 383, identifier:option_args; 384, integer:1; 385, block; 385, 386; 385, 402; 385, 407; 385, 418; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 389; 388, identifier:names; 389, call; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, string:', '; 392, identifier:join; 393, generator_expression; 393, 394; 393, 399; 394, attribute; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:a; 397, identifier:parameter; 398, identifier:name; 399, for_in_clause; 399, 400; 399, 401; 400, identifier:a; 401, identifier:option_args; 402, expression_statement; 402, 403; 403, assignment; 403, 404; 403, 405; 404, identifier:message; 405, parenthesized_expression; 405, 406; 406, string:'Option {option} of command {self.name} maps to multiple parameters: {names}'; 407, expression_statement; 407, 408; 408, assignment; 408, 409; 408, 410; 409, identifier:message; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:message; 413, identifier:format_map; 414, argument_list; 414, 415; 415, call; 415, 416; 415, 417; 416, identifier:locals; 417, argument_list; 418, raise_statement; 418, 419; 419, call; 419, 420; 419, 421; 420, identifier:CommandError; 421, argument_list; 421, 422; 422, identifier:message; 423, return_statement; 423, 424; 424, identifier:args | def args(self):
"""Create args from function parameters."""
params = self.parameters
args = OrderedDict()
# This will be overridden if the command explicitly defines an
# arg named help.
args['help'] = HelpArg(command=self)
normalize_name = self.normalize_name
get_arg_config = self.get_arg_config
get_short_option = self.get_short_option_for_arg
get_long_option = self.get_long_option_for_arg
get_inverse_option = self.get_inverse_option_for_arg
names = {normalize_name(name) for name in params}
used_short_options = set()
for param in params.values():
annotation = get_arg_config(param)
short_option = annotation.short_option
if short_option:
used_short_options.add(short_option)
for name, param in params.items():
name = normalize_name(name)
skip = (
name.startswith('_') or
param.kind is param.VAR_KEYWORD or
param.kind is param.KEYWORD_ONLY)
if skip:
continue
annotation = get_arg_config(param)
container = annotation.container
type = annotation.type
choices = annotation.choices
help = annotation.help
inverse_help = annotation.inverse_help
short_option = annotation.short_option
long_option = annotation.long_option
inverse_option = annotation.inverse_option
action = annotation.action
nargs = annotation.nargs
default = param.default
if default is not param.empty:
if not short_option:
short_option = get_short_option(name, names, used_short_options)
used_short_options.add(short_option)
if not long_option:
long_option = get_long_option(name)
if not inverse_option:
# NOTE: The DISABLE marker evaluates as True
inverse_option = get_inverse_option(long_option)
args[name] = Arg(
command=self,
parameter=param,
name=name,
container=container,
type=type,
default=default,
choices=choices,
help=help,
inverse_help=inverse_help,
short_option=short_option,
long_option=long_option,
inverse_option=inverse_option,
action=action,
nargs=nargs,
)
option_map = OrderedDict()
for arg in args.values():
for option in arg.options:
option_map.setdefault(option, [])
option_map[option].append(arg)
for option, option_args in option_map.items():
if len(option_args) > 1:
names = ', '.join(a.parameter.name for a in option_args)
message = (
'Option {option} of command {self.name} maps to multiple parameters: {names}')
message = message.format_map(locals())
raise CommandError(message)
return args |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:epcr_threads; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:formattedprimers; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ampliconsize; 8, integer:10000; 9, block; 9, 10; 9, 12; 9, 13; 9, 55; 9, 62; 9, 309; 9, 310; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, for_statement; 13, 14; 13, 15; 13, 18; 14, identifier:sample; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:metadata; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 27; 20, comparison_operator:!=; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:sample; 24, identifier:general; 25, identifier:bestassemblyfile; 26, string:'NA'; 27, block; 27, 28; 27, 42; 27, 49; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:threads; 31, call; 31, 32; 31, 33; 32, identifier:Thread; 33, argument_list; 33, 34; 33, 39; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:target; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:epcr; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:args; 41, tuple; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:threads; 46, identifier:setDaemon; 47, argument_list; 47, 48; 48, True; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:threads; 53, identifier:start; 54, argument_list; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logging; 59, identifier:info; 60, argument_list; 60, 61; 61, string:'Running ePCR analyses'; 62, for_statement; 62, 63; 62, 64; 62, 67; 63, identifier:sample; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:metadata; 67, block; 67, 68; 68, if_statement; 68, 69; 68, 76; 69, comparison_operator:!=; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:sample; 73, identifier:general; 74, identifier:bestassemblyfile; 75, string:'NA'; 76, block; 76, 77; 76, 88; 76, 89; 76, 99; 76, 100; 76, 124; 76, 135; 76, 155; 76, 156; 76, 193; 76, 223; 76, 224; 76, 225; 76, 226; 76, 227; 76, 228; 76, 229; 76, 230; 76, 231; 76, 280; 76, 297; 76, 298; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:setattr; 80, argument_list; 80, 81; 80, 82; 80, 85; 81, identifier:sample; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:analysistype; 85, call; 85, 86; 85, 87; 86, identifier:GenObject; 87, argument_list; 88, comment; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 98; 91, attribute; 91, 92; 91, 97; 92, subscript; 92, 93; 92, 94; 93, identifier:sample; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:analysistype; 97, identifier:primers; 98, identifier:formattedprimers; 99, comment; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 109; 102, attribute; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 105; 104, identifier:sample; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:analysistype; 108, identifier:reportdir; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:os; 113, identifier:path; 114, identifier:join; 115, argument_list; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:sample; 119, identifier:general; 120, identifier:outputdirectory; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:analysistype; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:make_path; 127, argument_list; 127, 128; 128, attribute; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 131; 130, identifier:sample; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:analysistype; 134, identifier:reportdir; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:outfile; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:path; 143, identifier:join; 144, argument_list; 144, 145; 144, 152; 145, attribute; 145, 146; 145, 151; 146, subscript; 146, 147; 146, 148; 147, identifier:sample; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:analysistype; 151, identifier:reportdir; 152, attribute; 152, 153; 152, 154; 153, identifier:sample; 154, identifier:name; 155, comment; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:sample; 161, identifier:commands; 162, identifier:famap; 163, call; 163, 164; 163, 168; 164, attribute; 164, 165; 164, 166; 164, 167; 165, string:'{famap} -b {outfile}.famap {fasta}'; 166, line_continuation:\; 167, identifier:format; 168, argument_list; 168, 169; 168, 183; 168, 186; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:famap; 171, call; 171, 172; 171, 177; 172, attribute; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:os; 175, identifier:path; 176, identifier:join; 177, argument_list; 177, 178; 177, 181; 177, 182; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:homepath; 181, string:'ePCR'; 182, string:'famap'; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:outfile; 185, identifier:outfile; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:fasta; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:sample; 191, identifier:general; 192, identifier:bestassemblyfile; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:sample; 198, identifier:commands; 199, identifier:fahash; 200, call; 200, 201; 200, 205; 201, attribute; 201, 202; 201, 203; 201, 204; 202, string:'{fahash} -b {outfile}.hash {outfile}.famap'; 203, line_continuation:\; 204, identifier:format; 205, argument_list; 205, 206; 205, 220; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:fahash; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:os; 212, identifier:path; 213, identifier:join; 214, argument_list; 214, 215; 214, 218; 214, 219; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:homepath; 218, string:'ePCR'; 219, string:'fahash'; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:outfile; 222, identifier:outfile; 223, comment; 224, comment; 225, comment; 226, comment; 227, comment; 228, comment; 229, comment; 230, comment; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 238; 233, attribute; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:sample; 236, identifier:commands; 237, identifier:epcr; 238, call; 238, 239; 238, 245; 239, attribute; 239, 240; 239, 243; 239, 244; 240, concatenated_string; 240, 241; 240, 242; 241, string:'{rePCR} -S {outfile}.hash -r + -d 1-{ampsize} -n {mismatches} -g 0 -G -q '; 242, string:'-o {outfile}.txt {primers}'; 243, line_continuation:\; 244, identifier:format; 245, argument_list; 245, 246; 245, 260; 245, 263; 245, 266; 245, 271; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:rePCR; 248, call; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:os; 252, identifier:path; 253, identifier:join; 254, argument_list; 254, 255; 254, 258; 254, 259; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:homepath; 258, string:'ePCR'; 259, string:'re-PCR'; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:outfile; 262, identifier:outfile; 263, keyword_argument; 263, 264; 263, 265; 264, identifier:ampsize; 265, identifier:ampliconsize; 266, keyword_argument; 266, 267; 266, 268; 267, identifier:mismatches; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:mismatches; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:primers; 273, attribute; 273, 274; 273, 279; 274, subscript; 274, 275; 274, 276; 275, identifier:sample; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:analysistype; 279, identifier:primers; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 289; 282, attribute; 282, 283; 282, 288; 283, subscript; 283, 284; 283, 285; 284, identifier:sample; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:analysistype; 288, identifier:resultsfile; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, string:'{of}.txt'; 292, identifier:format; 293, argument_list; 293, 294; 294, keyword_argument; 294, 295; 294, 296; 295, identifier:of; 296, identifier:outfile; 297, comment; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 305; 300, attribute; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:epcrqueue; 304, identifier:put; 305, argument_list; 305, 306; 306, tuple; 306, 307; 306, 308; 307, identifier:sample; 308, identifier:outfile; 309, comment; 310, expression_statement; 310, 311; 311, call; 311, 312; 311, 317; 312, attribute; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:self; 315, identifier:epcrqueue; 316, identifier:join; 317, argument_list | def epcr_threads(self, formattedprimers, ampliconsize=10000):
"""
Run ePCR in a multi-threaded fashion
"""
# Create the threads for the ePCR analysis
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
threads = Thread(target=self.epcr, args=())
threads.setDaemon(True)
threads.start()
logging.info('Running ePCR analyses')
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
setattr(sample, self.analysistype, GenObject())
# Get the primers ready
sample[self.analysistype].primers = formattedprimers
# Make the output path
sample[self.analysistype].reportdir = os.path.join(sample.general.outputdirectory,
self.analysistype)
make_path(sample[self.analysistype].reportdir)
outfile = os.path.join(sample[self.analysistype].reportdir, sample.name)
# Set the hashing and mapping commands
sample.commands.famap = '{famap} -b {outfile}.famap {fasta}'\
.format(famap=os.path.join(self.homepath, 'ePCR', 'famap'),
outfile=outfile,
fasta=sample.general.bestassemblyfile)
sample.commands.fahash = '{fahash} -b {outfile}.hash {outfile}.famap'\
.format(fahash=os.path.join(self.homepath, 'ePCR', 'fahash'),
outfile=outfile)
# re-PCR uses the subtyping primers list to search the contigs file using the following parameters
# -S {hash file} (Perform STS lookup using hash-file), -r + (Enable/disable reverse STS lookup)
# -m 10000 (Set variability for STS size for lookup), this very large, as I don't necessarily know
# the size of the amplicon
# -n 1 (Set max allowed mismatches per primer pair for lookup)
# -g 0 (Set max allowed indels per primer pair for lookup),
# -G (Print alignments in comments)
# -o {output file}
sample.commands.epcr = \
'{rePCR} -S {outfile}.hash -r + -d 1-{ampsize} -n {mismatches} -g 0 -G -q ' \
'-o {outfile}.txt {primers}'\
.format(rePCR=os.path.join(self.homepath, 'ePCR', 're-PCR'),
outfile=outfile,
ampsize=ampliconsize,
mismatches=self.mismatches,
primers=sample[self.analysistype].primers)
sample[self.analysistype].resultsfile = '{of}.txt'.format(of=outfile)
# Add the sample object and the output file to the queue
self.epcrqueue.put((sample, outfile))
# Join the threads
self.epcrqueue.join() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:aggregate; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, for_statement; 8, 9; 8, 10; 8, 13; 9, identifier:report; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:reportset; 13, block; 13, 14; 13, 34; 13, 35; 13, 36; 13, 45; 13, 46; 13, 50; 13, 51; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:printtime; 17, argument_list; 17, 18; 17, 31; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, string:'Processing {}'; 21, identifier:format; 22, argument_list; 22, 23; 23, subscript; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:report; 27, identifier:split; 28, argument_list; 28, 29; 29, string:'.'; 30, integer:0; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:start; 34, comment; 35, comment; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:header; 39, conditional_expression:if; 39, 40; 39, 41; 39, 44; 40, string:''; 41, comparison_operator:!=; 41, 42; 41, 43; 42, identifier:report; 43, string:'mlst.csv'; 44, string:'Strain,Genus,SequenceType,Matches,1,2,3,4,5,6,7\n'; 45, comment; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:data; 49, string:''; 50, comment; 51, with_statement; 51, 52; 51, 72; 52, with_clause; 52, 53; 53, with_item; 53, 54; 54, as_pattern; 54, 55; 54, 70; 55, call; 55, 56; 55, 57; 56, identifier:open; 57, argument_list; 57, 58; 57, 69; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:path; 63, identifier:join; 64, argument_list; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:reportpath; 68, identifier:report; 69, string:'w'; 70, as_pattern_target; 70, 71; 71, identifier:aggregate; 72, block; 72, 73; 72, 172; 72, 173; 72, 180; 73, for_statement; 73, 74; 73, 75; 73, 80; 73, 81; 74, identifier:sample; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:runmetadata; 79, identifier:samples; 80, comment; 81, block; 81, 82; 82, try_statement; 82, 83; 82, 84; 82, 168; 83, comment; 84, block; 84, 85; 85, with_statement; 85, 86; 85, 108; 85, 109; 86, with_clause; 86, 87; 87, with_item; 87, 88; 88, as_pattern; 88, 89; 88, 106; 89, call; 89, 90; 89, 91; 90, identifier:open; 91, argument_list; 91, 92; 91, 105; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:os; 96, identifier:path; 97, identifier:join; 98, argument_list; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:sample; 102, identifier:general; 103, identifier:reportpath; 104, identifier:report; 105, string:'r'; 106, as_pattern_target; 106, 107; 107, identifier:runreport; 108, comment; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 113; 110, 122; 111, not_operator; 111, 112; 112, identifier:header; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:header; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:runreport; 120, identifier:readline; 121, argument_list; 122, else_clause; 122, 123; 123, block; 123, 124; 124, for_statement; 124, 125; 124, 126; 124, 127; 124, 128; 125, identifier:row; 126, identifier:runreport; 127, comment; 128, block; 128, 129; 128, 142; 128, 143; 128, 144; 129, if_statement; 129, 130; 129, 137; 130, not_operator; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:row; 134, identifier:endswith; 135, argument_list; 135, 136; 136, string:'\n'; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:row; 141, string:'\n'; 142, comment; 143, comment; 144, if_statement; 144, 145; 144, 162; 144, 163; 145, comparison_operator:!=; 145, 146; 145, 154; 146, subscript; 146, 147; 146, 153; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:row; 150, identifier:split; 151, argument_list; 151, 152; 152, string:','; 153, integer:0; 154, subscript; 154, 155; 154, 161; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:header; 158, identifier:split; 159, argument_list; 159, 160; 160, string:','; 161, integer:0; 162, comment; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, augmented_assignment:+=; 165, 166; 165, 167; 166, identifier:data; 167, identifier:row; 168, except_clause; 168, 169; 168, 170; 169, identifier:IOError; 170, block; 170, 171; 171, pass_statement; 172, comment; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:aggregate; 177, identifier:write; 178, argument_list; 178, 179; 179, identifier:header; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:aggregate; 184, identifier:write; 185, argument_list; 185, 186; 186, identifier:data | def aggregate(self):
"""
Aggregate all reports of the same type into a master report
"""
for report in self.reportset:
printtime('Processing {}'.format(report.split('.')[0]), self.start)
# Initialise the header for each report - MLST is different, as the header is different for each
# MLST scheme. This provides a generic header instead
header = '' if report != 'mlst.csv' else 'Strain,Genus,SequenceType,Matches,1,2,3,4,5,6,7\n'
# Initialise a string to hold the data for each report
data = ''
# Open the aggregated report
with open(os.path.join(self.reportpath, report), 'w') as aggregate:
for sample in self.runmetadata.samples:
# Try to open the report for this run
try:
#
with open(os.path.join(sample.general.reportpath, report), 'r') as runreport:
# Only get the header from the first file
if not header:
header = runreport.readline()
else:
for row in runreport:
# The final entry in a report does not have a newline character. Add \n as required
if not row.endswith('\n'):
row += '\n'
# For certain reports, the header row is printed above each strain - ignore multiple
# instances of the header
if row.split(',')[0] != header.split(',')[0]:
# Add the row to the string of data
data += row
except IOError:
pass
# Write the strings to the aggregate report file
aggregate.write(header)
aggregate.write(data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_parse_sequences; 3, parameters; 3, 4; 3, 5; 4, identifier:ilines; 5, identifier:expect_qlen; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, while_statement; 9, 10; 9, 11; 10, True; 11, block; 11, 12; 11, 19; 11, 36; 11, 37; 11, 61; 11, 78; 11, 105; 11, 106; 11, 121; 11, 132; 11, 143; 11, 179; 11, 215; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:first; 15, call; 15, 16; 15, 17; 16, identifier:next; 17, argument_list; 17, 18; 18, identifier:ilines; 19, if_statement; 19, 20; 19, 33; 19, 34; 20, boolean_operator:and; 20, 21; 20, 27; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:first; 24, identifier:startswith; 25, argument_list; 25, 26; 26, string:'_'; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:first; 30, identifier:endswith; 31, argument_list; 31, 32; 32, string:'].'; 33, comment; 34, block; 34, 35; 35, break_statement; 36, comment; 37, try_statement; 37, 38; 37, 49; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 45; 41, pattern_list; 41, 42; 41, 43; 41, 44; 42, identifier:index; 43, identifier:this_len; 44, identifier:query_len; 45, call; 45, 46; 45, 47; 46, identifier:_parse_seq_preheader; 47, argument_list; 47, 48; 48, identifier:first; 49, except_clause; 49, 50; 49, 51; 50, identifier:ValueError; 51, block; 51, 52; 51, 60; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:logging; 56, identifier:warn; 57, argument_list; 57, 58; 57, 59; 58, string:'Unparseable line (SKIPPING):\n%s'; 59, identifier:first; 60, continue_statement; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 71; 63, tuple_pattern; 63, 64; 63, 65; 63, 66; 63, 67; 63, 68; 63, 69; 63, 70; 64, identifier:rec_id; 65, identifier:dbxrefs; 66, identifier:headlen; 67, identifier:taillen; 68, identifier:phylum; 69, identifier:taxchar; 70, identifier:description; 71, call; 71, 72; 71, 73; 72, identifier:_parse_seq_header; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:next; 76, argument_list; 76, 77; 77, identifier:ilines; 78, try_statement; 78, 79; 78, 93; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 86; 82, pattern_list; 82, 83; 82, 84; 82, 85; 83, identifier:headseq; 84, identifier:molseq; 85, identifier:tailseq; 86, call; 86, 87; 86, 88; 87, identifier:_parse_seq_body; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:next; 91, argument_list; 91, 92; 92, identifier:ilines; 93, except_clause; 93, 94; 93, 95; 94, identifier:ValueError; 95, block; 95, 96; 95, 104; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:logging; 100, identifier:warn; 101, argument_list; 101, 102; 101, 103; 102, string:'Unparseable sequence: %s -- SKIPPING'; 103, identifier:rec_id; 104, continue_statement; 105, comment; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:!=; 107, 108; 107, 109; 108, identifier:expect_qlen; 109, identifier:query_len; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:logging; 115, identifier:warn; 116, argument_list; 116, 117; 116, 118; 116, 119; 116, 120; 117, string:"Query length in %s given as %d; expected %d"; 118, identifier:rec_id; 119, identifier:query_len; 120, identifier:expect_qlen; 121, if_statement; 121, 122; 121, 127; 122, boolean_operator:and; 122, 123; 122, 125; 123, not_operator; 123, 124; 124, identifier:headseq; 125, not_operator; 125, 126; 126, identifier:headlen; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:headlen; 131, integer:0; 132, if_statement; 132, 133; 132, 138; 133, boolean_operator:and; 133, 134; 133, 136; 134, not_operator; 134, 135; 135, identifier:tailseq; 136, not_operator; 136, 137; 137, identifier:taillen; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:taillen; 142, integer:0; 143, if_statement; 143, 144; 143, 145; 144, identifier:headseq; 145, block; 145, 146; 146, if_statement; 146, 147; 146, 150; 146, 158; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:headlen; 149, None; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:headlen; 154, call; 154, 155; 154, 156; 155, identifier:len; 156, argument_list; 156, 157; 157, identifier:headseq; 158, elif_clause; 158, 159; 158, 165; 159, comparison_operator:!=; 159, 160; 159, 161; 160, identifier:headlen; 161, call; 161, 162; 161, 163; 162, identifier:len; 163, argument_list; 163, 164; 164, identifier:headseq; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:logging; 170, identifier:warn; 171, argument_list; 171, 172; 171, 173; 171, 174; 171, 175; 172, string:"Conflicting head flank lengths in %s: %d, %d"; 173, identifier:rec_id; 174, identifier:headlen; 175, call; 175, 176; 175, 177; 176, identifier:len; 177, argument_list; 177, 178; 178, identifier:headseq; 179, if_statement; 179, 180; 179, 181; 180, identifier:tailseq; 181, block; 181, 182; 182, if_statement; 182, 183; 182, 186; 182, 194; 183, comparison_operator:is; 183, 184; 183, 185; 184, identifier:taillen; 185, None; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:taillen; 190, call; 190, 191; 190, 192; 191, identifier:len; 192, argument_list; 192, 193; 193, identifier:tailseq; 194, elif_clause; 194, 195; 194, 201; 195, comparison_operator:!=; 195, 196; 195, 197; 196, identifier:taillen; 197, call; 197, 198; 197, 199; 198, identifier:len; 199, argument_list; 199, 200; 200, identifier:tailseq; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:logging; 206, identifier:warn; 207, argument_list; 207, 208; 207, 209; 207, 210; 207, 211; 208, string:"Conflicting tail flank lengths in %s: %d, %d"; 209, identifier:rec_id; 210, identifier:taillen; 211, call; 211, 212; 211, 213; 212, identifier:len; 213, argument_list; 213, 214; 214, identifier:tailseq; 215, expression_statement; 215, 216; 216, yield; 216, 217; 217, dictionary; 217, 218; 217, 221; 217, 224; 217, 227; 217, 230; 217, 233; 217, 236; 217, 239; 217, 242; 217, 245; 217, 248; 217, 251; 218, pair; 218, 219; 218, 220; 219, string:'index'; 220, identifier:index; 221, pair; 221, 222; 221, 223; 222, string:'id'; 223, identifier:rec_id; 224, pair; 224, 225; 224, 226; 225, string:'description'; 226, identifier:description; 227, pair; 227, 228; 227, 229; 228, string:'dbxrefs'; 229, identifier:dbxrefs; 230, pair; 230, 231; 230, 232; 231, string:'phylum'; 232, identifier:phylum; 233, pair; 233, 234; 233, 235; 234, string:'taxchar'; 235, identifier:taxchar; 236, pair; 236, 237; 236, 238; 237, string:'head_len'; 238, identifier:headlen; 239, pair; 239, 240; 239, 241; 240, string:'tail_len'; 241, identifier:taillen; 242, pair; 242, 243; 242, 244; 243, string:'head_seq'; 244, identifier:headseq; 245, pair; 245, 246; 245, 247; 246, string:'tail_seq'; 247, identifier:tailseq; 248, pair; 248, 249; 248, 250; 249, string:'length'; 250, identifier:this_len; 251, pair; 251, 252; 251, 253; 252, string:'seq'; 253, identifier:molseq | def _parse_sequences(ilines, expect_qlen):
"""Parse the sequences in the current block.
Sequence looks like:
$3=227(209):
>gi|15606894|ref|NP_214275.1| {|2(244)|<Aquificae(B)>}DNA polymerase III gamma subunit [Aquifex aeolicus VF5] >gi|2984127|gb|AAC07663.1| DNA polymerase III gamma subunit [Aquifex aeolicus VF5] >gi|75
{()YVPFARKYRPKFFREVIGQEAPVRILKNAIKNDRVAHaYLFAGPRGVGKTTIARILAKALNcknpskgepcgecencreiDRGVFPDLIEMDAASNRGIDDVRA-LKEAVNYKPIKG-KYKVYIIDEAHMLTKEAFNALLKTLEEPPPRTVFVLCTTEYDKILPTILSRCQRIIFSKVRKEKVIEYLKKICEKEGIECEEGALEVLAHASEGCMRDAASLLDQASVYGE()}*
"""
while True:
first = next(ilines)
if first.startswith('_') and first.endswith('].'):
# End of sequences & end of block
break
# ENH: handle wrapped lines?
try:
index, this_len, query_len = _parse_seq_preheader(first)
except ValueError:
logging.warn('Unparseable line (SKIPPING):\n%s', first)
continue
(rec_id, dbxrefs, headlen, taillen, phylum, taxchar, description
) = _parse_seq_header(next(ilines))
try:
headseq, molseq, tailseq = _parse_seq_body(next(ilines))
except ValueError:
logging.warn('Unparseable sequence: %s -- SKIPPING', rec_id)
continue
# Validation
if expect_qlen != query_len:
logging.warn("Query length in %s given as %d; expected %d",
rec_id, query_len, expect_qlen)
if not headseq and not headlen:
headlen = 0
if not tailseq and not taillen:
taillen = 0
if headseq:
if headlen is None:
headlen = len(headseq)
elif headlen != len(headseq):
logging.warn("Conflicting head flank lengths in %s: %d, %d",
rec_id, headlen, len(headseq))
if tailseq:
if taillen is None:
taillen = len(tailseq)
elif taillen != len(tailseq):
logging.warn("Conflicting tail flank lengths in %s: %d, %d",
rec_id, taillen, len(tailseq))
yield {'index': index,
'id': rec_id,
'description': description,
'dbxrefs': dbxrefs,
'phylum': phylum,
'taxchar': taxchar,
'head_len': headlen,
'tail_len': taillen,
'head_seq': headseq,
'tail_seq': tailseq,
'length': this_len,
'seq': molseq,
} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:realign_seqs; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:block; 5, default_parameter; 5, 6; 5, 7; 6, identifier:gap_char; 7, string:'.'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:align_indels; 10, False; 11, block; 11, 12; 11, 14; 11, 15; 11, 30; 11, 31; 11, 32; 11, 39; 11, 43; 11, 94; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:all_chars; 18, list_comprehension; 18, 19; 18, 25; 19, call; 19, 20; 19, 21; 20, identifier:list; 21, argument_list; 21, 22; 22, subscript; 22, 23; 22, 24; 23, identifier:sq; 24, string:'seq'; 25, for_in_clause; 25, 26; 25, 27; 26, identifier:sq; 27, subscript; 27, 28; 27, 29; 28, identifier:block; 29, string:'sequences'; 30, comment; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:nrows; 35, call; 35, 36; 35, 37; 36, identifier:len; 37, argument_list; 37, 38; 38, identifier:all_chars; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:i; 42, integer:0; 43, while_statement; 43, 44; 43, 52; 44, comparison_operator:<; 44, 45; 44, 46; 45, identifier:i; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:all_chars; 51, integer:0; 52, block; 52, 53; 52, 70; 52, 90; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:rows_need_gaps; 56, list_comprehension; 56, 57; 56, 58; 56, 61; 57, identifier:r; 58, for_in_clause; 58, 59; 58, 60; 59, identifier:r; 60, identifier:all_chars; 61, if_clause; 61, 62; 62, not_operator; 62, 63; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:r; 67, identifier:i; 68, identifier:islower; 69, argument_list; 70, if_statement; 70, 71; 70, 77; 71, comparison_operator:!=; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:rows_need_gaps; 76, identifier:nrows; 77, block; 77, 78; 78, for_statement; 78, 79; 78, 80; 78, 81; 79, identifier:row; 80, identifier:rows_need_gaps; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:row; 86, identifier:insert; 87, argument_list; 87, 88; 87, 89; 88, identifier:i; 89, identifier:gap_char; 90, expression_statement; 90, 91; 91, augmented_assignment:+=; 91, 92; 91, 93; 92, identifier:i; 93, integer:1; 94, return_statement; 94, 95; 95, list_comprehension; 95, 96; 95, 102; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:''; 99, identifier:join; 100, argument_list; 100, 101; 101, identifier:row; 102, for_in_clause; 102, 103; 102, 104; 103, identifier:row; 104, identifier:all_chars | def realign_seqs(block, gap_char='.', align_indels=False):
"""Add gaps to a block so all residues in a column are equivalent.
Given a block, containing a list of "sequences" (dicts) each containing a
"seq" (actual string sequence, where upper=match, lower=insert, dash=gap),
insert gaps (- or .) into the sequences s.t.
1. columns line up properly, and
2. all resulting sequences have the same length
The reason this needs to be done is that the query/consensus sequence is not
assigned gaps to account for inserts in the other sequences. We need to add
the gaps back to obtain a normal alignment.
`return`: a list of realigned sequence strings.
"""
# ENH: align inserts using an external tool (if align_indels)
all_chars = [list(sq['seq']) for sq in block['sequences']]
# NB: If speed is an issue here, consider Numpy or Cython
# main problem: list.insert is O(n) -- would OrderedDict help?
nrows = len(all_chars)
i = 0
while i < len(all_chars[0]):
rows_need_gaps = [r for r in all_chars if not r[i].islower()]
if len(rows_need_gaps) != nrows:
for row in rows_need_gaps:
row.insert(i, gap_char)
i += 1
return [''.join(row) for row in all_chars] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:collapse_to_consensus; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:seqrecords; 5, default_parameter; 5, 6; 5, 7; 6, identifier:strict; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:do_iron; 10, True; 11, block; 11, 12; 11, 14; 11, 18; 11, 26; 11, 27; 11, 66; 11, 75; 11, 82; 11, 114; 11, 203; 11, 215; 11, 216; 11, 229; 11, 235; 11, 236; 11, 376; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:level; 17, integer:0; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:name; 21, attribute; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:seqrecords; 24, integer:0; 25, identifier:id; 26, comment; 27, if_statement; 27, 28; 27, 33; 28, call; 28, 29; 28, 30; 29, identifier:hasattr; 30, argument_list; 30, 31; 30, 32; 31, identifier:seqrecords; 32, string:'_records'; 33, block; 33, 34; 33, 47; 33, 60; 34, if_statement; 34, 35; 34, 40; 35, call; 35, 36; 35, 37; 36, identifier:hasattr; 37, argument_list; 37, 38; 37, 39; 38, identifier:seqrecords; 39, string:'level'; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:level; 44, attribute; 44, 45; 44, 46; 45, identifier:seqrecords; 46, identifier:level; 47, if_statement; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:hasattr; 50, argument_list; 50, 51; 50, 52; 51, identifier:seqrecords; 52, string:'name'; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:name; 57, attribute; 57, 58; 57, 59; 58, identifier:seqrecords; 59, identifier:name; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:seqrecords; 63, attribute; 63, 64; 63, 65; 64, identifier:seqrecords; 65, identifier:_records; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:consensus; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:seqrecords; 72, identifier:pop; 73, argument_list; 73, 74; 74, integer:0; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:cons_length; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, identifier:consensus; 82, for_statement; 82, 83; 82, 86; 82, 90; 83, pattern_list; 83, 84; 83, 85; 84, identifier:i; 85, identifier:s; 86, call; 86, 87; 86, 88; 87, identifier:enumerate; 88, argument_list; 88, 89; 89, identifier:seqrecords; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 98; 92, comparison_operator:!=; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:len; 95, argument_list; 95, 96; 96, identifier:s; 97, identifier:cons_length; 98, block; 98, 99; 99, raise_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:ValueError; 102, argument_list; 102, 103; 103, binary_operator:%; 103, 104; 103, 105; 104, string:"Sequence #%d has length %d, consensus is %d"; 105, tuple; 105, 106; 105, 109; 105, 113; 106, binary_operator:+; 106, 107; 106, 108; 107, identifier:i; 108, integer:2; 109, call; 109, 110; 109, 111; 110, identifier:len; 111, argument_list; 111, 112; 112, identifier:s; 113, identifier:cons_length; 114, if_statement; 114, 115; 114, 123; 114, 124; 114, 185; 115, comparison_operator:in; 115, 116; 115, 117; 116, string:'.'; 117, call; 117, 118; 117, 119; 118, identifier:str; 119, argument_list; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:consensus; 122, identifier:seq; 123, comment; 124, block; 124, 125; 125, if_statement; 125, 126; 125, 134; 125, 168; 126, comparison_operator:in; 126, 127; 126, 128; 127, string:'-'; 128, call; 128, 129; 128, 130; 129, identifier:str; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:consensus; 133, identifier:seq; 134, block; 134, 135; 134, 143; 134, 152; 135, if_statement; 135, 136; 135, 137; 136, identifier:strict; 137, block; 137, 138; 138, raise_statement; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:ValueError; 141, argument_list; 141, 142; 142, string:"Consensus contains '-' gap characters"; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:logging; 147, identifier:warn; 148, argument_list; 148, 149; 149, concatenated_string; 149, 150; 149, 151; 150, string:"Consensus sequence contains both '.' and '-' gap "; 151, string:"characters -- is it really the consensus?"; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:aligned_cols; 155, list_comprehension; 155, 156; 155, 160; 156, parenthesized_expression; 156, 157; 157, comparison_operator:not; 157, 158; 157, 159; 158, identifier:c; 159, string:'.-'; 160, for_in_clause; 160, 161; 160, 162; 161, identifier:c; 162, call; 162, 163; 162, 164; 163, identifier:str; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:consensus; 167, identifier:seq; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:aligned_cols; 173, list_comprehension; 173, 174; 173, 177; 174, comparison_operator:!=; 174, 175; 174, 176; 175, identifier:c; 176, string:'.'; 177, for_in_clause; 177, 178; 177, 179; 178, identifier:c; 179, call; 179, 180; 179, 181; 180, identifier:str; 181, argument_list; 181, 182; 182, attribute; 182, 183; 182, 184; 183, identifier:consensus; 184, identifier:seq; 185, else_clause; 185, 186; 185, 187; 186, comment; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:aligned_cols; 191, list_comprehension; 191, 192; 191, 195; 192, comparison_operator:!=; 192, 193; 192, 194; 193, identifier:c; 194, string:'-'; 195, for_in_clause; 195, 196; 195, 197; 196, identifier:c; 197, call; 197, 198; 197, 199; 198, identifier:str; 199, argument_list; 199, 200; 200, attribute; 200, 201; 200, 202; 201, identifier:consensus; 202, identifier:seq; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:consensus; 207, identifier:seq; 208, call; 208, 209; 208, 210; 209, identifier:replace_asterisks; 210, argument_list; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:consensus; 213, identifier:seq; 214, string:'consensus'; 215, comment; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:block; 219, call; 219, 220; 219, 221; 220, identifier:consensus2block; 221, argument_list; 221, 222; 221, 223; 221, 226; 222, identifier:consensus; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:level; 225, identifier:level; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:name; 228, identifier:name; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:qlen; 232, subscript; 232, 233; 232, 234; 233, identifier:block; 234, string:'query_length'; 235, comment; 236, for_statement; 236, 237; 236, 240; 236, 254; 236, 255; 237, pattern_list; 237, 238; 237, 239; 238, identifier:index; 239, identifier:rec; 240, call; 240, 241; 240, 242; 241, identifier:zip; 242, argument_list; 242, 243; 242, 253; 243, call; 243, 244; 243, 245; 244, identifier:xrange; 245, argument_list; 245, 246; 245, 247; 246, integer:2; 247, binary_operator:+; 247, 248; 247, 252; 248, call; 248, 249; 248, 250; 249, identifier:len; 250, argument_list; 250, 251; 251, identifier:seqrecords; 252, integer:2; 253, identifier:seqrecords; 254, comment; 255, block; 255, 256; 255, 260; 255, 264; 255, 337; 255, 348; 255, 362; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:new_mol_seq; 259, list:[]; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:is_beginning; 263, True; 264, for_statement; 264, 265; 264, 268; 264, 279; 265, pattern_list; 265, 266; 265, 267; 266, identifier:aligned_col; 267, identifier:char; 268, call; 268, 269; 268, 270; 269, identifier:zip; 270, argument_list; 270, 271; 270, 272; 271, identifier:aligned_cols; 272, call; 272, 273; 272, 274; 273, identifier:replace_asterisks; 274, argument_list; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:rec; 277, identifier:seq; 278, identifier:index; 279, block; 279, 280; 280, if_statement; 280, 281; 280, 282; 280, 314; 281, identifier:aligned_col; 282, block; 282, 283; 282, 287; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:is_beginning; 286, False; 287, if_statement; 287, 288; 287, 291; 287, 292; 287, 300; 288, comparison_operator:in; 288, 289; 288, 290; 289, identifier:char; 290, string:'-.'; 291, comment; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:new_mol_seq; 297, identifier:append; 298, argument_list; 298, 299; 299, string:'-'; 300, else_clause; 300, 301; 300, 302; 301, comment; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:new_mol_seq; 307, identifier:append; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:char; 312, identifier:upper; 313, argument_list; 314, else_clause; 314, 315; 314, 316; 314, 317; 315, comment; 316, comment; 317, block; 317, 318; 318, if_statement; 318, 319; 318, 325; 319, boolean_operator:and; 319, 320; 319, 323; 320, comparison_operator:not; 320, 321; 320, 322; 321, identifier:char; 322, string:'-.'; 323, not_operator; 323, 324; 324, identifier:is_beginning; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:new_mol_seq; 330, identifier:append; 331, argument_list; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:char; 335, identifier:lower; 336, argument_list; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:rec; 341, identifier:seq; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, string:''; 345, identifier:join; 346, argument_list; 346, 347; 347, identifier:new_mol_seq; 348, if_statement; 348, 349; 348, 350; 349, identifier:do_iron; 350, block; 350, 351; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:rec; 355, identifier:seq; 356, call; 356, 357; 356, 358; 357, identifier:iron; 358, argument_list; 358, 359; 359, attribute; 359, 360; 359, 361; 360, identifier:rec; 361, identifier:seq; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 369; 364, attribute; 364, 365; 364, 368; 365, subscript; 365, 366; 365, 367; 366, identifier:block; 367, string:'sequences'; 368, identifier:append; 369, argument_list; 369, 370; 370, call; 370, 371; 370, 372; 371, identifier:seqrecord2sequence; 372, argument_list; 372, 373; 372, 374; 372, 375; 373, identifier:rec; 374, identifier:qlen; 375, identifier:index; 376, return_statement; 376, 377; 377, identifier:block | def collapse_to_consensus(seqrecords, strict=False, do_iron=True):
"""Opposite of realign_seqs.
Input sequences should all be the same length.
The first record must be the consensus.
"""
level = 0
name = seqrecords[0].id
# If this is a CMA alignment, extract additional info:
if hasattr(seqrecords, '_records'):
if hasattr(seqrecords, 'level'):
level = seqrecords.level
if hasattr(seqrecords, 'name'):
name = seqrecords.name
seqrecords = seqrecords._records
consensus = seqrecords.pop(0)
cons_length = len(consensus)
for i, s in enumerate(seqrecords):
if len(s) != cons_length:
raise ValueError(
"Sequence #%d has length %d, consensus is %d"
% (i+2, len(s), cons_length))
if '.' in str(consensus.seq):
# Strict -- error if there's a '-'
if '-' in str(consensus.seq):
if strict:
raise ValueError("Consensus contains '-' gap characters")
logging.warn("Consensus sequence contains both '.' and '-' gap "
"characters -- is it really the consensus?")
aligned_cols = [(c not in '.-') for c in str(consensus.seq)]
else:
aligned_cols = [c != '.' for c in str(consensus.seq)]
else:
# A little more ambiguous...
aligned_cols = [c != '-' for c in str(consensus.seq)]
consensus.seq = replace_asterisks(consensus.seq, 'consensus')
# Start a block with the consensus sequence
block = consensus2block(consensus, level=level, name=name)
qlen = block['query_length']
# Collapse & add remaining sequences to the block
for index, rec in zip(xrange(2, len(seqrecords)+2), seqrecords):
# Collapse rec.seq down to aligned size
new_mol_seq = []
is_beginning = True
for aligned_col, char in zip(aligned_cols,
replace_asterisks(rec.seq, index)):
if aligned_col:
is_beginning = False
if char in '-.':
# deletion
new_mol_seq.append('-')
else:
# aligned character
new_mol_seq.append(char.upper())
else:
# it's an insert or nothing
# (also, skip any left-side inserts)
if char not in '-.' and not is_beginning:
new_mol_seq.append(char.lower())
rec.seq = ''.join(new_mol_seq)
if do_iron:
rec.seq = iron(rec.seq)
block['sequences'].append(seqrecord2sequence(rec, qlen, index))
return block |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:iron; 3, parameters; 3, 4; 4, identifier:sequence; 5, block; 5, 6; 5, 8; 5, 17; 5, 21; 5, 407; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:r_indel; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:re; 14, identifier:compile; 15, argument_list; 15, 16; 16, string:r'(-[a-y]|[a-y]-)'; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:orig_sequence; 20, identifier:sequence; 21, while_statement; 21, 22; 21, 28; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:r_indel; 25, identifier:search; 26, argument_list; 26, 27; 27, identifier:sequence; 28, block; 28, 29; 28, 33; 28, 37; 28, 41; 28, 45; 28, 49; 28, 342; 28, 343; 28, 353; 28, 365; 28, 374; 28, 375; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:in_insert; 32, False; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:in_gap; 36, False; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:seen_gaps; 40, integer:0; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:inserts; 44, list:[]; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:outchars; 48, list:[]; 49, for_statement; 49, 50; 49, 51; 49, 52; 50, identifier:char; 51, identifier:sequence; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 55; 53, 172; 53, 277; 54, identifier:in_insert; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 62; 56, 63; 56, 71; 56, 114; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:char; 60, identifier:islower; 61, argument_list; 62, comment; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:inserts; 68, identifier:append; 69, argument_list; 69, 70; 70, identifier:char; 71, elif_clause; 71, 72; 71, 77; 71, 78; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:char; 75, identifier:isupper; 76, argument_list; 77, comment; 78, block; 78, 79; 78, 83; 78, 90; 78, 94; 78, 103; 78, 107; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:in_insert; 82, False; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:outchars; 87, identifier:extend; 88, argument_list; 88, 89; 89, identifier:inserts; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:inserts; 93, list:[]; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:outchars; 98, identifier:append; 99, argument_list; 99, 100; 100, binary_operator:*; 100, 101; 100, 102; 101, string:'-'; 102, identifier:seen_gaps; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:seen_gaps; 106, integer:0; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:outchars; 111, identifier:append; 112, argument_list; 112, 113; 113, identifier:char; 114, else_clause; 114, 115; 114, 116; 114, 117; 114, 118; 114, 119; 115, comment; 116, comment; 117, comment; 118, comment; 119, block; 119, 120; 119, 124; 120, assert_statement; 120, 121; 121, comparison_operator:==; 121, 122; 121, 123; 122, identifier:char; 123, string:'-'; 124, if_statement; 124, 125; 124, 127; 124, 140; 125, not_operator; 125, 126; 126, identifier:inserts; 127, block; 127, 128; 127, 132; 127, 136; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:in_insert; 131, False; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:in_gap; 135, True; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:seen_gaps; 139, integer:1; 140, else_clause; 140, 141; 141, block; 141, 142; 141, 158; 141, 159; 141, 160; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:outchars; 146, identifier:append; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 157; 149, attribute; 149, 150; 149, 156; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:inserts; 153, identifier:pop; 154, argument_list; 154, 155; 155, integer:0; 156, identifier:upper; 157, argument_list; 158, comment; 159, comment; 160, if_statement; 160, 161; 160, 163; 161, not_operator; 161, 162; 162, identifier:inserts; 163, block; 163, 164; 163, 168; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:in_insert; 167, False; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:in_gap; 171, True; 172, elif_clause; 172, 173; 172, 174; 173, identifier:in_gap; 174, block; 174, 175; 175, if_statement; 175, 176; 175, 181; 175, 220; 175, 266; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:char; 179, identifier:islower; 180, argument_list; 181, block; 181, 182; 181, 186; 181, 190; 181, 191; 181, 192; 181, 215; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:in_insert; 185, True; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:in_gap; 189, False; 190, comment; 191, comment; 192, if_statement; 192, 193; 192, 194; 193, identifier:inserts; 194, block; 194, 195; 194, 202; 194, 211; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:outchars; 199, identifier:extend; 200, argument_list; 200, 201; 201, identifier:inserts; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:outchars; 206, identifier:append; 207, argument_list; 207, 208; 208, binary_operator:*; 208, 209; 208, 210; 209, string:'-'; 210, identifier:seen_gaps; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:seen_gaps; 214, integer:0; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:inserts; 218, list:[char]; 218, 219; 219, identifier:char; 220, elif_clause; 220, 221; 220, 226; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:char; 224, identifier:isupper; 225, argument_list; 226, block; 226, 227; 226, 231; 226, 232; 226, 246; 226, 255; 226, 259; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:in_gap; 230, False; 231, comment; 232, if_statement; 232, 233; 232, 234; 233, identifier:inserts; 234, block; 234, 235; 234, 242; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:outchars; 239, identifier:extend; 240, argument_list; 240, 241; 241, identifier:inserts; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:inserts; 245, list:[]; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:outchars; 250, identifier:append; 251, argument_list; 251, 252; 252, binary_operator:*; 252, 253; 252, 254; 253, string:'-'; 254, identifier:seen_gaps; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:seen_gaps; 258, integer:0; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:outchars; 263, identifier:append; 264, argument_list; 264, 265; 265, identifier:char; 266, else_clause; 266, 267; 266, 268; 267, comment; 268, block; 268, 269; 268, 273; 269, assert_statement; 269, 270; 270, comparison_operator:==; 270, 271; 270, 272; 271, identifier:char; 272, string:'-'; 273, expression_statement; 273, 274; 274, augmented_assignment:+=; 274, 275; 274, 276; 275, identifier:seen_gaps; 276, integer:1; 277, else_clause; 277, 278; 278, block; 278, 279; 278, 294; 278, 295; 279, assert_statement; 279, 280; 279, 285; 280, boolean_operator:and; 280, 281; 280, 283; 281, not_operator; 281, 282; 282, identifier:inserts; 283, not_operator; 283, 284; 284, identifier:seen_gaps; 285, parenthesized_expression; 285, 286; 286, binary_operator:%; 286, 287; 286, 288; 287, string:"Inserts: %s, gaps: %s, seq: %s, in_ins=%s, in_gap=%s"; 288, tuple; 288, 289; 288, 290; 288, 291; 288, 292; 288, 293; 289, identifier:inserts; 290, identifier:seen_gaps; 291, identifier:sequence; 292, identifier:in_insert; 293, identifier:in_gap; 294, comment; 295, if_statement; 295, 296; 295, 301; 295, 302; 295, 310; 295, 328; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:char; 299, identifier:isupper; 300, argument_list; 301, comment; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:outchars; 307, identifier:append; 308, argument_list; 308, 309; 309, identifier:char; 310, elif_clause; 310, 311; 310, 316; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:char; 314, identifier:islower; 315, argument_list; 316, block; 316, 317; 316, 324; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:inserts; 321, identifier:append; 322, argument_list; 322, 323; 323, identifier:char; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:in_insert; 327, True; 328, else_clause; 328, 329; 329, block; 329, 330; 329, 334; 329, 338; 330, assert_statement; 330, 331; 331, comparison_operator:==; 331, 332; 331, 333; 332, identifier:char; 333, string:'-'; 334, expression_statement; 334, 335; 335, augmented_assignment:+=; 335, 336; 335, 337; 336, identifier:seen_gaps; 337, integer:1; 338, expression_statement; 338, 339; 339, assignment; 339, 340; 339, 341; 340, identifier:in_gap; 341, True; 342, comment; 343, if_statement; 343, 344; 343, 345; 344, identifier:inserts; 345, block; 345, 346; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:outchars; 350, identifier:extend; 351, argument_list; 351, 352; 352, identifier:inserts; 353, if_statement; 353, 354; 353, 355; 354, identifier:seen_gaps; 355, block; 355, 356; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:outchars; 360, identifier:append; 361, argument_list; 361, 362; 362, binary_operator:*; 362, 363; 362, 364; 363, string:'-'; 364, identifier:seen_gaps; 365, expression_statement; 365, 366; 366, assignment; 366, 367; 366, 368; 367, identifier:sequence; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, string:''; 371, identifier:join; 372, argument_list; 372, 373; 373, identifier:outchars; 374, comment; 375, assert_statement; 375, 376; 375, 400; 376, parenthesized_expression; 376, 377; 377, comparison_operator:==; 377, 378; 377, 389; 378, call; 378, 379; 378, 388; 379, attribute; 379, 380; 379, 387; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:sequence; 383, identifier:replace; 384, argument_list; 384, 385; 384, 386; 385, string:'-'; 386, string:''; 387, identifier:upper; 388, argument_list; 389, call; 389, 390; 389, 399; 390, attribute; 390, 391; 390, 398; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:orig_sequence; 394, identifier:replace; 395, argument_list; 395, 396; 395, 397; 396, string:'-'; 397, string:''; 398, identifier:upper; 399, argument_list; 400, binary_operator:+; 400, 401; 400, 406; 401, binary_operator:+; 401, 402; 401, 405; 402, binary_operator:+; 402, 403; 402, 404; 403, string:'\nOrig: '; 404, identifier:orig_sequence; 405, string:'\nIron: '; 406, identifier:sequence; 407, return_statement; 407, 408; 408, identifier:sequence | def iron(sequence):
"""'Iron out' indel regions in the aligned sequence.
Any inserts next to deletions are converted to matches (uppercase).
Given a CMA string like:
AAAAbc--de-f--gAAA
Result:
AAAABCDEFgAAA
"""
r_indel = re.compile(r'(-[a-y]|[a-y]-)')
orig_sequence = sequence
while r_indel.search(sequence):
in_insert = False
in_gap = False
seen_gaps = 0
inserts = []
outchars = []
for char in sequence:
if in_insert:
if char.islower():
# Extend the insert
inserts.append(char)
elif char.isupper():
# Indel is over; 'iron' out & emit inserts, then gaps
in_insert = False
outchars.extend(inserts)
inserts = []
outchars.append('-' * seen_gaps)
seen_gaps = 0
outchars.append(char)
else:
# Convert a preceding indel char to a 'match' (uppercase)
# If the indel and gap are both multiple chars, this will
# capitalize the insert left-to-right, then leave any gap
# remainer as-is.
assert char == '-'
if not inserts:
in_insert = False
in_gap = True
seen_gaps += 1
else:
outchars.append(inserts.pop(0).upper())
# NB: Only leave the insert region if we've finished
# converting all the insert chars
if not inserts:
in_insert = False
in_gap = True
elif in_gap:
if char.islower():
in_insert = True
in_gap = False
# If some inserts previously seen, emit them now
# If no inserts have been seen yet, we'll iron this indel
if inserts:
outchars.extend(inserts)
outchars.append('-' * seen_gaps)
seen_gaps = 0
inserts = [char]
elif char.isupper():
in_gap = False
# End of the gap -- emit
if inserts:
outchars.extend(inserts)
inserts = []
outchars.append('-' * seen_gaps)
seen_gaps = 0
outchars.append(char)
else:
# Extend the gap
assert char == '-'
seen_gaps += 1
else:
assert not inserts and not seen_gaps, (
"Inserts: %s, gaps: %s, seq: %s, in_ins=%s, in_gap=%s"
% (inserts, seen_gaps, sequence, in_insert, in_gap))
# Coming from Match state
if char.isupper():
# Extend the match
outchars.append(char)
elif char.islower():
inserts.append(char)
in_insert = True
else:
assert char == '-'
seen_gaps += 1
in_gap = True
# Emit any trailing indel
if inserts:
outchars.extend(inserts)
if seen_gaps:
outchars.append('-' * seen_gaps)
sequence = ''.join(outchars)
# logging.info(sequence)
assert (sequence.replace('-', '').upper()
==
orig_sequence.replace('-', '').upper()), \
'\nOrig: ' + orig_sequence + \
'\nIron: ' + sequence
return sequence |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:collect_reponames; 3, parameters; 4, block; 4, 5; 4, 7; 4, 11; 4, 12; 4, 149; 4, 150; 4, 221; 5, expression_statement; 5, 6; 6, comment; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:reponames; 10, list:[]; 11, comment; 12, try_statement; 12, 13; 12, 139; 12, 143; 13, block; 13, 14; 13, 43; 13, 47; 13, 102; 14, with_statement; 14, 15; 14, 26; 15, with_clause; 15, 16; 16, with_item; 16, 17; 17, as_pattern; 17, 18; 17, 24; 18, call; 18, 19; 18, 20; 19, identifier:open; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:os; 23, identifier:devnull; 24, as_pattern_target; 24, 25; 25, identifier:devnull; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:remote_data; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:subprocess; 33, identifier:check_output; 34, argument_list; 34, 35; 34, 40; 35, list:["git","remote","-v","show"]; 35, 36; 35, 37; 35, 38; 35, 39; 36, string:"git"; 37, string:"remote"; 38, string:"-v"; 39, string:"show"; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:stderr; 42, identifier:devnull; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:branches; 46, dictionary; 47, for_statement; 47, 48; 47, 49; 47, 60; 48, identifier:line; 49, call; 49, 50; 49, 58; 50, attribute; 50, 51; 50, 57; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:remote_data; 54, identifier:decode; 55, argument_list; 55, 56; 56, string:'utf-8'; 57, identifier:split; 58, argument_list; 58, 59; 59, string:"\n"; 60, block; 60, 61; 60, 71; 60, 80; 61, if_statement; 61, 62; 61, 69; 62, comparison_operator:==; 62, 63; 62, 68; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:line; 66, identifier:strip; 67, argument_list; 68, string:""; 69, block; 69, 70; 70, continue_statement; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:remote_match; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:re_mote; 77, identifier:match; 78, argument_list; 78, 79; 79, identifier:line; 80, if_statement; 80, 81; 80, 85; 81, not_operator; 81, 82; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:remote_match; 84, None; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 96; 88, subscript; 88, 89; 88, 90; 89, identifier:branches; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:remote_match; 93, identifier:group; 94, argument_list; 94, 95; 95, integer:1; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:remote_match; 99, identifier:group; 100, argument_list; 100, 101; 101, integer:5; 102, if_statement; 102, 103; 102, 109; 103, comparison_operator:>; 103, 104; 103, 108; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:branches; 108, integer:0; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 114; 110, 124; 111, comparison_operator:in; 111, 112; 111, 113; 112, string:"origin"; 113, identifier:branches; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:reponames; 119, identifier:append; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:branches; 123, string:"origin"; 124, else_clause; 124, 125; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:reponames; 130, identifier:append; 131, argument_list; 131, 132; 132, subscript; 132, 133; 132, 138; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:branches; 136, identifier:values; 137, argument_list; 138, integer:0; 139, except_clause; 139, 140; 139, 141; 140, identifier:OSError; 141, block; 141, 142; 142, pass_statement; 143, except_clause; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:subprocess; 146, identifier:CalledProcessError; 147, block; 147, 148; 148, pass_statement; 149, comment; 150, for_statement; 150, 151; 150, 152; 150, 158; 151, identifier:fname; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:glob; 155, identifier:iglob; 156, argument_list; 156, 157; 157, string:"*.html"; 158, block; 158, 159; 158, 168; 158, 169; 158, 175; 158, 183; 158, 193; 158, 211; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:fid; 162, call; 162, 163; 162, 164; 163, identifier:open; 164, argument_list; 164, 165; 164, 166; 164, 167; 165, identifier:fname; 166, string:"r"; 167, string:"utf8"; 168, comment; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:fid; 173, identifier:readline; 174, argument_list; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:line; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:fid; 181, identifier:readline; 182, argument_list; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:match; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:re; 189, identifier:match; 190, argument_list; 190, 191; 190, 192; 191, identifier:repo_marker_re; 192, identifier:line; 193, if_statement; 193, 194; 193, 198; 194, not_operator; 194, 195; 195, comparison_operator:is; 195, 196; 195, 197; 196, identifier:match; 197, None; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:reponames; 203, identifier:append; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:match; 208, identifier:group; 209, argument_list; 209, 210; 210, integer:1; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:reponames; 214, call; 214, 215; 214, 216; 215, identifier:list; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 219; 218, identifier:set; 219, argument_list; 219, 220; 220, identifier:reponames; 221, return_statement; 221, 222; 222, identifier:reponames | def collect_reponames():
"""
Try to figure out a list of repos to consider by default from the contents of the working directory.
"""
reponames = []
#try to figure out the repo from git repo in current directory
try:
with open(os.devnull) as devnull:
remote_data = subprocess.check_output(["git","remote","-v","show"],stderr=devnull)
branches = {}
for line in remote_data.decode('utf-8').split("\n"):
if line.strip() == "":
continue
remote_match = re_mote.match(line)
if not remote_match is None:
branches[remote_match.group(1)] = remote_match.group(5)
if len(branches) > 0:
if "origin" in branches:
reponames.append(branches["origin"])
else:
reponames.append(branches.values()[0])
except OSError:
pass
except subprocess.CalledProcessError:
pass
#scan html files for further repos to consider
for fname in glob.iglob("*.html"):
fid = open(fname,"r","utf8")
#check the second line for the repo marker
fid.readline()
line = fid.readline()
match = re.match(repo_marker_re,line)
if not match is None:
reponames.append(match.group(1))
reponames = list(set(reponames))
return reponames |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:build_markdown_table; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:headers; 5, identifier:rows; 6, default_parameter; 6, 7; 6, 8; 7, identifier:row_keys; 8, None; 9, block; 9, 10; 9, 12; 9, 20; 9, 36; 9, 51; 9, 67; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:row_maxes; 15, call; 15, 16; 15, 17; 16, identifier:_find_row_maxes; 17, argument_list; 17, 18; 17, 19; 18, identifier:headers; 19, identifier:rows; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:row_keys; 23, boolean_operator:or; 23, 24; 23, 25; 24, identifier:row_keys; 25, list_comprehension; 25, 26; 25, 27; 26, identifier:key; 27, for_in_clause; 27, 28; 27, 31; 28, pattern_list; 28, 29; 28, 30; 29, identifier:key; 30, identifier:value; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:headers; 34, identifier:items; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:table; 39, list:[
_build_row(headers, row_maxes, row_keys),
_build_separator(row_maxes, row_keys)
]; 39, 40; 39, 46; 40, call; 40, 41; 40, 42; 41, identifier:_build_row; 42, argument_list; 42, 43; 42, 44; 42, 45; 43, identifier:headers; 44, identifier:row_maxes; 45, identifier:row_keys; 46, call; 46, 47; 46, 48; 47, identifier:_build_separator; 48, argument_list; 48, 49; 48, 50; 49, identifier:row_maxes; 50, identifier:row_keys; 51, for_statement; 51, 52; 51, 53; 51, 54; 52, identifier:row; 53, identifier:rows; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:table; 59, identifier:append; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:_build_row; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, identifier:row; 65, identifier:row_maxes; 66, identifier:row_keys; 67, return_statement; 67, 68; 68, binary_operator:+; 68, 69; 68, 75; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:'\n'; 72, identifier:join; 73, argument_list; 73, 74; 74, identifier:table; 75, string:'\n' | def build_markdown_table(headers, rows, row_keys=None):
"""Build a lined up markdown table.
Args:
headers (dict): A key -> value pairing fo the headers.
rows (list): List of dictionaries that contain all the keys listed in
the headers.
row_keys (list): A sorted list of keys to display
Returns:
A valid Markdown Table as a string.
"""
row_maxes = _find_row_maxes(headers, rows)
row_keys = row_keys or [key for key, value in headers.items()]
table = [
_build_row(headers, row_maxes, row_keys),
_build_separator(row_maxes, row_keys)
]
for row in rows:
table.append(_build_row(row, row_maxes, row_keys))
return '\n'.join(table) + '\n' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:create_publication_assistant; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 11; 7, 17; 7, 24; 7, 34; 7, 35; 7, 61; 7, 62; 7, 88; 7, 89; 7, 100; 7, 101; 7, 154; 7, 160; 8, expression_statement; 8, 9; 9, string:'''
Create an assistant for a dataset that allows to make PID
requests for the dataset and all of its files.
:param drs_id: Mandatory. The dataset id of the dataset
to be published.
:param version_number: Mandatory. The version number of the
dataset to be published.
:param is_replica: Mandatory. Flag to indicate whether the
dataset is a replica.
.. note:: If the replica flag is set to False, the publication
may still be considered a replica by the consuming servlet,
namely if the dataset was already published at a different
host. For this, please refer to the consumer documentation.
:return: A publication assistant which provides all necessary
methods to publish a dataset and its files.
'''; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:logdebug; 14, argument_list; 14, 15; 14, 16; 15, identifier:LOGGER; 16, string:'Creating publication assistant..'; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:mandatory_args; 20, list:['drs_id', 'version_number', 'is_replica']; 20, 21; 20, 22; 20, 23; 21, string:'drs_id'; 22, string:'version_number'; 23, string:'is_replica'; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:esgfpid; 29, identifier:utils; 30, identifier:check_presence_of_mandatory_args; 31, argument_list; 31, 32; 31, 33; 32, identifier:args; 33, identifier:mandatory_args; 34, comment; 35, if_statement; 35, 36; 35, 41; 36, comparison_operator:is; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:__thredds_service_path; 40, None; 41, block; 41, 42; 41, 46; 41, 52; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:msg; 45, string:'No thredds_service_path given (but it is mandatory for publication)'; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:logwarn; 49, argument_list; 49, 50; 49, 51; 50, identifier:LOGGER; 51, identifier:msg; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:esgfpid; 57, identifier:exceptions; 58, identifier:ArgumentError; 59, argument_list; 59, 60; 60, identifier:msg; 61, comment; 62, if_statement; 62, 63; 62, 68; 63, comparison_operator:is; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:__data_node; 67, None; 68, block; 68, 69; 68, 73; 68, 79; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:msg; 72, string:'No data_node given (but it is mandatory for publication)'; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:logwarn; 76, argument_list; 76, 77; 76, 78; 77, identifier:LOGGER; 78, identifier:msg; 79, raise_statement; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:esgfpid; 84, identifier:exceptions; 85, identifier:ArgumentError; 86, argument_list; 86, 87; 87, identifier:msg; 88, comment; 89, if_statement; 89, 90; 89, 97; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:__coupler; 95, identifier:is_solr_switched_off; 96, argument_list; 97, block; 97, 98; 97, 99; 98, pass_statement; 99, comment; 100, comment; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:assistant; 104, call; 104, 105; 104, 112; 105, attribute; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:esgfpid; 109, identifier:assistant; 110, identifier:publish; 111, identifier:DatasetPublicationAssistant; 112, argument_list; 112, 113; 112, 118; 112, 123; 112, 128; 112, 133; 112, 138; 112, 143; 112, 148; 112, 153; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:drs_id; 115, subscript; 115, 116; 115, 117; 116, identifier:args; 117, string:'drs_id'; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:version_number; 120, subscript; 120, 121; 120, 122; 121, identifier:args; 122, string:'version_number'; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:thredds_service_path; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:__thredds_service_path; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:data_node; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:__data_node; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:prefix; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:prefix; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:coupler; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:__coupler; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:is_replica; 145, subscript; 145, 146; 145, 147; 146, identifier:args; 147, string:'is_replica'; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:consumer_solr_url; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:__consumer_solr_url; 153, comment; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:logdebug; 157, argument_list; 157, 158; 157, 159; 158, identifier:LOGGER; 159, string:'Creating publication assistant.. done'; 160, return_statement; 160, 161; 161, identifier:assistant | def create_publication_assistant(self, **args):
'''
Create an assistant for a dataset that allows to make PID
requests for the dataset and all of its files.
:param drs_id: Mandatory. The dataset id of the dataset
to be published.
:param version_number: Mandatory. The version number of the
dataset to be published.
:param is_replica: Mandatory. Flag to indicate whether the
dataset is a replica.
.. note:: If the replica flag is set to False, the publication
may still be considered a replica by the consuming servlet,
namely if the dataset was already published at a different
host. For this, please refer to the consumer documentation.
:return: A publication assistant which provides all necessary
methods to publish a dataset and its files.
'''
# Check args
logdebug(LOGGER, 'Creating publication assistant..')
mandatory_args = ['drs_id', 'version_number', 'is_replica']
esgfpid.utils.check_presence_of_mandatory_args(args, mandatory_args)
# Check if service path is given
if self.__thredds_service_path is None:
msg = 'No thredds_service_path given (but it is mandatory for publication)'
logwarn(LOGGER, msg)
raise esgfpid.exceptions.ArgumentError(msg)
# Check if data node is given
if self.__data_node is None:
msg = 'No data_node given (but it is mandatory for publication)'
logwarn(LOGGER, msg)
raise esgfpid.exceptions.ArgumentError(msg)
# Check if solr has access:
if self.__coupler.is_solr_switched_off():
pass # solr access not mandatory anymore
# Create publication assistant
assistant = esgfpid.assistant.publish.DatasetPublicationAssistant(
drs_id=args['drs_id'],
version_number=args['version_number'],
thredds_service_path=self.__thredds_service_path,
data_node=self.__data_node,
prefix=self.prefix,
coupler=self.__coupler,
is_replica=args['is_replica'],
consumer_solr_url=self.__consumer_solr_url # may be None
)
logdebug(LOGGER, 'Creating publication assistant.. done')
return assistant |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:replace_source; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:source; 6, identifier:name; 7, identifier:modules; 8, identifier:prefix; 9, block; 9, 10; 9, 12; 9, 16; 9, 104; 9, 117; 9, 128; 9, 137; 9, 141; 9, 198; 9, 209; 9, 221; 9, 234; 9, 244; 9, 252; 9, 274; 9, 278; 9, 291; 9, 304; 9, 316; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:needs_windll; 15, False; 16, function_definition; 16, 17; 16, 18; 16, 22; 17, function_name:_func_replacer; 18, parameters; 18, 19; 18, 20; 18, 21; 19, identifier:match; 20, identifier:modules; 21, identifier:windll; 22, block; 22, 23; 22, 32; 22, 41; 22, 52; 22, 102; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:matched; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:match; 29, identifier:group; 30, argument_list; 30, 31; 31, integer:0; 32, if_statement; 32, 33; 32, 38; 33, comparison_operator:in; 33, 34; 33, 35; 34, identifier:matched; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:BLACKLIST; 38, block; 38, 39; 39, return_statement; 39, 40; 40, identifier:matched; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:module; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:database; 49, identifier:query_func_module; 50, argument_list; 50, 51; 51, identifier:matched; 52, if_statement; 52, 53; 52, 54; 53, identifier:module; 54, block; 54, 55; 54, 82; 54, 94; 55, try_statement; 55, 56; 55, 68; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, augmented_assignment:+=; 58, 59; 58, 64; 59, subscript; 59, 60; 59, 61; 60, identifier:modules; 61, subscript; 61, 62; 61, 63; 62, identifier:module; 63, integer:0; 64, list:[module[1]]; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:module; 67, integer:1; 68, except_clause; 68, 69; 68, 70; 69, identifier:KeyError; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 78; 73, subscript; 73, 74; 73, 75; 74, identifier:modules; 75, subscript; 75, 76; 75, 77; 76, identifier:module; 77, integer:0; 78, list:[module[1]]; 78, 79; 79, subscript; 79, 80; 79, 81; 80, identifier:module; 81, integer:1; 82, if_statement; 82, 83; 82, 84; 83, identifier:windll; 84, block; 84, 85; 85, return_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, string:'{}->{}.{}'; 89, identifier:format; 90, argument_list; 90, 91; 90, 92; 91, identifier:windll; 92, list_splat; 92, 93; 93, identifier:module; 94, return_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, string:'{}->{}'; 98, identifier:format; 99, argument_list; 99, 100; 100, list_splat; 100, 101; 101, identifier:module; 102, return_statement; 102, 103; 103, identifier:matched; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:replacer; 107, call; 107, 108; 107, 109; 108, identifier:partial; 109, argument_list; 109, 110; 109, 111; 109, 114; 110, identifier:_func_replacer; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:modules; 113, identifier:modules; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:windll; 116, string:'windll'; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:replaced; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:re; 123, identifier:sub; 124, argument_list; 124, 125; 124, 126; 124, 127; 125, string:r'[_\w][_\w\d]*(?=\s*\()'; 126, identifier:replacer; 127, identifier:source; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:!=; 129, 130; 129, 131; 130, identifier:source; 131, identifier:replaced; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:needs_windll; 136, True; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:str_table; 140, dictionary; 141, function_definition; 141, 142; 141, 143; 141, 145; 142, function_name:_string_replacer; 143, parameters; 143, 144; 144, identifier:match; 145, block; 145, 146; 145, 160; 145, 190; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:matched; 149, subscript; 149, 150; 149, 155; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:match; 153, identifier:group; 154, argument_list; 155, slice; 155, 156; 155, 157; 155, 158; 156, integer:1; 157, colon; 158, unary_operator:-; 158, 159; 159, integer:1; 160, try_statement; 160, 161; 160, 168; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:number; 165, subscript; 165, 166; 165, 167; 166, identifier:str_table; 167, identifier:matched; 168, except_clause; 168, 169; 168, 170; 169, identifier:KeyError; 170, block; 170, 171; 170, 180; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:number; 174, binary_operator:+; 174, 175; 174, 179; 175, call; 175, 176; 175, 177; 176, identifier:len; 177, argument_list; 177, 178; 178, identifier:str_table; 179, integer:1; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:str_table; 184, identifier:update; 185, argument_list; 185, 186; 186, dictionary; 186, 187; 187, pair; 187, 188; 187, 189; 188, identifier:matched; 189, identifier:number; 190, return_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, string:'{}{}'; 194, identifier:format; 195, argument_list; 195, 196; 195, 197; 196, identifier:prefix; 197, identifier:number; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:replaced; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:re; 204, identifier:sub; 205, argument_list; 205, 206; 205, 207; 205, 208; 206, string:r'".+?"'; 207, identifier:_string_replacer; 208, identifier:replaced; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, pattern_list; 211, 212; 211, 213; 212, identifier:strings; 213, identifier:relocs; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:build_strings; 218, argument_list; 218, 219; 218, 220; 219, identifier:str_table; 220, identifier:prefix; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:strings; 224, call; 224, 225; 224, 233; 225, attribute; 225, 226; 225, 232; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, string:''; 229, identifier:join; 230, argument_list; 230, 231; 231, identifier:strings; 232, identifier:strip; 233, argument_list; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:windll32; 237, call; 237, 238; 237, 239; 238, identifier:reloc_var; 239, argument_list; 239, 240; 239, 241; 239, 242; 239, 243; 240, string:'windll'; 241, string:'reloc_delta'; 242, True; 243, string:'windll_t'; 244, if_statement; 244, 245; 244, 246; 245, identifier:needs_windll; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, augmented_assignment:+=; 248, 249; 248, 250; 249, identifier:relocs; 250, list:[windll32]; 250, 251; 251, identifier:windll32; 252, if_statement; 252, 253; 252, 254; 253, identifier:strings; 254, block; 254, 255; 254, 261; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:strings; 258, binary_operator:+; 258, 259; 258, 260; 259, string:'\n'; 260, identifier:strings; 261, if_statement; 261, 262; 261, 264; 262, not_operator; 262, 263; 263, identifier:needs_windll; 264, block; 264, 265; 264, 270; 265, expression_statement; 265, 266; 266, augmented_assignment:+=; 266, 267; 266, 268; 267, identifier:relocs; 268, list:[windll32]; 268, 269; 269, identifier:windll32; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:needs_windll; 273, True; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:windll64; 277, string:''; 278, if_statement; 278, 279; 278, 280; 279, identifier:needs_windll; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:windll64; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, string:'{0} *{1} = &_{1};\n'; 287, identifier:format; 288, argument_list; 288, 289; 288, 290; 289, string:'windll_t'; 290, string:'windll'; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:relocs; 294, call; 294, 295; 294, 296; 295, identifier:reloc_both; 296, argument_list; 296, 297; 296, 303; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, string:''; 300, identifier:join; 301, argument_list; 301, 302; 302, identifier:relocs; 303, identifier:windll64; 304, if_statement; 304, 305; 304, 309; 305, comparison_operator:in; 305, 306; 305, 307; 306, identifier:name; 307, list:['main']; 307, 308; 308, string:'main'; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:replaced; 313, binary_operator:+; 313, 314; 313, 315; 314, string:'\ninit();'; 315, identifier:replaced; 316, return_statement; 316, 317; 317, binary_operator:+; 317, 318; 317, 321; 318, binary_operator:+; 318, 319; 318, 320; 319, identifier:strings; 320, identifier:relocs; 321, identifier:replaced | def replace_source(self, source, name, modules, prefix):
"""Scan C source code for string literals as well as
function calls and do replacement using the specified
replacing function.
Note that the regular expression currently used for strings
is naive or quick and dirty.
"""
needs_windll = False
def _func_replacer(match, modules, windll):
matched = match.group(0)
if matched in self.BLACKLIST:
return matched
module = self.database.query_func_module(matched)
if module:
try:
modules[module[0]] += [module[1]]
except KeyError:
modules[module[0]] = [module[1]]
if windll:
return '{}->{}.{}'.format(windll, *module)
return '{}->{}'.format(*module)
return matched
replacer = partial(
_func_replacer, modules=modules, windll='windll')
replaced = re.sub(r'[_\w][_\w\d]*(?=\s*\()',
replacer, source)
if source != replaced:
needs_windll = True
str_table = {}
def _string_replacer(match):
matched = match.group()[1:-1]
try:
number = str_table[matched]
except KeyError:
number = len(str_table) + 1
str_table.update({matched: number})
return '{}{}'.format(prefix, number)
replaced = re.sub(r'".+?"', _string_replacer, replaced)
strings, relocs = self.build_strings(str_table, prefix)
strings = ''.join(strings).strip()
windll32 = reloc_var('windll', 'reloc_delta', True,
'windll_t')
if needs_windll:
relocs += [windll32]
if strings:
strings = '\n' + strings
if not needs_windll:
relocs += [windll32]
needs_windll = True
windll64 = ''
if needs_windll:
windll64 = '{0} *{1} = &_{1};\n'.format('windll_t',
'windll')
relocs = reloc_both(''.join(relocs), windll64)
if name in ['main']:
replaced = '\ninit();' + replaced
return strings + relocs + replaced |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_item; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:iterable; 5, identifier:number; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, block; 9, 10; 9, 12; 10, expression_statement; 10, 11; 11, comment; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:sorted; 15, argument_list; 15, 16; 15, 17; 15, 23; 16, identifier:iterable; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:key; 19, call; 19, 20; 19, 21; 20, identifier:itemgetter; 21, argument_list; 21, 22; 22, identifier:number; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:reverse; 25, identifier:reverse | def sort_item(iterable, number, reverse=False):
"""Sort the itertable according to the given number item."""
return sorted(iterable, key=itemgetter(number), reverse=reverse) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_equivalent_positions; 3, parameters; 3, 4; 4, identifier:block; 5, block; 5, 6; 5, 8; 5, 18; 5, 28; 5, 29; 5, 43; 5, 44; 5, 50; 5, 56; 5, 87; 5, 102; 5, 106; 5, 110; 5, 111; 5, 142; 5, 162; 5, 163; 5, 164; 5, 165; 5, 287; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:consensus; 11, subscript; 11, 12; 11, 17; 12, subscript; 12, 13; 12, 16; 13, subscript; 13, 14; 13, 15; 14, identifier:block; 15, string:'sequences'; 16, integer:0; 17, string:'seq'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:rest; 21, subscript; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:block; 24, string:'sequences'; 25, slice; 25, 26; 25, 27; 26, integer:1; 27, colon; 28, comment; 29, if_statement; 29, 30; 29, 37; 30, boolean_operator:or; 30, 31; 30, 34; 31, comparison_operator:in; 31, 32; 31, 33; 32, string:'-'; 33, identifier:consensus; 34, comparison_operator:in; 34, 35; 34, 36; 35, string:'.'; 36, identifier:consensus; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:ValueError; 41, argument_list; 41, 42; 42, string:"First sequence (consensus?) contains gaps"; 43, comment; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:seen; 47, call; 47, 48; 47, 49; 48, identifier:set; 49, argument_list; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:dupes; 53, call; 53, 54; 53, 55; 54, identifier:set; 55, argument_list; 56, for_statement; 56, 57; 56, 58; 56, 59; 57, identifier:rec; 58, identifier:rest; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 66; 60, 76; 61, comparison_operator:in; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:rec; 64, string:'id'; 65, identifier:seen; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:dupes; 71, identifier:add; 72, argument_list; 72, 73; 73, subscript; 73, 74; 73, 75; 74, identifier:rec; 75, string:'id'; 76, else_clause; 76, 77; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:seen; 82, identifier:add; 83, argument_list; 83, 84; 84, subscript; 84, 85; 84, 86; 85, identifier:rec; 86, string:'id'; 87, if_statement; 87, 88; 87, 89; 88, identifier:dupes; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:ValueError; 93, argument_list; 93, 94; 94, binary_operator:+; 94, 95; 94, 96; 95, string:"Duplicate sequences:\n"; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:'\n'; 99, identifier:join; 100, argument_list; 100, 101; 101, identifier:dupes; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:curr_shift; 105, dictionary; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:curr_resn; 109, dictionary; 110, comment; 111, for_statement; 111, 112; 111, 113; 111, 114; 111, 115; 111, 116; 111, 117; 111, 118; 111, 119; 111, 120; 112, identifier:rec; 113, identifier:rest; 114, comment; 115, comment; 116, comment; 117, comment; 118, comment; 119, comment; 120, block; 120, 121; 120, 129; 120, 130; 120, 131; 120, 132; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 128; 123, subscript; 123, 124; 123, 125; 124, identifier:curr_shift; 125, subscript; 125, 126; 125, 127; 126, identifier:rec; 127, string:'id'; 128, integer:0; 129, comment; 130, comment; 131, comment; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 139; 134, subscript; 134, 135; 134, 136; 135, identifier:curr_resn; 136, subscript; 136, 137; 136, 138; 137, identifier:rec; 138, string:'id'; 139, subscript; 139, 140; 139, 141; 140, identifier:rec; 141, string:'head_len'; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:equivalencies; 145, call; 145, 146; 145, 147; 146, identifier:dict; 147, generator_expression; 147, 148; 147, 153; 148, tuple; 148, 149; 148, 152; 149, binary_operator:+; 149, 150; 149, 151; 150, identifier:i; 151, integer:1; 152, dictionary; 153, for_in_clause; 153, 154; 153, 155; 154, identifier:i; 155, call; 155, 156; 155, 157; 156, identifier:xrange; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, identifier:consensus; 162, comment; 163, comment; 164, comment; 165, for_statement; 165, 166; 165, 169; 165, 173; 166, pattern_list; 166, 167; 166, 168; 167, identifier:i; 168, identifier:char; 169, call; 169, 170; 169, 171; 170, identifier:enumerate; 171, argument_list; 171, 172; 172, identifier:consensus; 173, block; 173, 174; 173, 180; 174, assert_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:char; 178, identifier:isupper; 179, argument_list; 180, for_statement; 180, 181; 180, 182; 180, 183; 181, identifier:rec; 182, identifier:rest; 183, block; 183, 184; 183, 190; 183, 198; 183, 275; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:rid; 187, subscript; 187, 188; 187, 189; 188, identifier:rec; 189, string:'id'; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:strposn; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:i; 195, subscript; 195, 196; 195, 197; 196, identifier:curr_shift; 197, identifier:rid; 198, if_statement; 198, 199; 198, 208; 198, 209; 198, 216; 198, 263; 199, call; 199, 200; 199, 207; 200, attribute; 200, 201; 200, 206; 201, subscript; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:rec; 204, string:'seq'; 205, identifier:strposn; 206, identifier:isupper; 207, argument_list; 208, comment; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, augmented_assignment:+=; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:curr_resn; 214, identifier:rid; 215, integer:1; 216, elif_clause; 216, 217; 216, 226; 216, 227; 217, call; 217, 218; 217, 225; 218, attribute; 218, 219; 218, 224; 219, subscript; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:rec; 222, string:'seq'; 223, identifier:strposn; 224, identifier:islower; 225, argument_list; 226, comment; 227, block; 227, 228; 227, 256; 227, 262; 228, while_statement; 228, 229; 228, 238; 228, 239; 229, call; 229, 230; 229, 237; 230, attribute; 230, 231; 230, 236; 231, subscript; 231, 232; 231, 235; 232, subscript; 232, 233; 232, 234; 233, identifier:rec; 234, string:'seq'; 235, identifier:strposn; 236, identifier:islower; 237, argument_list; 238, comment; 239, block; 239, 240; 239, 246; 239, 252; 240, expression_statement; 240, 241; 241, augmented_assignment:+=; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:curr_shift; 244, identifier:rid; 245, integer:1; 246, expression_statement; 246, 247; 247, augmented_assignment:+=; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:curr_resn; 250, identifier:rid; 251, integer:1; 252, expression_statement; 252, 253; 253, augmented_assignment:+=; 253, 254; 253, 255; 254, identifier:strposn; 255, integer:1; 256, expression_statement; 256, 257; 257, augmented_assignment:+=; 257, 258; 257, 261; 258, subscript; 258, 259; 258, 260; 259, identifier:curr_resn; 260, identifier:rid; 261, integer:1; 262, comment; 263, else_clause; 263, 264; 263, 265; 264, comment; 265, block; 265, 266; 265, 274; 266, assert_statement; 266, 267; 267, comparison_operator:in; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 272; 269, subscript; 269, 270; 269, 271; 270, identifier:rec; 271, string:'seq'; 272, identifier:strposn; 273, string:'.-'; 274, continue_statement; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 284; 277, subscript; 277, 278; 277, 283; 278, subscript; 278, 279; 278, 280; 279, identifier:equivalencies; 280, binary_operator:+; 280, 281; 280, 282; 281, identifier:i; 282, integer:1; 283, identifier:rid; 284, subscript; 284, 285; 284, 286; 285, identifier:curr_resn; 286, identifier:rid; 287, return_statement; 287, 288; 288, identifier:equivalencies | def get_equivalent_positions(block):
"""Create a mapping of equivalent residue positions to consensus.
Build a dict-of-dicts::
{consensus-posn: {id: equiv-posn, id: equiv-posn, ...}, ...}
The first sequence in the alignment is assumed to be the (gapless) consensus
sequence.
"""
consensus = block['sequences'][0]['seq']
rest = block['sequences'][1:]
# Validation
if '-' in consensus or '.' in consensus:
raise ValueError("First sequence (consensus?) contains gaps")
# Check for duplicate sequence IDs
seen = set()
dupes = set()
for rec in rest:
if rec['id'] in seen:
dupes.add(rec['id'])
else:
seen.add(rec['id'])
if dupes:
raise ValueError("Duplicate sequences:\n" + '\n'.join(dupes))
curr_shift = {}
curr_resn = {}
# NB: consensus doesn't have head/tail, but other sequences may
for rec in rest:
# Count inserts seen so far -- shift string indexes by this far ahead to
# get the "equivalent" location in the sequence string
# - as in, how far ahead in the current seq do we need to jump to get
# to a position equivalent to what's in the consensus?
# - can this ever be less than 0 (==consensus)? No, because that's
# where gaps come from. Good.
curr_shift[rec['id']] = 0
# Residue number in the actual sequence at the current (shifted)
# location
# curr_posn[id] = current equivalent res.num in `id` to cons[i]
curr_resn[rec['id']] = rec['head_len']
equivalencies = dict((i+1, {}) for i in xrange(len(consensus)))
# Map each character position i in the consensus sequence
# to equivalent residues in each of the other sequences
# i = index in the consensus string (== consensus res.num - 1)
for i, char in enumerate(consensus):
assert char.isupper()
for rec in rest:
rid = rec['id']
strposn = i + curr_shift[rid]
if rec['seq'][strposn].isupper():
# Match
curr_resn[rid] += 1
elif rec['seq'][strposn].islower():
# Insert
while rec['seq'][strposn].islower():
# Count the whole insert size
curr_shift[rid] += 1
curr_resn[rid] += 1
strposn += 1
curr_resn[rid] += 1 # Count the next match, too
else:
# Deletion / gap
assert rec['seq'][strposn] in '.-'
continue
equivalencies[i+1][rid] = curr_resn[rid]
return equivalencies |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:remove_path_segments; 3, parameters; 3, 4; 3, 5; 4, identifier:segments; 5, identifier:removes; 6, block; 6, 7; 6, 9; 6, 22; 6, 35; 6, 145; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 14; 10, comparison_operator:==; 10, 11; 10, 12; 11, identifier:segments; 12, list:['']; 12, 13; 13, string:''; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:segments; 19, identifier:append; 20, argument_list; 20, 21; 21, string:''; 22, if_statement; 22, 23; 22, 27; 23, comparison_operator:==; 23, 24; 23, 25; 24, identifier:removes; 25, list:['']; 25, 26; 26, string:''; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:removes; 32, identifier:append; 33, argument_list; 33, 34; 34, string:''; 35, if_statement; 35, 36; 35, 39; 35, 44; 35, 59; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:segments; 38, identifier:removes; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ret; 43, list:[]; 44, elif_clause; 44, 45; 44, 54; 45, comparison_operator:>; 45, 46; 45, 50; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, identifier:removes; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:segments; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:ret; 58, identifier:segments; 59, else_clause; 59, 60; 59, 61; 60, comment; 61, block; 61, 62; 61, 69; 61, 90; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:removes2; 65, call; 65, 66; 65, 67; 66, identifier:list; 67, argument_list; 67, 68; 68, identifier:removes; 69, if_statement; 69, 70; 69, 82; 70, boolean_operator:and; 70, 71; 70, 77; 71, comparison_operator:>; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:removes; 76, integer:1; 77, comparison_operator:==; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:removes; 80, integer:0; 81, string:''; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:removes2; 87, identifier:pop; 88, argument_list; 88, 89; 89, integer:0; 90, if_statement; 90, 91; 90, 106; 90, 139; 91, boolean_operator:and; 91, 92; 91, 93; 92, identifier:removes2; 93, comparison_operator:==; 93, 94; 93, 95; 94, identifier:removes2; 95, subscript; 95, 96; 95, 97; 96, identifier:segments; 97, slice; 97, 98; 97, 105; 98, binary_operator:*; 98, 99; 98, 101; 99, unary_operator:-; 99, 100; 100, integer:1; 101, call; 101, 102; 101, 103; 102, identifier:len; 103, argument_list; 103, 104; 104, identifier:removes2; 105, colon; 106, block; 106, 107; 106, 123; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:ret; 110, subscript; 110, 111; 110, 112; 111, identifier:segments; 112, slice; 112, 113; 112, 114; 113, colon; 114, binary_operator:-; 114, 115; 114, 119; 115, call; 115, 116; 115, 117; 116, identifier:len; 117, argument_list; 117, 118; 118, identifier:segments; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, identifier:removes2; 123, if_statement; 123, 124; 123, 131; 124, boolean_operator:and; 124, 125; 124, 130; 125, comparison_operator:!=; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:removes; 128, integer:0; 129, string:''; 130, identifier:ret; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:ret; 136, identifier:append; 137, argument_list; 137, 138; 138, string:''; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:ret; 144, identifier:segments; 145, return_statement; 145, 146; 146, identifier:ret | def remove_path_segments(segments, removes):
"""Removes the removes from the tail of segments.
Examples::
>>> # '/a/b/c' - 'b/c' == '/a/'
>>> assert remove_path_segments(['', 'a', 'b', 'c'], ['b', 'c']) == ['', 'a', '']
>>> # '/a/b/c' - '/b/c' == '/a
>>> assert remove_path_segments(['', 'a', 'b', 'c'], ['', 'b', 'c']) == ['', 'a']
:param segments: :class:`list`, a list of the path segment
:param removes: :class:`list`, a list of the path segment
:return: :class:`list`, The list of all remaining path segments after all segments
in ``removes`` have been removed from the end of ``segments``. If no segment
from ``removes`` were removed from the ``segments``, the ``segments`` is
return unmodified.
"""
if segments == ['']:
segments.append('')
if removes == ['']:
removes.append('')
if segments == removes:
ret = []
elif len(removes) > len(segments):
ret = segments
else:
# TODO(benjamin): incomplete
removes2 = list(removes)
if len(removes) > 1 and removes[0] == '':
removes2.pop(0)
if removes2 and removes2 == segments[-1 * len(removes2):]:
ret = segments[:len(segments) - len(removes2)]
if removes[0] != '' and ret:
ret.append('')
else:
ret = segments
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:error; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 11; 3, 14; 3, 15; 3, 18; 4, identifier:cls; 5, identifier:template; 6, comment; 7, default_parameter; 7, 8; 7, 9; 8, identifier:default_params; 9, dictionary; 10, comment; 11, default_parameter; 11, 12; 11, 13; 12, identifier:cause; 13, None; 14, comment; 15, default_parameter; 15, 16; 15, 17; 16, identifier:stack_depth; 17, integer:0; 18, dictionary_splat_pattern; 18, 19; 19, identifier:more_params; 20, block; 20, 21; 20, 23; 20, 49; 20, 71; 20, 83; 20, 87; 20, 168; 20, 179; 20, 197; 20, 220; 21, expression_statement; 21, 22; 22, comment; 23, if_statement; 23, 24; 23, 29; 24, not_operator; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:is_text; 27, argument_list; 27, 28; 28, identifier:template; 29, block; 29, 30; 29, 42; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:sys; 35, identifier:stderr; 36, identifier:write; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:str; 40, argument_list; 40, 41; 41, string:"Log.error was expecting a unicode template"; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:Log; 46, identifier:error; 47, argument_list; 47, 48; 48, string:"Log.error was expecting a unicode template"; 49, if_statement; 49, 50; 49, 62; 50, boolean_operator:and; 50, 51; 50, 52; 51, identifier:default_params; 52, call; 52, 53; 52, 54; 53, identifier:isinstance; 54, argument_list; 54, 55; 54, 61; 55, subscript; 55, 56; 55, 60; 56, call; 56, 57; 56, 58; 57, identifier:listwrap; 58, argument_list; 58, 59; 59, identifier:default_params; 60, integer:0; 61, identifier:BaseException; 62, block; 62, 63; 62, 67; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:cause; 66, identifier:default_params; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:default_params; 70, dictionary; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:params; 74, call; 74, 75; 74, 76; 75, identifier:Data; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:dict; 79, argument_list; 79, 80; 79, 81; 80, identifier:default_params; 81, dictionary_splat; 81, 82; 82, identifier:more_params; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:add_to_trace; 86, False; 87, if_statement; 87, 88; 87, 91; 87, 96; 87, 136; 87, 155; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:cause; 90, None; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:causes; 95, None; 96, elif_clause; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:is_list; 99, argument_list; 99, 100; 100, identifier:cause; 101, block; 101, 102; 101, 106; 101, 129; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:causes; 105, list:[]; 106, for_statement; 106, 107; 106, 108; 106, 112; 106, 113; 107, identifier:c; 108, call; 108, 109; 108, 110; 109, identifier:listwrap; 110, argument_list; 110, 111; 111, identifier:cause; 112, comment; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:causes; 118, identifier:append; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:Except; 123, identifier:wrap; 124, argument_list; 124, 125; 124, 126; 125, identifier:c; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:stack_depth; 128, integer:1; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:causes; 132, call; 132, 133; 132, 134; 133, identifier:FlatList; 134, argument_list; 134, 135; 135, identifier:causes; 136, elif_clause; 136, 137; 136, 142; 137, call; 137, 138; 137, 139; 138, identifier:isinstance; 139, argument_list; 139, 140; 139, 141; 140, identifier:cause; 141, identifier:BaseException; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:causes; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:Except; 149, identifier:wrap; 150, argument_list; 150, 151; 150, 152; 151, identifier:cause; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:stack_depth; 154, integer:1; 155, else_clause; 155, 156; 156, block; 156, 157; 156, 161; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:causes; 160, None; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:Log; 165, identifier:error; 166, argument_list; 166, 167; 167, string:"can only accept Exception, or list of exceptions"; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:trace; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:exceptions; 174, identifier:extract_stack; 175, argument_list; 175, 176; 176, binary_operator:+; 176, 177; 176, 178; 177, identifier:stack_depth; 178, integer:1; 179, if_statement; 179, 180; 179, 181; 180, identifier:add_to_trace; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 191; 184, attribute; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:cause; 188, integer:0; 189, identifier:trace; 190, identifier:extend; 191, argument_list; 191, 192; 192, subscript; 192, 193; 192, 194; 193, identifier:trace; 194, slice; 194, 195; 194, 196; 195, integer:1; 196, colon; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:e; 200, call; 200, 201; 200, 202; 201, identifier:Except; 202, argument_list; 202, 203; 202, 208; 202, 211; 202, 214; 202, 217; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:context; 205, attribute; 205, 206; 205, 207; 206, identifier:exceptions; 207, identifier:ERROR; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:template; 210, identifier:template; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:params; 213, identifier:params; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:cause; 216, identifier:causes; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:trace; 219, identifier:trace; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:raise_from_none; 223, argument_list; 223, 224; 224, identifier:e | def error(
cls,
template, # human readable template
default_params={}, # parameters for template
cause=None, # pausible cause
stack_depth=0,
**more_params
):
"""
raise an exception with a trace for the cause too
:param template: *string* human readable string with placeholders for parameters
:param default_params: *dict* parameters to fill in template
:param cause: *Exception* for chaining
:param stack_depth: *int* how many calls you want popped off the stack to report the *true* caller
:param log_context: *dict* extra key:value pairs for your convenience
:param more_params: *any more parameters (which will overwrite default_params)
:return:
"""
if not is_text(template):
sys.stderr.write(str("Log.error was expecting a unicode template"))
Log.error("Log.error was expecting a unicode template")
if default_params and isinstance(listwrap(default_params)[0], BaseException):
cause = default_params
default_params = {}
params = Data(dict(default_params, **more_params))
add_to_trace = False
if cause == None:
causes = None
elif is_list(cause):
causes = []
for c in listwrap(cause): # CAN NOT USE LIST-COMPREHENSION IN PYTHON3 (EXTRA STACK DEPTH FROM THE IN-LINED GENERATOR)
causes.append(Except.wrap(c, stack_depth=1))
causes = FlatList(causes)
elif isinstance(cause, BaseException):
causes = Except.wrap(cause, stack_depth=1)
else:
causes = None
Log.error("can only accept Exception, or list of exceptions")
trace = exceptions.extract_stack(stack_depth + 1)
if add_to_trace:
cause[0].trace.extend(trace[1:])
e = Except(context=exceptions.ERROR, template=template, params=params, cause=causes, trace=trace)
raise_from_none(e) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:summary_reporter; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:'Creating MOB-recon summary report'; 15, with_statement; 15, 16; 15, 36; 16, with_clause; 16, 17; 17, with_item; 17, 18; 18, as_pattern; 18, 19; 18, 34; 19, call; 19, 20; 19, 21; 20, identifier:open; 21, argument_list; 21, 22; 21, 33; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:path; 27, identifier:join; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:reportpath; 32, string:'mob_recon_summary.csv'; 33, string:'w'; 34, as_pattern_target; 34, 35; 35, identifier:summary; 36, block; 36, 37; 36, 43; 36, 193; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:data; 40, concatenated_string; 40, 41; 40, 42; 41, string:'Strain,Location,Contig,Incompatibility,IncompatibilityAccession,RelaxaseType,'; 42, string:'MashNearestNeighbor,MashNeighborDistance\n'; 43, for_statement; 43, 44; 43, 45; 43, 48; 43, 49; 44, identifier:sample; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:metadata; 48, comment; 49, block; 49, 50; 49, 62; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 59; 52, attribute; 52, 53; 52, 58; 53, subscript; 53, 54; 53, 55; 54, identifier:sample; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:analysistype; 58, identifier:pipelineresults; 59, call; 59, 60; 59, 61; 60, identifier:dict; 61, argument_list; 62, for_statement; 62, 63; 62, 66; 62, 77; 62, 78; 63, pattern_list; 63, 64; 63, 65; 64, identifier:primarykey; 65, identifier:results; 66, call; 66, 67; 66, 76; 67, attribute; 67, 68; 67, 75; 68, attribute; 68, 69; 68, 74; 69, subscript; 69, 70; 69, 71; 70, identifier:sample; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:analysistype; 74, identifier:report_dict; 75, identifier:items; 76, argument_list; 77, comment; 78, block; 78, 79; 79, if_statement; 79, 80; 79, 85; 80, comparison_operator:!=; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:results; 83, string:'cluster_id'; 84, string:'chromosome'; 85, block; 85, 86; 85, 146; 85, 150; 85, 151; 86, expression_statement; 86, 87; 87, augmented_assignment:+=; 87, 88; 87, 89; 88, identifier:data; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, string:','; 92, identifier:join; 93, generator_expression; 93, 94; 93, 112; 94, conditional_expression:if; 94, 95; 94, 105; 94, 111; 95, call; 95, 96; 95, 102; 96, attribute; 96, 97; 96, 101; 97, call; 97, 98; 97, 99; 98, identifier:str; 99, argument_list; 99, 100; 100, identifier:result; 101, identifier:replace; 102, argument_list; 102, 103; 102, 104; 103, string:','; 104, string:';'; 105, comparison_operator:!=; 105, 106; 105, 110; 106, call; 106, 107; 106, 108; 107, identifier:str; 108, argument_list; 108, 109; 109, identifier:result; 110, string:'nan'; 111, string:'ND'; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:result; 114, list:[
sample.name,
results['cluster_id'],
results['contig_id'].split('|')[1],
results['rep_type'],
results['rep_type_accession'],
results['relaxase_type'],
results['mash_nearest_neighbor'],
results['mash_neighbor_distance']]; 114, 115; 114, 118; 114, 121; 114, 131; 114, 134; 114, 137; 114, 140; 114, 143; 115, attribute; 115, 116; 115, 117; 116, identifier:sample; 117, identifier:name; 118, subscript; 118, 119; 118, 120; 119, identifier:results; 120, string:'cluster_id'; 121, subscript; 121, 122; 121, 130; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:results; 126, string:'contig_id'; 127, identifier:split; 128, argument_list; 128, 129; 129, string:'|'; 130, integer:1; 131, subscript; 131, 132; 131, 133; 132, identifier:results; 133, string:'rep_type'; 134, subscript; 134, 135; 134, 136; 135, identifier:results; 136, string:'rep_type_accession'; 137, subscript; 137, 138; 137, 139; 138, identifier:results; 139, string:'relaxase_type'; 140, subscript; 140, 141; 140, 142; 141, identifier:results; 142, string:'mash_nearest_neighbor'; 143, subscript; 143, 144; 143, 145; 144, identifier:results; 145, string:'mash_neighbor_distance'; 146, expression_statement; 146, 147; 147, augmented_assignment:+=; 147, 148; 147, 149; 148, identifier:data; 149, string:'\n'; 150, comment; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 164; 153, subscript; 153, 154; 153, 161; 154, attribute; 154, 155; 154, 160; 155, subscript; 155, 156; 155, 157; 156, identifier:sample; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:analysistype; 160, identifier:pipelineresults; 161, subscript; 161, 162; 161, 163; 162, identifier:results; 163, string:'cluster_id'; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, string:';'; 167, identifier:join; 168, generator_expression; 168, 169; 168, 187; 169, conditional_expression:if; 169, 170; 169, 180; 169, 186; 170, call; 170, 171; 170, 177; 171, attribute; 171, 172; 171, 176; 172, call; 172, 173; 172, 174; 173, identifier:str; 174, argument_list; 174, 175; 175, identifier:result; 176, identifier:replace; 177, argument_list; 177, 178; 177, 179; 178, string:','; 179, string:';'; 180, comparison_operator:!=; 180, 181; 180, 185; 181, call; 181, 182; 181, 183; 182, identifier:str; 183, argument_list; 183, 184; 184, identifier:result; 185, string:'nan'; 186, string:'ND'; 187, for_in_clause; 187, 188; 187, 189; 188, identifier:result; 189, list:[
results['rep_type']]; 189, 190; 190, subscript; 190, 191; 190, 192; 191, identifier:results; 192, string:'rep_type'; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:summary; 197, identifier:write; 198, argument_list; 198, 199; 199, identifier:data | def summary_reporter(self):
"""
Parse individual MOB Recon reports into a summary report
"""
logging.info('Creating MOB-recon summary report')
with open(os.path.join(self.reportpath, 'mob_recon_summary.csv'), 'w') as summary:
data = 'Strain,Location,Contig,Incompatibility,IncompatibilityAccession,RelaxaseType,' \
'MashNearestNeighbor,MashNeighborDistance\n'
for sample in self.metadata:
# Initialise a dictionary to store results for the COWBAT final report
sample[self.analysistype].pipelineresults = dict()
for primarykey, results in sample[self.analysistype].report_dict.items():
# Only process results if they are not calculated to be chromosomal
if results['cluster_id'] != 'chromosome':
data += ','.join(str(result).replace(',', ';') if str(result) != 'nan' else 'ND'
for result in [
sample.name,
results['cluster_id'],
results['contig_id'].split('|')[1],
results['rep_type'],
results['rep_type_accession'],
results['relaxase_type'],
results['mash_nearest_neighbor'],
results['mash_neighbor_distance']]
)
data += '\n'
# Add the calculated incompatibility to the pipeline results for use in the final COWBAT report
sample[self.analysistype].pipelineresults[results['cluster_id']] = \
';'.join(str(result).replace(',', ';') if str(result) != 'nan' else 'ND'
for result in [
results['rep_type']]
)
summary.write(data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:amrsummary; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:'Creating AMR summary table from ResFinder and MOB-recon outputs'; 15, with_statement; 15, 16; 15, 36; 16, with_clause; 16, 17; 17, with_item; 17, 18; 18, as_pattern; 18, 19; 18, 34; 19, call; 19, 20; 19, 21; 20, identifier:open; 21, argument_list; 21, 22; 21, 33; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:path; 27, identifier:join; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:reportpath; 32, string:'amr_summary.csv'; 33, string:'w'; 34, as_pattern_target; 34, 35; 35, identifier:amr; 36, block; 36, 37; 36, 41; 36, 324; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:data; 40, string:'Strain,Gene,Allele,Resistance,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\n'; 41, for_statement; 41, 42; 41, 43; 41, 46; 41, 47; 41, 48; 41, 49; 42, identifier:sample; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:metadata; 46, comment; 47, comment; 48, comment; 49, block; 49, 50; 49, 56; 49, 143; 49, 144; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:inc_dict; 53, call; 53, 54; 53, 55; 54, identifier:dict; 55, argument_list; 56, for_statement; 56, 57; 56, 60; 56, 71; 57, pattern_list; 57, 58; 57, 59; 58, identifier:primarykey; 59, identifier:results; 60, call; 60, 61; 60, 70; 61, attribute; 61, 62; 61, 69; 62, attribute; 62, 63; 62, 68; 63, subscript; 63, 64; 63, 65; 64, identifier:sample; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:analysistype; 68, identifier:report_dict; 69, identifier:items; 70, argument_list; 71, block; 71, 72; 72, try_statement; 72, 73; 72, 139; 73, block; 73, 74; 73, 80; 73, 81; 73, 82; 73, 107; 73, 108; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:inc; 77, subscript; 77, 78; 77, 79; 78, identifier:results; 79, string:'cluster_id'; 80, comment; 81, comment; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:rep; 85, conditional_expression:if; 85, 86; 85, 98; 85, 106; 86, call; 86, 87; 86, 95; 87, attribute; 87, 88; 87, 94; 88, call; 88, 89; 88, 90; 89, identifier:str; 90, argument_list; 90, 91; 91, subscript; 91, 92; 91, 93; 92, identifier:results; 93, string:'rep_type'; 94, identifier:replace; 95, argument_list; 95, 96; 95, 97; 96, string:','; 97, string:';'; 98, comparison_operator:!=; 98, 99; 98, 105; 99, call; 99, 100; 99, 101; 100, identifier:str; 101, argument_list; 101, 102; 102, subscript; 102, 103; 102, 104; 103, identifier:results; 104, string:'rep_type'; 105, string:'nan'; 106, string:'ND'; 107, comment; 108, try_statement; 108, 109; 108, 119; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:inc_dict; 115, identifier:inc; 116, identifier:add; 117, argument_list; 117, 118; 118, identifier:rep; 119, except_clause; 119, 120; 119, 121; 120, identifier:KeyError; 121, block; 121, 122; 121, 130; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:inc_dict; 126, identifier:inc; 127, call; 127, 128; 127, 129; 128, identifier:set; 129, argument_list; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:inc_dict; 135, identifier:inc; 136, identifier:add; 137, argument_list; 137, 138; 138, identifier:rep; 139, except_clause; 139, 140; 139, 141; 140, identifier:KeyError; 141, block; 141, 142; 142, pass_statement; 143, comment; 144, for_statement; 144, 145; 144, 148; 144, 159; 145, pattern_list; 145, 146; 145, 147; 146, identifier:primarykey; 147, identifier:results; 148, call; 148, 149; 148, 158; 149, attribute; 149, 150; 149, 157; 150, attribute; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 153; 152, identifier:sample; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:analysistype; 156, identifier:report_dict; 157, identifier:items; 158, argument_list; 159, block; 159, 160; 160, try_statement; 160, 161; 160, 320; 161, block; 161, 162; 161, 175; 161, 176; 161, 177; 161, 178; 161, 204; 161, 205; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:contig; 165, subscript; 165, 166; 165, 174; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:results; 170, string:'contig_id'; 171, identifier:split; 172, argument_list; 172, 173; 173, string:'|'; 174, integer:1; 175, comment; 176, comment; 177, comment; 178, if_statement; 178, 179; 178, 192; 179, call; 179, 180; 179, 190; 180, attribute; 180, 181; 180, 189; 181, subscript; 181, 182; 181, 188; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:contig; 185, identifier:split; 186, argument_list; 186, 187; 187, string:'_'; 188, integer:1; 189, identifier:startswith; 190, argument_list; 190, 191; 191, string:'length'; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:contig; 196, subscript; 196, 197; 196, 203; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:contig; 200, identifier:split; 201, argument_list; 201, 202; 202, string:'_'; 203, integer:0; 204, comment; 205, for_statement; 205, 206; 205, 207; 205, 212; 205, 213; 205, 214; 205, 215; 206, identifier:amr_result; 207, attribute; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:sample; 210, identifier:resfinder_assembled; 211, identifier:sampledata; 212, comment; 213, comment; 214, comment; 215, block; 215, 216; 216, if_statement; 216, 217; 216, 226; 216, 227; 217, comparison_operator:==; 217, 218; 217, 219; 218, identifier:contig; 219, call; 219, 220; 219, 221; 220, identifier:str; 221, argument_list; 221, 222; 222, subscript; 222, 223; 222, 224; 223, identifier:amr_result; 224, unary_operator:-; 224, 225; 225, integer:1; 226, comment; 227, block; 227, 228; 227, 241; 227, 242; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 231; 230, identifier:data; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, string:'{sn},'; 234, identifier:format; 235, argument_list; 235, 236; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:sn; 238, attribute; 238, 239; 238, 240; 239, identifier:sample; 240, identifier:name; 241, comment; 242, expression_statement; 242, 243; 243, augmented_assignment:+=; 243, 244; 243, 245; 244, identifier:data; 245, call; 245, 246; 245, 250; 246, attribute; 246, 247; 246, 248; 246, 249; 247, string:'{amr},{mob}\n'; 248, line_continuation:\; 249, identifier:format; 250, argument_list; 250, 251; 250, 278; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:amr; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, string:','; 256, identifier:join; 257, generator_expression; 257, 258; 257, 270; 258, conditional_expression:if; 258, 259; 258, 263; 258, 269; 259, call; 259, 260; 259, 261; 260, identifier:str; 261, argument_list; 261, 262; 262, identifier:res; 263, comparison_operator:!=; 263, 264; 263, 268; 264, call; 264, 265; 264, 266; 265, identifier:str; 266, argument_list; 266, 267; 267, identifier:res; 268, string:'nan'; 269, string:'ND'; 270, for_in_clause; 270, 271; 270, 272; 271, identifier:res; 272, subscript; 272, 273; 272, 274; 273, identifier:amr_result; 274, slice; 274, 275; 274, 276; 274, 277; 275, integer:0; 276, colon; 277, integer:4; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:mob; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, string:','; 283, identifier:join; 284, generator_expression; 284, 285; 284, 297; 285, conditional_expression:if; 285, 286; 285, 290; 285, 296; 286, call; 286, 287; 286, 288; 287, identifier:str; 288, argument_list; 288, 289; 289, identifier:res; 290, comparison_operator:!=; 290, 291; 290, 295; 291, call; 291, 292; 291, 293; 292, identifier:str; 293, argument_list; 293, 294; 294, identifier:res; 295, string:'nan'; 296, string:'ND'; 297, for_in_clause; 297, 298; 297, 299; 298, identifier:res; 299, list:[contig, results['cluster_id'],
';'.join(sorted(inc_dict[str(results['cluster_id'])]))
]; 299, 300; 299, 301; 299, 304; 300, identifier:contig; 301, subscript; 301, 302; 301, 303; 302, identifier:results; 303, string:'cluster_id'; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, string:';'; 307, identifier:join; 308, argument_list; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:sorted; 311, argument_list; 311, 312; 312, subscript; 312, 313; 312, 314; 313, identifier:inc_dict; 314, call; 314, 315; 314, 316; 315, identifier:str; 316, argument_list; 316, 317; 317, subscript; 317, 318; 317, 319; 318, identifier:results; 319, string:'cluster_id'; 320, except_clause; 320, 321; 320, 322; 321, identifier:KeyError; 322, block; 322, 323; 323, pass_statement; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:amr; 328, identifier:write; 329, argument_list; 329, 330; 330, identifier:data | def amrsummary(self):
"""
Create a report combining results from resfinder_assembled and mob_recon_summary reports
"""
logging.info('Creating AMR summary table from ResFinder and MOB-recon outputs')
with open(os.path.join(self.reportpath, 'amr_summary.csv'), 'w') as amr:
data = 'Strain,Gene,Allele,Resistance,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\n'
for sample in self.metadata:
# Initialise a dictionary to store a set of all the incompatibility types listed for a contig.
# As the inc type will only be located on one of possibly several contigs associated with a predicted
# plasmid, it is nice to know details about the plasmid
inc_dict = dict()
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
inc = results['cluster_id']
# Convert the rep_type field (predicted incompatibilities) into a more a consistent
# format - pandas will call empty fields 'nan', which is a float
rep = str(results['rep_type']).replace(',', ';') if str(results['rep_type']) != 'nan' else 'ND'
# Add the incompatibility to the set
try:
inc_dict[inc].add(rep)
except KeyError:
inc_dict[inc] = set()
inc_dict[inc].add(rep)
except KeyError:
pass
#
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
contig = results['contig_id'].split('|')[1]
# Unicycler gives contigs names such as: 3_length=187116_depth=1.60x_circular=true - test
# to see if the contig name looks unicycler-like, and set the name appropriately (in this
# case, it would be 3)
if contig.split('_')[1].startswith('length'):
contig = contig.split('_')[0]
# Use the list of results from the resfinder analyses
for amr_result in sample.resfinder_assembled.sampledata:
# Ensure that the current contig is the same as the one in the resfinder results. Ensure
# that the slice of the amr result is treated as a string. Unicycler contigs seem to be
# treated as integers
if contig == str(amr_result[-1]):
# Set up the output string
data += '{sn},'.format(sn=sample.name)
# Add the resistance and MOB recon outputs for the strain
data += '{amr},{mob}\n'\
.format(amr=','.join(str(res) if str(res) != 'nan' else 'ND' for res in
amr_result[0:4]),
mob=','.join(str(res) if str(res) != 'nan' else 'ND' for res in
[contig, results['cluster_id'],
';'.join(sorted(inc_dict[str(results['cluster_id'])]))
]
)
)
except KeyError:
pass
amr.write(data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:geneseekrsummary; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:'Creating predicted plasmid-borne gene summary table'; 15, with_statement; 15, 16; 15, 36; 16, with_clause; 16, 17; 17, with_item; 17, 18; 18, as_pattern; 18, 19; 18, 34; 19, call; 19, 20; 19, 21; 20, identifier:open; 21, argument_list; 21, 22; 21, 33; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:os; 26, identifier:path; 27, identifier:join; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:reportpath; 32, string:'plasmid_borne_summary.csv'; 33, string:'w'; 34, as_pattern_target; 34, 35; 35, identifier:pbs; 36, block; 36, 37; 36, 41; 36, 332; 36, 333; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:data; 40, string:'Strain,Gene,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\n'; 41, for_statement; 41, 42; 41, 43; 41, 46; 41, 47; 41, 48; 42, identifier:sample; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:metadata; 46, comment; 47, comment; 48, block; 48, 49; 48, 53; 48, 54; 48, 55; 48, 56; 48, 62; 48, 63; 48, 150; 48, 314; 48, 315; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:result_bool; 52, False; 53, comment; 54, comment; 55, comment; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:inc_dict; 59, call; 59, 60; 59, 61; 60, identifier:dict; 61, argument_list; 62, comment; 63, for_statement; 63, 64; 63, 67; 63, 78; 64, pattern_list; 64, 65; 64, 66; 65, identifier:primarykey; 66, identifier:results; 67, call; 67, 68; 67, 77; 68, attribute; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 72; 71, identifier:sample; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:analysistype; 75, identifier:report_dict; 76, identifier:items; 77, argument_list; 78, block; 78, 79; 79, try_statement; 79, 80; 79, 146; 80, block; 80, 81; 80, 87; 80, 88; 80, 89; 80, 114; 80, 115; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:inc; 84, subscript; 84, 85; 84, 86; 85, identifier:results; 86, string:'cluster_id'; 87, comment; 88, comment; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:rep; 92, conditional_expression:if; 92, 93; 92, 105; 92, 113; 93, call; 93, 94; 93, 102; 94, attribute; 94, 95; 94, 101; 95, call; 95, 96; 95, 97; 96, identifier:str; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 100; 99, identifier:results; 100, string:'rep_type'; 101, identifier:replace; 102, argument_list; 102, 103; 102, 104; 103, string:','; 104, string:';'; 105, comparison_operator:!=; 105, 106; 105, 112; 106, call; 106, 107; 106, 108; 107, identifier:str; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 111; 110, identifier:results; 111, string:'rep_type'; 112, string:'nan'; 113, string:'ND'; 114, comment; 115, try_statement; 115, 116; 115, 126; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:inc_dict; 122, identifier:inc; 123, identifier:add; 124, argument_list; 124, 125; 125, identifier:rep; 126, except_clause; 126, 127; 126, 128; 127, identifier:KeyError; 128, block; 128, 129; 128, 137; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:inc_dict; 133, identifier:inc; 134, call; 134, 135; 134, 136; 135, identifier:set; 136, argument_list; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:inc_dict; 142, identifier:inc; 143, identifier:add; 144, argument_list; 144, 145; 145, identifier:rep; 146, except_clause; 146, 147; 146, 148; 147, identifier:KeyError; 148, block; 148, 149; 149, pass_statement; 150, for_statement; 150, 151; 150, 154; 150, 165; 151, pattern_list; 151, 152; 151, 153; 152, identifier:primarykey; 153, identifier:results; 154, call; 154, 155; 154, 164; 155, attribute; 155, 156; 155, 163; 156, attribute; 156, 157; 156, 162; 157, subscript; 157, 158; 157, 159; 158, identifier:sample; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:analysistype; 162, identifier:report_dict; 163, identifier:items; 164, argument_list; 165, block; 165, 166; 166, try_statement; 166, 167; 166, 310; 167, block; 167, 168; 167, 181; 167, 182; 167, 183; 167, 184; 167, 210; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:contig; 171, subscript; 171, 172; 171, 180; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, subscript; 174, 175; 174, 176; 175, identifier:results; 176, string:'contig_id'; 177, identifier:split; 178, argument_list; 178, 179; 179, string:'|'; 180, integer:1; 181, comment; 182, comment; 183, comment; 184, if_statement; 184, 185; 184, 198; 185, call; 185, 186; 185, 196; 186, attribute; 186, 187; 186, 195; 187, subscript; 187, 188; 187, 194; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:contig; 191, identifier:split; 192, argument_list; 192, 193; 193, string:'_'; 194, integer:1; 195, identifier:startswith; 196, argument_list; 196, 197; 197, string:'length'; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:contig; 202, subscript; 202, 203; 202, 209; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:contig; 206, identifier:split; 207, argument_list; 207, 208; 208, string:'_'; 209, integer:0; 210, for_statement; 210, 211; 210, 214; 210, 223; 211, pattern_list; 211, 212; 211, 213; 212, identifier:gene; 213, identifier:result_dict; 214, call; 214, 215; 214, 222; 215, attribute; 215, 216; 215, 221; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:sample; 219, identifier:geneseekr_results; 220, identifier:sampledata; 221, identifier:items; 222, argument_list; 223, block; 223, 224; 224, if_statement; 224, 225; 224, 230; 225, comparison_operator:==; 225, 226; 225, 227; 226, identifier:contig; 227, subscript; 227, 228; 227, 229; 228, identifier:result_dict; 229, string:'query_id'; 230, block; 230, 231; 230, 237; 230, 238; 230, 239; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:percent_identity; 234, subscript; 234, 235; 234, 236; 235, identifier:result_dict; 236, string:'PercentIdentity'; 237, comment; 238, comment; 239, if_statement; 239, 240; 239, 250; 239, 251; 240, comparison_operator:>=; 240, 241; 240, 247; 241, call; 241, 242; 241, 243; 242, identifier:float; 243, argument_list; 243, 244; 244, subscript; 244, 245; 244, 246; 245, identifier:result_dict; 246, string:'PercentIdentity'; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:cutoff; 250, comment; 251, block; 251, 252; 251, 256; 251, 269; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:result_bool; 255, True; 256, expression_statement; 256, 257; 257, augmented_assignment:+=; 257, 258; 257, 259; 258, identifier:data; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, string:'{sn},'; 262, identifier:format; 263, argument_list; 263, 264; 264, keyword_argument; 264, 265; 264, 266; 265, identifier:sn; 266, attribute; 266, 267; 266, 268; 267, identifier:sample; 268, identifier:name; 269, expression_statement; 269, 270; 270, augmented_assignment:+=; 270, 271; 270, 272; 271, identifier:data; 272, call; 272, 273; 272, 277; 273, attribute; 273, 274; 273, 275; 273, 276; 274, string:'{gene},{pi},{contig},{cid},{inc}\n'; 275, line_continuation:\; 276, identifier:format; 277, argument_list; 277, 278; 277, 281; 277, 284; 277, 287; 277, 292; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:gene; 280, identifier:gene; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:pi; 283, identifier:percent_identity; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:contig; 286, identifier:contig; 287, keyword_argument; 287, 288; 287, 289; 288, identifier:cid; 289, subscript; 289, 290; 289, 291; 290, identifier:results; 291, string:'cluster_id'; 292, keyword_argument; 292, 293; 292, 294; 293, identifier:inc; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, string:';'; 297, identifier:join; 298, argument_list; 298, 299; 299, call; 299, 300; 299, 301; 300, identifier:sorted; 301, argument_list; 301, 302; 302, subscript; 302, 303; 302, 304; 303, identifier:inc_dict; 304, call; 304, 305; 304, 306; 305, identifier:str; 306, argument_list; 306, 307; 307, subscript; 307, 308; 307, 309; 308, identifier:results; 309, string:'cluster_id'; 310, except_clause; 310, 311; 310, 312; 311, identifier:KeyError; 312, block; 312, 313; 313, pass_statement; 314, comment; 315, if_statement; 315, 316; 315, 318; 316, not_operator; 316, 317; 317, identifier:result_bool; 318, block; 318, 319; 319, expression_statement; 319, 320; 320, augmented_assignment:+=; 320, 321; 320, 322; 321, identifier:data; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, string:'{sn}\n'; 325, identifier:format; 326, argument_list; 326, 327; 327, keyword_argument; 327, 328; 327, 329; 328, identifier:sn; 329, attribute; 329, 330; 329, 331; 330, identifier:sample; 331, identifier:name; 332, comment; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:pbs; 337, identifier:write; 338, argument_list; 338, 339; 339, identifier:data | def geneseekrsummary(self):
"""
Create a report combining GeneSeekr and MOB Recon outputs
"""
logging.info('Creating predicted plasmid-borne gene summary table')
with open(os.path.join(self.reportpath, 'plasmid_borne_summary.csv'), 'w') as pbs:
data = 'Strain,Gene,PercentIdentity,Contig,Location,PlasmidIncompatibilitySets\n'
for sample in self.metadata:
# Create a flag to determine whether the strain name needs to be added to the data string if there
# were no results
result_bool = False
# Initialise a dictionary to store a set of all the incompatibility types listed for a contig.
# As the inc type will only be located on one of possibly several contigs associated with a predicted
# plasmid, it is nice to know details about the plasmid
inc_dict = dict()
# Iterate through all the MOB recon outputs to populate the incompatibility set
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
inc = results['cluster_id']
# Convert the rep_type field (predicted incompatibilities) into a more a consistent
# format - pandas will call empty fields 'nan', which is a float
rep = str(results['rep_type']).replace(',', ';') if str(results['rep_type']) != 'nan' else 'ND'
# Add the incompatibility to the set
try:
inc_dict[inc].add(rep)
except KeyError:
inc_dict[inc] = set()
inc_dict[inc].add(rep)
except KeyError:
pass
for primarykey, results in sample[self.analysistype].report_dict.items():
try:
contig = results['contig_id'].split('|')[1]
# Unicycler gives contigs names such as: 3_length=187116_depth=1.60x_circular=true - test
# to see if the contig name looks unicycler-like, and set the name appropriately (in this
# case, it would be 3)
if contig.split('_')[1].startswith('length'):
contig = contig.split('_')[0]
for gene, result_dict in sample.geneseekr_results.sampledata.items():
if contig == result_dict['query_id']:
percent_identity = result_dict['PercentIdentity']
# Set up the output string if the percent identity of the match is greater than the
# cutoff
if float(result_dict['PercentIdentity']) >= self.cutoff:
# As there was at least a single gene passing the threshold, set the boolean to True
result_bool = True
data += '{sn},'.format(sn=sample.name)
data += '{gene},{pi},{contig},{cid},{inc}\n'\
.format(gene=gene,
pi=percent_identity,
contig=contig,
cid=results['cluster_id'],
inc=';'.join(sorted(inc_dict[str(results['cluster_id'])])))
except KeyError:
pass
# If there were no results associated with the strain, make the row the strain name only
if not result_bool:
data += '{sn}\n'.format(sn=sample.name)
# Write the string to the report
pbs.write(data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:filterunique; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, for_statement; 8, 9; 8, 10; 8, 13; 8, 14; 9, identifier:sample; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:metadata; 13, comment; 14, block; 14, 15; 14, 27; 14, 33; 14, 39; 14, 296; 14, 297; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 24; 17, attribute; 17, 18; 17, 23; 18, subscript; 18, 19; 18, 20; 19, identifier:sample; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:analysistype; 23, identifier:blastresults; 24, call; 24, 25; 24, 26; 25, identifier:list; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:resultdict; 30, call; 30, 31; 30, 32; 31, identifier:dict; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:rowdict; 36, call; 36, 37; 36, 38; 37, identifier:dict; 38, argument_list; 39, try_statement; 39, 40; 39, 41; 39, 292; 40, comment; 41, block; 41, 42; 42, for_statement; 42, 43; 42, 44; 42, 51; 42, 52; 43, identifier:contig; 44, attribute; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 47; 46, identifier:sample; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:analysistype; 50, identifier:queryranges; 51, comment; 52, block; 52, 53; 53, for_statement; 53, 54; 53, 55; 53, 64; 53, 65; 54, identifier:location; 55, subscript; 55, 56; 55, 63; 56, attribute; 56, 57; 56, 62; 57, subscript; 57, 58; 57, 59; 58, identifier:sample; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:analysistype; 62, identifier:queryranges; 63, identifier:contig; 64, comment; 65, block; 65, 66; 66, for_statement; 66, 67; 66, 68; 66, 77; 66, 78; 67, identifier:row; 68, subscript; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 72; 71, identifier:sample; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:analysistype; 75, identifier:results; 76, identifier:contig; 77, comment; 78, block; 78, 79; 78, 85; 78, 91; 78, 97; 78, 103; 78, 104; 78, 120; 78, 121; 78, 122; 78, 123; 78, 124; 78, 125; 78, 136; 78, 137; 78, 138; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:contig; 82, subscript; 82, 83; 82, 84; 83, identifier:row; 84, string:'query_id'; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:high; 88, subscript; 88, 89; 88, 90; 89, identifier:row; 90, string:'high'; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:low; 94, subscript; 94, 95; 94, 96; 95, identifier:row; 96, string:'low'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:percentidentity; 100, subscript; 100, 101; 100, 102; 101, identifier:row; 102, string:'percentidentity'; 103, comment; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:locstr; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:','; 110, identifier:join; 111, argument_list; 111, 112; 112, list_comprehension; 112, 113; 112, 117; 113, call; 113, 114; 113, 115; 114, identifier:str; 115, argument_list; 115, 116; 116, identifier:x; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:x; 119, identifier:location; 120, comment; 121, comment; 122, comment; 123, comment; 124, comment; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:loc; 128, call; 128, 129; 128, 130; 129, identifier:set; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 133; 132, identifier:range; 133, argument_list; 133, 134; 133, 135; 134, identifier:low; 135, identifier:high; 136, comment; 137, comment; 138, if_statement; 138, 139; 138, 156; 138, 157; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:loc; 142, identifier:intersection; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:set; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:range; 149, argument_list; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:location; 152, integer:0; 153, subscript; 153, 154; 153, 155; 154, identifier:location; 155, integer:1; 156, comment; 157, block; 157, 158; 158, try_statement; 158, 159; 158, 182; 158, 183; 159, block; 159, 160; 159, 171; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 169; 162, attribute; 162, 163; 162, 168; 163, subscript; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:resultdict; 166, identifier:contig; 167, identifier:locstr; 168, identifier:append; 169, argument_list; 169, 170; 170, identifier:percentidentity; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 180; 173, attribute; 173, 174; 173, 179; 174, subscript; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:rowdict; 177, identifier:contig; 178, identifier:locstr; 179, identifier:append; 180, argument_list; 180, 181; 181, identifier:row; 182, comment; 183, except_clause; 183, 184; 183, 185; 184, identifier:KeyError; 185, block; 185, 186; 186, try_statement; 186, 187; 186, 230; 186, 231; 187, block; 187, 188; 187, 198; 187, 209; 187, 219; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 195; 190, subscript; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:resultdict; 193, identifier:contig; 194, identifier:locstr; 195, call; 195, 196; 195, 197; 196, identifier:list; 197, argument_list; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 207; 200, attribute; 200, 201; 200, 206; 201, subscript; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:resultdict; 204, identifier:contig; 205, identifier:locstr; 206, identifier:append; 207, argument_list; 207, 208; 208, identifier:percentidentity; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 216; 211, subscript; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:rowdict; 214, identifier:contig; 215, identifier:locstr; 216, call; 216, 217; 216, 218; 217, identifier:list; 218, argument_list; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 228; 221, attribute; 221, 222; 221, 227; 222, subscript; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:rowdict; 225, identifier:contig; 226, identifier:locstr; 227, identifier:append; 228, argument_list; 228, 229; 229, identifier:row; 230, comment; 231, except_clause; 231, 232; 231, 233; 232, identifier:KeyError; 233, block; 233, 234; 233, 242; 233, 252; 233, 263; 233, 271; 233, 281; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:resultdict; 238, identifier:contig; 239, call; 239, 240; 239, 241; 240, identifier:dict; 241, argument_list; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 249; 244, subscript; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:resultdict; 247, identifier:contig; 248, identifier:locstr; 249, call; 249, 250; 249, 251; 250, identifier:list; 251, argument_list; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 261; 254, attribute; 254, 255; 254, 260; 255, subscript; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:resultdict; 258, identifier:contig; 259, identifier:locstr; 260, identifier:append; 261, argument_list; 261, 262; 262, identifier:percentidentity; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:rowdict; 267, identifier:contig; 268, call; 268, 269; 268, 270; 269, identifier:dict; 270, argument_list; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 278; 273, subscript; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:rowdict; 276, identifier:contig; 277, identifier:locstr; 278, call; 278, 279; 278, 280; 279, identifier:list; 280, argument_list; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 290; 283, attribute; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 288; 285, subscript; 285, 286; 285, 287; 286, identifier:rowdict; 287, identifier:contig; 288, identifier:locstr; 289, identifier:append; 290, argument_list; 290, 291; 291, identifier:row; 292, except_clause; 292, 293; 292, 294; 293, identifier:KeyError; 294, block; 294, 295; 295, pass_statement; 296, comment; 297, for_statement; 297, 298; 297, 299; 297, 300; 297, 301; 298, identifier:contig; 299, identifier:resultdict; 300, comment; 301, block; 301, 302; 301, 308; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:genes; 305, call; 305, 306; 305, 307; 306, identifier:list; 307, argument_list; 308, for_statement; 308, 309; 308, 310; 308, 313; 308, 314; 309, identifier:location; 310, subscript; 310, 311; 310, 312; 311, identifier:resultdict; 312, identifier:contig; 313, comment; 314, block; 314, 315; 314, 319; 314, 320; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:multiple; 318, False; 319, comment; 320, for_statement; 320, 321; 320, 322; 320, 327; 320, 328; 321, identifier:row; 322, subscript; 322, 323; 322, 326; 323, subscript; 323, 324; 323, 325; 324, identifier:rowdict; 325, identifier:contig; 326, identifier:location; 327, comment; 328, block; 328, 329; 329, if_statement; 329, 330; 329, 352; 330, boolean_operator:and; 330, 331; 330, 346; 330, 347; 331, boolean_operator:and; 331, 332; 331, 344; 332, comparison_operator:==; 332, 333; 332, 336; 333, subscript; 333, 334; 333, 335; 334, identifier:row; 335, string:'percentidentity'; 336, call; 336, 337; 336, 338; 337, identifier:max; 338, argument_list; 338, 339; 339, subscript; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:resultdict; 342, identifier:contig; 343, identifier:location; 344, not_operator; 344, 345; 345, identifier:multiple; 346, line_continuation:\; 347, comparison_operator:not; 347, 348; 347, 351; 348, subscript; 348, 349; 348, 350; 349, identifier:row; 350, string:'subject_id'; 351, identifier:genes; 352, block; 352, 353; 352, 366; 352, 375; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 364; 355, attribute; 355, 356; 355, 363; 356, attribute; 356, 357; 356, 362; 357, subscript; 357, 358; 357, 359; 358, identifier:sample; 359, attribute; 359, 360; 359, 361; 360, identifier:self; 361, identifier:analysistype; 362, identifier:blastresults; 363, identifier:append; 364, argument_list; 364, 365; 365, identifier:row; 366, expression_statement; 366, 367; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:genes; 370, identifier:append; 371, argument_list; 371, 372; 372, subscript; 372, 373; 372, 374; 373, identifier:row; 374, string:'subject_id'; 375, expression_statement; 375, 376; 376, assignment; 376, 377; 376, 378; 377, identifier:multiple; 378, True | def filterunique(self):
"""
Filters multiple BLAST hits in a common region of the genome. Leaves only the best hit
"""
for sample in self.metadata:
# Initialise variables
sample[self.analysistype].blastresults = list()
resultdict = dict()
rowdict = dict()
try:
# Iterate through all the contigs, which had BLAST hits
for contig in sample[self.analysistype].queryranges:
# Find all the locations in each contig that correspond to the BLAST hits
for location in sample[self.analysistype].queryranges[contig]:
# Extract the BLAST result dictionary for the contig
for row in sample[self.analysistype].results[contig]:
# Initialise variable to reduce the number of times row['value'] needs to be typed
contig = row['query_id']
high = row['high']
low = row['low']
percentidentity = row['percentidentity']
# Join the two ranges in the location list with a comma
locstr = ','.join([str(x) for x in location])
# Create a set of the location of all the base pairs between the low and high (-1) e.g.
# [6, 10] would give 6, 7, 8, 9, but NOT 10. This turns out to be useful, as there are
# genes located back-to-back in the genome e.g. strB and strA, with locations of 2557,3393
# and 3393,4196, respectively. By not including 3393 in the strB calculations, I don't
# have to worry about this single bp overlap
loc = set(range(low, high))
# Use a set intersection to determine whether the current result overlaps with location
# This will allow all the hits to be grouped together based on their location
if loc.intersection(set(range(location[0], location[1]))):
# Populate the grouped hits for each location
try:
resultdict[contig][locstr].append(percentidentity)
rowdict[contig][locstr].append(row)
# Initialise and populate the lists of the nested dictionary
except KeyError:
try:
resultdict[contig][locstr] = list()
resultdict[contig][locstr].append(percentidentity)
rowdict[contig][locstr] = list()
rowdict[contig][locstr].append(row)
# As this is a nested dictionary, it needs to be initialised here
except KeyError:
resultdict[contig] = dict()
resultdict[contig][locstr] = list()
resultdict[contig][locstr].append(percentidentity)
rowdict[contig] = dict()
rowdict[contig][locstr] = list()
rowdict[contig][locstr].append(row)
except KeyError:
pass
# Find the best hit for each location based on percent identity
for contig in resultdict:
# Do not allow the same gene to be added to the dictionary more than once
genes = list()
for location in resultdict[contig]:
# Initialise a variable to determine whether there is already a best hit found for the location
multiple = False
# Iterate through the BLAST results to find the best hit
for row in rowdict[contig][location]:
# Add the best hit to the .blastresults attribute of the object
if row['percentidentity'] == max(resultdict[contig][location]) and not multiple \
and row['subject_id'] not in genes:
sample[self.analysistype].blastresults.append(row)
genes.append(row['subject_id'])
multiple = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:makedbthreads; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 41; 5, 42; 5, 84; 5, 85; 5, 175; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 14; 10, identifier:sample; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:metadata; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 25; 16, comparison_operator:!=; 16, 17; 16, 24; 17, attribute; 17, 18; 17, 23; 18, subscript; 18, 19; 18, 20; 19, identifier:sample; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:analysistype; 23, identifier:combinedtargets; 24, string:'NA'; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:targetfolders; 32, identifier:add; 33, argument_list; 33, 34; 34, attribute; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 37; 36, identifier:sample; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:analysistype; 40, identifier:targetpath; 41, comment; 42, for_statement; 42, 43; 42, 44; 42, 53; 42, 54; 43, identifier:i; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:targetfolders; 53, comment; 54, block; 54, 55; 54, 69; 54, 70; 54, 77; 54, 78; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:threads; 58, call; 58, 59; 58, 60; 59, identifier:Thread; 60, argument_list; 60, 61; 60, 66; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:target; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:makeblastdb; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:args; 68, tuple; 69, comment; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:threads; 74, identifier:setDaemon; 75, argument_list; 75, 76; 76, True; 77, comment; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:threads; 82, identifier:start; 83, argument_list; 84, comment; 85, for_statement; 85, 86; 85, 87; 85, 90; 85, 91; 86, identifier:targetdir; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:targetfolders; 90, comment; 91, block; 91, 92; 91, 109; 91, 139; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:targetfiles; 97, call; 97, 98; 97, 99; 98, identifier:glob; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:path; 105, identifier:join; 106, argument_list; 106, 107; 106, 108; 107, identifier:targetdir; 108, string:'*.fasta'; 109, try_statement; 109, 110; 109, 119; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:_; 114, subscript; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:targetfiles; 118, integer:0; 119, except_clause; 119, 120; 119, 121; 120, identifier:IndexError; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:targetfiles; 127, call; 127, 128; 127, 129; 128, identifier:glob; 129, argument_list; 129, 130; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:os; 134, identifier:path; 135, identifier:join; 136, argument_list; 136, 137; 136, 138; 137, identifier:targetdir; 138, string:'*.fasta'; 139, for_statement; 139, 140; 139, 141; 139, 144; 139, 145; 140, identifier:targetfile; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:targetfiles; 144, comment; 145, block; 145, 146; 145, 165; 145, 166; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 153; 148, subscript; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:records; 152, identifier:targetfile; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:SeqIO; 156, identifier:to_dict; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:SeqIO; 161, identifier:parse; 162, argument_list; 162, 163; 162, 164; 163, identifier:targetfile; 164, string:'fasta'; 165, comment; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:dqueue; 172, identifier:put; 173, argument_list; 173, 174; 174, identifier:targetfile; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:dqueue; 181, identifier:join; 182, argument_list | def makedbthreads(self):
"""
Setup and create threads for class
"""
# Find all the target folders in the analysis and add them to the targetfolders set
for sample in self.metadata:
if sample[self.analysistype].combinedtargets != 'NA':
self.targetfolders.add(sample[self.analysistype].targetpath)
# Create and start threads for each fasta file in the list
for i in range(len(self.targetfolders)):
# Send the threads to makeblastdb
threads = Thread(target=self.makeblastdb, args=())
# Set the daemon to true - something to do with thread management
threads.setDaemon(True)
# Start the threading
threads.start()
# Make blast databases for MLST files (if necessary)
for targetdir in self.targetfolders:
# List comprehension to remove any previously created database files from list
self.targetfiles = glob(os.path.join(targetdir, '*.fasta'))
try:
_ = self.targetfiles[0]
except IndexError:
self.targetfiles = glob(os.path.join(targetdir, '*.fasta'))
for targetfile in self.targetfiles:
# Read the sequences from the target file to a dictionary
self.records[targetfile] = SeqIO.to_dict(SeqIO.parse(targetfile, 'fasta'))
# Add the fasta file to the queue
self.dqueue.put(targetfile)
self.dqueue.join() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:cowbat; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 51; 5, 87; 5, 118; 5, 154; 5, 190; 5, 231; 5, 267; 5, 309; 5, 351; 5, 393; 5, 435; 5, 471; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logging; 12, identifier:info; 13, argument_list; 13, 14; 14, string:'Beginning COWBAT database downloads'; 15, if_statement; 15, 16; 15, 39; 16, boolean_operator:or; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:overwrite; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:os; 25, identifier:path; 26, identifier:isdir; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:os; 32, identifier:path; 33, identifier:join; 34, argument_list; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:databasepath; 38, string:'genesippr'; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:sipprverse_targets; 45, argument_list; 45, 46; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:databasepath; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:databasepath; 51, if_statement; 51, 52; 51, 75; 52, boolean_operator:or; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:overwrite; 56, not_operator; 56, 57; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:os; 61, identifier:path; 62, identifier:isdir; 63, argument_list; 63, 64; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:os; 68, identifier:path; 69, identifier:join; 70, argument_list; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:databasepath; 74, string:'coregenome'; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:cowbat_targets; 81, argument_list; 81, 82; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:databasepath; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:databasepath; 87, if_statement; 87, 88; 87, 111; 88, boolean_operator:or; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:overwrite; 92, not_operator; 92, 93; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:os; 97, identifier:path; 98, identifier:isdir; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:os; 104, identifier:path; 105, identifier:join; 106, argument_list; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:databasepath; 110, string:'ConFindr'; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:confindr_targets; 117, argument_list; 118, if_statement; 118, 119; 118, 142; 119, boolean_operator:or; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:overwrite; 123, not_operator; 123, 124; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:os; 128, identifier:path; 129, identifier:isdir; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:os; 135, identifier:path; 136, identifier:join; 137, argument_list; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:databasepath; 141, string:'mash'; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:mash; 148, argument_list; 148, 149; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:databasepath; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:databasepath; 154, if_statement; 154, 155; 154, 178; 155, boolean_operator:or; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:overwrite; 159, not_operator; 159, 160; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:os; 164, identifier:path; 165, identifier:isdir; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:os; 171, identifier:path; 172, identifier:join; 173, argument_list; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:databasepath; 177, string:'MLST'; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:mlst; 184, argument_list; 184, 185; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:databasepath; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:databasepath; 190, if_statement; 190, 191; 190, 214; 191, boolean_operator:or; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:overwrite; 195, not_operator; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:os; 200, identifier:path; 201, identifier:isdir; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:os; 207, identifier:path; 208, identifier:join; 209, argument_list; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:databasepath; 213, string:'rMLST'; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:rmlst; 220, argument_list; 220, 221; 220, 226; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:databasepath; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:databasepath; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:credentials; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:credentials; 231, if_statement; 231, 232; 231, 255; 232, boolean_operator:or; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:overwrite; 236, not_operator; 236, 237; 237, call; 237, 238; 237, 243; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:os; 241, identifier:path; 242, identifier:isdir; 243, argument_list; 243, 244; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:os; 248, identifier:path; 249, identifier:join; 250, argument_list; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:databasepath; 254, string:'univec'; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:univec; 261, argument_list; 261, 262; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:databasepath; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:databasepath; 267, if_statement; 267, 268; 267, 291; 268, boolean_operator:or; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:overwrite; 272, not_operator; 272, 273; 273, call; 273, 274; 273, 279; 274, attribute; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:os; 277, identifier:path; 278, identifier:isdir; 279, argument_list; 279, 280; 280, call; 280, 281; 280, 286; 281, attribute; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:os; 284, identifier:path; 285, identifier:join; 286, argument_list; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:databasepath; 290, string:'resfinder'; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:self; 296, identifier:cge_db_downloader; 297, argument_list; 297, 298; 297, 303; 297, 306; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:databasepath; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:databasepath; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:analysistype; 305, string:'resfinder'; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:dbname; 308, string:'resfinder_db'; 309, if_statement; 309, 310; 309, 333; 310, boolean_operator:or; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:overwrite; 314, not_operator; 314, 315; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:os; 319, identifier:path; 320, identifier:isdir; 321, argument_list; 321, 322; 322, call; 322, 323; 322, 328; 323, attribute; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:os; 326, identifier:path; 327, identifier:join; 328, argument_list; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:databasepath; 332, string:'virulence'; 333, block; 333, 334; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:cge_db_downloader; 339, argument_list; 339, 340; 339, 345; 339, 348; 340, keyword_argument; 340, 341; 340, 342; 341, identifier:databasepath; 342, attribute; 342, 343; 342, 344; 343, identifier:self; 344, identifier:databasepath; 345, keyword_argument; 345, 346; 345, 347; 346, identifier:analysistype; 347, string:'virulence'; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:dbname; 350, string:'virulencefinder_db'; 351, if_statement; 351, 352; 351, 375; 352, boolean_operator:or; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:overwrite; 356, not_operator; 356, 357; 357, call; 357, 358; 357, 363; 358, attribute; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:os; 361, identifier:path; 362, identifier:isdir; 363, argument_list; 363, 364; 364, call; 364, 365; 364, 370; 365, attribute; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:os; 368, identifier:path; 369, identifier:join; 370, argument_list; 370, 371; 370, 374; 371, attribute; 371, 372; 371, 373; 372, identifier:self; 373, identifier:databasepath; 374, string:'serosippr'; 375, block; 375, 376; 376, expression_statement; 376, 377; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:self; 380, identifier:cge_db_downloader; 381, argument_list; 381, 382; 381, 387; 381, 390; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:databasepath; 384, attribute; 384, 385; 384, 386; 385, identifier:self; 386, identifier:databasepath; 387, keyword_argument; 387, 388; 387, 389; 388, identifier:analysistype; 389, string:'serosippr'; 390, keyword_argument; 390, 391; 390, 392; 391, identifier:dbname; 392, string:'serotypefinder_db'; 393, if_statement; 393, 394; 393, 417; 394, boolean_operator:or; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:self; 397, identifier:overwrite; 398, not_operator; 398, 399; 399, call; 399, 400; 399, 405; 400, attribute; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:os; 403, identifier:path; 404, identifier:isdir; 405, argument_list; 405, 406; 406, call; 406, 407; 406, 412; 407, attribute; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:os; 410, identifier:path; 411, identifier:join; 412, argument_list; 412, 413; 412, 416; 413, attribute; 413, 414; 413, 415; 414, identifier:self; 415, identifier:databasepath; 416, string:'pointfinder'; 417, block; 417, 418; 418, expression_statement; 418, 419; 419, call; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:self; 422, identifier:cge_db_downloader; 423, argument_list; 423, 424; 423, 429; 423, 432; 424, keyword_argument; 424, 425; 424, 426; 425, identifier:databasepath; 426, attribute; 426, 427; 426, 428; 427, identifier:self; 428, identifier:databasepath; 429, keyword_argument; 429, 430; 429, 431; 430, identifier:analysistype; 431, string:'pointfinder'; 432, keyword_argument; 432, 433; 432, 434; 433, identifier:dbname; 434, string:'pointfinder_db'; 435, if_statement; 435, 436; 435, 459; 436, boolean_operator:or; 436, 437; 436, 440; 437, attribute; 437, 438; 437, 439; 438, identifier:self; 439, identifier:overwrite; 440, not_operator; 440, 441; 441, call; 441, 442; 441, 447; 442, attribute; 442, 443; 442, 446; 443, attribute; 443, 444; 443, 445; 444, identifier:os; 445, identifier:path; 446, identifier:isdir; 447, argument_list; 447, 448; 448, call; 448, 449; 448, 454; 449, attribute; 449, 450; 449, 453; 450, attribute; 450, 451; 450, 452; 451, identifier:os; 452, identifier:path; 453, identifier:join; 454, argument_list; 454, 455; 454, 458; 455, attribute; 455, 456; 455, 457; 456, identifier:self; 457, identifier:databasepath; 458, string:'clark'; 459, block; 459, 460; 460, expression_statement; 460, 461; 461, call; 461, 462; 461, 465; 462, attribute; 462, 463; 462, 464; 463, identifier:self; 464, identifier:clark; 465, argument_list; 465, 466; 466, keyword_argument; 466, 467; 466, 468; 467, identifier:databasepath; 468, attribute; 468, 469; 468, 470; 469, identifier:self; 470, identifier:databasepath; 471, if_statement; 471, 472; 471, 495; 472, boolean_operator:or; 472, 473; 472, 476; 473, attribute; 473, 474; 473, 475; 474, identifier:self; 475, identifier:overwrite; 476, not_operator; 476, 477; 477, call; 477, 478; 477, 483; 478, attribute; 478, 479; 478, 482; 479, attribute; 479, 480; 479, 481; 480, identifier:os; 481, identifier:path; 482, identifier:isdir; 483, argument_list; 483, 484; 484, call; 484, 485; 484, 490; 485, attribute; 485, 486; 485, 489; 486, attribute; 486, 487; 486, 488; 487, identifier:os; 488, identifier:path; 489, identifier:join; 490, argument_list; 490, 491; 490, 494; 491, attribute; 491, 492; 491, 493; 492, identifier:self; 493, identifier:databasepath; 494, string:'mob_suite'; 495, block; 495, 496; 496, expression_statement; 496, 497; 497, call; 497, 498; 497, 501; 498, attribute; 498, 499; 498, 500; 499, identifier:self; 500, identifier:mob_suite_targets; 501, argument_list | def cowbat(self):
"""
Run all the methods
"""
logging.info('Beginning COWBAT database downloads')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'genesippr')):
self.sipprverse_targets(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'coregenome')):
self.cowbat_targets(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'ConFindr')):
self.confindr_targets()
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'mash')):
self.mash(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'MLST')):
self.mlst(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'rMLST')):
self.rmlst(databasepath=self.databasepath,
credentials=self.credentials)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'univec')):
self.univec(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'resfinder')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='resfinder',
dbname='resfinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'virulence')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='virulence',
dbname='virulencefinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'serosippr')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='serosippr',
dbname='serotypefinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'pointfinder')):
self.cge_db_downloader(databasepath=self.databasepath,
analysistype='pointfinder',
dbname='pointfinder_db')
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'clark')):
self.clark(databasepath=self.databasepath)
if self.overwrite or not os.path.isdir(os.path.join(self.databasepath, 'mob_suite')):
self.mob_suite_targets() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:setCalibration; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:dbBoostArray; 6, identifier:frequencies; 7, identifier:frange; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 19; 11, 200; 12, boolean_operator:and; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:dbBoostArray; 15, None; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:frequencies; 18, None; 19, block; 19, 20; 19, 29; 19, 46; 19, 63; 19, 79; 19, 87; 19, 150; 19, 151; 19, 157; 19, 158; 19, 159; 19, 160; 19, 181; 19, 182; 19, 188; 19, 194; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:logger; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:logging; 26, identifier:getLogger; 27, argument_list; 27, 28; 28, string:'main'; 29, if_statement; 29, 30; 29, 37; 30, comparison_operator:!=; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:dbBoostArray; 33, identifier:shape; 34, attribute; 34, 35; 34, 36; 35, identifier:frequencies; 36, identifier:shape; 37, block; 37, 38; 37, 45; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:logger; 42, identifier:error; 43, argument_list; 43, 44; 44, string:"ERROR: calibration array and frequency array must have same dimensions"; 45, return_statement; 46, if_statement; 46, 47; 46, 50; 46, 51; 47, comparison_operator:is; 47, 48; 47, 49; 48, identifier:frange; 49, None; 50, comment; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:frange; 55, tuple; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:frequencies; 58, integer:0; 59, subscript; 59, 60; 59, 61; 60, identifier:frequencies; 61, unary_operator:-; 61, 62; 62, integer:1; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:logger; 67, identifier:debug; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:'setting calibration with samplerate {}'; 72, identifier:format; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:samplerate; 78, argument_list; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:fs; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:samplerate; 86, argument_list; 87, if_statement; 87, 88; 87, 93; 87, 113; 88, comparison_operator:in; 88, 89; 88, 90; 89, identifier:fs; 90, attribute; 90, 91; 90, 92; 91, identifier:StimulusModel; 92, identifier:kernelCache; 93, block; 93, 94; 93, 101; 93, 102; 93, 103; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:logger; 98, identifier:debug; 99, argument_list; 99, 100; 100, string:'---->using cached filter'; 101, comment; 102, comment; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:impulseResponse; 108, subscript; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:StimulusModel; 111, identifier:kernelCache; 112, identifier:fs; 113, else_clause; 113, 114; 114, block; 114, 115; 114, 127; 114, 139; 114, 140; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:logger; 119, identifier:debug; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, string:'---->calculating new filter for fs {}'; 124, identifier:format; 125, argument_list; 125, 126; 126, identifier:fs; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:impulseResponse; 132, call; 132, 133; 132, 134; 133, identifier:impulse_response; 134, argument_list; 134, 135; 134, 136; 134, 137; 134, 138; 135, identifier:fs; 136, identifier:dbBoostArray; 137, identifier:frequencies; 138, identifier:frange; 139, comment; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 147; 142, subscript; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:StimulusModel; 145, identifier:kernelCache; 146, identifier:fs; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:impulseResponse; 150, comment; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:_calibration_fs; 156, identifier:fs; 157, comment; 158, comment; 159, comment; 160, if_statement; 160, 161; 160, 166; 161, comparison_operator:not; 161, 162; 161, 163; 162, identifier:DEFAULT_SAMPLERATE; 163, attribute; 163, 164; 163, 165; 164, identifier:StimulusModel; 165, identifier:kernelCache; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 174; 169, subscript; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:StimulusModel; 172, identifier:kernelCache; 173, identifier:DEFAULT_SAMPLERATE; 174, call; 174, 175; 174, 176; 175, identifier:impulse_response; 176, argument_list; 176, 177; 176, 178; 176, 179; 176, 180; 177, identifier:DEFAULT_SAMPLERATE; 178, identifier:dbBoostArray; 179, identifier:frequencies; 180, identifier:frange; 181, comment; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:_attenuationVector; 187, identifier:dbBoostArray; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:_calFrequencies; 193, identifier:frequencies; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:_calFrange; 199, identifier:frange; 200, else_clause; 200, 201; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:impulseResponse; 207, None | def setCalibration(self, dbBoostArray, frequencies, frange):
"""Sets the calibration to use with this stimulus,
creates a filter that will be applied to output signal generated by this model.
Set arguments to `None` to clear calibration.
:param dbBoostArray: frequency response of the system (in dB)
:type dbBoostArray: numpy.ndarray
:param frequencies: corresponding frequencies for the dbBoostArray
:type frequencies: numpy.ndarray
:param frange: The desired frequency range for which to apply the calibration, in Hz
:type frange: (int, int)
"""
if dbBoostArray is not None and frequencies is not None:
logger = logging.getLogger('main')
if dbBoostArray.shape != frequencies.shape:
logger.error("ERROR: calibration array and frequency array must have same dimensions")
return
if frange is None:
# maximum possible range
frange = (frequencies[0], frequencies[-1])
logger.debug('setting calibration with samplerate {}'.format(self.samplerate()))
fs = self.samplerate()
if fs in StimulusModel.kernelCache:
logger.debug('---->using cached filter')
# makes the assumption that the cache will be cleared if the frequency reponse
# changes
self.impulseResponse = StimulusModel.kernelCache[fs]
else:
logger.debug('---->calculating new filter for fs {}'.format(fs))
self.impulseResponse = impulse_response(fs, dbBoostArray, frequencies, frange)
# mutable type so will affect data structure persistently
StimulusModel.kernelCache[fs] = self.impulseResponse
# store this so we can quickly check if a calibration needs to be re-done
self._calibration_fs = fs
# calculate for the default samplerate, if not already, since
# we are very likely to need it, and it's better to have this done
# up front, than cause lag in the UI later
if DEFAULT_SAMPLERATE not in StimulusModel.kernelCache:
StimulusModel.kernelCache[DEFAULT_SAMPLERATE] = impulse_response(DEFAULT_SAMPLERATE, dbBoostArray, frequencies, frange)
# hang on to these for re-calculating impulse response on samplerate change
self._attenuationVector = dbBoostArray
self._calFrequencies = frequencies
self._calFrange = frange
else:
self.impulseResponse = None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:expandFunction; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:func; 6, default_parameter; 6, 7; 6, 8; 7, identifier:args; 8, list:[]; 9, block; 9, 10; 9, 12; 9, 13; 9, 23; 9, 31; 9, 35; 9, 48; 9, 69; 9, 73; 9, 120; 9, 121; 9, 122; 9, 123; 9, 127; 9, 200; 9, 201; 9, 230; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:params; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_autoParams; 21, identifier:allData; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:steps; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:autoParamRanges; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:ntraces; 34, integer:1; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:p; 37, identifier:steps; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:ntraces; 42, binary_operator:*; 42, 43; 42, 44; 43, identifier:ntraces; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:p; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:varylist; 51, list_comprehension; 51, 52; 51, 63; 52, list_comprehension; 52, 53; 52, 54; 53, None; 54, for_in_clause; 54, 55; 54, 56; 55, identifier:x; 56, call; 56, 57; 56, 58; 57, identifier:range; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:len; 61, argument_list; 61, 62; 62, identifier:params; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:y; 65, call; 65, 66; 65, 67; 66, identifier:range; 67, argument_list; 67, 68; 68, identifier:ntraces; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:x; 72, integer:1; 73, for_statement; 73, 74; 73, 77; 73, 81; 74, pattern_list; 74, 75; 74, 76; 75, identifier:iset; 76, identifier:step_set; 77, call; 77, 78; 77, 79; 78, identifier:enumerate; 79, argument_list; 79, 80; 80, identifier:steps; 81, block; 81, 82; 81, 111; 82, for_statement; 82, 83; 82, 84; 82, 88; 83, identifier:itrace; 84, call; 84, 85; 84, 86; 85, identifier:range; 86, argument_list; 86, 87; 87, identifier:ntraces; 88, block; 88, 89; 88, 101; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:idx; 92, binary_operator:%; 92, 93; 92, 97; 93, parenthesized_expression; 93, 94; 94, binary_operator:/; 94, 95; 94, 96; 95, identifier:itrace; 96, identifier:x; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, identifier:step_set; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:varylist; 106, identifier:itrace; 107, identifier:iset; 108, subscript; 108, 109; 108, 110; 109, identifier:step_set; 110, identifier:idx; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:x; 114, binary_operator:*; 114, 115; 114, 116; 115, identifier:x; 116, call; 116, 117; 116, 118; 117, identifier:len; 118, argument_list; 118, 119; 119, identifier:step_set; 120, comment; 121, comment; 122, comment; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:stim_list; 126, list:[]; 127, for_statement; 127, 128; 127, 129; 127, 133; 128, identifier:itrace; 129, call; 129, 130; 129, 131; 130, identifier:range; 131, argument_list; 131, 132; 132, identifier:ntraces; 133, block; 133, 134; 133, 187; 133, 188; 133, 189; 134, for_statement; 134, 135; 134, 138; 134, 142; 135, pattern_list; 135, 136; 135, 137; 136, identifier:ip; 137, identifier:param; 138, call; 138, 139; 138, 140; 139, identifier:enumerate; 140, argument_list; 140, 141; 141, identifier:params; 142, block; 142, 143; 143, for_statement; 143, 144; 143, 145; 143, 148; 143, 149; 143, 150; 143, 151; 143, 152; 143, 153; 144, identifier:component; 145, subscript; 145, 146; 145, 147; 146, identifier:param; 147, string:'selection'; 148, comment; 149, comment; 150, comment; 151, comment; 152, comment; 153, block; 153, 154; 153, 163; 153, 173; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:index; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:indexByComponent; 161, argument_list; 161, 162; 162, identifier:component; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:component; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:component; 170, argument_list; 170, 171; 171, list_splat; 171, 172; 172, identifier:index; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:component; 177, identifier:set; 178, argument_list; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:param; 181, string:'parameter'; 182, subscript; 182, 183; 182, 186; 183, subscript; 183, 184; 183, 185; 184, identifier:varylist; 185, identifier:itrace; 186, identifier:ip; 187, comment; 188, comment; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:stim_list; 193, identifier:append; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:func; 197, argument_list; 197, 198; 198, list_splat; 198, 199; 199, identifier:args; 200, comment; 201, for_statement; 201, 202; 201, 205; 201, 209; 202, pattern_list; 202, 203; 202, 204; 203, identifier:ip; 204, identifier:param; 205, call; 205, 206; 205, 207; 206, identifier:enumerate; 207, argument_list; 207, 208; 208, identifier:params; 209, block; 209, 210; 210, for_statement; 210, 211; 210, 212; 210, 215; 211, identifier:component; 212, subscript; 212, 213; 212, 214; 213, identifier:param; 214, string:'selection'; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:component; 220, identifier:set; 221, argument_list; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:param; 224, string:'parameter'; 225, subscript; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:varylist; 228, integer:0; 229, identifier:ip; 230, return_statement; 230, 231; 231, identifier:stim_list | def expandFunction(self, func, args=[]):
"""applies the given function to each of this stimulus's memerships when autoparamters are applied
:param func: callable to execute for each version of the stimulus
:type instancemethod:
:param args: arguments to feed to func
:type args: list
:returns: list<results of *func*>, one for each trace
"""
# initilize array to hold all varied parameters
params = self._autoParams.allData()
steps = self.autoParamRanges()
ntraces = 1
for p in steps:
ntraces = ntraces*len(p)
varylist = [[None for x in range(len(params))] for y in range(ntraces)]
x = 1
for iset, step_set in enumerate(steps):
for itrace in range(ntraces):
idx = (itrace / x) % len(step_set)
varylist[itrace][iset] = step_set[idx]
x = x*len(step_set)
# now create the stimuli according to steps
# go through list of modifing parameters, update this stimulus,
# and then save current state to list
stim_list = []
for itrace in range(ntraces):
for ip, param in enumerate(params):
for component in param['selection']:
# print 'setting component {} parameter {} to {}'.format(component.name, param['parameter'], varylist[itrace][ip])
# so I encountered a bug when the parameters were dragged the
# pickling/unpickling seems to either make a copy or somehow
# otherwise loose connection to the original components
# make sure to be setting the components that are in this model.
index = self.indexByComponent(component)
component = self.component(*index)
component.set(param['parameter'], varylist[itrace][ip])
# copy of current stim state, or go ahead and turn it into a signal?
# so then would I want to formulate some doc here as well?
stim_list.append(func(*args))
# now reset the components to start value
for ip, param in enumerate(params):
for component in param['selection']:
component.set(param['parameter'], varylist[0][ip])
return stim_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:signal; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:force_fs; 7, False; 8, block; 8, 9; 8, 11; 8, 18; 8, 35; 8, 39; 8, 59; 8, 60; 8, 64; 8, 65; 8, 66; 8, 67; 8, 128; 8, 129; 8, 142; 8, 152; 8, 168; 8, 169; 8, 170; 8, 191; 8, 203; 8, 261; 8, 262; 8, 263; 8, 270; 8, 274; 8, 275; 8, 276; 8, 277; 8, 278; 8, 279; 8, 280; 8, 281; 8, 282; 8, 290; 8, 302; 8, 451; 9, expression_statement; 9, 10; 10, comment; 11, assert_statement; 11, 12; 11, 17; 12, comparison_operator:not; 12, 13; 12, 14; 13, None; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:voltage_limits; 17, string:'Max voltage level not set'; 18, if_statement; 18, 19; 18, 20; 18, 25; 19, identifier:force_fs; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:samplerate; 24, identifier:force_fs; 25, else_clause; 25, 26; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:samplerate; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:samplerate; 34, argument_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:track_signals; 38, list:[]; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:max_db; 42, call; 42, 43; 42, 44; 43, identifier:max; 44, argument_list; 44, 45; 45, list_comprehension; 45, 46; 45, 51; 45, 56; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:comp; 49, identifier:intensity; 50, argument_list; 51, for_in_clause; 51, 52; 51, 53; 52, identifier:t; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_segments; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:comp; 58, identifier:t; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:atten; 63, integer:0; 64, comment; 65, comment; 66, comment; 67, for_statement; 67, 68; 67, 69; 67, 72; 68, identifier:track; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_segments; 72, block; 72, 73; 72, 77; 72, 108; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:track_list; 76, list:[]; 77, for_statement; 77, 78; 77, 79; 77, 80; 78, identifier:component; 79, identifier:track; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:track_list; 85, identifier:append; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:component; 90, identifier:signal; 91, argument_list; 91, 92; 91, 95; 91, 98; 91, 103; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:fs; 94, identifier:samplerate; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:atten; 97, integer:0; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:caldb; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:caldb; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:calv; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:calv; 108, if_statement; 108, 109; 108, 115; 109, comparison_operator:>; 109, 110; 109, 114; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, identifier:track_list; 114, integer:0; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:track_signals; 120, identifier:append; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:np; 125, identifier:hstack; 126, argument_list; 126, 127; 127, identifier:track_list; 128, comment; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:full_len; 132, call; 132, 133; 132, 134; 133, identifier:len; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:max; 137, argument_list; 137, 138; 137, 139; 138, identifier:track_signals; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:key; 141, identifier:len; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:total_signal; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:np; 148, identifier:zeros; 149, argument_list; 149, 150; 150, tuple; 150, 151; 151, identifier:full_len; 152, for_statement; 152, 153; 152, 154; 152, 155; 153, identifier:track; 154, identifier:track_signals; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, augmented_assignment:+=; 157, 158; 157, 167; 158, subscript; 158, 159; 158, 160; 159, identifier:total_signal; 160, slice; 160, 161; 160, 162; 160, 163; 161, integer:0; 162, colon; 163, call; 163, 164; 163, 165; 164, identifier:len; 165, argument_list; 165, 166; 166, identifier:track; 167, identifier:track; 168, comment; 169, comment; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:component_names; 173, call; 173, 174; 173, 175; 174, identifier:list; 175, argument_list; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:set; 178, argument_list; 178, 179; 179, list_comprehension; 179, 180; 179, 183; 179, 188; 180, attribute; 180, 181; 180, 182; 181, identifier:comp; 182, identifier:name; 183, for_in_clause; 183, 184; 183, 185; 184, identifier:track; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_segments; 188, for_in_clause; 188, 189; 188, 190; 189, identifier:comp; 190, identifier:track; 191, if_statement; 191, 192; 191, 195; 192, comparison_operator:in; 192, 193; 192, 194; 193, string:'silence'; 194, identifier:component_names; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:component_names; 200, identifier:remove; 201, argument_list; 201, 202; 202, string:'silence'; 203, if_statement; 203, 204; 203, 224; 203, 247; 204, boolean_operator:or; 204, 205; 204, 211; 205, comparison_operator:>; 205, 206; 205, 210; 206, call; 206, 207; 206, 208; 207, identifier:len; 208, argument_list; 208, 209; 209, identifier:component_names; 210, integer:1; 211, parenthesized_expression; 211, 212; 212, boolean_operator:and; 212, 213; 212, 219; 213, comparison_operator:==; 213, 214; 213, 218; 214, call; 214, 215; 214, 216; 215, identifier:len; 216, argument_list; 216, 217; 217, identifier:component_names; 218, integer:1; 219, comparison_operator:!=; 219, 220; 219, 223; 220, subscript; 220, 221; 220, 222; 221, identifier:component_names; 222, integer:0; 223, string:"Square Wave"; 224, block; 224, 225; 224, 235; 224, 243; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:total_signal; 228, call; 228, 229; 228, 230; 229, identifier:convolve_filter; 230, argument_list; 230, 231; 230, 232; 231, identifier:total_signal; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:impulseResponse; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:maxv; 238, subscript; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:voltage_limits; 242, integer:0; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:to_speaker; 246, True; 247, else_clause; 247, 248; 248, block; 248, 249; 248, 257; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:maxv; 252, subscript; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:voltage_limits; 256, integer:1; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:to_speaker; 260, False; 261, comment; 262, comment; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 269; 265, subscript; 265, 266; 265, 267; 266, identifier:total_signal; 267, unary_operator:-; 267, 268; 268, integer:1; 269, integer:0; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:undesired_attenuation; 273, integer:0; 274, comment; 275, comment; 276, comment; 277, comment; 278, comment; 279, comment; 280, comment; 281, comment; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:minv; 285, subscript; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:voltage_limits; 289, integer:2; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:sig_max; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:np; 296, identifier:max; 297, argument_list; 297, 298; 298, call; 298, 299; 298, 300; 299, identifier:abs; 300, argument_list; 300, 301; 301, identifier:total_signal; 302, if_statement; 302, 303; 302, 306; 302, 307; 302, 376; 303, comparison_operator:>; 303, 304; 303, 305; 304, identifier:sig_max; 305, identifier:maxv; 306, comment; 307, block; 307, 308; 307, 317; 307, 330; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:total_signal; 311, binary_operator:*; 311, 312; 311, 316; 312, parenthesized_expression; 312, 313; 313, binary_operator:/; 313, 314; 313, 315; 314, identifier:total_signal; 315, identifier:sig_max; 316, identifier:maxv; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:attenuated; 320, binary_operator:*; 320, 321; 320, 322; 321, integer:20; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:np; 325, identifier:log10; 326, argument_list; 326, 327; 327, binary_operator:/; 327, 328; 327, 329; 328, identifier:sig_max; 329, identifier:maxv; 330, if_statement; 330, 331; 330, 334; 330, 341; 331, comparison_operator:<=; 331, 332; 331, 333; 332, identifier:attenuated; 333, identifier:atten; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:atten; 338, binary_operator:-; 338, 339; 338, 340; 339, identifier:atten; 340, identifier:attenuated; 341, else_clause; 341, 342; 342, block; 342, 343; 342, 349; 342, 353; 342, 362; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:undesired_attenuation; 346, binary_operator:-; 346, 347; 346, 348; 347, identifier:attenuated; 348, identifier:atten; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 352; 351, identifier:atten; 352, integer:0; 353, expression_statement; 353, 354; 354, assignment; 354, 355; 354, 356; 355, identifier:logger; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:logging; 359, identifier:getLogger; 360, argument_list; 360, 361; 361, string:'main'; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:logger; 366, identifier:warning; 367, argument_list; 367, 368; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, string:"STIMULUS AMPLTIUDE {:.2f}V EXCEEDS MAXIMUM({}V), RESCALING. \
UNDESIRED ATTENUATION {:.2f}dB"; 371, identifier:format; 372, argument_list; 372, 373; 372, 374; 372, 375; 373, identifier:sig_max; 374, identifier:maxv; 375, identifier:undesired_attenuation; 376, elif_clause; 376, 377; 376, 386; 377, boolean_operator:and; 377, 378; 377, 385; 378, boolean_operator:and; 378, 379; 378, 382; 379, comparison_operator:<; 379, 380; 379, 381; 380, identifier:sig_max; 381, identifier:minv; 382, comparison_operator:!=; 382, 383; 382, 384; 383, identifier:sig_max; 384, integer:0; 385, identifier:to_speaker; 386, block; 386, 387; 386, 405; 386, 414; 386, 432; 386, 446; 386, 447; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 390; 389, identifier:before_rms; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:np; 393, identifier:sqrt; 394, argument_list; 394, 395; 395, call; 395, 396; 395, 399; 396, attribute; 396, 397; 396, 398; 397, identifier:np; 398, identifier:mean; 399, argument_list; 399, 400; 400, call; 400, 401; 400, 402; 401, identifier:pow; 402, argument_list; 402, 403; 402, 404; 403, identifier:total_signal; 404, integer:2; 405, expression_statement; 405, 406; 406, assignment; 406, 407; 406, 408; 407, identifier:total_signal; 408, binary_operator:*; 408, 409; 408, 413; 409, parenthesized_expression; 409, 410; 410, binary_operator:/; 410, 411; 410, 412; 411, identifier:total_signal; 412, identifier:sig_max; 413, identifier:minv; 414, expression_statement; 414, 415; 415, assignment; 415, 416; 415, 417; 416, identifier:after_rms; 417, call; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:np; 420, identifier:sqrt; 421, argument_list; 421, 422; 422, call; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:np; 425, identifier:mean; 426, argument_list; 426, 427; 427, call; 427, 428; 427, 429; 428, identifier:pow; 429, argument_list; 429, 430; 429, 431; 430, identifier:total_signal; 431, integer:2; 432, expression_statement; 432, 433; 433, assignment; 433, 434; 433, 435; 434, identifier:attenuated; 435, binary_operator:*; 435, 436; 435, 438; 436, unary_operator:-; 436, 437; 437, integer:20; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:np; 441, identifier:log10; 442, argument_list; 442, 443; 443, binary_operator:/; 443, 444; 443, 445; 444, identifier:before_rms; 445, identifier:after_rms; 446, comment; 447, expression_statement; 447, 448; 448, augmented_assignment:+=; 448, 449; 448, 450; 449, identifier:atten; 450, identifier:attenuated; 451, return_statement; 451, 452; 452, expression_list; 452, 453; 452, 454; 452, 455; 453, identifier:total_signal; 454, identifier:atten; 455, identifier:undesired_attenuation | def signal(self, force_fs=False):
"""The current stimulus in signal representation, this is the sum
of its components
:param force_fs: Allow to use a different samplerate than the default, should be used to recreate historical signals only
:type force_fs: int
:returns: numpy.ndarray -- voltage signal for this stimulus
"""
assert None not in self.voltage_limits, 'Max voltage level not set'
if force_fs:
samplerate = force_fs
else:
samplerate = self.samplerate()
track_signals = []
max_db = max([comp.intensity() for t in self._segments for comp in t])
# atten = self.caldb - max_db
atten = 0
# if max_db > self.caldb:
# raise Exception("Stimulus intensity over maxium")
# print 'caldb:', self.caldb, 'max db:', max_db, 'atten:', atten, 'calv', self.calv
for track in self._segments:
track_list = []
for component in track:
track_list.append(component.signal(fs=samplerate,
atten=0,
caldb=self.caldb,
calv=self.calv))
if len(track_list) > 0:
track_signals.append(np.hstack(track_list))
# track_signals = sorted(track_signals, key=len, reverse=True)
full_len = len(max(track_signals, key=len))
total_signal = np.zeros((full_len,))
for track in track_signals:
total_signal[0:len(track)] += track
# if there is only square waves in stimulus, do not apply calibration --
# it is assumed to not be a signal for the speaker
component_names = list(set([comp.name for track in self._segments for comp in track]))
if 'silence' in component_names:
component_names.remove('silence')
if len(component_names) > 1 or (len(component_names) == 1 and component_names[0] != "Square Wave"):
total_signal = convolve_filter(total_signal, self.impulseResponse)
maxv = self.voltage_limits[0]
to_speaker = True
else:
maxv = self.voltage_limits[1]
to_speaker = False
# last sample should always go to 0, so output isn't stuck on some
# other value when stim ends
total_signal[-1] = 0
undesired_attenuation = 0
# sig_max = max(abs(total_signal))
# if sig_max > self.calv:
# over_db = 20 * np.log10(sig_max/self.calv)
# allowance = float(min(over_db, atten))
# scalev = (10 ** (allowance/20)*self.calv)
# total_signal = total_signal/scalev
# print 'sigmax {}, over_db {}, allowance {}, scalev {}'.format(sig_max, over_db, allowance, scalev)
# atten -= allowance
minv = self.voltage_limits[2]
sig_max = np.max(abs(total_signal))
if sig_max > maxv:
# scale stim down to outputable max
total_signal = (total_signal/sig_max)*maxv
attenuated = 20 * np.log10(sig_max/maxv)
if attenuated <= atten:
atten = atten - attenuated
else:
undesired_attenuation = attenuated - atten
atten = 0
logger = logging.getLogger('main')
logger.warning("STIMULUS AMPLTIUDE {:.2f}V EXCEEDS MAXIMUM({}V), RESCALING. \
UNDESIRED ATTENUATION {:.2f}dB".format(sig_max, maxv, undesired_attenuation))
elif sig_max < minv and sig_max !=0 and to_speaker:
before_rms = np.sqrt(np.mean(pow(total_signal,2)))
total_signal = (total_signal/sig_max)*minv
after_rms = np.sqrt(np.mean(pow(total_signal,2)))
attenuated = -20 * np.log10(before_rms/after_rms)
# print 'signal below min, adding {} attenuation'.format(attenuated)
atten += attenuated
return total_signal, atten, undesired_attenuation |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:verify; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:windowSize; 7, None; 8, block; 8, 9; 8, 11; 8, 22; 8, 32; 8, 37; 8, 48; 8, 82; 8, 95; 8, 100; 8, 115; 8, 124; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 19; 12, comparison_operator:is; 12, 13; 12, 18; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:samplerate; 17, argument_list; 18, None; 19, block; 19, 20; 20, return_statement; 20, 21; 21, string:"Multiple recording files with conflicting samplerates"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:msg; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_autoParams; 30, identifier:verify; 31, argument_list; 32, if_statement; 32, 33; 32, 34; 33, identifier:msg; 34, block; 34, 35; 35, return_statement; 35, 36; 36, identifier:msg; 37, if_statement; 37, 38; 37, 45; 38, comparison_operator:==; 38, 39; 38, 44; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:traceCount; 43, argument_list; 44, integer:0; 45, block; 45, 46; 46, return_statement; 46, 47; 47, string:"Test is empty"; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:windowSize; 51, None; 52, block; 52, 53; 52, 64; 52, 65; 52, 66; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:durations; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:expandFunction; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:duration; 64, comment; 65, comment; 66, if_statement; 66, 67; 66, 79; 67, boolean_operator:or; 67, 68; 67, 73; 68, comparison_operator:>; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:durations; 71, integer:0; 72, identifier:windowSize; 73, comparison_operator:>; 73, 74; 73, 78; 74, subscript; 74, 75; 74, 76; 75, identifier:durations; 76, unary_operator:-; 76, 77; 77, integer:1; 78, identifier:windowSize; 79, block; 79, 80; 80, return_statement; 80, 81; 81, string:"Stimulus duration exceeds window duration"; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:msg; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:verifyExpanded; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:samplerate; 94, argument_list; 95, if_statement; 95, 96; 95, 97; 96, identifier:msg; 97, block; 97, 98; 98, return_statement; 98, 99; 99, identifier:msg; 100, if_statement; 100, 101; 100, 112; 101, boolean_operator:or; 101, 102; 101, 107; 102, comparison_operator:is; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:caldb; 106, None; 107, comparison_operator:is; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:calv; 111, None; 112, block; 112, 113; 113, return_statement; 113, 114; 114, string:"Test reference voltage not set"; 115, if_statement; 115, 116; 115, 121; 116, comparison_operator:in; 116, 117; 116, 118; 117, None; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:voltage_limits; 121, block; 121, 122; 122, return_statement; 122, 123; 123, string:"Device voltage limits not set"; 124, return_statement; 124, 125; 125, integer:0 | def verify(self, windowSize=None):
"""Checks the stimulus, including expanded parameters for invalidating conditions
:param windowSize: acquistion (recording) window size (seconds)
:type windowSize: float
:returns: str -- error message, if any, 0 otherwise"""
if self.samplerate() is None:
return "Multiple recording files with conflicting samplerates"
msg = self._autoParams.verify()
if msg:
return msg
if self.traceCount() == 0:
return "Test is empty"
if windowSize is not None:
durations = self.expandFunction(self.duration)
# print 'windowSize', windowSize, 'self', durations[0], durations[-1]
# ranges are linear, so we only need to test first and last
if durations[0] > windowSize or durations[-1] > windowSize:
return "Stimulus duration exceeds window duration"
msg = self.verifyExpanded(self.samplerate())
if msg:
return msg
if self.caldb is None or self.calv is None:
return "Test reference voltage not set"
if None in self.voltage_limits:
return "Device voltage limits not set"
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:getLogicalLines; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:fp; 5, default_parameter; 5, 6; 5, 7; 6, identifier:allowQP; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:findBegin; 10, False; 11, block; 11, 12; 11, 14; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 17; 14, 76; 15, not_operator; 15, 16; 16, identifier:allowQP; 17, block; 17, 18; 17, 28; 17, 29; 17, 31; 17, 32; 17, 33; 17, 37; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:val; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:fp; 24, identifier:read; 25, argument_list; 25, 26; 26, unary_operator:-; 26, 27; 27, integer:1; 28, comment; 29, expression_statement; 29, 30; 30, comment; 31, comment; 32, comment; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:lineNumber; 36, integer:1; 37, for_statement; 37, 38; 37, 39; 37, 45; 38, identifier:match; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:logical_lines_re; 42, identifier:finditer; 43, argument_list; 43, 44; 44, identifier:val; 45, block; 45, 46; 45, 62; 45, 72; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:line; 50, identifier:n; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:wrap_re; 54, identifier:subn; 55, argument_list; 55, 56; 55, 57; 56, string:''; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:match; 60, identifier:group; 61, argument_list; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:!=; 63, 64; 63, 65; 64, identifier:line; 65, string:''; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, yield; 68, 69; 69, expression_list; 69, 70; 69, 71; 70, identifier:line; 71, identifier:lineNumber; 72, expression_statement; 72, 73; 73, augmented_assignment:+=; 73, 74; 73, 75; 74, identifier:lineNumber; 75, identifier:n; 76, else_clause; 76, 77; 77, block; 77, 78; 77, 82; 77, 88; 77, 94; 77, 98; 77, 102; 77, 302; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:quotedPrintable; 81, False; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:newbuffer; 85, attribute; 85, 86; 85, 87; 86, identifier:six; 87, identifier:StringIO; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:logicalLine; 91, call; 91, 92; 91, 93; 92, identifier:newbuffer; 93, argument_list; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:lineNumber; 97, integer:0; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:lineStartNumber; 101, integer:0; 102, while_statement; 102, 103; 102, 104; 103, True; 104, block; 104, 105; 104, 113; 104, 134; 104, 176; 104, 267; 104, 268; 104, 269; 104, 277; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:line; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:fp; 111, identifier:readline; 112, argument_list; 113, if_statement; 113, 114; 113, 117; 113, 119; 114, comparison_operator:==; 114, 115; 114, 116; 115, identifier:line; 116, string:''; 117, block; 117, 118; 118, break_statement; 119, else_clause; 119, 120; 120, block; 120, 121; 120, 130; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:line; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:line; 127, identifier:rstrip; 128, argument_list; 128, 129; 129, identifier:CRLF; 130, expression_statement; 130, 131; 131, augmented_assignment:+=; 131, 132; 131, 133; 132, identifier:lineNumber; 133, integer:1; 134, if_statement; 134, 135; 134, 142; 135, comparison_operator:==; 135, 136; 135, 141; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:line; 139, identifier:rstrip; 140, argument_list; 141, string:''; 142, block; 142, 143; 142, 161; 142, 165; 142, 171; 142, 175; 143, if_statement; 143, 144; 143, 151; 144, comparison_operator:>; 144, 145; 144, 150; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:logicalLine; 148, identifier:tell; 149, argument_list; 150, integer:0; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, yield; 153, 154; 154, expression_list; 154, 155; 154, 160; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:logicalLine; 158, identifier:getvalue; 159, argument_list; 160, identifier:lineStartNumber; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:lineStartNumber; 164, identifier:lineNumber; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:logicalLine; 168, call; 168, 169; 168, 170; 169, identifier:newbuffer; 170, argument_list; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:quotedPrintable; 174, False; 175, continue_statement; 176, if_statement; 176, 177; 176, 180; 176, 199; 176, 217; 176, 252; 177, boolean_operator:and; 177, 178; 177, 179; 178, identifier:quotedPrintable; 179, identifier:allowQP; 180, block; 180, 181; 180, 188; 180, 195; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:logicalLine; 185, identifier:write; 186, argument_list; 186, 187; 187, string:'\n'; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:logicalLine; 192, identifier:write; 193, argument_list; 193, 194; 194, identifier:line; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:quotedPrintable; 198, False; 199, elif_clause; 199, 200; 199, 205; 200, comparison_operator:in; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:line; 203, integer:0; 204, identifier:SPACEORTAB; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:logicalLine; 210, identifier:write; 211, argument_list; 211, 212; 212, subscript; 212, 213; 212, 214; 213, identifier:line; 214, slice; 214, 215; 214, 216; 215, integer:1; 216, colon; 217, elif_clause; 217, 218; 217, 225; 218, comparison_operator:>; 218, 219; 218, 224; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:logicalLine; 222, identifier:tell; 223, argument_list; 224, integer:0; 225, block; 225, 226; 225, 235; 225, 239; 225, 245; 226, expression_statement; 226, 227; 227, yield; 227, 228; 228, expression_list; 228, 229; 228, 234; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:logicalLine; 232, identifier:getvalue; 233, argument_list; 234, identifier:lineStartNumber; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:lineStartNumber; 238, identifier:lineNumber; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:logicalLine; 242, call; 242, 243; 242, 244; 243, identifier:newbuffer; 244, argument_list; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:logicalLine; 249, identifier:write; 250, argument_list; 250, 251; 251, identifier:line; 252, else_clause; 252, 253; 253, block; 253, 254; 253, 260; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:logicalLine; 257, call; 257, 258; 257, 259; 258, identifier:newbuffer; 259, argument_list; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:logicalLine; 264, identifier:write; 265, argument_list; 265, 266; 266, identifier:line; 267, comment; 268, comment; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:val; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:logicalLine; 275, identifier:getvalue; 276, argument_list; 277, if_statement; 277, 278; 277, 297; 278, boolean_operator:and; 278, 279; 278, 285; 279, comparison_operator:==; 279, 280; 279, 284; 280, subscript; 280, 281; 280, 282; 281, identifier:val; 282, unary_operator:-; 282, 283; 283, integer:1; 284, string:'='; 285, comparison_operator:>=; 285, 286; 285, 296; 286, call; 286, 287; 286, 294; 287, attribute; 287, 288; 287, 293; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:val; 291, identifier:lower; 292, argument_list; 293, identifier:find; 294, argument_list; 294, 295; 295, string:'quoted-printable'; 296, integer:0; 297, block; 297, 298; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:quotedPrintable; 301, True; 302, if_statement; 302, 303; 302, 310; 303, comparison_operator:>; 303, 304; 303, 309; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:logicalLine; 307, identifier:tell; 308, argument_list; 309, integer:0; 310, block; 310, 311; 311, expression_statement; 311, 312; 312, yield; 312, 313; 313, expression_list; 313, 314; 313, 319; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:logicalLine; 317, identifier:getvalue; 318, argument_list; 319, identifier:lineStartNumber | def getLogicalLines(fp, allowQP=True, findBegin=False):
"""
Iterate through a stream, yielding one logical line at a time.
Because many applications still use vCard 2.1, we have to deal with the
quoted-printable encoding for long lines, as well as the vCard 3.0 and
vCalendar line folding technique, a whitespace character at the start
of the line.
Quoted-printable data will be decoded in the Behavior decoding phase.
# We're leaving this test in for awhile, because the unittest was ugly and dumb.
>>> from six import StringIO
>>> f=StringIO(testLines)
>>> for n, l in enumerate(getLogicalLines(f)):
... print("Line %s: %s" % (n, l[0]))
...
Line 0: Line 0 text, Line 0 continued.
Line 1: Line 1;encoding=quoted-printable:this is an evil=
evil=
format.
Line 2: Line 2 is a new line, it does not start with whitespace.
"""
if not allowQP:
val = fp.read(-1)
#Shouldn't need this anymore...
"""
if len(val) > 0:
if not findBegin:
val = val.decode('utf-8')
else:
for encoding in 'utf-8', 'utf-16-LE', 'utf-16-BE', 'iso-8859-1':
try:
val = val.decode(encoding)
if begin_re.search(val) is not None:
break
except UnicodeDecodeError:
pass
else:
raise ParseError('Could not find BEGIN when trying to determine encoding')
"""
# strip off any UTF8 BOMs which Python's UTF8 decoder leaves
#val = val.lstrip( unicode( codecs.BOM_UTF8, "utf8" ) )
lineNumber = 1
for match in logical_lines_re.finditer(val):
line, n = wrap_re.subn('', match.group())
if line != '':
yield line, lineNumber
lineNumber += n
else:
quotedPrintable = False
newbuffer = six.StringIO
logicalLine = newbuffer()
lineNumber = 0
lineStartNumber = 0
while True:
line = fp.readline()
if line == '':
break
else:
line = line.rstrip(CRLF)
lineNumber += 1
if line.rstrip() == '':
if logicalLine.tell() > 0:
yield logicalLine.getvalue(), lineStartNumber
lineStartNumber = lineNumber
logicalLine = newbuffer()
quotedPrintable = False
continue
if quotedPrintable and allowQP:
logicalLine.write('\n')
logicalLine.write(line)
quotedPrintable = False
elif line[0] in SPACEORTAB:
logicalLine.write(line[1:])
elif logicalLine.tell() > 0:
yield logicalLine.getvalue(), lineStartNumber
lineStartNumber = lineNumber
logicalLine = newbuffer()
logicalLine.write(line)
else:
logicalLine = newbuffer()
logicalLine.write(line)
# vCard 2.1 allows parameters to be encoded without a parameter name.
# False positives are unlikely, but possible.
val = logicalLine.getvalue()
if val[-1]=='=' and val.lower().find('quoted-printable') >= 0:
quotedPrintable=True
if logicalLine.tell() > 0:
yield logicalLine.getvalue(), lineStartNumber |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_bind_model; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 53; 5, 54; 5, 55; 5, 56; 5, 57; 5, 58; 5, 59; 5, 60; 5, 61; 5, 62; 5, 63; 5, 64; 5, 65; 5, 66; 5, 67; 5, 87; 5, 88; 5, 89; 5, 90; 5, 91; 5, 101; 5, 107; 5, 111; 5, 207; 5, 208; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 18; 9, comparison_operator:!=; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:groups; 15, integer:0; 16, identifier:level; 17, integer:0; 18, block; 18, 19; 18, 37; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:log; 25, identifier:info; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:"Got invalid first group: {0}"; 30, identifier:format; 31, argument_list; 31, 32; 32, subscript; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:groups; 36, integer:0; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:ValueError; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, string:"Invalid group tree: first group must have level of 0 (got {0})"; 44, identifier:format; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 52; 47, subscript; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:groups; 51, integer:0; 52, identifier:level; 53, comment; 54, comment; 55, comment; 56, comment; 57, comment; 58, comment; 59, comment; 60, comment; 61, comment; 62, comment; 63, comment; 64, comment; 65, comment; 66, comment; 67, class_definition; 67, 68; 67, 69; 67, 71; 68, identifier:Stack; 69, argument_list; 69, 70; 70, identifier:list; 71, block; 71, 72; 71, 74; 72, expression_statement; 72, 73; 73, comment; 74, function_definition; 74, 75; 74, 76; 74, 79; 75, function_name:push; 76, parameters; 76, 77; 76, 78; 77, identifier:self; 78, identifier:el; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:append; 85, argument_list; 85, 86; 86, identifier:el; 87, comment; 88, comment; 89, comment; 90, comment; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:parent_stack; 94, call; 94, 95; 94, 96; 95, identifier:Stack; 96, argument_list; 96, 97; 97, list:[self.root]; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:root; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:current_parent; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:root; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:prev_group; 110, None; 111, for_statement; 111, 112; 111, 113; 111, 116; 112, identifier:g; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:groups; 116, block; 116, 117; 116, 123; 116, 124; 116, 187; 116, 188; 116, 194; 116, 203; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:g; 121, identifier:db; 122, identifier:self; 123, comment; 124, if_statement; 124, 125; 124, 128; 124, 129; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:prev_group; 127, None; 128, comment; 129, block; 129, 130; 130, if_statement; 130, 131; 130, 138; 130, 139; 130, 140; 130, 152; 131, comparison_operator:>; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:g; 134, identifier:level; 135, attribute; 135, 136; 135, 137; 136, identifier:prev_group; 137, identifier:level; 138, comment; 139, comment; 140, block; 140, 141; 140, 145; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:current_parent; 144, identifier:prev_group; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:parent_stack; 149, identifier:push; 150, argument_list; 150, 151; 151, identifier:current_parent; 152, elif_clause; 152, 153; 152, 160; 152, 161; 153, comparison_operator:<; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:g; 156, identifier:level; 157, attribute; 157, 158; 157, 159; 158, identifier:prev_group; 159, identifier:level; 160, comment; 161, block; 161, 162; 161, 179; 161, 186; 162, while_statement; 162, 163; 162, 170; 163, comparison_operator:<=; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:g; 166, identifier:level; 167, attribute; 167, 168; 167, 169; 168, identifier:current_parent; 169, identifier:level; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:current_parent; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:parent_stack; 177, identifier:pop; 178, argument_list; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:parent_stack; 183, identifier:push; 184, argument_list; 184, 185; 185, identifier:current_parent; 186, comment; 187, comment; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:g; 192, identifier:parent; 193, identifier:current_parent; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:current_parent; 199, identifier:children; 200, identifier:append; 201, argument_list; 201, 202; 202, identifier:g; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:prev_group; 206, identifier:g; 207, comment; 208, for_statement; 208, 209; 208, 210; 208, 213; 209, identifier:entry; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:entries; 213, block; 213, 214; 214, for_statement; 214, 215; 214, 216; 214, 219; 214, 245; 215, identifier:group; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:groups; 219, block; 219, 220; 220, if_statement; 220, 221; 220, 228; 221, comparison_operator:==; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:entry; 224, identifier:group_id; 225, attribute; 225, 226; 225, 227; 226, identifier:group; 227, identifier:id; 228, block; 228, 229; 228, 238; 228, 244; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 236; 231, attribute; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:group; 234, identifier:entries; 235, identifier:append; 236, argument_list; 236, 237; 237, identifier:entry; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:entry; 242, identifier:group; 243, identifier:group; 244, break_statement; 245, else_clause; 245, 246; 245, 247; 246, comment; 247, block; 247, 248; 248, raise_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:NotImplementedError; 251, argument_list; 251, 252; 252, string:"Orphaned entries not (yet) supported." | def _bind_model(self):
"""
This method binds the various model objects together in the correct hierarchy
and adds referneces to this database object in the groups.
"""
if self.groups[0].level != 0:
self.log.info("Got invalid first group: {0}".format(self.groups[0]))
raise ValueError("Invalid group tree: first group must have level of 0 (got {0})".format(self.groups[0].level))
# The KeePassX source code maintains that first group to have incremented
# level is a child of the previous group with a lower level.
#
# [R]
# | A (1)
# +-| B (2)
# | | C (2)
# | D (1)
# +-| E (2)
# | F (2)
# +-| G (3)
# | H (3)
# | I (3)
#
class Stack(list):
""" A class to make parsing code slightly more semantic. """
def push(self, el):
self.append(el)
# This is a different parsing approach than taken by KeePassX (or other python
# libs), but seems a little more intuitive. It could be further simplified
# by noting that current_parent is always parent_stack[-1], but this is a bit
# more readable.
parent_stack = Stack([self.root])
current_parent = self.root
prev_group = None
for g in self.groups:
g.db = self # Bind database to group objects
if prev_group is not None: # first iteration is exceptional
if g.level > prev_group.level: # Always true for iteration 1 since root has level of -1
# Dropping down a level; the previous group is the parent
current_parent = prev_group
parent_stack.push(current_parent)
elif g.level < prev_group.level:
# Pop off parents until we have a parent with a level that is less than current
while g.level <= current_parent.level:
current_parent = parent_stack.pop()
parent_stack.push(current_parent) # We want to make sure that the top of the stack always matches current parent
# bi-directional child-parent binding
g.parent = current_parent
current_parent.children.append(g)
prev_group = g
# Bind group objects to entries
for entry in self.entries:
for group in self.groups:
if entry.group_id == group.id:
group.entries.append(entry)
entry.group = group
break
else:
# KeePassX adds these to the first group (i.e. root.children[0])
raise NotImplementedError("Orphaned entries not (yet) supported.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:bowtie; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 47; 5, 474; 6, expression_statement; 6, 7; 7, comment; 8, for_statement; 8, 9; 8, 10; 8, 16; 8, 17; 9, identifier:i; 10, call; 10, 11; 10, 12; 11, identifier:range; 12, argument_list; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:cpus; 16, comment; 17, block; 17, 18; 17, 32; 17, 33; 17, 40; 17, 41; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:threads; 21, call; 21, 22; 21, 23; 22, identifier:Thread; 23, argument_list; 23, 24; 23, 29; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:target; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:align; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:args; 31, tuple; 32, comment; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:threads; 37, identifier:setDaemon; 38, argument_list; 38, 39; 39, True; 40, comment; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:threads; 45, identifier:start; 46, argument_list; 47, with_statement; 47, 48; 47, 59; 48, with_clause; 48, 49; 49, with_item; 49, 50; 50, as_pattern; 50, 51; 50, 57; 51, call; 51, 52; 51, 53; 52, identifier:progressbar; 53, argument_list; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:metadata; 57, as_pattern_target; 57, 58; 58, identifier:bar; 59, block; 59, 60; 60, for_statement; 60, 61; 60, 62; 60, 63; 60, 64; 61, identifier:sample; 62, identifier:bar; 63, comment; 64, block; 64, 65; 64, 73; 64, 74; 64, 80; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:sample; 69, identifier:mapping; 70, call; 70, 71; 70, 72; 71, identifier:GenObject; 72, argument_list; 73, comment; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:sagen; 77, attribute; 77, 78; 77, 79; 78, identifier:sample; 79, identifier:general; 80, if_statement; 80, 81; 80, 86; 80, 448; 81, comparison_operator:!=; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:sagen; 84, identifier:bestassemblyfile; 85, string:"NA"; 86, block; 86, 87; 86, 103; 86, 104; 86, 105; 86, 112; 86, 113; 86, 136; 86, 151; 86, 157; 86, 175; 86, 176; 86, 192; 86, 204; 86, 205; 86, 224; 86, 241; 86, 260; 86, 261; 86, 384; 86, 405; 86, 406; 86, 417; 86, 428; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:sagen; 91, identifier:QualimapResults; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:os; 96, identifier:path; 97, identifier:join; 98, argument_list; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:sagen; 101, identifier:outputdirectory; 102, string:'qualimap_results'; 103, comment; 104, comment; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:make_path; 108, argument_list; 108, 109; 109, attribute; 109, 110; 109, 111; 110, identifier:sagen; 111, identifier:QualimapResults; 112, comment; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:sagen; 117, identifier:sortedbam; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:os; 122, identifier:path; 123, identifier:join; 124, argument_list; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:sagen; 127, identifier:QualimapResults; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:'{}_sorted.bam'; 131, identifier:format; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 135; 134, identifier:sample; 135, identifier:name; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:filenoext; 139, subscript; 139, 140; 139, 150; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:os; 144, identifier:path; 145, identifier:splitext; 146, argument_list; 146, 147; 147, attribute; 147, 148; 147, 149; 148, identifier:sagen; 149, identifier:filteredfile; 150, integer:0; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:sagen; 155, identifier:filenoext; 156, identifier:filenoext; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:sagen; 161, identifier:bowtie2results; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:os; 166, identifier:path; 167, identifier:join; 168, argument_list; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:sagen; 171, identifier:QualimapResults; 172, attribute; 172, 173; 172, 174; 173, identifier:sample; 174, identifier:name; 175, comment; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:bowtie2build; 179, call; 179, 180; 179, 181; 180, identifier:Bowtie2BuildCommandLine; 181, argument_list; 181, 182; 181, 187; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:reference; 184, attribute; 184, 185; 184, 186; 185, identifier:sagen; 186, identifier:bestassemblyfile; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:bt2; 189, attribute; 189, 190; 189, 191; 190, identifier:sagen; 191, identifier:bowtie2results; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 199; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:sample; 197, identifier:mapping; 198, identifier:BamFile; 199, binary_operator:+; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:sagen; 202, identifier:bowtie2results; 203, string:"_sorted.bam"; 204, comment; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:samsort; 208, call; 208, 209; 208, 210; 209, identifier:SamtoolsSortCommandline; 210, argument_list; 210, 211; 210, 218; 210, 221; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:input; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:sample; 216, identifier:mapping; 217, identifier:BamFile; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:o; 220, True; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:out_prefix; 223, string:"-"; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:samtools; 227, list:[SamtoolsViewCommandline(b=True, S=True, input_file="-"), samsort]; 227, 228; 227, 240; 228, call; 228, 229; 228, 230; 229, identifier:SamtoolsViewCommandline; 230, argument_list; 230, 231; 230, 234; 230, 237; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:b; 233, True; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:S; 236, True; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:input_file; 239, string:"-"; 240, identifier:samsort; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:indict; 244, dictionary; 244, 245; 244, 248; 244, 251; 244, 254; 244, 257; 245, pair; 245, 246; 245, 247; 246, string:'D'; 247, integer:5; 248, pair; 248, 249; 248, 250; 249, string:'R'; 250, integer:1; 251, pair; 251, 252; 251, 253; 252, string:'num_mismatches'; 253, integer:0; 254, pair; 254, 255; 254, 256; 255, string:'seed_length'; 256, integer:22; 257, pair; 257, 258; 257, 259; 258, string:'i_func'; 259, string:"S,0,2.50"; 260, comment; 261, try_statement; 261, 262; 261, 326; 262, block; 262, 263; 262, 271; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:_; 266, attribute; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:sample; 269, identifier:general; 270, identifier:mergedreads; 271, if_statement; 271, 272; 271, 282; 271, 308; 272, comparison_operator:==; 272, 273; 272, 281; 273, call; 273, 274; 273, 275; 274, identifier:len; 275, argument_list; 275, 276; 276, attribute; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:sample; 279, identifier:general; 280, identifier:trimmedcorrectedfastqfiles; 281, integer:2; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:indict; 287, identifier:update; 288, argument_list; 288, 289; 289, dictionary; 289, 290; 289, 299; 290, pair; 290, 291; 290, 292; 291, string:'m1'; 292, subscript; 292, 293; 292, 298; 293, attribute; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:sample; 296, identifier:general; 297, identifier:trimmedcorrectedfastqfiles; 298, integer:0; 299, pair; 299, 300; 299, 301; 300, string:'m2'; 301, subscript; 301, 302; 301, 307; 302, attribute; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:sample; 305, identifier:general; 306, identifier:trimmedcorrectedfastqfiles; 307, integer:1; 308, else_clause; 308, 309; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:indict; 314, identifier:update; 315, argument_list; 315, 316; 316, dictionary; 316, 317; 317, pair; 317, 318; 317, 319; 318, string:'U'; 319, subscript; 319, 320; 319, 325; 320, attribute; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:sample; 323, identifier:general; 324, identifier:trimmedcorrectedfastqfiles; 325, integer:0; 326, except_clause; 326, 327; 326, 328; 327, identifier:AttributeError; 328, block; 328, 329; 329, if_statement; 329, 330; 329, 340; 329, 366; 330, comparison_operator:==; 330, 331; 330, 339; 331, call; 331, 332; 331, 333; 332, identifier:len; 333, argument_list; 333, 334; 334, attribute; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:sample; 337, identifier:general; 338, identifier:assemblyfastq; 339, integer:2; 340, block; 340, 341; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:indict; 345, identifier:update; 346, argument_list; 346, 347; 347, dictionary; 347, 348; 347, 357; 348, pair; 348, 349; 348, 350; 349, string:'m1'; 350, subscript; 350, 351; 350, 356; 351, attribute; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:sample; 354, identifier:general; 355, identifier:assemblyfastq; 356, integer:0; 357, pair; 357, 358; 357, 359; 358, string:'m2'; 359, subscript; 359, 360; 359, 365; 360, attribute; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:sample; 363, identifier:general; 364, identifier:assemblyfastq; 365, integer:1; 366, else_clause; 366, 367; 367, block; 367, 368; 368, expression_statement; 368, 369; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:indict; 372, identifier:update; 373, argument_list; 373, 374; 374, dictionary; 374, 375; 375, pair; 375, 376; 375, 377; 376, string:'U'; 377, subscript; 377, 378; 377, 383; 378, attribute; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:sample; 381, identifier:general; 382, identifier:assemblyfastq; 383, integer:0; 384, expression_statement; 384, 385; 385, assignment; 385, 386; 385, 387; 386, identifier:bowtie2align; 387, call; 387, 388; 387, 389; 388, identifier:Bowtie2CommandLine; 389, argument_list; 389, 390; 389, 395; 389, 400; 389, 403; 390, keyword_argument; 390, 391; 390, 392; 391, identifier:bt2; 392, attribute; 392, 393; 392, 394; 393, identifier:sagen; 394, identifier:bowtie2results; 395, keyword_argument; 395, 396; 395, 397; 396, identifier:threads; 397, attribute; 397, 398; 397, 399; 398, identifier:self; 399, identifier:threads; 400, keyword_argument; 400, 401; 400, 402; 401, identifier:samtools; 402, identifier:samtools; 403, dictionary_splat; 403, 404; 404, identifier:indict; 405, comment; 406, expression_statement; 406, 407; 407, assignment; 407, 408; 407, 413; 408, attribute; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:sample; 411, identifier:commands; 412, identifier:bowtie2align; 413, call; 413, 414; 413, 415; 414, identifier:str; 415, argument_list; 415, 416; 416, identifier:bowtie2align; 417, expression_statement; 417, 418; 418, assignment; 418, 419; 418, 424; 419, attribute; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:sample; 422, identifier:commands; 423, identifier:bowtie2build; 424, call; 424, 425; 424, 426; 425, identifier:str; 426, argument_list; 426, 427; 427, identifier:bowtie2build; 428, expression_statement; 428, 429; 429, call; 429, 430; 429, 435; 430, attribute; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:self; 433, identifier:bowqueue; 434, identifier:put; 435, argument_list; 435, 436; 436, tuple; 436, 437; 436, 438; 436, 443; 437, identifier:sample; 438, attribute; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:sample; 441, identifier:commands; 442, identifier:bowtie2build; 443, attribute; 443, 444; 443, 447; 444, attribute; 444, 445; 444, 446; 445, identifier:sample; 446, identifier:commands; 447, identifier:bowtie2align; 448, else_clause; 448, 449; 449, block; 449, 450; 449, 458; 449, 466; 450, expression_statement; 450, 451; 451, assignment; 451, 452; 451, 457; 452, attribute; 452, 453; 452, 456; 453, attribute; 453, 454; 453, 455; 454, identifier:sample; 455, identifier:commands; 456, identifier:samtools; 457, string:"NA"; 458, expression_statement; 458, 459; 459, assignment; 459, 460; 459, 465; 460, attribute; 460, 461; 460, 464; 461, attribute; 461, 462; 461, 463; 462, identifier:sample; 463, identifier:mapping; 464, identifier:MeanInsertSize; 465, string:'NA'; 466, expression_statement; 466, 467; 467, assignment; 467, 468; 467, 473; 468, attribute; 468, 469; 468, 472; 469, attribute; 469, 470; 469, 471; 470, identifier:sample; 471, identifier:mapping; 472, identifier:MeanCoveragedata; 473, string:'NA'; 474, expression_statement; 474, 475; 475, call; 475, 476; 475, 481; 476, attribute; 476, 477; 476, 480; 477, attribute; 477, 478; 477, 479; 478, identifier:self; 479, identifier:bowqueue; 480, identifier:join; 481, argument_list | def bowtie(self):
"""
Create threads and commands for performing reference mapping for qualimap analyses
"""
for i in range(self.cpus):
# Send the threads to the merge method. :args is empty as I'm using
threads = Thread(target=self.align, args=())
# Set the daemon to true - something to do with thread management
threads.setDaemon(True)
# Start the threading
threads.start()
with progressbar(self.metadata) as bar:
for sample in bar:
# Initialise the mapping GenObject
sample.mapping = GenObject()
# Set an easier to write shortcut for sample.general
sagen = sample.general
if sagen.bestassemblyfile != "NA":
sagen.QualimapResults = os.path.join(sagen.outputdirectory, 'qualimap_results')
# Set the results folder
# Create this results folder if necessary
make_path(sagen.QualimapResults)
# Set file names
sagen.sortedbam = os.path.join(sagen.QualimapResults, '{}_sorted.bam'.format(sample.name))
filenoext = os.path.splitext(sagen.filteredfile)[0]
sagen.filenoext = filenoext
sagen.bowtie2results = os.path.join(sagen.QualimapResults, sample.name)
# Use fancy new bowtie2 wrapper
bowtie2build = Bowtie2BuildCommandLine(reference=sagen.bestassemblyfile,
bt2=sagen.bowtie2results)
sample.mapping.BamFile = sagen.bowtie2results + "_sorted.bam"
# SAMtools sort v1.3 has different run parameters
samsort = SamtoolsSortCommandline(input=sample.mapping.BamFile,
o=True,
out_prefix="-")
samtools = [SamtoolsViewCommandline(b=True, S=True, input_file="-"), samsort]
indict = {'D': 5, 'R': 1, 'num_mismatches': 0, 'seed_length': 22, 'i_func': "S,0,2.50"}
# Update the dictionary with the appropriate parameters for paired- vs. single-ended assemblies
try:
_ = sample.general.mergedreads
if len(sample.general.trimmedcorrectedfastqfiles) == 2:
indict.update({'m1': sample.general.trimmedcorrectedfastqfiles[0],
'm2': sample.general.trimmedcorrectedfastqfiles[1]})
else:
indict.update({'U': sample.general.trimmedcorrectedfastqfiles[0]})
except AttributeError:
if len(sample.general.assemblyfastq) == 2:
indict.update({'m1': sample.general.assemblyfastq[0],
'm2': sample.general.assemblyfastq[1]})
else:
indict.update({'U': sample.general.assemblyfastq[0]})
bowtie2align = Bowtie2CommandLine(bt2=sagen.bowtie2results,
threads=self.threads,
samtools=samtools,
**indict)
# Convert the commands to strings to allow them to be JSON serialized
sample.commands.bowtie2align = str(bowtie2align)
sample.commands.bowtie2build = str(bowtie2build)
self.bowqueue.put((sample, sample.commands.bowtie2build, sample.commands.bowtie2align))
else:
sample.commands.samtools = "NA"
sample.mapping.MeanInsertSize = 'NA'
sample.mapping.MeanCoveragedata = 'NA'
self.bowqueue.join() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:validate_pages_json_data; 3, parameters; 3, 4; 3, 5; 4, identifier:d; 5, identifier:preferred_lang; 6, block; 6, 7; 6, 9; 6, 16; 6, 20; 6, 38; 6, 54; 6, 63; 6, 85; 6, 91; 6, 375; 7, expression_statement; 7, 8; 8, comment; 9, import_from_statement; 9, 10; 9, 14; 10, relative_import; 10, 11; 10, 12; 11, import_prefix; 12, dotted_name; 12, 13; 13, identifier:models; 14, dotted_name; 14, 15; 15, identifier:Page; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:errors; 19, list:[]; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:seen_complete_slugs; 23, call; 23, 24; 23, 25; 24, identifier:dict; 25, generator_expression; 25, 26; 25, 33; 26, tuple; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:lang; 29, integer:0; 30, call; 30, 31; 30, 32; 31, identifier:set; 32, argument_list; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:lang; 35, attribute; 35, 36; 35, 37; 36, identifier:settings; 37, identifier:PAGE_LANGUAGES; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:valid_templates; 41, call; 41, 42; 41, 43; 42, identifier:set; 43, generator_expression; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:t; 46, integer:0; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:t; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:settings; 52, identifier:get_page_templates; 53, argument_list; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:valid_templates; 58, identifier:add; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:settings; 62, identifier:PAGE_DEFAULT_TEMPLATE; 63, if_statement; 63, 64; 63, 69; 64, comparison_operator:!=; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:d; 67, identifier:JSON_PAGE_EXPORT_NAME; 68, identifier:JSON_PAGE_EXPORT_VERSION; 69, block; 69, 70; 70, return_statement; 70, 71; 71, expression_list; 71, 72; 71, 84; 72, list:[_('Unsupported file version: %s') % repr(
d[JSON_PAGE_EXPORT_NAME])]; 72, 73; 73, binary_operator:%; 73, 74; 73, 78; 74, call; 74, 75; 74, 76; 75, identifier:_; 76, argument_list; 76, 77; 77, string:'Unsupported file version: %s'; 78, call; 78, 79; 78, 80; 79, identifier:repr; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 83; 82, identifier:d; 83, identifier:JSON_PAGE_EXPORT_NAME; 84, list:[]; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:pages; 88, subscript; 88, 89; 88, 90; 89, identifier:d; 90, string:'pages'; 91, for_statement; 91, 92; 91, 93; 91, 94; 91, 95; 92, identifier:p; 93, identifier:pages; 94, comment; 95, block; 95, 96; 95, 108; 95, 112; 95, 218; 95, 244; 95, 263; 95, 287; 95, 300; 95, 313; 95, 338; 95, 351; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:slug; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:p; 103, string:'complete_slug'; 104, identifier:get; 105, argument_list; 105, 106; 105, 107; 106, identifier:preferred_lang; 107, None; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:seen_parent; 111, False; 112, for_statement; 112, 113; 112, 116; 112, 123; 113, pattern_list; 113, 114; 113, 115; 114, identifier:lang; 115, identifier:s; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:p; 120, string:'complete_slug'; 121, identifier:items; 122, argument_list; 123, block; 123, 124; 123, 130; 123, 139; 123, 149; 123, 210; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:not; 125, 126; 125, 127; 126, identifier:lang; 127, identifier:seen_complete_slugs; 128, block; 128, 129; 129, continue_statement; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, subscript; 133, 134; 133, 135; 134, identifier:seen_complete_slugs; 135, identifier:lang; 136, identifier:add; 137, argument_list; 137, 138; 138, identifier:s; 139, if_statement; 139, 140; 139, 143; 139, 144; 140, comparison_operator:not; 140, 141; 140, 142; 141, string:'/'; 142, identifier:s; 143, comment; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:seen_parent; 148, True; 149, if_statement; 149, 150; 149, 152; 150, not_operator; 150, 151; 151, identifier:seen_parent; 152, block; 152, 153; 152, 165; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, pattern_list; 155, 156; 155, 157; 156, identifier:parent_slug; 157, identifier:ignore; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:s; 161, identifier:rsplit; 162, argument_list; 162, 163; 162, 164; 163, string:'/'; 164, integer:1; 165, if_statement; 165, 166; 165, 171; 165, 176; 166, comparison_operator:in; 166, 167; 166, 168; 167, identifier:parent_slug; 168, subscript; 168, 169; 168, 170; 169, identifier:seen_complete_slugs; 170, identifier:lang; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:seen_parent; 175, True; 176, else_clause; 176, 177; 177, block; 177, 178; 177, 193; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:parent; 181, call; 181, 182; 181, 187; 182, attribute; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:Page; 185, identifier:objects; 186, identifier:from_path; 187, argument_list; 187, 188; 187, 189; 187, 190; 188, identifier:parent_slug; 189, identifier:lang; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:exclude_drafts; 192, False; 193, if_statement; 193, 194; 193, 204; 193, 205; 194, boolean_operator:and; 194, 195; 194, 196; 195, identifier:parent; 196, comparison_operator:==; 196, 197; 196, 203; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:parent; 200, identifier:get_complete_slug; 201, argument_list; 201, 202; 202, identifier:lang; 203, identifier:parent_slug; 204, comment; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:seen_parent; 209, True; 210, if_statement; 210, 211; 210, 213; 211, not_operator; 211, 212; 212, identifier:slug; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:slug; 217, identifier:s; 218, if_statement; 218, 219; 218, 221; 219, not_operator; 219, 220; 220, identifier:slug; 221, block; 221, 222; 221, 243; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:errors; 226, identifier:append; 227, argument_list; 227, 228; 228, binary_operator:%; 228, 229; 228, 233; 229, call; 229, 230; 229, 231; 230, identifier:_; 231, argument_list; 231, 232; 232, string:"%s has no common language with this site"; 233, tuple; 233, 234; 234, subscript; 234, 235; 234, 242; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:p; 239, string:'complete_slug'; 240, identifier:values; 241, argument_list; 242, integer:0; 243, continue_statement; 244, if_statement; 244, 245; 244, 247; 245, not_operator; 245, 246; 246, identifier:seen_parent; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:errors; 252, identifier:append; 253, argument_list; 253, 254; 254, binary_operator:%; 254, 255; 254, 261; 255, call; 255, 256; 255, 257; 256, identifier:_; 257, argument_list; 257, 258; 258, concatenated_string; 258, 259; 258, 260; 259, string:"%s did not include its parent page and a matching"; 260, string:" one was not found on this site"; 261, tuple; 261, 262; 262, identifier:slug; 263, if_statement; 263, 264; 263, 269; 264, comparison_operator:not; 264, 265; 264, 268; 265, subscript; 265, 266; 265, 267; 266, identifier:p; 267, string:'template'; 268, identifier:valid_templates; 269, block; 269, 270; 269, 286; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:errors; 274, identifier:append; 275, argument_list; 275, 276; 276, binary_operator:%; 276, 277; 276, 281; 277, call; 277, 278; 277, 279; 278, identifier:_; 279, argument_list; 279, 280; 280, string:"%s uses a template not found on this site: %s"; 281, tuple; 281, 282; 281, 283; 282, identifier:slug; 283, subscript; 283, 284; 283, 285; 284, identifier:p; 285, string:'template'; 286, continue_statement; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:import_fields; 290, call; 290, 291; 290, 292; 291, identifier:set; 292, argument_list; 292, 293; 293, call; 293, 294; 293, 299; 294, attribute; 294, 295; 294, 298; 295, subscript; 295, 296; 295, 297; 296, identifier:p; 297, string:'content'; 298, identifier:keys; 299, argument_list; 300, expression_statement; 300, 301; 301, augmented_assignment:|=; 301, 302; 301, 303; 302, identifier:import_fields; 303, call; 303, 304; 303, 305; 304, identifier:set; 305, argument_list; 305, 306; 306, tuple; 306, 307; 306, 308; 306, 309; 306, 310; 306, 311; 306, 312; 307, string:'meta_title'; 308, string:'meta_description'; 309, string:'meta_keywords'; 310, string:'meta_author'; 311, string:'fb_page_type'; 312, string:'fb_image'; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:template_fields; 316, call; 316, 317; 316, 318; 317, identifier:set; 318, generator_expression; 318, 319; 318, 322; 318, 330; 319, attribute; 319, 320; 319, 321; 320, identifier:p; 321, identifier:name; 322, for_in_clause; 322, 323; 322, 324; 323, identifier:p; 324, call; 324, 325; 324, 326; 325, identifier:get_placeholders; 326, argument_list; 326, 327; 327, subscript; 327, 328; 327, 329; 328, identifier:p; 329, string:'template'; 330, if_clause; 330, 331; 331, comparison_operator:not; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:p; 334, identifier:name; 335, tuple; 335, 336; 335, 337; 336, string:'title'; 337, string:'slug'; 338, expression_statement; 338, 339; 339, augmented_assignment:|=; 339, 340; 339, 341; 340, identifier:template_fields; 341, call; 341, 342; 341, 343; 342, identifier:set; 343, argument_list; 343, 344; 344, tuple; 344, 345; 344, 346; 344, 347; 344, 348; 344, 349; 344, 350; 345, string:'meta_title'; 346, string:'meta_description'; 347, string:'meta_keywords'; 348, string:'meta_author'; 349, string:'fb_page_type'; 350, string:'fb_image'; 351, if_statement; 351, 352; 351, 355; 352, comparison_operator:!=; 352, 353; 352, 354; 353, identifier:template_fields; 354, identifier:import_fields; 355, block; 355, 356; 355, 374; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:errors; 360, identifier:append; 361, argument_list; 361, 362; 362, binary_operator:%; 362, 363; 362, 369; 363, call; 363, 364; 363, 365; 364, identifier:_; 365, argument_list; 365, 366; 366, concatenated_string; 366, 367; 366, 368; 367, string:"%s template contents are different than our "; 368, string:"template: %s"; 369, tuple; 369, 370; 369, 371; 370, identifier:slug; 371, subscript; 371, 372; 371, 373; 372, identifier:p; 373, string:'template'; 374, continue_statement; 375, return_statement; 375, 376; 376, identifier:errors | def validate_pages_json_data(d, preferred_lang):
"""
Check if an import of d will succeed, and return errors.
errors is a list of strings. The import should proceed only if errors
is empty.
"""
from .models import Page
errors = []
seen_complete_slugs = dict(
(lang[0], set()) for lang in settings.PAGE_LANGUAGES)
valid_templates = set(t[0] for t in settings.get_page_templates())
valid_templates.add(settings.PAGE_DEFAULT_TEMPLATE)
if d[JSON_PAGE_EXPORT_NAME] != JSON_PAGE_EXPORT_VERSION:
return [_('Unsupported file version: %s') % repr(
d[JSON_PAGE_EXPORT_NAME])], []
pages = d['pages']
for p in pages:
# use the complete slug as a way to identify pages in errors
slug = p['complete_slug'].get(preferred_lang, None)
seen_parent = False
for lang, s in p['complete_slug'].items():
if lang not in seen_complete_slugs:
continue
seen_complete_slugs[lang].add(s)
if '/' not in s: # root level, no parent req'd
seen_parent = True
if not seen_parent:
parent_slug, ignore = s.rsplit('/', 1)
if parent_slug in seen_complete_slugs[lang]:
seen_parent = True
else:
parent = Page.objects.from_path(parent_slug, lang,
exclude_drafts=False)
if parent and parent.get_complete_slug(lang) == parent_slug:
# parent not included, but exists on site
seen_parent = True
if not slug:
slug = s
if not slug:
errors.append(_("%s has no common language with this site")
% (p['complete_slug'].values()[0],))
continue
if not seen_parent:
errors.append(_("%s did not include its parent page and a matching"
" one was not found on this site") % (slug,))
if p['template'] not in valid_templates:
errors.append(_("%s uses a template not found on this site: %s")
% (slug, p['template']))
continue
import_fields = set(p['content'].keys())
import_fields |= set(('meta_title', 'meta_description', 'meta_keywords', 'meta_author', 'fb_page_type', 'fb_image'))
template_fields = set(p.name for p in get_placeholders(p['template']) if
p.name not in ('title', 'slug'))
template_fields |= set(('meta_title', 'meta_description', 'meta_keywords', 'meta_author', 'fb_page_type', 'fb_image'))
if template_fields != import_fields:
errors.append(_("%s template contents are different than our "
"template: %s") % (slug, p['template']))
continue
return errors |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:import_po_files; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:path; 6, string:'poexport'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:stdout; 9, None; 10, block; 10, 11; 10, 13; 10, 16; 10, 24; 10, 30; 10, 34; 10, 38; 10, 60; 10, 74; 10, 87; 10, 257; 10, 267; 11, expression_statement; 11, 12; 12, comment; 13, import_statement; 13, 14; 14, dotted_name; 14, 15; 15, identifier:polib; 16, import_from_statement; 16, 17; 16, 20; 16, 22; 17, dotted_name; 17, 18; 17, 19; 18, identifier:basic_cms; 19, identifier:models; 20, dotted_name; 20, 21; 21, identifier:Page; 22, dotted_name; 22, 23; 23, identifier:Content; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:source_language; 27, attribute; 27, 28; 27, 29; 28, identifier:settings; 29, identifier:PAGE_DEFAULT_LANGUAGE; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:source_list; 33, list:[]; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:pages_to_invalidate; 37, list:[]; 38, for_statement; 38, 39; 38, 40; 38, 47; 39, identifier:page; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:Page; 44, identifier:objects; 45, identifier:published; 46, argument_list; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:source_list; 52, identifier:extend; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:page; 57, identifier:content_by_language; 58, argument_list; 58, 59; 59, identifier:source_language; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:stdout; 63, None; 64, block; 64, 65; 64, 68; 65, import_statement; 65, 66; 66, dotted_name; 66, 67; 67, identifier:sys; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:stdout; 71, attribute; 71, 72; 71, 73; 72, identifier:sys; 73, identifier:stdout; 74, if_statement; 74, 75; 74, 82; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:path; 79, identifier:endswith; 80, argument_list; 80, 81; 81, string:'/'; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, augmented_assignment:+=; 84, 85; 84, 86; 85, identifier:path; 86, string:'/'; 87, for_statement; 87, 88; 87, 89; 87, 92; 88, identifier:lang; 89, attribute; 89, 90; 89, 91; 90, identifier:settings; 91, identifier:PAGE_LANGUAGES; 92, block; 92, 93; 93, if_statement; 93, 94; 93, 101; 94, comparison_operator:!=; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:lang; 97, integer:0; 98, attribute; 98, 99; 98, 100; 99, identifier:settings; 100, identifier:PAGE_DEFAULT_LANGUAGE; 101, block; 101, 102; 101, 113; 101, 123; 101, 132; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:stdout; 106, identifier:write; 107, argument_list; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"Update language %s.\n"; 110, subscript; 110, 111; 110, 112; 111, identifier:lang; 112, integer:0; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:po_path; 116, binary_operator:+; 116, 117; 116, 122; 117, binary_operator:+; 117, 118; 117, 119; 118, identifier:path; 119, subscript; 119, 120; 119, 121; 120, identifier:lang; 121, integer:0; 122, string:'.po'; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:po; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:polib; 129, identifier:pofile; 130, argument_list; 130, 131; 131, identifier:po_path; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:entry; 134, identifier:po; 135, block; 135, 136; 135, 154; 135, 167; 135, 183; 135, 196; 135, 211; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:meta_data; 139, call; 139, 140; 139, 152; 140, attribute; 140, 141; 140, 151; 141, subscript; 141, 142; 141, 150; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:entry; 146, identifier:tcomment; 147, identifier:split; 148, argument_list; 148, 149; 149, identifier:do_not_msg; 150, integer:1; 151, identifier:split; 152, argument_list; 152, 153; 153, string:"\n"; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:placeholder_name; 157, subscript; 157, 158; 157, 166; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:meta_data; 162, integer:1; 163, identifier:split; 164, argument_list; 164, 165; 165, string:'='; 166, integer:1; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:page_id; 170, call; 170, 171; 170, 172; 171, identifier:int; 172, argument_list; 172, 173; 173, subscript; 173, 174; 173, 182; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:meta_data; 178, integer:2; 179, identifier:split; 180, argument_list; 180, 181; 181, string:'='; 182, integer:1; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:page; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:Page; 190, identifier:objects; 191, identifier:get; 192, argument_list; 192, 193; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:id; 195, identifier:page_id; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:current_content; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:Content; 203, identifier:objects; 204, identifier:get_content; 205, argument_list; 205, 206; 205, 207; 205, 210; 206, identifier:page; 207, subscript; 207, 208; 207, 209; 208, identifier:lang; 209, integer:0; 210, identifier:placeholder_name; 211, if_statement; 211, 212; 211, 217; 212, comparison_operator:!=; 212, 213; 212, 214; 213, identifier:current_content; 214, attribute; 214, 215; 214, 216; 215, identifier:entry; 216, identifier:msgstr; 217, block; 217, 218; 217, 229; 217, 245; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:stdout; 222, identifier:write; 223, argument_list; 223, 224; 224, binary_operator:%; 224, 225; 224, 226; 225, string:"Update page %d placeholder %s.\n"; 226, tuple; 226, 227; 226, 228; 227, identifier:page_id; 228, identifier:placeholder_name; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 236; 231, attribute; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:Content; 234, identifier:objects; 235, identifier:create_content_if_changed; 236, argument_list; 236, 237; 236, 238; 236, 241; 236, 242; 237, identifier:page; 238, subscript; 238, 239; 238, 240; 239, identifier:lang; 240, integer:0; 241, identifier:placeholder_name; 242, attribute; 242, 243; 242, 244; 243, identifier:entry; 244, identifier:msgstr; 245, if_statement; 245, 246; 245, 249; 246, comparison_operator:not; 246, 247; 246, 248; 247, identifier:page; 248, identifier:pages_to_invalidate; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:pages_to_invalidate; 254, identifier:append; 255, argument_list; 255, 256; 256, identifier:page; 257, for_statement; 257, 258; 257, 259; 257, 260; 258, identifier:page; 259, identifier:pages_to_invalidate; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:page; 265, identifier:invalidate; 266, argument_list; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:stdout; 271, identifier:write; 272, argument_list; 272, 273; 273, binary_operator:%; 273, 274; 273, 275; 274, string:"Import finished from %s.\n"; 275, identifier:path | def import_po_files(path='poexport', stdout=None):
"""
Import all the content updates from the po files into
the pages.
"""
import polib
from basic_cms.models import Page, Content
source_language = settings.PAGE_DEFAULT_LANGUAGE
source_list = []
pages_to_invalidate = []
for page in Page.objects.published():
source_list.extend(page.content_by_language(source_language))
if stdout is None:
import sys
stdout = sys.stdout
if not path.endswith('/'):
path += '/'
for lang in settings.PAGE_LANGUAGES:
if lang[0] != settings.PAGE_DEFAULT_LANGUAGE:
stdout.write("Update language %s.\n" % lang[0])
po_path = path + lang[0] + '.po'
po = polib.pofile(po_path)
for entry in po:
meta_data = entry.tcomment.split(do_not_msg)[1].split("\n")
placeholder_name = meta_data[1].split('=')[1]
page_id = int(meta_data[2].split('=')[1])
page = Page.objects.get(id=page_id)
current_content = Content.objects.get_content(page, lang[0],
placeholder_name)
if current_content != entry.msgstr:
stdout.write("Update page %d placeholder %s.\n" % (page_id,
placeholder_name))
Content.objects.create_content_if_changed(
page, lang[0], placeholder_name, entry.msgstr)
if page not in pages_to_invalidate:
pages_to_invalidate.append(page)
for page in pages_to_invalidate:
page.invalidate()
stdout.write("Import finished from %s.\n" % path) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_scene_suggestions; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:current; 6, block; 6, 7; 6, 9; 6, 13; 6, 31; 6, 47; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:l; 12, list:[]; 13, if_statement; 13, 14; 13, 23; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:current; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:djadapter; 21, identifier:models; 22, identifier:Asset; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:l; 28, identifier:append; 29, argument_list; 29, 30; 30, identifier:current; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:l; 35, identifier:extend; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:list; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:current; 44, identifier:assets; 45, identifier:all; 46, argument_list; 47, return_statement; 47, 48; 48, identifier:l | def get_scene_suggestions(self, current):
"""Return a list with elements for reftracks for the current scene with this type.
For every element returned, the reftrack system will create a :class:`Reftrack` with the type
of this interface, if it is not already in the scene.
E.g. if you have a type that references whole scenes, you might suggest all
linked assets for shots, and all liked assets plus the current element itself for assets.
If you have a type like shader, that usually need a parent, you would return an empty list.
Cameras might only make sense for shots and not for assets etc.
Do not confuse this with :meth:`ReftypeInterface.get_suggestions`. It will gather suggestions
for children of a :class:`Reftrack`.
The standard implementation only returns an empty list!
:param reftrack: the reftrack which needs suggestions
:type reftrack: :class:`Reftrack`
:returns: list of suggestions, tuples of type and element.
:rtype: list
:raises: None
"""
l = []
if isinstance(current, djadapter.models.Asset):
l.append(current)
l.extend(list(current.assets.all()))
return l |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:assert_variable_type; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:variable; 5, identifier:expected_type; 6, default_parameter; 6, 7; 6, 8; 7, identifier:raise_exception; 8, True; 9, block; 9, 10; 9, 12; 9, 13; 9, 26; 9, 27; 9, 49; 9, 50; 9, 68; 9, 69; 9, 70; 9, 132; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, if_statement; 13, 14; 13, 20; 14, not_operator; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:expected_type; 19, identifier:list; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:expected_type; 24, list:[expected_type]; 24, 25; 25, identifier:expected_type; 26, comment; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:t; 29, identifier:expected_type; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 38; 32, not_operator; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:isinstance; 35, argument_list; 35, 36; 35, 37; 36, identifier:t; 37, identifier:type; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:ValueError; 42, argument_list; 42, 43; 43, binary_operator:%; 43, 44; 43, 45; 44, string:'expected_type argument "%s" is not a type'; 45, call; 45, 46; 45, 47; 46, identifier:str; 47, argument_list; 47, 48; 48, identifier:t; 49, comment; 50, if_statement; 50, 51; 50, 57; 51, not_operator; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:isinstance; 54, argument_list; 54, 55; 54, 56; 55, identifier:raise_exception; 56, identifier:bool; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ValueError; 61, argument_list; 61, 62; 62, binary_operator:%; 62, 63; 62, 64; 63, string:'raise_exception argument "%s" is not a bool'; 64, call; 64, 65; 64, 66; 65, identifier:str; 66, argument_list; 66, 67; 67, identifier:raise_exception; 68, comment; 69, comment; 70, if_statement; 70, 71; 70, 87; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, list_comprehension; 75, 76; 75, 78; 75, 81; 76, parenthesized_expression; 76, 77; 77, identifier:t; 78, for_in_clause; 78, 79; 78, 80; 79, identifier:t; 80, identifier:expected_type; 81, if_clause; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:isinstance; 84, argument_list; 84, 85; 84, 86; 85, identifier:variable; 86, identifier:t; 87, block; 87, 88; 87, 118; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:error_message; 91, binary_operator:%; 91, 92; 91, 93; 92, string:'"%s" is not an instance of type %s. It is of type %s'; 93, tuple; 93, 94; 93, 98; 93, 111; 94, call; 94, 95; 94, 96; 95, identifier:str; 96, argument_list; 96, 97; 97, identifier:variable; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, string:' or '; 101, identifier:join; 102, argument_list; 102, 103; 103, list_comprehension; 103, 104; 103, 108; 104, call; 104, 105; 104, 106; 105, identifier:str; 106, argument_list; 106, 107; 107, identifier:t; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:t; 110, identifier:expected_type; 111, call; 111, 112; 111, 113; 112, identifier:str; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:type; 116, argument_list; 116, 117; 117, identifier:variable; 118, if_statement; 118, 119; 118, 120; 118, 126; 119, identifier:raise_exception; 120, block; 120, 121; 121, raise_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:ValueError; 124, argument_list; 124, 125; 125, identifier:error_message; 126, else_clause; 126, 127; 127, block; 127, 128; 128, return_statement; 128, 129; 129, expression_list; 129, 130; 129, 131; 130, False; 131, identifier:error_message; 132, return_statement; 132, 133; 133, expression_list; 133, 134; 133, 135; 134, True; 135, None | def assert_variable_type(variable, expected_type, raise_exception=True):
"""Return True if a variable is of a certain type or types.
Otherwise raise a ValueError exception.
Positional arguments:
variable -- the variable to be checked
expected_type -- the expected type or types of the variable
raise_exception -- whether to raise an exception or just return
False on failure, with error message
"""
# if expected type is not a list make it one
if not isinstance(expected_type, list):
expected_type = [expected_type]
# make sure all entries in the expected_type list are types
for t in expected_type:
if not isinstance(t, type):
raise ValueError('expected_type argument "%s" is not a type' %str(t))
# make sure raise_exception is a bool
if not isinstance(raise_exception, bool):
raise ValueError('raise_exception argument "%s" is not a bool' %str(raise_exception))
# check the type of the variable against the list
# then raise an exception or return True
if not len([(t) for t in expected_type if isinstance(variable, t)]):
error_message = '"%s" is not an instance of type %s. It is of type %s' %(str(variable),' or '.join([str(t) for t in expected_type]), str(type(variable)))
if raise_exception:
raise ValueError(error_message)
else:
return False, error_message
return True, None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, while_statement; 8, 9; 8, 17; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:stopped; 15, identifier:isSet; 16, argument_list; 17, block; 17, 18; 18, try_statement; 18, 19; 18, 20; 18, 21; 18, 22; 18, 167; 19, comment; 20, comment; 21, comment; 22, block; 22, 23; 22, 36; 22, 58; 22, 76; 22, 87; 22, 114; 22, 126; 22, 137; 22, 138; 22, 139; 22, 140; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:timeout; 26, boolean_operator:or; 26, 27; 26, 35; 27, boolean_operator:and; 27, 28; 27, 34; 28, parenthesized_expression; 28, 29; 29, comparison_operator:!=; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_state; 33, string:'idle'; 34, float:0.2; 35, None; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 42; 38, pattern_list; 38, 39; 38, 40; 38, 41; 39, identifier:rdlist; 40, identifier:_; 41, identifier:_; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:select; 45, identifier:select; 46, argument_list; 46, 47; 46, 55; 46, 56; 46, 57; 47, list:[self._socket.fileno()]; 47, 48; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_socket; 53, identifier:fileno; 54, argument_list; 55, list:[]; 56, list:[]; 57, identifier:timeout; 58, if_statement; 58, 59; 58, 61; 59, not_operator; 59, 60; 60, identifier:rdlist; 61, block; 61, 62; 61, 75; 62, if_statement; 62, 63; 62, 68; 63, comparison_operator:!=; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_state; 67, string:'idle'; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_state; 74, string:'idle'; 75, continue_statement; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:data; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_socket; 84, identifier:recv; 85, argument_list; 85, 86; 86, integer:1024; 87, if_statement; 87, 88; 87, 90; 87, 91; 88, not_operator; 88, 89; 89, identifier:data; 90, comment; 91, block; 91, 92; 91, 113; 92, try_statement; 92, 93; 92, 107; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:os; 98, identifier:fstat; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:recv; 104, identifier:_socket; 105, identifier:fileno; 106, argument_list; 107, except_clause; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:socket; 110, identifier:error; 111, block; 111, 112; 112, break_statement; 113, continue_statement; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:code; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:utils; 120, identifier:mangleIR; 121, argument_list; 121, 122; 121, 123; 122, identifier:data; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:ignore_errors; 125, True; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:codeName; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:codeMap; 134, identifier:get; 135, argument_list; 135, 136; 136, identifier:code; 137, comment; 138, comment; 139, comment; 140, if_statement; 140, 141; 140, 149; 141, boolean_operator:and; 141, 142; 141, 143; 142, identifier:codeName; 143, parenthesized_expression; 143, 144; 144, comparison_operator:!=; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:_state; 148, identifier:codeName; 149, block; 149, 150; 149, 156; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_state; 155, identifier:codeName; 156, for_statement; 156, 157; 156, 158; 156, 161; 157, identifier:callback; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_callbacks; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:callback; 165, argument_list; 165, 166; 166, identifier:codeName; 167, except_clause; 167, 168; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:time; 173, identifier:sleep; 174, argument_list; 174, 175; 175, float:0.1 | def run(self):
"""Main loop of KIRA thread."""
while not self.stopped.isSet():
try:
# if the current state is idle, just block and wait forever
# if the current state is any other state, then a timeout of 200ms should
# be reasonable in all cases.
timeout = (self._state != 'idle') and 0.2 or None
rdlist, _, _ = select.select([self._socket.fileno()], [], [], timeout)
if not rdlist:
if self._state != 'idle':
self._state = 'idle'
continue
data = self._socket.recv(1024)
if not data:
# check if the socket is still valid
try:
os.fstat(recv._socket.fileno())
except socket.error:
break
continue
code = utils.mangleIR(data, ignore_errors=True)
codeName = self.codeMap.get(code)
# some manufacturers repeat their IR codes several times in rapid
# succession. by tracking the last code, we can eliminate redundant
# state changes
if codeName and (self._state != codeName):
self._state = codeName
for callback in self._callbacks:
callback(codeName)
except:
time.sleep(0.1) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_inc; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:native; 7, False; 8, block; 8, 9; 8, 11; 8, 69; 8, 169; 8, 258; 8, 269; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 17; 12, comparison_operator:==; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:sdk_version; 16, string:'v7.0A'; 17, block; 17, 18; 17, 32; 17, 56; 17, 67; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:include; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:os; 25, identifier:path; 26, identifier:join; 27, argument_list; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:sdk_dir; 31, string:'include'; 32, if_statement; 32, 33; 32, 41; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:os; 37, identifier:path; 38, identifier:isdir; 39, argument_list; 39, 40; 40, identifier:include; 41, block; 41, 42; 41, 53; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:logging; 46, identifier:info; 47, argument_list; 47, 48; 47, 52; 48, call; 48, 49; 48, 50; 49, identifier:_; 50, argument_list; 50, 51; 51, string:'using include: %s'; 52, identifier:include; 53, return_statement; 53, 54; 54, list:[include]; 54, 55; 55, identifier:include; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:logging; 60, identifier:debug; 61, argument_list; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:_; 64, argument_list; 64, 65; 65, string:'include not found: %s'; 66, identifier:include; 67, return_statement; 67, 68; 68, list:[]; 69, if_statement; 69, 70; 69, 75; 70, comparison_operator:==; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:sdk_version; 74, string:'v8.1'; 75, block; 75, 76; 75, 80; 75, 107; 75, 167; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:dirs; 79, list:[]; 80, if_statement; 80, 81; 80, 82; 80, 98; 81, identifier:native; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:parts; 86, list:['km', os.path.join('km', 'crt'), 'shared']; 86, 87; 86, 88; 86, 97; 87, string:'km'; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:os; 92, identifier:path; 93, identifier:join; 94, argument_list; 94, 95; 94, 96; 95, string:'km'; 96, string:'crt'; 97, string:'shared'; 98, else_clause; 98, 99; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:parts; 103, list:['um', 'winrt', 'shared']; 103, 104; 103, 105; 103, 106; 104, string:'um'; 105, string:'winrt'; 106, string:'shared'; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:part; 109, identifier:parts; 110, block; 110, 111; 110, 126; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:include; 114, call; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:os; 118, identifier:path; 119, identifier:join; 120, argument_list; 120, 121; 120, 124; 120, 125; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:sdk_dir; 124, string:'include'; 125, identifier:part; 126, if_statement; 126, 127; 126, 135; 126, 154; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:os; 131, identifier:path; 132, identifier:isdir; 133, argument_list; 133, 134; 134, identifier:include; 135, block; 135, 136; 135, 147; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:logging; 140, identifier:info; 141, argument_list; 141, 142; 141, 146; 142, call; 142, 143; 142, 144; 143, identifier:_; 144, argument_list; 144, 145; 145, string:'using include: %s'; 146, identifier:include; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:dirs; 151, identifier:append; 152, argument_list; 152, 153; 153, identifier:include; 154, else_clause; 154, 155; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:logging; 160, identifier:debug; 161, argument_list; 161, 162; 161, 166; 162, call; 162, 163; 162, 164; 163, identifier:_; 164, argument_list; 164, 165; 165, string:'inc not found: %s'; 166, identifier:include; 167, return_statement; 167, 168; 168, identifier:dirs; 169, if_statement; 169, 170; 169, 175; 170, comparison_operator:==; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:sdk_version; 174, string:'v10.0'; 175, block; 175, 176; 175, 180; 175, 192; 175, 256; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:dirs; 179, list:[]; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:extra; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:os; 187, identifier:path; 188, identifier:join; 189, argument_list; 189, 190; 189, 191; 190, string:'include'; 191, string:'10.0.10240.0'; 192, for_statement; 192, 193; 192, 194; 192, 199; 193, identifier:mode; 194, list:['um', 'ucrt', 'shared', 'winrt']; 194, 195; 194, 196; 194, 197; 194, 198; 195, string:'um'; 196, string:'ucrt'; 197, string:'shared'; 198, string:'winrt'; 199, block; 199, 200; 199, 215; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:include; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:os; 207, identifier:path; 208, identifier:join; 209, argument_list; 209, 210; 209, 213; 209, 214; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:sdk_dir; 213, identifier:extra; 214, identifier:mode; 215, if_statement; 215, 216; 215, 224; 215, 243; 216, call; 216, 217; 216, 222; 217, attribute; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:os; 220, identifier:path; 221, identifier:isdir; 222, argument_list; 222, 223; 223, identifier:include; 224, block; 224, 225; 224, 236; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:logging; 229, identifier:info; 230, argument_list; 230, 231; 230, 235; 231, call; 231, 232; 231, 233; 232, identifier:_; 233, argument_list; 233, 234; 234, string:'using include: %s'; 235, identifier:include; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:dirs; 240, identifier:append; 241, argument_list; 241, 242; 242, identifier:include; 243, else_clause; 243, 244; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:logging; 249, identifier:debug; 250, argument_list; 250, 251; 250, 255; 251, call; 251, 252; 251, 253; 252, identifier:_; 253, argument_list; 253, 254; 254, string:'inc not found: %s'; 255, identifier:include; 256, return_statement; 256, 257; 257, identifier:dirs; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:message; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, string:'unknown sdk version: {}'; 264, identifier:format; 265, argument_list; 265, 266; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:sdk_version; 269, raise_statement; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:RuntimeError; 272, argument_list; 272, 273; 273, identifier:message | def get_inc(self, native=False):
"""
Get include directories of Windows SDK.
"""
if self.sdk_version == 'v7.0A':
include = os.path.join(self.sdk_dir, 'include')
if os.path.isdir(include):
logging.info(_('using include: %s'), include)
return [include]
logging.debug(_('include not found: %s'), include)
return []
if self.sdk_version == 'v8.1':
dirs = []
if native:
parts = ['km', os.path.join('km', 'crt'), 'shared']
else:
parts = ['um', 'winrt', 'shared']
for part in parts:
include = os.path.join(self.sdk_dir, 'include', part)
if os.path.isdir(include):
logging.info(_('using include: %s'), include)
dirs.append(include)
else:
logging.debug(_('inc not found: %s'), include)
return dirs
if self.sdk_version == 'v10.0':
dirs = []
extra = os.path.join('include', '10.0.10240.0')
for mode in ['um', 'ucrt', 'shared', 'winrt']:
include = os.path.join(self.sdk_dir, extra, mode)
if os.path.isdir(include):
logging.info(_('using include: %s'), include)
dirs.append(include)
else:
logging.debug(_('inc not found: %s'), include)
return dirs
message = 'unknown sdk version: {}'.format(self.sdk_version)
raise RuntimeError(message) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_lib; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:arch; 7, string:'x86'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:native; 10, False; 11, block; 11, 12; 11, 14; 11, 82; 11, 171; 11, 259; 11, 270; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 20; 15, comparison_operator:==; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:sdk_version; 19, string:'v7.0A'; 20, block; 20, 21; 20, 30; 20, 45; 20, 69; 20, 80; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:==; 22, 23; 22, 24; 23, identifier:arch; 24, string:'x86'; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:arch; 29, string:''; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:lib; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:os; 37, identifier:path; 38, identifier:join; 39, argument_list; 39, 40; 39, 43; 39, 44; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:sdk_dir; 43, string:'lib'; 44, identifier:arch; 45, if_statement; 45, 46; 45, 54; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:os; 50, identifier:path; 51, identifier:isdir; 52, argument_list; 52, 53; 53, identifier:lib; 54, block; 54, 55; 54, 66; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logging; 59, identifier:info; 60, argument_list; 60, 61; 60, 65; 61, call; 61, 62; 61, 63; 62, identifier:_; 63, argument_list; 63, 64; 64, string:'using lib: %s'; 65, identifier:lib; 66, return_statement; 66, 67; 67, list:[lib]; 67, 68; 68, identifier:lib; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:logging; 73, identifier:debug; 74, argument_list; 74, 75; 74, 79; 75, call; 75, 76; 75, 77; 76, identifier:_; 77, argument_list; 77, 78; 78, string:'lib not found: %s'; 79, identifier:lib; 80, return_statement; 80, 81; 81, list:[]; 82, if_statement; 82, 83; 82, 88; 83, comparison_operator:==; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:sdk_version; 87, string:'v8.1'; 88, block; 88, 89; 88, 118; 88, 134; 88, 158; 88, 169; 89, if_statement; 89, 90; 89, 91; 89, 104; 90, identifier:native; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:extra; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:os; 99, identifier:path; 100, identifier:join; 101, argument_list; 101, 102; 101, 103; 102, string:'winv6.3'; 103, string:'km'; 104, else_clause; 104, 105; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:extra; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:os; 113, identifier:path; 114, identifier:join; 115, argument_list; 115, 116; 115, 117; 116, string:'winv6.3'; 117, string:'um'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:lib; 121, call; 121, 122; 121, 127; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:os; 125, identifier:path; 126, identifier:join; 127, argument_list; 127, 128; 127, 131; 127, 132; 127, 133; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:sdk_dir; 131, string:'lib'; 132, identifier:extra; 133, identifier:arch; 134, if_statement; 134, 135; 134, 143; 135, call; 135, 136; 135, 141; 136, attribute; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:os; 139, identifier:path; 140, identifier:isdir; 141, argument_list; 141, 142; 142, identifier:lib; 143, block; 143, 144; 143, 155; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:logging; 148, identifier:info; 149, argument_list; 149, 150; 149, 154; 150, call; 150, 151; 150, 152; 151, identifier:_; 152, argument_list; 152, 153; 153, string:'using lib: %s'; 154, identifier:lib; 155, return_statement; 155, 156; 156, list:[lib]; 156, 157; 157, identifier:lib; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:logging; 162, identifier:debug; 163, argument_list; 163, 164; 163, 168; 164, call; 164, 165; 164, 166; 165, identifier:_; 166, argument_list; 166, 167; 167, string:'lib not found: %s'; 168, identifier:lib; 169, return_statement; 169, 170; 170, list:[]; 171, if_statement; 171, 172; 171, 177; 172, comparison_operator:==; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:sdk_version; 176, string:'v10.0'; 177, block; 177, 178; 177, 182; 177, 194; 177, 257; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:dirs; 181, list:[]; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:extra; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:os; 189, identifier:path; 190, identifier:join; 191, argument_list; 191, 192; 191, 193; 192, string:'lib'; 193, string:'10.0.10240.0'; 194, for_statement; 194, 195; 194, 196; 194, 199; 195, identifier:mode; 196, list:['um', 'ucrt']; 196, 197; 196, 198; 197, string:'um'; 198, string:'ucrt'; 199, block; 199, 200; 199, 216; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:lib; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:os; 207, identifier:path; 208, identifier:join; 209, argument_list; 209, 210; 209, 213; 209, 214; 209, 215; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:sdk_dir; 213, identifier:extra; 214, identifier:mode; 215, identifier:arch; 216, if_statement; 216, 217; 216, 225; 216, 244; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:os; 221, identifier:path; 222, identifier:isdir; 223, argument_list; 223, 224; 224, identifier:lib; 225, block; 225, 226; 225, 237; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:logging; 230, identifier:info; 231, argument_list; 231, 232; 231, 236; 232, call; 232, 233; 232, 234; 233, identifier:_; 234, argument_list; 234, 235; 235, string:'using lib: %s'; 236, identifier:lib; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:dirs; 241, identifier:append; 242, argument_list; 242, 243; 243, identifier:lib; 244, else_clause; 244, 245; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:logging; 250, identifier:debug; 251, argument_list; 251, 252; 251, 256; 252, call; 252, 253; 252, 254; 253, identifier:_; 254, argument_list; 254, 255; 255, string:'lib not found: %s'; 256, identifier:lib; 257, return_statement; 257, 258; 258, identifier:dirs; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:message; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, string:'unknown sdk version: {}'; 265, identifier:format; 266, argument_list; 266, 267; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:sdk_version; 270, raise_statement; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:RuntimeError; 273, argument_list; 273, 274; 274, identifier:message | def get_lib(self, arch='x86', native=False):
"""
Get lib directories of Windows SDK.
"""
if self.sdk_version == 'v7.0A':
if arch == 'x86':
arch = ''
lib = os.path.join(self.sdk_dir, 'lib', arch)
if os.path.isdir(lib):
logging.info(_('using lib: %s'), lib)
return [lib]
logging.debug(_('lib not found: %s'), lib)
return []
if self.sdk_version == 'v8.1':
if native:
extra = os.path.join('winv6.3', 'km')
else:
extra = os.path.join('winv6.3', 'um')
lib = os.path.join(self.sdk_dir, 'lib', extra, arch)
if os.path.isdir(lib):
logging.info(_('using lib: %s'), lib)
return [lib]
logging.debug(_('lib not found: %s'), lib)
return []
if self.sdk_version == 'v10.0':
dirs = []
extra = os.path.join('lib', '10.0.10240.0')
for mode in ['um', 'ucrt']:
lib = os.path.join(self.sdk_dir, extra, mode, arch)
if os.path.isdir(lib):
logging.info(_('using lib: %s'), lib)
dirs.append(lib)
else:
logging.debug(_('lib not found: %s'), lib)
return dirs
message = 'unknown sdk version: {}'.format(self.sdk_version)
raise RuntimeError(message) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:interrogate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:platformIdentifier; 6, identifier:configuration; 7, identifier:libraries; 8, default_parameter; 8, 9; 8, 10; 9, identifier:libOverrides; 10, dictionary; 11, block; 11, 12; 11, 14; 11, 15; 11, 30; 11, 31; 11, 37; 11, 342; 11, 343; 11, 360; 11, 371; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:libModules; 18, call; 18, 19; 18, 20; 19, identifier:list; 20, argument_list; 20, 21; 21, list_comprehension; 21, 22; 21, 23; 21, 26; 22, identifier:lib; 23, for_in_clause; 23, 24; 23, 25; 24, identifier:lib; 25, identifier:libraries; 26, if_clause; 26, 27; 27, comparison_operator:not; 27, 28; 27, 29; 28, identifier:lib; 29, identifier:libOverrides; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:details; 34, call; 34, 35; 34, 36; 35, identifier:ThirdPartyLibraryDetails; 36, argument_list; 37, if_statement; 37, 38; 37, 44; 37, 45; 38, comparison_operator:>; 38, 39; 38, 43; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, identifier:libModules; 43, integer:0; 44, comment; 45, block; 45, 46; 45, 56; 45, 57; 45, 71; 45, 72; 45, 82; 45, 98; 45, 120; 45, 121; 45, 207; 45, 208; 45, 219; 45, 223; 45, 258; 45, 259; 45, 265; 45, 279; 45, 285; 45, 316; 45, 317; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:modules; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_getThirdPartyLibs; 53, argument_list; 53, 54; 53, 55; 54, identifier:platformIdentifier; 55, identifier:configuration; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:modules; 60, list_comprehension; 60, 61; 60, 62; 60, 65; 61, identifier:m; 62, for_in_clause; 62, 63; 62, 64; 63, identifier:m; 64, identifier:modules; 65, if_clause; 65, 66; 66, comparison_operator:in; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:m; 69, string:'Name'; 70, identifier:libModules; 71, comment; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:names; 75, list_comprehension; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:m; 78, string:'Name'; 79, for_in_clause; 79, 80; 79, 81; 80, identifier:m; 81, identifier:modules; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:unsupported; 85, list_comprehension; 85, 86; 85, 91; 85, 94; 86, binary_operator:+; 86, 87; 86, 90; 87, binary_operator:+; 87, 88; 87, 89; 88, string:'"'; 89, identifier:m; 90, string:'"'; 91, for_in_clause; 91, 92; 91, 93; 92, identifier:m; 93, identifier:libModules; 94, if_clause; 94, 95; 95, comparison_operator:not; 95, 96; 95, 97; 96, identifier:m; 97, identifier:names; 98, if_statement; 98, 99; 98, 105; 99, comparison_operator:>; 99, 100; 99, 104; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, identifier:unsupported; 104, integer:0; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:Utility; 110, identifier:printStderr; 111, argument_list; 111, 112; 112, binary_operator:+; 112, 113; 112, 114; 113, string:'Warning: unsupported libraries '; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, string:','; 117, identifier:join; 118, argument_list; 118, 119; 119, identifier:unsupported; 120, comment; 121, for_statement; 121, 122; 121, 123; 121, 124; 122, identifier:module; 123, identifier:modules; 124, block; 124, 125; 125, if_statement; 125, 126; 125, 143; 126, boolean_operator:and; 126, 127; 126, 135; 127, comparison_operator:>; 127, 128; 127, 134; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, subscript; 131, 132; 131, 133; 132, identifier:module; 133, string:'PublicAdditionalLibraries'; 134, integer:0; 135, comparison_operator:>; 135, 136; 135, 142; 136, call; 136, 137; 136, 138; 137, identifier:len; 138, argument_list; 138, 139; 139, subscript; 139, 140; 139, 141; 140, identifier:module; 141, string:'PublicLibraryPaths'; 142, integer:0; 143, block; 143, 144; 143, 158; 143, 177; 143, 201; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:libPath; 147, subscript; 147, 148; 147, 157; 148, parenthesized_expression; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:_absolutePaths; 153, argument_list; 153, 154; 154, subscript; 154, 155; 154, 156; 155, identifier:module; 156, string:'PublicLibraryPaths'; 157, integer:0; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:libs; 161, call; 161, 162; 161, 163; 162, identifier:list; 163, argument_list; 163, 164; 164, list_comprehension; 164, 165; 164, 172; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:lib; 168, identifier:replace; 169, argument_list; 169, 170; 169, 171; 170, string:'\\'; 171, string:'/'; 172, for_in_clause; 172, 173; 172, 174; 173, identifier:lib; 174, subscript; 174, 175; 174, 176; 175, identifier:module; 176, string:'PublicAdditionalLibraries'; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:libs; 180, call; 180, 181; 180, 182; 181, identifier:list; 182, argument_list; 182, 183; 183, list_comprehension; 183, 184; 183, 198; 184, conditional_expression:if; 184, 185; 184, 194; 184, 197; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:os; 189, identifier:path; 190, identifier:join; 191, argument_list; 191, 192; 191, 193; 192, identifier:libPath; 193, identifier:lib; 194, comparison_operator:not; 194, 195; 194, 196; 195, string:'/'; 196, identifier:lib; 197, identifier:lib; 198, for_in_clause; 198, 199; 198, 200; 199, identifier:lib; 200, identifier:libs; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:module; 205, string:'PublicAdditionalLibraries'; 206, identifier:libs; 207, comment; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:fields; 211, list:[
'Directory',
'PublicAdditionalLibraries',
'PublicLibraryPaths',
'PublicSystemIncludePaths',
'PublicIncludePaths',
'PrivateIncludePaths',
'PublicDefinitions'
]; 211, 212; 211, 213; 211, 214; 211, 215; 211, 216; 211, 217; 211, 218; 212, string:'Directory'; 213, string:'PublicAdditionalLibraries'; 214, string:'PublicLibraryPaths'; 215, string:'PublicSystemIncludePaths'; 216, string:'PublicIncludePaths'; 217, string:'PrivateIncludePaths'; 218, string:'PublicDefinitions'; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:flattened; 222, dictionary; 223, for_statement; 223, 224; 223, 225; 223, 226; 224, identifier:field; 225, identifier:fields; 226, block; 226, 227; 226, 245; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:transform; 230, conditional_expression:if; 230, 231; 230, 241; 230, 244; 231, parenthesized_expression; 231, 232; 232, lambda; 232, 233; 232, 235; 233, lambda_parameters; 233, 234; 234, identifier:l; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:_absolutePaths; 239, argument_list; 239, 240; 240, identifier:l; 241, comparison_operator:!=; 241, 242; 241, 243; 242, identifier:field; 243, string:'Definitions'; 244, None; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 250; 247, subscript; 247, 248; 247, 249; 248, identifier:flattened; 249, identifier:field; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:_flatten; 254, argument_list; 254, 255; 254, 256; 254, 257; 255, identifier:field; 256, identifier:modules; 257, identifier:transform; 258, comment; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:libraryDirectories; 262, subscript; 262, 263; 262, 264; 263, identifier:flattened; 264, string:'PublicLibraryPaths'; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:headerDirectories; 268, binary_operator:+; 268, 269; 268, 276; 269, binary_operator:+; 269, 270; 269, 273; 270, subscript; 270, 271; 270, 272; 271, identifier:flattened; 272, string:'PublicSystemIncludePaths'; 273, subscript; 273, 274; 273, 275; 274, identifier:flattened; 275, string:'PublicIncludePaths'; 276, subscript; 276, 277; 276, 278; 277, identifier:flattened; 278, string:'PrivateIncludePaths'; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:modulePaths; 282, subscript; 282, 283; 282, 284; 283, identifier:flattened; 284, string:'Directory'; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:prefixDirectories; 288, call; 288, 289; 288, 290; 289, identifier:list; 290, argument_list; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:set; 293, argument_list; 293, 294; 294, binary_operator:+; 294, 295; 294, 302; 295, binary_operator:+; 295, 296; 295, 301; 296, binary_operator:+; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:flattened; 299, string:'Directory'; 300, identifier:headerDirectories; 301, identifier:libraryDirectories; 302, list_comprehension; 302, 303; 302, 311; 303, call; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:os; 307, identifier:path; 308, identifier:dirname; 309, argument_list; 309, 310; 310, identifier:p; 311, for_in_clause; 311, 312; 311, 313; 312, identifier:p; 313, binary_operator:+; 313, 314; 313, 315; 314, identifier:headerDirectories; 315, identifier:libraryDirectories; 316, comment; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:details; 320, call; 320, 321; 320, 322; 321, identifier:ThirdPartyLibraryDetails; 322, argument_list; 322, 323; 322, 326; 322, 329; 322, 332; 322, 337; 323, keyword_argument; 323, 324; 323, 325; 324, identifier:prefixDirs; 325, identifier:prefixDirectories; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:includeDirs; 328, identifier:headerDirectories; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:linkDirs; 331, identifier:libraryDirectories; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:definitions; 334, subscript; 334, 335; 334, 336; 335, identifier:flattened; 336, string:'PublicDefinitions'; 337, keyword_argument; 337, 338; 337, 339; 338, identifier:libs; 339, subscript; 339, 340; 339, 341; 340, identifier:flattened; 341, string:'PublicAdditionalLibraries'; 342, comment; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:overridesToApply; 346, call; 346, 347; 346, 348; 347, identifier:list; 348, argument_list; 348, 349; 349, list_comprehension; 349, 350; 349, 353; 349, 356; 350, subscript; 350, 351; 350, 352; 351, identifier:libOverrides; 352, identifier:lib; 353, for_in_clause; 353, 354; 353, 355; 354, identifier:lib; 355, identifier:libraries; 356, if_clause; 356, 357; 357, comparison_operator:in; 357, 358; 357, 359; 358, identifier:lib; 359, identifier:libOverrides; 360, for_statement; 360, 361; 360, 362; 360, 363; 361, identifier:override; 362, identifier:overridesToApply; 363, block; 363, 364; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:details; 368, identifier:merge; 369, argument_list; 369, 370; 370, identifier:override; 371, return_statement; 371, 372; 372, identifier:details | def interrogate(self, platformIdentifier, configuration, libraries, libOverrides = {}):
"""
Interrogates UnrealBuildTool about the build flags for the specified third-party libraries
"""
# Determine which libraries need their modules parsed by UBT, and which are override-only
libModules = list([lib for lib in libraries if lib not in libOverrides])
# Check that we have at least one module to parse
details = ThirdPartyLibraryDetails()
if len(libModules) > 0:
# Retrieve the list of third-party library modules from UnrealBuildTool
modules = self._getThirdPartyLibs(platformIdentifier, configuration)
# Filter the list of modules to include only those that were requested
modules = [m for m in modules if m['Name'] in libModules]
# Emit a warning if any of the requested modules are not supported
names = [m['Name'] for m in modules]
unsupported = ['"' + m + '"' for m in libModules if m not in names]
if len(unsupported) > 0:
Utility.printStderr('Warning: unsupported libraries ' + ','.join(unsupported))
# Some libraries are listed as just the filename without the leading directory (especially prevalent under Windows)
for module in modules:
if len(module['PublicAdditionalLibraries']) > 0 and len(module['PublicLibraryPaths']) > 0:
libPath = (self._absolutePaths(module['PublicLibraryPaths']))[0]
libs = list([lib.replace('\\', '/') for lib in module['PublicAdditionalLibraries']])
libs = list([os.path.join(libPath, lib) if '/' not in lib else lib for lib in libs])
module['PublicAdditionalLibraries'] = libs
# Flatten the lists of paths
fields = [
'Directory',
'PublicAdditionalLibraries',
'PublicLibraryPaths',
'PublicSystemIncludePaths',
'PublicIncludePaths',
'PrivateIncludePaths',
'PublicDefinitions'
]
flattened = {}
for field in fields:
transform = (lambda l: self._absolutePaths(l)) if field != 'Definitions' else None
flattened[field] = self._flatten(field, modules, transform)
# Compose the prefix directories from the module root directories, the header and library paths, and their direct parent directories
libraryDirectories = flattened['PublicLibraryPaths']
headerDirectories = flattened['PublicSystemIncludePaths'] + flattened['PublicIncludePaths'] + flattened['PrivateIncludePaths']
modulePaths = flattened['Directory']
prefixDirectories = list(set(flattened['Directory'] + headerDirectories + libraryDirectories + [os.path.dirname(p) for p in headerDirectories + libraryDirectories]))
# Wrap the results in a ThirdPartyLibraryDetails instance, converting any relative directory paths into absolute ones
details = ThirdPartyLibraryDetails(
prefixDirs = prefixDirectories,
includeDirs = headerDirectories,
linkDirs = libraryDirectories,
definitions = flattened['PublicDefinitions'],
libs = flattened['PublicAdditionalLibraries']
)
# Apply any overrides
overridesToApply = list([libOverrides[lib] for lib in libraries if lib in libOverrides])
for override in overridesToApply:
details.merge(override)
return details |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_getThirdPartyLibs; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:platformIdentifier; 6, identifier:configuration; 7, block; 7, 8; 7, 10; 7, 11; 7, 23; 7, 30; 7, 31; 7, 39; 7, 51; 7, 52; 7, 53; 7, 54; 7, 55; 7, 56; 7, 57; 7, 73; 7, 79; 7, 102; 7, 115; 7, 116; 7, 117; 7, 166; 7, 167; 7, 181; 7, 182; 7, 183; 7, 184; 7, 198; 7, 199; 7, 215; 7, 232; 7, 233; 7, 245; 7, 246; 7, 257; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:cachedList; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:CachedDataManager; 17, identifier:getCachedDataKey; 18, argument_list; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:engineVersionHash; 22, string:'ThirdPartyLibraries'; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:!=; 24, 25; 24, 26; 25, identifier:cachedList; 26, None; 27, block; 27, 28; 28, return_statement; 28, 29; 29, identifier:cachedList; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:tempDir; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:tempfile; 37, identifier:mkdtemp; 38, argument_list; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:jsonFile; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:os; 46, identifier:path; 47, identifier:join; 48, argument_list; 48, 49; 48, 50; 49, identifier:tempDir; 50, string:'ubt_output.json'; 51, comment; 52, comment; 53, comment; 54, comment; 55, comment; 56, comment; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:sentinelFile; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:os; 64, identifier:path; 65, identifier:join; 66, argument_list; 66, 67; 66, 70; 66, 71; 66, 72; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:engineRoot; 70, string:'Engine'; 71, string:'Build'; 72, string:'InstalledBuild.txt'; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:sentinelBackup; 76, binary_operator:+; 76, 77; 76, 78; 77, identifier:sentinelFile; 78, string:'.bak'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:renameSentinel; 82, boolean_operator:and; 82, 83; 82, 91; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:os; 87, identifier:path; 88, identifier:exists; 89, argument_list; 89, 90; 90, identifier:sentinelFile; 91, comparison_operator:==; 91, 92; 91, 101; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:os; 96, identifier:environ; 97, identifier:get; 98, argument_list; 98, 99; 98, 100; 99, string:'UE4CLI_SENTINEL_RENAME'; 100, string:'0'; 101, string:'1'; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:==; 103, 104; 103, 105; 104, identifier:renameSentinel; 105, True; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:shutil; 111, identifier:move; 112, argument_list; 112, 113; 112, 114; 113, identifier:sentinelFile; 114, identifier:sentinelBackup; 115, comment; 116, comment; 117, try_statement; 117, 118; 117, 151; 118, block; 118, 119; 118, 141; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:args; 122, conditional_expression:if; 122, 123; 122, 128; 122, 135; 123, list:['-Mode=JsonExport', '-OutputFile=' +jsonFile ]; 123, 124; 123, 125; 124, string:'-Mode=JsonExport'; 125, binary_operator:+; 125, 126; 125, 127; 126, string:'-OutputFile='; 127, identifier:jsonFile; 128, comparison_operator:>=; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:engineVersion; 133, string:'MinorVersion'; 134, integer:22; 135, list:['-gather', '-jsonexport=' + jsonFile, '-SkipBuild']; 135, 136; 135, 137; 135, 140; 136, string:'-gather'; 137, binary_operator:+; 137, 138; 137, 139; 138, string:'-jsonexport='; 139, identifier:jsonFile; 140, string:'-SkipBuild'; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:runUBTFunc; 146, argument_list; 146, 147; 146, 148; 146, 149; 146, 150; 147, string:'UE4Editor'; 148, identifier:platformIdentifier; 149, identifier:configuration; 150, identifier:args; 151, finally_clause; 151, 152; 152, block; 152, 153; 153, if_statement; 153, 154; 153, 157; 154, comparison_operator:==; 154, 155; 154, 156; 155, identifier:renameSentinel; 156, True; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:shutil; 162, identifier:move; 163, argument_list; 163, 164; 163, 165; 164, identifier:sentinelBackup; 165, identifier:sentinelFile; 166, comment; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:result; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:json; 173, identifier:loads; 174, argument_list; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:Utility; 178, identifier:readFile; 179, argument_list; 179, 180; 180, identifier:jsonFile; 181, comment; 182, comment; 183, comment; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:modules; 187, list_comprehension; 187, 188; 187, 193; 188, subscript; 188, 189; 188, 192; 189, subscript; 189, 190; 189, 191; 190, identifier:result; 191, string:'Modules'; 192, identifier:key; 193, for_in_clause; 193, 194; 193, 195; 194, identifier:key; 195, subscript; 195, 196; 195, 197; 196, identifier:result; 197, string:'Modules'; 198, comment; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:thirdPartyRoot; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:os; 206, identifier:path; 207, identifier:join; 208, argument_list; 208, 209; 208, 212; 208, 213; 208, 214; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:engineRoot; 212, string:'Engine'; 213, string:'Source'; 214, string:'ThirdParty'; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:thirdparty; 218, call; 218, 219; 218, 220; 219, identifier:list; 220, argument_list; 220, 221; 221, list_comprehension; 221, 222; 221, 223; 221, 226; 222, identifier:m; 223, for_in_clause; 223, 224; 223, 225; 224, identifier:m; 225, identifier:modules; 226, if_clause; 226, 227; 227, comparison_operator:in; 227, 228; 227, 229; 228, identifier:thirdPartyRoot; 229, subscript; 229, 230; 229, 231; 230, identifier:m; 231, string:'Directory'; 232, comment; 233, try_statement; 233, 234; 233, 242; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:shutil; 239, identifier:rmtree; 240, argument_list; 240, 241; 241, identifier:tempDir; 242, except_clause; 242, 243; 243, block; 243, 244; 244, pass_statement; 245, comment; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:CachedDataManager; 250, identifier:setCachedDataKey; 251, argument_list; 251, 252; 251, 255; 251, 256; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:engineVersionHash; 255, string:'ThirdPartyLibraries'; 256, identifier:thirdparty; 257, return_statement; 257, 258; 258, identifier:thirdparty | def _getThirdPartyLibs(self, platformIdentifier, configuration):
"""
Runs UnrealBuildTool in JSON export mode and extracts the list of third-party libraries
"""
# If we have previously cached the library list for the current engine version, use the cached data
cachedList = CachedDataManager.getCachedDataKey(self.engineVersionHash, 'ThirdPartyLibraries')
if cachedList != None:
return cachedList
# Create a temp directory to hold the JSON file
tempDir = tempfile.mkdtemp()
jsonFile = os.path.join(tempDir, 'ubt_output.json')
# Installed Builds of the Engine only contain a small handful of third-party libraries, rather than the full set
# included in a source build of the Engine. However, if the ThirdParty directory from a source build is copied
# into an Installed Build and the `InstalledBuild.txt` sentinel file is temporarily renamed, we can get the best
# of both worlds and utilise the full set of third-party libraries. Enable this sentinel renaming behaviour only
# if you have copied the ThirdParty directory from a source build into your Installed Build, or else the UBT
# command will fail trying to rebuild UnrealHeaderTool.
sentinelFile = os.path.join(self.engineRoot, 'Engine', 'Build', 'InstalledBuild.txt')
sentinelBackup = sentinelFile + '.bak'
renameSentinel = os.path.exists(sentinelFile) and os.environ.get('UE4CLI_SENTINEL_RENAME', '0') == '1'
if renameSentinel == True:
shutil.move(sentinelFile, sentinelBackup)
# Invoke UnrealBuildTool in JSON export mode (make sure we specify gathering mode, since this is a prerequisite of JSON export)
# (Ensure we always perform sentinel file cleanup even when errors occur)
try:
args = ['-Mode=JsonExport', '-OutputFile=' +jsonFile ] if self.engineVersion['MinorVersion'] >= 22 else ['-gather', '-jsonexport=' + jsonFile, '-SkipBuild']
self.runUBTFunc('UE4Editor', platformIdentifier, configuration, args)
finally:
if renameSentinel == True:
shutil.move(sentinelBackup, sentinelFile)
# Parse the JSON output
result = json.loads(Utility.readFile(jsonFile))
# Extract the list of third-party library modules
# (Note that since UE4.21, modules no longer have a "Type" field, so we must
# rely on the "Directory" field filter below to identify third-party libraries)
modules = [result['Modules'][key] for key in result['Modules']]
# Filter out any modules from outside the Engine/Source/ThirdParty directory
thirdPartyRoot = os.path.join(self.engineRoot, 'Engine', 'Source', 'ThirdParty')
thirdparty = list([m for m in modules if thirdPartyRoot in m['Directory']])
# Remove the temp directory
try:
shutil.rmtree(tempDir)
except:
pass
# Cache the list of libraries for use by subsequent runs
CachedDataManager.setCachedDataKey(self.engineVersionHash, 'ThirdPartyLibraries', thirdparty)
return thirdparty |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 57; 2, function_name:add_vt; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 3, 42; 3, 45; 3, 48; 3, 51; 3, 54; 4, identifier:self; 5, identifier:vt_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:name; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:vt_params; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:vt_refs; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:custom; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:vt_creation_time; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:vt_modification_time; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:vt_dependencies; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:summary; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:impact; 32, None; 33, default_parameter; 33, 34; 33, 35; 34, identifier:affected; 35, None; 36, default_parameter; 36, 37; 36, 38; 37, identifier:insight; 38, None; 39, default_parameter; 39, 40; 39, 41; 40, identifier:solution; 41, None; 42, default_parameter; 42, 43; 42, 44; 43, identifier:solution_t; 44, None; 45, default_parameter; 45, 46; 45, 47; 46, identifier:detection; 47, None; 48, default_parameter; 48, 49; 48, 50; 49, identifier:qod_t; 50, None; 51, default_parameter; 51, 52; 51, 53; 52, identifier:qod_v; 53, None; 54, default_parameter; 54, 55; 54, 56; 55, identifier:severities; 56, None; 57, block; 57, 58; 57, 60; 57, 68; 57, 84; 57, 95; 57, 104; 57, 115; 57, 130; 57, 145; 57, 160; 57, 175; 57, 190; 57, 205; 57, 220; 57, 235; 57, 250; 57, 265; 57, 295; 57, 310; 57, 340; 57, 355; 58, expression_statement; 58, 59; 59, comment; 60, if_statement; 60, 61; 60, 63; 61, not_operator; 61, 62; 62, identifier:vt_id; 63, block; 63, 64; 63, 67; 64, return_statement; 64, 65; 65, unary_operator:-; 65, 66; 66, integer:2; 67, comment; 68, if_statement; 68, 69; 68, 79; 69, comparison_operator:is; 69, 70; 69, 78; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:vt_id_pattern; 75, identifier:fullmatch; 76, argument_list; 76, 77; 77, identifier:vt_id; 78, None; 79, block; 79, 80; 79, 83; 80, return_statement; 80, 81; 81, unary_operator:-; 81, 82; 82, integer:2; 83, comment; 84, if_statement; 84, 85; 84, 90; 85, comparison_operator:in; 85, 86; 85, 87; 86, identifier:vt_id; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:vts; 90, block; 90, 91; 90, 94; 91, return_statement; 91, 92; 92, unary_operator:-; 92, 93; 93, integer:1; 94, comment; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:name; 98, None; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:name; 103, string:''; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:vts; 110, identifier:vt_id; 111, dictionary; 111, 112; 112, pair; 112, 113; 112, 114; 113, string:'name'; 114, identifier:name; 115, if_statement; 115, 116; 115, 119; 116, comparison_operator:is; 116, 117; 116, 118; 117, identifier:custom; 118, None; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 129; 122, subscript; 122, 123; 122, 128; 123, subscript; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:vts; 127, identifier:vt_id; 128, string:"custom"; 129, identifier:custom; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:is; 131, 132; 131, 133; 132, identifier:vt_params; 133, None; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 144; 137, subscript; 137, 138; 137, 143; 138, subscript; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:vts; 142, identifier:vt_id; 143, string:"vt_params"; 144, identifier:vt_params; 145, if_statement; 145, 146; 145, 149; 146, comparison_operator:is; 146, 147; 146, 148; 147, identifier:vt_refs; 148, None; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 159; 152, subscript; 152, 153; 152, 158; 153, subscript; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:vts; 157, identifier:vt_id; 158, string:"vt_refs"; 159, identifier:vt_refs; 160, if_statement; 160, 161; 160, 164; 161, comparison_operator:is; 161, 162; 161, 163; 162, identifier:vt_dependencies; 163, None; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 174; 167, subscript; 167, 168; 167, 173; 168, subscript; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:vts; 172, identifier:vt_id; 173, string:"vt_dependencies"; 174, identifier:vt_dependencies; 175, if_statement; 175, 176; 175, 179; 176, comparison_operator:is; 176, 177; 176, 178; 177, identifier:vt_creation_time; 178, None; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 189; 182, subscript; 182, 183; 182, 188; 183, subscript; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:vts; 187, identifier:vt_id; 188, string:"creation_time"; 189, identifier:vt_creation_time; 190, if_statement; 190, 191; 190, 194; 191, comparison_operator:is; 191, 192; 191, 193; 192, identifier:vt_modification_time; 193, None; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 204; 197, subscript; 197, 198; 197, 203; 198, subscript; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:vts; 202, identifier:vt_id; 203, string:"modification_time"; 204, identifier:vt_modification_time; 205, if_statement; 205, 206; 205, 209; 206, comparison_operator:is; 206, 207; 206, 208; 207, identifier:summary; 208, None; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 219; 212, subscript; 212, 213; 212, 218; 213, subscript; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:vts; 217, identifier:vt_id; 218, string:"summary"; 219, identifier:summary; 220, if_statement; 220, 221; 220, 224; 221, comparison_operator:is; 221, 222; 221, 223; 222, identifier:impact; 223, None; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 234; 227, subscript; 227, 228; 227, 233; 228, subscript; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:vts; 232, identifier:vt_id; 233, string:"impact"; 234, identifier:impact; 235, if_statement; 235, 236; 235, 239; 236, comparison_operator:is; 236, 237; 236, 238; 237, identifier:affected; 238, None; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 249; 242, subscript; 242, 243; 242, 248; 243, subscript; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:vts; 247, identifier:vt_id; 248, string:"affected"; 249, identifier:affected; 250, if_statement; 250, 251; 250, 254; 251, comparison_operator:is; 251, 252; 251, 253; 252, identifier:insight; 253, None; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 264; 257, subscript; 257, 258; 257, 263; 258, subscript; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:vts; 262, identifier:vt_id; 263, string:"insight"; 264, identifier:insight; 265, if_statement; 265, 266; 265, 269; 266, comparison_operator:is; 266, 267; 266, 268; 267, identifier:solution; 268, None; 269, block; 269, 270; 269, 280; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 279; 272, subscript; 272, 273; 272, 278; 273, subscript; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:vts; 277, identifier:vt_id; 278, string:"solution"; 279, identifier:solution; 280, if_statement; 280, 281; 280, 284; 281, comparison_operator:is; 281, 282; 281, 283; 282, identifier:solution_t; 283, None; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 294; 287, subscript; 287, 288; 287, 293; 288, subscript; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:vts; 292, identifier:vt_id; 293, string:"solution_type"; 294, identifier:solution_t; 295, if_statement; 295, 296; 295, 299; 296, comparison_operator:is; 296, 297; 296, 298; 297, identifier:detection; 298, None; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 309; 302, subscript; 302, 303; 302, 308; 303, subscript; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:vts; 307, identifier:vt_id; 308, string:"detection"; 309, identifier:detection; 310, if_statement; 310, 311; 310, 314; 310, 325; 311, comparison_operator:is; 311, 312; 311, 313; 312, identifier:qod_t; 313, None; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 324; 317, subscript; 317, 318; 317, 323; 318, subscript; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:self; 321, identifier:vts; 322, identifier:vt_id; 323, string:"qod_type"; 324, identifier:qod_t; 325, elif_clause; 325, 326; 325, 329; 326, comparison_operator:is; 326, 327; 326, 328; 327, identifier:qod_v; 328, None; 329, block; 329, 330; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 339; 332, subscript; 332, 333; 332, 338; 333, subscript; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:vts; 337, identifier:vt_id; 338, string:"qod"; 339, identifier:qod_v; 340, if_statement; 340, 341; 340, 344; 341, comparison_operator:is; 341, 342; 341, 343; 342, identifier:severities; 343, None; 344, block; 344, 345; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 354; 347, subscript; 347, 348; 347, 353; 348, subscript; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:vts; 352, identifier:vt_id; 353, string:"severities"; 354, identifier:severities; 355, return_statement; 355, 356; 356, call; 356, 357; 356, 358; 357, identifier:len; 358, argument_list; 358, 359; 359, attribute; 359, 360; 359, 361; 360, identifier:self; 361, identifier:vts | def add_vt(self, vt_id, name=None, vt_params=None, vt_refs=None,
custom=None, vt_creation_time=None, vt_modification_time=None,
vt_dependencies=None, summary=None, impact=None, affected=None,
insight=None, solution=None, solution_t=None, detection=None,
qod_t=None, qod_v=None, severities=None):
""" Add a vulnerability test information.
Returns: The new number of stored VTs.
-1 in case the VT ID was already present and thus the
new VT was not considered.
-2 in case the vt_id was invalid.
"""
if not vt_id:
return -2 # no valid vt_id
if self.vt_id_pattern.fullmatch(vt_id) is None:
return -2 # no valid vt_id
if vt_id in self.vts:
return -1 # The VT was already in the list.
if name is None:
name = ''
self.vts[vt_id] = {'name': name}
if custom is not None:
self.vts[vt_id]["custom"] = custom
if vt_params is not None:
self.vts[vt_id]["vt_params"] = vt_params
if vt_refs is not None:
self.vts[vt_id]["vt_refs"] = vt_refs
if vt_dependencies is not None:
self.vts[vt_id]["vt_dependencies"] = vt_dependencies
if vt_creation_time is not None:
self.vts[vt_id]["creation_time"] = vt_creation_time
if vt_modification_time is not None:
self.vts[vt_id]["modification_time"] = vt_modification_time
if summary is not None:
self.vts[vt_id]["summary"] = summary
if impact is not None:
self.vts[vt_id]["impact"] = impact
if affected is not None:
self.vts[vt_id]["affected"] = affected
if insight is not None:
self.vts[vt_id]["insight"] = insight
if solution is not None:
self.vts[vt_id]["solution"] = solution
if solution_t is not None:
self.vts[vt_id]["solution_type"] = solution_t
if detection is not None:
self.vts[vt_id]["detection"] = detection
if qod_t is not None:
self.vts[vt_id]["qod_type"] = qod_t
elif qod_v is not None:
self.vts[vt_id]["qod"] = qod_v
if severities is not None:
self.vts[vt_id]["severities"] = severities
return len(self.vts) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_preprocess_scan_params; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:xml_params; 6, block; 6, 7; 6, 9; 6, 13; 6, 29; 6, 30; 6, 77; 6, 78; 6, 205; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:params; 12, dictionary; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:param; 15, identifier:xml_params; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 24; 19, subscript; 19, 20; 19, 21; 20, identifier:params; 21, attribute; 21, 22; 21, 23; 22, identifier:param; 23, identifier:tag; 24, boolean_operator:or; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:param; 27, identifier:text; 28, string:''; 29, comment; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:key; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:scanner_params; 35, block; 35, 36; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:not; 37, 38; 37, 39; 38, identifier:key; 39, identifier:params; 40, block; 40, 41; 40, 52; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:params; 45, identifier:key; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:get_scanner_param_default; 50, argument_list; 50, 51; 51, identifier:key; 52, if_statement; 52, 53; 52, 61; 53, comparison_operator:==; 53, 54; 53, 60; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:get_scanner_param_type; 58, argument_list; 58, 59; 59, identifier:key; 60, string:'selection'; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:params; 66, identifier:key; 67, subscript; 67, 68; 67, 76; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:params; 72, identifier:key; 73, identifier:split; 74, argument_list; 74, 75; 75, string:'|'; 76, integer:0; 77, comment; 78, for_statement; 78, 79; 78, 80; 78, 81; 79, identifier:key; 80, identifier:params; 81, block; 81, 82; 81, 91; 81, 96; 81, 127; 81, 183; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:param_type; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:get_scanner_param_type; 89, argument_list; 89, 90; 90, identifier:key; 91, if_statement; 91, 92; 91, 94; 92, not_operator; 92, 93; 93, identifier:param_type; 94, block; 94, 95; 95, continue_statement; 96, if_statement; 96, 97; 96, 102; 97, comparison_operator:in; 97, 98; 97, 99; 98, identifier:param_type; 99, list:['integer', 'boolean']; 99, 100; 99, 101; 100, string:'integer'; 101, string:'boolean'; 102, block; 102, 103; 103, try_statement; 103, 104; 103, 116; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:params; 109, identifier:key; 110, call; 110, 111; 110, 112; 111, identifier:int; 112, argument_list; 112, 113; 113, subscript; 113, 114; 113, 115; 114, identifier:params; 115, identifier:key; 116, except_clause; 116, 117; 116, 118; 117, identifier:ValueError; 118, block; 118, 119; 119, raise_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:OSPDError; 122, argument_list; 122, 123; 122, 126; 123, binary_operator:%; 123, 124; 123, 125; 124, string:'Invalid %s value'; 125, identifier:key; 126, string:'start_scan'; 127, if_statement; 127, 128; 127, 131; 127, 149; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:param_type; 130, string:'boolean'; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 140; 133, comparison_operator:not; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:params; 136, identifier:key; 137, list:[0, 1]; 137, 138; 137, 139; 138, integer:0; 139, integer:1; 140, block; 140, 141; 141, raise_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:OSPDError; 144, argument_list; 144, 145; 144, 148; 145, binary_operator:%; 145, 146; 145, 147; 146, string:'Invalid %s value'; 147, identifier:key; 148, string:'start_scan'; 149, elif_clause; 149, 150; 149, 153; 150, comparison_operator:==; 150, 151; 150, 152; 151, identifier:param_type; 152, string:'selection'; 153, block; 153, 154; 153, 168; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:selection; 157, call; 157, 158; 157, 166; 158, attribute; 158, 159; 158, 165; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:get_scanner_param_default; 163, argument_list; 163, 164; 164, identifier:key; 165, identifier:split; 166, argument_list; 166, 167; 167, string:'|'; 168, if_statement; 168, 169; 168, 174; 169, comparison_operator:not; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:params; 172, identifier:key; 173, identifier:selection; 174, block; 174, 175; 175, raise_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:OSPDError; 178, argument_list; 178, 179; 178, 182; 179, binary_operator:%; 179, 180; 179, 181; 180, string:'Invalid %s value'; 181, identifier:key; 182, string:'start_scan'; 183, if_statement; 183, 184; 183, 196; 184, boolean_operator:and; 184, 185; 184, 191; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:get_scanner_param_mandatory; 189, argument_list; 189, 190; 190, identifier:key; 191, comparison_operator:==; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:params; 194, identifier:key; 195, string:''; 196, block; 196, 197; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:OSPDError; 200, argument_list; 200, 201; 200, 204; 201, binary_operator:%; 201, 202; 201, 203; 202, string:'Mandatory %s value is missing'; 203, identifier:key; 204, string:'start_scan'; 205, return_statement; 205, 206; 206, identifier:params | def _preprocess_scan_params(self, xml_params):
""" Processes the scan parameters. """
params = {}
for param in xml_params:
params[param.tag] = param.text or ''
# Set default values.
for key in self.scanner_params:
if key not in params:
params[key] = self.get_scanner_param_default(key)
if self.get_scanner_param_type(key) == 'selection':
params[key] = params[key].split('|')[0]
# Validate values.
for key in params:
param_type = self.get_scanner_param_type(key)
if not param_type:
continue
if param_type in ['integer', 'boolean']:
try:
params[key] = int(params[key])
except ValueError:
raise OSPDError('Invalid %s value' % key, 'start_scan')
if param_type == 'boolean':
if params[key] not in [0, 1]:
raise OSPDError('Invalid %s value' % key, 'start_scan')
elif param_type == 'selection':
selection = self.get_scanner_param_default(key).split('|')
if params[key] not in selection:
raise OSPDError('Invalid %s value' % key, 'start_scan')
if self.get_scanner_param_mandatory(key) and params[key] == '':
raise OSPDError('Mandatory %s value is missing' % key,
'start_scan')
return params |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:start_scan; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:scan_id; 6, identifier:targets; 7, default_parameter; 7, 8; 7, 9; 8, identifier:parallel; 9, integer:1; 10, block; 10, 11; 10, 13; 10, 19; 10, 23; 10, 31; 10, 35; 10, 49; 10, 174; 10, 175; 10, 215; 10, 216; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:os; 17, identifier:setsid; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:multiscan_proc; 22, list:[]; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:logger; 27, identifier:info; 28, argument_list; 28, 29; 28, 30; 29, string:"%s: Scan started."; 30, identifier:scan_id; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:target_list; 34, identifier:targets; 35, if_statement; 35, 36; 35, 42; 36, boolean_operator:or; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:target_list; 39, None; 40, not_operator; 40, 41; 41, identifier:target_list; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:OSPDError; 46, argument_list; 46, 47; 46, 48; 47, string:'Erroneous targets list'; 48, string:'start_scan'; 49, for_statement; 49, 50; 49, 53; 49, 57; 50, pattern_list; 50, 51; 50, 52; 51, identifier:index; 52, identifier:target; 53, call; 53, 54; 53, 55; 54, identifier:enumerate; 55, argument_list; 55, 56; 56, identifier:target_list; 57, block; 57, 58; 57, 100; 57, 101; 57, 114; 57, 127; 57, 147; 57, 158; 57, 164; 58, while_statement; 58, 59; 58, 65; 59, comparison_operator:>=; 59, 60; 59, 64; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:multiscan_proc; 64, identifier:parallel; 65, block; 65, 66; 65, 75; 65, 83; 65, 93; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:progress; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:calculate_progress; 73, argument_list; 73, 74; 74, identifier:scan_id; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:set_scan_progress; 80, argument_list; 80, 81; 80, 82; 81, identifier:scan_id; 82, identifier:progress; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:multiscan_proc; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:check_pending_target; 90, argument_list; 90, 91; 90, 92; 91, identifier:scan_id; 92, identifier:multiscan_proc; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:time; 97, identifier:sleep; 98, argument_list; 98, 99; 99, integer:1; 100, comment; 101, if_statement; 101, 102; 101, 112; 102, comparison_operator:==; 102, 103; 102, 109; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:get_scan_status; 107, argument_list; 107, 108; 108, identifier:scan_id; 109, attribute; 109, 110; 109, 111; 110, identifier:ScanStatus; 111, identifier:STOPPED; 112, block; 112, 113; 113, return_statement; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:logger; 118, identifier:info; 119, argument_list; 119, 120; 119, 121; 119, 124; 120, string:"%s: Host scan started on ports %s."; 121, subscript; 121, 122; 121, 123; 122, identifier:target; 123, integer:0; 124, subscript; 124, 125; 124, 126; 125, identifier:target; 126, integer:1; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:scan_process; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:multiprocessing; 133, identifier:Process; 134, argument_list; 134, 135; 134, 140; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:target; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:parallel_scan; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:args; 142, tuple; 142, 143; 142, 144; 143, identifier:scan_id; 144, subscript; 144, 145; 144, 146; 145, identifier:target; 146, integer:0; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:multiscan_proc; 151, identifier:append; 152, argument_list; 152, 153; 153, tuple; 153, 154; 153, 155; 154, identifier:scan_process; 155, subscript; 155, 156; 155, 157; 156, identifier:target; 157, integer:0; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:scan_process; 162, identifier:start; 163, argument_list; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:set_scan_status; 169, argument_list; 169, 170; 169, 171; 170, identifier:scan_id; 171, attribute; 171, 172; 171, 173; 172, identifier:ScanStatus; 173, identifier:RUNNING; 174, comment; 175, while_statement; 175, 176; 175, 177; 176, identifier:multiscan_proc; 177, block; 177, 178; 177, 188; 177, 208; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:multiscan_proc; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:check_pending_target; 185, argument_list; 185, 186; 185, 187; 186, identifier:scan_id; 187, identifier:multiscan_proc; 188, if_statement; 188, 189; 188, 190; 189, identifier:multiscan_proc; 190, block; 190, 191; 190, 200; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:progress; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:calculate_progress; 198, argument_list; 198, 199; 199, identifier:scan_id; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:set_scan_progress; 205, argument_list; 205, 206; 205, 207; 206, identifier:scan_id; 207, identifier:progress; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:time; 212, identifier:sleep; 213, argument_list; 213, 214; 214, integer:1; 215, comment; 216, if_statement; 216, 217; 216, 227; 217, comparison_operator:!=; 217, 218; 217, 224; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:get_scan_status; 222, argument_list; 222, 223; 223, identifier:scan_id; 224, attribute; 224, 225; 224, 226; 225, identifier:ScanStatus; 226, identifier:STOPPED; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:finish_scan; 233, argument_list; 233, 234; 234, identifier:scan_id | def start_scan(self, scan_id, targets, parallel=1):
""" Handle N parallel scans if 'parallel' is greater than 1. """
os.setsid()
multiscan_proc = []
logger.info("%s: Scan started.", scan_id)
target_list = targets
if target_list is None or not target_list:
raise OSPDError('Erroneous targets list', 'start_scan')
for index, target in enumerate(target_list):
while len(multiscan_proc) >= parallel:
progress = self.calculate_progress(scan_id)
self.set_scan_progress(scan_id, progress)
multiscan_proc = self.check_pending_target(scan_id,
multiscan_proc)
time.sleep(1)
#If the scan status is stopped, does not launch anymore target scans
if self.get_scan_status(scan_id) == ScanStatus.STOPPED:
return
logger.info("%s: Host scan started on ports %s.", target[0], target[1])
scan_process = multiprocessing.Process(target=self.parallel_scan,
args=(scan_id, target[0]))
multiscan_proc.append((scan_process, target[0]))
scan_process.start()
self.set_scan_status(scan_id, ScanStatus.RUNNING)
# Wait until all single target were scanned
while multiscan_proc:
multiscan_proc = self.check_pending_target(scan_id, multiscan_proc)
if multiscan_proc:
progress = self.calculate_progress(scan_id)
self.set_scan_progress(scan_id, progress)
time.sleep(1)
# Only set the scan as finished if the scan was not stopped.
if self.get_scan_status(scan_id) != ScanStatus.STOPPED:
self.finish_scan(scan_id) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:ports_as_list; 3, parameters; 3, 4; 4, identifier:port_str; 5, block; 5, 6; 5, 8; 5, 23; 5, 40; 5, 46; 5, 52; 5, 62; 5, 71; 5, 80; 5, 105; 5, 130; 5, 137; 5, 141; 5, 145; 5, 146; 5, 253; 5, 298; 5, 343; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 11; 9, not_operator; 9, 10; 10, identifier:port_str; 11, block; 11, 12; 11, 19; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:LOGGER; 16, identifier:info; 17, argument_list; 17, 18; 18, string:"Invalid port value"; 19, return_statement; 19, 20; 20, list:[None, None]; 20, 21; 20, 22; 21, None; 22, None; 23, if_statement; 23, 24; 23, 28; 24, call; 24, 25; 24, 26; 25, identifier:ports_str_check_failed; 26, argument_list; 26, 27; 27, identifier:port_str; 28, block; 28, 29; 28, 36; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:LOGGER; 33, identifier:info; 34, argument_list; 34, 35; 35, string:"{0}: Port list malformed."; 36, return_statement; 36, 37; 37, list:[None, None]; 37, 38; 37, 39; 38, None; 39, None; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:tcp_list; 43, call; 43, 44; 43, 45; 44, identifier:list; 45, argument_list; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:udp_list; 49, call; 49, 50; 49, 51; 50, identifier:list; 51, argument_list; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:ports; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:port_str; 58, identifier:replace; 59, argument_list; 59, 60; 59, 61; 60, string:' '; 61, string:''; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:b_tcp; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:ports; 68, identifier:find; 69, argument_list; 69, 70; 70, string:"T"; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:b_udp; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:ports; 77, identifier:find; 78, argument_list; 78, 79; 79, string:"U"; 80, if_statement; 80, 81; 80, 88; 81, comparison_operator:==; 81, 82; 81, 87; 82, subscript; 82, 83; 82, 84; 83, identifier:ports; 84, binary_operator:-; 84, 85; 84, 86; 85, identifier:b_tcp; 86, integer:1; 87, string:','; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:ports; 92, binary_operator:+; 92, 93; 92, 100; 93, subscript; 93, 94; 93, 95; 94, identifier:ports; 95, slice; 95, 96; 95, 97; 96, colon; 97, binary_operator:-; 97, 98; 97, 99; 98, identifier:b_tcp; 99, integer:1; 100, subscript; 100, 101; 100, 102; 101, identifier:ports; 102, slice; 102, 103; 102, 104; 103, identifier:b_tcp; 104, colon; 105, if_statement; 105, 106; 105, 113; 106, comparison_operator:==; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 109; 108, identifier:ports; 109, binary_operator:-; 109, 110; 109, 111; 110, identifier:b_udp; 111, integer:1; 112, string:','; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:ports; 117, binary_operator:+; 117, 118; 117, 125; 118, subscript; 118, 119; 118, 120; 119, identifier:ports; 120, slice; 120, 121; 120, 122; 121, colon; 122, binary_operator:-; 122, 123; 122, 124; 123, identifier:b_udp; 124, integer:1; 125, subscript; 125, 126; 125, 127; 126, identifier:ports; 127, slice; 127, 128; 127, 129; 128, identifier:b_udp; 129, colon; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:ports; 133, call; 133, 134; 133, 135; 134, identifier:port_str_arrange; 135, argument_list; 135, 136; 136, identifier:ports; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:tports; 140, string:''; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:uports; 144, string:''; 145, comment; 146, if_statement; 146, 147; 146, 156; 146, 193; 146, 194; 146, 220; 146, 221; 146, 247; 147, boolean_operator:and; 147, 148; 147, 152; 148, comparison_operator:!=; 148, 149; 148, 150; 149, identifier:b_udp; 150, unary_operator:-; 150, 151; 151, integer:1; 152, comparison_operator:!=; 152, 153; 152, 154; 153, identifier:b_tcp; 154, unary_operator:-; 154, 155; 155, integer:1; 156, block; 156, 157; 156, 178; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:tports; 160, subscript; 160, 161; 160, 162; 161, identifier:ports; 162, slice; 162, 163; 162, 171; 162, 172; 163, binary_operator:+; 163, 164; 163, 170; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:ports; 167, identifier:index; 168, argument_list; 168, 169; 169, string:'T:'; 170, integer:2; 171, colon; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:ports; 175, identifier:index; 176, argument_list; 176, 177; 177, string:'U:'; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:uports; 181, subscript; 181, 182; 181, 183; 182, identifier:ports; 183, slice; 183, 184; 183, 192; 184, binary_operator:+; 184, 185; 184, 191; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:ports; 188, identifier:index; 189, argument_list; 189, 190; 190, string:'U:'; 191, integer:2; 192, colon; 193, comment; 194, elif_clause; 194, 195; 194, 204; 195, boolean_operator:and; 195, 196; 195, 200; 196, comparison_operator:==; 196, 197; 196, 198; 197, identifier:b_tcp; 198, unary_operator:-; 198, 199; 199, integer:1; 200, comparison_operator:!=; 200, 201; 200, 202; 201, identifier:b_udp; 202, unary_operator:-; 202, 203; 203, integer:1; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:uports; 208, subscript; 208, 209; 208, 210; 209, identifier:ports; 210, slice; 210, 211; 210, 219; 211, binary_operator:+; 211, 212; 211, 218; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:ports; 215, identifier:index; 216, argument_list; 216, 217; 217, string:'U:'; 218, integer:2; 219, colon; 220, comment; 221, elif_clause; 221, 222; 221, 231; 222, boolean_operator:and; 222, 223; 222, 227; 223, comparison_operator:==; 223, 224; 223, 225; 224, identifier:b_udp; 225, unary_operator:-; 225, 226; 226, integer:1; 227, comparison_operator:!=; 227, 228; 227, 229; 228, identifier:b_tcp; 229, unary_operator:-; 229, 230; 230, integer:1; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:tports; 235, subscript; 235, 236; 235, 237; 236, identifier:ports; 237, slice; 237, 238; 237, 246; 238, binary_operator:+; 238, 239; 238, 245; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:ports; 242, identifier:index; 243, argument_list; 243, 244; 244, string:'T:'; 245, integer:2; 246, colon; 247, else_clause; 247, 248; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:tports; 252, identifier:ports; 253, if_statement; 253, 254; 253, 255; 254, identifier:tports; 255, block; 255, 256; 255, 292; 256, for_statement; 256, 257; 256, 258; 256, 264; 257, identifier:port; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:tports; 261, identifier:split; 262, argument_list; 262, 263; 263, string:','; 264, block; 264, 265; 265, if_statement; 265, 266; 265, 269; 265, 280; 266, comparison_operator:in; 266, 267; 266, 268; 267, string:'-'; 268, identifier:port; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:tcp_list; 274, identifier:extend; 275, argument_list; 275, 276; 276, call; 276, 277; 276, 278; 277, identifier:port_range_expand; 278, argument_list; 278, 279; 279, identifier:port; 280, else_clause; 280, 281; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:tcp_list; 286, identifier:append; 287, argument_list; 287, 288; 288, call; 288, 289; 288, 290; 289, identifier:int; 290, argument_list; 290, 291; 291, identifier:port; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:tcp_list; 296, identifier:sort; 297, argument_list; 298, if_statement; 298, 299; 298, 300; 299, identifier:uports; 300, block; 300, 301; 300, 337; 301, for_statement; 301, 302; 301, 303; 301, 309; 302, identifier:port; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:uports; 306, identifier:split; 307, argument_list; 307, 308; 308, string:','; 309, block; 309, 310; 310, if_statement; 310, 311; 310, 314; 310, 325; 311, comparison_operator:in; 311, 312; 311, 313; 312, string:'-'; 313, identifier:port; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:udp_list; 319, identifier:extend; 320, argument_list; 320, 321; 321, call; 321, 322; 321, 323; 322, identifier:port_range_expand; 323, argument_list; 323, 324; 324, identifier:port; 325, else_clause; 325, 326; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:udp_list; 331, identifier:append; 332, argument_list; 332, 333; 333, call; 333, 334; 333, 335; 334, identifier:int; 335, argument_list; 335, 336; 336, identifier:port; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:udp_list; 341, identifier:sort; 342, argument_list; 343, return_statement; 343, 344; 344, tuple; 344, 345; 344, 346; 345, identifier:tcp_list; 346, identifier:udp_list | def ports_as_list(port_str):
"""
Parses a ports string into two list of individual tcp and udp ports.
@input string containing a port list
e.g. T:1,2,3,5-8 U:22,80,600-1024
@return two list of sorted integers, for tcp and udp ports respectively.
"""
if not port_str:
LOGGER.info("Invalid port value")
return [None, None]
if ports_str_check_failed(port_str):
LOGGER.info("{0}: Port list malformed.")
return [None, None]
tcp_list = list()
udp_list = list()
ports = port_str.replace(' ', '')
b_tcp = ports.find("T")
b_udp = ports.find("U")
if ports[b_tcp - 1] == ',':
ports = ports[:b_tcp - 1] + ports[b_tcp:]
if ports[b_udp - 1] == ',':
ports = ports[:b_udp - 1] + ports[b_udp:]
ports = port_str_arrange(ports)
tports = ''
uports = ''
# TCP ports listed first, then UDP ports
if b_udp != -1 and b_tcp != -1:
tports = ports[ports.index('T:') + 2:ports.index('U:')]
uports = ports[ports.index('U:') + 2:]
# Only UDP ports
elif b_tcp == -1 and b_udp != -1:
uports = ports[ports.index('U:') + 2:]
# Only TCP ports
elif b_udp == -1 and b_tcp != -1:
tports = ports[ports.index('T:') + 2:]
else:
tports = ports
if tports:
for port in tports.split(','):
if '-' in port:
tcp_list.extend(port_range_expand(port))
else:
tcp_list.append(int(port))
tcp_list.sort()
if uports:
for port in uports.split(','):
if '-' in port:
udp_list.extend(port_range_expand(port))
else:
udp_list.append(int(port))
udp_list.sort()
return (tcp_list, udp_list) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:create_args_parser; 3, parameters; 3, 4; 4, identifier:description; 5, block; 5, 6; 5, 8; 5, 19; 5, 49; 5, 181; 5, 218; 5, 247; 5, 269; 5, 288; 5, 299; 5, 318; 5, 337; 5, 355; 5, 372; 5, 385; 5, 399; 5, 412; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:parser; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:argparse; 14, identifier:ArgumentParser; 15, argument_list; 15, 16; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:description; 18, identifier:description; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:network_port; 21, parameters; 21, 22; 22, identifier:string; 23, block; 23, 24; 23, 26; 23, 33; 23, 47; 24, expression_statement; 24, 25; 25, comment; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:value; 29, call; 29, 30; 29, 31; 30, identifier:int; 31, argument_list; 31, 32; 32, identifier:string; 33, if_statement; 33, 34; 33, 39; 34, not_operator; 34, 35; 35, comparison_operator:<; 35, 36; 35, 37; 35, 38; 36, integer:0; 37, identifier:value; 38, integer:65535; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:argparse; 44, identifier:ArgumentTypeError; 45, argument_list; 45, 46; 46, string:'port must be in ]0,65535] interval'; 47, return_statement; 47, 48; 48, identifier:value; 49, function_definition; 49, 50; 49, 51; 49, 53; 50, function_name:cacert_file; 51, parameters; 51, 52; 52, identifier:cacert; 53, block; 53, 54; 53, 56; 53, 85; 53, 141; 53, 160; 53, 179; 54, expression_statement; 54, 55; 55, comment; 56, try_statement; 56, 57; 56, 69; 56, 75; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:context; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:ssl; 64, identifier:create_default_context; 65, argument_list; 65, 66; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:cafile; 68, identifier:cacert; 69, except_clause; 69, 70; 69, 71; 69, 72; 70, identifier:AttributeError; 71, comment; 72, block; 72, 73; 73, return_statement; 73, 74; 74, identifier:cacert; 75, except_clause; 75, 76; 75, 77; 76, identifier:IOError; 77, block; 77, 78; 78, raise_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:argparse; 82, identifier:ArgumentTypeError; 83, argument_list; 83, 84; 84, string:'CA Certificate not found'; 85, try_statement; 85, 86; 85, 129; 86, block; 86, 87; 86, 99; 86, 108; 86, 120; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:not_after; 90, subscript; 90, 91; 90, 98; 91, subscript; 91, 92; 91, 97; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:context; 95, identifier:get_ca_certs; 96, argument_list; 97, integer:0; 98, string:'notAfter'; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:not_after; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:ssl; 105, identifier:cert_time_to_seconds; 106, argument_list; 106, 107; 107, identifier:not_after; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:not_before; 111, subscript; 111, 112; 111, 119; 112, subscript; 112, 113; 112, 118; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:context; 116, identifier:get_ca_certs; 117, argument_list; 118, integer:0; 119, string:'notBefore'; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:not_before; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:ssl; 126, identifier:cert_time_to_seconds; 127, argument_list; 127, 128; 128, identifier:not_before; 129, except_clause; 129, 130; 129, 133; 130, tuple; 130, 131; 130, 132; 131, identifier:KeyError; 132, identifier:IndexError; 133, block; 133, 134; 134, raise_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:argparse; 138, identifier:ArgumentTypeError; 139, argument_list; 139, 140; 140, string:'CA Certificate is erroneous'; 141, if_statement; 141, 142; 141, 152; 142, comparison_operator:<; 142, 143; 142, 144; 143, identifier:not_after; 144, call; 144, 145; 144, 146; 145, identifier:int; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:time; 150, identifier:time; 151, argument_list; 152, block; 152, 153; 153, raise_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:argparse; 157, identifier:ArgumentTypeError; 158, argument_list; 158, 159; 159, string:'CA Certificate expired'; 160, if_statement; 160, 161; 160, 171; 161, comparison_operator:>; 161, 162; 161, 163; 162, identifier:not_before; 163, call; 163, 164; 163, 165; 164, identifier:int; 165, argument_list; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:time; 169, identifier:time; 170, argument_list; 171, block; 171, 172; 172, raise_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:argparse; 176, identifier:ArgumentTypeError; 177, argument_list; 177, 178; 178, string:'CA Certificate not active yet'; 179, return_statement; 179, 180; 180, identifier:cacert; 181, function_definition; 181, 182; 181, 183; 181, 185; 182, function_name:log_level; 183, parameters; 183, 184; 184, identifier:string; 185, block; 185, 186; 185, 188; 185, 201; 185, 216; 186, expression_statement; 186, 187; 187, comment; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:value; 191, call; 191, 192; 191, 193; 192, identifier:getattr; 193, argument_list; 193, 194; 193, 195; 193, 200; 194, identifier:logging; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:string; 198, identifier:upper; 199, argument_list; 200, None; 201, if_statement; 201, 202; 201, 208; 202, not_operator; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:isinstance; 205, argument_list; 205, 206; 205, 207; 206, identifier:value; 207, identifier:int; 208, block; 208, 209; 209, raise_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:argparse; 213, identifier:ArgumentTypeError; 214, argument_list; 214, 215; 215, string:'log level must be one of {debug,info,warning,error,critical}'; 216, return_statement; 216, 217; 217, identifier:value; 218, function_definition; 218, 219; 218, 220; 218, 222; 219, function_name:filename; 220, parameters; 220, 221; 221, identifier:string; 222, block; 222, 223; 222, 225; 222, 245; 223, expression_statement; 223, 224; 224, comment; 225, if_statement; 225, 226; 225, 235; 226, not_operator; 226, 227; 227, call; 227, 228; 227, 233; 228, attribute; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:os; 231, identifier:path; 232, identifier:isfile; 233, argument_list; 233, 234; 234, identifier:string; 235, block; 235, 236; 236, raise_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:argparse; 240, identifier:ArgumentTypeError; 241, argument_list; 241, 242; 242, binary_operator:%; 242, 243; 242, 244; 243, string:'%s is not a valid file path'; 244, identifier:string; 245, return_statement; 245, 246; 246, identifier:string; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:parser; 251, identifier:add_argument; 252, argument_list; 252, 253; 252, 254; 252, 255; 252, 258; 252, 261; 253, string:'-p'; 254, string:'--port'; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:default; 257, identifier:PORT; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:type; 260, identifier:network_port; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:help; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, string:'TCP Port to listen on. Default: {0}'; 266, identifier:format; 267, argument_list; 267, 268; 268, identifier:PORT; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:parser; 273, identifier:add_argument; 274, argument_list; 274, 275; 274, 276; 274, 277; 274, 280; 275, string:'-b'; 276, string:'--bind-address'; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:default; 279, identifier:ADDRESS; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:help; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, string:'Address to listen on. Default: {0}'; 285, identifier:format; 286, argument_list; 286, 287; 287, identifier:ADDRESS; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:parser; 292, identifier:add_argument; 293, argument_list; 293, 294; 293, 295; 293, 296; 294, string:'-u'; 295, string:'--unix-socket'; 296, keyword_argument; 296, 297; 296, 298; 297, identifier:help; 298, string:'Unix file socket to listen on.'; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:parser; 303, identifier:add_argument; 304, argument_list; 304, 305; 304, 306; 304, 307; 304, 310; 305, string:'-k'; 306, string:'--key-file'; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:type; 309, identifier:filename; 310, keyword_argument; 310, 311; 310, 312; 311, identifier:help; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, string:'Server key file. Default: {0}'; 315, identifier:format; 316, argument_list; 316, 317; 317, identifier:KEY_FILE; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:parser; 322, identifier:add_argument; 323, argument_list; 323, 324; 323, 325; 323, 326; 323, 329; 324, string:'-c'; 325, string:'--cert-file'; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:type; 328, identifier:filename; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:help; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, string:'Server cert file. Default: {0}'; 334, identifier:format; 335, argument_list; 335, 336; 336, identifier:CERT_FILE; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:parser; 341, identifier:add_argument; 342, argument_list; 342, 343; 342, 344; 342, 347; 343, string:'--ca-file'; 344, keyword_argument; 344, 345; 344, 346; 345, identifier:type; 346, identifier:cacert_file; 347, keyword_argument; 347, 348; 347, 349; 348, identifier:help; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, string:'CA cert file. Default: {0}'; 352, identifier:format; 353, argument_list; 353, 354; 354, identifier:CA_FILE; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:parser; 359, identifier:add_argument; 360, argument_list; 360, 361; 360, 362; 360, 363; 360, 366; 360, 369; 361, string:'-L'; 362, string:'--log-level'; 363, keyword_argument; 363, 364; 363, 365; 364, identifier:default; 365, string:'warning'; 366, keyword_argument; 366, 367; 366, 368; 367, identifier:type; 368, identifier:log_level; 369, keyword_argument; 369, 370; 369, 371; 370, identifier:help; 371, string:'Wished level of logging. Default: WARNING'; 372, expression_statement; 372, 373; 373, call; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:parser; 376, identifier:add_argument; 377, argument_list; 377, 378; 377, 379; 377, 382; 378, string:'--foreground'; 379, keyword_argument; 379, 380; 379, 381; 380, identifier:action; 381, string:'store_true'; 382, keyword_argument; 382, 383; 382, 384; 383, identifier:help; 384, string:'Run in foreground and logs all messages to console.'; 385, expression_statement; 385, 386; 386, call; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, identifier:parser; 389, identifier:add_argument; 390, argument_list; 390, 391; 390, 392; 390, 393; 390, 396; 391, string:'-l'; 392, string:'--log-file'; 393, keyword_argument; 393, 394; 393, 395; 394, identifier:type; 395, identifier:filename; 396, keyword_argument; 396, 397; 396, 398; 397, identifier:help; 398, string:'Path to the logging file.'; 399, expression_statement; 399, 400; 400, call; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:parser; 403, identifier:add_argument; 404, argument_list; 404, 405; 404, 406; 404, 409; 405, string:'--version'; 406, keyword_argument; 406, 407; 406, 408; 407, identifier:action; 408, string:'store_true'; 409, keyword_argument; 409, 410; 409, 411; 410, identifier:help; 411, string:'Print version then exit.'; 412, return_statement; 412, 413; 413, identifier:parser | def create_args_parser(description):
""" Create a command-line arguments parser for OSPD. """
parser = argparse.ArgumentParser(description=description)
def network_port(string):
""" Check if provided string is a valid network port. """
value = int(string)
if not 0 < value <= 65535:
raise argparse.ArgumentTypeError(
'port must be in ]0,65535] interval')
return value
def cacert_file(cacert):
""" Check if provided file is a valid CA Certificate """
try:
context = ssl.create_default_context(cafile=cacert)
except AttributeError:
# Python version < 2.7.9
return cacert
except IOError:
raise argparse.ArgumentTypeError('CA Certificate not found')
try:
not_after = context.get_ca_certs()[0]['notAfter']
not_after = ssl.cert_time_to_seconds(not_after)
not_before = context.get_ca_certs()[0]['notBefore']
not_before = ssl.cert_time_to_seconds(not_before)
except (KeyError, IndexError):
raise argparse.ArgumentTypeError('CA Certificate is erroneous')
if not_after < int(time.time()):
raise argparse.ArgumentTypeError('CA Certificate expired')
if not_before > int(time.time()):
raise argparse.ArgumentTypeError('CA Certificate not active yet')
return cacert
def log_level(string):
""" Check if provided string is a valid log level. """
value = getattr(logging, string.upper(), None)
if not isinstance(value, int):
raise argparse.ArgumentTypeError(
'log level must be one of {debug,info,warning,error,critical}')
return value
def filename(string):
""" Check if provided string is a valid file path. """
if not os.path.isfile(string):
raise argparse.ArgumentTypeError(
'%s is not a valid file path' % string)
return string
parser.add_argument('-p', '--port', default=PORT, type=network_port,
help='TCP Port to listen on. Default: {0}'.format(PORT))
parser.add_argument('-b', '--bind-address', default=ADDRESS,
help='Address to listen on. Default: {0}'
.format(ADDRESS))
parser.add_argument('-u', '--unix-socket',
help='Unix file socket to listen on.')
parser.add_argument('-k', '--key-file', type=filename,
help='Server key file. Default: {0}'.format(KEY_FILE))
parser.add_argument('-c', '--cert-file', type=filename,
help='Server cert file. Default: {0}'.format(CERT_FILE))
parser.add_argument('--ca-file', type=cacert_file,
help='CA cert file. Default: {0}'.format(CA_FILE))
parser.add_argument('-L', '--log-level', default='warning', type=log_level,
help='Wished level of logging. Default: WARNING')
parser.add_argument('--foreground', action='store_true',
help='Run in foreground and logs all messages to console.')
parser.add_argument('-l', '--log-file', type=filename,
help='Path to the logging file.')
parser.add_argument('--version', action='store_true',
help='Print version then exit.')
return parser |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_handle_func; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:value; 6, identifier:rule; 7, identifier:path; 8, default_parameter; 8, 9; 8, 10; 9, identifier:done; 10, None; 11, block; 11, 12; 11, 14; 11, 20; 11, 21; 11, 26; 11, 30; 11, 120; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:func; 17, attribute; 17, 18; 17, 19; 18, identifier:rule; 19, identifier:func; 20, comment; 21, if_statement; 21, 22; 21, 24; 22, not_operator; 22, 23; 23, identifier:func; 24, block; 24, 25; 25, return_statement; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:found_method; 29, False; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:extension; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:loaded_extensions; 35, block; 35, 36; 35, 45; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:method; 39, call; 39, 40; 39, 41; 40, identifier:getattr; 41, argument_list; 41, 42; 41, 43; 41, 44; 42, identifier:extension; 43, identifier:func; 44, None; 45, if_statement; 45, 46; 45, 47; 46, identifier:method; 47, block; 47, 48; 47, 52; 47, 53; 47, 62; 47, 102; 47, 103; 47, 117; 47, 118; 47, 119; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:found_method; 51, True; 52, comment; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:ret; 56, call; 56, 57; 56, 58; 57, identifier:method; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, identifier:value; 60, identifier:rule; 61, identifier:path; 62, if_statement; 62, 63; 62, 70; 63, boolean_operator:and; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:ret; 66, True; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:ret; 69, None; 70, block; 70, 71; 70, 80; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:msg; 74, binary_operator:%; 74, 75; 74, 76; 75, string:'%s. Path: {path}'; 76, call; 76, 77; 76, 78; 77, identifier:unicode; 78, argument_list; 78, 79; 79, identifier:ret; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:errors; 86, identifier:append; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:SchemaError; 91, identifier:SchemaErrorEntry; 92, argument_list; 92, 93; 92, 96; 92, 99; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:msg; 95, identifier:msg; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:path; 98, identifier:path; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:value; 101, None; 102, comment; 103, if_statement; 103, 104; 103, 106; 104, not_operator; 104, 105; 105, identifier:ret; 106, block; 106, 107; 107, raise_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:CoreError; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:u"Error when running extension function : {0}"; 114, identifier:format; 115, argument_list; 115, 116; 116, identifier:func; 117, comment; 118, comment; 119, break_statement; 120, if_statement; 120, 121; 120, 123; 121, not_operator; 121, 122; 122, identifier:found_method; 123, block; 123, 124; 124, raise_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:CoreError; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, string:u"Did not find method '{0}' in any loaded extension file"; 131, identifier:format; 132, argument_list; 132, 133; 133, identifier:func | def _handle_func(self, value, rule, path, done=None):
"""
Helper function that should check if func is specified for this rule and
then handle it for all cases in a generic way.
"""
func = rule.func
# func keyword is not defined so nothing to do
if not func:
return
found_method = False
for extension in self.loaded_extensions:
method = getattr(extension, func, None)
if method:
found_method = True
# No exception will should be caught. If one is raised it should bubble up all the way.
ret = method(value, rule, path)
if ret is not True and ret is not None:
msg = '%s. Path: {path}' % unicode(ret)
self.errors.append(SchemaError.SchemaErrorEntry(
msg=msg,
path=path,
value=None))
# If False or None or some other object that is interpreted as False
if not ret:
raise CoreError(u"Error when running extension function : {0}".format(func))
# Only run the first matched function. Sinc loading order is determined
# it should be easy to determine which file is used before others
break
if not found_method:
raise CoreError(u"Did not find method '{0}' in any loaded extension file".format(func)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_validate_range; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:max_; 6, identifier:min_; 7, identifier:max_ex; 8, identifier:min_ex; 9, identifier:value; 10, identifier:path; 11, identifier:prefix; 12, block; 12, 13; 12, 15; 12, 35; 12, 48; 12, 96; 12, 144; 12, 192; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 29; 16, boolean_operator:and; 16, 17; 16, 23; 17, not_operator; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:isinstance; 20, argument_list; 20, 21; 20, 22; 21, identifier:value; 22, identifier:int; 23, not_operator; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:value; 28, identifier:float; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:CoreError; 33, argument_list; 33, 34; 34, string:"Value must be a integer type"; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:log; 39, identifier:debug; 40, argument_list; 40, 41; 40, 42; 40, 43; 40, 44; 40, 45; 40, 46; 40, 47; 41, string:u"Validate range : %s : %s : %s : %s : %s : %s"; 42, identifier:max_; 43, identifier:min_; 44, identifier:max_ex; 45, identifier:min_ex; 46, identifier:value; 47, identifier:path; 48, if_statement; 48, 49; 48, 56; 49, boolean_operator:and; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:max_; 52, None; 53, comparison_operator:<; 53, 54; 53, 55; 54, identifier:max_; 55, identifier:value; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:errors; 63, identifier:append; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:SchemaError; 68, identifier:SchemaErrorEntry; 69, argument_list; 69, 70; 69, 73; 69, 76; 69, 90; 69, 93; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:msg; 72, string:u"Type '{prefix}' has size of '{value}', greater than max limit '{max_}'. Path: '{path}'"; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:path; 75, identifier:path; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:value; 78, conditional_expression:if; 78, 79; 78, 83; 78, 89; 79, call; 79, 80; 79, 81; 80, identifier:nativestr; 81, argument_list; 81, 82; 82, identifier:value; 83, call; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:tt; 86, string:'str'; 87, argument_list; 87, 88; 88, identifier:value; 89, identifier:value; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:prefix; 92, identifier:prefix; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:max_; 95, identifier:max_; 96, if_statement; 96, 97; 96, 104; 97, boolean_operator:and; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:min_; 100, None; 101, comparison_operator:>; 101, 102; 101, 103; 102, identifier:min_; 103, identifier:value; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:errors; 111, identifier:append; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:SchemaError; 116, identifier:SchemaErrorEntry; 117, argument_list; 117, 118; 117, 121; 117, 124; 117, 138; 117, 141; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:msg; 120, string:u"Type '{prefix}' has size of '{value}', less than min limit '{min_}'. Path: '{path}'"; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:path; 123, identifier:path; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:value; 126, conditional_expression:if; 126, 127; 126, 131; 126, 137; 127, call; 127, 128; 127, 129; 128, identifier:nativestr; 129, argument_list; 129, 130; 130, identifier:value; 131, call; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:tt; 134, string:'str'; 135, argument_list; 135, 136; 136, identifier:value; 137, identifier:value; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:prefix; 140, identifier:prefix; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:min_; 143, identifier:min_; 144, if_statement; 144, 145; 144, 152; 145, boolean_operator:and; 145, 146; 145, 149; 146, comparison_operator:is; 146, 147; 146, 148; 147, identifier:max_ex; 148, None; 149, comparison_operator:<=; 149, 150; 149, 151; 150, identifier:max_ex; 151, identifier:value; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 160; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:errors; 159, identifier:append; 160, argument_list; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:SchemaError; 164, identifier:SchemaErrorEntry; 165, argument_list; 165, 166; 165, 169; 165, 172; 165, 186; 165, 189; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:msg; 168, string:u"Type '{prefix}' has size of '{value}', greater than or equals to max limit(exclusive) '{max_ex}'. Path: '{path}'"; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:path; 171, identifier:path; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:value; 174, conditional_expression:if; 174, 175; 174, 179; 174, 185; 175, call; 175, 176; 175, 177; 176, identifier:nativestr; 177, argument_list; 177, 178; 178, identifier:value; 179, call; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:tt; 182, string:'str'; 183, argument_list; 183, 184; 184, identifier:value; 185, identifier:value; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:prefix; 188, identifier:prefix; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:max_ex; 191, identifier:max_ex; 192, if_statement; 192, 193; 192, 200; 193, boolean_operator:and; 193, 194; 193, 197; 194, comparison_operator:is; 194, 195; 194, 196; 195, identifier:min_ex; 196, None; 197, comparison_operator:>=; 197, 198; 197, 199; 198, identifier:min_ex; 199, identifier:value; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:errors; 207, identifier:append; 208, argument_list; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:SchemaError; 212, identifier:SchemaErrorEntry; 213, argument_list; 213, 214; 213, 217; 213, 220; 213, 234; 213, 237; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:msg; 216, string:u"Type '{prefix}' has size of '{value}', less than or equals to min limit(exclusive) '{min_ex}'. Path: '{path}'"; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:path; 219, identifier:path; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:value; 222, conditional_expression:if; 222, 223; 222, 227; 222, 233; 223, call; 223, 224; 223, 225; 224, identifier:nativestr; 225, argument_list; 225, 226; 226, identifier:value; 227, call; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:tt; 230, string:'str'; 231, argument_list; 231, 232; 232, identifier:value; 233, identifier:value; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:prefix; 236, identifier:prefix; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:min_ex; 239, identifier:min_ex | def _validate_range(self, max_, min_, max_ex, min_ex, value, path, prefix):
"""
Validate that value is within range values.
"""
if not isinstance(value, int) and not isinstance(value, float):
raise CoreError("Value must be a integer type")
log.debug(
u"Validate range : %s : %s : %s : %s : %s : %s",
max_,
min_,
max_ex,
min_ex,
value,
path,
)
if max_ is not None and max_ < value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', greater than max limit '{max_}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
max_=max_))
if min_ is not None and min_ > value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', less than min limit '{min_}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
min_=min_))
if max_ex is not None and max_ex <= value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', greater than or equals to max limit(exclusive) '{max_ex}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
max_ex=max_ex))
if min_ex is not None and min_ex >= value:
self.errors.append(SchemaError.SchemaErrorEntry(
msg=u"Type '{prefix}' has size of '{value}', less than or equals to min limit(exclusive) '{min_ex}'. Path: '{path}'",
path=path,
value=nativestr(value) if tt['str'](value) else value,
prefix=prefix,
min_ex=min_ex)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:tsses; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:db; 5, default_parameter; 5, 6; 5, 7; 6, identifier:merge_overlapping; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:attrs; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:attrs_sep; 13, string:":"; 14, default_parameter; 14, 15; 14, 16; 15, identifier:merge_kwargs; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:as_bed6; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:bedtools_227_or_later; 22, True; 23, block; 23, 24; 23, 26; 23, 38; 23, 75; 23, 110; 23, 122; 23, 192; 23, 193; 23, 208; 23, 209; 23, 233; 23, 314; 23, 392; 24, expression_statement; 24, 25; 25, comment; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:_override; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:os; 33, identifier:environ; 34, identifier:get; 35, argument_list; 35, 36; 35, 37; 36, string:'GFFUTILS_USES_BEDTOOLS_227_OR_LATER'; 37, None; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:_override; 41, None; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 47; 43, 52; 43, 61; 44, comparison_operator:==; 44, 45; 44, 46; 45, identifier:_override; 46, string:'true'; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:bedtools_227_or_later; 51, True; 52, elif_clause; 52, 53; 52, 56; 53, comparison_operator:==; 53, 54; 53, 55; 54, identifier:_override; 55, string:'false'; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:bedtools_227_or_later; 60, False; 61, else_clause; 61, 62; 62, block; 62, 63; 63, raise_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:ValueError; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, concatenated_string; 69, 70; 69, 71; 70, string:"Unknown value for GFFUTILS_USES_BEDTOOLS_227_OR_LATER "; 71, string:"environment variable: {0}"; 72, identifier:format; 73, argument_list; 73, 74; 74, identifier:_override; 75, if_statement; 75, 76; 75, 77; 75, 93; 76, identifier:bedtools_227_or_later; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:_merge_kwargs; 81, call; 81, 82; 81, 83; 82, identifier:dict; 83, argument_list; 83, 84; 83, 87; 83, 90; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:o; 86, string:'distinct'; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:s; 89, True; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:c; 92, string:'4,5,6'; 93, else_clause; 93, 94; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:_merge_kwargs; 98, call; 98, 99; 98, 100; 99, identifier:dict; 100, argument_list; 100, 101; 100, 104; 100, 107; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:o; 103, string:'distinct'; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:s; 106, True; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:c; 109, string:'4'; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:is; 111, 112; 111, 113; 112, identifier:merge_kwargs; 113, None; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:_merge_kwargs; 119, identifier:update; 120, argument_list; 120, 121; 121, identifier:merge_kwargs; 122, function_definition; 122, 123; 122, 124; 122, 125; 123, function_name:gen; 124, parameters; 125, block; 125, 126; 125, 128; 126, expression_statement; 126, 127; 127, comment; 128, for_statement; 128, 129; 128, 130; 128, 136; 129, identifier:gene; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:db; 133, identifier:features_of_type; 134, argument_list; 134, 135; 135, string:'gene'; 136, block; 136, 137; 137, for_statement; 137, 138; 137, 139; 137, 148; 138, identifier:transcript; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:db; 142, identifier:children; 143, argument_list; 143, 144; 143, 145; 144, identifier:gene; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:level; 147, integer:1; 148, block; 148, 149; 148, 174; 148, 184; 149, if_statement; 149, 150; 149, 155; 149, 164; 150, comparison_operator:==; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:transcript; 153, identifier:strand; 154, string:'-'; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:transcript; 160, identifier:start; 161, attribute; 161, 162; 161, 163; 162, identifier:transcript; 163, identifier:stop; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:transcript; 170, identifier:stop; 171, attribute; 171, 172; 171, 173; 172, identifier:transcript; 173, identifier:start; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:transcript; 178, identifier:featuretype; 179, binary_operator:+; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:transcript; 182, identifier:featuretype; 183, string:'_TSS'; 184, expression_statement; 184, 185; 185, yield; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:helpers; 189, identifier:asinterval; 190, argument_list; 190, 191; 191, identifier:transcript; 192, comment; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:x; 196, call; 196, 197; 196, 207; 197, attribute; 197, 198; 197, 206; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:pybedtools; 201, identifier:BedTool; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:gen; 205, argument_list; 206, identifier:sort; 207, argument_list; 208, comment; 209, if_statement; 209, 210; 209, 213; 210, comparison_operator:is; 210, 211; 210, 212; 211, identifier:attrs; 212, None; 213, block; 213, 214; 214, if_statement; 214, 215; 214, 222; 214, 227; 215, comparison_operator:==; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:db; 219, identifier:dialect; 220, string:'fmt'; 221, string:'gtf'; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:attrs; 226, string:'gene_id'; 227, else_clause; 227, 228; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:attrs; 232, string:'ID'; 233, if_statement; 233, 234; 233, 237; 234, boolean_operator:or; 234, 235; 234, 236; 235, identifier:merge_overlapping; 236, identifier:as_bed6; 237, block; 237, 238; 237, 252; 237, 301; 238, if_statement; 238, 239; 238, 246; 239, call; 239, 240; 239, 241; 240, identifier:isinstance; 241, argument_list; 241, 242; 241, 243; 242, identifier:attrs; 243, attribute; 243, 244; 243, 245; 244, identifier:six; 245, identifier:string_types; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:attrs; 250, list:[attrs]; 250, 251; 251, identifier:attrs; 252, function_definition; 252, 253; 252, 254; 252, 256; 253, function_name:to_bed; 254, parameters; 254, 255; 255, identifier:f; 256, block; 256, 257; 256, 259; 256, 276; 257, expression_statement; 257, 258; 258, comment; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:name; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:attrs_sep; 265, identifier:join; 266, argument_list; 266, 267; 267, list_comprehension; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:f; 271, identifier:attrs; 272, identifier:i; 273, for_in_clause; 273, 274; 273, 275; 274, identifier:i; 275, identifier:attrs; 276, return_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:pybedtools; 280, identifier:Interval; 281, argument_list; 281, 282; 281, 285; 281, 288; 281, 291; 281, 292; 281, 298; 282, attribute; 282, 283; 282, 284; 283, identifier:f; 284, identifier:chrom; 285, attribute; 285, 286; 285, 287; 286, identifier:f; 287, identifier:start; 288, attribute; 288, 289; 288, 290; 289, identifier:f; 290, identifier:stop; 291, identifier:name; 292, call; 292, 293; 292, 294; 293, identifier:str; 294, argument_list; 294, 295; 295, attribute; 295, 296; 295, 297; 296, identifier:f; 297, identifier:score; 298, attribute; 298, 299; 298, 300; 299, identifier:f; 300, identifier:strand; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:x; 304, call; 304, 305; 304, 313; 305, attribute; 305, 306; 305, 312; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:x; 309, identifier:each; 310, argument_list; 310, 311; 311, identifier:to_bed; 312, identifier:saveas; 313, argument_list; 314, if_statement; 314, 315; 314, 316; 315, identifier:merge_overlapping; 316, block; 316, 317; 317, if_statement; 317, 318; 317, 319; 317, 330; 318, identifier:bedtools_227_or_later; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:x; 323, call; 323, 324; 323, 327; 324, attribute; 324, 325; 324, 326; 325, identifier:x; 326, identifier:merge; 327, argument_list; 327, 328; 328, dictionary_splat; 328, 329; 329, identifier:_merge_kwargs; 330, else_clause; 330, 331; 331, block; 331, 332; 331, 369; 332, function_definition; 332, 333; 332, 334; 332, 336; 333, function_name:fix_merge; 334, parameters; 334, 335; 335, identifier:f; 336, block; 336, 337; 336, 347; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:f; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:featurefuncs; 343, identifier:extend_fields; 344, argument_list; 344, 345; 344, 346; 345, identifier:f; 346, integer:6; 347, return_statement; 347, 348; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:pybedtools; 351, identifier:Interval; 352, argument_list; 352, 353; 352, 356; 352, 359; 352, 362; 352, 365; 352, 366; 353, attribute; 353, 354; 353, 355; 354, identifier:f; 355, identifier:chrom; 356, attribute; 356, 357; 356, 358; 357, identifier:f; 358, identifier:start; 359, attribute; 359, 360; 359, 361; 360, identifier:f; 361, identifier:stop; 362, subscript; 362, 363; 362, 364; 363, identifier:f; 364, integer:4; 365, string:'.'; 366, subscript; 366, 367; 366, 368; 367, identifier:f; 368, integer:3; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 372; 371, identifier:x; 372, call; 372, 373; 372, 391; 373, attribute; 373, 374; 373, 390; 374, call; 374, 375; 374, 388; 375, attribute; 375, 376; 375, 387; 376, call; 376, 377; 376, 386; 377, attribute; 377, 378; 377, 385; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:x; 381, identifier:merge; 382, argument_list; 382, 383; 383, dictionary_splat; 383, 384; 384, identifier:_merge_kwargs; 385, identifier:saveas; 386, argument_list; 387, identifier:each; 388, argument_list; 388, 389; 389, identifier:fix_merge; 390, identifier:saveas; 391, argument_list; 392, return_statement; 392, 393; 393, identifier:x | def tsses(db, merge_overlapping=False, attrs=None, attrs_sep=":",
merge_kwargs=None, as_bed6=False, bedtools_227_or_later=True):
"""
Create 1-bp transcription start sites for all transcripts in the database
and return as a sorted pybedtools.BedTool object pointing to a temporary
file.
To save the file to a known location, use the `.moveto()` method on the
resulting `pybedtools.BedTool` object.
To extend regions upstream/downstream, see the `.slop()` method on the
resulting `pybedtools.BedTool object`.
Requires pybedtools.
Parameters
----------
db : gffutils.FeatureDB
The database to use
as_bed6 : bool
If True, output file is in BED6 format; otherwise it remains in the
GFF/GTF format and dialect of the file used to create the database.
Note that the merge options below necessarily force `as_bed6=True`.
merge_overlapping : bool
If True, output will be in BED format. Overlapping TSSes will be merged
into a single feature, and their names will be collapsed using
`merge_sep` and placed in the new name field.
merge_kwargs : dict
If `merge_overlapping=True`, these keyword arguments are passed to
pybedtools.BedTool.merge(), which are in turn sent to `bedtools merge`.
The merge operates on a BED6 file which will have had the name field
constructed as specified by other arguments here. See the available
options for your installed version of BEDTools; the defaults used here
are `merge_kwargs=dict(o='distinct', c=4, s=True)`.
Any provided `merge_kwargs` are used to *update* the default. It is
recommended to not override `c=4` and `s=True`, otherwise the
post-merge fixing may not work correctly. Good candidates for tweaking
are `d` (merge distance), `o` (operation), `delim` (delimiter to use
for collapse operations).
attrs : str or list
Only has an effect when `as_bed6=True` or `merge_overlapping=True`.
Determines what goes in the name field of an output BED file. By
default, "gene_id" for GTF databases and "ID" for GFF. If a list of
attributes is supplied, e.g. ["gene_id", "transcript_id"], then these
will be joined by `attr_join_sep` and then placed in the name field.
attrs_sep: str
If `as_bed6=True` or `merge_overlapping=True`, then use this character
to separate attributes in the name field of the output BED. If also
using `merge_overlapping=True`, you'll probably want this to be
different than `merge_sep` in order to parse things out later.
bedtools_227_or_later : bool
In version 2.27, BEDTools changed the output for merge. By default,
this function expects BEDTools version 2.27 or later, but set this to
False to assume the older behavior.
For testing purposes, the environment variable
GFFUTILS_USES_BEDTOOLS_227_OR_LATER is set to either "true" or "false"
and is used to override this argument.
Examples
--------
>>> import gffutils
>>> db = gffutils.create_db(
... gffutils.example_filename('FBgn0031208.gtf'),
... ":memory:",
... keep_order=True,
... verbose=False)
Default settings -- no merging, and report a separate TSS on each line even
if they overlap (as in the first two):
>>> print(tsses(db)) # doctest: +NORMALIZE_WHITESPACE
chr2L gffutils_derived transcript_TSS 7529 7529 . + . gene_id "FBgn0031208"; transcript_id "FBtr0300689";
chr2L gffutils_derived transcript_TSS 7529 7529 . + . gene_id "FBgn0031208"; transcript_id "FBtr0300690";
chr2L gffutils_derived transcript_TSS 11000 11000 . - . gene_id "Fk_gene_1"; transcript_id "transcript_Fk_gene_1";
chr2L gffutils_derived transcript_TSS 12500 12500 . - . gene_id "Fk_gene_2"; transcript_id "transcript_Fk_gene_2";
<BLANKLINE>
Default merging, showing the first two TSSes merged and reported as
a single unique TSS for the gene. Note the conversion to BED:
>>> x = tsses(db, merge_overlapping=True)
>>> print(x) # doctest: +NORMALIZE_WHITESPACE
chr2L 7528 7529 FBgn0031208 . +
chr2L 10999 11000 Fk_gene_1 . -
chr2L 12499 12500 Fk_gene_2 . -
<BLANKLINE>
Report both gene ID and transcript ID in the name. In some cases this can
be easier to parse than the original GTF or GFF file. With no merging
specified, we must add `as_bed6=True` to see the names in BED format.
>>> x = tsses(db, attrs=['gene_id', 'transcript_id'], as_bed6=True)
>>> print(x) # doctest: +NORMALIZE_WHITESPACE
chr2L 7528 7529 FBgn0031208:FBtr0300689 . +
chr2L 7528 7529 FBgn0031208:FBtr0300690 . +
chr2L 10999 11000 Fk_gene_1:transcript_Fk_gene_1 . -
chr2L 12499 12500 Fk_gene_2:transcript_Fk_gene_2 . -
<BLANKLINE>
Use a 3kb merge distance so the last 2 features are merged together:
>>> x = tsses(db, merge_overlapping=True, merge_kwargs=dict(d=3000))
>>> print(x) # doctest: +NORMALIZE_WHITESPACE
chr2L 7528 7529 FBgn0031208 . +
chr2L 10999 12500 Fk_gene_1,Fk_gene_2 . -
<BLANKLINE>
The set of unique TSSes for each gene, +1kb upstream and 500bp downstream:
>>> x = tsses(db, merge_overlapping=True)
>>> x = x.slop(l=1000, r=500, s=True, genome='dm3')
>>> print(x) # doctest: +NORMALIZE_WHITESPACE
chr2L 6528 8029 FBgn0031208 . +
chr2L 10499 12000 Fk_gene_1 . -
chr2L 11999 13500 Fk_gene_2 . -
<BLANKLINE>
"""
_override = os.environ.get('GFFUTILS_USES_BEDTOOLS_227_OR_LATER', None)
if _override is not None:
if _override == 'true':
bedtools_227_or_later = True
elif _override == 'false':
bedtools_227_or_later = False
else:
raise ValueError(
"Unknown value for GFFUTILS_USES_BEDTOOLS_227_OR_LATER "
"environment variable: {0}".format(_override))
if bedtools_227_or_later:
_merge_kwargs = dict(o='distinct', s=True, c='4,5,6')
else:
_merge_kwargs = dict(o='distinct', s=True, c='4')
if merge_kwargs is not None:
_merge_kwargs.update(merge_kwargs)
def gen():
"""
Generator of pybedtools.Intervals representing TSSes.
"""
for gene in db.features_of_type('gene'):
for transcript in db.children(gene, level=1):
if transcript.strand == '-':
transcript.start = transcript.stop
else:
transcript.stop = transcript.start
transcript.featuretype = transcript.featuretype + '_TSS'
yield helpers.asinterval(transcript)
# GFF/GTF format
x = pybedtools.BedTool(gen()).sort()
# Figure out default attrs to use, depending on the original format.
if attrs is None:
if db.dialect['fmt'] == 'gtf':
attrs = 'gene_id'
else:
attrs = 'ID'
if merge_overlapping or as_bed6:
if isinstance(attrs, six.string_types):
attrs = [attrs]
def to_bed(f):
"""
Given a pybedtools.Interval, return a new Interval with the name
set according to the kwargs provided above.
"""
name = attrs_sep.join([f.attrs[i] for i in attrs])
return pybedtools.Interval(
f.chrom,
f.start,
f.stop,
name,
str(f.score),
f.strand)
x = x.each(to_bed).saveas()
if merge_overlapping:
if bedtools_227_or_later:
x = x.merge(**_merge_kwargs)
else:
def fix_merge(f):
f = featurefuncs.extend_fields(f, 6)
return pybedtools.Interval(
f.chrom,
f.start,
f.stop,
f[4],
'.',
f[3])
x = x.merge(**_merge_kwargs).saveas().each(fix_merge).saveas()
return x |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:interfeatures; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:features; 6, default_parameter; 6, 7; 6, 8; 7, identifier:new_featuretype; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:merge_attributes; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:dialect; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:attribute_func; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:update_attributes; 20, None; 21, block; 21, 22; 21, 24; 22, expression_statement; 22, 23; 23, comment; 24, for_statement; 24, 25; 24, 28; 24, 32; 24, 33; 25, pattern_list; 25, 26; 25, 27; 26, identifier:i; 27, identifier:f; 28, call; 28, 29; 28, 30; 29, identifier:enumerate; 30, argument_list; 30, 31; 31, identifier:features; 32, comment; 33, block; 33, 34; 33, 50; 33, 56; 33, 73; 33, 94; 33, 113; 33, 117; 33, 123; 33, 124; 33, 128; 33, 132; 33, 155; 33, 165; 33, 178; 33, 182; 33, 218; 33, 241; 33, 250; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:i; 37, integer:0; 38, block; 38, 39; 38, 45; 38, 49; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:interfeature_start; 42, attribute; 42, 43; 42, 44; 43, identifier:f; 44, identifier:stop; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:last_feature; 48, identifier:f; 49, continue_statement; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:interfeature_stop; 53, attribute; 53, 54; 53, 55; 54, identifier:f; 55, identifier:start; 56, if_statement; 56, 57; 56, 60; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:new_featuretype; 59, None; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:new_featuretype; 64, binary_operator:%; 64, 65; 64, 66; 65, string:'inter_%s_%s'; 66, tuple; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:last_feature; 69, identifier:featuretype; 70, attribute; 70, 71; 70, 72; 71, identifier:f; 72, identifier:featuretype; 73, if_statement; 73, 74; 73, 81; 73, 86; 74, comparison_operator:!=; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:last_feature; 77, identifier:strand; 78, attribute; 78, 79; 78, 80; 79, identifier:f; 80, identifier:strand; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:new_strand; 85, string:'.'; 86, else_clause; 86, 87; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:new_strand; 91, attribute; 91, 92; 91, 93; 92, identifier:f; 93, identifier:strand; 94, if_statement; 94, 95; 94, 102; 94, 103; 94, 104; 94, 105; 94, 106; 94, 107; 95, comparison_operator:!=; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:last_feature; 98, identifier:chrom; 99, attribute; 99, 100; 99, 101; 100, identifier:f; 101, identifier:chrom; 102, comment; 103, comment; 104, comment; 105, comment; 106, comment; 107, block; 107, 108; 107, 112; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:last_feature; 111, identifier:f; 112, continue_statement; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:strand; 116, identifier:new_strand; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:chrom; 120, attribute; 120, 121; 120, 122; 121, identifier:last_feature; 122, identifier:chrom; 123, comment; 124, expression_statement; 124, 125; 125, augmented_assignment:+=; 125, 126; 125, 127; 126, identifier:interfeature_start; 127, integer:1; 128, expression_statement; 128, 129; 129, augmented_assignment:-=; 129, 130; 129, 131; 130, identifier:interfeature_stop; 131, integer:1; 132, if_statement; 132, 133; 132, 134; 132, 149; 133, identifier:merge_attributes; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:new_attributes; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:helpers; 141, identifier:merge_attributes; 142, argument_list; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:last_feature; 145, identifier:attributes; 146, attribute; 146, 147; 146, 148; 147, identifier:f; 148, identifier:attributes; 149, else_clause; 149, 150; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:new_attributes; 154, dictionary; 155, if_statement; 155, 156; 155, 157; 156, identifier:update_attributes; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:new_attributes; 162, identifier:update; 163, argument_list; 163, 164; 164, identifier:update_attributes; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:new_bin; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:bins; 171, identifier:bins; 172, argument_list; 172, 173; 172, 174; 172, 175; 173, identifier:interfeature_start; 174, identifier:interfeature_stop; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:one; 177, True; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:_id; 181, None; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:fields; 185, call; 185, 186; 185, 187; 186, identifier:dict; 187, argument_list; 187, 188; 187, 191; 187, 194; 187, 197; 187, 200; 187, 203; 187, 206; 187, 209; 187, 212; 187, 215; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:seqid; 190, identifier:chrom; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:source; 193, string:'gffutils_derived'; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:featuretype; 196, identifier:new_featuretype; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:start; 199, identifier:interfeature_start; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:end; 202, identifier:interfeature_stop; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:score; 205, string:'.'; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:strand; 208, identifier:strand; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:frame; 211, string:'.'; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:attributes; 214, identifier:new_attributes; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:bin; 217, identifier:new_bin; 218, if_statement; 218, 219; 218, 222; 218, 223; 218, 224; 218, 225; 219, comparison_operator:is; 219, 220; 219, 221; 220, identifier:dialect; 221, None; 222, comment; 223, comment; 224, comment; 225, block; 225, 226; 226, try_statement; 226, 227; 226, 234; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:dialect; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:dialect; 234, except_clause; 234, 235; 234, 236; 235, identifier:AttributeError; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:dialect; 240, None; 241, expression_statement; 241, 242; 242, yield; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:_feature_returner; 247, argument_list; 247, 248; 248, dictionary_splat; 248, 249; 249, identifier:fields; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:interfeature_start; 253, attribute; 253, 254; 253, 255; 254, identifier:f; 255, identifier:stop | def interfeatures(self, features, new_featuretype=None,
merge_attributes=True, dialect=None,
attribute_func=None, update_attributes=None):
"""
Construct new features representing the space between features.
For example, if `features` is a list of exons, then this method will
return the introns. If `features` is a list of genes, then this method
will return the intergenic regions.
Providing N features will return N - 1 new features.
This method purposefully does *not* do any merging or sorting of
coordinates, so you may want to use :meth:`FeatureDB.merge` first, or
when selecting features use the `order_by` kwarg, e.g.,
`db.features_of_type('gene', order_by=('seqid', 'start'))`.
Parameters
----------
features : iterable of :class:`feature.Feature` instances
Sorted, merged iterable
new_featuretype : string or None
The new features will all be of this type, or, if None (default)
then the featuretypes will be constructed from the neighboring
features, e.g., `inter_exon_exon`.
merge_attributes : bool
If True, new features' attributes will be a merge of the neighboring
features' attributes. This is useful if you have provided a list of
exons; the introns will then retain the transcript and/or gene
parents as a single item. Otherwise, if False, the attribute will
be a comma-separated list of values, potentially listing the same
gene ID twice.
attribute_func : callable or None
If None, then nothing special is done to the attributes. If
callable, then the callable accepts two attribute dictionaries and
returns a single attribute dictionary. If `merge_attributes` is
True, then `attribute_func` is called before `merge_attributes`.
This could be useful for manually managing IDs for the new
features.
update_attributes : dict
After attributes have been modified and merged, this dictionary can
be used to replace parts of the attributes dictionary.
Returns
-------
A generator that yields :class:`Feature` objects
"""
for i, f in enumerate(features):
# no inter-feature for the first one
if i == 0:
interfeature_start = f.stop
last_feature = f
continue
interfeature_stop = f.start
if new_featuretype is None:
new_featuretype = 'inter_%s_%s' % (
last_feature.featuretype, f.featuretype)
if last_feature.strand != f.strand:
new_strand = '.'
else:
new_strand = f.strand
if last_feature.chrom != f.chrom:
# We've moved to a new chromosome. For example, if we're
# getting intergenic regions from all genes, they will be on
# different chromosomes. We still assume sorted features, but
# don't complain if they're on different chromosomes -- just
# move on.
last_feature = f
continue
strand = new_strand
chrom = last_feature.chrom
# Shrink
interfeature_start += 1
interfeature_stop -= 1
if merge_attributes:
new_attributes = helpers.merge_attributes(
last_feature.attributes, f.attributes)
else:
new_attributes = {}
if update_attributes:
new_attributes.update(update_attributes)
new_bin = bins.bins(
interfeature_start, interfeature_stop, one=True)
_id = None
fields = dict(
seqid=chrom,
source='gffutils_derived',
featuretype=new_featuretype,
start=interfeature_start,
end=interfeature_stop,
score='.',
strand=strand,
frame='.',
attributes=new_attributes,
bin=new_bin)
if dialect is None:
# Support for @classmethod -- if calling from the class, then
# self.dialect is not defined, so defer to Feature's default
# (which will be constants.dialect, or GFF3).
try:
dialect = self.dialect
except AttributeError:
dialect = None
yield self._feature_returner(**fields)
interfeature_start = f.stop |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:update; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:make_backup; 8, True; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 14; 11, 19; 11, 24; 11, 52; 11, 53; 11, 57; 11, 80; 11, 81; 11, 92; 11, 188; 11, 195; 11, 201; 11, 207; 12, expression_statement; 12, 13; 13, comment; 14, import_from_statement; 14, 15; 14, 17; 15, dotted_name; 15, 16; 16, identifier:gffutils; 17, dotted_name; 17, 18; 18, identifier:create; 19, import_from_statement; 19, 20; 19, 22; 20, dotted_name; 20, 21; 21, identifier:gffutils; 22, dotted_name; 22, 23; 23, identifier:iterators; 24, if_statement; 24, 25; 24, 26; 25, identifier:make_backup; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 37; 28, call; 28, 29; 28, 30; 29, identifier:isinstance; 30, argument_list; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:dbfn; 34, attribute; 34, 35; 34, 36; 35, identifier:six; 36, identifier:string_types; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:shutil; 42, identifier:copy2; 43, argument_list; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:dbfn; 47, binary_operator:+; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:dbfn; 51, string:'.bak'; 52, comment; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:_iterator_kwargs; 56, dictionary; 57, for_statement; 57, 58; 57, 61; 57, 66; 58, pattern_list; 58, 59; 58, 60; 59, identifier:k; 60, identifier:v; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:kwargs; 64, identifier:items; 65, argument_list; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 73; 68, comparison_operator:in; 68, 69; 68, 70; 69, identifier:k; 70, attribute; 70, 71; 70, 72; 71, identifier:constants; 72, identifier:_iterator_kwargs; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:_iterator_kwargs; 78, identifier:k; 79, identifier:v; 80, comment; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:data; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:iterators; 87, identifier:DataIterator; 88, argument_list; 88, 89; 88, 90; 89, identifier:data; 90, dictionary_splat; 90, 91; 91, identifier:_iterator_kwargs; 92, if_statement; 92, 93; 92, 100; 92, 141; 92, 184; 93, comparison_operator:==; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:dialect; 98, string:'fmt'; 99, string:'gtf'; 100, block; 100, 101; 100, 118; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:not; 102, 103; 102, 104; 103, string:'id_spec'; 104, identifier:kwargs; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:kwargs; 110, string:'id_spec'; 111, dictionary; 111, 112; 111, 115; 112, pair; 112, 113; 112, 114; 113, string:'gene'; 114, string:'gene_id'; 115, pair; 115, 116; 115, 117; 116, string:'transcript'; 117, string:'transcript_id'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:db; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:create; 124, identifier:_GTFDBCreator; 125, argument_list; 125, 126; 125, 129; 125, 134; 125, 139; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:data; 128, identifier:data; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:dbfn; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:dbfn; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:dialect; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:dialect; 139, dictionary_splat; 139, 140; 140, identifier:kwargs; 141, elif_clause; 141, 142; 141, 149; 142, comparison_operator:==; 142, 143; 142, 148; 143, subscript; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:dialect; 147, string:'fmt'; 148, string:'gff3'; 149, block; 149, 150; 149, 161; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:not; 151, 152; 151, 153; 152, string:'id_spec'; 153, identifier:kwargs; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:kwargs; 159, string:'id_spec'; 160, string:'ID'; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:db; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:create; 167, identifier:_GFFDBCreator; 168, argument_list; 168, 169; 168, 172; 168, 177; 168, 182; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:data; 171, identifier:data; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:dbfn; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:dbfn; 177, keyword_argument; 177, 178; 177, 179; 178, identifier:dialect; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:dialect; 182, dictionary_splat; 182, 183; 183, identifier:kwargs; 184, else_clause; 184, 185; 185, block; 185, 186; 186, raise_statement; 186, 187; 187, identifier:ValueError; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:db; 192, identifier:_populate_from_lines; 193, argument_list; 193, 194; 194, identifier:data; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:db; 199, identifier:_update_relations; 200, argument_list; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:db; 205, identifier:_finalize; 206, argument_list; 207, return_statement; 207, 208; 208, identifier:db | def update(self, data, make_backup=True, **kwargs):
"""
Update database with features in `data`.
data : str, iterable, FeatureDB instance
If FeatureDB, all data will be used. If string, assume it's
a filename of a GFF or GTF file. Otherwise, assume it's an
iterable of Feature objects. The classes in gffutils.iterators may
be helpful in this case.
make_backup : bool
If True, and the database you're about to update is a file on disk,
makes a copy of the existing database and saves it with a .bak
extension.
Notes
-----
Other kwargs are used in the same way as in gffutils.create_db; see the
help for that function for details.
Returns
-------
FeatureDB with updated features.
"""
from gffutils import create
from gffutils import iterators
if make_backup:
if isinstance(self.dbfn, six.string_types):
shutil.copy2(self.dbfn, self.dbfn + '.bak')
# get iterator-specific kwargs
_iterator_kwargs = {}
for k, v in kwargs.items():
if k in constants._iterator_kwargs:
_iterator_kwargs[k] = v
# Handle all sorts of input
data = iterators.DataIterator(data, **_iterator_kwargs)
if self.dialect['fmt'] == 'gtf':
if 'id_spec' not in kwargs:
kwargs['id_spec'] = {
'gene': 'gene_id', 'transcript': 'transcript_id'}
db = create._GTFDBCreator(
data=data, dbfn=self.dbfn, dialect=self.dialect, **kwargs)
elif self.dialect['fmt'] == 'gff3':
if 'id_spec' not in kwargs:
kwargs['id_spec'] = 'ID'
db = create._GFFDBCreator(
data=data, dbfn=self.dbfn, dialect=self.dialect, **kwargs)
else:
raise ValueError
db._populate_from_lines(data)
db._update_relations()
db._finalize()
return db |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:create_introns; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:exon_featuretype; 7, string:'exon'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:grandparent_featuretype; 10, string:'gene'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:parent_featuretype; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:new_featuretype; 16, string:'intron'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:merge_attributes; 19, True; 20, block; 20, 21; 20, 23; 20, 45; 20, 95; 21, expression_statement; 21, 22; 22, comment; 23, if_statement; 23, 24; 23, 37; 24, boolean_operator:or; 24, 25; 24, 29; 25, parenthesized_expression; 25, 26; 26, boolean_operator:and; 26, 27; 26, 28; 27, identifier:grandparent_featuretype; 28, identifier:parent_featuretype; 29, parenthesized_expression; 29, 30; 30, boolean_operator:and; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:grandparent_featuretype; 33, None; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:parent_featuretype; 36, None; 37, block; 37, 38; 38, raise_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:ValueError; 41, argument_list; 41, 42; 42, concatenated_string; 42, 43; 42, 44; 43, string:"exactly one of `grandparent_featuretype` or "; 44, string:"`parent_featuretype` should be provided"; 45, if_statement; 45, 46; 45, 47; 45, 76; 46, identifier:grandparent_featuretype; 47, block; 47, 48; 48, function_definition; 48, 49; 48, 50; 48, 51; 49, function_name:child_gen; 50, parameters; 51, block; 51, 52; 52, for_statement; 52, 53; 52, 54; 52, 60; 53, identifier:gene; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:features_of_type; 58, argument_list; 58, 59; 59, identifier:grandparent_featuretype; 60, block; 60, 61; 61, for_statement; 61, 62; 61, 63; 61, 72; 62, identifier:child; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:children; 67, argument_list; 67, 68; 67, 69; 68, identifier:gene; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:level; 71, integer:1; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, yield; 74, 75; 75, identifier:child; 76, elif_clause; 76, 77; 76, 78; 77, identifier:parent_featuretype; 78, block; 78, 79; 79, function_definition; 79, 80; 79, 81; 79, 82; 80, function_name:child_gen; 81, parameters; 82, block; 82, 83; 83, for_statement; 83, 84; 83, 85; 83, 91; 84, identifier:child; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:features_of_type; 89, argument_list; 89, 90; 90, identifier:parent_featuretype; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, yield; 93, 94; 94, identifier:child; 95, for_statement; 95, 96; 95, 97; 95, 100; 96, identifier:child; 97, call; 97, 98; 97, 99; 98, identifier:child_gen; 99, argument_list; 100, block; 100, 101; 100, 119; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:exons; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:children; 108, argument_list; 108, 109; 108, 110; 108, 113; 108, 116; 109, identifier:child; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:level; 112, integer:1; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:featuretype; 115, identifier:exon_featuretype; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:order_by; 118, string:'start'; 119, for_statement; 119, 120; 119, 121; 119, 138; 120, identifier:intron; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:interfeatures; 125, argument_list; 125, 126; 125, 127; 125, 130; 125, 133; 126, identifier:exons; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:new_featuretype; 129, identifier:new_featuretype; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:merge_attributes; 132, identifier:merge_attributes; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:dialect; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:dialect; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, yield; 140, 141; 141, identifier:intron | def create_introns(self, exon_featuretype='exon',
grandparent_featuretype='gene', parent_featuretype=None,
new_featuretype='intron', merge_attributes=True):
"""
Create introns from existing annotations.
Parameters
----------
exon_featuretype : string
Feature type to use in order to infer introns. Typically `"exon"`.
grandparent_featuretype : string
If `grandparent_featuretype` is not None, then group exons by
children of this featuretype. If `granparent_featuretype` is
"gene" (default), then introns will be created for all first-level
children of genes. This may include mRNA, rRNA, ncRNA, etc. If
you only want to infer introns from one of these featuretypes
(e.g., mRNA), then use the `parent_featuretype` kwarg which is
mutually exclusive with `grandparent_featuretype`.
parent_featuretype : string
If `parent_featuretype` is not None, then only use this featuretype
to infer introns. Use this if you only want a subset of
featuretypes to have introns (e.g., "mRNA" only, and not ncRNA or
rRNA). Mutually exclusive with `grandparent_featuretype`.
new_featuretype : string
Feature type to use for the inferred introns; default is
`"intron"`.
merge_attributes : bool
Whether or not to merge attributes from all exons. If False then no
attributes will be created for the introns.
Returns
-------
A generator object that yields :class:`Feature` objects representing
new introns
Notes
-----
The returned generator can be passed directly to the
:meth:`FeatureDB.update` method to permanently add them to the
database, e.g., ::
db.update(db.create_introns())
"""
if (grandparent_featuretype and parent_featuretype) or (
grandparent_featuretype is None and parent_featuretype is None
):
raise ValueError("exactly one of `grandparent_featuretype` or "
"`parent_featuretype` should be provided")
if grandparent_featuretype:
def child_gen():
for gene in self.features_of_type(grandparent_featuretype):
for child in self.children(gene, level=1):
yield child
elif parent_featuretype:
def child_gen():
for child in self.features_of_type(parent_featuretype):
yield child
for child in child_gen():
exons = self.children(child, level=1, featuretype=exon_featuretype,
order_by='start')
for intron in self.interfeatures(
exons, new_featuretype=new_featuretype,
merge_attributes=merge_attributes, dialect=self.dialect
):
yield intron |
Subsets and Splits