sequence
stringlengths
546
16.2k
code
stringlengths
108
19.3k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:gather_categories; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:imap; 5, identifier:header; 6, default_parameter; 6, 7; 6, 8; 7, identifier:categories; 8, None; 9, block; 9, 10; 9, 12; 9, 13; 9, 34; 9, 55; 9, 61; 9, 68; 9, 127; 9, 128; 9, 151; 9, 152; 9, 213; 9, 214; 9, 220; 9, 242; 9, 254; 9, 255; 9, 256; 9, 338; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:categories; 16, None; 17, block; 17, 18; 18, return_statement; 18, 19; 19, dictionary; 19, 20; 20, pair; 20, 21; 20, 22; 21, string:"default"; 22, call; 22, 23; 22, 24; 23, identifier:DataCategory; 24, argument_list; 24, 25; 24, 33; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:imap; 31, identifier:keys; 32, argument_list; 33, dictionary; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:cat_ids; 37, list_comprehension; 37, 38; 37, 44; 37, 47; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:header; 41, identifier:index; 42, argument_list; 42, 43; 43, identifier:cat; 44, for_in_clause; 44, 45; 44, 46; 45, identifier:cat; 46, identifier:categories; 47, if_clause; 47, 48; 48, boolean_operator:and; 48, 49; 48, 52; 49, comparison_operator:in; 49, 50; 49, 51; 50, identifier:cat; 51, identifier:header; 52, comparison_operator:not; 52, 53; 52, 54; 53, string:"="; 54, identifier:cat; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:table; 58, call; 58, 59; 58, 60; 59, identifier:OrderedDict; 60, argument_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:conditions; 64, call; 64, 65; 64, 66; 65, identifier:defaultdict; 66, argument_list; 66, 67; 67, identifier:set; 68, for_statement; 68, 69; 68, 72; 68, 76; 69, pattern_list; 69, 70; 69, 71; 70, identifier:i; 71, identifier:cat; 72, call; 72, 73; 72, 74; 73, identifier:enumerate; 74, argument_list; 74, 75; 75, identifier:categories; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 92; 78, boolean_operator:and; 78, 79; 78, 82; 79, comparison_operator:in; 79, 80; 79, 81; 80, string:"="; 81, identifier:cat; 82, comparison_operator:in; 82, 83; 82, 91; 83, subscript; 83, 84; 83, 90; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:cat; 87, identifier:split; 88, argument_list; 88, 89; 89, string:"="; 90, integer:0; 91, identifier:header; 92, block; 92, 93; 92, 111; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:cat_name; 96, subscript; 96, 97; 96, 98; 97, identifier:header; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:header; 101, identifier:index; 102, argument_list; 102, 103; 103, subscript; 103, 104; 103, 110; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:cat; 107, identifier:split; 108, argument_list; 108, 109; 109, string:"="; 110, integer:0; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:conditions; 116, identifier:cat_name; 117, identifier:add; 118, argument_list; 118, 119; 119, subscript; 119, 120; 119, 126; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:cat; 123, identifier:split; 124, argument_list; 124, 125; 125, string:"="; 126, integer:1; 127, comment; 128, if_statement; 128, 129; 128, 134; 129, boolean_operator:and; 129, 130; 129, 132; 130, not_operator; 130, 131; 131, identifier:cat_ids; 132, not_operator; 132, 133; 133, identifier:conditions; 134, block; 134, 135; 135, return_statement; 135, 136; 136, dictionary; 136, 137; 137, pair; 137, 138; 137, 139; 138, string:"default"; 139, call; 139, 140; 139, 141; 140, identifier:DataCategory; 141, argument_list; 141, 142; 141, 150; 142, call; 142, 143; 142, 144; 143, identifier:set; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:imap; 148, identifier:keys; 149, argument_list; 150, dictionary; 151, comment; 152, if_statement; 152, 153; 152, 157; 153, boolean_operator:and; 153, 154; 153, 155; 154, identifier:cat_ids; 155, not_operator; 155, 156; 156, identifier:conditions; 157, block; 157, 158; 157, 211; 158, for_statement; 158, 159; 158, 162; 158, 167; 159, pattern_list; 159, 160; 159, 161; 160, identifier:sid; 161, identifier:row; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:imap; 165, identifier:items; 166, argument_list; 167, block; 167, 168; 167, 183; 167, 200; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:cat_name; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, string:"_"; 174, identifier:join; 175, argument_list; 175, 176; 176, list_comprehension; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:row; 179, identifier:cid; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:cid; 182, identifier:cat_ids; 183, if_statement; 183, 184; 183, 187; 184, comparison_operator:not; 184, 185; 184, 186; 185, identifier:cat_name; 186, identifier:table; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:table; 192, identifier:cat_name; 193, call; 193, 194; 193, 195; 194, identifier:DataCategory; 195, argument_list; 195, 196; 195, 199; 196, call; 196, 197; 196, 198; 197, identifier:set; 198, argument_list; 199, dictionary; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 209; 202, attribute; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:table; 206, identifier:cat_name; 207, identifier:sids; 208, identifier:add; 209, argument_list; 209, 210; 210, identifier:sid; 211, return_statement; 211, 212; 212, identifier:table; 213, comment; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:cond_ids; 217, call; 217, 218; 217, 219; 218, identifier:set; 219, argument_list; 220, for_statement; 220, 221; 220, 222; 220, 223; 221, identifier:k; 222, identifier:conditions; 223, block; 223, 224; 224, try_statement; 224, 225; 224, 238; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:cond_ids; 230, identifier:add; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:header; 235, identifier:index; 236, argument_list; 236, 237; 237, identifier:k; 238, except_clause; 238, 239; 238, 240; 239, identifier:ValueError; 240, block; 240, 241; 241, continue_statement; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:idx_to_test; 245, call; 245, 246; 245, 252; 246, attribute; 246, 247; 246, 251; 247, call; 247, 248; 247, 249; 248, identifier:set; 249, argument_list; 249, 250; 250, identifier:cat_ids; 251, identifier:union; 252, argument_list; 252, 253; 253, identifier:cond_ids; 254, comment; 255, comment; 256, for_statement; 256, 257; 256, 260; 256, 265; 257, pattern_list; 257, 258; 257, 259; 258, identifier:sid; 259, identifier:row; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:imap; 263, identifier:items; 264, argument_list; 265, block; 265, 266; 266, if_statement; 266, 267; 266, 286; 267, call; 267, 268; 267, 269; 268, identifier:all; 269, argument_list; 269, 270; 270, list_comprehension; 270, 271; 270, 283; 271, comparison_operator:in; 271, 272; 271, 280; 272, subscript; 272, 273; 272, 274; 273, identifier:row; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:header; 277, identifier:index; 278, argument_list; 278, 279; 279, identifier:c; 280, subscript; 280, 281; 280, 282; 281, identifier:conditions; 282, identifier:c; 283, for_in_clause; 283, 284; 283, 285; 284, identifier:c; 285, identifier:conditions; 286, block; 286, 287; 286, 302; 286, 327; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:key; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, string:"_"; 293, identifier:join; 294, argument_list; 294, 295; 295, list_comprehension; 295, 296; 295, 299; 296, subscript; 296, 297; 296, 298; 297, identifier:row; 298, identifier:idx; 299, for_in_clause; 299, 300; 299, 301; 300, identifier:idx; 301, identifier:idx_to_test; 302, try_statement; 302, 303; 302, 312; 303, block; 303, 304; 304, assert_statement; 304, 305; 305, comparison_operator:in; 305, 306; 305, 307; 306, identifier:key; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:table; 310, identifier:keys; 311, argument_list; 312, except_clause; 312, 313; 312, 314; 313, identifier:AssertionError; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 320; 317, subscript; 317, 318; 317, 319; 318, identifier:table; 319, identifier:key; 320, call; 320, 321; 320, 322; 321, identifier:DataCategory; 322, argument_list; 322, 323; 322, 326; 323, call; 323, 324; 323, 325; 324, identifier:set; 325, argument_list; 326, dictionary; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 336; 329, attribute; 329, 330; 329, 335; 330, attribute; 330, 331; 330, 334; 331, subscript; 331, 332; 331, 333; 332, identifier:table; 333, identifier:key; 334, identifier:sids; 335, identifier:add; 336, argument_list; 336, 337; 337, identifier:sid; 338, try_statement; 338, 339; 338, 347; 338, 366; 339, block; 339, 340; 340, assert_statement; 340, 341; 341, comparison_operator:>; 341, 342; 341, 346; 342, call; 342, 343; 342, 344; 343, identifier:len; 344, argument_list; 344, 345; 345, identifier:table; 346, integer:0; 347, except_clause; 347, 348; 347, 349; 348, identifier:AssertionError; 349, block; 349, 350; 350, return_statement; 350, 351; 351, dictionary; 351, 352; 352, pair; 352, 353; 352, 354; 353, string:"default"; 354, call; 354, 355; 354, 356; 355, identifier:DataCategory; 356, argument_list; 356, 357; 356, 365; 357, call; 357, 358; 357, 359; 358, identifier:set; 359, argument_list; 359, 360; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:imap; 363, identifier:keys; 364, argument_list; 365, dictionary; 366, else_clause; 366, 367; 367, block; 367, 368; 368, return_statement; 368, 369; 369, identifier:table
def gather_categories(imap, header, categories=None): """ Find the user specified categories in the map and create a dictionary to contain the relevant data for each type within the categories. Multiple categories will have their types combined such that each possible combination will have its own entry in the dictionary. :type imap: dict :param imap: The input mapping file data keyed by SampleID :type header: list :param header: The header line from the input mapping file. This will be searched for the user-specified categories :type categories: list :param categories: The list of user-specified category column name from mapping file :rtype: dict :return: A sorted dictionary keyed on the combinations of all the types found within the user-specified categories. Each entry will contain an empty DataCategory namedtuple. If no categories are specified, a single entry with the key 'default' will be returned """ # If no categories provided, return all SampleIDs if categories is None: return {"default": DataCategory(set(imap.keys()), {})} cat_ids = [header.index(cat) for cat in categories if cat in header and "=" not in cat] table = OrderedDict() conditions = defaultdict(set) for i, cat in enumerate(categories): if "=" in cat and cat.split("=")[0] in header: cat_name = header[header.index(cat.split("=")[0])] conditions[cat_name].add(cat.split("=")[1]) # If invalid categories or conditions identified, return all SampleIDs if not cat_ids and not conditions: return {"default": DataCategory(set(imap.keys()), {})} #If only category column given, return column-wise SampleIDs if cat_ids and not conditions: for sid, row in imap.items(): cat_name = "_".join([row[cid] for cid in cat_ids]) if cat_name not in table: table[cat_name] = DataCategory(set(), {}) table[cat_name].sids.add(sid) return table # Collect all condition names cond_ids = set() for k in conditions: try: cond_ids.add(header.index(k)) except ValueError: continue idx_to_test = set(cat_ids).union(cond_ids) # If column name and condition given, return overlapping SampleIDs of column and # condition combinations for sid, row in imap.items(): if all([row[header.index(c)] in conditions[c] for c in conditions]): key = "_".join([row[idx] for idx in idx_to_test]) try: assert key in table.keys() except AssertionError: table[key] = DataCategory(set(), {}) table[key].sids.add(sid) try: assert len(table) > 0 except AssertionError: return {"default": DataCategory(set(imap.keys()), {})} else: return table
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:color_mapping; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:sample_map; 5, identifier:header; 6, identifier:group_column; 7, default_parameter; 7, 8; 7, 9; 8, identifier:color_column; 9, None; 10, block; 10, 11; 10, 13; 10, 19; 10, 29; 10, 104; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:group_colors; 16, call; 16, 17; 16, 18; 17, identifier:OrderedDict; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:group_gather; 22, call; 22, 23; 22, 24; 23, identifier:gather_categories; 24, argument_list; 24, 25; 24, 26; 24, 27; 25, identifier:sample_map; 26, identifier:header; 27, list:[group_column]; 27, 28; 28, identifier:group_column; 29, if_statement; 29, 30; 29, 33; 29, 77; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:color_column; 32, None; 33, block; 33, 34; 33, 44; 33, 45; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:color_gather; 37, call; 37, 38; 37, 39; 38, identifier:gather_categories; 39, argument_list; 39, 40; 39, 41; 39, 42; 40, identifier:sample_map; 41, identifier:header; 42, list:[color_column]; 42, 43; 43, identifier:color_column; 44, comment; 45, for_statement; 45, 46; 45, 47; 45, 48; 46, identifier:group; 47, identifier:group_gather; 48, block; 48, 49; 49, for_statement; 49, 50; 49, 51; 49, 52; 49, 53; 49, 54; 50, identifier:color; 51, identifier:color_gather; 52, comment; 53, comment; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 70; 56, call; 56, 57; 56, 64; 57, attribute; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, subscript; 59, 60; 59, 61; 60, identifier:group_gather; 61, identifier:group; 62, identifier:sids; 63, identifier:intersection; 64, argument_list; 64, 65; 65, attribute; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:color_gather; 68, identifier:color; 69, identifier:sids; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:group_colors; 75, identifier:group; 76, identifier:color; 77, else_clause; 77, 78; 78, block; 78, 79; 78, 90; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:bcolors; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:itertools; 85, identifier:cycle; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:Set3_12; 89, identifier:hex_colors; 90, for_statement; 90, 91; 90, 92; 90, 93; 91, identifier:group; 92, identifier:group_gather; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:group_colors; 98, identifier:group; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:bcolors; 102, identifier:next; 103, argument_list; 104, return_statement; 104, 105; 105, identifier:group_colors
def color_mapping(sample_map, header, group_column, color_column=None): """ Determine color-category mapping. If color_column was specified, then map the category names to color values. Otherwise, use the palettable colors to automatically generate a set of colors for the group values. :type sample_map: dict :param unifracFN: Map associating each line of the mapping file with the appropriate sample ID (each value of the map also contains the sample ID) :type header: tuple :param A tuple of header line for mapping file :type group_column: str :param group_column: String denoting the column name for sample groups. :type color_column: str :param color_column: String denoting the column name for sample colors. :type return: dict :param return: {SampleID: Color} """ group_colors = OrderedDict() group_gather = gather_categories(sample_map, header, [group_column]) if color_column is not None: color_gather = gather_categories(sample_map, header, [color_column]) # match sample IDs between color_gather and group_gather for group in group_gather: for color in color_gather: # allow incomplete assignment of colors, if group sids overlap at # all with the color sids, consider it a match if group_gather[group].sids.intersection(color_gather[color].sids): group_colors[group] = color else: bcolors = itertools.cycle(Set3_12.hex_colors) for group in group_gather: group_colors[group] = bcolors.next() return group_colors
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:shuffle_genome; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 12; 3, 15; 3, 16; 3, 19; 3, 22; 3, 23; 3, 26; 4, identifier:genome; 5, identifier:cat; 6, default_parameter; 6, 7; 6, 8; 7, identifier:fraction; 8, call; 8, 9; 8, 10; 9, identifier:float; 10, argument_list; 10, 11; 11, integer:100; 12, default_parameter; 12, 13; 12, 14; 13, identifier:plot; 14, True; 15, line_continuation:\; 16, default_parameter; 16, 17; 16, 18; 17, identifier:alpha; 18, float:0.1; 19, default_parameter; 19, 20; 19, 21; 20, identifier:beta; 21, integer:100000; 22, line_continuation:\; 23, default_parameter; 23, 24; 23, 25; 24, identifier:min_length; 25, integer:1000; 26, default_parameter; 26, 27; 26, 28; 27, identifier:max_length; 28, integer:200000; 29, block; 29, 30; 29, 32; 29, 41; 29, 62; 29, 69; 29, 73; 29, 74; 29, 160; 29, 161; 29, 168; 29, 169; 29, 252; 29, 253; 30, expression_statement; 30, 31; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:header; 35, binary_operator:%; 35, 36; 35, 37; 36, string:'>randomized_%s'; 37, parenthesized_expression; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:genome; 40, identifier:name; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:sequence; 44, call; 44, 45; 44, 46; 45, identifier:list; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:''; 50, identifier:join; 51, argument_list; 51, 52; 52, list_comprehension; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:i; 55, integer:1; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:i; 58, call; 58, 59; 58, 60; 59, identifier:parse_fasta; 60, argument_list; 60, 61; 61, identifier:genome; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:length; 65, call; 65, 66; 65, 67; 66, identifier:len; 67, argument_list; 67, 68; 68, identifier:sequence; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:shuffled; 72, list:[]; 73, comment; 74, while_statement; 74, 75; 74, 78; 75, comparison_operator:is; 75, 76; 75, 77; 76, identifier:sequence; 77, False; 78, block; 78, 79; 78, 92; 78, 102; 78, 129; 78, 137; 78, 138; 78, 139; 78, 140; 78, 141; 78, 142; 78, 154; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:s; 82, call; 82, 83; 82, 84; 83, identifier:int; 84, argument_list; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:random; 88, identifier:gammavariate; 89, argument_list; 89, 90; 89, 91; 90, identifier:alpha; 91, identifier:beta; 92, if_statement; 92, 93; 92, 100; 93, boolean_operator:or; 93, 94; 93, 97; 94, comparison_operator:<=; 94, 95; 94, 96; 95, identifier:s; 96, identifier:min_length; 97, comparison_operator:>=; 97, 98; 97, 99; 98, identifier:s; 99, identifier:max_length; 100, block; 100, 101; 101, continue_statement; 102, if_statement; 102, 103; 102, 109; 102, 118; 103, comparison_operator:<; 103, 104; 103, 108; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:sequence; 108, identifier:s; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:seq; 113, subscript; 113, 114; 113, 115; 114, identifier:sequence; 115, slice; 115, 116; 115, 117; 116, integer:0; 117, colon; 118, else_clause; 118, 119; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:seq; 123, subscript; 123, 124; 123, 125; 124, identifier:sequence; 125, slice; 125, 126; 125, 127; 125, 128; 126, integer:0; 127, colon; 128, identifier:s; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:sequence; 132, subscript; 132, 133; 132, 134; 133, identifier:sequence; 134, slice; 134, 135; 134, 136; 135, identifier:s; 136, colon; 137, comment; 138, comment; 139, comment; 140, comment; 141, comment; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:shuffled; 146, identifier:append; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, string:''; 151, identifier:join; 152, argument_list; 152, 153; 153, identifier:seq; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:==; 155, 156; 155, 157; 156, identifier:sequence; 157, list:[]; 158, block; 158, 159; 159, break_statement; 160, comment; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:random; 165, identifier:shuffle; 166, argument_list; 166, 167; 167, identifier:shuffled; 168, comment; 169, if_statement; 169, 170; 169, 176; 169, 181; 170, comparison_operator:==; 170, 171; 170, 172; 171, identifier:fraction; 172, call; 172, 173; 172, 174; 173, identifier:float; 174, argument_list; 174, 175; 175, integer:100; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:subset; 180, identifier:shuffled; 181, else_clause; 181, 182; 182, block; 182, 183; 182, 194; 182, 202; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:max_pieces; 186, call; 186, 187; 186, 188; 187, identifier:int; 188, argument_list; 188, 189; 189, binary_operator:/; 189, 190; 189, 193; 190, binary_operator:*; 190, 191; 190, 192; 191, identifier:length; 192, identifier:fraction; 193, integer:100; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, pattern_list; 196, 197; 196, 198; 197, identifier:subset; 198, identifier:total; 199, expression_list; 199, 200; 199, 201; 200, list:[]; 201, integer:0; 202, for_statement; 202, 203; 202, 204; 202, 205; 203, identifier:fragment; 204, identifier:shuffled; 205, block; 205, 206; 205, 213; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:length; 209, call; 209, 210; 209, 211; 210, identifier:len; 211, argument_list; 211, 212; 212, identifier:fragment; 213, if_statement; 213, 214; 213, 219; 213, 231; 214, comparison_operator:<=; 214, 215; 214, 218; 215, binary_operator:+; 215, 216; 215, 217; 216, identifier:total; 217, identifier:length; 218, identifier:max_pieces; 219, block; 219, 220; 219, 227; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:subset; 224, identifier:append; 225, argument_list; 225, 226; 226, identifier:fragment; 227, expression_statement; 227, 228; 228, augmented_assignment:+=; 228, 229; 228, 230; 229, identifier:total; 230, identifier:length; 231, else_clause; 231, 232; 232, block; 232, 233; 232, 239; 232, 251; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:diff; 236, binary_operator:-; 236, 237; 236, 238; 237, identifier:max_pieces; 238, identifier:total; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:subset; 243, identifier:append; 244, argument_list; 244, 245; 245, subscript; 245, 246; 245, 247; 246, identifier:fragment; 247, slice; 247, 248; 247, 249; 247, 250; 248, integer:0; 249, colon; 250, identifier:diff; 251, break_statement; 252, comment; 253, if_statement; 253, 254; 253, 257; 253, 268; 254, comparison_operator:is; 254, 255; 254, 256; 255, identifier:cat; 256, True; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, yield; 259, 260; 260, list:[header, ''.join(subset)]; 260, 261; 260, 262; 261, identifier:header; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, string:''; 265, identifier:join; 266, argument_list; 266, 267; 267, identifier:subset; 268, else_clause; 268, 269; 269, block; 269, 270; 270, for_statement; 270, 271; 270, 274; 270, 278; 271, pattern_list; 271, 272; 271, 273; 272, identifier:i; 273, identifier:seq; 274, call; 274, 275; 274, 276; 275, identifier:enumerate; 276, argument_list; 276, 277; 277, identifier:subset; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, yield; 280, 281; 281, list:['%s fragment:%s' % (header, i), seq]; 281, 282; 281, 287; 282, binary_operator:%; 282, 283; 282, 284; 283, string:'%s fragment:%s'; 284, tuple; 284, 285; 284, 286; 285, identifier:header; 286, identifier:i; 287, identifier:seq
def shuffle_genome(genome, cat, fraction = float(100), plot = True, \ alpha = 0.1, beta = 100000, \ min_length = 1000, max_length = 200000): """ randomly shuffle genome """ header = '>randomized_%s' % (genome.name) sequence = list(''.join([i[1] for i in parse_fasta(genome)])) length = len(sequence) shuffled = [] # break genome into pieces while sequence is not False: s = int(random.gammavariate(alpha, beta)) if s <= min_length or s >= max_length: continue if len(sequence) < s: seq = sequence[0:] else: seq = sequence[0:s] sequence = sequence[s:] # if bool(random.getrandbits(1)) is True: # seq = rev_c(seq) # print('fragment length: %s reverse complement: True' % ('{:,}'.format(s)), file=sys.stderr) # else: # print('fragment length: %s reverse complement: False' % ('{:,}'.format(s)), file=sys.stderr) shuffled.append(''.join(seq)) if sequence == []: break # shuffle pieces random.shuffle(shuffled) # subset fragments if fraction == float(100): subset = shuffled else: max_pieces = int(length * fraction/100) subset, total = [], 0 for fragment in shuffled: length = len(fragment) if total + length <= max_pieces: subset.append(fragment) total += length else: diff = max_pieces - total subset.append(fragment[0:diff]) break # combine sequences, if requested if cat is True: yield [header, ''.join(subset)] else: for i, seq in enumerate(subset): yield ['%s fragment:%s' % (header, i), seq]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sam2fastq; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:sam; 5, default_parameter; 5, 6; 5, 7; 6, identifier:singles; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:force; 10, False; 11, block; 11, 12; 11, 14; 11, 22; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, pattern_list; 16, 17; 16, 18; 17, identifier:L; 18, identifier:R; 19, expression_list; 19, 20; 19, 21; 20, None; 21, None; 22, for_statement; 22, 23; 22, 24; 22, 25; 23, identifier:line; 24, identifier:sam; 25, block; 25, 26; 25, 37; 25, 49; 25, 84; 25, 99; 25, 111; 25, 112; 25, 129; 25, 130; 25, 174; 25, 175; 25, 263; 26, if_statement; 26, 27; 26, 35; 27, comparison_operator:is; 27, 28; 27, 34; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:line; 31, identifier:startswith; 32, argument_list; 32, 33; 33, string:'@'; 34, True; 35, block; 35, 36; 36, continue_statement; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:line; 40, call; 40, 41; 40, 48; 41, attribute; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:line; 45, identifier:strip; 46, argument_list; 47, identifier:split; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:bit; 52, list_comprehension; 52, 53; 52, 59; 52, 60; 53, conditional_expression:if; 53, 54; 53, 55; 53, 58; 54, True; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:i; 57, string:'1'; 58, False; 59, line_continuation:\; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:i; 62, subscript; 62, 63; 62, 79; 63, subscript; 63, 64; 63, 78; 64, call; 64, 65; 64, 76; 65, attribute; 65, 66; 65, 75; 66, call; 66, 67; 66, 68; 67, identifier:bin; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:int; 71, argument_list; 71, 72; 72, subscript; 72, 73; 72, 74; 73, identifier:line; 74, integer:1; 75, identifier:split; 76, argument_list; 76, 77; 77, string:'b'; 78, integer:1; 79, slice; 79, 80; 79, 81; 79, 82; 80, colon; 81, colon; 82, unary_operator:-; 82, 83; 83, integer:1; 84, while_statement; 84, 85; 84, 91; 85, comparison_operator:<; 85, 86; 85, 90; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, identifier:bit; 90, integer:8; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:bit; 96, identifier:append; 97, argument_list; 97, 98; 98, False; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 110; 101, pattern_list; 101, 102; 101, 103; 101, 104; 101, 105; 101, 106; 101, 107; 101, 108; 101, 109; 102, identifier:pair; 103, identifier:proper; 104, identifier:na; 105, identifier:nap; 106, identifier:rev; 107, identifier:mrev; 108, identifier:left; 109, identifier:right; 110, identifier:bit; 111, comment; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:pair; 115, False; 116, block; 116, 117; 116, 128; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:singles; 120, True; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:print_single; 125, argument_list; 125, 126; 125, 127; 126, identifier:line; 127, identifier:rev; 128, continue_statement; 129, comment; 130, if_statement; 130, 131; 130, 134; 130, 160; 131, comparison_operator:is; 131, 132; 131, 133; 132, identifier:rev; 133, True; 134, block; 134, 135; 134, 148; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:seq; 138, subscript; 138, 139; 138, 147; 139, call; 139, 140; 139, 141; 140, identifier:rc; 141, argument_list; 141, 142; 142, list:['', line[9]]; 142, 143; 142, 144; 143, string:''; 144, subscript; 144, 145; 144, 146; 145, identifier:line; 146, integer:9; 147, integer:1; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:qual; 151, subscript; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:line; 154, integer:10; 155, slice; 155, 156; 155, 157; 155, 158; 156, colon; 157, colon; 158, unary_operator:-; 158, 159; 159, integer:1; 160, else_clause; 160, 161; 161, block; 161, 162; 161, 168; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:seq; 165, subscript; 165, 166; 165, 167; 166, identifier:line; 167, integer:9; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:qual; 171, subscript; 171, 172; 171, 173; 172, identifier:line; 173, integer:10; 174, comment; 175, if_statement; 175, 176; 175, 179; 176, comparison_operator:is; 176, 177; 176, 178; 177, identifier:left; 178, True; 179, block; 179, 180; 179, 218; 179, 228; 179, 244; 180, if_statement; 180, 181; 180, 188; 181, boolean_operator:and; 181, 182; 181, 185; 182, comparison_operator:is; 182, 183; 182, 184; 183, identifier:L; 184, None; 185, comparison_operator:is; 185, 186; 185, 187; 186, identifier:force; 187, False; 188, block; 188, 189; 188, 199; 188, 214; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 192; 191, identifier:print; 192, argument_list; 192, 193; 192, 194; 193, string:'sam file is not sorted'; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:file; 196, attribute; 196, 197; 196, 198; 197, identifier:sys; 198, identifier:stderr; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:print; 202, argument_list; 202, 203; 202, 209; 203, binary_operator:%; 203, 204; 203, 205; 204, string:'\te.g.: %s'; 205, parenthesized_expression; 205, 206; 206, subscript; 206, 207; 206, 208; 207, identifier:line; 208, integer:0; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:file; 211, attribute; 211, 212; 211, 213; 212, identifier:sys; 213, identifier:stderr; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:exit; 217, argument_list; 218, if_statement; 218, 219; 218, 222; 219, comparison_operator:is; 219, 220; 219, 221; 220, identifier:L; 221, None; 222, block; 222, 223; 222, 227; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:L; 226, None; 227, continue_statement; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:L; 231, list:['@%s' % line[0], seq, '+%s' % line[0], qual]; 231, 232; 231, 237; 231, 238; 231, 243; 232, binary_operator:%; 232, 233; 232, 234; 233, string:'@%s'; 234, subscript; 234, 235; 234, 236; 235, identifier:line; 236, integer:0; 237, identifier:seq; 238, binary_operator:%; 238, 239; 238, 240; 239, string:'+%s'; 240, subscript; 240, 241; 240, 242; 241, identifier:line; 242, integer:0; 243, identifier:qual; 244, if_statement; 244, 245; 244, 248; 245, comparison_operator:is; 245, 246; 245, 247; 246, identifier:R; 247, None; 248, block; 248, 249; 248, 252; 248, 255; 249, expression_statement; 249, 250; 250, yield; 250, 251; 251, identifier:L; 252, expression_statement; 252, 253; 253, yield; 253, 254; 254, identifier:R; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 260; 257, pattern_list; 257, 258; 257, 259; 258, identifier:L; 259, identifier:R; 260, expression_list; 260, 261; 260, 262; 261, None; 262, None; 263, if_statement; 263, 264; 263, 267; 264, comparison_operator:is; 264, 265; 264, 266; 265, identifier:right; 266, True; 267, block; 267, 268; 267, 306; 267, 316; 267, 332; 268, if_statement; 268, 269; 268, 276; 269, boolean_operator:and; 269, 270; 269, 273; 270, comparison_operator:is; 270, 271; 270, 272; 271, identifier:R; 272, None; 273, comparison_operator:is; 273, 274; 273, 275; 274, identifier:force; 275, False; 276, block; 276, 277; 276, 287; 276, 302; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 280; 279, identifier:print; 280, argument_list; 280, 281; 280, 282; 281, string:'sam file is not sorted'; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:file; 284, attribute; 284, 285; 284, 286; 285, identifier:sys; 286, identifier:stderr; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 290; 289, identifier:print; 290, argument_list; 290, 291; 290, 297; 291, binary_operator:%; 291, 292; 291, 293; 292, string:'\te.g.: %s'; 293, parenthesized_expression; 293, 294; 294, subscript; 294, 295; 294, 296; 295, identifier:line; 296, integer:0; 297, keyword_argument; 297, 298; 297, 299; 298, identifier:file; 299, attribute; 299, 300; 299, 301; 300, identifier:sys; 301, identifier:stderr; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:exit; 305, argument_list; 306, if_statement; 306, 307; 306, 310; 307, comparison_operator:is; 307, 308; 307, 309; 308, identifier:R; 309, None; 310, block; 310, 311; 310, 315; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:R; 314, None; 315, continue_statement; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:R; 319, list:['@%s' % line[0], seq, '+%s' % line[0], qual]; 319, 320; 319, 325; 319, 326; 319, 331; 320, binary_operator:%; 320, 321; 320, 322; 321, string:'@%s'; 322, subscript; 322, 323; 322, 324; 323, identifier:line; 324, integer:0; 325, identifier:seq; 326, binary_operator:%; 326, 327; 326, 328; 327, string:'+%s'; 328, subscript; 328, 329; 328, 330; 329, identifier:line; 330, integer:0; 331, identifier:qual; 332, if_statement; 332, 333; 332, 336; 333, comparison_operator:is; 333, 334; 333, 335; 334, identifier:L; 335, None; 336, block; 336, 337; 336, 340; 336, 343; 337, expression_statement; 337, 338; 338, yield; 338, 339; 339, identifier:L; 340, expression_statement; 340, 341; 341, yield; 341, 342; 342, identifier:R; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 348; 345, pattern_list; 345, 346; 345, 347; 346, identifier:L; 347, identifier:R; 348, expression_list; 348, 349; 348, 350; 349, None; 350, None
def sam2fastq(sam, singles = False, force = False): """ convert sam to fastq """ L, R = None, None for line in sam: if line.startswith('@') is True: continue line = line.strip().split() bit = [True if i == '1' else False \ for i in bin(int(line[1])).split('b')[1][::-1]] while len(bit) < 8: bit.append(False) pair, proper, na, nap, rev, mrev, left, right = bit # make sure read is paired if pair is False: if singles is True: print_single(line, rev) continue # check if sequence is reverse-complemented if rev is True: seq = rc(['', line[9]])[1] qual = line[10][::-1] else: seq = line[9] qual = line[10] # check if read is forward or reverse, return when both have been found if left is True: if L is not None and force is False: print('sam file is not sorted', file = sys.stderr) print('\te.g.: %s' % (line[0]), file = sys.stderr) exit() if L is not None: L = None continue L = ['@%s' % line[0], seq, '+%s' % line[0], qual] if R is not None: yield L yield R L, R = None, None if right is True: if R is not None and force is False: print('sam file is not sorted', file = sys.stderr) print('\te.g.: %s' % (line[0]), file = sys.stderr) exit() if R is not None: R = None continue R = ['@%s' % line[0], seq, '+%s' % line[0], qual] if L is not None: yield L yield R L, R = None, None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_sam; 3, parameters; 3, 4; 3, 5; 4, identifier:sam; 5, identifier:sort; 6, block; 6, 7; 6, 9; 6, 31; 6, 143; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:tempdir; 12, binary_operator:%; 12, 13; 12, 14; 13, string:'%s/'; 14, parenthesized_expression; 14, 15; 15, subscript; 15, 16; 15, 30; 16, call; 16, 17; 16, 27; 17, attribute; 17, 18; 17, 26; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:os; 22, identifier:path; 23, identifier:abspath; 24, argument_list; 24, 25; 25, identifier:sam; 26, identifier:rsplit; 27, argument_list; 27, 28; 27, 29; 28, string:'/'; 29, integer:1; 30, integer:0; 31, if_statement; 31, 32; 31, 35; 31, 121; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:sort; 34, True; 35, block; 35, 36; 35, 51; 35, 114; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:mapping; 39, binary_operator:%; 39, 40; 39, 41; 40, string:'%s.sorted.sam'; 41, parenthesized_expression; 41, 42; 42, subscript; 42, 43; 42, 50; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:sam; 46, identifier:rsplit; 47, argument_list; 47, 48; 47, 49; 48, string:'.'; 49, integer:1; 50, integer:0; 51, if_statement; 51, 52; 51, 55; 51, 81; 52, comparison_operator:!=; 52, 53; 52, 54; 53, identifier:sam; 54, string:'-'; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 67; 57, comparison_operator:is; 57, 58; 57, 66; 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:exists; 64, argument_list; 64, 65; 65, identifier:mapping; 66, False; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:os; 72, identifier:system; 73, argument_list; 73, 74; 74, binary_operator:%; 74, 75; 74, 76; 75, string:"\ sort -k1 --buffer-size=%sG -T %s -o %s %s\ "; 76, tuple; 76, 77; 76, 78; 76, 79; 76, 80; 77, identifier:sbuffer; 78, identifier:tempdir; 79, identifier:mapping; 80, identifier:sam; 81, else_clause; 81, 82; 82, block; 82, 83; 82, 87; 82, 108; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:mapping; 86, string:'stdin-sam.sorted.sam'; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:p; 90, call; 90, 91; 90, 92; 91, identifier:Popen; 92, argument_list; 92, 93; 92, 100; 92, 105; 93, binary_operator:%; 93, 94; 93, 95; 93, 96; 94, string:"sort -k1 --buffer-size=%sG -T %s -o %s"; 95, line_continuation:\; 96, tuple; 96, 97; 96, 98; 96, 99; 97, identifier:sbuffer; 98, identifier:tempdir; 99, identifier:mapping; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:stdin; 102, attribute; 102, 103; 102, 104; 103, identifier:sys; 104, identifier:stdin; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:shell; 107, True; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:p; 112, identifier:communicate; 113, argument_list; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:mapping; 117, call; 117, 118; 117, 119; 118, identifier:open; 119, argument_list; 119, 120; 120, identifier:mapping; 121, else_clause; 121, 122; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 127; 123, 134; 124, comparison_operator:==; 124, 125; 124, 126; 125, identifier:sam; 126, string:'-'; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:mapping; 131, attribute; 131, 132; 131, 133; 132, identifier:sys; 133, identifier:stdin; 134, else_clause; 134, 135; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:mapping; 139, call; 139, 140; 139, 141; 140, identifier:open; 141, argument_list; 141, 142; 142, identifier:sam; 143, return_statement; 143, 144; 144, identifier:mapping
def sort_sam(sam, sort): """ sort sam file """ tempdir = '%s/' % (os.path.abspath(sam).rsplit('/', 1)[0]) if sort is True: mapping = '%s.sorted.sam' % (sam.rsplit('.', 1)[0]) if sam != '-': if os.path.exists(mapping) is False: os.system("\ sort -k1 --buffer-size=%sG -T %s -o %s %s\ " % (sbuffer, tempdir, mapping, sam)) else: mapping = 'stdin-sam.sorted.sam' p = Popen("sort -k1 --buffer-size=%sG -T %s -o %s" \ % (sbuffer, tempdir, mapping), stdin = sys.stdin, shell = True) p.communicate() mapping = open(mapping) else: if sam == '-': mapping = sys.stdin else: mapping = open(sam) return mapping
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:crossmap; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:fas; 5, identifier:reads; 6, identifier:options; 7, identifier:no_shrink; 8, identifier:keepDB; 9, identifier:threads; 10, identifier:cluster; 11, identifier:nodes; 12, block; 12, 13; 12, 15; 12, 24; 12, 28; 12, 215; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:cluster; 18, True; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:threads; 23, string:'48'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:btc; 27, list:[]; 28, for_statement; 28, 29; 28, 30; 28, 31; 29, identifier:fa; 30, identifier:fas; 31, block; 31, 32; 31, 40; 31, 47; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:btd; 35, call; 35, 36; 35, 37; 36, identifier:bowtiedb; 37, argument_list; 37, 38; 37, 39; 38, identifier:fa; 39, identifier:keepDB; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 46; 42, pattern_list; 42, 43; 42, 44; 42, 45; 43, identifier:F; 44, identifier:R; 45, identifier:U; 46, identifier:reads; 47, if_statement; 47, 48; 47, 51; 47, 144; 48, comparison_operator:is; 48, 49; 48, 50; 49, identifier:F; 50, False; 51, block; 51, 52; 51, 61; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:U; 55, False; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:u; 60, False; 61, for_statement; 61, 62; 61, 65; 61, 69; 62, pattern_list; 62, 63; 62, 64; 63, identifier:i; 64, identifier:f; 65, call; 65, 66; 65, 67; 66, identifier:enumerate; 67, argument_list; 67, 68; 68, identifier:F; 69, block; 69, 70; 69, 76; 69, 87; 69, 127; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:r; 73, subscript; 73, 74; 73, 75; 74, identifier:R; 75, identifier:i; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:U; 79, False; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:u; 84, subscript; 84, 85; 84, 86; 85, identifier:U; 86, identifier:i; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:sam; 90, binary_operator:%; 90, 91; 90, 92; 91, string:'%s/%s-vs-%s'; 92, tuple; 92, 93; 92, 98; 92, 99; 92, 109; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:os; 96, identifier:getcwd; 97, argument_list; 98, line_continuation:\; 99, subscript; 99, 100; 99, 107; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:fa; 103, identifier:rsplit; 104, argument_list; 104, 105; 104, 106; 105, string:'/'; 106, integer:1; 107, unary_operator:-; 107, 108; 108, integer:1; 109, subscript; 109, 110; 109, 126; 110, call; 110, 111; 110, 123; 111, attribute; 111, 112; 111, 122; 112, subscript; 112, 113; 112, 120; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:f; 116, identifier:rsplit; 117, argument_list; 117, 118; 117, 119; 118, string:'/'; 119, integer:1; 120, unary_operator:-; 120, 121; 121, integer:1; 122, identifier:rsplit; 123, argument_list; 123, 124; 123, 125; 124, string:'.'; 125, integer:3; 126, integer:0; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:btc; 131, identifier:append; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:bowtie; 135, argument_list; 135, 136; 135, 137; 135, 138; 135, 139; 135, 140; 135, 141; 135, 142; 135, 143; 136, identifier:sam; 137, identifier:btd; 138, identifier:f; 139, identifier:r; 140, identifier:u; 141, identifier:options; 142, identifier:no_shrink; 143, identifier:threads; 144, else_clause; 144, 145; 145, block; 145, 146; 145, 150; 145, 154; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:f; 149, False; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:r; 153, False; 154, for_statement; 154, 155; 154, 156; 154, 157; 155, identifier:u; 156, identifier:U; 157, block; 157, 158; 157, 198; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:sam; 161, binary_operator:%; 161, 162; 161, 163; 162, string:'%s/%s-vs-%s'; 163, tuple; 163, 164; 163, 169; 163, 170; 163, 180; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:os; 167, identifier:getcwd; 168, argument_list; 169, line_continuation:\; 170, subscript; 170, 171; 170, 178; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:fa; 174, identifier:rsplit; 175, argument_list; 175, 176; 175, 177; 176, string:'/'; 177, integer:1; 178, unary_operator:-; 178, 179; 179, integer:1; 180, subscript; 180, 181; 180, 197; 181, call; 181, 182; 181, 194; 182, attribute; 182, 183; 182, 193; 183, subscript; 183, 184; 183, 191; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:u; 187, identifier:rsplit; 188, argument_list; 188, 189; 188, 190; 189, string:'/'; 190, integer:1; 191, unary_operator:-; 191, 192; 192, integer:1; 193, identifier:rsplit; 194, argument_list; 194, 195; 194, 196; 195, string:'.'; 196, integer:3; 197, integer:0; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:btc; 202, identifier:append; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 206; 205, identifier:bowtie; 206, argument_list; 206, 207; 206, 208; 206, 209; 206, 210; 206, 211; 206, 212; 206, 213; 206, 214; 207, identifier:sam; 208, identifier:btd; 209, identifier:f; 210, identifier:r; 211, identifier:u; 212, identifier:options; 213, identifier:no_shrink; 214, identifier:threads; 215, if_statement; 215, 216; 215, 219; 215, 242; 216, comparison_operator:is; 216, 217; 216, 218; 217, identifier:cluster; 218, False; 219, block; 219, 220; 220, for_statement; 220, 221; 220, 222; 220, 223; 221, identifier:i; 222, identifier:btc; 223, block; 223, 224; 223, 236; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:p; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:subprocess; 230, identifier:Popen; 231, argument_list; 231, 232; 231, 233; 232, identifier:i; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:shell; 235, True; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:p; 240, identifier:communicate; 241, argument_list; 242, else_clause; 242, 243; 243, block; 243, 244; 243, 275; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:ID; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, string:''; 250, identifier:join; 251, generator_expression; 251, 252; 251, 269; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:random; 255, identifier:choice; 256, argument_list; 256, 257; 257, list_comprehension; 257, 258; 257, 262; 258, call; 258, 259; 258, 260; 259, identifier:str; 260, argument_list; 260, 261; 261, identifier:i; 262, for_in_clause; 262, 263; 262, 264; 263, identifier:i; 264, call; 264, 265; 264, 266; 265, identifier:range; 266, argument_list; 266, 267; 266, 268; 267, integer:0; 268, integer:9; 269, for_in_clause; 269, 270; 269, 271; 270, identifier:_; 271, call; 271, 272; 271, 273; 272, identifier:range; 273, argument_list; 273, 274; 274, integer:5; 275, for_statement; 275, 276; 275, 279; 275, 288; 276, pattern_list; 276, 277; 276, 278; 277, identifier:node; 278, identifier:commands; 279, call; 279, 280; 279, 281; 280, identifier:enumerate; 281, argument_list; 281, 282; 281, 287; 282, call; 282, 283; 282, 284; 283, identifier:chunks; 284, argument_list; 284, 285; 284, 286; 285, identifier:btc; 286, identifier:nodes; 287, integer:1; 288, block; 288, 289; 288, 306; 288, 319; 288, 325; 288, 344; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:bs; 292, call; 292, 293; 292, 294; 293, identifier:open; 294, argument_list; 294, 295; 294, 305; 295, binary_operator:%; 295, 296; 295, 297; 296, string:'%s/crossmap-qsub.%s.%s.sh'; 297, tuple; 297, 298; 297, 303; 297, 304; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:os; 301, identifier:getcwd; 302, argument_list; 303, identifier:ID; 304, identifier:node; 305, string:'w'; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:print; 309, argument_list; 309, 310; 309, 316; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, string:'\n'; 313, identifier:join; 314, argument_list; 314, 315; 315, identifier:commands; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:file; 318, identifier:bs; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:bs; 323, identifier:close; 324, argument_list; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 328; 327, identifier:p; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:subprocess; 331, identifier:Popen; 332, argument_list; 332, 333; 332, 340; 332, 341; 333, binary_operator:%; 333, 334; 333, 335; 333, 336; 334, string:'qsub -V -N crossmap %s'; 335, line_continuation:\; 336, parenthesized_expression; 336, 337; 337, attribute; 337, 338; 337, 339; 338, identifier:bs; 339, identifier:name; 340, line_continuation:\; 341, keyword_argument; 341, 342; 341, 343; 342, identifier:shell; 343, True; 344, expression_statement; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:p; 348, identifier:communicate; 349, argument_list
def crossmap(fas, reads, options, no_shrink, keepDB, threads, cluster, nodes): """ map all read sets against all fasta files """ if cluster is True: threads = '48' btc = [] for fa in fas: btd = bowtiedb(fa, keepDB) F, R, U = reads if F is not False: if U is False: u = False for i, f in enumerate(F): r = R[i] if U is not False: u = U[i] sam = '%s/%s-vs-%s' % (os.getcwd(), \ fa.rsplit('/', 1)[-1], f.rsplit('/', 1)[-1].rsplit('.', 3)[0]) btc.append(bowtie(sam, btd, f, r, u, options, no_shrink, threads)) else: f = False r = False for u in U: sam = '%s/%s-vs-%s' % (os.getcwd(), \ fa.rsplit('/', 1)[-1], u.rsplit('/', 1)[-1].rsplit('.', 3)[0]) btc.append(bowtie(sam, btd, f, r, u, options, no_shrink, threads)) if cluster is False: for i in btc: p = subprocess.Popen(i, shell = True) p.communicate() else: ID = ''.join(random.choice([str(i) for i in range(0, 9)]) for _ in range(5)) for node, commands in enumerate(chunks(btc, nodes), 1): bs = open('%s/crossmap-qsub.%s.%s.sh' % (os.getcwd(), ID, node), 'w') print('\n'.join(commands), file=bs) bs.close() p = subprocess.Popen(\ 'qsub -V -N crossmap %s' \ % (bs.name), \ shell = True) p.communicate()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:bit_by_bit; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:in_data; 6, block; 6, 7; 6, 9; 6, 10; 6, 28; 6, 34; 6, 100; 6, 138; 6, 155; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, if_statement; 10, 11; 10, 16; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:in_data; 15, identifier:str; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:in_data; 20, list_comprehension; 20, 21; 20, 25; 21, call; 21, 22; 21, 23; 22, identifier:ord; 23, argument_list; 23, 24; 24, identifier:c; 25, for_in_clause; 25, 26; 25, 27; 26, identifier:c; 27, identifier:in_data; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:register; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:NonDirectInit; 34, for_statement; 34, 35; 34, 36; 34, 37; 35, identifier:octet; 36, identifier:in_data; 37, block; 37, 38; 37, 53; 38, if_statement; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:ReflectIn; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:octet; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:reflect; 50, argument_list; 50, 51; 50, 52; 51, identifier:octet; 52, integer:8; 53, for_statement; 53, 54; 53, 55; 53, 59; 54, identifier:i; 55, call; 55, 56; 55, 57; 56, identifier:range; 57, argument_list; 57, 58; 58, integer:8; 59, block; 59, 60; 59, 68; 59, 91; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:topbit; 63, binary_operator:&; 63, 64; 63, 65; 64, identifier:register; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:MSB_Mask; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:register; 71, binary_operator:|; 71, 72; 71, 81; 72, parenthesized_expression; 72, 73; 73, binary_operator:&; 73, 74; 73, 78; 74, parenthesized_expression; 74, 75; 75, binary_operator:<<; 75, 76; 75, 77; 76, identifier:register; 77, integer:1; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:Mask; 81, parenthesized_expression; 81, 82; 82, binary_operator:&; 82, 83; 82, 90; 83, parenthesized_expression; 83, 84; 84, binary_operator:>>; 84, 85; 84, 86; 85, identifier:octet; 86, parenthesized_expression; 86, 87; 87, binary_operator:-; 87, 88; 87, 89; 88, integer:7; 89, identifier:i; 90, integer:0x01; 91, if_statement; 91, 92; 91, 93; 92, identifier:topbit; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, augmented_assignment:^=; 95, 96; 95, 97; 96, identifier:register; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:Poly; 100, for_statement; 100, 101; 100, 102; 100, 108; 101, identifier:i; 102, call; 102, 103; 102, 104; 103, identifier:range; 104, argument_list; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:Width; 108, block; 108, 109; 108, 117; 108, 129; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:topbit; 112, binary_operator:&; 112, 113; 112, 114; 113, identifier:register; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:MSB_Mask; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:register; 120, parenthesized_expression; 120, 121; 121, binary_operator:&; 121, 122; 121, 126; 122, parenthesized_expression; 122, 123; 123, binary_operator:<<; 123, 124; 123, 125; 124, identifier:register; 125, integer:1; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:Mask; 129, if_statement; 129, 130; 129, 131; 130, identifier:topbit; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, augmented_assignment:^=; 133, 134; 133, 135; 134, identifier:register; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:Poly; 138, if_statement; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:ReflectOut; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:register; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:reflect; 150, argument_list; 150, 151; 150, 152; 151, identifier:register; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:Width; 155, return_statement; 155, 156; 156, binary_operator:^; 156, 157; 156, 158; 157, identifier:register; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:XorOut
def bit_by_bit(self, in_data): """ Classic simple and slow CRC implementation. This function iterates bit by bit over the augmented input message and returns the calculated CRC value at the end. """ # If the input data is a string, convert to bytes. if isinstance(in_data, str): in_data = [ord(c) for c in in_data] register = self.NonDirectInit for octet in in_data: if self.ReflectIn: octet = self.reflect(octet, 8) for i in range(8): topbit = register & self.MSB_Mask register = ((register << 1) & self.Mask) | ((octet >> (7 - i)) & 0x01) if topbit: register ^= self.Poly for i in range(self.Width): topbit = register & self.MSB_Mask register = ((register << 1) & self.Mask) if topbit: register ^= self.Poly if self.ReflectOut: register = self.reflect(register, self.Width) return register ^ self.XorOut
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse_ggKbase_tables; 3, parameters; 3, 4; 3, 5; 4, identifier:tables; 5, identifier:id_type; 6, block; 6, 7; 6, 9; 6, 13; 6, 282; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:g2info; 12, dictionary; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:table; 15, identifier:tables; 16, block; 16, 17; 17, for_statement; 17, 18; 17, 19; 17, 23; 18, identifier:line; 19, call; 19, 20; 19, 21; 20, identifier:open; 21, argument_list; 21, 22; 22, identifier:table; 23, block; 23, 24; 23, 37; 23, 70; 23, 84; 23, 95; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:line; 27, call; 27, 28; 27, 35; 28, attribute; 28, 29; 28, 34; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:line; 32, identifier:strip; 33, argument_list; 34, identifier:split; 35, argument_list; 35, 36; 36, string:'\t'; 37, if_statement; 37, 38; 37, 46; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:line; 42, integer:0; 43, identifier:startswith; 44, argument_list; 44, 45; 45, string:'name'; 46, block; 46, 47; 46, 51; 46, 57; 46, 63; 46, 69; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:header; 50, identifier:line; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:header; 55, integer:4; 56, string:'genome size (bp)'; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, subscript; 59, 60; 59, 61; 60, identifier:header; 61, integer:12; 62, string:'#SCGs'; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:header; 67, integer:13; 68, string:'#SCG duplicates'; 69, continue_statement; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 76; 72, pattern_list; 72, 73; 72, 74; 72, 75; 73, identifier:name; 74, identifier:code; 75, identifier:info; 76, expression_list; 76, 77; 76, 80; 76, 83; 77, subscript; 77, 78; 77, 79; 78, identifier:line; 79, integer:0; 80, subscript; 80, 81; 80, 82; 81, identifier:line; 82, integer:1; 83, identifier:line; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:info; 87, list_comprehension; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:to_int; 90, argument_list; 90, 91; 91, identifier:i; 92, for_in_clause; 92, 93; 92, 94; 93, identifier:i; 94, identifier:info; 95, if_statement; 95, 96; 95, 99; 95, 100; 95, 201; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:id_type; 98, False; 99, comment; 100, block; 100, 101; 100, 114; 100, 155; 100, 178; 101, if_statement; 101, 102; 101, 109; 102, boolean_operator:or; 102, 103; 102, 106; 103, comparison_operator:in; 103, 104; 103, 105; 104, string:'UNK'; 105, identifier:code; 106, comparison_operator:in; 106, 107; 106, 108; 107, string:'unknown'; 108, identifier:code; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:code; 113, identifier:name; 114, if_statement; 114, 115; 114, 126; 115, boolean_operator:and; 115, 116; 115, 120; 116, parenthesized_expression; 116, 117; 117, comparison_operator:!=; 117, 118; 117, 119; 118, identifier:name; 119, identifier:code; 120, parenthesized_expression; 120, 121; 121, boolean_operator:and; 121, 122; 121, 123; 122, identifier:name; 123, comparison_operator:in; 123, 124; 123, 125; 124, identifier:code; 125, identifier:g2info; 126, block; 126, 127; 126, 137; 126, 151; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:print; 130, argument_list; 130, 131; 130, 132; 131, string:'# duplicate name or code in table(s)'; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:file; 134, attribute; 134, 135; 134, 136; 135, identifier:sys; 136, identifier:stderr; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:print; 140, argument_list; 140, 141; 140, 146; 141, binary_operator:%; 141, 142; 141, 143; 142, string:'# %s and/or %s'; 143, tuple; 143, 144; 143, 145; 144, identifier:name; 145, identifier:code; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:file; 148, attribute; 148, 149; 148, 150; 149, identifier:sys; 150, identifier:stderr; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:exit; 154, argument_list; 155, if_statement; 155, 156; 155, 159; 156, comparison_operator:not; 156, 157; 156, 158; 157, identifier:name; 158, identifier:g2info; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 165; 162, subscript; 162, 163; 162, 164; 163, identifier:g2info; 164, identifier:name; 165, dictionary_comprehension; 165, 166; 165, 169; 166, pair; 166, 167; 166, 168; 167, identifier:item; 168, identifier:stat; 169, for_in_clause; 169, 170; 169, 173; 170, pattern_list; 170, 171; 170, 172; 171, identifier:item; 172, identifier:stat; 173, call; 173, 174; 173, 175; 174, identifier:zip; 175, argument_list; 175, 176; 175, 177; 176, identifier:header; 177, identifier:info; 178, if_statement; 178, 179; 178, 182; 179, comparison_operator:not; 179, 180; 179, 181; 180, identifier:code; 181, identifier:g2info; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:g2info; 187, identifier:code; 188, dictionary_comprehension; 188, 189; 188, 192; 189, pair; 189, 190; 189, 191; 190, identifier:item; 191, identifier:stat; 192, for_in_clause; 192, 193; 192, 196; 193, pattern_list; 193, 194; 193, 195; 194, identifier:item; 195, identifier:stat; 196, call; 196, 197; 196, 198; 197, identifier:zip; 198, argument_list; 198, 199; 198, 200; 199, identifier:header; 200, identifier:info; 201, else_clause; 201, 202; 202, block; 202, 203; 202, 237; 202, 247; 202, 265; 203, if_statement; 203, 204; 203, 207; 203, 212; 203, 221; 204, comparison_operator:==; 204, 205; 204, 206; 205, identifier:id_type; 206, string:'name'; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:ID; 211, identifier:name; 212, elif_clause; 212, 213; 212, 216; 213, comparison_operator:==; 213, 214; 213, 215; 214, identifier:id_type; 215, string:'code'; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:ID; 220, identifier:code; 221, else_clause; 221, 222; 222, block; 222, 223; 222, 233; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 226; 225, identifier:print; 226, argument_list; 226, 227; 226, 228; 227, string:'# specify name or code column using -id'; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:file; 230, attribute; 230, 231; 230, 232; 231, identifier:sys; 232, identifier:stderr; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 236; 235, identifier:exit; 236, argument_list; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:ID; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:ID; 243, identifier:replace; 244, argument_list; 244, 245; 244, 246; 245, string:' '; 246, string:''; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:g2info; 251, identifier:ID; 252, dictionary_comprehension; 252, 253; 252, 256; 253, pair; 253, 254; 253, 255; 254, identifier:item; 255, identifier:stat; 256, for_in_clause; 256, 257; 256, 260; 257, pattern_list; 257, 258; 257, 259; 258, identifier:item; 259, identifier:stat; 260, call; 260, 261; 260, 262; 261, identifier:zip; 262, argument_list; 262, 263; 262, 264; 263, identifier:header; 264, identifier:info; 265, if_statement; 265, 266; 265, 273; 266, comparison_operator:==; 266, 267; 266, 272; 267, subscript; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:g2info; 270, identifier:ID; 271, string:'genome size (bp)'; 272, string:''; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 281; 276, subscript; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:g2info; 279, identifier:ID; 280, string:'genome size (bp)'; 281, integer:0; 282, return_statement; 282, 283; 283, identifier:g2info
def parse_ggKbase_tables(tables, id_type): """ convert ggKbase genome info tables to dictionary """ g2info = {} for table in tables: for line in open(table): line = line.strip().split('\t') if line[0].startswith('name'): header = line header[4] = 'genome size (bp)' header[12] = '#SCGs' header[13] = '#SCG duplicates' continue name, code, info = line[0], line[1], line info = [to_int(i) for i in info] if id_type is False: # try to use name and code ID if 'UNK' in code or 'unknown' in code: code = name if (name != code) and (name and code in g2info): print('# duplicate name or code in table(s)', file=sys.stderr) print('# %s and/or %s' % (name, code), file=sys.stderr) exit() if name not in g2info: g2info[name] = {item:stat for item, stat in zip(header, info)} if code not in g2info: g2info[code] = {item:stat for item, stat in zip(header, info)} else: if id_type == 'name': ID = name elif id_type == 'code': ID = code else: print('# specify name or code column using -id', file=sys.stderr) exit() ID = ID.replace(' ', '') g2info[ID] = {item:stat for item, stat in zip(header, info)} if g2info[ID]['genome size (bp)'] == '': g2info[ID]['genome size (bp)'] = 0 return g2info
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:top_hits; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:hits; 5, identifier:num; 6, identifier:column; 7, identifier:reverse; 8, block; 8, 9; 8, 11; 8, 26; 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:hits; 15, identifier:sort; 16, argument_list; 16, 17; 16, 23; 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:column; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:reverse; 25, identifier:reverse; 26, for_statement; 26, 27; 26, 28; 26, 34; 27, identifier:hit; 28, subscript; 28, 29; 28, 30; 29, identifier:hits; 30, slice; 30, 31; 30, 32; 30, 33; 31, integer:0; 32, colon; 33, identifier:num; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, yield; 36, 37; 37, identifier:hit
def top_hits(hits, num, column, reverse): """ get top hits after sorting by column number """ hits.sort(key = itemgetter(column), reverse = reverse) for hit in hits[0:num]: yield hit
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:numBlast_sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:blast; 5, identifier:numHits; 6, identifier:evalueT; 7, identifier:bitT; 8, block; 8, 9; 8, 11; 8, 27; 8, 30; 8, 40; 8, 140; 8, 149; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:header; 14, list:['#query', 'target', 'pident', 'alen', 'mismatch', 'gapopen', 'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore']; 14, 15; 14, 16; 14, 17; 14, 18; 14, 19; 14, 20; 14, 21; 14, 22; 14, 23; 14, 24; 14, 25; 14, 26; 15, string:'#query'; 16, string:'target'; 17, string:'pident'; 18, string:'alen'; 19, string:'mismatch'; 20, string:'gapopen'; 21, string:'qstart'; 22, string:'qend'; 23, string:'tstart'; 24, string:'tend'; 25, string:'evalue'; 26, string:'bitscore'; 27, expression_statement; 27, 28; 28, yield; 28, 29; 29, identifier:header; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:hmm; 33, dictionary_comprehension; 33, 34; 33, 37; 34, pair; 34, 35; 34, 36; 35, identifier:h; 36, list:[]; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:h; 39, identifier:header; 40, for_statement; 40, 41; 40, 42; 40, 43; 41, identifier:line; 42, identifier:blast; 43, block; 43, 44; 43, 53; 43, 66; 43, 67; 43, 89; 43, 101; 43, 111; 43, 121; 44, if_statement; 44, 45; 44, 51; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:line; 48, identifier:startswith; 49, argument_list; 49, 50; 50, string:'#'; 51, block; 51, 52; 52, continue_statement; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:line; 56, call; 56, 57; 56, 64; 57, attribute; 57, 58; 57, 63; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:line; 61, identifier:strip; 62, argument_list; 63, identifier:split; 64, argument_list; 64, 65; 65, string:'\t'; 66, comment; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 76; 69, pattern_list; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:line; 72, integer:10; 73, subscript; 73, 74; 73, 75; 74, identifier:line; 75, integer:11; 76, expression_list; 76, 77; 76, 83; 77, call; 77, 78; 77, 79; 78, identifier:float; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:line; 82, integer:10; 83, call; 83, 84; 83, 85; 84, identifier:float; 85, argument_list; 85, 86; 86, subscript; 86, 87; 86, 88; 87, identifier:line; 88, integer:11; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, pattern_list; 91, 92; 91, 93; 92, identifier:evalue; 93, identifier:bit; 94, expression_list; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:line; 97, integer:10; 98, subscript; 98, 99; 98, 100; 99, identifier:line; 100, integer:11; 101, if_statement; 101, 102; 101, 109; 102, boolean_operator:and; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:evalueT; 105, False; 106, comparison_operator:>; 106, 107; 106, 108; 107, identifier:evalue; 108, identifier:evalueT; 109, block; 109, 110; 110, continue_statement; 111, if_statement; 111, 112; 111, 119; 112, boolean_operator:and; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:bitT; 115, False; 116, comparison_operator:<; 116, 117; 116, 118; 117, identifier:bit; 118, identifier:bitT; 119, block; 119, 120; 120, continue_statement; 121, for_statement; 121, 122; 121, 125; 121, 130; 122, pattern_list; 122, 123; 122, 124; 123, identifier:i; 124, identifier:h; 125, call; 125, 126; 125, 127; 126, identifier:zip; 127, argument_list; 127, 128; 127, 129; 128, identifier:line; 129, identifier:header; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:hmm; 136, identifier:h; 137, identifier:append; 138, argument_list; 138, 139; 139, identifier:i; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:hmm; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:pd; 146, identifier:DataFrame; 147, argument_list; 147, 148; 148, identifier:hmm; 149, for_statement; 149, 150; 149, 153; 149, 162; 150, pattern_list; 150, 151; 150, 152; 151, identifier:query; 152, identifier:df; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:hmm; 156, identifier:groupby; 157, argument_list; 157, 158; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:by; 160, list:['#query']; 160, 161; 161, string:'#query'; 162, block; 162, 163; 162, 178; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:df; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:df; 169, identifier:sort_values; 170, argument_list; 170, 171; 170, 175; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:by; 173, list:['bitscore']; 173, 174; 174, string:'bitscore'; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:ascending; 177, False; 178, for_statement; 178, 179; 178, 180; 178, 190; 179, identifier:hit; 180, subscript; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:df; 184, identifier:header; 185, identifier:values; 186, slice; 186, 187; 186, 188; 186, 189; 187, integer:0; 188, colon; 189, identifier:numHits; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, yield; 192, 193; 193, identifier:hit
def numBlast_sort(blast, numHits, evalueT, bitT): """ parse b6 output with sorting """ header = ['#query', 'target', 'pident', 'alen', 'mismatch', 'gapopen', 'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore'] yield header hmm = {h:[] for h in header} for line in blast: if line.startswith('#'): continue line = line.strip().split('\t') # Evalue and Bitscore thresholds line[10], line[11] = float(line[10]), float(line[11]) evalue, bit = line[10], line[11] if evalueT is not False and evalue > evalueT: continue if bitT is not False and bit < bitT: continue for i, h in zip(line, header): hmm[h].append(i) hmm = pd.DataFrame(hmm) for query, df in hmm.groupby(by = ['#query']): df = df.sort_values(by = ['bitscore'], ascending = False) for hit in df[header].values[0:numHits]: yield hit
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:numDomtblout; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:domtblout; 5, identifier:numHits; 6, identifier:evalueT; 7, identifier:bitT; 8, identifier:sort; 9, block; 9, 10; 9, 12; 9, 31; 9, 58; 9, 61; 9, 69; 9, 280; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:sort; 15, True; 16, block; 16, 17; 16, 30; 17, for_statement; 17, 18; 17, 19; 17, 26; 18, identifier:hit; 19, call; 19, 20; 19, 21; 20, identifier:numDomtblout_sort; 21, argument_list; 21, 22; 21, 23; 21, 24; 21, 25; 22, identifier:domtblout; 23, identifier:numHits; 24, identifier:evalueT; 25, identifier:bitT; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, yield; 28, 29; 29, identifier:hit; 30, return_statement; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:header; 34, list:['#target name', 'target accession', 'tlen', 'query name', 'query accession', 'qlen', 'full E-value', 'full score', 'full bias', 'domain #', '# domains', 'domain c-Evalue', 'domain i-Evalue', 'domain score', 'domain bias', 'hmm from', 'hmm to', 'seq from', 'seq to', 'env from', 'env to', 'acc', 'target description']; 34, 35; 34, 36; 34, 37; 34, 38; 34, 39; 34, 40; 34, 41; 34, 42; 34, 43; 34, 44; 34, 45; 34, 46; 34, 47; 34, 48; 34, 49; 34, 50; 34, 51; 34, 52; 34, 53; 34, 54; 34, 55; 34, 56; 34, 57; 35, string:'#target name'; 36, string:'target accession'; 37, string:'tlen'; 38, string:'query name'; 39, string:'query accession'; 40, string:'qlen'; 41, string:'full E-value'; 42, string:'full score'; 43, string:'full bias'; 44, string:'domain #'; 45, string:'# domains'; 46, string:'domain c-Evalue'; 47, string:'domain i-Evalue'; 48, string:'domain score'; 49, string:'domain bias'; 50, string:'hmm from'; 51, string:'hmm to'; 52, string:'seq from'; 53, string:'seq to'; 54, string:'env from'; 55, string:'env to'; 56, string:'acc'; 57, string:'target description'; 58, expression_statement; 58, 59; 59, yield; 59, 60; 60, identifier:header; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, pattern_list; 63, 64; 63, 65; 64, identifier:prev; 65, identifier:hits; 66, expression_list; 66, 67; 66, 68; 67, None; 68, list:[]; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:line; 71, identifier:domtblout; 72, block; 72, 73; 72, 82; 72, 83; 72, 95; 72, 108; 72, 117; 72, 124; 72, 125; 72, 135; 72, 136; 72, 158; 72, 170; 72, 182; 72, 212; 72, 276; 73, if_statement; 73, 74; 73, 80; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:line; 77, identifier:startswith; 78, argument_list; 78, 79; 79, string:'#'; 80, block; 80, 81; 81, continue_statement; 82, comment; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:line; 86, call; 86, 87; 86, 94; 87, attribute; 87, 88; 87, 93; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:line; 91, identifier:strip; 92, argument_list; 93, identifier:split; 94, argument_list; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:desc; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, string:' '; 101, identifier:join; 102, argument_list; 102, 103; 103, subscript; 103, 104; 103, 105; 104, identifier:line; 105, slice; 105, 106; 105, 107; 106, integer:18; 107, colon; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:line; 111, subscript; 111, 112; 111, 113; 112, identifier:line; 113, slice; 113, 114; 113, 115; 113, 116; 114, integer:0; 115, colon; 116, integer:18; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:line; 121, identifier:append; 122, argument_list; 122, 123; 123, identifier:desc; 124, comment; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:ID; 128, binary_operator:+; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:line; 131, integer:0; 132, subscript; 132, 133; 132, 134; 133, identifier:line; 134, integer:9; 135, comment; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 145; 138, pattern_list; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:line; 141, integer:11; 142, subscript; 142, 143; 142, 144; 143, identifier:line; 144, integer:13; 145, expression_list; 145, 146; 145, 152; 146, call; 146, 147; 146, 148; 147, identifier:float; 148, argument_list; 148, 149; 149, subscript; 149, 150; 149, 151; 150, identifier:line; 151, integer:11; 152, call; 152, 153; 152, 154; 153, identifier:float; 154, argument_list; 154, 155; 155, subscript; 155, 156; 155, 157; 156, identifier:line; 157, integer:13; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, pattern_list; 160, 161; 160, 162; 161, identifier:evalue; 162, identifier:bitscore; 163, expression_list; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:line; 166, integer:11; 167, subscript; 167, 168; 167, 169; 168, identifier:line; 169, integer:13; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 179; 172, pattern_list; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:line; 175, integer:11; 176, subscript; 176, 177; 176, 178; 177, identifier:line; 178, integer:13; 179, expression_list; 179, 180; 179, 181; 180, identifier:evalue; 181, identifier:bitscore; 182, if_statement; 182, 183; 182, 186; 183, comparison_operator:!=; 183, 184; 183, 185; 184, identifier:ID; 185, identifier:prev; 186, block; 186, 187; 186, 208; 187, if_statement; 187, 188; 187, 194; 188, comparison_operator:>; 188, 189; 188, 193; 189, call; 189, 190; 189, 191; 190, identifier:len; 191, argument_list; 191, 192; 192, identifier:hits; 193, integer:0; 194, block; 194, 195; 195, for_statement; 195, 196; 195, 197; 195, 204; 196, identifier:hit; 197, call; 197, 198; 197, 199; 198, identifier:top_hits; 199, argument_list; 199, 200; 199, 201; 199, 202; 199, 203; 200, identifier:hits; 201, identifier:numHits; 202, integer:13; 203, True; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, yield; 206, 207; 207, identifier:hit; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:hits; 211, list:[]; 212, if_statement; 212, 213; 212, 220; 212, 228; 212, 244; 212, 260; 213, boolean_operator:and; 213, 214; 213, 217; 214, comparison_operator:==; 214, 215; 214, 216; 215, identifier:evalueT; 216, False; 217, comparison_operator:==; 217, 218; 217, 219; 218, identifier:bitT; 219, False; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:hits; 225, identifier:append; 226, argument_list; 226, 227; 227, identifier:line; 228, elif_clause; 228, 229; 228, 236; 229, boolean_operator:and; 229, 230; 229, 233; 230, comparison_operator:<=; 230, 231; 230, 232; 231, identifier:evalue; 232, identifier:evalueT; 233, comparison_operator:==; 233, 234; 233, 235; 234, identifier:bitT; 235, False; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:hits; 241, identifier:append; 242, argument_list; 242, 243; 243, identifier:line; 244, elif_clause; 244, 245; 244, 252; 245, boolean_operator:and; 245, 246; 245, 249; 246, comparison_operator:<=; 246, 247; 246, 248; 247, identifier:evalue; 248, identifier:evalueT; 249, comparison_operator:>=; 249, 250; 249, 251; 250, identifier:bit; 251, identifier:bitT; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:hits; 257, identifier:append; 258, argument_list; 258, 259; 259, identifier:line; 260, elif_clause; 260, 261; 260, 268; 261, boolean_operator:and; 261, 262; 261, 265; 262, comparison_operator:==; 262, 263; 262, 264; 263, identifier:evalueT; 264, False; 265, comparison_operator:>=; 265, 266; 265, 267; 266, identifier:bit; 267, identifier:bitT; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:hits; 273, identifier:append; 274, argument_list; 274, 275; 275, identifier:line; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:prev; 279, identifier:ID; 280, for_statement; 280, 281; 280, 282; 280, 289; 281, identifier:hit; 282, call; 282, 283; 282, 284; 283, identifier:top_hits; 284, argument_list; 284, 285; 284, 286; 284, 287; 284, 288; 285, identifier:hits; 286, identifier:numHits; 287, integer:13; 288, True; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, yield; 291, 292; 292, identifier:hit
def numDomtblout(domtblout, numHits, evalueT, bitT, sort): """ parse hmm domain table output this version is faster but does not work unless the table is sorted """ if sort is True: for hit in numDomtblout_sort(domtblout, numHits, evalueT, bitT): yield hit return header = ['#target name', 'target accession', 'tlen', 'query name', 'query accession', 'qlen', 'full E-value', 'full score', 'full bias', 'domain #', '# domains', 'domain c-Evalue', 'domain i-Evalue', 'domain score', 'domain bias', 'hmm from', 'hmm to', 'seq from', 'seq to', 'env from', 'env to', 'acc', 'target description'] yield header prev, hits = None, [] for line in domtblout: if line.startswith('#'): continue # parse line and get description line = line.strip().split() desc = ' '.join(line[18:]) line = line[0:18] line.append(desc) # create ID based on query name and domain number ID = line[0] + line[9] # domain c-Evalue and domain score thresholds line[11], line[13] = float(line[11]), float(line[13]) evalue, bitscore = line[11], line[13] line[11], line[13] = evalue, bitscore if ID != prev: if len(hits) > 0: for hit in top_hits(hits, numHits, 13, True): yield hit hits = [] if evalueT == False and bitT == False: hits.append(line) elif evalue <= evalueT and bitT == False: hits.append(line) elif evalue <= evalueT and bit >= bitT: hits.append(line) elif evalueT == False and bit >= bitT: hits.append(line) prev = ID for hit in top_hits(hits, numHits, 13, True): yield hit
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:compare_clades; 3, parameters; 3, 4; 4, identifier:pw; 5, block; 5, 6; 5, 8; 5, 22; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:names; 11, call; 11, 12; 11, 13; 12, identifier:sorted; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:set; 16, argument_list; 16, 17; 17, list_comprehension; 17, 18; 17, 19; 18, identifier:i; 19, for_in_clause; 19, 20; 19, 21; 20, identifier:i; 21, identifier:pw; 22, for_statement; 22, 23; 22, 24; 22, 29; 23, identifier:i; 24, call; 24, 25; 24, 26; 25, identifier:range; 26, argument_list; 26, 27; 26, 28; 27, integer:0; 28, integer:4; 29, block; 29, 30; 29, 38; 29, 220; 29, 225; 29, 262; 29, 263; 29, 267; 29, 272; 29, 335; 29, 340; 29, 341; 29, 345; 29, 350; 29, 416; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, pattern_list; 32, 33; 32, 34; 33, identifier:wi; 34, identifier:bt; 35, expression_list; 35, 36; 35, 37; 36, dictionary; 37, dictionary; 38, for_statement; 38, 39; 38, 40; 38, 41; 39, identifier:a; 40, identifier:names; 41, block; 41, 42; 42, for_statement; 42, 43; 42, 44; 42, 47; 43, identifier:b; 44, subscript; 44, 45; 44, 46; 45, identifier:pw; 46, identifier:a; 47, block; 47, 48; 47, 58; 47, 66; 47, 88; 47, 156; 48, if_statement; 48, 49; 48, 56; 49, boolean_operator:or; 49, 50; 49, 53; 50, comparison_operator:not; 50, 51; 50, 52; 51, string:';'; 52, identifier:a; 53, comparison_operator:not; 53, 54; 53, 55; 54, string:';'; 55, identifier:b; 56, block; 56, 57; 57, continue_statement; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:pident; 61, subscript; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:pw; 64, identifier:a; 65, identifier:b; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, pattern_list; 68, 69; 68, 70; 69, identifier:cA; 70, identifier:cB; 71, expression_list; 71, 72; 71, 80; 72, subscript; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:a; 76, identifier:split; 77, argument_list; 77, 78; 78, string:';'; 79, identifier:i; 80, subscript; 80, 81; 80, 87; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:b; 84, identifier:split; 85, argument_list; 85, 86; 86, string:';'; 87, identifier:i; 88, if_statement; 88, 89; 88, 100; 88, 125; 89, boolean_operator:and; 89, 90; 89, 97; 90, boolean_operator:and; 90, 91; 90, 94; 91, comparison_operator:==; 91, 92; 91, 93; 92, identifier:i; 93, integer:0; 94, comparison_operator:in; 94, 95; 94, 96; 95, string:'_'; 96, identifier:cA; 97, comparison_operator:in; 97, 98; 97, 99; 98, string:'_'; 99, identifier:cB; 100, block; 100, 101; 100, 113; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:cA; 104, subscript; 104, 105; 104, 112; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:cA; 108, identifier:rsplit; 109, argument_list; 109, 110; 109, 111; 110, string:'_'; 111, integer:1; 112, integer:1; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:cB; 116, subscript; 116, 117; 116, 124; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:cB; 120, identifier:rsplit; 121, argument_list; 121, 122; 121, 123; 122, string:'_'; 123, integer:1; 124, integer:1; 125, elif_clause; 125, 126; 125, 133; 126, boolean_operator:or; 126, 127; 126, 130; 127, comparison_operator:in; 127, 128; 127, 129; 128, string:'>'; 129, identifier:cA; 130, comparison_operator:in; 130, 131; 130, 132; 131, string:'>'; 132, identifier:cB; 133, block; 133, 134; 133, 145; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:cA; 137, subscript; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:cA; 141, identifier:split; 142, argument_list; 142, 143; 143, string:'>'; 144, integer:1; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:cB; 148, subscript; 148, 149; 148, 155; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:cB; 152, identifier:split; 153, argument_list; 153, 154; 154, string:'>'; 155, integer:1; 156, if_statement; 156, 157; 156, 160; 156, 181; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:cA; 159, identifier:cB; 160, block; 160, 161; 160, 172; 161, if_statement; 161, 162; 161, 165; 162, comparison_operator:not; 162, 163; 162, 164; 163, identifier:cA; 164, identifier:wi; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:wi; 170, identifier:cA; 171, list:[]; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 179; 174, attribute; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:wi; 177, identifier:cA; 178, identifier:append; 179, argument_list; 179, 180; 180, identifier:pident; 181, else_clause; 181, 182; 182, block; 182, 183; 182, 194; 182, 209; 183, if_statement; 183, 184; 183, 187; 184, comparison_operator:not; 184, 185; 184, 186; 185, identifier:cA; 186, identifier:bt; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:bt; 192, identifier:cA; 193, dictionary; 194, if_statement; 194, 195; 194, 200; 195, comparison_operator:not; 195, 196; 195, 197; 196, identifier:cB; 197, subscript; 197, 198; 197, 199; 198, identifier:bt; 199, identifier:cA; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 208; 203, subscript; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:bt; 206, identifier:cA; 207, identifier:cB; 208, list:[]; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 218; 211, attribute; 211, 212; 211, 217; 212, subscript; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:bt; 215, identifier:cA; 216, identifier:cB; 217, identifier:append; 218, argument_list; 218, 219; 219, identifier:pident; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:print; 223, argument_list; 223, 224; 224, string:'\n# min. within'; 225, for_statement; 225, 226; 225, 229; 225, 237; 226, pattern_list; 226, 227; 226, 228; 227, identifier:clade; 228, identifier:pidents; 229, call; 229, 230; 229, 231; 230, identifier:list; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:wi; 235, identifier:items; 236, argument_list; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 241; 240, identifier:print; 241, argument_list; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, string:'\t'; 245, identifier:join; 246, argument_list; 246, 247; 247, list:['wi:%s' % str(i), clade, str(min(pidents))]; 247, 248; 247, 254; 247, 255; 248, binary_operator:%; 248, 249; 248, 250; 249, string:'wi:%s'; 250, call; 250, 251; 250, 252; 251, identifier:str; 252, argument_list; 252, 253; 253, identifier:i; 254, identifier:clade; 255, call; 255, 256; 255, 257; 256, identifier:str; 257, argument_list; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:min; 260, argument_list; 260, 261; 261, identifier:pidents; 262, comment; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:comps; 266, list:[]; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:print; 270, argument_list; 270, 271; 271, string:'\n# max. between'; 272, for_statement; 272, 273; 272, 274; 272, 278; 273, identifier:comp; 274, call; 274, 275; 274, 276; 275, identifier:print_pairwise; 276, argument_list; 276, 277; 277, identifier:bt; 278, block; 278, 279; 279, if_statement; 279, 280; 279, 283; 280, comparison_operator:is; 280, 281; 280, 282; 281, identifier:comp; 282, None; 283, block; 283, 284; 283, 309; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 287; 286, identifier:print; 287, argument_list; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, string:'\t'; 291, identifier:join; 292, argument_list; 292, 293; 293, binary_operator:+; 293, 294; 293, 301; 294, list:['bt:%s' % str(i)]; 294, 295; 295, binary_operator:%; 295, 296; 295, 297; 296, string:'bt:%s'; 297, call; 297, 298; 297, 299; 298, identifier:str; 299, argument_list; 299, 300; 300, identifier:i; 301, list_comprehension; 301, 302; 301, 306; 302, call; 302, 303; 302, 304; 303, identifier:str; 304, argument_list; 304, 305; 305, identifier:j; 306, for_in_clause; 306, 307; 306, 308; 307, identifier:j; 308, identifier:comp; 309, if_statement; 309, 310; 309, 315; 310, comparison_operator:!=; 310, 311; 310, 314; 311, subscript; 311, 312; 311, 313; 312, identifier:comp; 313, integer:0; 314, string:'#'; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:comps; 320, identifier:extend; 321, argument_list; 321, 322; 322, list_comprehension; 322, 323; 322, 324; 322, 331; 323, identifier:j; 324, for_in_clause; 324, 325; 324, 326; 325, identifier:j; 326, subscript; 326, 327; 326, 328; 327, identifier:comp; 328, slice; 328, 329; 328, 330; 329, integer:1; 330, colon; 331, if_clause; 331, 332; 332, comparison_operator:!=; 332, 333; 332, 334; 333, identifier:j; 334, string:'-'; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:print_comps; 338, argument_list; 338, 339; 339, identifier:comps; 340, comment; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 344; 343, identifier:comps; 344, list:[]; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 348; 347, identifier:print; 348, argument_list; 348, 349; 349, string:'\n# median between'; 350, for_statement; 350, 351; 350, 352; 350, 359; 351, identifier:comp; 352, call; 352, 353; 352, 354; 353, identifier:print_pairwise; 354, argument_list; 354, 355; 354, 356; 355, identifier:bt; 356, keyword_argument; 356, 357; 356, 358; 357, identifier:median; 358, True; 359, block; 359, 360; 360, if_statement; 360, 361; 360, 364; 361, comparison_operator:is; 361, 362; 361, 363; 362, identifier:comp; 363, None; 364, block; 364, 365; 364, 390; 365, expression_statement; 365, 366; 366, call; 366, 367; 366, 368; 367, identifier:print; 368, argument_list; 368, 369; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, string:'\t'; 372, identifier:join; 373, argument_list; 373, 374; 374, binary_operator:+; 374, 375; 374, 382; 375, list:['bt:%s' % str(i)]; 375, 376; 376, binary_operator:%; 376, 377; 376, 378; 377, string:'bt:%s'; 378, call; 378, 379; 378, 380; 379, identifier:str; 380, argument_list; 380, 381; 381, identifier:i; 382, list_comprehension; 382, 383; 382, 387; 383, call; 383, 384; 383, 385; 384, identifier:str; 385, argument_list; 385, 386; 386, identifier:j; 387, for_in_clause; 387, 388; 387, 389; 388, identifier:j; 389, identifier:comp; 390, if_statement; 390, 391; 390, 396; 391, comparison_operator:!=; 391, 392; 391, 395; 392, subscript; 392, 393; 392, 394; 393, identifier:comp; 394, integer:0; 395, string:'#'; 396, block; 396, 397; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:comps; 401, identifier:extend; 402, argument_list; 402, 403; 403, list_comprehension; 403, 404; 403, 405; 403, 412; 404, identifier:j; 405, for_in_clause; 405, 406; 405, 407; 406, identifier:j; 407, subscript; 407, 408; 407, 409; 408, identifier:comp; 409, slice; 409, 410; 409, 411; 410, integer:1; 411, colon; 412, if_clause; 412, 413; 413, comparison_operator:!=; 413, 414; 413, 415; 414, identifier:j; 415, string:'-'; 416, expression_statement; 416, 417; 417, call; 417, 418; 417, 419; 418, identifier:print_comps; 419, argument_list; 419, 420; 420, identifier:comps
def compare_clades(pw): """ print min. pident within each clade and then matrix of between-clade max. """ names = sorted(set([i for i in pw])) for i in range(0, 4): wi, bt = {}, {} for a in names: for b in pw[a]: if ';' not in a or ';' not in b: continue pident = pw[a][b] cA, cB = a.split(';')[i], b.split(';')[i] if i == 0 and '_' in cA and '_' in cB: cA = cA.rsplit('_', 1)[1] cB = cB.rsplit('_', 1)[1] elif '>' in cA or '>' in cB: cA = cA.split('>')[1] cB = cB.split('>')[1] if cA == cB: if cA not in wi: wi[cA] = [] wi[cA].append(pident) else: if cA not in bt: bt[cA] = {} if cB not in bt[cA]: bt[cA][cB] = [] bt[cA][cB].append(pident) print('\n# min. within') for clade, pidents in list(wi.items()): print('\t'.join(['wi:%s' % str(i), clade, str(min(pidents))])) # print matrix of maximum between groups comps = [] print('\n# max. between') for comp in print_pairwise(bt): if comp is not None: print('\t'.join(['bt:%s' % str(i)] + [str(j) for j in comp])) if comp[0] != '#': comps.extend([j for j in comp[1:] if j != '-']) print_comps(comps) # print matrix of median between groups comps = [] print('\n# median between') for comp in print_pairwise(bt, median = True): if comp is not None: print('\t'.join(['bt:%s' % str(i)] + [str(j) for j in comp])) if comp[0] != '#': comps.extend([j for j in comp[1:] if j != '-']) print_comps(comps)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:searchAccession; 3, parameters; 3, 4; 4, identifier:acc; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 20; 5, 95; 5, 96; 5, 106; 5, 181; 5, 182; 5, 192; 5, 267; 5, 298; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 15; 12, pattern_list; 12, 13; 12, 14; 13, identifier:out; 14, identifier:error; 15, call; 15, 16; 15, 17; 16, identifier:entrez; 17, argument_list; 17, 18; 17, 19; 18, string:'genome'; 19, identifier:acc; 20, for_statement; 20, 21; 20, 22; 20, 27; 21, identifier:line; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:out; 25, identifier:splitlines; 26, argument_list; 27, block; 27, 28; 27, 41; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:line; 31, call; 31, 32; 31, 40; 32, attribute; 32, 33; 32, 39; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:line; 36, identifier:decode; 37, argument_list; 37, 38; 38, string:'ascii'; 39, identifier:strip; 40, argument_list; 41, if_statement; 41, 42; 41, 49; 42, boolean_operator:or; 42, 43; 42, 46; 43, comparison_operator:in; 43, 44; 43, 45; 44, string:'Assembly_Accession'; 45, identifier:line; 46, comparison_operator:in; 46, 47; 46, 48; 47, string:'BioSample'; 48, identifier:line; 49, block; 49, 50; 49, 82; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:newAcc; 53, subscript; 53, 54; 53, 81; 54, call; 54, 55; 54, 79; 55, attribute; 55, 56; 55, 78; 56, subscript; 56, 57; 56, 77; 57, call; 57, 58; 57, 75; 58, attribute; 58, 59; 58, 74; 59, subscript; 59, 60; 59, 73; 60, call; 60, 61; 60, 71; 61, attribute; 61, 62; 61, 70; 62, subscript; 62, 63; 62, 69; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:line; 66, identifier:split; 67, argument_list; 67, 68; 68, string:'>'; 69, integer:1; 70, identifier:split; 71, argument_list; 71, 72; 72, string:'<'; 73, integer:0; 74, identifier:split; 75, argument_list; 75, 76; 76, string:'.'; 77, integer:0; 78, identifier:split; 79, argument_list; 79, 80; 80, string:','; 81, integer:0; 82, if_statement; 82, 83; 82, 89; 83, comparison_operator:>; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, identifier:newAcc; 88, integer:0; 89, block; 89, 90; 90, return_statement; 90, 91; 91, tuple; 91, 92; 91, 93; 91, 94; 92, True; 93, identifier:acc; 94, identifier:newAcc; 95, comment; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, pattern_list; 98, 99; 98, 100; 99, identifier:out; 100, identifier:error; 101, call; 101, 102; 101, 103; 102, identifier:entrez; 103, argument_list; 103, 104; 103, 105; 104, string:'nucleotide'; 105, identifier:acc; 106, for_statement; 106, 107; 106, 108; 106, 113; 107, identifier:line; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:out; 111, identifier:splitlines; 112, argument_list; 113, block; 113, 114; 113, 127; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:line; 117, call; 117, 118; 117, 126; 118, attribute; 118, 119; 118, 125; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:line; 122, identifier:decode; 123, argument_list; 123, 124; 124, string:'ascii'; 125, identifier:strip; 126, argument_list; 127, if_statement; 127, 128; 127, 135; 128, boolean_operator:or; 128, 129; 128, 132; 129, comparison_operator:in; 129, 130; 129, 131; 130, string:'Assembly_Accession'; 131, identifier:line; 132, comparison_operator:in; 132, 133; 132, 134; 133, string:'BioSample'; 134, identifier:line; 135, block; 135, 136; 135, 168; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:newAcc; 139, subscript; 139, 140; 139, 167; 140, call; 140, 141; 140, 165; 141, attribute; 141, 142; 141, 164; 142, subscript; 142, 143; 142, 163; 143, call; 143, 144; 143, 161; 144, attribute; 144, 145; 144, 160; 145, subscript; 145, 146; 145, 159; 146, call; 146, 147; 146, 157; 147, attribute; 147, 148; 147, 156; 148, subscript; 148, 149; 148, 155; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:line; 152, identifier:split; 153, argument_list; 153, 154; 154, string:'>'; 155, integer:1; 156, identifier:split; 157, argument_list; 157, 158; 158, string:'<'; 159, integer:0; 160, identifier:split; 161, argument_list; 161, 162; 162, string:'.'; 163, integer:0; 164, identifier:split; 165, argument_list; 165, 166; 166, string:','; 167, integer:0; 168, if_statement; 168, 169; 168, 175; 169, comparison_operator:>; 169, 170; 169, 174; 170, call; 170, 171; 170, 172; 171, identifier:len; 172, argument_list; 172, 173; 173, identifier:newAcc; 174, integer:0; 175, block; 175, 176; 176, return_statement; 176, 177; 177, tuple; 177, 178; 177, 179; 177, 180; 178, True; 179, identifier:acc; 180, identifier:newAcc; 181, comment; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, pattern_list; 184, 185; 184, 186; 185, identifier:out; 186, identifier:error; 187, call; 187, 188; 187, 189; 188, identifier:entrez; 189, argument_list; 189, 190; 189, 191; 190, string:'assembly'; 191, identifier:acc; 192, for_statement; 192, 193; 192, 194; 192, 199; 193, identifier:line; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:out; 197, identifier:splitlines; 198, argument_list; 199, block; 199, 200; 199, 213; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:line; 203, call; 203, 204; 203, 212; 204, attribute; 204, 205; 204, 211; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:line; 208, identifier:decode; 209, argument_list; 209, 210; 210, string:'ascii'; 211, identifier:strip; 212, argument_list; 213, if_statement; 213, 214; 213, 221; 214, boolean_operator:or; 214, 215; 214, 218; 215, comparison_operator:in; 215, 216; 215, 217; 216, string:'Assembly_Accession'; 217, identifier:line; 218, comparison_operator:in; 218, 219; 218, 220; 219, string:'BioSample'; 220, identifier:line; 221, block; 221, 222; 221, 254; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:newAcc; 225, subscript; 225, 226; 225, 253; 226, call; 226, 227; 226, 251; 227, attribute; 227, 228; 227, 250; 228, subscript; 228, 229; 228, 249; 229, call; 229, 230; 229, 247; 230, attribute; 230, 231; 230, 246; 231, subscript; 231, 232; 231, 245; 232, call; 232, 233; 232, 243; 233, attribute; 233, 234; 233, 242; 234, subscript; 234, 235; 234, 241; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:line; 238, identifier:split; 239, argument_list; 239, 240; 240, string:'>'; 241, integer:1; 242, identifier:split; 243, argument_list; 243, 244; 244, string:'<'; 245, integer:0; 246, identifier:split; 247, argument_list; 247, 248; 248, string:'.'; 249, integer:0; 250, identifier:split; 251, argument_list; 251, 252; 252, string:','; 253, integer:0; 254, if_statement; 254, 255; 254, 261; 255, comparison_operator:>; 255, 256; 255, 260; 256, call; 256, 257; 256, 258; 257, identifier:len; 258, argument_list; 258, 259; 259, identifier:newAcc; 260, integer:0; 261, block; 261, 262; 262, return_statement; 262, 263; 263, tuple; 263, 264; 263, 265; 263, 266; 264, True; 265, identifier:acc; 266, identifier:newAcc; 267, for_statement; 267, 268; 267, 269; 267, 274; 268, identifier:error; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:error; 272, identifier:splitlines; 273, argument_list; 274, block; 274, 275; 274, 288; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:error; 278, call; 278, 279; 278, 287; 279, attribute; 279, 280; 279, 286; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:error; 283, identifier:decode; 284, argument_list; 284, 285; 285, string:'ascii'; 286, identifier:strip; 287, argument_list; 288, if_statement; 288, 289; 288, 292; 289, comparison_operator:in; 289, 290; 289, 291; 290, string:'500 Can'; 291, identifier:error; 292, block; 292, 293; 293, return_statement; 293, 294; 294, tuple; 294, 295; 294, 296; 294, 297; 295, False; 296, identifier:acc; 297, string:'no network'; 298, return_statement; 298, 299; 299, tuple; 299, 300; 299, 301; 299, 302; 300, False; 301, identifier:acc; 302, string:'efetch failed'
def searchAccession(acc): """ attempt to use NCBI Entrez to get BioSample ID """ # try genbank file # genome database out, error = entrez('genome', acc) for line in out.splitlines(): line = line.decode('ascii').strip() if 'Assembly_Accession' in line or 'BioSample' in line: newAcc = line.split('>')[1].split('<')[0].split('.')[0].split(',')[0] if len(newAcc) > 0: return (True, acc, newAcc) # nucleotide database out, error = entrez('nucleotide', acc) for line in out.splitlines(): line = line.decode('ascii').strip() if 'Assembly_Accession' in line or 'BioSample' in line: newAcc = line.split('>')[1].split('<')[0].split('.')[0].split(',')[0] if len(newAcc) > 0: return (True, acc, newAcc) # assembly database out, error = entrez('assembly', acc) for line in out.splitlines(): line = line.decode('ascii').strip() if 'Assembly_Accession' in line or 'BioSample' in line: newAcc = line.split('>')[1].split('<')[0].split('.')[0].split(',')[0] if len(newAcc) > 0: return (True, acc, newAcc) for error in error.splitlines(): error = error.decode('ascii').strip() if '500 Can' in error: return (False, acc, 'no network') return (False, acc, 'efetch failed')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_configure_logger; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:fmt; 5, identifier:quiet; 6, identifier:level; 7, identifier:fpath; 8, identifier:pre_hooks; 9, identifier:post_hooks; 10, identifier:metric_grouping_interval; 11, block; 11, 12; 11, 14; 11, 15; 11, 27; 11, 29; 11, 33; 11, 34; 11, 61; 11, 67; 11, 81; 11, 91; 11, 100; 11, 106; 11, 129; 11, 145; 11, 161; 11, 168; 11, 182; 11, 186; 11, 187; 11, 199; 11, 217; 11, 225; 11, 243; 11, 252; 11, 253; 11, 280; 11, 281; 11, 289; 11, 298; 11, 305; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:level; 18, call; 18, 19; 18, 20; 19, identifier:getattr; 20, argument_list; 20, 21; 20, 22; 21, identifier:logging; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:level; 25, identifier:upper; 26, argument_list; 27, global_statement; 27, 28; 28, identifier:_GLOBAL_LOG_CONFIGURED; 29, if_statement; 29, 30; 29, 31; 30, identifier:_GLOBAL_LOG_CONFIGURED; 31, block; 31, 32; 32, return_statement; 33, comment; 34, function_definition; 34, 35; 34, 36; 34, 38; 35, function_name:wrap_hook; 36, parameters; 36, 37; 37, identifier:fn; 38, block; 38, 39; 38, 59; 39, decorated_definition; 39, 40; 39, 45; 40, decorator; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:wraps; 43, argument_list; 43, 44; 44, identifier:fn; 45, function_definition; 45, 46; 45, 47; 45, 51; 46, function_name:processor; 47, parameters; 47, 48; 47, 49; 47, 50; 48, identifier:logger; 49, identifier:method_name; 50, identifier:event_dict; 51, block; 51, 52; 51, 57; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:fn; 55, argument_list; 55, 56; 56, identifier:event_dict; 57, return_statement; 57, 58; 58, identifier:event_dict; 59, return_statement; 59, 60; 60, identifier:processor; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:processors; 64, call; 64, 65; 64, 66; 65, identifier:define_log_processors; 66, argument_list; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:processors; 71, identifier:extend; 72, argument_list; 72, 73; 73, list_comprehension; 73, 74; 73, 78; 74, call; 74, 75; 74, 76; 75, identifier:wrap_hook; 76, argument_list; 76, 77; 77, identifier:h; 78, for_in_clause; 78, 79; 78, 80; 79, identifier:h; 80, identifier:pre_hooks; 81, if_statement; 81, 82; 81, 83; 82, identifier:metric_grouping_interval; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:processors; 88, identifier:append; 89, argument_list; 89, 90; 90, identifier:metrics_grouping_processor; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:log_renderer; 94, call; 94, 95; 94, 96; 95, identifier:define_log_renderer; 96, argument_list; 96, 97; 96, 98; 96, 99; 97, identifier:fmt; 98, identifier:fpath; 99, identifier:quiet; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:stderr_required; 103, parenthesized_expression; 103, 104; 104, not_operator; 104, 105; 105, identifier:quiet; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:pretty_to_stderr; 109, parenthesized_expression; 109, 110; 110, boolean_operator:and; 110, 111; 110, 112; 111, identifier:stderr_required; 112, parenthesized_expression; 112, 113; 113, boolean_operator:or; 113, 114; 113, 117; 114, comparison_operator:==; 114, 115; 114, 116; 115, identifier:fmt; 116, string:"pretty"; 117, parenthesized_expression; 117, 118; 118, boolean_operator:and; 118, 119; 118, 122; 119, comparison_operator:is; 119, 120; 119, 121; 120, identifier:fmt; 121, None; 122, call; 122, 123; 122, 128; 123, attribute; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:sys; 126, identifier:stderr; 127, identifier:isatty; 128, argument_list; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:should_inject_pretty_renderer; 132, parenthesized_expression; 132, 133; 133, boolean_operator:and; 133, 134; 133, 135; 134, identifier:pretty_to_stderr; 135, not_operator; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:isinstance; 138, argument_list; 138, 139; 138, 140; 139, identifier:log_renderer; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:structlog; 143, identifier:dev; 144, identifier:ConsoleRenderer; 145, if_statement; 145, 146; 145, 147; 146, identifier:should_inject_pretty_renderer; 147, block; 147, 148; 147, 152; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:stderr_required; 151, False; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:processors; 156, identifier:append; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 160; 159, identifier:StderrConsoleRenderer; 160, argument_list; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:processors; 165, identifier:append; 166, argument_list; 166, 167; 167, identifier:log_renderer; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:processors; 172, identifier:extend; 173, argument_list; 173, 174; 174, list_comprehension; 174, 175; 174, 179; 175, call; 175, 176; 175, 177; 176, identifier:wrap_hook; 177, argument_list; 177, 178; 178, identifier:h; 179, for_in_clause; 179, 180; 179, 181; 180, identifier:h; 181, identifier:post_hooks; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:streams; 185, list:[]; 186, comment; 187, if_statement; 187, 188; 187, 189; 188, identifier:stderr_required; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:streams; 194, identifier:append; 195, argument_list; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:sys; 198, identifier:stderr; 199, if_statement; 199, 200; 199, 203; 199, 204; 199, 205; 200, comparison_operator:is; 200, 201; 200, 202; 201, identifier:fpath; 202, None; 203, comment; 204, comment; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:streams; 210, identifier:append; 211, argument_list; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:open; 214, argument_list; 214, 215; 214, 216; 215, identifier:fpath; 216, string:'a'; 217, assert_statement; 217, 218; 217, 224; 218, comparison_operator:!=; 218, 219; 218, 223; 219, call; 219, 220; 219, 221; 220, identifier:len; 221, argument_list; 221, 222; 222, identifier:streams; 223, integer:0; 224, string:"cannot configure logger for 0 streams"; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:stream; 228, conditional_expression:if; 228, 229; 228, 232; 228, 238; 229, subscript; 229, 230; 229, 231; 230, identifier:streams; 231, integer:0; 232, comparison_operator:==; 232, 233; 232, 237; 233, call; 233, 234; 233, 235; 234, identifier:len; 235, argument_list; 235, 236; 236, identifier:streams; 237, integer:1; 238, call; 238, 239; 238, 240; 239, identifier:Stream; 240, argument_list; 240, 241; 241, list_splat; 241, 242; 242, identifier:streams; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:atexit; 247, identifier:register; 248, argument_list; 248, 249; 249, attribute; 249, 250; 249, 251; 250, identifier:stream; 251, identifier:close; 252, comment; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:structlog; 257, identifier:configure; 258, argument_list; 258, 259; 258, 262; 258, 265; 258, 274; 258, 277; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:processors; 261, identifier:processors; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:context_class; 264, identifier:dict; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:logger_factory; 267, call; 267, 268; 267, 269; 268, identifier:LevelLoggerFactory; 269, argument_list; 269, 270; 269, 271; 270, identifier:stream; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:level; 273, identifier:level; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:wrapper_class; 276, identifier:BoundLevelLogger; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:cache_logger_on_first_use; 279, True; 280, comment; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:stdlib_root_log; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:logging; 287, identifier:getLogger; 288, argument_list; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:stdlib_root_log; 293, identifier:addHandler; 294, argument_list; 294, 295; 295, call; 295, 296; 295, 297; 296, identifier:StdlibStructlogHandler; 297, argument_list; 298, expression_statement; 298, 299; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:stdlib_root_log; 302, identifier:setLevel; 303, argument_list; 303, 304; 304, identifier:level; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 308; 307, identifier:_GLOBAL_LOG_CONFIGURED; 308, True
def _configure_logger(fmt, quiet, level, fpath, pre_hooks, post_hooks, metric_grouping_interval): """ configures a logger when required write to stderr or a file """ # NOTE not thread safe. Multiple BaseScripts cannot be instantiated concurrently. level = getattr(logging, level.upper()) global _GLOBAL_LOG_CONFIGURED if _GLOBAL_LOG_CONFIGURED: return # since the hooks need to run through structlog, need to wrap them like processors def wrap_hook(fn): @wraps(fn) def processor(logger, method_name, event_dict): fn(event_dict) return event_dict return processor processors = define_log_processors() processors.extend( [ wrap_hook(h) for h in pre_hooks ] ) if metric_grouping_interval: processors.append(metrics_grouping_processor) log_renderer = define_log_renderer(fmt, fpath, quiet) stderr_required = (not quiet) pretty_to_stderr = ( stderr_required and ( fmt == "pretty" or (fmt is None and sys.stderr.isatty()) ) ) should_inject_pretty_renderer = ( pretty_to_stderr and not isinstance(log_renderer, structlog.dev.ConsoleRenderer) ) if should_inject_pretty_renderer: stderr_required = False processors.append(StderrConsoleRenderer()) processors.append(log_renderer) processors.extend( [ wrap_hook(h) for h in post_hooks ] ) streams = [] # we need to use a stream if we are writing to both file and stderr, and both are json if stderr_required: streams.append(sys.stderr) if fpath is not None: # TODO handle creating a directory for this log file ? # TODO set mode and encoding appropriately streams.append(open(fpath, 'a')) assert len(streams) != 0, "cannot configure logger for 0 streams" stream = streams[0] if len(streams) == 1 else Stream(*streams) atexit.register(stream.close) # a global level struct log config unless otherwise specified. structlog.configure( processors=processors, context_class=dict, logger_factory=LevelLoggerFactory(stream, level=level), wrapper_class=BoundLevelLogger, cache_logger_on_first_use=True, ) # TODO take care of removing other handlers stdlib_root_log = logging.getLogger() stdlib_root_log.addHandler(StdlibStructlogHandler()) stdlib_root_log.setLevel(level) _GLOBAL_LOG_CONFIGURED = True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:combine_modifiers; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:graphemes; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 24; 6, 210; 6, 211; 6, 221; 6, 225; 6, 229; 6, 287; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:result; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:temp; 16, string:""; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:count; 20, call; 20, 21; 20, 22; 21, identifier:len; 22, argument_list; 22, 23; 23, identifier:graphemes; 24, for_statement; 24, 25; 24, 26; 24, 30; 25, identifier:grapheme; 26, call; 26, 27; 26, 28; 27, identifier:reversed; 28, argument_list; 28, 29; 29, identifier:graphemes; 30, block; 30, 31; 30, 35; 30, 90; 30, 91; 30, 125; 30, 126; 30, 197; 30, 206; 31, expression_statement; 31, 32; 32, augmented_assignment:-=; 32, 33; 32, 34; 33, identifier:count; 34, integer:1; 35, if_statement; 35, 36; 35, 62; 36, boolean_operator:and; 36, 37; 36, 52; 36, 53; 37, boolean_operator:and; 37, 38; 37, 44; 38, comparison_operator:==; 38, 39; 38, 43; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, identifier:grapheme; 43, integer:1; 44, comparison_operator:==; 44, 45; 44, 51; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:unicodedata; 48, identifier:category; 49, argument_list; 49, 50; 50, identifier:grapheme; 51, string:"Lm"; 52, line_continuation:\; 53, not_operator; 53, 54; 54, comparison_operator:in; 54, 55; 54, 59; 55, call; 55, 56; 55, 57; 56, identifier:ord; 57, argument_list; 57, 58; 58, identifier:grapheme; 59, list:[712, 716]; 59, 60; 59, 61; 60, integer:712; 61, integer:716; 62, block; 62, 63; 62, 69; 62, 70; 62, 71; 62, 88; 62, 89; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:temp; 66, binary_operator:+; 66, 67; 66, 68; 67, identifier:grapheme; 68, identifier:temp; 69, comment; 70, comment; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:==; 72, 73; 72, 74; 73, identifier:count; 74, integer:0; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 82; 78, subscript; 78, 79; 78, 80; 79, identifier:result; 80, unary_operator:-; 80, 81; 81, integer:1; 82, binary_operator:+; 82, 83; 82, 84; 83, identifier:temp; 84, subscript; 84, 85; 84, 86; 85, identifier:result; 86, unary_operator:-; 86, 87; 87, integer:1; 88, continue_statement; 89, comment; 90, comment; 91, if_statement; 91, 92; 91, 107; 92, boolean_operator:and; 92, 93; 92, 99; 93, comparison_operator:==; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:grapheme; 98, integer:1; 99, comparison_operator:in; 99, 100; 99, 104; 100, call; 100, 101; 100, 102; 101, identifier:ord; 102, argument_list; 102, 103; 103, identifier:grapheme; 104, list:[712, 716]; 104, 105; 104, 106; 105, integer:712; 106, integer:716; 107, block; 107, 108; 107, 120; 107, 124; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 114; 110, subscript; 110, 111; 110, 112; 111, identifier:result; 112, unary_operator:-; 112, 113; 113, integer:1; 114, binary_operator:+; 114, 115; 114, 116; 115, identifier:grapheme; 116, subscript; 116, 117; 116, 118; 117, identifier:result; 118, unary_operator:-; 118, 119; 119, integer:1; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:temp; 123, string:""; 124, continue_statement; 125, comment; 126, if_statement; 126, 127; 126, 142; 127, boolean_operator:and; 127, 128; 127, 134; 128, comparison_operator:==; 128, 129; 128, 133; 129, call; 129, 130; 129, 131; 130, identifier:len; 131, argument_list; 131, 132; 132, identifier:grapheme; 133, integer:1; 134, comparison_operator:==; 134, 135; 134, 141; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:unicodedata; 138, identifier:category; 139, argument_list; 139, 140; 140, identifier:grapheme; 141, string:"Sk"; 142, block; 142, 143; 143, if_statement; 143, 144; 143, 150; 143, 163; 144, comparison_operator:==; 144, 145; 144, 149; 145, call; 145, 146; 145, 147; 146, identifier:len; 147, argument_list; 147, 148; 148, identifier:result; 149, integer:0; 150, block; 150, 151; 150, 158; 150, 162; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:result; 155, identifier:append; 156, argument_list; 156, 157; 157, identifier:grapheme; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:temp; 161, string:""; 162, continue_statement; 163, else_clause; 163, 164; 164, block; 164, 165; 165, if_statement; 165, 166; 165, 179; 166, comparison_operator:==; 166, 167; 166, 178; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:unicodedata; 170, identifier:category; 171, argument_list; 171, 172; 172, subscript; 172, 173; 172, 177; 173, subscript; 173, 174; 173, 175; 174, identifier:result; 175, unary_operator:-; 175, 176; 176, integer:1; 177, integer:0; 178, string:"Sk"; 179, block; 179, 180; 179, 192; 179, 196; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 186; 182, subscript; 182, 183; 182, 184; 183, identifier:result; 184, unary_operator:-; 184, 185; 185, integer:1; 186, binary_operator:+; 186, 187; 186, 188; 187, identifier:grapheme; 188, subscript; 188, 189; 188, 190; 189, identifier:result; 190, unary_operator:-; 190, 191; 191, integer:1; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:temp; 195, string:""; 196, continue_statement; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:result; 201, identifier:append; 202, argument_list; 202, 203; 203, binary_operator:+; 203, 204; 203, 205; 204, identifier:grapheme; 205, identifier:temp; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:temp; 209, string:""; 210, comment; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:segments; 214, subscript; 214, 215; 214, 216; 215, identifier:result; 216, slice; 216, 217; 216, 218; 216, 219; 217, colon; 218, colon; 219, unary_operator:-; 219, 220; 220, integer:1; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:i; 224, integer:0; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:r; 228, list:[]; 229, while_statement; 229, 230; 229, 236; 229, 237; 230, comparison_operator:<; 230, 231; 230, 232; 231, identifier:i; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, identifier:segments; 236, comment; 237, block; 237, 238; 238, if_statement; 238, 239; 238, 252; 238, 272; 239, comparison_operator:in; 239, 240; 239, 249; 240, call; 240, 241; 240, 242; 241, identifier:ord; 242, argument_list; 242, 243; 243, subscript; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:segments; 246, identifier:i; 247, unary_operator:-; 247, 248; 248, integer:1; 249, list:[865, 860]; 249, 250; 249, 251; 250, integer:865; 251, integer:860; 252, block; 252, 253; 252, 268; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:r; 257, identifier:append; 258, argument_list; 258, 259; 259, binary_operator:+; 259, 260; 259, 263; 260, subscript; 260, 261; 260, 262; 261, identifier:segments; 262, identifier:i; 263, subscript; 263, 264; 263, 265; 264, identifier:segments; 265, binary_operator:+; 265, 266; 265, 267; 266, identifier:i; 267, integer:1; 268, expression_statement; 268, 269; 269, augmented_assignment:+=; 269, 270; 269, 271; 270, identifier:i; 271, integer:2; 272, else_clause; 272, 273; 273, block; 273, 274; 273, 283; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:r; 278, identifier:append; 279, argument_list; 279, 280; 280, subscript; 280, 281; 280, 282; 281, identifier:segments; 282, identifier:i; 283, expression_statement; 283, 284; 284, augmented_assignment:+=; 284, 285; 284, 286; 285, identifier:i; 286, integer:1; 287, return_statement; 287, 288; 288, identifier:r
def combine_modifiers(self, graphemes): """ Given a string that is space-delimited on Unicode grapheme clusters, group Unicode modifier letters with their preceding base characters, deal with tie bars, etc. Parameters ---------- string : str A Unicode string tokenized into grapheme clusters to be tokenized into simple IPA. """ result = [] temp = "" count = len(graphemes) for grapheme in reversed(graphemes): count -= 1 if len(grapheme) == 1 and unicodedata.category(grapheme) == "Lm" \ and not ord(grapheme) in [712, 716]: temp = grapheme + temp # hack for the cases where a space modifier is the first character in the # string if count == 0: result[-1] = temp + result[-1] continue # pragma: no cover # catch and repair stress marks if len(grapheme) == 1 and ord(grapheme) in [712, 716]: result[-1] = grapheme + result[-1] temp = "" continue # combine contour tone marks (non-accents) if len(grapheme) == 1 and unicodedata.category(grapheme) == "Sk": if len(result) == 0: result.append(grapheme) temp = "" continue else: if unicodedata.category(result[-1][0]) == "Sk": result[-1] = grapheme + result[-1] temp = "" continue result.append(grapheme + temp) temp = "" # last check for tie bars segments = result[::-1] i = 0 r = [] while i < len(segments): # tie bars if ord(segments[i][-1]) in [865, 860]: r.append(segments[i] + segments[i + 1]) i += 2 else: r.append(segments[i]) i += 1 return r
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:check_mismatches; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:read; 5, identifier:pair; 6, identifier:mismatches; 7, identifier:mm_option; 8, identifier:req_map; 9, block; 9, 10; 9, 12; 9, 13; 9, 48; 9, 49; 9, 56; 9, 63; 9, 64; 9, 75; 9, 76; 9, 83; 9, 84; 9, 100; 9, 101; 9, 127; 9, 128; 9, 180; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:pair; 16, False; 17, block; 17, 18; 17, 25; 17, 32; 17, 33; 17, 40; 17, 41; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:mm; 21, call; 21, 22; 21, 23; 22, identifier:count_mismatches; 23, argument_list; 23, 24; 24, identifier:read; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:mm; 28, False; 29, block; 29, 30; 30, return_statement; 30, 31; 31, False; 32, comment; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:mismatches; 36, False; 37, block; 37, 38; 38, return_statement; 38, 39; 39, True; 40, comment; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:<=; 42, 43; 42, 44; 43, identifier:mm; 44, identifier:mismatches; 45, block; 45, 46; 46, return_statement; 46, 47; 47, True; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:r_mm; 52, call; 52, 53; 52, 54; 53, identifier:count_mismatches; 54, argument_list; 54, 55; 55, identifier:read; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:p_mm; 59, call; 59, 60; 59, 61; 60, identifier:count_mismatches; 61, argument_list; 61, 62; 62, identifier:pair; 63, comment; 64, if_statement; 64, 65; 64, 72; 65, boolean_operator:and; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:r_mm; 68, False; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:p_mm; 71, False; 72, block; 72, 73; 73, return_statement; 73, 74; 74, False; 75, comment; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:mismatches; 79, False; 80, block; 80, 81; 81, return_statement; 81, 82; 82, True; 83, comment; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:is; 85, 86; 85, 87; 86, identifier:req_map; 87, True; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 97; 90, boolean_operator:or; 90, 91; 90, 94; 91, comparison_operator:is; 91, 92; 91, 93; 92, identifier:r_mm; 93, False; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:p_mm; 96, False; 97, block; 97, 98; 98, return_statement; 98, 99; 99, False; 100, comment; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:==; 102, 103; 102, 104; 103, identifier:mm_option; 104, string:'one'; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 124; 107, boolean_operator:or; 107, 108; 107, 116; 108, parenthesized_expression; 108, 109; 109, boolean_operator:and; 109, 110; 109, 113; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:r_mm; 112, False; 113, comparison_operator:<=; 113, 114; 113, 115; 114, identifier:r_mm; 115, identifier:mismatches; 116, parenthesized_expression; 116, 117; 117, boolean_operator:and; 117, 118; 117, 121; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:p_mm; 120, False; 121, comparison_operator:<=; 121, 122; 121, 123; 122, identifier:p_mm; 123, identifier:mismatches; 124, block; 124, 125; 125, return_statement; 125, 126; 126, True; 127, comment; 128, if_statement; 128, 129; 128, 132; 128, 133; 128, 134; 129, comparison_operator:==; 129, 130; 129, 131; 130, identifier:mm_option; 131, string:'both'; 132, comment; 133, comment; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 139; 135, 147; 135, 159; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:r_mm; 138, False; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 144; 141, comparison_operator:<=; 141, 142; 141, 143; 142, identifier:p_mm; 143, identifier:mismatches; 144, block; 144, 145; 145, return_statement; 145, 146; 146, True; 147, elif_clause; 147, 148; 147, 151; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:p_mm; 150, False; 151, block; 151, 152; 152, if_statement; 152, 153; 152, 156; 153, comparison_operator:<=; 153, 154; 153, 155; 154, identifier:r_mm; 155, identifier:mismatches; 156, block; 156, 157; 157, return_statement; 157, 158; 158, True; 159, elif_clause; 159, 160; 159, 177; 160, boolean_operator:and; 160, 161; 160, 169; 161, parenthesized_expression; 161, 162; 162, boolean_operator:and; 162, 163; 162, 166; 163, comparison_operator:is; 163, 164; 163, 165; 164, identifier:r_mm; 165, False; 166, comparison_operator:<=; 166, 167; 166, 168; 167, identifier:r_mm; 168, identifier:mismatches; 169, parenthesized_expression; 169, 170; 170, boolean_operator:and; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:p_mm; 173, False; 174, comparison_operator:<=; 174, 175; 174, 176; 175, identifier:p_mm; 176, identifier:mismatches; 177, block; 177, 178; 178, return_statement; 178, 179; 179, True; 180, return_statement; 180, 181; 181, False
def check_mismatches(read, pair, mismatches, mm_option, req_map): """ - check to see if the read maps with <= threshold number of mismatches - mm_option = 'one' or 'both' depending on whether or not one or both reads in a pair need to pass the mismatch threshold - pair can be False if read does not have a pair - make sure alignment score is not 0, which would indicate that the read was not aligned to the reference """ # if read is not paired, make sure it is mapped and that mm <= thresh if pair is False: mm = count_mismatches(read) if mm is False: return False # if no threshold is supplied, return True if mismatches is False: return True # passes threshold? if mm <= mismatches: return True # paired reads r_mm = count_mismatches(read) p_mm = count_mismatches(pair) # if neither read is mapped, return False if r_mm is False and p_mm is False: return False # if no threshold, return True if mismatches is False: return True # if req_map is True, both reads have to map if req_map is True: if r_mm is False or p_mm is False: return False ## if option is 'one,' only one read has to pass threshold if mm_option == 'one': if (r_mm is not False and r_mm <= mismatches) or (p_mm is not False and p_mm <= mismatches): return True ## if option is 'both,' both reads have to pass threshold if mm_option == 'both': ## if one read in pair does not map to the scaffold, ## make sure the other read passes threshold if r_mm is False: if p_mm <= mismatches: return True elif p_mm is False: if r_mm <= mismatches: return True elif (r_mm is not False and r_mm <= mismatches) and (p_mm is not False and p_mm <= mismatches): return True return False
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_steam; 3, parameters; 4, block; 4, 5; 4, 7; 4, 8; 4, 9; 4, 10; 4, 30; 4, 31; 4, 32; 4, 40; 4, 54; 4, 68; 4, 69; 4, 70; 4, 71; 4, 72; 4, 97; 4, 98; 4, 99; 4, 100; 4, 101; 5, expression_statement; 5, 6; 6, comment; 7, comment; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:helper; 13, lambda; 13, 14; 13, 16; 14, lambda_parameters; 14, 15; 15, identifier:udd; 16, conditional_expression:if; 16, 17; 16, 21; 16, 29; 17, call; 17, 18; 17, 19; 18, identifier:Steam; 19, argument_list; 19, 20; 20, identifier:udd; 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:exists; 27, argument_list; 27, 28; 28, identifier:udd; 29, None; 30, comment; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:plat; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:platform; 38, identifier:system; 39, argument_list; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:==; 41, 42; 41, 43; 42, identifier:plat; 43, string:'Darwin'; 44, block; 44, 45; 45, return_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:helper; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:paths; 52, identifier:default_osx_userdata_path; 53, argument_list; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:plat; 57, string:'Linux'; 58, block; 58, 59; 59, return_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:helper; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:paths; 66, identifier:default_linux_userdata_path; 67, argument_list; 68, comment; 69, comment; 70, comment; 71, comment; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:==; 73, 74; 73, 75; 74, identifier:plat; 75, string:'Windows'; 76, block; 76, 77; 76, 85; 76, 86; 76, 87; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:possible_dir; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:winutils; 83, identifier:find_userdata_directory; 84, argument_list; 85, comment; 86, comment; 87, return_statement; 87, 88; 88, conditional_expression:if; 88, 89; 88, 93; 88, 96; 89, call; 89, 90; 89, 91; 90, identifier:helper; 91, argument_list; 91, 92; 92, identifier:possible_dir; 93, comparison_operator:is; 93, 94; 93, 95; 94, identifier:possible_dir; 95, None; 96, None; 97, comment; 98, comment; 99, comment; 100, comment; 101, return_statement; 101, 102; 102, None
def get_steam(): """ Returns a Steam object representing the current Steam installation on the users computer. If the user doesn't have Steam installed, returns None. """ # Helper function which checks if the potential userdata directory exists # and returns a new Steam instance with that userdata directory if it does. # If the directory doesnt exist it returns None instead helper = lambda udd: Steam(udd) if os.path.exists(udd) else None # For both OS X and Linux, Steam stores it's userdata in a consistent # location. plat = platform.system() if plat == 'Darwin': return helper(paths.default_osx_userdata_path()) if plat == 'Linux': return helper(paths.default_linux_userdata_path()) # Windows is a bit trickier. The userdata directory is stored in the Steam # installation directory, meaning that theoretically it could be anywhere. # Luckily, Valve stores the installation directory in the registry, so its # still possible for us to figure out automatically if plat == 'Windows': possible_dir = winutils.find_userdata_directory() # Unlike the others, `possible_dir` might be None (if something odd # happened with the registry) return helper(possible_dir) if possible_dir is not None else None # This should never be hit. Windows, OS X, and Linux should be the only # supported platforms. # TODO: Add logging here so that the user (developer) knows that something # odd happened. return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:generate_barcodes; 3, parameters; 3, 4; 3, 5; 4, identifier:nIds; 5, default_parameter; 5, 6; 5, 7; 6, identifier:codeLen; 7, integer:12; 8, block; 8, 9; 8, 11; 8, 41; 8, 56; 8, 77; 8, 78; 8, 90; 8, 115; 8, 119; 8, 195; 9, expression_statement; 9, 10; 10, comment; 11, function_definition; 11, 12; 11, 13; 11, 17; 12, function_name:next_code; 13, parameters; 13, 14; 13, 15; 13, 16; 14, identifier:b; 15, identifier:c; 16, identifier:i; 17, block; 17, 18; 18, return_statement; 18, 19; 19, binary_operator:+; 19, 20; 19, 27; 20, binary_operator:+; 20, 21; 20, 26; 21, subscript; 21, 22; 21, 23; 22, identifier:c; 23, slice; 23, 24; 23, 25; 24, colon; 25, identifier:i; 26, identifier:b; 27, parenthesized_expression; 27, 28; 28, conditional_expression:if; 28, 29; 28, 36; 28, 40; 29, subscript; 29, 30; 29, 31; 30, identifier:c; 31, slice; 31, 32; 31, 35; 32, binary_operator:+; 32, 33; 32, 34; 33, identifier:i; 34, integer:1; 35, colon; 36, comparison_operator:<; 36, 37; 36, 38; 37, identifier:i; 38, unary_operator:-; 38, 39; 39, integer:1; 40, string:''; 41, function_definition; 41, 42; 41, 43; 41, 44; 42, function_name:rand_base; 43, parameters; 44, block; 44, 45; 45, return_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:random; 49, identifier:choice; 50, argument_list; 50, 51; 51, list:['A', 'T', 'C', 'G']; 51, 52; 51, 53; 51, 54; 51, 55; 52, string:'A'; 53, string:'T'; 54, string:'C'; 55, string:'G'; 56, function_definition; 56, 57; 56, 58; 56, 60; 57, function_name:rand_seq; 58, parameters; 58, 59; 59, identifier:n; 60, block; 60, 61; 61, return_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, string:''; 65, identifier:join; 66, argument_list; 66, 67; 67, list_comprehension; 67, 68; 67, 71; 68, call; 68, 69; 68, 70; 69, identifier:rand_base; 70, argument_list; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:_; 73, call; 73, 74; 73, 75; 74, identifier:range; 75, argument_list; 75, 76; 76, identifier:n; 77, comment; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:hpf; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:re; 84, identifier:compile; 85, argument_list; 85, 86; 85, 87; 86, string:'aaaa|cccc|gggg|tttt'; 87, attribute; 87, 88; 87, 89; 88, identifier:re; 89, identifier:IGNORECASE; 90, while_statement; 90, 91; 90, 92; 91, True; 92, block; 92, 93; 92, 101; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:codes; 96, list:[rand_seq(codeLen)]; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:rand_seq; 99, argument_list; 99, 100; 100, identifier:codeLen; 101, if_statement; 101, 102; 101, 113; 102, parenthesized_expression; 102, 103; 103, comparison_operator:is; 103, 104; 103, 112; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:hpf; 107, identifier:search; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 111; 110, identifier:codes; 111, integer:0; 112, None; 113, block; 113, 114; 114, break_statement; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:idx; 118, integer:0; 119, while_statement; 119, 120; 119, 126; 120, comparison_operator:<; 120, 121; 120, 125; 121, call; 121, 122; 121, 123; 122, identifier:len; 123, argument_list; 123, 124; 124, identifier:codes; 125, identifier:nIds; 126, block; 126, 127; 126, 131; 126, 185; 127, expression_statement; 127, 128; 128, augmented_assignment:-=; 128, 129; 128, 130; 129, identifier:idx; 130, integer:1; 131, if_statement; 131, 132; 131, 136; 131, 152; 132, comparison_operator:<; 132, 133; 132, 134; 133, identifier:idx; 134, unary_operator:-; 134, 135; 135, identifier:codeLen; 136, block; 136, 137; 136, 142; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:idx; 140, unary_operator:-; 140, 141; 141, integer:1; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:codes; 146, identifier:append; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:rand_seq; 150, argument_list; 150, 151; 151, identifier:codeLen; 152, else_clause; 152, 153; 153, block; 153, 154; 153, 168; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:nc; 157, call; 157, 158; 157, 159; 158, identifier:next_code; 159, argument_list; 159, 160; 159, 163; 159, 167; 160, call; 160, 161; 160, 162; 161, identifier:rand_base; 162, argument_list; 163, subscript; 163, 164; 163, 165; 164, identifier:codes; 165, unary_operator:-; 165, 166; 166, integer:1; 167, identifier:idx; 168, if_statement; 168, 169; 168, 177; 169, comparison_operator:is; 169, 170; 169, 176; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:hpf; 173, identifier:search; 174, argument_list; 174, 175; 175, identifier:nc; 176, None; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:codes; 182, identifier:append; 183, argument_list; 183, 184; 184, identifier:nc; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:codes; 188, call; 188, 189; 188, 190; 189, identifier:list; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:set; 193, argument_list; 193, 194; 194, identifier:codes; 195, return_statement; 195, 196; 196, identifier:codes
def generate_barcodes(nIds, codeLen=12): """ Given a list of sample IDs generate unique n-base barcodes for each. Note that only 4^n unique barcodes are possible. """ def next_code(b, c, i): return c[:i] + b + (c[i+1:] if i < -1 else '') def rand_base(): return random.choice(['A', 'T', 'C', 'G']) def rand_seq(n): return ''.join([rand_base() for _ in range(n)]) # homopolymer filter regex: match if 4 identical bases in a row hpf = re.compile('aaaa|cccc|gggg|tttt', re.IGNORECASE) while True: codes = [rand_seq(codeLen)] if (hpf.search(codes[0]) is None): break idx = 0 while len(codes) < nIds: idx -= 1 if idx < -codeLen: idx = -1 codes.append(rand_seq(codeLen)) else: nc = next_code(rand_base(), codes[-1], idx) if hpf.search(nc) is None: codes.append(nc) codes = list(set(codes)) return codes
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:parse_fasta_annotations; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:fastas; 5, identifier:annot_tables; 6, identifier:trans_table; 7, block; 7, 8; 7, 10; 7, 58; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:annot_tables; 13, False; 14, block; 14, 15; 14, 19; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:annots; 18, dictionary; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:table; 21, identifier:annot_tables; 22, block; 22, 23; 23, for_statement; 23, 24; 23, 25; 23, 29; 24, identifier:cds; 25, call; 25, 26; 25, 27; 26, identifier:open; 27, argument_list; 27, 28; 28, identifier:table; 29, block; 29, 30; 29, 46; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 37; 32, pattern_list; 32, 33; 32, 34; 32, 35; 32, 36; 33, identifier:ID; 34, identifier:start; 35, identifier:end; 36, identifier:strand; 37, call; 37, 38; 37, 45; 38, attribute; 38, 39; 38, 44; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:cds; 42, identifier:strip; 43, argument_list; 44, identifier:split; 45, argument_list; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:annots; 50, identifier:ID; 51, list:[start, end, int(strand)]; 51, 52; 51, 53; 51, 54; 52, identifier:start; 53, identifier:end; 54, call; 54, 55; 54, 56; 55, identifier:int; 56, argument_list; 56, 57; 57, identifier:strand; 58, for_statement; 58, 59; 58, 60; 58, 61; 59, identifier:fasta; 60, identifier:fastas; 61, block; 61, 62; 62, for_statement; 62, 63; 62, 64; 62, 68; 63, identifier:seq; 64, call; 64, 65; 64, 66; 65, identifier:parse_fasta; 66, argument_list; 66, 67; 67, identifier:fasta; 68, block; 68, 69; 68, 101; 68, 189; 68, 208; 68, 209; 68, 318; 68, 335; 69, if_statement; 69, 70; 69, 86; 70, boolean_operator:and; 70, 71; 70, 83; 71, parenthesized_expression; 71, 72; 72, boolean_operator:and; 72, 73; 72, 78; 73, comparison_operator:not; 73, 74; 73, 75; 74, string:'# ;gc_cont'; 75, subscript; 75, 76; 75, 77; 76, identifier:seq; 77, integer:0; 78, comparison_operator:not; 78, 79; 78, 80; 79, string:'# ID='; 80, subscript; 80, 81; 80, 82; 81, identifier:seq; 82, integer:0; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:annot_tables; 85, False; 86, block; 86, 87; 86, 97; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:print; 90, argument_list; 90, 91; 90, 92; 91, string:'# specify fasta from Prodigal or annotations table (-t)'; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:file; 94, attribute; 94, 95; 94, 96; 95, identifier:sys; 96, identifier:stderr; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:exit; 100, argument_list; 101, if_statement; 101, 102; 101, 107; 101, 160; 102, comparison_operator:in; 102, 103; 102, 104; 103, string:'ID='; 104, subscript; 104, 105; 104, 106; 105, identifier:seq; 106, integer:0; 107, block; 107, 108; 107, 130; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:ID; 111, subscript; 111, 112; 111, 129; 112, call; 112, 113; 112, 126; 113, attribute; 113, 114; 113, 125; 114, subscript; 114, 115; 114, 124; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:seq; 119, integer:0; 120, identifier:rsplit; 121, argument_list; 121, 122; 121, 123; 122, string:'ID='; 123, integer:1; 124, integer:1; 125, identifier:split; 126, argument_list; 126, 127; 126, 128; 127, string:';'; 128, integer:1; 129, integer:0; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:contig; 133, subscript; 133, 134; 133, 159; 134, call; 134, 135; 134, 153; 135, attribute; 135, 136; 135, 152; 136, subscript; 136, 137; 136, 151; 137, call; 137, 138; 137, 149; 138, attribute; 138, 139; 138, 148; 139, subscript; 139, 140; 139, 147; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:seq; 144, integer:0; 145, identifier:split; 146, argument_list; 147, integer:0; 148, identifier:split; 149, argument_list; 149, 150; 150, string:'>'; 151, integer:1; 152, identifier:rsplit; 153, argument_list; 153, 154; 153, 158; 154, binary_operator:%; 154, 155; 154, 156; 155, string:'_%s'; 156, parenthesized_expression; 156, 157; 157, identifier:ID; 158, integer:1; 159, integer:0; 160, else_clause; 160, 161; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:contig; 165, subscript; 165, 166; 165, 188; 166, call; 166, 167; 166, 185; 167, attribute; 167, 168; 167, 184; 168, subscript; 168, 169; 168, 183; 169, call; 169, 170; 169, 181; 170, attribute; 170, 171; 170, 180; 171, subscript; 171, 172; 171, 179; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, subscript; 174, 175; 174, 176; 175, identifier:seq; 176, integer:0; 177, identifier:split; 178, argument_list; 179, integer:0; 180, identifier:split; 181, argument_list; 181, 182; 182, string:'>'; 183, integer:1; 184, identifier:rsplit; 185, argument_list; 185, 186; 185, 187; 186, string:'_'; 187, integer:1; 188, integer:0; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:locus; 192, subscript; 192, 193; 192, 207; 193, call; 193, 194; 193, 205; 194, attribute; 194, 195; 194, 204; 195, subscript; 195, 196; 195, 203; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:seq; 200, integer:0; 201, identifier:split; 202, argument_list; 203, integer:0; 204, identifier:split; 205, argument_list; 205, 206; 206, string:'>'; 207, integer:1; 208, comment; 209, if_statement; 209, 210; 209, 222; 209, 292; 209, 293; 210, parenthesized_expression; 210, 211; 211, boolean_operator:or; 211, 212; 211, 217; 212, comparison_operator:in; 212, 213; 212, 214; 213, string:'# ;gc_cont'; 214, subscript; 214, 215; 214, 216; 215, identifier:seq; 216, integer:0; 217, comparison_operator:in; 217, 218; 217, 219; 218, string:'# ID='; 219, subscript; 219, 220; 219, 221; 220, identifier:seq; 221, integer:0; 222, block; 222, 223; 222, 234; 222, 256; 222, 272; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:info; 226, call; 226, 227; 226, 232; 227, attribute; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:seq; 230, integer:0; 231, identifier:split; 232, argument_list; 232, 233; 233, string:' # '; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 240; 236, pattern_list; 236, 237; 236, 238; 236, 239; 237, identifier:start; 238, identifier:end; 239, identifier:strand; 240, expression_list; 240, 241; 240, 247; 240, 253; 241, call; 241, 242; 241, 243; 242, identifier:int; 243, argument_list; 243, 244; 244, subscript; 244, 245; 244, 246; 245, identifier:info; 246, integer:1; 247, call; 247, 248; 247, 249; 248, identifier:int; 249, argument_list; 249, 250; 250, subscript; 250, 251; 250, 252; 251, identifier:info; 252, integer:2; 253, subscript; 253, 254; 253, 255; 254, identifier:info; 255, integer:3; 256, if_statement; 256, 257; 256, 260; 256, 265; 257, comparison_operator:==; 257, 258; 257, 259; 258, identifier:strand; 259, string:'1'; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:strand; 264, integer:1; 265, else_clause; 265, 266; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:strand; 270, unary_operator:-; 270, 271; 271, integer:1; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:product; 275, list:[''.join(info[4].split()[1:])]; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, string:''; 279, identifier:join; 280, argument_list; 280, 281; 281, subscript; 281, 282; 281, 289; 282, call; 282, 283; 282, 288; 283, attribute; 283, 284; 283, 287; 284, subscript; 284, 285; 284, 286; 285, identifier:info; 286, integer:4; 287, identifier:split; 288, argument_list; 289, slice; 289, 290; 289, 291; 290, integer:1; 291, colon; 292, comment; 293, else_clause; 293, 294; 294, block; 294, 295; 294, 304; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 301; 297, pattern_list; 297, 298; 297, 299; 297, 300; 298, identifier:start; 299, identifier:end; 300, identifier:strand; 301, subscript; 301, 302; 301, 303; 302, identifier:annots; 303, identifier:locus; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:product; 307, subscript; 307, 308; 307, 317; 308, call; 308, 309; 308, 314; 309, attribute; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:seq; 312, integer:0; 313, identifier:split; 314, argument_list; 314, 315; 314, 316; 315, string:' '; 316, integer:1; 317, integer:1; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:info; 321, dictionary; 321, 322; 321, 326; 321, 332; 322, pair; 322, 323; 322, 324; 323, string:'transl_table'; 324, list:[trans_table]; 324, 325; 325, identifier:trans_table; 326, pair; 326, 327; 326, 328; 327, string:'translation'; 328, list:[seq[1]]; 328, 329; 329, subscript; 329, 330; 329, 331; 330, identifier:seq; 331, integer:1; 332, pair; 332, 333; 332, 334; 333, string:'product'; 334, identifier:product; 335, expression_statement; 335, 336; 336, yield; 336, 337; 337, expression_list; 337, 338; 337, 339; 338, identifier:contig; 339, list:[locus, [start, end, strand], info]; 339, 340; 339, 341; 339, 345; 340, identifier:locus; 341, list:[start, end, strand]; 341, 342; 341, 343; 341, 344; 342, identifier:start; 343, identifier:end; 344, identifier:strand; 345, identifier:info
def parse_fasta_annotations(fastas, annot_tables, trans_table): """ parse gene call information from Prodigal fasta output """ if annot_tables is not False: annots = {} for table in annot_tables: for cds in open(table): ID, start, end, strand = cds.strip().split() annots[ID] = [start, end, int(strand)] for fasta in fastas: for seq in parse_fasta(fasta): if ('# ;gc_cont' not in seq[0] and '# ID=' not in seq[0]) and annot_tables is False: print('# specify fasta from Prodigal or annotations table (-t)', file=sys.stderr) exit() if 'ID=' in seq[0]: ID = seq[0].rsplit('ID=', 1)[1].split(';', 1)[0] contig = seq[0].split()[0].split('>')[1].rsplit('_%s' % (ID), 1)[0] else: contig = seq[0].split()[0].split('>')[1].rsplit('_', 1)[0] locus = seq[0].split()[0].split('>')[1] # annotation info from Prodigal if ('# ;gc_cont' in seq[0] or '# ID=' in seq[0]): info = seq[0].split(' # ') start, end, strand = int(info[1]), int(info[2]), info[3] if strand == '1': strand = 1 else: strand = -1 product = [''.join(info[4].split()[1:])] # annotation info from table else: start, end, strand = annots[locus] product = seq[0].split(' ', 1)[1] info = {'transl_table':[trans_table], \ 'translation':[seq[1]], \ 'product':product} yield contig, [locus, [start, end, strand], info]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:find_consensus; 3, parameters; 3, 4; 4, identifier:bases; 5, block; 5, 6; 5, 8; 5, 17; 5, 34; 5, 35; 5, 78; 5, 96; 5, 126; 5, 186; 5, 192; 5, 198; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:nucs; 11, list:['A', 'T', 'G', 'C', 'N']; 11, 12; 11, 13; 11, 14; 11, 15; 11, 16; 12, string:'A'; 13, string:'T'; 14, string:'G'; 15, string:'C'; 16, string:'N'; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:total; 20, call; 20, 21; 20, 22; 21, identifier:sum; 22, argument_list; 22, 23; 23, list_comprehension; 23, 24; 23, 27; 23, 30; 24, subscript; 24, 25; 24, 26; 25, identifier:bases; 26, identifier:nuc; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:nuc; 29, identifier:nucs; 30, if_clause; 30, 31; 31, comparison_operator:in; 31, 32; 31, 33; 32, identifier:nuc; 33, identifier:bases; 34, comment; 35, try_statement; 35, 36; 35, 54; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:top; 40, call; 40, 41; 40, 42; 41, identifier:max; 42, argument_list; 42, 43; 43, list_comprehension; 43, 44; 43, 47; 43, 50; 44, subscript; 44, 45; 44, 46; 45, identifier:bases; 46, identifier:nuc; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:nuc; 49, identifier:nucs; 50, if_clause; 50, 51; 51, comparison_operator:in; 51, 52; 51, 53; 52, identifier:nuc; 53, identifier:bases; 54, except_clause; 54, 55; 55, block; 55, 56; 55, 64; 55, 70; 55, 76; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:bases; 60, string:'consensus'; 61, tuple; 61, 62; 61, 63; 62, string:'N'; 63, string:'n/a'; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:bases; 68, string:'consensus frequency'; 69, string:'n/a'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:bases; 74, string:'reference frequency'; 75, string:'n/a'; 76, return_statement; 76, 77; 77, identifier:bases; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:top; 81, list_comprehension; 81, 82; 81, 87; 81, 90; 82, tuple; 82, 83; 82, 84; 83, identifier:nuc; 84, subscript; 84, 85; 84, 86; 85, identifier:bases; 86, identifier:nuc; 87, for_in_clause; 87, 88; 87, 89; 88, identifier:nuc; 89, identifier:bases; 90, if_clause; 90, 91; 91, comparison_operator:==; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:bases; 94, identifier:nuc; 95, identifier:top; 96, if_statement; 96, 97; 96, 104; 96, 113; 97, comparison_operator:==; 97, 98; 97, 103; 98, subscript; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:top; 101, integer:0; 102, integer:1; 103, integer:0; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:bases; 109, string:'consensus'; 110, tuple; 110, 111; 110, 112; 111, string:'n/a'; 112, integer:0; 113, else_clause; 113, 114; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:bases; 119, string:'consensus'; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:random; 123, identifier:choice; 124, argument_list; 124, 125; 125, identifier:top; 126, if_statement; 126, 127; 126, 130; 126, 139; 127, comparison_operator:==; 127, 128; 127, 129; 128, identifier:total; 129, integer:0; 130, block; 130, 131; 130, 135; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:c_freq; 134, string:'n/a'; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:ref_freq; 138, string:'n/a'; 139, else_clause; 139, 140; 140, block; 140, 141; 140, 157; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:c_freq; 144, binary_operator:/; 144, 145; 144, 153; 145, call; 145, 146; 145, 147; 146, identifier:float; 147, argument_list; 147, 148; 148, subscript; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:bases; 151, string:'consensus'; 152, integer:1; 153, call; 153, 154; 153, 155; 154, identifier:float; 155, argument_list; 155, 156; 156, identifier:total; 157, if_statement; 157, 158; 157, 163; 157, 168; 158, comparison_operator:not; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:bases; 161, string:'ref'; 162, identifier:bases; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:ref_freq; 167, integer:0; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:ref_freq; 173, binary_operator:/; 173, 174; 173, 182; 174, call; 174, 175; 174, 176; 175, identifier:float; 176, argument_list; 176, 177; 177, subscript; 177, 178; 177, 179; 178, identifier:bases; 179, subscript; 179, 180; 179, 181; 180, identifier:bases; 181, string:'ref'; 182, call; 182, 183; 182, 184; 183, identifier:float; 184, argument_list; 184, 185; 185, identifier:total; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:bases; 190, string:'consensus frequency'; 191, identifier:c_freq; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:bases; 196, string:'reference frequency'; 197, identifier:ref_freq; 198, return_statement; 198, 199; 199, identifier:bases
def find_consensus(bases): """ find consensus base based on nucleotide frequencies """ nucs = ['A', 'T', 'G', 'C', 'N'] total = sum([bases[nuc] for nuc in nucs if nuc in bases]) # save most common base as consensus (random nuc if there is a tie) try: top = max([bases[nuc] for nuc in nucs if nuc in bases]) except: bases['consensus'] = ('N', 'n/a') bases['consensus frequency'] = 'n/a' bases['reference frequency'] = 'n/a' return bases top = [(nuc, bases[nuc]) for nuc in bases if bases[nuc] == top] if top[0][1] == 0: bases['consensus'] = ('n/a', 0) else: bases['consensus'] = random.choice(top) if total == 0: c_freq = 'n/a' ref_freq = 'n/a' else: c_freq = float(bases['consensus'][1]) / float(total) if bases['ref'] not in bases: ref_freq = 0 else: ref_freq = float(bases[bases['ref']]) / float(total) bases['consensus frequency'] = c_freq bases['reference frequency'] = ref_freq return bases
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:print_consensus; 3, parameters; 3, 4; 4, identifier:genomes; 5, block; 5, 6; 5, 8; 5, 9; 5, 13; 5, 14; 5, 132; 5, 133; 5, 209; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:cons; 12, dictionary; 13, comment; 14, for_statement; 14, 15; 14, 18; 14, 26; 15, pattern_list; 15, 16; 15, 17; 16, identifier:genome; 17, identifier:contigs; 18, call; 18, 19; 18, 20; 19, identifier:list; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:genomes; 24, identifier:items; 25, argument_list; 26, block; 26, 27; 26, 33; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, subscript; 29, 30; 29, 31; 30, identifier:cons; 31, identifier:genome; 32, dictionary; 33, for_statement; 33, 34; 33, 37; 33, 45; 34, pattern_list; 34, 35; 34, 36; 35, identifier:contig; 36, identifier:samples; 37, call; 37, 38; 37, 39; 38, identifier:list; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:contigs; 43, identifier:items; 44, argument_list; 45, block; 45, 46; 46, for_statement; 46, 47; 46, 50; 46, 58; 47, pattern_list; 47, 48; 47, 49; 48, identifier:sample; 49, identifier:stats; 50, call; 50, 51; 50, 52; 51, identifier:list; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:samples; 56, identifier:items; 57, argument_list; 58, block; 58, 59; 58, 74; 58, 86; 59, if_statement; 59, 60; 59, 65; 60, comparison_operator:not; 60, 61; 60, 62; 61, identifier:sample; 62, subscript; 62, 63; 62, 64; 63, identifier:cons; 64, identifier:genome; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:cons; 71, identifier:genome; 72, identifier:sample; 73, dictionary; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:seq; 77, assignment; 77, 78; 77, 85; 78, subscript; 78, 79; 78, 84; 79, subscript; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:cons; 82, identifier:genome; 83, identifier:sample; 84, identifier:contig; 85, list:[]; 86, for_statement; 86, 87; 86, 90; 86, 97; 87, pattern_list; 87, 88; 87, 89; 88, identifier:pos; 89, identifier:ps; 90, call; 90, 91; 90, 92; 91, identifier:enumerate; 92, argument_list; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:stats; 95, string:'bp_stats'; 96, integer:1; 97, block; 97, 98; 97, 112; 97, 125; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, pattern_list; 100, 101; 100, 102; 101, identifier:ref; 102, identifier:consensus; 103, expression_list; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:ps; 106, string:'ref'; 107, subscript; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:ps; 110, string:'consensus'; 111, integer:0; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:==; 113, 114; 113, 115; 114, identifier:consensus; 115, string:'n/a'; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:consensus; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:ref; 123, identifier:lower; 124, argument_list; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:seq; 129, identifier:append; 130, argument_list; 130, 131; 131, identifier:consensus; 132, comment; 133, for_statement; 133, 134; 133, 137; 133, 142; 134, pattern_list; 134, 135; 134, 136; 135, identifier:genome; 136, identifier:samples; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:cons; 140, identifier:items; 141, argument_list; 142, block; 142, 143; 143, for_statement; 143, 144; 143, 147; 143, 152; 144, pattern_list; 144, 145; 144, 146; 145, identifier:sample; 146, identifier:contigs; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:samples; 150, identifier:items; 151, argument_list; 152, block; 152, 153; 152, 161; 152, 169; 152, 203; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:fn; 156, binary_operator:%; 156, 157; 156, 158; 157, string:'%s.%s.consensus.fa'; 158, tuple; 158, 159; 158, 160; 159, identifier:genome; 160, identifier:sample; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:f; 164, call; 164, 165; 164, 166; 165, identifier:open; 166, argument_list; 166, 167; 166, 168; 167, identifier:fn; 168, string:'w'; 169, for_statement; 169, 170; 169, 173; 169, 178; 170, pattern_list; 170, 171; 170, 172; 171, identifier:contig; 172, identifier:seq; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:contigs; 176, identifier:items; 177, argument_list; 178, block; 178, 179; 178, 190; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:print; 182, argument_list; 182, 183; 182, 187; 183, binary_operator:%; 183, 184; 183, 185; 184, string:'>%s'; 185, parenthesized_expression; 185, 186; 186, identifier:contig; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:file; 189, identifier:f; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:print; 193, argument_list; 193, 194; 193, 200; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, string:''; 197, identifier:join; 198, argument_list; 198, 199; 199, identifier:seq; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:file; 202, identifier:f; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:f; 207, identifier:close; 208, argument_list; 209, return_statement; 209, 210; 210, identifier:cons
def print_consensus(genomes): """ print consensensus sequences for each genome and sample """ # generate consensus sequences cons = {} # cons[genome][sample][contig] = consensus for genome, contigs in list(genomes.items()): cons[genome] = {} for contig, samples in list(contigs.items()): for sample, stats in list(samples.items()): if sample not in cons[genome]: cons[genome][sample] = {} seq = cons[genome][sample][contig] = [] for pos, ps in enumerate(stats['bp_stats'], 1): ref, consensus = ps['ref'], ps['consensus'][0] if consensus == 'n/a': consensus = ref.lower() seq.append(consensus) # print consensus sequences for genome, samples in cons.items(): for sample, contigs in samples.items(): fn = '%s.%s.consensus.fa' % (genome, sample) f = open(fn, 'w') for contig, seq in contigs.items(): print('>%s' % (contig), file = f) print(''.join(seq), file = f) f.close() return cons
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse_cov; 3, parameters; 3, 4; 3, 5; 4, identifier:cov_table; 5, identifier:scaffold2genome; 6, block; 6, 7; 6, 9; 6, 13; 6, 14; 6, 18; 6, 19; 6, 20; 6, 190; 6, 191; 6, 207; 6, 267; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:size; 12, dictionary; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:mapped; 17, dictionary; 18, comment; 19, comment; 20, for_statement; 20, 21; 20, 22; 20, 26; 21, identifier:line; 22, call; 22, 23; 22, 24; 23, identifier:open; 24, argument_list; 24, 25; 25, identifier:cov_table; 26, block; 26, 27; 26, 40; 26, 84; 26, 97; 26, 104; 26, 119; 26, 129; 26, 135; 26, 141; 26, 164; 26, 165; 26, 171; 26, 172; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:line; 30, call; 30, 31; 30, 38; 31, attribute; 31, 32; 31, 37; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:line; 35, identifier:strip; 36, argument_list; 37, identifier:split; 38, argument_list; 38, 39; 39, string:'\t'; 40, if_statement; 40, 41; 40, 49; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:line; 45, integer:0; 46, identifier:startswith; 47, argument_list; 47, 48; 48, string:'#'; 49, block; 49, 50; 49, 58; 49, 83; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:samples; 53, subscript; 53, 54; 53, 55; 54, identifier:line; 55, slice; 55, 56; 55, 57; 56, integer:1; 57, colon; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:samples; 61, list_comprehension; 61, 62; 61, 80; 62, subscript; 62, 63; 62, 79; 63, call; 63, 64; 63, 76; 64, attribute; 64, 65; 64, 75; 65, subscript; 65, 66; 65, 73; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:i; 69, identifier:rsplit; 70, argument_list; 70, 71; 70, 72; 71, string:'/'; 72, integer:1; 73, unary_operator:-; 73, 74; 74, integer:1; 75, identifier:split; 76, argument_list; 76, 77; 76, 78; 77, string:'.'; 78, integer:1; 79, integer:0; 80, for_in_clause; 80, 81; 80, 82; 81, identifier:i; 82, identifier:samples; 83, continue_statement; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, pattern_list; 86, 87; 86, 88; 87, identifier:scaffold; 88, identifier:length; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:line; 93, integer:0; 94, identifier:split; 95, argument_list; 95, 96; 96, string:': '; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:length; 100, call; 100, 101; 100, 102; 101, identifier:float; 102, argument_list; 102, 103; 103, identifier:length; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:covs; 107, list_comprehension; 107, 108; 107, 112; 108, call; 108, 109; 108, 110; 109, identifier:float; 110, argument_list; 110, 111; 111, identifier:i; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:i; 114, subscript; 114, 115; 114, 116; 115, identifier:line; 116, slice; 116, 117; 116, 118; 117, integer:1; 118, colon; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:bases; 122, list_comprehension; 122, 123; 122, 126; 123, binary_operator:*; 123, 124; 123, 125; 124, identifier:c; 125, identifier:length; 126, for_in_clause; 126, 127; 126, 128; 127, identifier:c; 128, identifier:covs; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:not; 130, 131; 130, 132; 131, identifier:scaffold; 132, identifier:scaffold2genome; 133, block; 133, 134; 134, continue_statement; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:genome; 138, subscript; 138, 139; 138, 140; 139, identifier:scaffold2genome; 140, identifier:scaffold; 141, if_statement; 141, 142; 141, 145; 142, comparison_operator:not; 142, 143; 142, 144; 143, identifier:genome; 144, identifier:size; 145, block; 145, 146; 145, 152; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:size; 150, identifier:genome; 151, integer:0; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:mapped; 156, identifier:genome; 157, dictionary_comprehension; 157, 158; 157, 161; 158, pair; 158, 159; 158, 160; 159, identifier:sample; 160, integer:0; 161, for_in_clause; 161, 162; 161, 163; 162, identifier:sample; 163, identifier:samples; 164, comment; 165, expression_statement; 165, 166; 166, augmented_assignment:+=; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:size; 169, identifier:genome; 170, identifier:length; 171, comment; 172, for_statement; 172, 173; 172, 176; 172, 181; 173, pattern_list; 173, 174; 173, 175; 174, identifier:sample; 175, identifier:count; 176, call; 176, 177; 176, 178; 177, identifier:zip; 178, argument_list; 178, 179; 178, 180; 179, identifier:samples; 180, identifier:bases; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, augmented_assignment:+=; 183, 184; 183, 189; 184, subscript; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:mapped; 187, identifier:genome; 188, identifier:sample; 189, identifier:count; 190, comment; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:coverage; 194, dictionary; 194, 195; 194, 198; 194, 201; 194, 204; 195, pair; 195, 196; 195, 197; 196, string:'genome'; 197, list:[]; 198, pair; 198, 199; 198, 200; 199, string:'genome size (bp)'; 200, list:[]; 201, pair; 201, 202; 201, 203; 202, string:'sample'; 203, list:[]; 204, pair; 204, 205; 204, 206; 205, string:'coverage'; 206, list:[]; 207, for_statement; 207, 208; 207, 211; 207, 216; 208, pattern_list; 208, 209; 208, 210; 209, identifier:genome; 210, identifier:length; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:size; 214, identifier:items; 215, argument_list; 216, block; 216, 217; 217, for_statement; 217, 218; 217, 219; 217, 220; 218, identifier:sample; 219, identifier:samples; 220, block; 220, 221; 220, 231; 220, 240; 220, 249; 220, 258; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:cov; 224, binary_operator:/; 224, 225; 224, 230; 225, subscript; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:mapped; 228, identifier:genome; 229, identifier:sample; 230, identifier:length; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 238; 233, attribute; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:coverage; 236, string:'genome'; 237, identifier:append; 238, argument_list; 238, 239; 239, identifier:genome; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:coverage; 245, string:'genome size (bp)'; 246, identifier:append; 247, argument_list; 247, 248; 248, identifier:length; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 256; 251, attribute; 251, 252; 251, 255; 252, subscript; 252, 253; 252, 254; 253, identifier:coverage; 254, string:'sample'; 255, identifier:append; 256, argument_list; 256, 257; 257, identifier:sample; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 265; 260, attribute; 260, 261; 260, 264; 261, subscript; 261, 262; 261, 263; 262, identifier:coverage; 263, string:'coverage'; 264, identifier:append; 265, argument_list; 265, 266; 266, identifier:cov; 267, return_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:pd; 271, identifier:DataFrame; 272, argument_list; 272, 273; 273, identifier:coverage
def parse_cov(cov_table, scaffold2genome): """ calculate genome coverage from scaffold coverage table """ size = {} # size[genome] = genome size mapped = {} # mapped[genome][sample] = mapped bases # parse coverage files for line in open(cov_table): line = line.strip().split('\t') if line[0].startswith('#'): samples = line[1:] samples = [i.rsplit('/', 1)[-1].split('.', 1)[0] for i in samples] continue scaffold, length = line[0].split(': ') length = float(length) covs = [float(i) for i in line[1:]] bases = [c * length for c in covs] if scaffold not in scaffold2genome: continue genome = scaffold2genome[scaffold] if genome not in size: size[genome] = 0 mapped[genome] = {sample:0 for sample in samples} # keep track of genome size size[genome] += length # keep track of number of mapped bases for sample, count in zip(samples, bases): mapped[genome][sample] += count # calculate coverage from base counts and genome size coverage = {'genome':[], 'genome size (bp)':[], 'sample':[], 'coverage':[]} for genome, length in size.items(): for sample in samples: cov = mapped[genome][sample] / length coverage['genome'].append(genome) coverage['genome size (bp)'].append(length) coverage['sample'].append(sample) coverage['coverage'].append(cov) return pd.DataFrame(coverage)

No dataset card yet

Downloads last month
9