nodes
stringlengths
501
22.4k
edges
stringlengths
138
5.07k
code
stringlengths
108
19.3k
0, module; 1, function_definition; 2, function_name:_get_paths_for_status; 3, parameters; 4, block; 5, identifier:self; 6, identifier:status; 7, expression_statement; 8, expression_statement; 9, return_statement; 10, comment:""" Returns sorted list of paths for given ``status``. :param status: one of: *added*, *modified* or *deleted* """; 11, assignment; 12, call; 13, pattern_list; 14, attribute; 15, identifier:sorted; 16, argument_list; 17, identifier:added; 18, identifier:modified; 19, identifier:deleted; 20, identifier:self; 21, identifier:_changes_cache; 22, subscript; 23, dictionary; 24, identifier:status; 25, pair; 26, pair; 27, pair; 28, string; 29, call; 30, string; 31, call; 32, string; 33, call; 34, string_content:added; 35, identifier:list; 36, argument_list; 37, string_content:modified; 38, identifier:list; 39, argument_list; 40, string_content:deleted; 41, identifier:list; 42, argument_list; 43, identifier:added; 44, identifier:modified; 45, identifier:deleted
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 9, 12; 11, 13; 11, 14; 12, 15; 12, 16; 13, 17; 13, 18; 13, 19; 14, 20; 14, 21; 16, 22; 22, 23; 22, 24; 23, 25; 23, 26; 23, 27; 25, 28; 25, 29; 26, 30; 26, 31; 27, 32; 27, 33; 28, 34; 29, 35; 29, 36; 30, 37; 31, 38; 31, 39; 32, 40; 33, 41; 33, 42; 36, 43; 39, 44; 42, 45
def _get_paths_for_status(self, status): """ Returns sorted list of paths for given ``status``. :param status: one of: *added*, *modified* or *deleted* """ added, modified, deleted = self._changes_cache return sorted({ 'added': list(added), 'modified': list(modified), 'deleted': list(deleted)}[status] )
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, identifier:args; 12, identifier:kwargs; 13, comment:"""Sort this setlist in place."""; 14, call; 15, pattern_list; 16, call; 17, block; 18, attribute; 19, argument_list; 20, identifier:index; 21, identifier:value; 22, identifier:enumerate; 23, argument_list; 24, expression_statement; 25, attribute; 26, identifier:sort; 27, list_splat; 28, dictionary_splat; 29, attribute; 30, assignment; 31, identifier:self; 32, identifier:_list; 33, identifier:args; 34, identifier:kwargs; 35, identifier:self; 36, identifier:_list; 37, subscript; 38, identifier:index; 39, attribute; 40, identifier:value; 41, identifier:self; 42, identifier:_dict
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 9, 14; 10, 15; 10, 16; 10, 17; 14, 18; 14, 19; 15, 20; 15, 21; 16, 22; 16, 23; 17, 24; 18, 25; 18, 26; 19, 27; 19, 28; 23, 29; 24, 30; 25, 31; 25, 32; 27, 33; 28, 34; 29, 35; 29, 36; 30, 37; 30, 38; 37, 39; 37, 40; 39, 41; 39, 42
def sort(self, *args, **kwargs): """Sort this setlist in place.""" self._list.sort(*args, **kwargs) for index, value in enumerate(self._list): self._dict[value] = index
0, module; 1, function_definition; 2, function_name:find; 3, parameters; 4, block; 5, identifier:self; 6, identifier:term; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, if_statement; 16, return_statement; 17, identifier:limit; 18, integer:0; 19, identifier:sort; 20, False; 21, identifier:ranks; 22, None; 23, comment:""" Searches the stack for cards with a value, suit, name, or abbreviation matching the given argument, 'term'. :arg str term: The search term. Can be a card full name, value, suit, or abbreviation. :arg int limit: The number of items to retrieve for each term. ``0`` equals no limit. :arg bool sort: Whether or not to sort the results. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: A list of stack indices for the cards matching the given terms, if found. """; 24, assignment; 25, assignment; 26, assignment; 27, not_operator; 28, block; 29, else_clause; 30, identifier:sort; 31, block; 32, identifier:found_indices; 33, identifier:ranks; 34, boolean_operator; 35, identifier:found_indices; 36, list; 37, identifier:count; 38, integer:0; 39, identifier:limit; 40, for_statement; 41, block; 42, expression_statement; 43, identifier:ranks; 44, attribute; 45, pattern_list; 46, call; 47, block; 48, for_statement; 49, assignment; 50, identifier:self; 51, identifier:ranks; 52, identifier:i; 53, identifier:card; 54, identifier:enumerate; 55, argument_list; 56, if_statement; 57, pattern_list; 58, call; 59, block; 60, identifier:found_indices; 61, call; 62, attribute; 63, call; 64, block; 65, identifier:i; 66, identifier:card; 67, identifier:enumerate; 68, argument_list; 69, if_statement; 70, identifier:sort_card_indices; 71, argument_list; 72, identifier:self; 73, identifier:cards; 74, identifier:check_term; 75, argument_list; 76, expression_statement; 77, attribute; 78, comparison_operator:count < limit; 79, block; 80, else_clause; 81, identifier:self; 82, identifier:found_indices; 83, identifier:ranks; 84, identifier:card; 85, identifier:term; 86, call; 87, identifier:self; 88, identifier:cards; 89, identifier:count; 90, identifier:limit; 91, if_statement; 92, block; 93, attribute; 94, argument_list; 95, call; 96, block; 97, break_statement; 98, identifier:found_indices; 99, identifier:append; 100, identifier:i; 101, identifier:check_term; 102, argument_list; 103, expression_statement; 104, expression_statement; 105, identifier:card; 106, identifier:term; 107, call; 108, augmented_assignment; 109, attribute; 110, argument_list; 111, identifier:count; 112, integer:1; 113, identifier:found_indices; 114, identifier:append; 115, identifier:i
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 11, 24; 12, 25; 13, 26; 14, 27; 14, 28; 14, 29; 15, 30; 15, 31; 16, 32; 24, 33; 24, 34; 25, 35; 25, 36; 26, 37; 26, 38; 27, 39; 28, 40; 29, 41; 31, 42; 34, 43; 34, 44; 40, 45; 40, 46; 40, 47; 41, 48; 42, 49; 44, 50; 44, 51; 45, 52; 45, 53; 46, 54; 46, 55; 47, 56; 48, 57; 48, 58; 48, 59; 49, 60; 49, 61; 55, 62; 56, 63; 56, 64; 57, 65; 57, 66; 58, 67; 58, 68; 59, 69; 61, 70; 61, 71; 62, 72; 62, 73; 63, 74; 63, 75; 64, 76; 68, 77; 69, 78; 69, 79; 69, 80; 71, 81; 71, 82; 71, 83; 75, 84; 75, 85; 76, 86; 77, 87; 77, 88; 78, 89; 78, 90; 79, 91; 80, 92; 86, 93; 86, 94; 91, 95; 91, 96; 92, 97; 93, 98; 93, 99; 94, 100; 95, 101; 95, 102; 96, 103; 96, 104; 102, 105; 102, 106; 103, 107; 104, 108; 107, 109; 107, 110; 108, 111; 108, 112; 109, 113; 109, 114; 110, 115
def find(self, term, limit=0, sort=False, ranks=None): """ Searches the stack for cards with a value, suit, name, or abbreviation matching the given argument, 'term'. :arg str term: The search term. Can be a card full name, value, suit, or abbreviation. :arg int limit: The number of items to retrieve for each term. ``0`` equals no limit. :arg bool sort: Whether or not to sort the results. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: A list of stack indices for the cards matching the given terms, if found. """ ranks = ranks or self.ranks found_indices = [] count = 0 if not limit: for i, card in enumerate(self.cards): if check_term(card, term): found_indices.append(i) else: for i, card in enumerate(self.cards): if count < limit: if check_term(card, term): found_indices.append(i) count += 1 else: break if sort: found_indices = sort_card_indices(self, found_indices, ranks) return found_indices
0, module; 1, function_definition; 2, function_name:get_list; 3, parameters; 4, block; 5, identifier:self; 6, identifier:terms; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, try_statement; 14, if_statement; 15, return_statement; 16, identifier:limit; 17, integer:0; 18, identifier:sort; 19, False; 20, identifier:ranks; 21, None; 22, comment:""" Get the specified cards from the stack. :arg term: The search term. Can be a card full name, value, suit, abbreviation, or stack indice. :arg int limit: The number of items to retrieve for each term. :arg bool sort: Whether or not to sort the results, by poker ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: A list of the specified cards, if found. """; 23, assignment; 24, assignment; 25, block; 26, except_clause; 27, identifier:sort; 28, block; 29, identifier:got_cards; 30, identifier:ranks; 31, boolean_operator; 32, identifier:got_cards; 33, list; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, block; 38, expression_statement; 39, identifier:ranks; 40, attribute; 41, assignment; 42, assignment; 43, assignment; 44, expression_statement; 45, for_statement; 46, expression_statement; 47, assignment; 48, identifier:self; 49, identifier:ranks; 50, identifier:indices; 51, call; 52, identifier:got_cards; 53, list_comprehension; 54, attribute; 55, list_comprehension; 56, assignment; 57, identifier:item; 58, identifier:terms; 59, block; 60, assignment; 61, identifier:got_cards; 62, call; 63, attribute; 64, argument_list; 65, subscript; 66, for_in_clause; 67, if_clause; 68, identifier:self; 69, identifier:cards; 70, identifier:v; 71, for_in_clause; 72, if_clause; 73, identifier:indices; 74, list; 75, try_statement; 76, attribute; 77, list_comprehension; 78, identifier:sort_cards; 79, argument_list; 80, identifier:self; 81, identifier:find_list; 82, identifier:terms; 83, keyword_argument; 84, attribute; 85, identifier:i; 86, identifier:i; 87, identifier:indices; 88, comparison_operator:self.cards[i] not in got_cards; 89, pattern_list; 90, call; 91, comparison_operator:i not in indices; 92, block; 93, except_clause; 94, identifier:self; 95, identifier:cards; 96, identifier:v; 97, for_in_clause; 98, if_clause; 99, identifier:got_cards; 100, identifier:ranks; 101, identifier:limit; 102, identifier:limit; 103, identifier:self; 104, identifier:cards; 105, subscript; 106, identifier:got_cards; 107, identifier:i; 108, identifier:v; 109, identifier:enumerate; 110, argument_list; 111, identifier:i; 112, identifier:indices; 113, expression_statement; 114, if_statement; 115, block; 116, pattern_list; 117, call; 118, comparison_operator:i not in indices; 119, attribute; 120, identifier:i; 121, attribute; 122, assignment; 123, comparison_operator:card not in got_cards; 124, block; 125, expression_statement; 126, expression_statement; 127, identifier:i; 128, identifier:v; 129, identifier:enumerate; 130, argument_list; 131, identifier:i; 132, identifier:indices; 133, identifier:self; 134, identifier:cards; 135, identifier:self; 136, identifier:cards; 137, identifier:card; 138, subscript; 139, identifier:card; 140, identifier:got_cards; 141, expression_statement; 142, expression_statement; 143, augmented_assignment; 144, augmented_assignment; 145, attribute; 146, attribute; 147, identifier:item; 148, call; 149, call; 150, identifier:indices; 151, call; 152, identifier:got_cards; 153, list_comprehension; 154, identifier:self; 155, identifier:cards; 156, identifier:self; 157, identifier:cards; 158, attribute; 159, argument_list; 160, attribute; 161, argument_list; 162, attribute; 163, argument_list; 164, subscript; 165, for_in_clause; 166, if_clause; 167, identifier:got_cards; 168, identifier:append; 169, identifier:card; 170, identifier:indices; 171, identifier:append; 172, identifier:item; 173, identifier:self; 174, identifier:find; 175, identifier:item; 176, keyword_argument; 177, attribute; 178, identifier:i; 179, identifier:i; 180, identifier:indices; 181, comparison_operator:self.cards[i] not in got_cards; 182, identifier:limit; 183, identifier:limit; 184, identifier:self; 185, identifier:cards; 186, subscript; 187, identifier:got_cards; 188, attribute; 189, identifier:i; 190, identifier:self; 191, identifier:cards
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 7, 17; 8, 18; 8, 19; 9, 20; 9, 21; 10, 22; 11, 23; 12, 24; 13, 25; 13, 26; 14, 27; 14, 28; 15, 29; 23, 30; 23, 31; 24, 32; 24, 33; 25, 34; 25, 35; 25, 36; 26, 37; 28, 38; 31, 39; 31, 40; 34, 41; 35, 42; 36, 43; 37, 44; 37, 45; 37, 46; 38, 47; 40, 48; 40, 49; 41, 50; 41, 51; 42, 52; 42, 53; 43, 54; 43, 55; 44, 56; 45, 57; 45, 58; 45, 59; 46, 60; 47, 61; 47, 62; 51, 63; 51, 64; 53, 65; 53, 66; 53, 67; 54, 68; 54, 69; 55, 70; 55, 71; 55, 72; 56, 73; 56, 74; 59, 75; 60, 76; 60, 77; 62, 78; 62, 79; 63, 80; 63, 81; 64, 82; 64, 83; 65, 84; 65, 85; 66, 86; 66, 87; 67, 88; 71, 89; 71, 90; 72, 91; 75, 92; 75, 93; 76, 94; 76, 95; 77, 96; 77, 97; 77, 98; 79, 99; 79, 100; 83, 101; 83, 102; 84, 103; 84, 104; 88, 105; 88, 106; 89, 107; 89, 108; 90, 109; 90, 110; 91, 111; 91, 112; 92, 113; 92, 114; 93, 115; 97, 116; 97, 117; 98, 118; 105, 119; 105, 120; 110, 121; 113, 122; 114, 123; 114, 124; 115, 125; 115, 126; 116, 127; 116, 128; 117, 129; 117, 130; 118, 131; 118, 132; 119, 133; 119, 134; 121, 135; 121, 136; 122, 137; 122, 138; 123, 139; 123, 140; 124, 141; 124, 142; 125, 143; 126, 144; 130, 145; 138, 146; 138, 147; 141, 148; 142, 149; 143, 150; 143, 151; 144, 152; 144, 153; 145, 154; 145, 155; 146, 156; 146, 157; 148, 158; 148, 159; 149, 160; 149, 161; 151, 162; 151, 163; 153, 164; 153, 165; 153, 166; 158, 167; 158, 168; 159, 169; 160, 170; 160, 171; 161, 172; 162, 173; 162, 174; 163, 175; 163, 176; 164, 177; 164, 178; 165, 179; 165, 180; 166, 181; 176, 182; 176, 183; 177, 184; 177, 185; 181, 186; 181, 187; 186, 188; 186, 189; 188, 190; 188, 191
def get_list(self, terms, limit=0, sort=False, ranks=None): """ Get the specified cards from the stack. :arg term: The search term. Can be a card full name, value, suit, abbreviation, or stack indice. :arg int limit: The number of items to retrieve for each term. :arg bool sort: Whether or not to sort the results, by poker ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: A list of the specified cards, if found. """ ranks = ranks or self.ranks got_cards = [] try: indices = self.find_list(terms, limit=limit) got_cards = [self.cards[i] for i in indices if self.cards[i] not in got_cards] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] except: indices = [] for item in terms: try: card = self.cards[item] if card not in got_cards: got_cards.append(card) indices.append(item) except: indices += self.find(item, limit=limit) got_cards += [self.cards[i] for i in indices if self.cards[i] not in got_cards] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] if sort: got_cards = sort_cards(got_cards, ranks) return got_cards
0, module; 1, function_definition; 2, function_name:is_sorted; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, return_statement; 10, identifier:ranks; 11, None; 12, comment:""" Checks whether the stack is sorted. :arg dict ranks: The rank dict to reference for checking. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: Whether or not the cards are sorted. """; 13, assignment; 14, call; 15, identifier:ranks; 16, boolean_operator; 17, identifier:check_sorted; 18, argument_list; 19, identifier:ranks; 20, attribute; 21, identifier:self; 22, identifier:ranks; 23, identifier:self; 24, identifier:ranks
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 8, 13; 9, 14; 13, 15; 13, 16; 14, 17; 14, 18; 16, 19; 16, 20; 18, 21; 18, 22; 20, 23; 20, 24
def is_sorted(self, ranks=None): """ Checks whether the stack is sorted. :arg dict ranks: The rank dict to reference for checking. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: Whether or not the cards are sorted. """ ranks = ranks or self.ranks return check_sorted(self, ranks)
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, identifier:ranks; 11, None; 12, comment:""" Sorts the stack, either by poker ranks, or big two ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted cards. """; 13, assignment; 14, assignment; 15, identifier:ranks; 16, boolean_operator; 17, attribute; 18, call; 19, identifier:ranks; 20, attribute; 21, identifier:self; 22, identifier:cards; 23, identifier:sort_cards; 24, argument_list; 25, identifier:self; 26, identifier:ranks; 27, attribute; 28, identifier:ranks; 29, identifier:self; 30, identifier:cards
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 8, 13; 9, 14; 13, 15; 13, 16; 14, 17; 14, 18; 16, 19; 16, 20; 17, 21; 17, 22; 18, 23; 18, 24; 20, 25; 20, 26; 24, 27; 24, 28; 27, 29; 27, 30
def sort(self, ranks=None): """ Sorts the stack, either by poker ranks, or big two ranks. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted cards. """ ranks = ranks or self.ranks self.cards = sort_cards(self.cards, ranks)
0, module; 1, function_definition; 2, function_name:canonical_headers; 3, parameters; 4, block; 5, identifier:self; 6, identifier:headers_to_sign; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:""" Return the headers that need to be included in the StringToSign in their canonical form by converting all header keys to lower case, sorting them in alphabetical order and then joining them into a string, separated by newlines. """; 12, assignment; 13, call; 14, call; 15, identifier:l; 16, list_comprehension; 17, attribute; 18, argument_list; 19, attribute; 20, argument_list; 21, binary_operator:'%s:%s'%(n.lower().strip(), headers_to_sign[n].strip()); 22, for_in_clause; 23, identifier:l; 24, identifier:sort; 25, string; 26, identifier:join; 27, identifier:l; 28, string; 29, tuple; 30, identifier:n; 31, identifier:headers_to_sign; 32, string_content; 33, string_content:%s:%s; 34, call; 35, call; 36, escape_sequence:\n; 37, attribute; 38, argument_list; 39, attribute; 40, argument_list; 41, call; 42, identifier:strip; 43, subscript; 44, identifier:strip; 45, attribute; 46, argument_list; 47, identifier:headers_to_sign; 48, identifier:n; 49, identifier:n; 50, identifier:lower
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 10, 14; 12, 15; 12, 16; 13, 17; 13, 18; 14, 19; 14, 20; 16, 21; 16, 22; 17, 23; 17, 24; 19, 25; 19, 26; 20, 27; 21, 28; 21, 29; 22, 30; 22, 31; 25, 32; 28, 33; 29, 34; 29, 35; 32, 36; 34, 37; 34, 38; 35, 39; 35, 40; 37, 41; 37, 42; 39, 43; 39, 44; 41, 45; 41, 46; 43, 47; 43, 48; 45, 49; 45, 50
def canonical_headers(self, headers_to_sign): """ Return the headers that need to be included in the StringToSign in their canonical form by converting all header keys to lower case, sorting them in alphabetical order and then joining them into a string, separated by newlines. """ l = ['%s:%s'%(n.lower().strip(), headers_to_sign[n].strip()) for n in headers_to_sign] l.sort() return '\n'.join(l)
0, module; 1, function_definition; 2, function_name:build_cards; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, return_statement; 12, identifier:jokers; 13, False; 14, identifier:num_jokers; 15, integer:0; 16, comment:""" Builds a list containing a full French deck of 52 Card instances. The cards are sorted according to ``DEFAULT_RANKS``. .. note: Adding jokers may break some functions & methods at the moment. :arg bool jokers: Whether or not to include jokers in the deck. :arg int num_jokers: The number of jokers to include. :returns: A list containing a full French deck of 52 Card instances. """; 17, assignment; 18, identifier:jokers; 19, block; 20, augmented_assignment; 21, identifier:new_deck; 22, identifier:new_deck; 23, list; 24, expression_statement; 25, identifier:new_deck; 26, list_comprehension; 27, augmented_assignment; 28, call; 29, for_in_clause; 30, for_in_clause; 31, identifier:new_deck; 32, list_comprehension; 33, identifier:Card; 34, argument_list; 35, identifier:value; 36, identifier:VALUES; 37, identifier:suit; 38, identifier:SUITS; 39, call; 40, for_in_clause; 41, identifier:value; 42, identifier:suit; 43, identifier:Card; 44, argument_list; 45, identifier:i; 46, call; 47, string:"Joker"; 48, None; 49, identifier:xrange; 50, argument_list; 51, identifier:num_jokers
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 5, 12; 5, 13; 6, 14; 6, 15; 7, 16; 8, 17; 9, 18; 9, 19; 10, 20; 11, 21; 17, 22; 17, 23; 19, 24; 20, 25; 20, 26; 24, 27; 26, 28; 26, 29; 26, 30; 27, 31; 27, 32; 28, 33; 28, 34; 29, 35; 29, 36; 30, 37; 30, 38; 32, 39; 32, 40; 34, 41; 34, 42; 39, 43; 39, 44; 40, 45; 40, 46; 44, 47; 44, 48; 46, 49; 46, 50; 50, 51
def build_cards(jokers=False, num_jokers=0): """ Builds a list containing a full French deck of 52 Card instances. The cards are sorted according to ``DEFAULT_RANKS``. .. note: Adding jokers may break some functions & methods at the moment. :arg bool jokers: Whether or not to include jokers in the deck. :arg int num_jokers: The number of jokers to include. :returns: A list containing a full French deck of 52 Card instances. """ new_deck = [] if jokers: new_deck += [Card("Joker", None) for i in xrange(num_jokers)] new_deck += [Card(value, suit) for value in VALUES for suit in SUITS] return new_deck
0, module; 1, function_definition; 2, function_name:check_sorted; 3, parameters; 4, block; 5, identifier:cards; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, identifier:ranks; 12, None; 13, comment:""" Checks whether the given cards are sorted by the given ranks. :arg cards: The cards to check. Can be a ``Stack``, ``Deck``, or ``list`` of ``Card`` isntances. :arg dict ranks: The ranks to check against. Default is DEFAULT_RANKS. :returns: ``True`` or ``False``. """; 14, assignment; 15, assignment; 16, boolean_operator; 17, block; 18, else_clause; 19, identifier:ranks; 20, boolean_operator; 21, identifier:sorted_cards; 22, call; 23, comparison_operator:cards == sorted_cards; 24, comparison_operator:cards[::-1] == sorted_cards; 25, return_statement; 26, block; 27, identifier:ranks; 28, identifier:DEFAULT_RANKS; 29, identifier:sort_cards; 30, argument_list; 31, identifier:cards; 32, identifier:sorted_cards; 33, subscript; 34, identifier:sorted_cards; 35, True; 36, return_statement; 37, identifier:cards; 38, identifier:ranks; 39, identifier:cards; 40, slice; 41, False; 42, unary_operator; 43, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 6, 12; 7, 13; 8, 14; 9, 15; 10, 16; 10, 17; 10, 18; 14, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 18, 26; 20, 27; 20, 28; 22, 29; 22, 30; 23, 31; 23, 32; 24, 33; 24, 34; 25, 35; 26, 36; 30, 37; 30, 38; 33, 39; 33, 40; 36, 41; 40, 42; 42, 43
def check_sorted(cards, ranks=None): """ Checks whether the given cards are sorted by the given ranks. :arg cards: The cards to check. Can be a ``Stack``, ``Deck``, or ``list`` of ``Card`` isntances. :arg dict ranks: The ranks to check against. Default is DEFAULT_RANKS. :returns: ``True`` or ``False``. """ ranks = ranks or DEFAULT_RANKS sorted_cards = sort_cards(cards, ranks) if cards == sorted_cards or cards[::-1] == sorted_cards: return True else: return False
0, module; 1, function_definition; 2, function_name:sort_card_indices; 3, parameters; 4, block; 5, identifier:cards; 6, identifier:indices; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, identifier:ranks; 14, None; 15, comment:""" Sorts the given Deck indices by the given ranks. Must also supply the ``Stack``, ``Deck``, or ``list`` that the indices are from. :arg cards: The cards the indices are from. Can be a ``Stack``, ``Deck``, or ``list`` :arg list indices: The indices to sort. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted indices. """; 16, assignment; 17, call; 18, block; 19, call; 20, block; 21, identifier:indices; 22, identifier:ranks; 23, boolean_operator; 24, attribute; 25, argument_list; 26, expression_statement; 27, attribute; 28, argument_list; 29, expression_statement; 30, identifier:ranks; 31, identifier:DEFAULT_RANKS; 32, identifier:ranks; 33, identifier:get; 34, string:"suits"; 35, assignment; 36, identifier:ranks; 37, identifier:get; 38, string:"values"; 39, assignment; 40, identifier:indices; 41, call; 42, identifier:indices; 43, call; 44, identifier:sorted; 45, argument_list; 46, identifier:sorted; 47, argument_list; 48, identifier:indices; 49, keyword_argument; 50, identifier:indices; 51, keyword_argument; 52, identifier:key; 53, lambda; 54, identifier:key; 55, lambda; 56, lambda_parameters; 57, conditional_expression:ranks["suits"][cards[x].suit] if cards[x].suit != None else 0; 58, lambda_parameters; 59, subscript; 60, identifier:x; 61, subscript; 62, comparison_operator:cards[x].suit != None; 63, integer:0; 64, identifier:x; 65, subscript; 66, attribute; 67, subscript; 68, attribute; 69, attribute; 70, None; 71, identifier:ranks; 72, string:"values"; 73, subscript; 74, identifier:value; 75, identifier:ranks; 76, string:"suits"; 77, subscript; 78, identifier:suit; 79, subscript; 80, identifier:suit; 81, identifier:cards; 82, identifier:x; 83, identifier:cards; 84, identifier:x; 85, identifier:cards; 86, identifier:x
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 7, 14; 8, 15; 9, 16; 10, 17; 10, 18; 11, 19; 11, 20; 12, 21; 16, 22; 16, 23; 17, 24; 17, 25; 18, 26; 19, 27; 19, 28; 20, 29; 23, 30; 23, 31; 24, 32; 24, 33; 25, 34; 26, 35; 27, 36; 27, 37; 28, 38; 29, 39; 35, 40; 35, 41; 39, 42; 39, 43; 41, 44; 41, 45; 43, 46; 43, 47; 45, 48; 45, 49; 47, 50; 47, 51; 49, 52; 49, 53; 51, 54; 51, 55; 53, 56; 53, 57; 55, 58; 55, 59; 56, 60; 57, 61; 57, 62; 57, 63; 58, 64; 59, 65; 59, 66; 61, 67; 61, 68; 62, 69; 62, 70; 65, 71; 65, 72; 66, 73; 66, 74; 67, 75; 67, 76; 68, 77; 68, 78; 69, 79; 69, 80; 73, 81; 73, 82; 77, 83; 77, 84; 79, 85; 79, 86
def sort_card_indices(cards, indices, ranks=None): """ Sorts the given Deck indices by the given ranks. Must also supply the ``Stack``, ``Deck``, or ``list`` that the indices are from. :arg cards: The cards the indices are from. Can be a ``Stack``, ``Deck``, or ``list`` :arg list indices: The indices to sort. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted indices. """ ranks = ranks or DEFAULT_RANKS if ranks.get("suits"): indices = sorted( indices, key=lambda x: ranks["suits"][cards[x].suit] if cards[x].suit != None else 0 ) if ranks.get("values"): indices = sorted( indices, key=lambda x: ranks["values"][cards[x].value] ) return indices
0, module; 1, function_definition; 2, function_name:sort_cards; 3, parameters; 4, block; 5, identifier:cards; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, return_statement; 12, identifier:ranks; 13, None; 14, comment:""" Sorts a given list of cards, either by poker ranks, or big two ranks. :arg cards: The cards to sort. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted cards. """; 15, assignment; 16, call; 17, block; 18, call; 19, block; 20, identifier:cards; 21, identifier:ranks; 22, boolean_operator; 23, attribute; 24, argument_list; 25, expression_statement; 26, attribute; 27, argument_list; 28, expression_statement; 29, identifier:ranks; 30, identifier:DEFAULT_RANKS; 31, identifier:ranks; 32, identifier:get; 33, string:"suits"; 34, assignment; 35, identifier:ranks; 36, identifier:get; 37, string:"values"; 38, assignment; 39, identifier:cards; 40, call; 41, identifier:cards; 42, call; 43, identifier:sorted; 44, argument_list; 45, identifier:sorted; 46, argument_list; 47, identifier:cards; 48, keyword_argument; 49, identifier:cards; 50, keyword_argument; 51, identifier:key; 52, lambda; 53, identifier:key; 54, lambda; 55, lambda_parameters; 56, conditional_expression:ranks["suits"][x.suit] if x.suit != None else 0; 57, lambda_parameters; 58, subscript; 59, identifier:x; 60, subscript; 61, comparison_operator:x.suit != None; 62, integer:0; 63, identifier:x; 64, subscript; 65, attribute; 66, subscript; 67, attribute; 68, attribute; 69, None; 70, identifier:ranks; 71, string:"values"; 72, identifier:x; 73, identifier:value; 74, identifier:ranks; 75, string:"suits"; 76, identifier:x; 77, identifier:suit; 78, identifier:x; 79, identifier:suit
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 8, 15; 9, 16; 9, 17; 10, 18; 10, 19; 11, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 18, 26; 18, 27; 19, 28; 22, 29; 22, 30; 23, 31; 23, 32; 24, 33; 25, 34; 26, 35; 26, 36; 27, 37; 28, 38; 34, 39; 34, 40; 38, 41; 38, 42; 40, 43; 40, 44; 42, 45; 42, 46; 44, 47; 44, 48; 46, 49; 46, 50; 48, 51; 48, 52; 50, 53; 50, 54; 52, 55; 52, 56; 54, 57; 54, 58; 55, 59; 56, 60; 56, 61; 56, 62; 57, 63; 58, 64; 58, 65; 60, 66; 60, 67; 61, 68; 61, 69; 64, 70; 64, 71; 65, 72; 65, 73; 66, 74; 66, 75; 67, 76; 67, 77; 68, 78; 68, 79
def sort_cards(cards, ranks=None): """ Sorts a given list of cards, either by poker ranks, or big two ranks. :arg cards: The cards to sort. :arg dict ranks: The rank dict to reference for sorting. If ``None``, it will default to ``DEFAULT_RANKS``. :returns: The sorted cards. """ ranks = ranks or DEFAULT_RANKS if ranks.get("suits"): cards = sorted( cards, key=lambda x: ranks["suits"][x.suit] if x.suit != None else 0 ) if ranks.get("values"): cards = sorted( cards, key=lambda x: ranks["values"][x.value] ) return cards
0, module; 1, function_definition; 2, function_name:key; 3, parameters; 4, block; 5, identifier:self; 6, identifier:frame; 7, expression_statement; 8, function_definition; 9, comment:# Look up frame by exact match; 10, if_statement; 11, comment:# Look up parent frame for v2.2 frames; 12, if_statement; 13, comment:# Try each pattern; 14, for_statement; 15, return_statement; 16, string:"Return the sort key for the given frame."; 17, function_name:keytuple; 18, parameters; 19, block; 20, comparison_operator:type(frame) in self.frame_keys; 21, block; 22, boolean_operator; 23, block; 24, tuple_pattern; 25, attribute; 26, block; 27, call; 28, identifier:primary; 29, if_statement; 30, return_statement; 31, call; 32, attribute; 33, return_statement; 34, call; 35, comparison_operator:type(frame).__bases__[0] in self.frame_keys; 36, return_statement; 37, identifier:pattern; 38, identifier:key; 39, identifier:self; 40, identifier:re_keys; 41, if_statement; 42, identifier:keytuple; 43, argument_list; 44, comparison_operator:frame.frameno is None; 45, block; 46, tuple; 47, identifier:type; 48, argument_list; 49, identifier:self; 50, identifier:frame_keys; 51, call; 52, attribute; 53, argument_list; 54, subscript; 55, attribute; 56, call; 57, call; 58, block; 59, attribute; 60, attribute; 61, None; 62, return_statement; 63, identifier:primary; 64, integer:0; 65, attribute; 66, identifier:frame; 67, identifier:keytuple; 68, argument_list; 69, identifier:frame; 70, identifier:_in_version; 71, integer:2; 72, attribute; 73, integer:0; 74, identifier:self; 75, identifier:frame_keys; 76, identifier:keytuple; 77, argument_list; 78, attribute; 79, argument_list; 80, return_statement; 81, identifier:self; 82, identifier:unknown_key; 83, identifier:frame; 84, identifier:frameno; 85, tuple; 86, identifier:frame; 87, identifier:frameno; 88, subscript; 89, call; 90, identifier:__bases__; 91, subscript; 92, identifier:re; 93, identifier:match; 94, identifier:pattern; 95, attribute; 96, call; 97, identifier:primary; 98, integer:1; 99, attribute; 100, call; 101, identifier:type; 102, argument_list; 103, attribute; 104, subscript; 105, identifier:frame; 106, identifier:frameid; 107, identifier:keytuple; 108, argument_list; 109, identifier:self; 110, identifier:frame_keys; 111, identifier:type; 112, argument_list; 113, identifier:frame; 114, identifier:self; 115, identifier:frame_keys; 116, attribute; 117, integer:0; 118, identifier:key; 119, identifier:frame; 120, call; 121, identifier:__bases__; 122, identifier:type; 123, argument_list; 124, identifier:frame
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 7, 16; 8, 17; 8, 18; 8, 19; 10, 20; 10, 21; 12, 22; 12, 23; 14, 24; 14, 25; 14, 26; 15, 27; 18, 28; 19, 29; 19, 30; 20, 31; 20, 32; 21, 33; 22, 34; 22, 35; 23, 36; 24, 37; 24, 38; 25, 39; 25, 40; 26, 41; 27, 42; 27, 43; 29, 44; 29, 45; 30, 46; 31, 47; 31, 48; 32, 49; 32, 50; 33, 51; 34, 52; 34, 53; 35, 54; 35, 55; 36, 56; 41, 57; 41, 58; 43, 59; 44, 60; 44, 61; 45, 62; 46, 63; 46, 64; 46, 65; 48, 66; 51, 67; 51, 68; 52, 69; 52, 70; 53, 71; 54, 72; 54, 73; 55, 74; 55, 75; 56, 76; 56, 77; 57, 78; 57, 79; 58, 80; 59, 81; 59, 82; 60, 83; 60, 84; 62, 85; 65, 86; 65, 87; 68, 88; 72, 89; 72, 90; 77, 91; 78, 92; 78, 93; 79, 94; 79, 95; 80, 96; 85, 97; 85, 98; 88, 99; 88, 100; 89, 101; 89, 102; 91, 103; 91, 104; 95, 105; 95, 106; 96, 107; 96, 108; 99, 109; 99, 110; 100, 111; 100, 112; 102, 113; 103, 114; 103, 115; 104, 116; 104, 117; 108, 118; 112, 119; 116, 120; 116, 121; 120, 122; 120, 123; 123, 124
def key(self, frame): "Return the sort key for the given frame." def keytuple(primary): if frame.frameno is None: return (primary, 1) return (primary, 0, frame.frameno) # Look up frame by exact match if type(frame) in self.frame_keys: return keytuple(self.frame_keys[type(frame)]) # Look up parent frame for v2.2 frames if frame._in_version(2) and type(frame).__bases__[0] in self.frame_keys: return keytuple(self.frame_keys[type(frame).__bases__[0]]) # Try each pattern for (pattern, key) in self.re_keys: if re.match(pattern, frame.frameid): return keytuple(key) return keytuple(self.unknown_key)
0, module; 1, function_definition; 2, function_name:frames; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, for_statement; 12, if_statement; 13, expression_statement; 14, return_statement; 15, identifier:key; 16, None; 17, identifier:orig_order; 18, False; 19, comment:"""Returns a list of frames in this tag. If KEY is None, returns all frames in the tag; otherwise returns all frames whose frameid matches KEY. If ORIG_ORDER is True, then the frames are returned in their original order. Otherwise the frames are sorted in canonical order according to the frame_order field of this tag. """; 20, comparison_operator:key is not None; 21, comment:# If there are multiple frames, then they are already in original order.; 22, block; 23, assignment; 24, identifier:frameid; 25, call; 26, block; 27, identifier:orig_order; 28, block; 29, else_clause; 30, call; 31, identifier:frames; 32, identifier:key; 33, None; 34, expression_statement; 35, if_statement; 36, return_statement; 37, identifier:frames; 38, list; 39, attribute; 40, argument_list; 41, for_statement; 42, expression_statement; 43, block; 44, attribute; 45, argument_list; 46, assignment; 47, comparison_operator:len(self._frames[key]) == 0; 48, block; 49, subscript; 50, attribute; 51, identifier:keys; 52, identifier:frame; 53, subscript; 54, block; 55, assignment; 56, expression_statement; 57, identifier:frames; 58, identifier:sort; 59, keyword_argument; 60, identifier:key; 61, call; 62, call; 63, integer:0; 64, raise_statement; 65, attribute; 66, identifier:key; 67, identifier:self; 68, identifier:_frames; 69, attribute; 70, identifier:frameid; 71, expression_statement; 72, identifier:key; 73, parenthesized_expression; 74, assignment; 75, identifier:key; 76, identifier:key; 77, attribute; 78, argument_list; 79, identifier:len; 80, argument_list; 81, call; 82, identifier:self; 83, identifier:_frames; 84, identifier:self; 85, identifier:_frames; 86, call; 87, lambda; 88, identifier:key; 89, attribute; 90, identifier:self; 91, identifier:_normalize_key; 92, identifier:key; 93, subscript; 94, identifier:KeyError; 95, argument_list; 96, attribute; 97, argument_list; 98, lambda_parameters; 99, conditional_expression:(0, frame.frameno) if frame.frameno is not None else (1,); 100, attribute; 101, identifier:key; 102, attribute; 103, identifier:key; 104, binary_operator:"Key not found: " + repr(key); 105, identifier:frames; 106, identifier:append; 107, identifier:frame; 108, identifier:frame; 109, tuple; 110, comparison_operator:frame.frameno is not None; 111, tuple; 112, identifier:self; 113, identifier:frame_order; 114, identifier:self; 115, identifier:_frames; 116, string:"Key not found: "; 117, call; 118, integer:0; 119, attribute; 120, attribute; 121, None; 122, integer:1; 123, identifier:repr; 124, argument_list; 125, identifier:frame; 126, identifier:frameno; 127, identifier:frame; 128, identifier:frameno; 129, identifier:key
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 6, 16; 7, 17; 7, 18; 8, 19; 9, 20; 9, 21; 9, 22; 10, 23; 11, 24; 11, 25; 11, 26; 12, 27; 12, 28; 12, 29; 13, 30; 14, 31; 20, 32; 20, 33; 22, 34; 22, 35; 22, 36; 23, 37; 23, 38; 25, 39; 25, 40; 26, 41; 28, 42; 29, 43; 30, 44; 30, 45; 34, 46; 35, 47; 35, 48; 36, 49; 39, 50; 39, 51; 41, 52; 41, 53; 41, 54; 42, 55; 43, 56; 44, 57; 44, 58; 45, 59; 46, 60; 46, 61; 47, 62; 47, 63; 48, 64; 49, 65; 49, 66; 50, 67; 50, 68; 53, 69; 53, 70; 54, 71; 55, 72; 55, 73; 56, 74; 59, 75; 59, 76; 61, 77; 61, 78; 62, 79; 62, 80; 64, 81; 65, 82; 65, 83; 69, 84; 69, 85; 71, 86; 73, 87; 74, 88; 74, 89; 77, 90; 77, 91; 78, 92; 80, 93; 81, 94; 81, 95; 86, 96; 86, 97; 87, 98; 87, 99; 89, 100; 89, 101; 93, 102; 93, 103; 95, 104; 96, 105; 96, 106; 97, 107; 98, 108; 99, 109; 99, 110; 99, 111; 100, 112; 100, 113; 102, 114; 102, 115; 104, 116; 104, 117; 109, 118; 109, 119; 110, 120; 110, 121; 111, 122; 117, 123; 117, 124; 119, 125; 119, 126; 120, 127; 120, 128; 124, 129
def frames(self, key=None, orig_order=False): """Returns a list of frames in this tag. If KEY is None, returns all frames in the tag; otherwise returns all frames whose frameid matches KEY. If ORIG_ORDER is True, then the frames are returned in their original order. Otherwise the frames are sorted in canonical order according to the frame_order field of this tag. """ if key is not None: # If there are multiple frames, then they are already in original order. key = self._normalize_key(key) if len(self._frames[key]) == 0: raise KeyError("Key not found: " + repr(key)) return self._frames[key] frames = [] for frameid in self._frames.keys(): for frame in self._frames[frameid]: frames.append(frame) if orig_order: key = (lambda frame: (0, frame.frameno) if frame.frameno is not None else (1,)) else: key = self.frame_order.key frames.sort(key=key) return frames
0, module; 1, function_definition; 2, function_name:detach; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:force; 14, False; 15, comment:""" Detach this EBS volume from an EC2 instance. :type force: bool :param force: Forces detachment if the previous detachment attempt did not occur cleanly. This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures. :rtype: bool :return: True if successful """; 16, assignment; 17, attribute; 18, block; 19, assignment; 20, attribute; 21, block; 22, call; 23, identifier:instance_id; 24, None; 25, identifier:self; 26, identifier:attach_data; 27, expression_statement; 28, identifier:device; 29, None; 30, identifier:self; 31, identifier:attach_data; 32, expression_statement; 33, attribute; 34, argument_list; 35, assignment; 36, assignment; 37, attribute; 38, identifier:detach_volume; 39, attribute; 40, identifier:instance_id; 41, identifier:device; 42, identifier:force; 43, identifier:instance_id; 44, attribute; 45, identifier:device; 46, attribute; 47, identifier:self; 48, identifier:connection; 49, identifier:self; 50, identifier:id; 51, attribute; 52, identifier:instance_id; 53, attribute; 54, identifier:device; 55, identifier:self; 56, identifier:attach_data; 57, identifier:self; 58, identifier:attach_data
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 8, 16; 9, 17; 9, 18; 10, 19; 11, 20; 11, 21; 12, 22; 16, 23; 16, 24; 17, 25; 17, 26; 18, 27; 19, 28; 19, 29; 20, 30; 20, 31; 21, 32; 22, 33; 22, 34; 27, 35; 32, 36; 33, 37; 33, 38; 34, 39; 34, 40; 34, 41; 34, 42; 35, 43; 35, 44; 36, 45; 36, 46; 37, 47; 37, 48; 39, 49; 39, 50; 44, 51; 44, 52; 46, 53; 46, 54; 51, 55; 51, 56; 53, 57; 53, 58
def detach(self, force=False): """ Detach this EBS volume from an EC2 instance. :type force: bool :param force: Forces detachment if the previous detachment attempt did not occur cleanly. This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures. :rtype: bool :return: True if successful """ instance_id = None if self.attach_data: instance_id = self.attach_data.instance_id device = None if self.attach_data: device = self.attach_data.device return self.connection.detach_volume(self.id, instance_id, device, force)
0, module; 1, function_definition; 2, function_name:make_node_dict; 3, parameters; 4, block; 5, identifier:outer_list; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, return_statement; 16, identifier:sort; 17, string:"zone"; 18, comment:"""Convert node data from nested-list to sorted dict."""; 19, assignment; 20, assignment; 21, identifier:inner_list; 22, identifier:outer_list; 23, block; 24, comparison_operator:sort == "name"; 25, comment:# sort by provider - name; 26, block; 27, else_clause; 28, assignment; 29, assignment; 30, pattern_list; 31, call; 32, block; 33, identifier:node_dict; 34, identifier:raw_dict; 35, dictionary; 36, identifier:x; 37, integer:1; 38, for_statement; 39, identifier:sort; 40, string:"name"; 41, expression_statement; 42, comment:# sort by provider - zone - name; 43, block; 44, identifier:x; 45, integer:1; 46, identifier:node_dict; 47, dictionary; 48, identifier:i; 49, identifier:v; 50, attribute; 51, argument_list; 52, expression_statement; 53, expression_statement; 54, identifier:node; 55, identifier:inner_list; 56, block; 57, assignment; 58, expression_statement; 59, identifier:srt_dict; 60, identifier:items; 61, assignment; 62, augmented_assignment; 63, expression_statement; 64, expression_statement; 65, identifier:srt_dict; 66, call; 67, assignment; 68, subscript; 69, identifier:v; 70, identifier:x; 71, integer:1; 72, assignment; 73, augmented_assignment; 74, identifier:OrderedDict; 75, argument_list; 76, identifier:srt_dict; 77, call; 78, identifier:node_dict; 79, identifier:x; 80, subscript; 81, identifier:node; 82, identifier:x; 83, integer:1; 84, call; 85, identifier:OrderedDict; 86, argument_list; 87, identifier:raw_dict; 88, identifier:x; 89, identifier:sorted; 90, argument_list; 91, call; 92, call; 93, keyword_argument; 94, identifier:sorted; 95, argument_list; 96, attribute; 97, argument_list; 98, identifier:key; 99, lambda; 100, call; 101, keyword_argument; 102, identifier:raw_dict; 103, identifier:items; 104, lambda_parameters; 105, tuple; 106, attribute; 107, argument_list; 108, identifier:key; 109, lambda; 110, identifier:k; 111, attribute; 112, call; 113, identifier:raw_dict; 114, identifier:items; 115, lambda_parameters; 116, tuple; 117, subscript; 118, identifier:cloud; 119, attribute; 120, argument_list; 121, identifier:k; 122, attribute; 123, attribute; 124, call; 125, identifier:k; 126, integer:1; 127, attribute; 128, identifier:lower; 129, subscript; 130, identifier:cloud; 131, subscript; 132, identifier:zone; 133, attribute; 134, argument_list; 135, subscript; 136, identifier:name; 137, identifier:k; 138, integer:1; 139, identifier:k; 140, integer:1; 141, attribute; 142, identifier:lower; 143, identifier:k; 144, integer:1; 145, subscript; 146, identifier:name; 147, identifier:k; 148, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 6, 16; 6, 17; 7, 18; 8, 19; 9, 20; 10, 21; 10, 22; 10, 23; 11, 24; 11, 25; 11, 26; 11, 27; 12, 28; 13, 29; 14, 30; 14, 31; 14, 32; 15, 33; 19, 34; 19, 35; 20, 36; 20, 37; 23, 38; 24, 39; 24, 40; 26, 41; 27, 42; 27, 43; 28, 44; 28, 45; 29, 46; 29, 47; 30, 48; 30, 49; 31, 50; 31, 51; 32, 52; 32, 53; 38, 54; 38, 55; 38, 56; 41, 57; 43, 58; 50, 59; 50, 60; 52, 61; 53, 62; 56, 63; 56, 64; 57, 65; 57, 66; 58, 67; 61, 68; 61, 69; 62, 70; 62, 71; 63, 72; 64, 73; 66, 74; 66, 75; 67, 76; 67, 77; 68, 78; 68, 79; 72, 80; 72, 81; 73, 82; 73, 83; 75, 84; 77, 85; 77, 86; 80, 87; 80, 88; 84, 89; 84, 90; 86, 91; 90, 92; 90, 93; 91, 94; 91, 95; 92, 96; 92, 97; 93, 98; 93, 99; 95, 100; 95, 101; 96, 102; 96, 103; 99, 104; 99, 105; 100, 106; 100, 107; 101, 108; 101, 109; 104, 110; 105, 111; 105, 112; 106, 113; 106, 114; 109, 115; 109, 116; 111, 117; 111, 118; 112, 119; 112, 120; 115, 121; 116, 122; 116, 123; 116, 124; 117, 125; 117, 126; 119, 127; 119, 128; 122, 129; 122, 130; 123, 131; 123, 132; 124, 133; 124, 134; 127, 135; 127, 136; 129, 137; 129, 138; 131, 139; 131, 140; 133, 141; 133, 142; 135, 143; 135, 144; 141, 145; 141, 146; 145, 147; 145, 148
def make_node_dict(outer_list, sort="zone"): """Convert node data from nested-list to sorted dict.""" raw_dict = {} x = 1 for inner_list in outer_list: for node in inner_list: raw_dict[x] = node x += 1 if sort == "name": # sort by provider - name srt_dict = OrderedDict(sorted(raw_dict.items(), key=lambda k: (k[1].cloud, k[1].name.lower()))) else: # sort by provider - zone - name srt_dict = OrderedDict(sorted(raw_dict.items(), key=lambda k: (k[1].cloud, k[1].zone, k[1].name.lower()))) x = 1 node_dict = {} for i, v in srt_dict.items(): node_dict[x] = v x += 1 return node_dict
0, module; 1, function_definition; 2, function_name:crack; 3, parameters; 4, block; 5, identifier:ciphertext; 6, list_splat_pattern; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, comment:# Find a local maximum by swapping two letters and scoring the decryption; 12, function_definition; 13, comment:# Outer climb rereuns hill climb ntrials number of times each time at a different start location; 14, function_definition; 15, expression_statement; 16, return_statement; 17, identifier:fitness_functions; 18, identifier:ntrials; 19, integer:30; 20, identifier:nswaps; 21, integer:3000; 22, comment:"""Break ``ciphertext`` using hill climbing. Note: Currently ntrails and nswaps default to magic numbers. Generally the trend is, the longer the text, the lower the number of trials you need to run, because the hill climbing will lead to the best answer faster. Because randomness is involved, there is the possibility of the correct decryption not being found. In this circumstance you just need to run the code again. Example: >>> decryptions = crack("XUOOB", fitness.english.quadgrams) >>> print(decryptions[0]) HELLO Args: ciphertext (str): The text to decrypt *fitness_functions (variable length argument list): Functions to score decryption with Keyword Args: ntrials (int): The number of times to run the hill climbing algorithm nswaps (int): The number of rounds to find a local maximum Returns: Sorted list of decryptions Raises: ValueError: If nswaps or ntrails are not positive integers ValueError: If no fitness_functions are given """; 23, boolean_operator; 24, block; 25, function_name:next_node_inner_climb; 26, parameters; 27, comment:# Swap 2 characters in the key; 28, block; 29, function_name:next_node_outer_climb; 30, parameters; 31, block; 32, assignment; 33, call; 34, comparison_operator:ntrials <= 0; 35, comparison_operator:nswaps <= 0; 36, raise_statement; 37, identifier:node; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, return_statement; 43, identifier:node; 44, expression_statement; 45, expression_statement; 46, return_statement; 47, comment:# The last item in this list is the item with the highest score; 48, pattern_list; 49, call; 50, identifier:sorted; 51, argument_list; 52, identifier:ntrials; 53, integer:0; 54, identifier:nswaps; 55, integer:0; 56, call; 57, assignment; 58, assignment; 59, assignment; 60, assignment; 61, expression_list; 62, call; 63, assignment; 64, expression_list; 65, identifier:_; 66, identifier:_; 67, identifier:decryptions; 68, identifier:hill_climb; 69, argument_list; 70, identifier:decryptions; 71, keyword_argument; 72, identifier:ValueError; 73, argument_list; 74, pattern_list; 75, call; 76, pattern_list; 77, expression_list; 78, identifier:plaintext; 79, call; 80, identifier:node_score; 81, call; 82, identifier:node; 83, identifier:node_score; 84, call; 85, attribute; 86, argument_list; 87, pattern_list; 88, call; 89, identifier:key; 90, identifier:best_score; 91, subscript; 92, identifier:ntrials; 93, call; 94, identifier:next_node_outer_climb; 95, identifier:reverse; 96, True; 97, string:"ntrials and nswaps must be positive integers"; 98, identifier:a; 99, identifier:b; 100, attribute; 101, argument_list; 102, subscript; 103, subscript; 104, subscript; 105, subscript; 106, identifier:decrypt; 107, argument_list; 108, identifier:score; 109, argument_list; 110, identifier:Decryption; 111, argument_list; 112, identifier:random; 113, identifier:shuffle; 114, identifier:node; 115, identifier:key; 116, identifier:best_score; 117, identifier:outputs; 118, identifier:hill_climb; 119, argument_list; 120, identifier:outputs; 121, unary_operator; 122, identifier:list; 123, argument_list; 124, identifier:random; 125, identifier:sample; 126, call; 127, integer:2; 128, identifier:node; 129, identifier:a; 130, identifier:node; 131, identifier:b; 132, identifier:node; 133, identifier:b; 134, identifier:node; 135, identifier:a; 136, identifier:node; 137, identifier:ciphertext; 138, identifier:plaintext; 139, list_splat; 140, identifier:plaintext; 141, call; 142, identifier:node_score; 143, identifier:nswaps; 144, subscript; 145, identifier:next_node_inner_climb; 146, integer:1; 147, attribute; 148, identifier:range; 149, argument_list; 150, identifier:fitness_functions; 151, attribute; 152, argument_list; 153, identifier:node; 154, slice; 155, identifier:string; 156, identifier:ascii_uppercase; 157, call; 158, string; 159, identifier:join; 160, identifier:node; 161, identifier:len; 162, argument_list; 163, identifier:node
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 6, 17; 7, 18; 7, 19; 8, 20; 8, 21; 9, 22; 10, 23; 10, 24; 12, 25; 12, 26; 12, 27; 12, 28; 14, 29; 14, 30; 14, 31; 15, 32; 16, 33; 23, 34; 23, 35; 24, 36; 26, 37; 28, 38; 28, 39; 28, 40; 28, 41; 28, 42; 30, 43; 31, 44; 31, 45; 31, 46; 31, 47; 32, 48; 32, 49; 33, 50; 33, 51; 34, 52; 34, 53; 35, 54; 35, 55; 36, 56; 38, 57; 39, 58; 40, 59; 41, 60; 42, 61; 44, 62; 45, 63; 46, 64; 48, 65; 48, 66; 48, 67; 49, 68; 49, 69; 51, 70; 51, 71; 56, 72; 56, 73; 57, 74; 57, 75; 58, 76; 58, 77; 59, 78; 59, 79; 60, 80; 60, 81; 61, 82; 61, 83; 61, 84; 62, 85; 62, 86; 63, 87; 63, 88; 64, 89; 64, 90; 64, 91; 69, 92; 69, 93; 69, 94; 71, 95; 71, 96; 73, 97; 74, 98; 74, 99; 75, 100; 75, 101; 76, 102; 76, 103; 77, 104; 77, 105; 79, 106; 79, 107; 81, 108; 81, 109; 84, 110; 84, 111; 85, 112; 85, 113; 86, 114; 87, 115; 87, 116; 87, 117; 88, 118; 88, 119; 91, 120; 91, 121; 93, 122; 93, 123; 100, 124; 100, 125; 101, 126; 101, 127; 102, 128; 102, 129; 103, 130; 103, 131; 104, 132; 104, 133; 105, 134; 105, 135; 107, 136; 107, 137; 109, 138; 109, 139; 111, 140; 111, 141; 111, 142; 119, 143; 119, 144; 119, 145; 121, 146; 123, 147; 126, 148; 126, 149; 139, 150; 141, 151; 141, 152; 144, 153; 144, 154; 147, 155; 147, 156; 149, 157; 151, 158; 151, 159; 152, 160; 157, 161; 157, 162; 162, 163
def crack(ciphertext, *fitness_functions, ntrials=30, nswaps=3000): """Break ``ciphertext`` using hill climbing. Note: Currently ntrails and nswaps default to magic numbers. Generally the trend is, the longer the text, the lower the number of trials you need to run, because the hill climbing will lead to the best answer faster. Because randomness is involved, there is the possibility of the correct decryption not being found. In this circumstance you just need to run the code again. Example: >>> decryptions = crack("XUOOB", fitness.english.quadgrams) >>> print(decryptions[0]) HELLO Args: ciphertext (str): The text to decrypt *fitness_functions (variable length argument list): Functions to score decryption with Keyword Args: ntrials (int): The number of times to run the hill climbing algorithm nswaps (int): The number of rounds to find a local maximum Returns: Sorted list of decryptions Raises: ValueError: If nswaps or ntrails are not positive integers ValueError: If no fitness_functions are given """ if ntrials <= 0 or nswaps <= 0: raise ValueError("ntrials and nswaps must be positive integers") # Find a local maximum by swapping two letters and scoring the decryption def next_node_inner_climb(node): # Swap 2 characters in the key a, b = random.sample(range(len(node)), 2) node[a], node[b] = node[b], node[a] plaintext = decrypt(node, ciphertext) node_score = score(plaintext, *fitness_functions) return node, node_score, Decryption(plaintext, ''.join(node), node_score) # Outer climb rereuns hill climb ntrials number of times each time at a different start location def next_node_outer_climb(node): random.shuffle(node) key, best_score, outputs = hill_climb(nswaps, node[:], next_node_inner_climb) return key, best_score, outputs[-1] # The last item in this list is the item with the highest score _, _, decryptions = hill_climb(ntrials, list(string.ascii_uppercase), next_node_outer_climb) return sorted(decryptions, reverse=True)
0, module; 1, function_definition; 2, function_name:key_periods; 3, parameters; 4, block; 5, identifier:ciphertext; 6, identifier:max_key_period; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, comment:"""Rank all key periods for ``ciphertext`` up to and including ``max_key_period`` Example: >>> key_periods(ciphertext, 30) [2, 4, 8, 3, ...] Args: ciphertext (str): The text to analyze max_key_period (int): The maximum period the key could be Returns: Sorted list of keys Raises: ValueError: If max_key_period is less than or equal to 0 """; 13, comparison_operator:max_key_period <= 0; 14, block; 15, assignment; 16, identifier:period; 17, call; 18, block; 19, list_comprehension; 20, identifier:max_key_period; 21, integer:0; 22, raise_statement; 23, identifier:key_scores; 24, list; 25, identifier:range; 26, argument_list; 27, expression_statement; 28, expression_statement; 29, subscript; 30, for_in_clause; 31, call; 32, integer:1; 33, binary_operator:min(max_key_period, len(ciphertext)) + 1; 34, assignment; 35, call; 36, identifier:p; 37, integer:0; 38, identifier:p; 39, call; 40, identifier:ValueError; 41, argument_list; 42, call; 43, integer:1; 44, identifier:score; 45, call; 46, attribute; 47, argument_list; 48, identifier:sorted; 49, argument_list; 50, string:"max_key_period must be a positive integer"; 51, identifier:min; 52, argument_list; 53, identifier:abs; 54, argument_list; 55, identifier:key_scores; 56, identifier:append; 57, tuple; 58, identifier:key_scores; 59, keyword_argument; 60, identifier:max_key_period; 61, call; 62, binary_operator:ENGLISH_IC - index_of_coincidence(*split_columns(ciphertext, period)); 63, identifier:period; 64, identifier:score; 65, identifier:key; 66, lambda; 67, identifier:len; 68, argument_list; 69, identifier:ENGLISH_IC; 70, call; 71, lambda_parameters; 72, subscript; 73, identifier:ciphertext; 74, identifier:index_of_coincidence; 75, argument_list; 76, identifier:x; 77, identifier:x; 78, integer:1; 79, list_splat; 80, call; 81, identifier:split_columns; 82, argument_list; 83, identifier:ciphertext; 84, identifier:period
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 8, 14; 9, 15; 10, 16; 10, 17; 10, 18; 11, 19; 13, 20; 13, 21; 14, 22; 15, 23; 15, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 22, 31; 26, 32; 26, 33; 27, 34; 28, 35; 29, 36; 29, 37; 30, 38; 30, 39; 31, 40; 31, 41; 33, 42; 33, 43; 34, 44; 34, 45; 35, 46; 35, 47; 39, 48; 39, 49; 41, 50; 42, 51; 42, 52; 45, 53; 45, 54; 46, 55; 46, 56; 47, 57; 49, 58; 49, 59; 52, 60; 52, 61; 54, 62; 57, 63; 57, 64; 59, 65; 59, 66; 61, 67; 61, 68; 62, 69; 62, 70; 66, 71; 66, 72; 68, 73; 70, 74; 70, 75; 71, 76; 72, 77; 72, 78; 75, 79; 79, 80; 80, 81; 80, 82; 82, 83; 82, 84
def key_periods(ciphertext, max_key_period): """Rank all key periods for ``ciphertext`` up to and including ``max_key_period`` Example: >>> key_periods(ciphertext, 30) [2, 4, 8, 3, ...] Args: ciphertext (str): The text to analyze max_key_period (int): The maximum period the key could be Returns: Sorted list of keys Raises: ValueError: If max_key_period is less than or equal to 0 """ if max_key_period <= 0: raise ValueError("max_key_period must be a positive integer") key_scores = [] for period in range(1, min(max_key_period, len(ciphertext)) + 1): score = abs(ENGLISH_IC - index_of_coincidence(*split_columns(ciphertext, period))) key_scores.append((period, score)) return [p[0] for p in sorted(key_scores, key=lambda x: x[1])]
0, module; 1, function_definition; 2, function_name:crack; 3, parameters; 4, block; 5, identifier:ciphertext; 6, list_splat_pattern; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, for_statement; 14, return_statement; 15, identifier:fitness_functions; 16, identifier:min_key; 17, integer:0; 18, identifier:max_key; 19, integer:26; 20, identifier:shift_function; 21, identifier:shift_case_english; 22, comment:"""Break ``ciphertext`` by enumerating keys between ``min_key`` and ``max_key``. Example: >>> decryptions = crack("KHOOR", fitness.english.quadgrams) >>> print(''.join(decryptions[0].plaintext)) HELLO Args: ciphertext (iterable): The symbols to decrypt *fitness_functions (variable length argument list): Functions to score decryption with Keyword Args: min_key (int): Key to start with max_key (int): Key to stop at (exclusive) shift_function (function(shift, symbol)): Shift function to use Returns: Sorted list of decryptions Raises: ValueError: If min_key exceeds max_key ValueError: If no fitness_functions are given """; 23, comparison_operator:min_key >= max_key; 24, block; 25, assignment; 26, identifier:key; 27, call; 28, block; 29, call; 30, identifier:min_key; 31, identifier:max_key; 32, raise_statement; 33, identifier:decryptions; 34, list; 35, identifier:range; 36, argument_list; 37, expression_statement; 38, expression_statement; 39, identifier:sorted; 40, argument_list; 41, call; 42, identifier:min_key; 43, identifier:max_key; 44, assignment; 45, call; 46, identifier:decryptions; 47, keyword_argument; 48, identifier:ValueError; 49, argument_list; 50, identifier:plaintext; 51, call; 52, attribute; 53, argument_list; 54, identifier:reverse; 55, True; 56, string:"min_key cannot exceed max_key"; 57, identifier:decrypt; 58, argument_list; 59, identifier:decryptions; 60, identifier:append; 61, call; 62, identifier:key; 63, identifier:ciphertext; 64, keyword_argument; 65, identifier:Decryption; 66, argument_list; 67, identifier:shift_function; 68, identifier:shift_function; 69, identifier:plaintext; 70, identifier:key; 71, call; 72, identifier:score; 73, argument_list; 74, identifier:plaintext; 75, list_splat; 76, identifier:fitness_functions
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 7, 16; 7, 17; 8, 18; 8, 19; 9, 20; 9, 21; 10, 22; 11, 23; 11, 24; 12, 25; 13, 26; 13, 27; 13, 28; 14, 29; 23, 30; 23, 31; 24, 32; 25, 33; 25, 34; 27, 35; 27, 36; 28, 37; 28, 38; 29, 39; 29, 40; 32, 41; 36, 42; 36, 43; 37, 44; 38, 45; 40, 46; 40, 47; 41, 48; 41, 49; 44, 50; 44, 51; 45, 52; 45, 53; 47, 54; 47, 55; 49, 56; 51, 57; 51, 58; 52, 59; 52, 60; 53, 61; 58, 62; 58, 63; 58, 64; 61, 65; 61, 66; 64, 67; 64, 68; 66, 69; 66, 70; 66, 71; 71, 72; 71, 73; 73, 74; 73, 75; 75, 76
def crack(ciphertext, *fitness_functions, min_key=0, max_key=26, shift_function=shift_case_english): """Break ``ciphertext`` by enumerating keys between ``min_key`` and ``max_key``. Example: >>> decryptions = crack("KHOOR", fitness.english.quadgrams) >>> print(''.join(decryptions[0].plaintext)) HELLO Args: ciphertext (iterable): The symbols to decrypt *fitness_functions (variable length argument list): Functions to score decryption with Keyword Args: min_key (int): Key to start with max_key (int): Key to stop at (exclusive) shift_function (function(shift, symbol)): Shift function to use Returns: Sorted list of decryptions Raises: ValueError: If min_key exceeds max_key ValueError: If no fitness_functions are given """ if min_key >= max_key: raise ValueError("min_key cannot exceed max_key") decryptions = [] for key in range(min_key, max_key): plaintext = decrypt(key, ciphertext, shift_function=shift_function) decryptions.append(Decryption(plaintext, key, score(plaintext, *fitness_functions))) return sorted(decryptions, reverse=True)
0, module; 1, function_definition; 2, function_name:get_sort_limit; 3, parameters; 4, block; 5, expression_statement; 6, expression_statement; 7, if_statement; 8, return_statement; 9, comment:""" returns the 'sort_limit' from the request """; 10, assignment; 11, parenthesized_expression; 12, block; 13, identifier:limit; 14, identifier:limit; 15, call; 16, comparison_operator:limit < 1; 17, expression_statement; 18, comment:# catalog raises IndexError if limit < 1; 19, attribute; 20, argument_list; 21, identifier:limit; 22, integer:1; 23, assignment; 24, identifier:_; 25, identifier:convert; 26, call; 27, attribute; 28, identifier:limit; 29, None; 30, identifier:get; 31, argument_list; 32, identifier:_; 33, identifier:to_int; 34, string:"sort_limit"
0, 1; 1, 2; 1, 3; 1, 4; 4, 5; 4, 6; 4, 7; 4, 8; 5, 9; 6, 10; 7, 11; 7, 12; 8, 13; 10, 14; 10, 15; 11, 16; 12, 17; 12, 18; 15, 19; 15, 20; 16, 21; 16, 22; 17, 23; 19, 24; 19, 25; 20, 26; 20, 27; 23, 28; 23, 29; 26, 30; 26, 31; 27, 32; 27, 33; 31, 34
def get_sort_limit(): """ returns the 'sort_limit' from the request """ limit = _.convert(get("sort_limit"), _.to_int) if (limit < 1): limit = None # catalog raises IndexError if limit < 1 return limit
0, module; 1, function_definition; 2, function_name:get_sort_on; 3, parameters; 4, block; 5, default_parameter; 6, expression_statement; 7, expression_statement; 8, if_statement; 9, return_statement; 10, identifier:allowed_indexes; 11, None; 12, comment:""" returns the 'sort_on' from the request """; 13, assignment; 14, boolean_operator; 15, block; 16, identifier:sort_on; 17, identifier:sort_on; 18, call; 19, identifier:allowed_indexes; 20, comparison_operator:sort_on not in allowed_indexes; 21, expression_statement; 22, return_statement; 23, identifier:get; 24, argument_list; 25, identifier:sort_on; 26, identifier:allowed_indexes; 27, call; 28, None; 29, string:"sort_on"; 30, attribute; 31, argument_list; 32, identifier:logger; 33, identifier:warn; 34, call; 35, attribute; 36, argument_list; 37, string:"Index '{}' is not in allowed_indexes"; 38, identifier:format; 39, identifier:sort_on
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 5, 10; 5, 11; 6, 12; 7, 13; 8, 14; 8, 15; 9, 16; 13, 17; 13, 18; 14, 19; 14, 20; 15, 21; 15, 22; 18, 23; 18, 24; 20, 25; 20, 26; 21, 27; 22, 28; 24, 29; 27, 30; 27, 31; 30, 32; 30, 33; 31, 34; 34, 35; 34, 36; 35, 37; 35, 38; 36, 39
def get_sort_on(allowed_indexes=None): """ returns the 'sort_on' from the request """ sort_on = get("sort_on") if allowed_indexes and sort_on not in allowed_indexes: logger.warn("Index '{}' is not in allowed_indexes".format(sort_on)) return None return sort_on
0, module; 1, function_definition; 2, function_name:to_list; 3, parameters; 4, block; 5, identifier:thing; 6, expression_statement; 7, if_statement; 8, if_statement; 9, if_statement; 10, if_statement; 11, return_statement; 12, comment:""" converts an object to a list >>> to_list(1) [1] >>> to_list([1,2,3]) [1, 2, 3] >>> to_list(("a", "b", "c")) ['a', 'b', 'c'] >>> to_list(dict(a=1, b=2)) [{'a': 1, 'b': 2}] >>> to_list(None) [] >>> to_list("['a', 'b', 'c']") ['a', 'b', 'c'] >>> to_list("") [''] >>> to_list([]) [] >>> to_list("['[]']") ['[]'] >>> sorted(to_list(set(["a", "b", "c"]))) ['a', 'b', 'c'] """; 13, comparison_operator:thing is None; 14, block; 15, call; 16, block; 17, call; 18, block; 19, not_operator; 20, block; 21, call; 22, identifier:thing; 23, None; 24, return_statement; 25, identifier:isinstance; 26, argument_list; 27, return_statement; 28, identifier:isinstance; 29, argument_list; 30, if_statement; 31, parenthesized_expression; 32, return_statement; 33, identifier:list; 34, argument_list; 35, list; 36, identifier:thing; 37, identifier:set; 38, call; 39, identifier:thing; 40, attribute; 41, call; 42, comment:# handle a list inside a string coming from the batch navigation; 43, block; 44, boolean_operator; 45, list; 46, identifier:thing; 47, identifier:list; 48, argument_list; 49, identifier:types; 50, identifier:StringTypes; 51, attribute; 52, argument_list; 53, return_statement; 54, call; 55, call; 56, identifier:thing; 57, identifier:thing; 58, identifier:thing; 59, identifier:startswith; 60, string:"["; 61, call; 62, identifier:is_list; 63, argument_list; 64, identifier:is_tuple; 65, argument_list; 66, attribute; 67, argument_list; 68, identifier:thing; 69, identifier:thing; 70, identifier:ast; 71, identifier:literal_eval; 72, identifier:thing
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 7, 13; 7, 14; 8, 15; 8, 16; 9, 17; 9, 18; 10, 19; 10, 20; 11, 21; 13, 22; 13, 23; 14, 24; 15, 25; 15, 26; 16, 27; 17, 28; 17, 29; 18, 30; 19, 31; 20, 32; 21, 33; 21, 34; 24, 35; 26, 36; 26, 37; 27, 38; 29, 39; 29, 40; 30, 41; 30, 42; 30, 43; 31, 44; 32, 45; 34, 46; 38, 47; 38, 48; 40, 49; 40, 50; 41, 51; 41, 52; 43, 53; 44, 54; 44, 55; 45, 56; 48, 57; 51, 58; 51, 59; 52, 60; 53, 61; 54, 62; 54, 63; 55, 64; 55, 65; 61, 66; 61, 67; 63, 68; 65, 69; 66, 70; 66, 71; 67, 72
def to_list(thing): """ converts an object to a list >>> to_list(1) [1] >>> to_list([1,2,3]) [1, 2, 3] >>> to_list(("a", "b", "c")) ['a', 'b', 'c'] >>> to_list(dict(a=1, b=2)) [{'a': 1, 'b': 2}] >>> to_list(None) [] >>> to_list("['a', 'b', 'c']") ['a', 'b', 'c'] >>> to_list("") [''] >>> to_list([]) [] >>> to_list("['[]']") ['[]'] >>> sorted(to_list(set(["a", "b", "c"]))) ['a', 'b', 'c'] """ if thing is None: return [] if isinstance(thing, set): return list(thing) if isinstance(thing, types.StringTypes): if thing.startswith("["): # handle a list inside a string coming from the batch navigation return ast.literal_eval(thing) if not (is_list(thing) or is_tuple(thing)): return [thing] return list(thing)
0, module; 1, function_definition; 2, function_name:get_sort_spec; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:"""Build sort specification """; 12, assignment; 13, assignment; 14, assignment; 15, expression_list; 16, identifier:all_indexes; 17, call; 18, identifier:si; 19, call; 20, identifier:so; 21, call; 22, identifier:si; 23, identifier:so; 24, attribute; 25, argument_list; 26, attribute; 27, argument_list; 28, attribute; 29, argument_list; 30, attribute; 31, identifier:get_indexes; 32, identifier:req; 33, identifier:get_sort_on; 34, keyword_argument; 35, identifier:req; 36, identifier:get_sort_order; 37, identifier:self; 38, identifier:catalog; 39, identifier:allowed_indexes; 40, identifier:all_indexes
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 13, 19; 14, 20; 14, 21; 15, 22; 15, 23; 17, 24; 17, 25; 19, 26; 19, 27; 21, 28; 21, 29; 24, 30; 24, 31; 26, 32; 26, 33; 27, 34; 28, 35; 28, 36; 30, 37; 30, 38; 34, 39; 34, 40
def get_sort_spec(self): """Build sort specification """ all_indexes = self.catalog.get_indexes() si = req.get_sort_on(allowed_indexes=all_indexes) so = req.get_sort_order() return si, so
0, module; 1, function_definition; 2, function_name:sort_dict; 3, parameters; 4, block; 5, identifier:self; 6, identifier:data; 7, identifier:key; 8, expression_statement; 9, return_statement; 10, string; 11, conditional_expression:sorted(data, key=itemgetter(key)) if data else []; 12, string_content:Sort a list of dictionaries by dictionary key; 13, call; 14, identifier:data; 15, list; 16, identifier:sorted; 17, argument_list; 18, identifier:data; 19, keyword_argument; 20, identifier:key; 21, call; 22, identifier:itemgetter; 23, argument_list; 24, identifier:key
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 10, 12; 11, 13; 11, 14; 11, 15; 13, 16; 13, 17; 17, 18; 17, 19; 19, 20; 19, 21; 21, 22; 21, 23; 23, 24
def sort_dict(self, data, key): '''Sort a list of dictionaries by dictionary key''' return sorted(data, key=itemgetter(key)) if data else []
0, module; 1, function_definition; 2, function_name:load_drops; 3, parameters; 4, block; 5, identifier:self; 6, identifier:dropin; 7, expression_statement; 8, expression_statement; 9, try_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, comment:"""Load `drops` from the given dropin. Args: dropin (string): path of a dropin, e.g. dropin.auth Returns: An iterable contains the drops object in the given dropin This method load drops object by some sort of convension. For example, assuming we want to load drops type `models` from dropin `dropin.articls`. The drops are discoveried with the following sequence:: import dropin.articles drops = dropin.articles.models if anything goes wrong, next try is :: import dropin.articles.models as drops if the current drops object has attribute **__drops__** :: drops = drops.__drops__ if the current drops object is a callable :: drops = drops() if not drops was found, an empty list is returned. """; 14, assignment; 15, block; 16, except_clause; 17, call; 18, block; 19, call; 20, block; 21, boolean_operator; 22, identifier:obj; 23, call; 24, expression_statement; 25, identifier:AttributeError; 26, block; 27, identifier:hasattr; 28, argument_list; 29, expression_statement; 30, identifier:callable; 31, argument_list; 32, expression_statement; 33, identifier:drops; 34, list; 35, identifier:load_object; 36, argument_list; 37, assignment; 38, try_statement; 39, identifier:drops; 40, string; 41, assignment; 42, identifier:drops; 43, assignment; 44, identifier:dropin; 45, identifier:drops; 46, call; 47, block; 48, except_clause; 49, string_content:__drops__; 50, identifier:drops; 51, attribute; 52, identifier:drops; 53, call; 54, identifier:getattr; 55, argument_list; 56, expression_statement; 57, identifier:ImportError; 58, block; 59, identifier:drops; 60, identifier:__drops__; 61, identifier:drops; 62, argument_list; 63, identifier:obj; 64, attribute; 65, assignment; 66, expression_statement; 67, attribute; 68, identifier:self; 69, identifier:drops_type; 70, identifier:drops; 71, call; 72, assignment; 73, identifier:self; 74, identifier:app; 75, identifier:load_object; 76, argument_list; 77, identifier:drops; 78, None; 79, binary_operator:'%s.%s' % (dropin, self.drops_type); 80, string; 81, tuple; 82, string_content:%s.%s; 83, identifier:dropin; 84, attribute; 85, identifier:self; 86, identifier:drops_type
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 9, 16; 10, 17; 10, 18; 11, 19; 11, 20; 12, 21; 14, 22; 14, 23; 15, 24; 16, 25; 16, 26; 17, 27; 17, 28; 18, 29; 19, 30; 19, 31; 20, 32; 21, 33; 21, 34; 23, 35; 23, 36; 24, 37; 26, 38; 28, 39; 28, 40; 29, 41; 31, 42; 32, 43; 36, 44; 37, 45; 37, 46; 38, 47; 38, 48; 40, 49; 41, 50; 41, 51; 43, 52; 43, 53; 46, 54; 46, 55; 47, 56; 48, 57; 48, 58; 51, 59; 51, 60; 53, 61; 53, 62; 55, 63; 55, 64; 56, 65; 58, 66; 62, 67; 64, 68; 64, 69; 65, 70; 65, 71; 66, 72; 67, 73; 67, 74; 71, 75; 71, 76; 72, 77; 72, 78; 76, 79; 79, 80; 79, 81; 80, 82; 81, 83; 81, 84; 84, 85; 84, 86
def load_drops(self, dropin): """Load `drops` from the given dropin. Args: dropin (string): path of a dropin, e.g. dropin.auth Returns: An iterable contains the drops object in the given dropin This method load drops object by some sort of convension. For example, assuming we want to load drops type `models` from dropin `dropin.articls`. The drops are discoveried with the following sequence:: import dropin.articles drops = dropin.articles.models if anything goes wrong, next try is :: import dropin.articles.models as drops if the current drops object has attribute **__drops__** :: drops = drops.__drops__ if the current drops object is a callable :: drops = drops() if not drops was found, an empty list is returned. """ obj = load_object(dropin) try: drops = getattr(obj, self.drops_type) except AttributeError: try: drops = load_object('%s.%s' % (dropin, self.drops_type)) except ImportError: drops = None if hasattr(drops, '__drops__'): drops = drops.__drops__ if callable(drops): drops = drops(self.app) return drops or []
0, module; 1, function_definition; 2, function_name:sort_by; 3, parameters; 4, block; 5, identifier:self; 6, identifier:attr_or_key; 7, default_parameter; 8, expression_statement; 9, comment:# work out the direction; 10, if_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, identifier:direction; 15, string; 16, comment:"""Sort the view by an attribute or key :param attr_or_key: The attribute or key to sort by :param direction: Either `asc` or `desc` indicating the direction of sorting """; 17, comparison_operator:direction in ('+', 'asc', gtk.SORT_ASCENDING); 18, block; 19, elif_clause; 20, else_clause; 21, call; 22, comment:# is a key; 23, block; 24, else_clause; 25, call; 26, call; 27, string_content:asc; 28, identifier:direction; 29, tuple; 30, expression_statement; 31, comparison_operator:direction in ('-', 'desc', gtk.SORT_DESCENDING); 32, block; 33, block; 34, identifier:callable; 35, argument_list; 36, expression_statement; 37, comment:# it's an attribute; 38, block; 39, attribute; 40, argument_list; 41, attribute; 42, argument_list; 43, string; 44, string; 45, attribute; 46, assignment; 47, identifier:direction; 48, tuple; 49, expression_statement; 50, raise_statement; 51, identifier:attr_or_key; 52, assignment; 53, expression_statement; 54, attribute; 55, identifier:set_default_sort_func; 56, identifier:sort_func; 57, identifier:attr_or_key; 58, attribute; 59, identifier:set_sort_column_id; 60, unary_operator; 61, identifier:direction; 62, string_content:+; 63, string_content:asc; 64, identifier:gtk; 65, identifier:SORT_ASCENDING; 66, identifier:direction; 67, attribute; 68, string; 69, string; 70, attribute; 71, assignment; 72, call; 73, identifier:sort_func; 74, attribute; 75, assignment; 76, identifier:self; 77, identifier:model; 78, identifier:self; 79, identifier:model; 80, integer:1; 81, identifier:gtk; 82, identifier:SORT_ASCENDING; 83, string_content:-; 84, string_content:desc; 85, identifier:gtk; 86, identifier:SORT_DESCENDING; 87, identifier:direction; 88, attribute; 89, identifier:AttributeError; 90, argument_list; 91, identifier:self; 92, identifier:_key_sort_func; 93, identifier:sort_func; 94, attribute; 95, identifier:gtk; 96, identifier:SORT_DESCENDING; 97, string; 98, identifier:self; 99, identifier:_attr_sort_func; 100, string_content:unrecognised direction
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 7, 14; 7, 15; 8, 16; 10, 17; 10, 18; 10, 19; 10, 20; 11, 21; 11, 22; 11, 23; 11, 24; 12, 25; 13, 26; 15, 27; 17, 28; 17, 29; 18, 30; 19, 31; 19, 32; 20, 33; 21, 34; 21, 35; 23, 36; 24, 37; 24, 38; 25, 39; 25, 40; 26, 41; 26, 42; 29, 43; 29, 44; 29, 45; 30, 46; 31, 47; 31, 48; 32, 49; 33, 50; 35, 51; 36, 52; 38, 53; 39, 54; 39, 55; 40, 56; 40, 57; 41, 58; 41, 59; 42, 60; 42, 61; 43, 62; 44, 63; 45, 64; 45, 65; 46, 66; 46, 67; 48, 68; 48, 69; 48, 70; 49, 71; 50, 72; 52, 73; 52, 74; 53, 75; 54, 76; 54, 77; 58, 78; 58, 79; 60, 80; 67, 81; 67, 82; 68, 83; 69, 84; 70, 85; 70, 86; 71, 87; 71, 88; 72, 89; 72, 90; 74, 91; 74, 92; 75, 93; 75, 94; 88, 95; 88, 96; 90, 97; 94, 98; 94, 99; 97, 100
def sort_by(self, attr_or_key, direction='asc'): """Sort the view by an attribute or key :param attr_or_key: The attribute or key to sort by :param direction: Either `asc` or `desc` indicating the direction of sorting """ # work out the direction if direction in ('+', 'asc', gtk.SORT_ASCENDING): direction = gtk.SORT_ASCENDING elif direction in ('-', 'desc', gtk.SORT_DESCENDING): direction = gtk.SORT_DESCENDING else: raise AttributeError('unrecognised direction') if callable(attr_or_key): # is a key sort_func = self._key_sort_func else: # it's an attribute sort_func = self._attr_sort_func self.model.set_default_sort_func(sort_func, attr_or_key) self.model.set_sort_column_id(-1, direction)
0, module; 1, function_definition; 2, function_name:load_file; 3, parameters; 4, block; 5, identifier:self; 6, identifier:filepath; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, with_statement; 12, return_statement; 13, comment:""" This function opens any type of a readable file and decompose the file object into a list, for each line, of lists containing splitted line strings using space as a spacer. Parameters ---------- filepath : :class:`str` The full path or a relative path to any type of file. Returns ------- :class:`dict` Returns a dictionary containing the molecular information extracted from the input files. This information will vary with file type and information stored in it. The data is sorted into lists that contain one feature for example key atom_id: [atom_id_1, atom_id_2] Over the process of analysis this dictionary will be updated with new data. """; 14, assignment; 15, assignment; 16, assignment; 17, with_clause; 18, block; 19, parenthesized_expression; 20, attribute; 21, identifier:filepath; 22, pattern_list; 23, call; 24, pattern_list; 25, call; 26, with_item; 27, expression_statement; 28, call; 29, identifier:self; 30, identifier:file_path; 31, identifier:_; 32, attribute; 33, attribute; 34, argument_list; 35, identifier:_; 36, attribute; 37, attribute; 38, argument_list; 39, as_pattern; 40, assignment; 41, subscript; 42, argument_list; 43, identifier:self; 44, identifier:file_type; 45, attribute; 46, identifier:splitext; 47, identifier:filepath; 48, identifier:self; 49, identifier:file_name; 50, attribute; 51, identifier:split; 52, identifier:filepath; 53, call; 54, as_pattern_target; 55, attribute; 56, call; 57, attribute; 58, attribute; 59, identifier:os; 60, identifier:path; 61, identifier:os; 62, identifier:path; 63, identifier:open; 64, argument_list; 65, identifier:ffile; 66, identifier:self; 67, identifier:file_content; 68, attribute; 69, argument_list; 70, identifier:self; 71, identifier:_load_funcs; 72, identifier:self; 73, identifier:file_type; 74, identifier:filepath; 75, identifier:ffile; 76, identifier:readlines
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 10, 16; 11, 17; 11, 18; 12, 19; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 18, 27; 19, 28; 20, 29; 20, 30; 22, 31; 22, 32; 23, 33; 23, 34; 24, 35; 24, 36; 25, 37; 25, 38; 26, 39; 27, 40; 28, 41; 28, 42; 32, 43; 32, 44; 33, 45; 33, 46; 34, 47; 36, 48; 36, 49; 37, 50; 37, 51; 38, 52; 39, 53; 39, 54; 40, 55; 40, 56; 41, 57; 41, 58; 45, 59; 45, 60; 50, 61; 50, 62; 53, 63; 53, 64; 54, 65; 55, 66; 55, 67; 56, 68; 56, 69; 57, 70; 57, 71; 58, 72; 58, 73; 64, 74; 68, 75; 68, 76
def load_file(self, filepath): """ This function opens any type of a readable file and decompose the file object into a list, for each line, of lists containing splitted line strings using space as a spacer. Parameters ---------- filepath : :class:`str` The full path or a relative path to any type of file. Returns ------- :class:`dict` Returns a dictionary containing the molecular information extracted from the input files. This information will vary with file type and information stored in it. The data is sorted into lists that contain one feature for example key atom_id: [atom_id_1, atom_id_2] Over the process of analysis this dictionary will be updated with new data. """ self.file_path = filepath _, self.file_type = os.path.splitext(filepath) _, self.file_name = os.path.split(filepath) with open(filepath) as ffile: self.file_content = ffile.readlines() return (self._load_funcs[self.file_type]())
0, module; 1, function_definition; 2, function_name:find; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, dictionary_splat_pattern; 13, expression_statement; 14, if_statement; 15, if_statement; 16, expression_statement; 17, if_statement; 18, expression_statement; 19, for_statement; 20, if_statement; 21, if_statement; 22, identifier:limit; 23, None; 24, identifier:reverse; 25, False; 26, identifier:sort; 27, None; 28, identifier:exclude; 29, None; 30, identifier:duplicates; 31, True; 32, identifier:pretty; 33, False; 34, identifier:filters; 35, comment:""" Using filters and sorts, this finds all hyperlinks on a web page :param limit: Crop results down to limit specified :param reverse: Reverse the list of links, useful for before limiting :param exclude: Remove links from list :param duplicates: Determines if identical URLs should be displayed :param pretty: Quick and pretty formatting using pprint :param filters: All the links to search for """; 36, comparison_operator:exclude is None; 37, block; 38, comparison_operator:'href' not in filters; 39, block; 40, assignment; 41, identifier:reverse; 42, block; 43, assignment; 44, identifier:anchor; 45, identifier:search; 46, block; 47, comparison_operator:sort is not None; 48, block; 49, identifier:pretty; 50, block; 51, else_clause; 52, identifier:exclude; 53, None; 54, expression_statement; 55, string; 56, identifier:filters; 57, expression_statement; 58, identifier:search; 59, call; 60, expression_statement; 61, identifier:links; 62, list; 63, expression_statement; 64, try_statement; 65, try_statement; 66, expression_statement; 67, for_statement; 68, if_statement; 69, if_statement; 70, if_statement; 71, identifier:sort; 72, None; 73, expression_statement; 74, expression_statement; 75, return_statement; 76, block; 77, assignment; 78, string_content:href; 79, assignment; 80, attribute; 81, argument_list; 82, call; 83, assignment; 84, block; 85, except_clause; 86, block; 87, except_clause; 88, assignment; 89, identifier:nixd; 90, identifier:exclude; 91, block; 92, not_operator; 93, block; 94, not_operator; 95, block; 96, boolean_operator; 97, block; 98, assignment; 99, assignment; 100, call; 101, return_statement; 102, identifier:exclude; 103, list; 104, subscript; 105, True; 106, attribute; 107, identifier:findAll; 108, string; 109, dictionary_splat; 110, attribute; 111, argument_list; 112, identifier:build_link; 113, attribute; 114, expression_statement; 115, identifier:KeyError; 116, block; 117, expression_statement; 118, identifier:KeyError; 119, block; 120, identifier:ignore_link; 121, False; 122, for_statement; 123, identifier:duplicates; 124, for_statement; 125, identifier:ignore_link; 126, expression_statement; 127, comparison_operator:limit is not None; 128, comparison_operator:len(links) == limit; 129, break_statement; 130, identifier:links; 131, call; 132, identifier:pp; 133, call; 134, attribute; 135, argument_list; 136, identifier:links; 137, identifier:filters; 138, string; 139, identifier:self; 140, identifier:_soup; 141, string_content:a; 142, identifier:filters; 143, identifier:search; 144, identifier:reverse; 145, identifier:anchor; 146, identifier:attrs; 147, assignment; 148, pass_statement; 149, assignment; 150, pass_statement; 151, pattern_list; 152, call; 153, block; 154, identifier:link; 155, identifier:links; 156, block; 157, call; 158, identifier:limit; 159, None; 160, call; 161, identifier:limit; 162, identifier:sorted; 163, argument_list; 164, attribute; 165, argument_list; 166, identifier:pp; 167, identifier:pprint; 168, identifier:links; 169, string_content:href; 170, subscript; 171, call; 172, subscript; 173, boolean_operator; 174, identifier:key; 175, identifier:value; 176, attribute; 177, argument_list; 178, if_statement; 179, if_statement; 180, attribute; 181, argument_list; 182, identifier:len; 183, argument_list; 184, identifier:links; 185, keyword_argument; 186, keyword_argument; 187, identifier:pprint; 188, identifier:PrettyPrinter; 189, keyword_argument; 190, identifier:build_link; 191, string; 192, identifier:seoify_hyperlink; 193, argument_list; 194, identifier:build_link; 195, string; 196, attribute; 197, subscript; 198, identifier:six; 199, identifier:iteritems; 200, identifier:nixd; 201, comparison_operator:key in build_link; 202, block; 203, comparison_operator:link['href'] == anchor['href']; 204, block; 205, identifier:links; 206, identifier:append; 207, identifier:build_link; 208, identifier:links; 209, identifier:key; 210, identifier:sort; 211, identifier:reverse; 212, identifier:reverse; 213, identifier:indent; 214, integer:4; 215, string_content:seo; 216, subscript; 217, string_content:text; 218, identifier:anchor; 219, identifier:string; 220, identifier:build_link; 221, string; 222, identifier:key; 223, identifier:build_link; 224, if_statement; 225, subscript; 226, subscript; 227, expression_statement; 228, identifier:anchor; 229, string; 230, string_content:seo; 231, parenthesized_expression; 232, block; 233, else_clause; 234, identifier:link; 235, string; 236, identifier:anchor; 237, string; 238, assignment; 239, string_content:href; 240, boolean_operator; 241, for_statement; 242, block; 243, string_content:href; 244, string_content:href; 245, identifier:ignore_link; 246, True; 247, call; 248, not_operator; 249, identifier:item; 250, subscript; 251, block; 252, expression_statement; 253, identifier:isinstance; 254, argument_list; 255, call; 256, identifier:build_link; 257, identifier:key; 258, expression_statement; 259, assignment; 260, subscript; 261, attribute; 262, identifier:isinstance; 263, argument_list; 264, assignment; 265, identifier:ignore_link; 266, call; 267, identifier:build_link; 268, identifier:key; 269, identifier:collections; 270, identifier:Iterable; 271, subscript; 272, attribute; 273, identifier:ignore_link; 274, call; 275, identifier:exclude_match; 276, argument_list; 277, identifier:build_link; 278, identifier:key; 279, identifier:six; 280, identifier:string_types; 281, identifier:exclude_match; 282, argument_list; 283, identifier:value; 284, subscript; 285, identifier:value; 286, identifier:item; 287, identifier:build_link; 288, identifier:key
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 6, 22; 6, 23; 7, 24; 7, 25; 8, 26; 8, 27; 9, 28; 9, 29; 10, 30; 10, 31; 11, 32; 11, 33; 12, 34; 13, 35; 14, 36; 14, 37; 15, 38; 15, 39; 16, 40; 17, 41; 17, 42; 18, 43; 19, 44; 19, 45; 19, 46; 20, 47; 20, 48; 21, 49; 21, 50; 21, 51; 36, 52; 36, 53; 37, 54; 38, 55; 38, 56; 39, 57; 40, 58; 40, 59; 42, 60; 43, 61; 43, 62; 46, 63; 46, 64; 46, 65; 46, 66; 46, 67; 46, 68; 46, 69; 46, 70; 47, 71; 47, 72; 48, 73; 50, 74; 50, 75; 51, 76; 54, 77; 55, 78; 57, 79; 59, 80; 59, 81; 60, 82; 63, 83; 64, 84; 64, 85; 65, 86; 65, 87; 66, 88; 67, 89; 67, 90; 67, 91; 68, 92; 68, 93; 69, 94; 69, 95; 70, 96; 70, 97; 73, 98; 74, 99; 75, 100; 76, 101; 77, 102; 77, 103; 79, 104; 79, 105; 80, 106; 80, 107; 81, 108; 81, 109; 82, 110; 82, 111; 83, 112; 83, 113; 84, 114; 85, 115; 85, 116; 86, 117; 87, 118; 87, 119; 88, 120; 88, 121; 91, 122; 92, 123; 93, 124; 94, 125; 95, 126; 96, 127; 96, 128; 97, 129; 98, 130; 98, 131; 99, 132; 99, 133; 100, 134; 100, 135; 101, 136; 104, 137; 104, 138; 106, 139; 106, 140; 108, 141; 109, 142; 110, 143; 110, 144; 113, 145; 113, 146; 114, 147; 116, 148; 117, 149; 119, 150; 122, 151; 122, 152; 122, 153; 124, 154; 124, 155; 124, 156; 126, 157; 127, 158; 127, 159; 128, 160; 128, 161; 131, 162; 131, 163; 133, 164; 133, 165; 134, 166; 134, 167; 135, 168; 138, 169; 147, 170; 147, 171; 149, 172; 149, 173; 151, 174; 151, 175; 152, 176; 152, 177; 153, 178; 156, 179; 157, 180; 157, 181; 160, 182; 160, 183; 163, 184; 163, 185; 163, 186; 164, 187; 164, 188; 165, 189; 170, 190; 170, 191; 171, 192; 171, 193; 172, 194; 172, 195; 173, 196; 173, 197; 176, 198; 176, 199; 177, 200; 178, 201; 178, 202; 179, 203; 179, 204; 180, 205; 180, 206; 181, 207; 183, 208; 185, 209; 185, 210; 186, 211; 186, 212; 189, 213; 189, 214; 191, 215; 193, 216; 195, 217; 196, 218; 196, 219; 197, 220; 197, 221; 201, 222; 201, 223; 202, 224; 203, 225; 203, 226; 204, 227; 216, 228; 216, 229; 221, 230; 224, 231; 224, 232; 224, 233; 225, 234; 225, 235; 226, 236; 226, 237; 227, 238; 229, 239; 231, 240; 232, 241; 233, 242; 235, 243; 237, 244; 238, 245; 238, 246; 240, 247; 240, 248; 241, 249; 241, 250; 241, 251; 242, 252; 247, 253; 247, 254; 248, 255; 250, 256; 250, 257; 251, 258; 252, 259; 254, 260; 254, 261; 255, 262; 255, 263; 258, 264; 259, 265; 259, 266; 260, 267; 260, 268; 261, 269; 261, 270; 263, 271; 263, 272; 264, 273; 264, 274; 266, 275; 266, 276; 271, 277; 271, 278; 272, 279; 272, 280; 274, 281; 274, 282; 276, 283; 276, 284; 282, 285; 282, 286; 284, 287; 284, 288
def find(self, limit=None, reverse=False, sort=None, exclude=None, duplicates=True, pretty=False, **filters): """ Using filters and sorts, this finds all hyperlinks on a web page :param limit: Crop results down to limit specified :param reverse: Reverse the list of links, useful for before limiting :param exclude: Remove links from list :param duplicates: Determines if identical URLs should be displayed :param pretty: Quick and pretty formatting using pprint :param filters: All the links to search for """ if exclude is None: exclude = [] if 'href' not in filters: filters['href'] = True search = self._soup.findAll('a', **filters) if reverse: search.reverse() links = [] for anchor in search: build_link = anchor.attrs try: build_link[u'seo'] = seoify_hyperlink(anchor['href']) except KeyError: pass try: build_link[u'text'] = anchor.string or build_link['seo'] except KeyError: pass ignore_link = False for nixd in exclude: for key, value in six.iteritems(nixd): if key in build_link: if (isinstance(build_link[key], collections.Iterable) and not isinstance(build_link[key], six.string_types)): for item in build_link[key]: ignore_link = exclude_match(value, item) else: ignore_link = exclude_match(value, build_link[key]) if not duplicates: for link in links: if link['href'] == anchor['href']: ignore_link = True if not ignore_link: links.append(build_link) if limit is not None and len(links) == limit: break if sort is not None: links = sorted(links, key=sort, reverse=reverse) if pretty: pp = pprint.PrettyPrinter(indent=4) return pp.pprint(links) else: return links
0, module; 1, function_definition; 2, function_name:__draw_cmp; 3, parameters; 4, block; 5, identifier:self; 6, identifier:obj1; 7, identifier:obj2; 8, expression_statement; 9, if_statement; 10, comment:"""Defines how our drawable objects should be sorted"""; 11, comparison_operator:obj1.draw_order > obj2.draw_order; 12, block; 13, elif_clause; 14, else_clause; 15, attribute; 16, attribute; 17, return_statement; 18, comparison_operator:obj1.draw_order < obj2.draw_order; 19, block; 20, block; 21, identifier:obj1; 22, identifier:draw_order; 23, identifier:obj2; 24, identifier:draw_order; 25, integer:1; 26, attribute; 27, attribute; 28, return_statement; 29, return_statement; 30, identifier:obj1; 31, identifier:draw_order; 32, identifier:obj2; 33, identifier:draw_order; 34, unary_operator; 35, integer:0; 36, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 9, 12; 9, 13; 9, 14; 11, 15; 11, 16; 12, 17; 13, 18; 13, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 18, 26; 18, 27; 19, 28; 20, 29; 26, 30; 26, 31; 27, 32; 27, 33; 28, 34; 29, 35; 34, 36
def __draw_cmp(self, obj1, obj2): """Defines how our drawable objects should be sorted""" if obj1.draw_order > obj2.draw_order: return 1 elif obj1.draw_order < obj2.draw_order: return -1 else: return 0
0, module; 1, function_definition; 2, function_name:__up_cmp; 3, parameters; 4, block; 5, identifier:self; 6, identifier:obj1; 7, identifier:obj2; 8, expression_statement; 9, if_statement; 10, comment:"""Defines how our updatable objects should be sorted"""; 11, comparison_operator:obj1.update_order > obj2.update_order; 12, block; 13, elif_clause; 14, else_clause; 15, attribute; 16, attribute; 17, return_statement; 18, comparison_operator:obj1.update_order < obj2.update_order; 19, block; 20, block; 21, identifier:obj1; 22, identifier:update_order; 23, identifier:obj2; 24, identifier:update_order; 25, integer:1; 26, attribute; 27, attribute; 28, return_statement; 29, return_statement; 30, identifier:obj1; 31, identifier:update_order; 32, identifier:obj2; 33, identifier:update_order; 34, unary_operator; 35, integer:0; 36, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 9, 12; 9, 13; 9, 14; 11, 15; 11, 16; 12, 17; 13, 18; 13, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 17, 25; 18, 26; 18, 27; 19, 28; 20, 29; 26, 30; 26, 31; 27, 32; 27, 33; 28, 34; 29, 35; 34, 36
def __up_cmp(self, obj1, obj2): """Defines how our updatable objects should be sorted""" if obj1.update_order > obj2.update_order: return 1 elif obj1.update_order < obj2.update_order: return -1 else: return 0
0, module; 1, function_definition; 2, function_name:discover; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# 'ssdp:all'; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, expression_statement; 16, comment:# only return 'Virtual Media Player' and sort the list; 17, return_statement; 18, identifier:timeout; 19, integer:1; 20, identifier:retries; 21, integer:1; 22, comment:"""Discover Raumfeld devices in the network :param timeout: The timeout in seconds :param retries: How often the search should be retried :returns: A list of raumfeld devices, sorted by name """; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, call; 28, identifier:_; 29, call; 30, block; 31, assignment; 32, call; 33, identifier:locations; 34, list; 35, identifier:group; 36, tuple; 37, identifier:service; 38, string; 39, identifier:message; 40, call; 41, attribute; 42, argument_list; 43, identifier:range; 44, argument_list; 45, expression_statement; 46, comment:# socket options; 47, expression_statement; 48, expression_statement; 49, comment:# send group multicast; 50, expression_statement; 51, while_statement; 52, identifier:devices; 53, list_comprehension; 54, identifier:sorted; 55, argument_list; 56, string; 57, integer:1900; 58, string_content:ssdp:urn:schemas-upnp-org:device:MediaRenderer:1; 59, attribute; 60, argument_list; 61, identifier:socket; 62, identifier:setdefaulttimeout; 63, identifier:timeout; 64, identifier:retries; 65, assignment; 66, call; 67, call; 68, call; 69, True; 70, block; 71, call; 72, for_in_clause; 73, list_comprehension; 74, keyword_argument; 75, string_content:239.255.255.250; 76, call; 77, identifier:format; 78, keyword_argument; 79, keyword_argument; 80, identifier:sock; 81, call; 82, attribute; 83, argument_list; 84, attribute; 85, argument_list; 86, attribute; 87, argument_list; 88, try_statement; 89, identifier:RaumfeldDevice; 90, argument_list; 91, identifier:location; 92, identifier:locations; 93, identifier:device; 94, for_in_clause; 95, if_clause; 96, identifier:key; 97, lambda; 98, attribute; 99, argument_list; 100, identifier:group; 101, identifier:group; 102, identifier:st; 103, identifier:service; 104, attribute; 105, argument_list; 106, identifier:sock; 107, identifier:setsockopt; 108, attribute; 109, attribute; 110, integer:1; 111, identifier:sock; 112, identifier:setsockopt; 113, attribute; 114, attribute; 115, integer:2; 116, identifier:sock; 117, identifier:sendto; 118, call; 119, identifier:group; 120, block; 121, except_clause; 122, identifier:location; 123, identifier:device; 124, identifier:devices; 125, comparison_operator:device.model_description == 'Virtual Media Player'; 126, lambda_parameters; 127, attribute; 128, string; 129, identifier:join; 130, list; 131, identifier:socket; 132, identifier:socket; 133, attribute; 134, attribute; 135, attribute; 136, identifier:socket; 137, identifier:SOL_SOCKET; 138, identifier:socket; 139, identifier:SO_REUSEADDR; 140, identifier:socket; 141, identifier:IPPROTO_IP; 142, identifier:socket; 143, identifier:IP_MULTICAST_TTL; 144, attribute; 145, argument_list; 146, expression_statement; 147, for_statement; 148, attribute; 149, block; 150, attribute; 151, string; 152, identifier:device; 153, identifier:device; 154, identifier:friendly_name; 155, string_content; 156, string; 157, string; 158, string:'MAN: "ssdp:discover"'; 159, string; 160, string; 161, string; 162, string; 163, identifier:socket; 164, identifier:AF_INET; 165, identifier:socket; 166, identifier:SOCK_DGRAM; 167, identifier:socket; 168, identifier:IPPROTO_UDP; 169, identifier:message; 170, identifier:encode; 171, string; 172, assignment; 173, identifier:line; 174, call; 175, block; 176, identifier:socket; 177, identifier:timeout; 178, break_statement; 179, identifier:device; 180, identifier:model_description; 181, string_content:Virtual Media Player; 182, escape_sequence:\r; 183, escape_sequence:\n; 184, string_content:M-SEARCH * HTTP/1.1; 185, string_content:HOST: {group[0]}:{group[1]}; 186, string_content:ST: {st}; 187, string_content:MX: 1; 188, string_content:utf-8; 189, identifier:response; 190, call; 191, attribute; 192, argument_list; 193, if_statement; 194, attribute; 195, argument_list; 196, identifier:response; 197, identifier:split; 198, string; 199, call; 200, block; 201, call; 202, identifier:decode; 203, string; 204, string_content; 205, attribute; 206, argument_list; 207, expression_statement; 208, if_statement; 209, attribute; 210, argument_list; 211, string_content:utf-8; 212, escape_sequence:\r; 213, escape_sequence:\n; 214, identifier:line; 215, identifier:startswith; 216, string; 217, assignment; 218, not_operator; 219, block; 220, identifier:sock; 221, identifier:recv; 222, integer:2048; 223, string_content:Location:; 224, identifier:location; 225, call; 226, comparison_operator:location in locations; 227, expression_statement; 228, attribute; 229, argument_list; 230, identifier:location; 231, identifier:locations; 232, call; 233, subscript; 234, identifier:strip; 235, attribute; 236, argument_list; 237, call; 238, integer:1; 239, identifier:locations; 240, identifier:append; 241, identifier:location; 242, attribute; 243, argument_list; 244, identifier:line; 245, identifier:split; 246, string; 247, string_content:
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 5, 18; 5, 19; 6, 20; 6, 21; 7, 22; 8, 23; 9, 24; 10, 25; 12, 26; 13, 27; 14, 28; 14, 29; 14, 30; 15, 31; 17, 32; 23, 33; 23, 34; 24, 35; 24, 36; 25, 37; 25, 38; 26, 39; 26, 40; 27, 41; 27, 42; 29, 43; 29, 44; 30, 45; 30, 46; 30, 47; 30, 48; 30, 49; 30, 50; 30, 51; 31, 52; 31, 53; 32, 54; 32, 55; 36, 56; 36, 57; 38, 58; 40, 59; 40, 60; 41, 61; 41, 62; 42, 63; 44, 64; 45, 65; 47, 66; 48, 67; 50, 68; 51, 69; 51, 70; 53, 71; 53, 72; 55, 73; 55, 74; 56, 75; 59, 76; 59, 77; 60, 78; 60, 79; 65, 80; 65, 81; 66, 82; 66, 83; 67, 84; 67, 85; 68, 86; 68, 87; 70, 88; 71, 89; 71, 90; 72, 91; 72, 92; 73, 93; 73, 94; 73, 95; 74, 96; 74, 97; 76, 98; 76, 99; 78, 100; 78, 101; 79, 102; 79, 103; 81, 104; 81, 105; 82, 106; 82, 107; 83, 108; 83, 109; 83, 110; 84, 111; 84, 112; 85, 113; 85, 114; 85, 115; 86, 116; 86, 117; 87, 118; 87, 119; 88, 120; 88, 121; 90, 122; 94, 123; 94, 124; 95, 125; 97, 126; 97, 127; 98, 128; 98, 129; 99, 130; 104, 131; 104, 132; 105, 133; 105, 134; 105, 135; 108, 136; 108, 137; 109, 138; 109, 139; 113, 140; 113, 141; 114, 142; 114, 143; 118, 144; 118, 145; 120, 146; 120, 147; 121, 148; 121, 149; 125, 150; 125, 151; 126, 152; 127, 153; 127, 154; 128, 155; 130, 156; 130, 157; 130, 158; 130, 159; 130, 160; 130, 161; 130, 162; 133, 163; 133, 164; 134, 165; 134, 166; 135, 167; 135, 168; 144, 169; 144, 170; 145, 171; 146, 172; 147, 173; 147, 174; 147, 175; 148, 176; 148, 177; 149, 178; 150, 179; 150, 180; 151, 181; 155, 182; 155, 183; 156, 184; 157, 185; 159, 186; 160, 187; 171, 188; 172, 189; 172, 190; 174, 191; 174, 192; 175, 193; 190, 194; 190, 195; 191, 196; 191, 197; 192, 198; 193, 199; 193, 200; 194, 201; 194, 202; 195, 203; 198, 204; 199, 205; 199, 206; 200, 207; 200, 208; 201, 209; 201, 210; 203, 211; 204, 212; 204, 213; 205, 214; 205, 215; 206, 216; 207, 217; 208, 218; 208, 219; 209, 220; 209, 221; 210, 222; 216, 223; 217, 224; 217, 225; 218, 226; 219, 227; 225, 228; 225, 229; 226, 230; 226, 231; 227, 232; 228, 233; 228, 234; 232, 235; 232, 236; 233, 237; 233, 238; 235, 239; 235, 240; 236, 241; 237, 242; 237, 243; 242, 244; 242, 245; 243, 246; 246, 247
def discover(timeout=1, retries=1): """Discover Raumfeld devices in the network :param timeout: The timeout in seconds :param retries: How often the search should be retried :returns: A list of raumfeld devices, sorted by name """ locations = [] group = ('239.255.255.250', 1900) service = 'ssdp:urn:schemas-upnp-org:device:MediaRenderer:1' # 'ssdp:all' message = '\r\n'.join(['M-SEARCH * HTTP/1.1', 'HOST: {group[0]}:{group[1]}', 'MAN: "ssdp:discover"', 'ST: {st}', 'MX: 1', '', '']).format(group=group, st=service) socket.setdefaulttimeout(timeout) for _ in range(retries): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # socket options sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) # send group multicast sock.sendto(message.encode('utf-8'), group) while True: try: response = sock.recv(2048).decode('utf-8') for line in response.split('\r\n'): if line.startswith('Location: '): location = line.split(' ')[1].strip() if not location in locations: locations.append(location) except socket.timeout: break devices = [RaumfeldDevice(location) for location in locations] # only return 'Virtual Media Player' and sort the list return sorted([device for device in devices if device.model_description == 'Virtual Media Player'], key=lambda device: device.friendly_name)
0, module; 1, function_definition; 2, function_name:get_user_trades; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# TODO Workaround for the broken limit param in QuadrigaCX API; 13, return_statement; 14, identifier:limit; 15, integer:0; 16, identifier:offset; 17, integer:0; 18, identifier:sort; 19, string; 20, comment:"""Return user's trade history. :param limit: Maximum number of trades to return. If set to 0 or lower, all trades are returned (default: 0). :type limit: int :param offset: Number of trades to skip. :type offset: int :param sort: Method used to sort the results by date and time. Allowed values are "desc" for descending order, and "asc" for ascending order (default: "desc"). :type sort: str | unicode :return: User's trade history. :rtype: [dict] """; 21, call; 22, assignment; 23, conditional_expression:res[:limit] if len(res) > limit > 0 else res; 24, string_content:desc; 25, attribute; 26, argument_list; 27, identifier:res; 28, call; 29, subscript; 30, comparison_operator:len(res) > limit > 0; 31, identifier:res; 32, identifier:self; 33, identifier:_log; 34, string; 35, attribute; 36, argument_list; 37, identifier:res; 38, slice; 39, call; 40, identifier:limit; 41, integer:0; 42, string_content:get user trades; 43, attribute; 44, identifier:post; 45, keyword_argument; 46, keyword_argument; 47, identifier:limit; 48, identifier:len; 49, argument_list; 50, identifier:self; 51, identifier:_rest_client; 52, identifier:endpoint; 53, string; 54, identifier:payload; 55, dictionary; 56, identifier:res; 57, string_content:/user_transactions; 58, pair; 59, pair; 60, pair; 61, pair; 62, string; 63, attribute; 64, string; 65, identifier:limit; 66, string; 67, identifier:offset; 68, string; 69, identifier:sort; 70, string_content:book; 71, identifier:self; 72, identifier:name; 73, string_content:limit; 74, string_content:offset; 75, string_content:sort
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 6, 14; 6, 15; 7, 16; 7, 17; 8, 18; 8, 19; 9, 20; 10, 21; 11, 22; 13, 23; 19, 24; 21, 25; 21, 26; 22, 27; 22, 28; 23, 29; 23, 30; 23, 31; 25, 32; 25, 33; 26, 34; 28, 35; 28, 36; 29, 37; 29, 38; 30, 39; 30, 40; 30, 41; 34, 42; 35, 43; 35, 44; 36, 45; 36, 46; 38, 47; 39, 48; 39, 49; 43, 50; 43, 51; 45, 52; 45, 53; 46, 54; 46, 55; 49, 56; 53, 57; 55, 58; 55, 59; 55, 60; 55, 61; 58, 62; 58, 63; 59, 64; 59, 65; 60, 66; 60, 67; 61, 68; 61, 69; 62, 70; 63, 71; 63, 72; 64, 73; 66, 74; 68, 75
def get_user_trades(self, limit=0, offset=0, sort='desc'): """Return user's trade history. :param limit: Maximum number of trades to return. If set to 0 or lower, all trades are returned (default: 0). :type limit: int :param offset: Number of trades to skip. :type offset: int :param sort: Method used to sort the results by date and time. Allowed values are "desc" for descending order, and "asc" for ascending order (default: "desc"). :type sort: str | unicode :return: User's trade history. :rtype: [dict] """ self._log('get user trades') res = self._rest_client.post( endpoint='/user_transactions', payload={ 'book': self.name, 'limit': limit, 'offset': offset, 'sort': sort } ) # TODO Workaround for the broken limit param in QuadrigaCX API return res[:limit] if len(res) > limit > 0 else res
0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, typed_parameter; 7, expression_statement; 8, try_statement; 9, identifier:col; 10, type; 11, comment:""" Sorts the main dataframe according to the given column :param col: column name :type col: str :example: ``ds.sort("Col 1")`` """; 12, block; 13, except_clause; 14, identifier:str; 15, expression_statement; 16, as_pattern; 17, block; 18, assignment; 19, identifier:Exception; 20, as_pattern_target; 21, expression_statement; 22, attribute; 23, call; 24, identifier:e; 25, call; 26, identifier:self; 27, identifier:df; 28, attribute; 29, argument_list; 30, attribute; 31, argument_list; 32, call; 33, identifier:sort_values; 34, identifier:col; 35, identifier:self; 36, identifier:err; 37, identifier:e; 38, binary_operator:"Can not sort the dataframe from column " + str(col); 39, attribute; 40, argument_list; 41, string:"Can not sort the dataframe from column "; 42, call; 43, attribute; 44, identifier:copy; 45, identifier:str; 46, argument_list; 47, identifier:self; 48, identifier:df; 49, identifier:col
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 6, 9; 6, 10; 7, 11; 8, 12; 8, 13; 10, 14; 12, 15; 13, 16; 13, 17; 15, 18; 16, 19; 16, 20; 17, 21; 18, 22; 18, 23; 20, 24; 21, 25; 22, 26; 22, 27; 23, 28; 23, 29; 25, 30; 25, 31; 28, 32; 28, 33; 29, 34; 30, 35; 30, 36; 31, 37; 31, 38; 32, 39; 32, 40; 38, 41; 38, 42; 39, 43; 39, 44; 42, 45; 42, 46; 43, 47; 43, 48; 46, 49
def sort(self, col: str): """ Sorts the main dataframe according to the given column :param col: column name :type col: str :example: ``ds.sort("Col 1")`` """ try: self.df = self.df.copy().sort_values(col) except Exception as e: self.err(e, "Can not sort the dataframe from column " + str(col))
0, module; 1, function_definition; 2, function_name:iterate; 3, parameters; 4, block; 5, identifier:MachineClass; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, function_definition; 13, function_definition; 14, function_definition; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, try_statement; 19, return_statement; 20, identifier:stop_function; 21, lambda; 22, identifier:machines; 23, integer:1000; 24, identifier:survival_rate; 25, float:0.05; 26, identifier:mutation_rate; 27, float:0.075; 28, identifier:silent; 29, False; 30, comment:"""Creates a bunch of machines, runs them for a number of steps and then gives them a fitness score. The best produce offspring that are passed on to the next generation. Args: setup: Function taking a Machine argument, makes the machine ready machine_class: A class that should inherit from Machine and contain the following methods: setUp(self) [optional]: Run before each new run, should at least call self.reset() for each run. tearDown(self) [optional]: Run after each run. crossover(self, other): Returns a Machine offspring between itself and another Machine. score(self): Score the machine. Lower is better. Can return a tuple of values used to sort the machines from best to worst in fitness. stop_function: An optional function that takes the current generation number and returns True if the processing should stop. machines: The number of machines to create for each generation. steps: The number of instructions each machine is allowed to execute in each run. code_length: Tuple of (minimum code length, maximum code length) for a Machine. survival_ratio: Ratio of the best Machines which are allowed to produce offspring for the next generation. mutation_rate: Rate for each machine's chance of being mutated. """; 31, function_name:make_random; 32, parameters; 33, block; 34, function_name:run_once; 35, parameters; 36, block; 37, function_name:make_offspring; 38, parameters; 39, block; 40, assignment; 41, assignment; 42, identifier:silent; 43, block; 44, else_clause; 45, block; 46, except_clause; 47, identifier:survivors; 48, lambda_parameters; 49, comparison_operator:iterations < 10000; 50, identifier:n; 51, return_statement; 52, identifier:m; 53, expression_statement; 54, expression_statement; 55, expression_statement; 56, return_statement; 57, identifier:survivors; 58, expression_statement; 59, expression_statement; 60, return_statement; 61, identifier:generation; 62, call; 63, identifier:survivors; 64, identifier:generation; 65, expression_statement; 66, block; 67, expression_statement; 68, while_statement; 69, identifier:KeyboardInterrupt; 70, block; 71, identifier:iterations; 72, identifier:iterations; 73, integer:10000; 74, call; 75, call; 76, call; 77, call; 78, identifier:m; 79, assignment; 80, assignment; 81, call; 82, identifier:map; 83, argument_list; 84, assignment; 85, expression_statement; 86, assignment; 87, not_operator; 88, block; 89, pass_statement; 90, attribute; 91, argument_list; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, identifier:a; 99, call; 100, identifier:b; 101, call; 102, attribute; 103, argument_list; 104, identifier:make_random; 105, call; 106, identifier:log; 107, lambda; 108, assignment; 109, identifier:iterations; 110, integer:0; 111, call; 112, expression_statement; 113, expression_statement; 114, comment:# Run all machines in this generation; 115, expression_statement; 116, comment:# Sort machines from best to worst; 117, expression_statement; 118, comment:# Select the best; 119, expression_statement; 120, comment:# Remove code larger than 50; 121, for_statement; 122, comment:# Remove dead ones; 123, expression_statement; 124, comment:#survivors = [s for s in survivors if len(s.code)<=50]; 125, comment:# All dead? start with a new set; 126, if_statement; 127, comment:# Create a new generation based on the survivors.; 128, expression_statement; 129, expression_statement; 130, expression_statement; 131, comment:# Add mutations from time to time; 132, for_statement; 133, expression_statement; 134, call; 135, identifier:randomize; 136, identifier:m; 137, identifier:setUp; 138, identifier:m; 139, identifier:run; 140, identifier:m; 141, identifier:tearDown; 142, identifier:stochastic_choice; 143, argument_list; 144, identifier:stochastic_choice; 145, argument_list; 146, identifier:a; 147, identifier:crossover; 148, identifier:b; 149, identifier:xrange; 150, argument_list; 151, lambda_parameters; 152, None; 153, identifier:log; 154, identifier:_log; 155, identifier:stop_function; 156, argument_list; 157, augmented_assignment; 158, call; 159, assignment; 160, assignment; 161, assignment; 162, identifier:s; 163, identifier:survivors; 164, block; 165, assignment; 166, comparison_operator:len(survivors) == 0; 167, block; 168, call; 169, assignment; 170, assignment; 171, identifier:m; 172, identifier:generation; 173, block; 174, call; 175, identifier:MachineClass; 176, argument_list; 177, identifier:survivors; 178, identifier:survivors; 179, identifier:machines; 180, identifier:s; 181, default_parameter; 182, identifier:iterations; 183, identifier:survivors; 184, identifier:iterations; 185, integer:1; 186, identifier:log; 187, argument_list; 188, identifier:generation; 189, call; 190, identifier:generation; 191, call; 192, identifier:survivors; 193, subscript; 194, if_statement; 195, identifier:survivors; 196, list_comprehension; 197, call; 198, integer:0; 199, expression_statement; 200, expression_statement; 201, expression_statement; 202, continue_statement; 203, identifier:log; 204, argument_list; 205, identifier:cross; 206, lambda; 207, identifier:generation; 208, call; 209, if_statement; 210, identifier:log; 211, argument_list; 212, identifier:stream; 213, None; 214, string:"running ... "; 215, identifier:map; 216, argument_list; 217, identifier:sorted; 218, argument_list; 219, identifier:generation; 220, slice; 221, comparison_operator:len(s.code) >= 50; 222, block; 223, identifier:s; 224, for_in_clause; 225, if_clause; 226, identifier:len; 227, argument_list; 228, call; 229, assignment; 230, assignment; 231, string:"crossover ... "; 232, lambda_parameters; 233, call; 234, identifier:map; 235, argument_list; 236, comparison_operator:random.random() > mutation_rate; 237, block; 238, binary_operator:"\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\n" % (iterations, average(survivors, lambda m: m.score()), average(survivors, lambda m: len(m.code)), average(survivors, lambda m: len(m.stack) + len(m.return_stack))); 239, identifier:run_once; 240, identifier:generation; 241, identifier:generation; 242, keyword_argument; 243, call; 244, call; 245, integer:50; 246, expression_statement; 247, identifier:s; 248, identifier:survivors; 249, comparison_operator:len(s.code)>0; 250, identifier:survivors; 251, identifier:log; 252, argument_list; 253, identifier:survivors; 254, call; 255, identifier:generation; 256, identifier:survivors; 257, identifier:_; 258, identifier:make_offspring; 259, argument_list; 260, identifier:cross; 261, call; 262, call; 263, identifier:mutation_rate; 264, expression_statement; 265, string:"\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\n"; 266, tuple; 267, identifier:key; 268, lambda; 269, identifier:int; 270, argument_list; 271, identifier:len; 272, argument_list; 273, assignment; 274, call; 275, integer:0; 276, string:"\nNo survivors, restarting"; 277, identifier:map; 278, argument_list; 279, identifier:survivors; 280, identifier:xrange; 281, argument_list; 282, attribute; 283, argument_list; 284, call; 285, identifier:iterations; 286, call; 287, call; 288, call; 289, lambda_parameters; 290, call; 291, binary_operator:survival_rate * len(generation); 292, attribute; 293, attribute; 294, subscript; 295, identifier:len; 296, argument_list; 297, identifier:make_random; 298, call; 299, identifier:machines; 300, identifier:random; 301, identifier:random; 302, attribute; 303, argument_list; 304, identifier:average; 305, argument_list; 306, identifier:average; 307, argument_list; 308, identifier:average; 309, argument_list; 310, identifier:m; 311, attribute; 312, argument_list; 313, identifier:survival_rate; 314, call; 315, identifier:s; 316, identifier:code; 317, identifier:s; 318, identifier:code; 319, attribute; 320, slice; 321, attribute; 322, identifier:xrange; 323, argument_list; 324, identifier:m; 325, identifier:mutate; 326, identifier:survivors; 327, lambda; 328, identifier:survivors; 329, lambda; 330, identifier:survivors; 331, lambda; 332, identifier:m; 333, identifier:score; 334, identifier:len; 335, argument_list; 336, identifier:s; 337, identifier:code; 338, integer:50; 339, identifier:s; 340, identifier:code; 341, identifier:machines; 342, lambda_parameters; 343, call; 344, lambda_parameters; 345, call; 346, lambda_parameters; 347, binary_operator:len(m.stack) + len(m.return_stack); 348, identifier:generation; 349, identifier:m; 350, attribute; 351, argument_list; 352, identifier:m; 353, identifier:len; 354, argument_list; 355, identifier:m; 356, call; 357, call; 358, identifier:m; 359, identifier:score; 360, attribute; 361, identifier:len; 362, argument_list; 363, identifier:len; 364, argument_list; 365, identifier:m; 366, identifier:code; 367, attribute; 368, attribute; 369, identifier:m; 370, identifier:stack; 371, identifier:m; 372, identifier:return_stack
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 6, 20; 6, 21; 7, 22; 7, 23; 8, 24; 8, 25; 9, 26; 9, 27; 10, 28; 10, 29; 11, 30; 12, 31; 12, 32; 12, 33; 13, 34; 13, 35; 13, 36; 14, 37; 14, 38; 14, 39; 15, 40; 16, 41; 17, 42; 17, 43; 17, 44; 18, 45; 18, 46; 19, 47; 21, 48; 21, 49; 32, 50; 33, 51; 35, 52; 36, 53; 36, 54; 36, 55; 36, 56; 38, 57; 39, 58; 39, 59; 39, 60; 40, 61; 40, 62; 41, 63; 41, 64; 43, 65; 44, 66; 45, 67; 45, 68; 46, 69; 46, 70; 48, 71; 49, 72; 49, 73; 51, 74; 53, 75; 54, 76; 55, 77; 56, 78; 58, 79; 59, 80; 60, 81; 62, 82; 62, 83; 65, 84; 66, 85; 67, 86; 68, 87; 68, 88; 70, 89; 74, 90; 74, 91; 75, 92; 75, 93; 76, 94; 76, 95; 77, 96; 77, 97; 79, 98; 79, 99; 80, 100; 80, 101; 81, 102; 81, 103; 83, 104; 83, 105; 84, 106; 84, 107; 85, 108; 86, 109; 86, 110; 87, 111; 88, 112; 88, 113; 88, 114; 88, 115; 88, 116; 88, 117; 88, 118; 88, 119; 88, 120; 88, 121; 88, 122; 88, 123; 88, 124; 88, 125; 88, 126; 88, 127; 88, 128; 88, 129; 88, 130; 88, 131; 88, 132; 88, 133; 90, 134; 90, 135; 92, 136; 92, 137; 94, 138; 94, 139; 96, 140; 96, 141; 99, 142; 99, 143; 101, 144; 101, 145; 102, 146; 102, 147; 103, 148; 105, 149; 105, 150; 107, 151; 107, 152; 108, 153; 108, 154; 111, 155; 111, 156; 112, 157; 113, 158; 115, 159; 117, 160; 119, 161; 121, 162; 121, 163; 121, 164; 123, 165; 126, 166; 126, 167; 128, 168; 129, 169; 130, 170; 132, 171; 132, 172; 132, 173; 133, 174; 134, 175; 134, 176; 143, 177; 145, 178; 150, 179; 151, 180; 151, 181; 156, 182; 156, 183; 157, 184; 157, 185; 158, 186; 158, 187; 159, 188; 159, 189; 160, 190; 160, 191; 161, 192; 161, 193; 164, 194; 165, 195; 165, 196; 166, 197; 166, 198; 167, 199; 167, 200; 167, 201; 167, 202; 168, 203; 168, 204; 169, 205; 169, 206; 170, 207; 170, 208; 173, 209; 174, 210; 174, 211; 181, 212; 181, 213; 187, 214; 189, 215; 189, 216; 191, 217; 191, 218; 193, 219; 193, 220; 194, 221; 194, 222; 196, 223; 196, 224; 196, 225; 197, 226; 197, 227; 199, 228; 200, 229; 201, 230; 204, 231; 206, 232; 206, 233; 208, 234; 208, 235; 209, 236; 209, 237; 211, 238; 216, 239; 216, 240; 218, 241; 218, 242; 220, 243; 221, 244; 221, 245; 222, 246; 224, 247; 224, 248; 225, 249; 227, 250; 228, 251; 228, 252; 229, 253; 229, 254; 230, 255; 230, 256; 232, 257; 233, 258; 233, 259; 235, 260; 235, 261; 236, 262; 236, 263; 237, 264; 238, 265; 238, 266; 242, 267; 242, 268; 243, 269; 243, 270; 244, 271; 244, 272; 246, 273; 249, 274; 249, 275; 252, 276; 254, 277; 254, 278; 259, 279; 261, 280; 261, 281; 262, 282; 262, 283; 264, 284; 266, 285; 266, 286; 266, 287; 266, 288; 268, 289; 268, 290; 270, 291; 272, 292; 273, 293; 273, 294; 274, 295; 274, 296; 278, 297; 278, 298; 281, 299; 282, 300; 282, 301; 284, 302; 284, 303; 286, 304; 286, 305; 287, 306; 287, 307; 288, 308; 288, 309; 289, 310; 290, 311; 290, 312; 291, 313; 291, 314; 292, 315; 292, 316; 293, 317; 293, 318; 294, 319; 294, 320; 296, 321; 298, 322; 298, 323; 302, 324; 302, 325; 305, 326; 305, 327; 307, 328; 307, 329; 309, 330; 309, 331; 311, 332; 311, 333; 314, 334; 314, 335; 319, 336; 319, 337; 320, 338; 321, 339; 321, 340; 323, 341; 327, 342; 327, 343; 329, 344; 329, 345; 331, 346; 331, 347; 335, 348; 342, 349; 343, 350; 343, 351; 344, 352; 345, 353; 345, 354; 346, 355; 347, 356; 347, 357; 350, 358; 350, 359; 354, 360; 356, 361; 356, 362; 357, 363; 357, 364; 360, 365; 360, 366; 362, 367; 364, 368; 367, 369; 367, 370; 368, 371; 368, 372
def iterate(MachineClass, stop_function=lambda iterations: iterations < 10000, machines=1000, survival_rate=0.05, mutation_rate=0.075, silent=False): """Creates a bunch of machines, runs them for a number of steps and then gives them a fitness score. The best produce offspring that are passed on to the next generation. Args: setup: Function taking a Machine argument, makes the machine ready machine_class: A class that should inherit from Machine and contain the following methods: setUp(self) [optional]: Run before each new run, should at least call self.reset() for each run. tearDown(self) [optional]: Run after each run. crossover(self, other): Returns a Machine offspring between itself and another Machine. score(self): Score the machine. Lower is better. Can return a tuple of values used to sort the machines from best to worst in fitness. stop_function: An optional function that takes the current generation number and returns True if the processing should stop. machines: The number of machines to create for each generation. steps: The number of instructions each machine is allowed to execute in each run. code_length: Tuple of (minimum code length, maximum code length) for a Machine. survival_ratio: Ratio of the best Machines which are allowed to produce offspring for the next generation. mutation_rate: Rate for each machine's chance of being mutated. """ def make_random(n): return MachineClass().randomize() def run_once(m): m.setUp() m.run() m.tearDown() return m def make_offspring(survivors): a = stochastic_choice(survivors) b = stochastic_choice(survivors) return a.crossover(b) generation = map(make_random, xrange(machines)) survivors = generation if silent: log = lambda s,stream=None: None else: log = _log try: iterations = 0 while not stop_function(iterations, survivors): iterations += 1 log("running ... ") # Run all machines in this generation generation = map(run_once, generation) # Sort machines from best to worst generation = sorted(generation, key=lambda m: m.score()) # Select the best survivors = generation[:int(survival_rate * len(generation))] # Remove code larger than 50 for s in survivors: if len(s.code) >= 50: s.code = s.code[:50] # Remove dead ones survivors = [s for s in survivors if len(s.code)>0] #survivors = [s for s in survivors if len(s.code)<=50] # All dead? start with a new set if len(survivors) == 0: log("\nNo survivors, restarting") survivors = map(make_random, xrange(machines)) generation = survivors continue # Create a new generation based on the survivors. log("crossover ... ") cross = lambda _: make_offspring(survivors) generation = map(cross, xrange(machines)) # Add mutations from time to time for m in generation: if random.random() > mutation_rate: m.mutate() log("\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\n" % (iterations, average(survivors, lambda m: m.score()), average(survivors, lambda m: len(m.code)), average(survivors, lambda m: len(m.stack) + len(m.return_stack)))) except KeyboardInterrupt: pass return survivors
0, module; 1, function_definition; 2, function_name:count_account; 3, parameters; 4, block; 5, identifier:self; 6, identifier:domain; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, return_statement; 13, comment:""" Count the number of accounts for a given domain, sorted by cos :returns: a list of pairs <ClassOfService object>,count """; 14, assignment; 15, assignment; 16, assignment; 17, identifier:i; 18, identifier:cos_list; 19, block; 20, call; 21, identifier:selector; 22, call; 23, identifier:cos_list; 24, call; 25, identifier:ret; 26, list; 27, expression_statement; 28, expression_statement; 29, identifier:list; 30, argument_list; 31, attribute; 32, argument_list; 33, attribute; 34, argument_list; 35, assignment; 36, call; 37, identifier:ret; 38, identifier:domain; 39, identifier:to_selector; 40, identifier:self; 41, identifier:request_list; 42, string; 43, dictionary; 44, identifier:count; 45, call; 46, attribute; 47, argument_list; 48, string_content:CountAccount; 49, pair; 50, identifier:int; 51, argument_list; 52, identifier:ret; 53, identifier:append; 54, tuple; 55, string; 56, identifier:selector; 57, subscript; 58, call; 59, identifier:count; 60, string_content:domain; 61, identifier:i; 62, string; 63, attribute; 64, argument_list; 65, string_content:_content; 66, attribute; 67, identifier:from_dict; 68, identifier:i; 69, identifier:zobjects; 70, identifier:ClassOfService
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 10, 16; 11, 17; 11, 18; 11, 19; 12, 20; 14, 21; 14, 22; 15, 23; 15, 24; 16, 25; 16, 26; 19, 27; 19, 28; 20, 29; 20, 30; 22, 31; 22, 32; 24, 33; 24, 34; 27, 35; 28, 36; 30, 37; 31, 38; 31, 39; 33, 40; 33, 41; 34, 42; 34, 43; 35, 44; 35, 45; 36, 46; 36, 47; 42, 48; 43, 49; 45, 50; 45, 51; 46, 52; 46, 53; 47, 54; 49, 55; 49, 56; 51, 57; 54, 58; 54, 59; 55, 60; 57, 61; 57, 62; 58, 63; 58, 64; 62, 65; 63, 66; 63, 67; 64, 68; 66, 69; 66, 70
def count_account(self, domain): """ Count the number of accounts for a given domain, sorted by cos :returns: a list of pairs <ClassOfService object>,count """ selector = domain.to_selector() cos_list = self.request_list('CountAccount', {'domain': selector}) ret = [] for i in cos_list: count = int(i['_content']) ret.append((zobjects.ClassOfService.from_dict(i), count)) return list(ret)
0, module; 1, function_definition; 2, function_name:search_directory; 3, parameters; 4, block; 5, identifier:self; 6, dictionary_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, return_statement; 13, identifier:kwargs; 14, comment:""" SearchAccount is deprecated, using SearchDirectory :param query: Query string - should be an LDAP-style filter string (RFC 2254) :param limit: The maximum number of accounts to return (0 is default and means all) :param offset: The starting offset (0, 25, etc) :param domain: The domain name to limit the search to :param applyCos: applyCos - Flag whether or not to apply the COS policy to account. Specify 0 (false) if only requesting attrs that aren't inherited from COS :param applyConfig: whether or not to apply the global config attrs to account. specify 0 (false) if only requesting attrs that aren't inherited from global config :param sortBy: Name of attribute to sort on. Default is the account name. :param types: Comma-separated list of types to return. Legal values are: accounts|distributionlists|aliases|resources|domains|coses (default is accounts) :param sortAscending: Whether to sort in ascending order. Default is 1 (true) :param countOnly: Whether response should be count only. Default is 0 (false) :param attrs: Comma-seperated list of attrs to return ("displayName", "zimbraId", "zimbraAccountStatus") :return: dict of list of "account" "alias" "dl" "calresource" "domain" "cos" """; 15, assignment; 16, assignment; 17, assignment; 18, pattern_list; 19, call; 20, block; 21, identifier:result; 22, identifier:search_response; 23, call; 24, identifier:result; 25, dictionary; 26, identifier:items; 27, dictionary; 28, identifier:obj_type; 29, identifier:func; 30, attribute; 31, argument_list; 32, if_statement; 33, attribute; 34, argument_list; 35, pair; 36, pair; 37, pair; 38, pair; 39, pair; 40, comment:# "alias": TODO,; 41, identifier:items; 42, identifier:items; 43, comparison_operator:obj_type in search_response; 44, block; 45, identifier:self; 46, identifier:request; 47, string; 48, identifier:kwargs; 49, string:"account"; 50, attribute; 51, string:"domain"; 52, attribute; 53, string:"dl"; 54, attribute; 55, string:"cos"; 56, attribute; 57, string:"calresource"; 58, attribute; 59, identifier:obj_type; 60, identifier:search_response; 61, if_statement; 62, string_content:SearchDirectory; 63, attribute; 64, identifier:from_dict; 65, attribute; 66, identifier:from_dict; 67, attribute; 68, identifier:from_dict; 69, attribute; 70, identifier:from_dict; 71, attribute; 72, identifier:from_dict; 73, call; 74, block; 75, else_clause; 76, identifier:zobjects; 77, identifier:Account; 78, identifier:zobjects; 79, identifier:Domain; 80, identifier:zobjects; 81, identifier:DistributionList; 82, identifier:zobjects; 83, identifier:COS; 84, identifier:zobjects; 85, identifier:CalendarResource; 86, identifier:isinstance; 87, argument_list; 88, expression_statement; 89, block; 90, subscript; 91, identifier:list; 92, assignment; 93, expression_statement; 94, identifier:search_response; 95, identifier:obj_type; 96, subscript; 97, list_comprehension; 98, assignment; 99, identifier:result; 100, identifier:obj_type; 101, call; 102, for_in_clause; 103, subscript; 104, call; 105, identifier:func; 106, argument_list; 107, identifier:v; 108, subscript; 109, identifier:result; 110, identifier:obj_type; 111, identifier:func; 112, argument_list; 113, identifier:v; 114, identifier:search_response; 115, identifier:obj_type; 116, subscript; 117, identifier:search_response; 118, identifier:obj_type
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 11, 19; 11, 20; 12, 21; 15, 22; 15, 23; 16, 24; 16, 25; 17, 26; 17, 27; 18, 28; 18, 29; 19, 30; 19, 31; 20, 32; 23, 33; 23, 34; 27, 35; 27, 36; 27, 37; 27, 38; 27, 39; 27, 40; 30, 41; 30, 42; 32, 43; 32, 44; 33, 45; 33, 46; 34, 47; 34, 48; 35, 49; 35, 50; 36, 51; 36, 52; 37, 53; 37, 54; 38, 55; 38, 56; 39, 57; 39, 58; 43, 59; 43, 60; 44, 61; 47, 62; 50, 63; 50, 64; 52, 65; 52, 66; 54, 67; 54, 68; 56, 69; 56, 70; 58, 71; 58, 72; 61, 73; 61, 74; 61, 75; 63, 76; 63, 77; 65, 78; 65, 79; 67, 80; 67, 81; 69, 82; 69, 83; 71, 84; 71, 85; 73, 86; 73, 87; 74, 88; 75, 89; 87, 90; 87, 91; 88, 92; 89, 93; 90, 94; 90, 95; 92, 96; 92, 97; 93, 98; 96, 99; 96, 100; 97, 101; 97, 102; 98, 103; 98, 104; 101, 105; 101, 106; 102, 107; 102, 108; 103, 109; 103, 110; 104, 111; 104, 112; 106, 113; 108, 114; 108, 115; 112, 116; 116, 117; 116, 118
def search_directory(self, **kwargs): """ SearchAccount is deprecated, using SearchDirectory :param query: Query string - should be an LDAP-style filter string (RFC 2254) :param limit: The maximum number of accounts to return (0 is default and means all) :param offset: The starting offset (0, 25, etc) :param domain: The domain name to limit the search to :param applyCos: applyCos - Flag whether or not to apply the COS policy to account. Specify 0 (false) if only requesting attrs that aren't inherited from COS :param applyConfig: whether or not to apply the global config attrs to account. specify 0 (false) if only requesting attrs that aren't inherited from global config :param sortBy: Name of attribute to sort on. Default is the account name. :param types: Comma-separated list of types to return. Legal values are: accounts|distributionlists|aliases|resources|domains|coses (default is accounts) :param sortAscending: Whether to sort in ascending order. Default is 1 (true) :param countOnly: Whether response should be count only. Default is 0 (false) :param attrs: Comma-seperated list of attrs to return ("displayName", "zimbraId", "zimbraAccountStatus") :return: dict of list of "account" "alias" "dl" "calresource" "domain" "cos" """ search_response = self.request('SearchDirectory', kwargs) result = {} items = { "account": zobjects.Account.from_dict, "domain": zobjects.Domain.from_dict, "dl": zobjects.DistributionList.from_dict, "cos": zobjects.COS.from_dict, "calresource": zobjects.CalendarResource.from_dict # "alias": TODO, } for obj_type, func in items.items(): if obj_type in search_response: if isinstance(search_response[obj_type], list): result[obj_type] = [ func(v) for v in search_response[obj_type]] else: result[obj_type] = func(search_response[obj_type]) return result
0, module; 1, function_definition; 2, function_name:search; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:kwargs; 13, comment:""" Search object in account :returns: a dic where value c contains the list of results (if there is any). Example : { 'more': '0', 'offset': '0', 'sortBy': 'dateDesc', 'c': [ { 'id': '-261', 'm': {'id': '261', 's': '2556', 'l': '2'}, 'u': '0', 'd': '1450714720000', 'sf': '1450714720000', 'e': {'t': 'f', 'd': 'kokopu', 'a': '[email protected]'}, 'n': '1', 'fr': {'_content': 'Hello there !'}, 'su': {'_content': 'The subject is cool'} } ] """; 14, assignment; 15, assignment; 16, call; 17, identifier:content; 18, identifier:kwargs; 19, subscript; 20, dictionary; 21, attribute; 22, argument_list; 23, identifier:content; 24, string; 25, pair; 26, identifier:self; 27, identifier:request; 28, string; 29, identifier:content; 30, string_content:query; 31, string; 32, identifier:query; 33, string_content:Search; 34, string_content:_content
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 9, 14; 10, 15; 11, 16; 14, 17; 14, 18; 15, 19; 15, 20; 16, 21; 16, 22; 19, 23; 19, 24; 20, 25; 21, 26; 21, 27; 22, 28; 22, 29; 24, 30; 25, 31; 25, 32; 28, 33; 31, 34
def search(self, query, **kwargs): """ Search object in account :returns: a dic where value c contains the list of results (if there is any). Example : { 'more': '0', 'offset': '0', 'sortBy': 'dateDesc', 'c': [ { 'id': '-261', 'm': {'id': '261', 's': '2556', 'l': '2'}, 'u': '0', 'd': '1450714720000', 'sf': '1450714720000', 'e': {'t': 'f', 'd': 'kokopu', 'a': '[email protected]'}, 'n': '1', 'fr': {'_content': 'Hello there !'}, 'su': {'_content': 'The subject is cool'} } ] """ content = kwargs content['query'] = {'_content': query} return self.request('Search', content)
0, module; 1, function_definition; 2, function_name:_call_zincrby; 3, parameters; 4, block; 5, identifier:self; 6, identifier:command; 7, identifier:value; 8, list_splat_pattern; 9, dictionary_splat_pattern; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:args; 14, identifier:kwargs; 15, comment:""" This command update a score of a given value. But it can be a new value of the sorted set, so we index it. """; 16, attribute; 17, block; 18, call; 19, identifier:self; 20, identifier:indexable; 21, expression_statement; 22, attribute; 23, argument_list; 24, call; 25, identifier:self; 26, identifier:_traverse_command; 27, identifier:command; 28, identifier:value; 29, list_splat; 30, dictionary_splat; 31, attribute; 32, argument_list; 33, identifier:args; 34, identifier:kwargs; 35, identifier:self; 36, identifier:index; 37, list; 38, identifier:value
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 8, 13; 9, 14; 10, 15; 11, 16; 11, 17; 12, 18; 16, 19; 16, 20; 17, 21; 18, 22; 18, 23; 21, 24; 22, 25; 22, 26; 23, 27; 23, 28; 23, 29; 23, 30; 24, 31; 24, 32; 29, 33; 30, 34; 31, 35; 31, 36; 32, 37; 37, 38
def _call_zincrby(self, command, value, *args, **kwargs): """ This command update a score of a given value. But it can be a new value of the sorted set, so we index it. """ if self.indexable: self.index([value]) return self._traverse_command(command, value, *args, **kwargs)
0, module; 1, function_definition; 2, function_name:_extract_value_from_storage; 3, parameters; 4, block; 5, identifier:self; 6, identifier:string; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, return_statement; 11, comment:"""Taking a string that was a member of the zset, extract the value and pk Parameters ---------- string: str The member extracted from the sorted set Returns ------- tuple Tuple with the value and the pk, extracted from the string """; 12, assignment; 13, assignment; 14, expression_list; 15, identifier:parts; 16, call; 17, identifier:pk; 18, call; 19, call; 20, identifier:pk; 21, attribute; 22, argument_list; 23, attribute; 24, argument_list; 25, attribute; 26, argument_list; 27, identifier:string; 28, identifier:split; 29, attribute; 30, identifier:parts; 31, identifier:pop; 32, attribute; 33, identifier:join; 34, identifier:parts; 35, identifier:self; 36, identifier:separator; 37, identifier:self; 38, identifier:separator
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 10, 14; 12, 15; 12, 16; 13, 17; 13, 18; 14, 19; 14, 20; 16, 21; 16, 22; 18, 23; 18, 24; 19, 25; 19, 26; 21, 27; 21, 28; 22, 29; 23, 30; 23, 31; 25, 32; 25, 33; 26, 34; 29, 35; 29, 36; 32, 37; 32, 38
def _extract_value_from_storage(self, string): """Taking a string that was a member of the zset, extract the value and pk Parameters ---------- string: str The member extracted from the sorted set Returns ------- tuple Tuple with the value and the pk, extracted from the string """ parts = string.split(self.separator) pk = parts.pop() return self.separator.join(parts), pk
0, module; 1, function_definition; 2, function_name:get_boundaries; 3, parameters; 4, block; 5, identifier:self; 6, identifier:filter_type; 7, identifier:value; 8, expression_statement; 9, assert_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, return_statement; 15, comment:"""Compute the boundaries to pass to zrangebylex depending of the filter type The third return value, ``exclude`` is ``None`` except for the filters `lt` and `gt` because we cannot explicitly exclude it when querying the sorted-set For the parameters, see BaseRangeIndex.store Notes ----- For zrangebylex: - `(` means "not included" - `[` means "included" - `\xff` is the last char, it allows to say "starting with" - `-` alone means "from the very beginning" - `+` alone means "to the very end" """; 16, comparison_operator:filter_type in self.handled_suffixes; 17, assignment; 18, assignment; 19, assignment; 20, comparison_operator:filter_type in (None, 'eq'); 21, comment:# we include the separator to only get the members with the exact value; 22, block; 23, elif_clause; 24, elif_clause; 25, elif_clause; 26, elif_clause; 27, elif_clause; 28, expression_list; 29, identifier:filter_type; 30, attribute; 31, identifier:start; 32, string; 33, identifier:end; 34, string; 35, identifier:exclude; 36, None; 37, identifier:filter_type; 38, tuple; 39, expression_statement; 40, expression_statement; 41, comparison_operator:filter_type == 'gt'; 42, comment:# starting at the value, excluded; 43, block; 44, comparison_operator:filter_type == 'gte'; 45, comment:# starting at the value, included; 46, block; 47, comparison_operator:filter_type == 'lt'; 48, comment:# ending with the value, excluded; 49, block; 50, comparison_operator:filter_type == 'lte'; 51, comment:# ending with the value, included (but not starting with, hence the separator); 52, block; 53, comparison_operator:filter_type == 'startswith'; 54, comment:# using `\xff` to simulate "startswith"; 55, block; 56, identifier:start; 57, identifier:end; 58, identifier:exclude; 59, identifier:self; 60, identifier:handled_suffixes; 61, string_content:-; 62, string_content:+; 63, None; 64, string; 65, assignment; 66, assignment; 67, identifier:filter_type; 68, string; 69, expression_statement; 70, expression_statement; 71, identifier:filter_type; 72, string; 73, expression_statement; 74, identifier:filter_type; 75, string; 76, expression_statement; 77, expression_statement; 78, identifier:filter_type; 79, string; 80, expression_statement; 81, expression_statement; 82, identifier:filter_type; 83, string; 84, expression_statement; 85, expression_statement; 86, string_content:eq; 87, identifier:start; 88, binary_operator:u'[%s%s' % (value, self.separator); 89, identifier:end; 90, binary_operator:start.encode('utf-8') + b'\xff'; 91, string_content:gt; 92, assignment; 93, assignment; 94, string_content:gte; 95, assignment; 96, string_content:lt; 97, assignment; 98, assignment; 99, string_content:lte; 100, assignment; 101, assignment; 102, string_content:startswith; 103, assignment; 104, assignment; 105, string; 106, tuple; 107, call; 108, string; 109, identifier:start; 110, binary_operator:u'(%s' % value; 111, identifier:exclude; 112, identifier:value; 113, identifier:start; 114, binary_operator:u'[%s' % value; 115, identifier:end; 116, binary_operator:u'(%s' % value; 117, identifier:exclude; 118, identifier:value; 119, identifier:end; 120, binary_operator:u'[%s%s' % (value, self.separator); 121, identifier:end; 122, binary_operator:end.encode('utf-8') + b'\xff'; 123, identifier:start; 124, binary_operator:u'[%s' % value; 125, identifier:end; 126, binary_operator:start.encode('utf-8') + b'\xff'; 127, string_content:[%s%s; 128, identifier:value; 129, attribute; 130, attribute; 131, argument_list; 132, string_content; 133, string; 134, identifier:value; 135, string; 136, identifier:value; 137, string; 138, identifier:value; 139, string; 140, tuple; 141, call; 142, string; 143, string; 144, identifier:value; 145, call; 146, string; 147, identifier:self; 148, identifier:separator; 149, identifier:start; 150, identifier:encode; 151, string; 152, escape_sequence:\xff; 153, string_content:(%s; 154, string_content:[%s; 155, string_content:(%s; 156, string_content:[%s%s; 157, identifier:value; 158, attribute; 159, attribute; 160, argument_list; 161, string_content; 162, string_content:[%s; 163, attribute; 164, argument_list; 165, string_content; 166, string_content:utf-8; 167, identifier:self; 168, identifier:separator; 169, identifier:end; 170, identifier:encode; 171, string; 172, escape_sequence:\xff; 173, identifier:start; 174, identifier:encode; 175, string; 176, escape_sequence:\xff; 177, string_content:utf-8; 178, string_content:utf-8
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 8, 15; 9, 16; 10, 17; 11, 18; 12, 19; 13, 20; 13, 21; 13, 22; 13, 23; 13, 24; 13, 25; 13, 26; 13, 27; 14, 28; 16, 29; 16, 30; 17, 31; 17, 32; 18, 33; 18, 34; 19, 35; 19, 36; 20, 37; 20, 38; 22, 39; 22, 40; 23, 41; 23, 42; 23, 43; 24, 44; 24, 45; 24, 46; 25, 47; 25, 48; 25, 49; 26, 50; 26, 51; 26, 52; 27, 53; 27, 54; 27, 55; 28, 56; 28, 57; 28, 58; 30, 59; 30, 60; 32, 61; 34, 62; 38, 63; 38, 64; 39, 65; 40, 66; 41, 67; 41, 68; 43, 69; 43, 70; 44, 71; 44, 72; 46, 73; 47, 74; 47, 75; 49, 76; 49, 77; 50, 78; 50, 79; 52, 80; 52, 81; 53, 82; 53, 83; 55, 84; 55, 85; 64, 86; 65, 87; 65, 88; 66, 89; 66, 90; 68, 91; 69, 92; 70, 93; 72, 94; 73, 95; 75, 96; 76, 97; 77, 98; 79, 99; 80, 100; 81, 101; 83, 102; 84, 103; 85, 104; 88, 105; 88, 106; 90, 107; 90, 108; 92, 109; 92, 110; 93, 111; 93, 112; 95, 113; 95, 114; 97, 115; 97, 116; 98, 117; 98, 118; 100, 119; 100, 120; 101, 121; 101, 122; 103, 123; 103, 124; 104, 125; 104, 126; 105, 127; 106, 128; 106, 129; 107, 130; 107, 131; 108, 132; 110, 133; 110, 134; 114, 135; 114, 136; 116, 137; 116, 138; 120, 139; 120, 140; 122, 141; 122, 142; 124, 143; 124, 144; 126, 145; 126, 146; 129, 147; 129, 148; 130, 149; 130, 150; 131, 151; 132, 152; 133, 153; 135, 154; 137, 155; 139, 156; 140, 157; 140, 158; 141, 159; 141, 160; 142, 161; 143, 162; 145, 163; 145, 164; 146, 165; 151, 166; 158, 167; 158, 168; 159, 169; 159, 170; 160, 171; 161, 172; 163, 173; 163, 174; 164, 175; 165, 176; 171, 177; 175, 178
def get_boundaries(self, filter_type, value): """Compute the boundaries to pass to zrangebylex depending of the filter type The third return value, ``exclude`` is ``None`` except for the filters `lt` and `gt` because we cannot explicitly exclude it when querying the sorted-set For the parameters, see BaseRangeIndex.store Notes ----- For zrangebylex: - `(` means "not included" - `[` means "included" - `\xff` is the last char, it allows to say "starting with" - `-` alone means "from the very beginning" - `+` alone means "to the very end" """ assert filter_type in self.handled_suffixes start = '-' end = '+' exclude = None if filter_type in (None, 'eq'): # we include the separator to only get the members with the exact value start = u'[%s%s' % (value, self.separator) end = start.encode('utf-8') + b'\xff' elif filter_type == 'gt': # starting at the value, excluded start = u'(%s' % value exclude = value elif filter_type == 'gte': # starting at the value, included start = u'[%s' % value elif filter_type == 'lt': # ending with the value, excluded end = u'(%s' % value exclude = value elif filter_type == 'lte': # ending with the value, included (but not starting with, hence the separator) end = u'[%s%s' % (value, self.separator) end = end.encode('utf-8') + b'\xff' elif filter_type == 'startswith': # using `\xff` to simulate "startswith" start = u'[%s' % value end = start.encode('utf-8') + b'\xff' return start, end, exclude
0, module; 1, function_definition; 2, function_name:get_boundaries; 3, parameters; 4, block; 5, identifier:self; 6, identifier:filter_type; 7, identifier:value; 8, expression_statement; 9, assert_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, return_statement; 15, comment:"""Compute the boundaries to pass to the sorted-set command depending of the filter type The third return value, ``exclude`` is always ``None`` because we can easily restrict the score to filter on in the sorted-set. For the parameters, see BaseRangeIndex.store Notes ----- For zrangebyscore: - `(` means "not included" - `-inf` alone means "from the very beginning" - `+inf` alone means "to the very end" """; 16, comparison_operator:filter_type in self.handled_suffixes; 17, assignment; 18, assignment; 19, assignment; 20, comparison_operator:filter_type in (None, 'eq'); 21, comment:# only one score; 22, block; 23, elif_clause; 24, elif_clause; 25, elif_clause; 26, elif_clause; 27, expression_list; 28, identifier:filter_type; 29, attribute; 30, identifier:start; 31, string; 32, identifier:end; 33, string; 34, identifier:exclude; 35, None; 36, identifier:filter_type; 37, tuple; 38, expression_statement; 39, comparison_operator:filter_type == 'gt'; 40, block; 41, comparison_operator:filter_type == 'gte'; 42, block; 43, comparison_operator:filter_type == 'lt'; 44, block; 45, comparison_operator:filter_type == 'lte'; 46, block; 47, identifier:start; 48, identifier:end; 49, identifier:exclude; 50, identifier:self; 51, identifier:handled_suffixes; 52, string_content:-inf; 53, string_content:+inf; 54, None; 55, string; 56, assignment; 57, identifier:filter_type; 58, string; 59, expression_statement; 60, identifier:filter_type; 61, string; 62, expression_statement; 63, identifier:filter_type; 64, string; 65, expression_statement; 66, identifier:filter_type; 67, string; 68, expression_statement; 69, string_content:eq; 70, identifier:start; 71, assignment; 72, string_content:gt; 73, assignment; 74, string_content:gte; 75, assignment; 76, string_content:lt; 77, assignment; 78, string_content:lte; 79, assignment; 80, identifier:end; 81, identifier:value; 82, identifier:start; 83, binary_operator:'(%s' % value; 84, identifier:start; 85, identifier:value; 86, identifier:end; 87, binary_operator:'(%s' % value; 88, identifier:end; 89, identifier:value; 90, string; 91, identifier:value; 92, string; 93, identifier:value; 94, string_content:(%s; 95, string_content:(%s
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 8, 15; 9, 16; 10, 17; 11, 18; 12, 19; 13, 20; 13, 21; 13, 22; 13, 23; 13, 24; 13, 25; 13, 26; 14, 27; 16, 28; 16, 29; 17, 30; 17, 31; 18, 32; 18, 33; 19, 34; 19, 35; 20, 36; 20, 37; 22, 38; 23, 39; 23, 40; 24, 41; 24, 42; 25, 43; 25, 44; 26, 45; 26, 46; 27, 47; 27, 48; 27, 49; 29, 50; 29, 51; 31, 52; 33, 53; 37, 54; 37, 55; 38, 56; 39, 57; 39, 58; 40, 59; 41, 60; 41, 61; 42, 62; 43, 63; 43, 64; 44, 65; 45, 66; 45, 67; 46, 68; 55, 69; 56, 70; 56, 71; 58, 72; 59, 73; 61, 74; 62, 75; 64, 76; 65, 77; 67, 78; 68, 79; 71, 80; 71, 81; 73, 82; 73, 83; 75, 84; 75, 85; 77, 86; 77, 87; 79, 88; 79, 89; 83, 90; 83, 91; 87, 92; 87, 93; 90, 94; 92, 95
def get_boundaries(self, filter_type, value): """Compute the boundaries to pass to the sorted-set command depending of the filter type The third return value, ``exclude`` is always ``None`` because we can easily restrict the score to filter on in the sorted-set. For the parameters, see BaseRangeIndex.store Notes ----- For zrangebyscore: - `(` means "not included" - `-inf` alone means "from the very beginning" - `+inf` alone means "to the very end" """ assert filter_type in self.handled_suffixes start = '-inf' end = '+inf' exclude = None if filter_type in (None, 'eq'): # only one score start = end = value elif filter_type == 'gt': start = '(%s' % value elif filter_type == 'gte': start = value elif filter_type == 'lt': end = '(%s' % value elif filter_type == 'lte': end = value return start, end, exclude
0, module; 1, function_definition; 2, function_name:_combine_sets; 3, parameters; 4, block; 5, identifier:self; 6, identifier:sets; 7, identifier:final_set; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:""" Given a list of set, combine them to create the final set that will be used to make the final redis call. If we have a least a sorted set, use zinterstore insted of sunionstore """; 12, attribute; 13, block; 14, else_clause; 15, identifier:final_set; 16, identifier:self; 17, identifier:_has_sortedsets; 18, expression_statement; 19, block; 20, call; 21, expression_statement; 22, attribute; 23, argument_list; 24, assignment; 25, call; 26, identifier:zinterstore; 27, identifier:final_set; 28, call; 29, identifier:final_set; 30, call; 31, attribute; 32, argument_list; 33, identifier:list; 34, argument_list; 35, attribute; 36, argument_list; 37, attribute; 38, identifier:get_connection; 39, identifier:sets; 40, call; 41, identifier:_combine_sets; 42, identifier:sets; 43, identifier:final_set; 44, identifier:self; 45, identifier:cls; 46, identifier:super; 47, argument_list; 48, identifier:ExtendedCollectionManager; 49, identifier:self
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 8, 11; 9, 12; 9, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 14, 19; 18, 20; 19, 21; 20, 22; 20, 23; 21, 24; 22, 25; 22, 26; 23, 27; 23, 28; 24, 29; 24, 30; 25, 31; 25, 32; 28, 33; 28, 34; 30, 35; 30, 36; 31, 37; 31, 38; 34, 39; 35, 40; 35, 41; 36, 42; 36, 43; 37, 44; 37, 45; 40, 46; 40, 47; 47, 48; 47, 49
def _combine_sets(self, sets, final_set): """ Given a list of set, combine them to create the final set that will be used to make the final redis call. If we have a least a sorted set, use zinterstore insted of sunionstore """ if self._has_sortedsets: self.cls.get_connection().zinterstore(final_set, list(sets)) else: final_set = super(ExtendedCollectionManager, self)._combine_sets(sets, final_set) return final_set
0, module; 1, function_definition; 2, function_name:_final_redis_call; 3, parameters; 4, block; 5, identifier:self; 6, identifier:final_set; 7, identifier:sort_options; 8, expression_statement; 9, expression_statement; 10, comment:# we have a sorted set without need to sort, use zrange; 11, if_statement; 12, comment:# we have a stored collection, without other filter, and no need to; 13, comment:# sort, use lrange; 14, if_statement; 15, comment:# normal call; 16, return_statement; 17, comment:""" The final redis call to obtain the values to return from the "final_set" with some sort options. IIf we have at leaset a sorted set and if we don't have any sort options, call zrange on the final set wich is the result of a call to zinterstore. """; 18, assignment; 19, boolean_operator; 20, block; 21, boolean_operator; 22, block; 23, call; 24, identifier:conn; 25, call; 26, attribute; 27, comparison_operator:sort_options is None; 28, return_statement; 29, boolean_operator; 30, line_continuation:\; 31, parenthesized_expression; 32, return_statement; 33, attribute; 34, argument_list; 35, attribute; 36, argument_list; 37, identifier:self; 38, identifier:_has_sortedsets; 39, identifier:sort_options; 40, None; 41, call; 42, boolean_operator; 43, line_continuation:\; 44, comparison_operator:len(self._lazy_collection['intersects']) == 1; 45, boolean_operator; 46, call; 47, call; 48, identifier:_final_redis_call; 49, identifier:final_set; 50, identifier:sort_options; 51, attribute; 52, identifier:get_connection; 53, attribute; 54, argument_list; 55, attribute; 56, not_operator; 57, call; 58, integer:1; 59, comparison_operator:sort_options is None; 60, comparison_operator:sort_options == {'by': 'nosort'}; 61, attribute; 62, argument_list; 63, identifier:super; 64, argument_list; 65, identifier:self; 66, identifier:cls; 67, identifier:conn; 68, identifier:zrange; 69, identifier:final_set; 70, integer:0; 71, unary_operator; 72, identifier:self; 73, identifier:stored_key; 74, subscript; 75, identifier:len; 76, argument_list; 77, identifier:sort_options; 78, None; 79, identifier:sort_options; 80, dictionary; 81, identifier:conn; 82, identifier:lrange; 83, identifier:final_set; 84, integer:0; 85, unary_operator; 86, identifier:ExtendedCollectionManager; 87, identifier:self; 88, integer:1; 89, attribute; 90, string; 91, subscript; 92, pair; 93, integer:1; 94, identifier:self; 95, identifier:_lazy_collection; 96, string_content:sets; 97, attribute; 98, string; 99, string; 100, string; 101, identifier:self; 102, identifier:_lazy_collection; 103, string_content:intersects; 104, string_content:by; 105, string_content:nosort
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 8, 17; 9, 18; 11, 19; 11, 20; 14, 21; 14, 22; 16, 23; 18, 24; 18, 25; 19, 26; 19, 27; 20, 28; 21, 29; 21, 30; 21, 31; 22, 32; 23, 33; 23, 34; 25, 35; 25, 36; 26, 37; 26, 38; 27, 39; 27, 40; 28, 41; 29, 42; 29, 43; 29, 44; 31, 45; 32, 46; 33, 47; 33, 48; 34, 49; 34, 50; 35, 51; 35, 52; 41, 53; 41, 54; 42, 55; 42, 56; 44, 57; 44, 58; 45, 59; 45, 60; 46, 61; 46, 62; 47, 63; 47, 64; 51, 65; 51, 66; 53, 67; 53, 68; 54, 69; 54, 70; 54, 71; 55, 72; 55, 73; 56, 74; 57, 75; 57, 76; 59, 77; 59, 78; 60, 79; 60, 80; 61, 81; 61, 82; 62, 83; 62, 84; 62, 85; 64, 86; 64, 87; 71, 88; 74, 89; 74, 90; 76, 91; 80, 92; 85, 93; 89, 94; 89, 95; 90, 96; 91, 97; 91, 98; 92, 99; 92, 100; 97, 101; 97, 102; 98, 103; 99, 104; 100, 105
def _final_redis_call(self, final_set, sort_options): """ The final redis call to obtain the values to return from the "final_set" with some sort options. IIf we have at leaset a sorted set and if we don't have any sort options, call zrange on the final set wich is the result of a call to zinterstore. """ conn = self.cls.get_connection() # we have a sorted set without need to sort, use zrange if self._has_sortedsets and sort_options is None: return conn.zrange(final_set, 0, -1) # we have a stored collection, without other filter, and no need to # sort, use lrange if self.stored_key and not self._lazy_collection['sets']\ and len(self._lazy_collection['intersects']) == 1\ and (sort_options is None or sort_options == {'by': 'nosort'}): return conn.lrange(final_set, 0, -1) # normal call return super(ExtendedCollectionManager, self)._final_redis_call( final_set, sort_options)
0, module; 1, function_definition; 2, function_name:_collection_length; 3, parameters; 4, block; 5, identifier:self; 6, identifier:final_set; 7, expression_statement; 8, expression_statement; 9, comment:# we have a sorted set without need to sort, use zcard; 10, if_statement; 11, comment:# normal call; 12, return_statement; 13, comment:""" Return the length of the final collection, directly asking redis for the count without calling sort """; 14, assignment; 15, attribute; 16, block; 17, comment:# we have a stored collection, without other filter, use llen; 18, elif_clause; 19, call; 20, identifier:conn; 21, call; 22, identifier:self; 23, identifier:_has_sortedsets; 24, return_statement; 25, boolean_operator; 26, block; 27, attribute; 28, argument_list; 29, attribute; 30, argument_list; 31, call; 32, boolean_operator; 33, line_continuation:\; 34, comparison_operator:len(self._lazy_collection['intersects']) == 1; 35, return_statement; 36, call; 37, identifier:_collection_length; 38, identifier:final_set; 39, attribute; 40, identifier:get_connection; 41, attribute; 42, argument_list; 43, attribute; 44, not_operator; 45, call; 46, integer:1; 47, call; 48, identifier:super; 49, argument_list; 50, identifier:self; 51, identifier:cls; 52, identifier:conn; 53, identifier:zcard; 54, identifier:final_set; 55, identifier:self; 56, identifier:stored_key; 57, subscript; 58, identifier:len; 59, argument_list; 60, attribute; 61, argument_list; 62, identifier:ExtendedCollectionManager; 63, identifier:self; 64, attribute; 65, string; 66, subscript; 67, identifier:conn; 68, identifier:llen; 69, identifier:final_set; 70, identifier:self; 71, identifier:_lazy_collection; 72, string_content:sets; 73, attribute; 74, string; 75, identifier:self; 76, identifier:_lazy_collection; 77, string_content:intersects
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 10, 15; 10, 16; 10, 17; 10, 18; 12, 19; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 18, 25; 18, 26; 19, 27; 19, 28; 21, 29; 21, 30; 24, 31; 25, 32; 25, 33; 25, 34; 26, 35; 27, 36; 27, 37; 28, 38; 29, 39; 29, 40; 31, 41; 31, 42; 32, 43; 32, 44; 34, 45; 34, 46; 35, 47; 36, 48; 36, 49; 39, 50; 39, 51; 41, 52; 41, 53; 42, 54; 43, 55; 43, 56; 44, 57; 45, 58; 45, 59; 47, 60; 47, 61; 49, 62; 49, 63; 57, 64; 57, 65; 59, 66; 60, 67; 60, 68; 61, 69; 64, 70; 64, 71; 65, 72; 66, 73; 66, 74; 73, 75; 73, 76; 74, 77
def _collection_length(self, final_set): """ Return the length of the final collection, directly asking redis for the count without calling sort """ conn = self.cls.get_connection() # we have a sorted set without need to sort, use zcard if self._has_sortedsets: return conn.zcard(final_set) # we have a stored collection, without other filter, use llen elif self.stored_key and not self._lazy_collection['sets']\ and len(self._lazy_collection['intersects']) == 1: return conn.llen(final_set) # normal call return super(ExtendedCollectionManager, self)._collection_length(final_set)
0, module; 1, function_definition; 2, function_name:_prepare_sort_by_score; 3, parameters; 4, block; 5, identifier:self; 6, identifier:values; 7, identifier:sort_options; 8, expression_statement; 9, comment:# create the keys; 10, expression_statement; 11, comment:# ask to sort on our new keys; 12, expression_statement; 13, comment:# retrieve original sort parameters; 14, for_statement; 15, comment:# if we want to get the score with values/values_list; 16, if_statement; 17, return_statement; 18, comment:""" Create the key to sort on the sorted set references in self._sort_by_sortedset and adapte sort options """; 19, assignment; 20, assignment; 21, identifier:key; 22, tuple; 23, block; 24, call; 25, block; 26, expression_list; 27, pattern_list; 28, call; 29, subscript; 30, binary_operator:'%s:*' % base_tmp_key; 31, string; 32, string; 33, string; 34, string; 35, if_statement; 36, attribute; 37, argument_list; 38, try_statement; 39, identifier:base_tmp_key; 40, identifier:tmp_keys; 41, identifier:base_tmp_key; 42, identifier:tmp_keys; 43, attribute; 44, argument_list; 45, identifier:sort_options; 46, string; 47, string; 48, identifier:base_tmp_key; 49, string_content:desc; 50, string_content:alpha; 51, string_content:get; 52, string_content:store; 53, comparison_operator:key in self._sort_by_sortedset; 54, block; 55, identifier:sort_options; 56, identifier:get; 57, string; 58, block; 59, except_clause; 60, else_clause; 61, identifier:self; 62, identifier:_zset_to_keys; 63, keyword_argument; 64, keyword_argument; 65, string_content:by; 66, string_content:%s:*; 67, identifier:key; 68, attribute; 69, expression_statement; 70, string_content:get; 71, expression_statement; 72, block; 73, block; 74, identifier:key; 75, subscript; 76, identifier:values; 77, identifier:values; 78, identifier:self; 79, identifier:_sort_by_sortedset; 80, assignment; 81, assignment; 82, pass_statement; 83, expression_statement; 84, attribute; 85, string; 86, subscript; 87, subscript; 88, identifier:pos; 89, call; 90, assignment; 91, identifier:self; 92, identifier:_sort_by_sortedset; 93, string_content:by; 94, identifier:sort_options; 95, identifier:key; 96, attribute; 97, identifier:key; 98, attribute; 99, argument_list; 100, subscript; 101, binary_operator:'%s:*' % base_tmp_key; 102, identifier:self; 103, identifier:_sort_by_sortedset; 104, subscript; 105, identifier:index; 106, identifier:SORTED_SCORE; 107, subscript; 108, identifier:pos; 109, string; 110, identifier:base_tmp_key; 111, identifier:sort_options; 112, string; 113, identifier:sort_options; 114, string; 115, string_content:%s:*; 116, string_content:get; 117, string_content:get
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 8, 18; 10, 19; 12, 20; 14, 21; 14, 22; 14, 23; 16, 24; 16, 25; 17, 26; 19, 27; 19, 28; 20, 29; 20, 30; 22, 31; 22, 32; 22, 33; 22, 34; 23, 35; 24, 36; 24, 37; 25, 38; 26, 39; 26, 40; 27, 41; 27, 42; 28, 43; 28, 44; 29, 45; 29, 46; 30, 47; 30, 48; 31, 49; 32, 50; 33, 51; 34, 52; 35, 53; 35, 54; 36, 55; 36, 56; 37, 57; 38, 58; 38, 59; 38, 60; 43, 61; 43, 62; 44, 63; 44, 64; 46, 65; 47, 66; 53, 67; 53, 68; 54, 69; 57, 70; 58, 71; 59, 72; 60, 73; 63, 74; 63, 75; 64, 76; 64, 77; 68, 78; 68, 79; 69, 80; 71, 81; 72, 82; 73, 83; 75, 84; 75, 85; 80, 86; 80, 87; 81, 88; 81, 89; 83, 90; 84, 91; 84, 92; 85, 93; 86, 94; 86, 95; 87, 96; 87, 97; 89, 98; 89, 99; 90, 100; 90, 101; 96, 102; 96, 103; 98, 104; 98, 105; 99, 106; 100, 107; 100, 108; 101, 109; 101, 110; 104, 111; 104, 112; 107, 113; 107, 114; 109, 115; 112, 116; 114, 117
def _prepare_sort_by_score(self, values, sort_options): """ Create the key to sort on the sorted set references in self._sort_by_sortedset and adapte sort options """ # create the keys base_tmp_key, tmp_keys = self._zset_to_keys( key=self._sort_by_sortedset['by'], values=values, ) # ask to sort on our new keys sort_options['by'] = '%s:*' % base_tmp_key # retrieve original sort parameters for key in ('desc', 'alpha', 'get', 'store'): if key in self._sort_by_sortedset: sort_options[key] = self._sort_by_sortedset[key] # if we want to get the score with values/values_list if sort_options.get('get'): try: pos = sort_options['get'].index(SORTED_SCORE) except: pass else: sort_options['get'][pos] = '%s:*' % base_tmp_key return base_tmp_key, tmp_keys
0, module; 1, function_definition; 2, function_name:_prepare_sort_options; 3, parameters; 4, block; 5, identifier:self; 6, identifier:has_pk; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, return_statement; 12, comment:""" Prepare sort options for _values attributes. If we manager sort by score after getting the result, we do not want to get values from the first sort call, but only from the last one, after converting results in zset into keys """; 13, assignment; 14, attribute; 15, comment:# if we asked for values, we have to use the redis 'sort'; 16, comment:# command, which is able to return other fields.; 17, block; 18, attribute; 19, block; 20, identifier:sort_options; 21, identifier:sort_options; 22, call; 23, identifier:self; 24, identifier:_values; 25, if_statement; 26, expression_statement; 27, identifier:self; 28, identifier:_sort_by_sortedset_after; 29, for_statement; 30, if_statement; 31, if_statement; 32, attribute; 33, argument_list; 34, not_operator; 35, block; 36, assignment; 37, identifier:key; 38, tuple; 39, block; 40, boolean_operator; 41, block; 42, not_operator; 43, block; 44, call; 45, identifier:_prepare_sort_options; 46, identifier:has_pk; 47, identifier:sort_options; 48, expression_statement; 49, subscript; 50, subscript; 51, string; 52, string; 53, if_statement; 54, identifier:sort_options; 55, parenthesized_expression; 56, for_statement; 57, identifier:sort_options; 58, expression_statement; 59, identifier:super; 60, argument_list; 61, assignment; 62, identifier:sort_options; 63, string; 64, subscript; 65, string; 66, string_content:get; 67, string_content:store; 68, comparison_operator:key in self._sort_by_sortedset; 69, block; 70, boolean_operator; 71, identifier:key; 72, tuple; 73, block; 74, assignment; 75, identifier:ExtendedCollectionManager; 76, identifier:self; 77, identifier:sort_options; 78, dictionary; 79, string_content:get; 80, attribute; 81, string; 82, string_content:keys; 83, identifier:key; 84, attribute; 85, delete_statement; 86, not_operator; 87, attribute; 88, string; 89, string; 90, if_statement; 91, identifier:sort_options; 92, None; 93, identifier:self; 94, identifier:_values; 95, string_content:fields; 96, identifier:self; 97, identifier:_sort_by_sortedset; 98, subscript; 99, identifier:has_pk; 100, identifier:self; 101, identifier:_want_score_value; 102, string_content:get; 103, string_content:store; 104, comparison_operator:key in sort_options; 105, block; 106, attribute; 107, identifier:key; 108, identifier:key; 109, identifier:sort_options; 110, expression_statement; 111, identifier:self; 112, identifier:_sort_by_sortedset; 113, assignment; 114, subscript; 115, call; 116, attribute; 117, identifier:key; 118, attribute; 119, argument_list; 120, identifier:self; 121, identifier:_sort_by_sortedset; 122, identifier:sort_options; 123, identifier:pop; 124, identifier:key
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 9, 14; 9, 15; 9, 16; 9, 17; 10, 18; 10, 19; 11, 20; 13, 21; 13, 22; 14, 23; 14, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 19, 31; 22, 32; 22, 33; 25, 34; 25, 35; 26, 36; 29, 37; 29, 38; 29, 39; 30, 40; 30, 41; 31, 42; 31, 43; 32, 44; 32, 45; 33, 46; 34, 47; 35, 48; 36, 49; 36, 50; 38, 51; 38, 52; 39, 53; 40, 54; 40, 55; 41, 56; 42, 57; 43, 58; 44, 59; 44, 60; 48, 61; 49, 62; 49, 63; 50, 64; 50, 65; 51, 66; 52, 67; 53, 68; 53, 69; 55, 70; 56, 71; 56, 72; 56, 73; 58, 74; 60, 75; 60, 76; 61, 77; 61, 78; 63, 79; 64, 80; 64, 81; 65, 82; 68, 83; 68, 84; 69, 85; 70, 86; 70, 87; 72, 88; 72, 89; 73, 90; 74, 91; 74, 92; 80, 93; 80, 94; 81, 95; 84, 96; 84, 97; 85, 98; 86, 99; 87, 100; 87, 101; 88, 102; 89, 103; 90, 104; 90, 105; 98, 106; 98, 107; 104, 108; 104, 109; 105, 110; 106, 111; 106, 112; 110, 113; 113, 114; 113, 115; 114, 116; 114, 117; 115, 118; 115, 119; 116, 120; 116, 121; 118, 122; 118, 123; 119, 124
def _prepare_sort_options(self, has_pk): """ Prepare sort options for _values attributes. If we manager sort by score after getting the result, we do not want to get values from the first sort call, but only from the last one, after converting results in zset into keys """ sort_options = super(ExtendedCollectionManager, self)._prepare_sort_options(has_pk) if self._values: # if we asked for values, we have to use the redis 'sort' # command, which is able to return other fields. if not sort_options: sort_options = {} sort_options['get'] = self._values['fields']['keys'] if self._sort_by_sortedset_after: for key in ('get', 'store'): if key in self._sort_by_sortedset: del self._sort_by_sortedset[key] if sort_options and (not has_pk or self._want_score_value): for key in ('get', 'store'): if key in sort_options: self._sort_by_sortedset[key] = sort_options.pop(key) if not sort_options: sort_options = None return sort_options
0, module; 1, function_definition; 2, function_name:_get_final_set; 3, parameters; 4, block; 5, identifier:self; 6, identifier:sets; 7, identifier:pk; 8, identifier:sort_options; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, comment:# if we have a slice and we want to sort by the score of a sorted set,; 13, comment:# as redis sort command doesn't handle this, we have to create keys for; 14, comment:# each value of the sorted set and sort on them; 15, comment:# @antirez, y u don't allow this !!??!!; 16, if_statement; 17, return_statement; 18, comment:""" Add intersects fo sets and call parent's _get_final_set. If we have to sort by sorted score, and we have a slice, we have to convert the whole sorted set to keys now. """; 19, subscript; 20, comment:# if the intersect method was called, we had new sets to intersect; 21, comment:# to the global set of sets.; 22, comment:# And it there is no real filters, we had the set of the whole; 23, comment:# collection because we cannot be sure that entries in "intersects"; 24, comment:# are all real primary keys; 25, block; 26, assignment; 27, boolean_operator; 28, comment:# TODO: if we have filters, maybe apply _zet_to_keys to only; 29, comment:# intersected values; 30, block; 31, expression_list; 32, attribute; 33, string; 34, expression_statement; 35, expression_statement; 36, if_statement; 37, pattern_list; 38, call; 39, identifier:final_set; 40, attribute; 41, expression_statement; 42, comment:# new keys have to be deleted once the final sort is done; 43, if_statement; 44, expression_statement; 45, expression_statement; 46, identifier:final_set; 47, identifier:keys_to_delete_later; 48, identifier:self; 49, identifier:_lazy_collection; 50, string_content:intersects; 51, assignment; 52, call; 53, boolean_operator; 54, block; 55, identifier:final_set; 56, identifier:keys_to_delete_later; 57, attribute; 58, argument_list; 59, identifier:self; 60, identifier:_sort_by_sortedset_before; 61, assignment; 62, not_operator; 63, block; 64, call; 65, augmented_assignment; 66, identifier:sets; 67, subscript; 68, attribute; 69, argument_list; 70, not_operator; 71, not_operator; 72, expression_statement; 73, call; 74, identifier:_get_final_set; 75, identifier:sets; 76, identifier:pk; 77, identifier:sort_options; 78, pattern_list; 79, call; 80, identifier:keys_to_delete_later; 81, expression_statement; 82, attribute; 83, argument_list; 84, identifier:keys_to_delete_later; 85, identifier:tmp_keys; 86, identifier:sets; 87, slice; 88, identifier:sets; 89, identifier:extend; 90, subscript; 91, subscript; 92, attribute; 93, call; 94, identifier:super; 95, argument_list; 96, identifier:base_tmp_key; 97, identifier:tmp_keys; 98, attribute; 99, argument_list; 100, assignment; 101, identifier:keys_to_delete_later; 102, identifier:append; 103, identifier:base_tmp_key; 104, attribute; 105, string; 106, attribute; 107, string; 108, identifier:self; 109, identifier:stored_key; 110, attribute; 111, argument_list; 112, identifier:ExtendedCollectionManager; 113, identifier:self; 114, identifier:self; 115, identifier:_prepare_sort_by_score; 116, None; 117, identifier:sort_options; 118, identifier:keys_to_delete_later; 119, list; 120, identifier:self; 121, identifier:_lazy_collection; 122, string_content:intersects; 123, identifier:self; 124, identifier:_lazy_collection; 125, string_content:sets; 126, identifier:sets; 127, identifier:append; 128, attribute; 129, call; 130, identifier:collection_key; 131, attribute; 132, argument_list; 133, attribute; 134, identifier:get_field; 135, string; 136, identifier:self; 137, identifier:cls; 138, string_content:pk
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 9, 18; 10, 19; 10, 20; 10, 21; 10, 22; 10, 23; 10, 24; 10, 25; 11, 26; 16, 27; 16, 28; 16, 29; 16, 30; 17, 31; 19, 32; 19, 33; 25, 34; 25, 35; 25, 36; 26, 37; 26, 38; 27, 39; 27, 40; 30, 41; 30, 42; 30, 43; 30, 44; 30, 45; 31, 46; 31, 47; 32, 48; 32, 49; 33, 50; 34, 51; 35, 52; 36, 53; 36, 54; 37, 55; 37, 56; 38, 57; 38, 58; 40, 59; 40, 60; 41, 61; 43, 62; 43, 63; 44, 64; 45, 65; 51, 66; 51, 67; 52, 68; 52, 69; 53, 70; 53, 71; 54, 72; 57, 73; 57, 74; 58, 75; 58, 76; 58, 77; 61, 78; 61, 79; 62, 80; 63, 81; 64, 82; 64, 83; 65, 84; 65, 85; 67, 86; 67, 87; 68, 88; 68, 89; 69, 90; 70, 91; 71, 92; 72, 93; 73, 94; 73, 95; 78, 96; 78, 97; 79, 98; 79, 99; 81, 100; 82, 101; 82, 102; 83, 103; 90, 104; 90, 105; 91, 106; 91, 107; 92, 108; 92, 109; 93, 110; 93, 111; 95, 112; 95, 113; 98, 114; 98, 115; 99, 116; 99, 117; 100, 118; 100, 119; 104, 120; 104, 121; 105, 122; 106, 123; 106, 124; 107, 125; 110, 126; 110, 127; 111, 128; 128, 129; 128, 130; 129, 131; 129, 132; 131, 133; 131, 134; 132, 135; 133, 136; 133, 137; 135, 138
def _get_final_set(self, sets, pk, sort_options): """ Add intersects fo sets and call parent's _get_final_set. If we have to sort by sorted score, and we have a slice, we have to convert the whole sorted set to keys now. """ if self._lazy_collection['intersects']: # if the intersect method was called, we had new sets to intersect # to the global set of sets. # And it there is no real filters, we had the set of the whole # collection because we cannot be sure that entries in "intersects" # are all real primary keys sets = sets[::] sets.extend(self._lazy_collection['intersects']) if not self._lazy_collection['sets'] and not self.stored_key: sets.append(self.cls.get_field('pk').collection_key) final_set, keys_to_delete_later = super(ExtendedCollectionManager, self)._get_final_set(sets, pk, sort_options) # if we have a slice and we want to sort by the score of a sorted set, # as redis sort command doesn't handle this, we have to create keys for # each value of the sorted set and sort on them # @antirez, y u don't allow this !!??!! if final_set and self._sort_by_sortedset_before: # TODO: if we have filters, maybe apply _zet_to_keys to only # intersected values base_tmp_key, tmp_keys = self._prepare_sort_by_score(None, sort_options) # new keys have to be deleted once the final sort is done if not keys_to_delete_later: keys_to_delete_later = [] keys_to_delete_later.append(base_tmp_key) keys_to_delete_later += tmp_keys return final_set, keys_to_delete_later
0, module; 1, function_definition; 2, function_name:_prepare_sort_options; 3, parameters; 4, block; 5, identifier:self; 6, identifier:has_pk; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, comment:""" Prepare "sort" options to use when calling the collection, depending on "_sort" and "_sort_limits" attributes """; 14, assignment; 15, boolean_operator; 16, block; 17, comparison_operator:self._sort_limits is not None; 18, block; 19, boolean_operator; 20, block; 21, identifier:sort_options; 22, identifier:sort_options; 23, dictionary; 24, comparison_operator:self._sort is not None; 25, not_operator; 26, expression_statement; 27, attribute; 28, None; 29, if_statement; 30, expression_statement; 31, not_operator; 32, comparison_operator:self._sort is None; 33, expression_statement; 34, attribute; 35, None; 36, identifier:has_pk; 37, call; 38, identifier:self; 39, identifier:_sort_limits; 40, boolean_operator; 41, block; 42, elif_clause; 43, call; 44, identifier:sort_options; 45, attribute; 46, None; 47, assignment; 48, identifier:self; 49, identifier:_sort; 50, attribute; 51, argument_list; 52, comparison_operator:'start' in self._sort_limits; 53, comparison_operator:'num' not in self._sort_limits; 54, expression_statement; 55, boolean_operator; 56, block; 57, attribute; 58, argument_list; 59, identifier:self; 60, identifier:_sort; 61, identifier:sort_options; 62, None; 63, identifier:sort_options; 64, identifier:update; 65, attribute; 66, string; 67, attribute; 68, string; 69, attribute; 70, assignment; 71, comparison_operator:'num' in self._sort_limits; 72, comparison_operator:'start' not in self._sort_limits; 73, expression_statement; 74, identifier:sort_options; 75, identifier:update; 76, attribute; 77, identifier:self; 78, identifier:_sort; 79, string_content:start; 80, identifier:self; 81, identifier:_sort_limits; 82, string_content:num; 83, identifier:self; 84, identifier:_sort_limits; 85, subscript; 86, unary_operator; 87, string; 88, attribute; 89, string; 90, attribute; 91, assignment; 92, identifier:self; 93, identifier:_sort_limits; 94, attribute; 95, string; 96, integer:1; 97, string_content:num; 98, identifier:self; 99, identifier:_sort_limits; 100, string_content:start; 101, identifier:self; 102, identifier:_sort_limits; 103, subscript; 104, integer:0; 105, identifier:self; 106, identifier:_sort_limits; 107, string_content:num; 108, attribute; 109, string; 110, identifier:self; 111, identifier:_sort_limits; 112, string_content:start
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 9, 16; 10, 17; 10, 18; 11, 19; 11, 20; 12, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 17, 27; 17, 28; 18, 29; 18, 30; 19, 31; 19, 32; 20, 33; 24, 34; 24, 35; 25, 36; 26, 37; 27, 38; 27, 39; 29, 40; 29, 41; 29, 42; 30, 43; 31, 44; 32, 45; 32, 46; 33, 47; 34, 48; 34, 49; 37, 50; 37, 51; 40, 52; 40, 53; 41, 54; 42, 55; 42, 56; 43, 57; 43, 58; 45, 59; 45, 60; 47, 61; 47, 62; 50, 63; 50, 64; 51, 65; 52, 66; 52, 67; 53, 68; 53, 69; 54, 70; 55, 71; 55, 72; 56, 73; 57, 74; 57, 75; 58, 76; 65, 77; 65, 78; 66, 79; 67, 80; 67, 81; 68, 82; 69, 83; 69, 84; 70, 85; 70, 86; 71, 87; 71, 88; 72, 89; 72, 90; 73, 91; 76, 92; 76, 93; 85, 94; 85, 95; 86, 96; 87, 97; 88, 98; 88, 99; 89, 100; 90, 101; 90, 102; 91, 103; 91, 104; 94, 105; 94, 106; 95, 107; 103, 108; 103, 109; 108, 110; 108, 111; 109, 112
def _prepare_sort_options(self, has_pk): """ Prepare "sort" options to use when calling the collection, depending on "_sort" and "_sort_limits" attributes """ sort_options = {} if self._sort is not None and not has_pk: sort_options.update(self._sort) if self._sort_limits is not None: if 'start' in self._sort_limits and 'num' not in self._sort_limits: self._sort_limits['num'] = -1 elif 'num' in self._sort_limits and 'start' not in self._sort_limits: self._sort_limits['start'] = 0 sort_options.update(self._sort_limits) if not sort_options and self._sort is None: sort_options = None return sort_options
0, module; 1, function_definition; 2, function_name:_final_redis_call; 3, parameters; 4, block; 5, identifier:self; 6, identifier:final_set; 7, identifier:sort_options; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, comment:""" The final redis call to obtain the values to return from the "final_set" with some sort options. """; 12, assignment; 13, comparison_operator:sort_options is not None; 14, comment:# a sort, or values, call the SORT command on the set; 15, block; 16, else_clause; 17, identifier:conn; 18, call; 19, identifier:sort_options; 20, None; 21, return_statement; 22, comment:# no sort, nor values, simply return the full set; 23, block; 24, attribute; 25, argument_list; 26, call; 27, return_statement; 28, attribute; 29, identifier:get_connection; 30, attribute; 31, argument_list; 32, call; 33, identifier:self; 34, identifier:cls; 35, identifier:conn; 36, identifier:sort; 37, identifier:final_set; 38, dictionary_splat; 39, attribute; 40, argument_list; 41, identifier:sort_options; 42, identifier:conn; 43, identifier:smembers; 44, identifier:final_set
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 8, 11; 9, 12; 10, 13; 10, 14; 10, 15; 10, 16; 12, 17; 12, 18; 13, 19; 13, 20; 15, 21; 16, 22; 16, 23; 18, 24; 18, 25; 21, 26; 23, 27; 24, 28; 24, 29; 26, 30; 26, 31; 27, 32; 28, 33; 28, 34; 30, 35; 30, 36; 31, 37; 31, 38; 32, 39; 32, 40; 38, 41; 39, 42; 39, 43; 40, 44
def _final_redis_call(self, final_set, sort_options): """ The final redis call to obtain the values to return from the "final_set" with some sort options. """ conn = self.cls.get_connection() if sort_options is not None: # a sort, or values, call the SORT command on the set return conn.sort(final_set, **sort_options) else: # no sort, nor values, simply return the full set return conn.smembers(final_set)
0, module; 1, function_definition; 2, function_name:query_mongo_sort_decend; 3, parameters; 4, block; 5, identifier:database_name; 6, identifier:collection_name; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, try_statement; 16, return_statement; 17, identifier:query; 18, dictionary; 19, identifier:skip; 20, integer:0; 21, identifier:limit; 22, call; 23, identifier:return_keys; 24, tuple; 25, identifier:sortkey; 26, None; 27, comment:"""return a response_dict with a list of search results in decending order based on a sort key """; 28, assignment; 29, assignment; 30, block; 31, except_clause; 32, identifier:response_dict; 33, identifier:getattr; 34, argument_list; 35, identifier:l; 36, list; 37, identifier:response_dict; 38, dictionary; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, expression_statement; 43, if_statement; 44, comment:# response_dict['num_results']=int(mysearchresult.count(with_limit_and_skip=False)); 45, expression_statement; 46, expression_statement; 47, for_statement; 48, expression_statement; 49, block; 50, identifier:settings; 51, string; 52, integer:200; 53, assignment; 54, assignment; 55, assignment; 56, assignment; 57, identifier:return_keys; 58, block; 59, else_clause; 60, assignment; 61, assignment; 62, identifier:d; 63, identifier:mysearchresult; 64, block; 65, assignment; 66, expression_statement; 67, expression_statement; 68, expression_statement; 69, expression_statement; 70, expression_statement; 71, expression_statement; 72, expression_statement; 73, string_content:MONGO_LIMIT; 74, identifier:mongodb_client_url; 75, call; 76, identifier:mc; 77, call; 78, identifier:db; 79, subscript; 80, identifier:collection; 81, subscript; 82, expression_statement; 83, for_statement; 84, comment:# print "returndict=",return_dict; 85, expression_statement; 86, block; 87, subscript; 88, integer:200; 89, subscript; 90, string:"search-results"; 91, expression_statement; 92, delete_statement; 93, expression_statement; 94, subscript; 95, identifier:l; 96, call; 97, call; 98, assignment; 99, assignment; 100, assignment; 101, assignment; 102, assignment; 103, identifier:getattr; 104, argument_list; 105, identifier:MongoClient; 106, argument_list; 107, identifier:mc; 108, call; 109, identifier:db; 110, call; 111, assignment; 112, identifier:k; 113, identifier:return_keys; 114, block; 115, assignment; 116, expression_statement; 117, identifier:response_dict; 118, string; 119, identifier:response_dict; 120, string; 121, assignment; 122, subscript; 123, call; 124, identifier:response_dict; 125, string; 126, identifier:print; 127, argument_list; 128, identifier:print; 129, argument_list; 130, subscript; 131, integer:0; 132, subscript; 133, integer:500; 134, subscript; 135, string:"Error"; 136, subscript; 137, list; 138, subscript; 139, call; 140, identifier:settings; 141, string; 142, string; 143, identifier:mongodb_client_url; 144, keyword_argument; 145, identifier:str; 146, argument_list; 147, identifier:str; 148, argument_list; 149, identifier:return_dict; 150, dictionary; 151, expression_statement; 152, identifier:mysearchresult; 153, call; 154, assignment; 155, string_content:code; 156, string_content:type; 157, subscript; 158, call; 159, identifier:d; 160, string; 161, attribute; 162, argument_list; 163, string_content:results; 164, string:"Error reading from Mongo"; 165, call; 166, identifier:response_dict; 167, string; 168, identifier:response_dict; 169, string; 170, identifier:response_dict; 171, string; 172, identifier:response_dict; 173, string; 174, identifier:response_dict; 175, string; 176, identifier:str; 177, argument_list; 178, string_content:MONGODB_CLIENT; 179, string_content:mongodb://localhost:27017/; 180, identifier:document_class; 181, identifier:OrderedDict; 182, identifier:database_name; 183, identifier:collection_name; 184, assignment; 185, attribute; 186, argument_list; 187, identifier:mysearchresult; 188, call; 189, identifier:d; 190, string; 191, attribute; 192, argument_list; 193, string_content:_id; 194, identifier:l; 195, identifier:append; 196, identifier:d; 197, identifier:str; 198, argument_list; 199, string_content:num_results; 200, string_content:code; 201, string_content:type; 202, string_content:results; 203, string_content:message; 204, call; 205, subscript; 206, integer:1; 207, call; 208, identifier:sort; 209, identifier:sortkey; 210, identifier:DESCENDING; 211, attribute; 212, argument_list; 213, string_content:id; 214, subscript; 215, identifier:__str__; 216, call; 217, attribute; 218, argument_list; 219, identifier:return_dict; 220, identifier:k; 221, attribute; 222, argument_list; 223, call; 224, identifier:sort; 225, identifier:sortkey; 226, identifier:DESCENDING; 227, identifier:d; 228, string; 229, attribute; 230, argument_list; 231, identifier:sys; 232, identifier:exc_info; 233, call; 234, identifier:limit; 235, identifier:limit; 236, attribute; 237, argument_list; 238, string_content:_id; 239, identifier:sys; 240, identifier:exc_info; 241, attribute; 242, argument_list; 243, call; 244, identifier:limit; 245, identifier:limit; 246, call; 247, identifier:skip; 248, identifier:skip; 249, attribute; 250, argument_list; 251, attribute; 252, argument_list; 253, call; 254, identifier:skip; 255, identifier:skip; 256, identifier:collection; 257, identifier:find; 258, identifier:query; 259, identifier:return_dict; 260, attribute; 261, argument_list; 262, identifier:collection; 263, identifier:find; 264, identifier:query
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 7, 17; 7, 18; 8, 19; 8, 20; 9, 21; 9, 22; 10, 23; 10, 24; 11, 25; 11, 26; 12, 27; 13, 28; 14, 29; 15, 30; 15, 31; 16, 32; 22, 33; 22, 34; 28, 35; 28, 36; 29, 37; 29, 38; 30, 39; 30, 40; 30, 41; 30, 42; 30, 43; 30, 44; 30, 45; 30, 46; 30, 47; 30, 48; 31, 49; 34, 50; 34, 51; 34, 52; 39, 53; 40, 54; 41, 55; 42, 56; 43, 57; 43, 58; 43, 59; 45, 60; 46, 61; 47, 62; 47, 63; 47, 64; 48, 65; 49, 66; 49, 67; 49, 68; 49, 69; 49, 70; 49, 71; 49, 72; 51, 73; 53, 74; 53, 75; 54, 76; 54, 77; 55, 78; 55, 79; 56, 80; 56, 81; 58, 82; 58, 83; 58, 84; 58, 85; 59, 86; 60, 87; 60, 88; 61, 89; 61, 90; 64, 91; 64, 92; 64, 93; 65, 94; 65, 95; 66, 96; 67, 97; 68, 98; 69, 99; 70, 100; 71, 101; 72, 102; 75, 103; 75, 104; 77, 105; 77, 106; 79, 107; 79, 108; 81, 109; 81, 110; 82, 111; 83, 112; 83, 113; 83, 114; 85, 115; 86, 116; 87, 117; 87, 118; 89, 119; 89, 120; 91, 121; 92, 122; 93, 123; 94, 124; 94, 125; 96, 126; 96, 127; 97, 128; 97, 129; 98, 130; 98, 131; 99, 132; 99, 133; 100, 134; 100, 135; 101, 136; 101, 137; 102, 138; 102, 139; 104, 140; 104, 141; 104, 142; 106, 143; 106, 144; 108, 145; 108, 146; 110, 147; 110, 148; 111, 149; 111, 150; 114, 151; 115, 152; 115, 153; 116, 154; 118, 155; 120, 156; 121, 157; 121, 158; 122, 159; 122, 160; 123, 161; 123, 162; 125, 163; 127, 164; 129, 165; 130, 166; 130, 167; 132, 168; 132, 169; 134, 170; 134, 171; 136, 172; 136, 173; 138, 174; 138, 175; 139, 176; 139, 177; 141, 178; 142, 179; 144, 180; 144, 181; 146, 182; 148, 183; 151, 184; 153, 185; 153, 186; 154, 187; 154, 188; 157, 189; 157, 190; 158, 191; 158, 192; 160, 193; 161, 194; 161, 195; 162, 196; 165, 197; 165, 198; 167, 199; 169, 200; 171, 201; 173, 202; 175, 203; 177, 204; 184, 205; 184, 206; 185, 207; 185, 208; 186, 209; 186, 210; 188, 211; 188, 212; 190, 213; 191, 214; 191, 215; 198, 216; 204, 217; 204, 218; 205, 219; 205, 220; 207, 221; 207, 222; 211, 223; 211, 224; 212, 225; 212, 226; 214, 227; 214, 228; 216, 229; 216, 230; 217, 231; 217, 232; 221, 233; 221, 234; 222, 235; 223, 236; 223, 237; 228, 238; 229, 239; 229, 240; 233, 241; 233, 242; 236, 243; 236, 244; 237, 245; 241, 246; 241, 247; 242, 248; 243, 249; 243, 250; 246, 251; 246, 252; 249, 253; 249, 254; 250, 255; 251, 256; 251, 257; 252, 258; 252, 259; 253, 260; 253, 261; 260, 262; 260, 263; 261, 264
def query_mongo_sort_decend( database_name, collection_name, query={}, skip=0, limit=getattr( settings, 'MONGO_LIMIT', 200), return_keys=(), sortkey=None): """return a response_dict with a list of search results in decending order based on a sort key """ l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(collection_name)] if return_keys: return_dict = {} for k in return_keys: return_dict[k] = 1 # print "returndict=",return_dict mysearchresult = collection.find( query, return_dict).skip(skip).limit(limit).sort( sortkey, DESCENDING) else: mysearchresult = collection.find(query).skip( skip).limit(limit).sort(sortkey, DESCENDING) # response_dict['num_results']=int(mysearchresult.count(with_limit_and_skip=False)) response_dict['code'] = 200 response_dict['type'] = "search-results" for d in mysearchresult: d['id'] = d['_id'].__str__() del d['_id'] l.append(d) response_dict['results'] = l except: print("Error reading from Mongo") print(str(sys.exc_info())) response_dict['num_results'] = 0 response_dict['code'] = 500 response_dict['type'] = "Error" response_dict['results'] = [] response_dict['message'] = str(sys.exc_info()) return response_dict
0, module; 1, function_definition; 2, function_name:build_sort; 3, parameters; 4, block; 5, identifier:self; 6, dictionary_splat_pattern; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, return_statement; 12, identifier:kwargs; 13, string; 14, assignment; 15, assignment; 16, identifier:order; 17, block; 18, identifier:sort; 19, string_content:Break url parameters and turn into sort arguments; 20, identifier:sort; 21, list; 22, identifier:order; 23, call; 24, if_statement; 25, if_statement; 26, attribute; 27, argument_list; 28, comparison_operator:type(order) is list; 29, block; 30, comparison_operator:order[:1] == '-'; 31, block; 32, else_clause; 33, identifier:kwargs; 34, identifier:get; 35, string; 36, None; 37, call; 38, identifier:list; 39, expression_statement; 40, subscript; 41, string; 42, expression_statement; 43, block; 44, string_content:order_by; 45, identifier:type; 46, argument_list; 47, assignment; 48, identifier:order; 49, slice; 50, string_content:-; 51, call; 52, expression_statement; 53, identifier:order; 54, identifier:order; 55, subscript; 56, integer:1; 57, attribute; 58, argument_list; 59, call; 60, identifier:order; 61, integer:0; 62, identifier:sort; 63, identifier:append; 64, tuple; 65, attribute; 66, argument_list; 67, subscript; 68, unary_operator; 69, identifier:sort; 70, identifier:append; 71, tuple; 72, identifier:order; 73, slice; 74, integer:1; 75, identifier:order; 76, integer:1; 77, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 7, 13; 8, 14; 9, 15; 10, 16; 10, 17; 11, 18; 13, 19; 14, 20; 14, 21; 15, 22; 15, 23; 17, 24; 17, 25; 23, 26; 23, 27; 24, 28; 24, 29; 25, 30; 25, 31; 25, 32; 26, 33; 26, 34; 27, 35; 27, 36; 28, 37; 28, 38; 29, 39; 30, 40; 30, 41; 31, 42; 32, 43; 35, 44; 37, 45; 37, 46; 39, 47; 40, 48; 40, 49; 41, 50; 42, 51; 43, 52; 46, 53; 47, 54; 47, 55; 49, 56; 51, 57; 51, 58; 52, 59; 55, 60; 55, 61; 57, 62; 57, 63; 58, 64; 59, 65; 59, 66; 64, 67; 64, 68; 65, 69; 65, 70; 66, 71; 67, 72; 67, 73; 68, 74; 71, 75; 71, 76; 73, 77
def build_sort(self, **kwargs): ''' Break url parameters and turn into sort arguments ''' sort = [] order = kwargs.get('order_by', None) if order: if type(order) is list: order = order[0] if order[:1] == '-': sort.append((order[1:], -1)) else: sort.append((order, 1)) return sort
0, module; 1, function_definition; 2, function_name:load_remotes; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, expression_statement; 8, import_from_statement; 9, try_statement; 10, if_statement; 11, identifier:extra_path; 12, None; 13, identifier:load_user; 14, True; 15, comment:"""Load the YAML remotes file, which sort of combines the Accounts file with part of the remotes sections from the main config :return: An `AttrDict` """; 16, dotted_name; 17, dotted_name; 18, block; 19, except_clause; 20, boolean_operator; 21, block; 22, else_clause; 23, identifier:os; 24, identifier:path; 25, identifier:getmtime; 26, expression_statement; 27, identifier:ConfigurationError; 28, block; 29, comparison_operator:remotes_file is not None; 30, call; 31, expression_statement; 32, expression_statement; 33, if_statement; 34, expression_statement; 35, return_statement; 36, block; 37, assignment; 38, expression_statement; 39, identifier:remotes_file; 40, None; 41, attribute; 42, argument_list; 43, assignment; 44, call; 45, not_operator; 46, block; 47, assignment; 48, identifier:config; 49, return_statement; 50, identifier:remotes_file; 51, call; 52, assignment; 53, attribute; 54, identifier:exists; 55, identifier:remotes_file; 56, identifier:config; 57, call; 58, attribute; 59, argument_list; 60, comparison_operator:'remotes' in config; 61, expression_statement; 62, attribute; 63, list; 64, None; 65, identifier:find_config_file; 66, argument_list; 67, identifier:remotes_file; 68, None; 69, identifier:os; 70, identifier:path; 71, identifier:AttrDict; 72, argument_list; 73, identifier:config; 74, identifier:update_yaml; 75, identifier:remotes_file; 76, string; 77, identifier:config; 78, assignment; 79, attribute; 80, identifier:loaded; 81, identifier:remotes_file; 82, call; 83, identifier:REMOTES_FILE; 84, keyword_argument; 85, keyword_argument; 86, string_content:remotes; 87, attribute; 88, call; 89, identifier:config; 90, identifier:remotes; 91, identifier:getmtime; 92, argument_list; 93, identifier:extra_path; 94, identifier:extra_path; 95, identifier:load_user; 96, identifier:load_user; 97, identifier:config; 98, identifier:remotes; 99, identifier:AttrDict; 100, argument_list; 101, identifier:remotes_file
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 5, 11; 5, 12; 6, 13; 6, 14; 7, 15; 8, 16; 8, 17; 9, 18; 9, 19; 10, 20; 10, 21; 10, 22; 16, 23; 16, 24; 17, 25; 18, 26; 19, 27; 19, 28; 20, 29; 20, 30; 21, 31; 21, 32; 21, 33; 21, 34; 21, 35; 22, 36; 26, 37; 28, 38; 29, 39; 29, 40; 30, 41; 30, 42; 31, 43; 32, 44; 33, 45; 33, 46; 34, 47; 35, 48; 36, 49; 37, 50; 37, 51; 38, 52; 41, 53; 41, 54; 42, 55; 43, 56; 43, 57; 44, 58; 44, 59; 45, 60; 46, 61; 47, 62; 47, 63; 49, 64; 51, 65; 51, 66; 52, 67; 52, 68; 53, 69; 53, 70; 57, 71; 57, 72; 58, 73; 58, 74; 59, 75; 60, 76; 60, 77; 61, 78; 62, 79; 62, 80; 63, 81; 63, 82; 66, 83; 66, 84; 66, 85; 76, 86; 78, 87; 78, 88; 79, 89; 79, 90; 82, 91; 82, 92; 84, 93; 84, 94; 85, 95; 85, 96; 87, 97; 87, 98; 88, 99; 88, 100; 92, 101
def load_remotes(extra_path=None, load_user=True): """Load the YAML remotes file, which sort of combines the Accounts file with part of the remotes sections from the main config :return: An `AttrDict` """ from os.path import getmtime try: remotes_file = find_config_file(REMOTES_FILE, extra_path=extra_path, load_user=load_user) except ConfigurationError: remotes_file = None if remotes_file is not None and os.path.exists(remotes_file): config = AttrDict() config.update_yaml(remotes_file) if not 'remotes' in config: config.remotes = AttrDict() config.remotes.loaded = [remotes_file, getmtime(remotes_file)] return config else: return None
0, module; 1, function_definition; 2, function_name:find_previous; 3, parameters; 4, block; 5, identifier:element; 6, identifier:l; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, comment:""" find previous element in a sorted list >>> find_previous(0, [0]) 0 >>> find_previous(2, [1, 1, 3]) 1 >>> find_previous(0, [1, 2]) >>> find_previous(1.5, [1, 2]) 1 >>> find_previous(3, [1, 2]) 2 """; 11, assignment; 12, pattern_list; 13, call; 14, comment:# current is the last element; 15, block; 16, identifier:length; 17, call; 18, identifier:index; 19, identifier:current; 20, identifier:enumerate; 21, argument_list; 22, if_statement; 23, comment:# current is the first element; 24, if_statement; 25, if_statement; 26, identifier:len; 27, argument_list; 28, identifier:l; 29, comparison_operator:length - 1 == index; 30, block; 31, comparison_operator:index == 0; 32, block; 33, comparison_operator:current <= element < l[index+1]; 34, block; 35, identifier:l; 36, binary_operator:length - 1; 37, identifier:index; 38, return_statement; 39, identifier:index; 40, integer:0; 41, if_statement; 42, identifier:current; 43, identifier:element; 44, subscript; 45, return_statement; 46, identifier:length; 47, integer:1; 48, identifier:current; 49, comparison_operator:element < current; 50, block; 51, identifier:l; 52, binary_operator:index+1; 53, identifier:current; 54, identifier:element; 55, identifier:current; 56, return_statement; 57, identifier:index; 58, integer:1; 59, None
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 9, 12; 9, 13; 9, 14; 9, 15; 11, 16; 11, 17; 12, 18; 12, 19; 13, 20; 13, 21; 15, 22; 15, 23; 15, 24; 15, 25; 17, 26; 17, 27; 21, 28; 22, 29; 22, 30; 24, 31; 24, 32; 25, 33; 25, 34; 27, 35; 29, 36; 29, 37; 30, 38; 31, 39; 31, 40; 32, 41; 33, 42; 33, 43; 33, 44; 34, 45; 36, 46; 36, 47; 38, 48; 41, 49; 41, 50; 44, 51; 44, 52; 45, 53; 49, 54; 49, 55; 50, 56; 52, 57; 52, 58; 56, 59
def find_previous(element, l): """ find previous element in a sorted list >>> find_previous(0, [0]) 0 >>> find_previous(2, [1, 1, 3]) 1 >>> find_previous(0, [1, 2]) >>> find_previous(1.5, [1, 2]) 1 >>> find_previous(3, [1, 2]) 2 """ length = len(l) for index, current in enumerate(l): # current is the last element if length - 1 == index: return current # current is the first element if index == 0: if element < current: return None if current <= element < l[index+1]: return current
0, module; 1, function_definition; 2, function_name:tsort; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, comment:# parts = parts.copy(); 10, expression_statement; 11, expression_statement; 12, while_statement; 13, if_statement; 14, return_statement; 15, comment:"""Given a partial ordering, return a totally ordered list. part is a dict of partial orderings. Each value is a set, which the key depends on. The return value is a list of sets, each of which has only dependencies on items in previous entries in the list. raise ValueError if ordering is not possible (check for circular or missing dependencies)"""; 16, assignment; 17, pattern_list; 18, call; 19, block; 20, assignment; 21, assignment; 22, True; 23, block; 24, identifier:parts; 25, block; 26, identifier:result; 27, identifier:task_dict; 28, dictionary; 29, identifier:key; 30, identifier:task; 31, attribute; 32, argument_list; 33, expression_statement; 34, identifier:parts; 35, call; 36, identifier:result; 37, list; 38, expression_statement; 39, if_statement; 40, expression_statement; 41, expression_statement; 42, raise_statement; 43, attribute; 44, identifier:iteritems; 45, assignment; 46, attribute; 47, argument_list; 48, assignment; 49, not_operator; 50, block; 51, call; 52, assignment; 53, call; 54, identifier:self; 55, identifier:tasks; 56, subscript; 57, attribute; 58, identifier:task_dict; 59, identifier:copy; 60, identifier:level; 61, call; 62, identifier:level; 63, break_statement; 64, attribute; 65, argument_list; 66, identifier:parts; 67, call; 68, identifier:ValueError; 69, argument_list; 70, identifier:task_dict; 71, identifier:task; 72, identifier:task; 73, identifier:dependencies; 74, identifier:set; 75, argument_list; 76, identifier:result; 77, identifier:append; 78, identifier:level; 79, identifier:dict; 80, argument_list; 81, string; 82, list_comprehension; 83, list_comprehension; 84, string_content:total ordering not possible (check for circular or missing dependencies); 85, identifier:name; 86, for_in_clause; 87, if_clause; 88, tuple; 89, for_in_clause; 90, if_clause; 91, pattern_list; 92, call; 93, not_operator; 94, identifier:name; 95, binary_operator:deps - level; 96, pattern_list; 97, call; 98, comparison_operator:name not in level; 99, identifier:name; 100, identifier:deps; 101, attribute; 102, argument_list; 103, identifier:deps; 104, identifier:deps; 105, identifier:level; 106, identifier:name; 107, identifier:deps; 108, attribute; 109, argument_list; 110, identifier:name; 111, identifier:level; 112, identifier:parts; 113, identifier:iteritems; 114, identifier:parts; 115, identifier:iteritems
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 6, 15; 7, 16; 8, 17; 8, 18; 8, 19; 10, 20; 11, 21; 12, 22; 12, 23; 13, 24; 13, 25; 14, 26; 16, 27; 16, 28; 17, 29; 17, 30; 18, 31; 18, 32; 19, 33; 20, 34; 20, 35; 21, 36; 21, 37; 23, 38; 23, 39; 23, 40; 23, 41; 25, 42; 31, 43; 31, 44; 33, 45; 35, 46; 35, 47; 38, 48; 39, 49; 39, 50; 40, 51; 41, 52; 42, 53; 43, 54; 43, 55; 45, 56; 45, 57; 46, 58; 46, 59; 48, 60; 48, 61; 49, 62; 50, 63; 51, 64; 51, 65; 52, 66; 52, 67; 53, 68; 53, 69; 56, 70; 56, 71; 57, 72; 57, 73; 61, 74; 61, 75; 64, 76; 64, 77; 65, 78; 67, 79; 67, 80; 69, 81; 75, 82; 80, 83; 81, 84; 82, 85; 82, 86; 82, 87; 83, 88; 83, 89; 83, 90; 86, 91; 86, 92; 87, 93; 88, 94; 88, 95; 89, 96; 89, 97; 90, 98; 91, 99; 91, 100; 92, 101; 92, 102; 93, 103; 95, 104; 95, 105; 96, 106; 96, 107; 97, 108; 97, 109; 98, 110; 98, 111; 101, 112; 101, 113; 108, 114; 108, 115
def tsort(self): """Given a partial ordering, return a totally ordered list. part is a dict of partial orderings. Each value is a set, which the key depends on. The return value is a list of sets, each of which has only dependencies on items in previous entries in the list. raise ValueError if ordering is not possible (check for circular or missing dependencies)""" task_dict = {} for key, task in self.tasks.iteritems(): task_dict[task] = task.dependencies # parts = parts.copy() parts = task_dict.copy() result = [] while True: level = set([name for name, deps in parts.iteritems() if not deps]) if not level: break result.append(level) parts = dict([(name, deps - level) for name, deps in parts.iteritems() if name not in level]) if parts: raise ValueError('total ordering not possible (check for circular or missing dependencies)') return result
0, module; 1, function_definition; 2, function_name:getBounds; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, return_statement; 10, identifier:tzinfo; 11, None; 12, comment:""" Return a pair describing the bounds of self. This returns a pair (min, max) of Time instances. It is not quite the same as (self, self + self.resolution). This is because timezones are insignificant for instances with a resolution greater or equal to 1 day. To illustrate the problem, consider a Time instance:: T = Time.fromHumanly('today', tzinfo=anything) This will return an equivalent instance independent of the tzinfo used. The hour, minute, and second of this instance are 0, and its resolution is one day. Now say we have a sorted list of times, and we want to get all times for 'today', where whoever said 'today' is in a timezone that's 5 hours ahead of UTC. The start of 'today' in this timezone is UTC 05:00. The example instance T above is before this, but obviously it is today. The min and max times this returns are such that all potentially matching instances are within this range. However, this range might contain unmatching instances. As an example of this, if 'today' is April first 2005, then Time.fromISO8601TimeAndDate('2005-04-01T00:00:00') sorts in the same place as T from above, but is not in the UTC+5 'today'. TIME IS FUN! """; 13, boolean_operator; 14, block; 15, else_clause; 16, tuple; 17, comparison_operator:self.resolution >= datetime.timedelta(days=1); 18, line_continuation:\; 19, comparison_operator:tzinfo is not None; 20, expression_statement; 21, block; 22, call; 23, call; 24, attribute; 25, call; 26, identifier:tzinfo; 27, None; 28, assignment; 29, expression_statement; 30, identifier:min; 31, argument_list; 32, identifier:max; 33, argument_list; 34, identifier:self; 35, identifier:resolution; 36, attribute; 37, argument_list; 38, identifier:time; 39, call; 40, assignment; 41, call; 42, call; 43, call; 44, call; 45, identifier:datetime; 46, identifier:timedelta; 47, keyword_argument; 48, attribute; 49, argument_list; 50, identifier:time; 51, attribute; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, attribute; 57, argument_list; 58, attribute; 59, argument_list; 60, identifier:days; 61, integer:1; 62, attribute; 63, identifier:replace; 64, keyword_argument; 65, identifier:self; 66, identifier:_time; 67, identifier:self; 68, identifier:fromDatetime; 69, identifier:time; 70, identifier:self; 71, identifier:fromDatetime; 72, attribute; 73, identifier:self; 74, identifier:fromDatetime; 75, binary_operator:time + self.resolution; 76, identifier:self; 77, identifier:fromDatetime; 78, binary_operator:self._time + self.resolution; 79, identifier:self; 80, identifier:_time; 81, identifier:tzinfo; 82, identifier:tzinfo; 83, identifier:self; 84, identifier:_time; 85, identifier:time; 86, attribute; 87, attribute; 88, attribute; 89, identifier:self; 90, identifier:resolution; 91, identifier:self; 92, identifier:_time; 93, identifier:self; 94, identifier:resolution
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 8, 13; 8, 14; 8, 15; 9, 16; 13, 17; 13, 18; 13, 19; 14, 20; 15, 21; 16, 22; 16, 23; 17, 24; 17, 25; 19, 26; 19, 27; 20, 28; 21, 29; 22, 30; 22, 31; 23, 32; 23, 33; 24, 34; 24, 35; 25, 36; 25, 37; 28, 38; 28, 39; 29, 40; 31, 41; 31, 42; 33, 43; 33, 44; 36, 45; 36, 46; 37, 47; 39, 48; 39, 49; 40, 50; 40, 51; 41, 52; 41, 53; 42, 54; 42, 55; 43, 56; 43, 57; 44, 58; 44, 59; 47, 60; 47, 61; 48, 62; 48, 63; 49, 64; 51, 65; 51, 66; 52, 67; 52, 68; 53, 69; 54, 70; 54, 71; 55, 72; 56, 73; 56, 74; 57, 75; 58, 76; 58, 77; 59, 78; 62, 79; 62, 80; 64, 81; 64, 82; 72, 83; 72, 84; 75, 85; 75, 86; 78, 87; 78, 88; 86, 89; 86, 90; 87, 91; 87, 92; 88, 93; 88, 94
def getBounds(self, tzinfo=None): """ Return a pair describing the bounds of self. This returns a pair (min, max) of Time instances. It is not quite the same as (self, self + self.resolution). This is because timezones are insignificant for instances with a resolution greater or equal to 1 day. To illustrate the problem, consider a Time instance:: T = Time.fromHumanly('today', tzinfo=anything) This will return an equivalent instance independent of the tzinfo used. The hour, minute, and second of this instance are 0, and its resolution is one day. Now say we have a sorted list of times, and we want to get all times for 'today', where whoever said 'today' is in a timezone that's 5 hours ahead of UTC. The start of 'today' in this timezone is UTC 05:00. The example instance T above is before this, but obviously it is today. The min and max times this returns are such that all potentially matching instances are within this range. However, this range might contain unmatching instances. As an example of this, if 'today' is April first 2005, then Time.fromISO8601TimeAndDate('2005-04-01T00:00:00') sorts in the same place as T from above, but is not in the UTC+5 'today'. TIME IS FUN! """ if self.resolution >= datetime.timedelta(days=1) \ and tzinfo is not None: time = self._time.replace(tzinfo=tzinfo) else: time = self._time return ( min(self.fromDatetime(time), self.fromDatetime(self._time)), max(self.fromDatetime(time + self.resolution), self.fromDatetime(self._time + self.resolution)) )
0, module; 1, function_definition; 2, function_name:_get_all_migrations; 3, parameters; 4, block; 5, expression_statement; 6, import_from_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, expression_statement; 12, return_statement; 13, comment:""" Returns sorted list of all migrations. Returns: list of (int, str) tuples: first elem of the tuple is migration number, second if module name. """; 14, relative_import; 15, dotted_name; 16, assignment; 17, assignment; 18, assignment; 19, pattern_list; 20, call; 21, block; 22, assignment; 23, identifier:all_migrations; 24, import_prefix; 25, identifier:migrations; 26, identifier:package; 27, identifier:migrations; 28, identifier:prefix; 29, binary_operator:package.__name__ + '.'; 30, identifier:all_migrations; 31, list; 32, identifier:importer; 33, identifier:modname; 34, identifier:ispkg; 35, attribute; 36, argument_list; 37, expression_statement; 38, expression_statement; 39, identifier:all_migrations; 40, call; 41, attribute; 42, string; 43, identifier:pkgutil; 44, identifier:iter_modules; 45, attribute; 46, identifier:prefix; 47, assignment; 48, call; 49, identifier:sorted; 50, argument_list; 51, identifier:package; 52, identifier:__name__; 53, string_content:.; 54, identifier:package; 55, identifier:__path__; 56, identifier:version; 57, call; 58, attribute; 59, argument_list; 60, identifier:all_migrations; 61, keyword_argument; 62, identifier:int; 63, argument_list; 64, identifier:all_migrations; 65, identifier:append; 66, tuple; 67, identifier:key; 68, lambda; 69, subscript; 70, identifier:version; 71, identifier:modname; 72, lambda_parameters; 73, subscript; 74, call; 75, integer:0; 76, identifier:x; 77, identifier:x; 78, integer:0; 79, attribute; 80, argument_list; 81, subscript; 82, identifier:split; 83, string; 84, call; 85, unary_operator; 86, string_content:_; 87, attribute; 88, argument_list; 89, integer:1; 90, identifier:modname; 91, identifier:split; 92, string; 93, string_content:.
0, 1; 1, 2; 1, 3; 1, 4; 4, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 5, 13; 6, 14; 6, 15; 7, 16; 8, 17; 9, 18; 10, 19; 10, 20; 10, 21; 11, 22; 12, 23; 14, 24; 15, 25; 16, 26; 16, 27; 17, 28; 17, 29; 18, 30; 18, 31; 19, 32; 19, 33; 19, 34; 20, 35; 20, 36; 21, 37; 21, 38; 22, 39; 22, 40; 29, 41; 29, 42; 35, 43; 35, 44; 36, 45; 36, 46; 37, 47; 38, 48; 40, 49; 40, 50; 41, 51; 41, 52; 42, 53; 45, 54; 45, 55; 47, 56; 47, 57; 48, 58; 48, 59; 50, 60; 50, 61; 57, 62; 57, 63; 58, 64; 58, 65; 59, 66; 61, 67; 61, 68; 63, 69; 66, 70; 66, 71; 68, 72; 68, 73; 69, 74; 69, 75; 72, 76; 73, 77; 73, 78; 74, 79; 74, 80; 79, 81; 79, 82; 80, 83; 81, 84; 81, 85; 83, 86; 84, 87; 84, 88; 85, 89; 87, 90; 87, 91; 88, 92; 92, 93
def _get_all_migrations(): """ Returns sorted list of all migrations. Returns: list of (int, str) tuples: first elem of the tuple is migration number, second if module name. """ from . import migrations package = migrations prefix = package.__name__ + '.' all_migrations = [] for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix): version = int(modname.split('.')[-1].split('_')[0]) all_migrations.append((version, modname)) all_migrations = sorted(all_migrations, key=lambda x: x[0]) return all_migrations
0, module; 1, function_definition; 2, function_name:sort_genes; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:stable; 14, True; 15, identifier:inplace; 16, False; 17, identifier:ascending; 18, True; 19, comment:"""Sort the rows of the matrix alphabetically by gene name. Parameters ---------- stable: bool, optional Whether to use a stable sorting algorithm. [True] inplace: bool, optional Whether to perform the operation in place.[False] ascending: bool, optional Whether to sort in ascending order [True] Returns ------- `ExpMatrix` The sorted matrix. """; 20, assignment; 21, identifier:stable; 22, block; 23, call; 24, identifier:kind; 25, string; 26, expression_statement; 27, attribute; 28, argument_list; 29, string_content:quicksort; 30, assignment; 31, identifier:self; 32, identifier:sort_index; 33, keyword_argument; 34, keyword_argument; 35, keyword_argument; 36, identifier:kind; 37, string; 38, identifier:kind; 39, identifier:kind; 40, identifier:inplace; 41, identifier:inplace; 42, identifier:ascending; 43, identifier:ascending; 44, string_content:mergesort
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 10, 20; 11, 21; 11, 22; 12, 23; 20, 24; 20, 25; 22, 26; 23, 27; 23, 28; 25, 29; 26, 30; 27, 31; 27, 32; 28, 33; 28, 34; 28, 35; 30, 36; 30, 37; 33, 38; 33, 39; 34, 40; 34, 41; 35, 42; 35, 43; 37, 44
def sort_genes(self, stable=True, inplace=False, ascending=True): """Sort the rows of the matrix alphabetically by gene name. Parameters ---------- stable: bool, optional Whether to use a stable sorting algorithm. [True] inplace: bool, optional Whether to perform the operation in place.[False] ascending: bool, optional Whether to sort in ascending order [True] Returns ------- `ExpMatrix` The sorted matrix. """ kind = 'quicksort' if stable: kind = 'mergesort' return self.sort_index(kind=kind, inplace=inplace, ascending=ascending)
0, module; 1, function_definition; 2, function_name:sort_samples; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:stable; 14, True; 15, identifier:inplace; 16, False; 17, identifier:ascending; 18, True; 19, comment:"""Sort the columns of the matrix alphabetically by sample name. Parameters ---------- stable: bool, optional Whether to use a stable sorting algorithm. [True] inplace: bool, optional Whether to perform the operation in place.[False] ascending: bool, optional Whether to sort in ascending order [True] Returns ------- `ExpMatrix` The sorted matrix. """; 20, assignment; 21, identifier:stable; 22, block; 23, call; 24, identifier:kind; 25, string; 26, expression_statement; 27, attribute; 28, argument_list; 29, string_content:quicksort; 30, assignment; 31, identifier:self; 32, identifier:sort_index; 33, keyword_argument; 34, keyword_argument; 35, keyword_argument; 36, keyword_argument; 37, identifier:kind; 38, string; 39, identifier:axis; 40, integer:1; 41, identifier:kind; 42, identifier:kind; 43, identifier:inplace; 44, identifier:inplace; 45, identifier:ascending; 46, identifier:ascending; 47, string_content:mergesort
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 6, 14; 7, 15; 7, 16; 8, 17; 8, 18; 9, 19; 10, 20; 11, 21; 11, 22; 12, 23; 20, 24; 20, 25; 22, 26; 23, 27; 23, 28; 25, 29; 26, 30; 27, 31; 27, 32; 28, 33; 28, 34; 28, 35; 28, 36; 30, 37; 30, 38; 33, 39; 33, 40; 34, 41; 34, 42; 35, 43; 35, 44; 36, 45; 36, 46; 38, 47
def sort_samples(self, stable=True, inplace=False, ascending=True): """Sort the columns of the matrix alphabetically by sample name. Parameters ---------- stable: bool, optional Whether to use a stable sorting algorithm. [True] inplace: bool, optional Whether to perform the operation in place.[False] ascending: bool, optional Whether to sort in ascending order [True] Returns ------- `ExpMatrix` The sorted matrix. """ kind = 'quicksort' if stable: kind = 'mergesort' return self.sort_index(axis=1, kind=kind, inplace=inplace, ascending=ascending)
0, module; 1, function_definition; 2, function_name:parseColors; 3, parameters; 4, block; 5, identifier:colors; 6, identifier:defaultColor; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, comment:""" Parse command line color information. @param colors: A C{list} of space separated "value color" strings, such as ["0.9 red", "0.75 rgb(23, 190, 207)", "0.1 #CF3CF3"]. @param defaultColor: The C{str} color to use for cells that do not reach the identity fraction threshold of any color in C{colors}. @return: A C{list} of (threshold, color) tuples, where threshold is a C{float} (from C{colors}) and color is a C{str} (from C{colors}). The list will be sorted by decreasing threshold values. """; 14, assignment; 15, identifier:colors; 16, block; 17, call; 18, boolean_operator; 19, block; 20, identifier:result; 21, identifier:result; 22, list; 23, for_statement; 24, attribute; 25, argument_list; 26, not_operator; 27, comparison_operator:result[-1][0] > 0.0; 28, expression_statement; 29, identifier:colorInfo; 30, identifier:colors; 31, block; 32, identifier:result; 33, identifier:sort; 34, keyword_argument; 35, keyword_argument; 36, identifier:result; 37, subscript; 38, float:0.0; 39, call; 40, expression_statement; 41, if_statement; 42, identifier:key; 43, call; 44, identifier:reverse; 45, True; 46, subscript; 47, integer:0; 48, attribute; 49, argument_list; 50, assignment; 51, comparison_operator:len(fields) == 2; 52, block; 53, else_clause; 54, identifier:itemgetter; 55, argument_list; 56, identifier:result; 57, unary_operator; 58, identifier:result; 59, identifier:append; 60, tuple; 61, identifier:fields; 62, call; 63, call; 64, integer:2; 65, expression_statement; 66, try_statement; 67, if_statement; 68, expression_statement; 69, block; 70, integer:0; 71, integer:1; 72, float:0.0; 73, identifier:defaultColor; 74, attribute; 75, argument_list; 76, identifier:len; 77, argument_list; 78, assignment; 79, block; 80, except_clause; 81, comparison_operator:0.0 > threshold > 1.0; 82, block; 83, call; 84, expression_statement; 85, expression_statement; 86, identifier:colorInfo; 87, identifier:split; 88, keyword_argument; 89, identifier:fields; 90, pattern_list; 91, identifier:fields; 92, expression_statement; 93, identifier:ValueError; 94, block; 95, float:0.0; 96, identifier:threshold; 97, float:1.0; 98, expression_statement; 99, expression_statement; 100, attribute; 101, argument_list; 102, call; 103, call; 104, identifier:maxsplit; 105, integer:1; 106, identifier:threshold; 107, identifier:color; 108, assignment; 109, expression_statement; 110, expression_statement; 111, call; 112, call; 113, identifier:result; 114, identifier:append; 115, tuple; 116, identifier:print; 117, argument_list; 118, attribute; 119, argument_list; 120, identifier:threshold; 121, call; 122, call; 123, call; 124, identifier:print; 125, argument_list; 126, attribute; 127, argument_list; 128, identifier:threshold; 129, identifier:color; 130, binary_operator:'--color arguments must be given as space-separated ' 'pairs of "value color". You have given %r, which does ' 'not contain a space.' % colorInfo; 131, keyword_argument; 132, identifier:sys; 133, identifier:exit; 134, integer:1; 135, identifier:float; 136, argument_list; 137, identifier:print; 138, argument_list; 139, attribute; 140, argument_list; 141, binary_operator:'--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold from 0.0 to 1.0. Your ' 'value %r is not in that range.' % threshold; 142, keyword_argument; 143, identifier:sys; 144, identifier:exit; 145, integer:1; 146, concatenated_string; 147, identifier:colorInfo; 148, identifier:file; 149, attribute; 150, identifier:threshold; 151, binary_operator:'--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold. Your value %r is not ' 'numeric.' % threshold; 152, keyword_argument; 153, identifier:sys; 154, identifier:exit; 155, integer:1; 156, concatenated_string; 157, identifier:threshold; 158, identifier:file; 159, attribute; 160, string; 161, string:'pairs of "value color". You have given %r, which does '; 162, string; 163, identifier:sys; 164, identifier:stderr; 165, concatenated_string; 166, identifier:threshold; 167, identifier:file; 168, attribute; 169, string; 170, string:'pairs of "value color" where the value is a '; 171, string; 172, string; 173, identifier:sys; 174, identifier:stderr; 175, string_content:--color arguments must be given as space-separated; 176, string_content:not contain a space.; 177, string; 178, string:'pairs of "value color" where the value is a '; 179, string; 180, string; 181, identifier:sys; 182, identifier:stderr; 183, string_content:--color arguments must be given as space-separated; 184, string_content:numeric identity threshold from 0.0 to 1.0. Your; 185, string_content:value %r is not in that range.; 186, string_content:--color arguments must be given as space-separated; 187, string_content:numeric identity threshold. Your value %r is not; 188, string_content:numeric.
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 9, 16; 10, 17; 11, 18; 11, 19; 12, 20; 14, 21; 14, 22; 16, 23; 17, 24; 17, 25; 18, 26; 18, 27; 19, 28; 23, 29; 23, 30; 23, 31; 24, 32; 24, 33; 25, 34; 25, 35; 26, 36; 27, 37; 27, 38; 28, 39; 31, 40; 31, 41; 34, 42; 34, 43; 35, 44; 35, 45; 37, 46; 37, 47; 39, 48; 39, 49; 40, 50; 41, 51; 41, 52; 41, 53; 43, 54; 43, 55; 46, 56; 46, 57; 48, 58; 48, 59; 49, 60; 50, 61; 50, 62; 51, 63; 51, 64; 52, 65; 52, 66; 52, 67; 52, 68; 53, 69; 55, 70; 57, 71; 60, 72; 60, 73; 62, 74; 62, 75; 63, 76; 63, 77; 65, 78; 66, 79; 66, 80; 67, 81; 67, 82; 68, 83; 69, 84; 69, 85; 74, 86; 74, 87; 75, 88; 77, 89; 78, 90; 78, 91; 79, 92; 80, 93; 80, 94; 81, 95; 81, 96; 81, 97; 82, 98; 82, 99; 83, 100; 83, 101; 84, 102; 85, 103; 88, 104; 88, 105; 90, 106; 90, 107; 92, 108; 94, 109; 94, 110; 98, 111; 99, 112; 100, 113; 100, 114; 101, 115; 102, 116; 102, 117; 103, 118; 103, 119; 108, 120; 108, 121; 109, 122; 110, 123; 111, 124; 111, 125; 112, 126; 112, 127; 115, 128; 115, 129; 117, 130; 117, 131; 118, 132; 118, 133; 119, 134; 121, 135; 121, 136; 122, 137; 122, 138; 123, 139; 123, 140; 125, 141; 125, 142; 126, 143; 126, 144; 127, 145; 130, 146; 130, 147; 131, 148; 131, 149; 136, 150; 138, 151; 138, 152; 139, 153; 139, 154; 140, 155; 141, 156; 141, 157; 142, 158; 142, 159; 146, 160; 146, 161; 146, 162; 149, 163; 149, 164; 151, 165; 151, 166; 152, 167; 152, 168; 156, 169; 156, 170; 156, 171; 156, 172; 159, 173; 159, 174; 160, 175; 162, 176; 165, 177; 165, 178; 165, 179; 165, 180; 168, 181; 168, 182; 169, 183; 171, 184; 172, 185; 177, 186; 179, 187; 180, 188
def parseColors(colors, defaultColor): """ Parse command line color information. @param colors: A C{list} of space separated "value color" strings, such as ["0.9 red", "0.75 rgb(23, 190, 207)", "0.1 #CF3CF3"]. @param defaultColor: The C{str} color to use for cells that do not reach the identity fraction threshold of any color in C{colors}. @return: A C{list} of (threshold, color) tuples, where threshold is a C{float} (from C{colors}) and color is a C{str} (from C{colors}). The list will be sorted by decreasing threshold values. """ result = [] if colors: for colorInfo in colors: fields = colorInfo.split(maxsplit=1) if len(fields) == 2: threshold, color = fields try: threshold = float(threshold) except ValueError: print('--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold. Your value %r is not ' 'numeric.' % threshold, file=sys.stderr) sys.exit(1) if 0.0 > threshold > 1.0: print('--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold from 0.0 to 1.0. Your ' 'value %r is not in that range.' % threshold, file=sys.stderr) sys.exit(1) result.append((threshold, color)) else: print('--color arguments must be given as space-separated ' 'pairs of "value color". You have given %r, which does ' 'not contain a space.' % colorInfo, file=sys.stderr) sys.exit(1) result.sort(key=itemgetter(0), reverse=True) if not result or result[-1][0] > 0.0: result.append((0.0, defaultColor)) return result
0, module; 1, function_definition; 2, function_name:bisect_index; 3, parameters; 4, block; 5, identifier:a; 6, identifier:x; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, raise_statement; 11, comment:""" Find the leftmost index of an element in a list using binary search. Parameters ---------- a: list A sorted list. x: arbitrary The element. Returns ------- int The index. """; 12, assignment; 13, boolean_operator; 14, block; 15, identifier:ValueError; 16, identifier:i; 17, call; 18, comparison_operator:i != len(a); 19, comparison_operator:a[i] == x; 20, return_statement; 21, attribute; 22, argument_list; 23, identifier:i; 24, call; 25, subscript; 26, identifier:x; 27, identifier:i; 28, identifier:bisect; 29, identifier:bisect_left; 30, identifier:a; 31, identifier:x; 32, identifier:len; 33, argument_list; 34, identifier:a; 35, identifier:i; 36, identifier:a
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 7, 11; 8, 12; 9, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 13, 19; 14, 20; 17, 21; 17, 22; 18, 23; 18, 24; 19, 25; 19, 26; 20, 27; 21, 28; 21, 29; 22, 30; 22, 31; 24, 32; 24, 33; 25, 34; 25, 35; 33, 36
def bisect_index(a, x): """ Find the leftmost index of an element in a list using binary search. Parameters ---------- a: list A sorted list. x: arbitrary The element. Returns ------- int The index. """ i = bisect.bisect_left(a, x) if i != len(a) and a[i] == x: return i raise ValueError
0, module; 1, function_definition; 2, function_name:writeSampleIndex; 3, parameters; 4, block; 5, identifier:self; 6, identifier:fp; 7, expression_statement; 8, expression_statement; 9, comment:""" Write a file of sample indices and names, sorted by index. @param fp: A file-like object, opened for writing. """; 10, call; 11, identifier:print; 12, argument_list; 13, call; 14, keyword_argument; 15, attribute; 16, generator_expression; 17, identifier:file; 18, identifier:fp; 19, string; 20, identifier:join; 21, binary_operator:'%d %s' % (index, name); 22, for_in_clause; 23, string_content; 24, string; 25, tuple; 26, tuple_pattern; 27, call; 28, escape_sequence:\n; 29, string_content:%d %s; 30, identifier:index; 31, identifier:name; 32, identifier:index; 33, identifier:name; 34, identifier:sorted; 35, generator_expression; 36, tuple; 37, for_in_clause; 38, identifier:index; 39, identifier:name; 40, tuple_pattern; 41, call; 42, identifier:name; 43, identifier:index; 44, attribute; 45, argument_list; 46, attribute; 47, identifier:items; 48, identifier:self; 49, identifier:_samples
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 12, 13; 12, 14; 13, 15; 13, 16; 14, 17; 14, 18; 15, 19; 15, 20; 16, 21; 16, 22; 19, 23; 21, 24; 21, 25; 22, 26; 22, 27; 23, 28; 24, 29; 25, 30; 25, 31; 26, 32; 26, 33; 27, 34; 27, 35; 35, 36; 35, 37; 36, 38; 36, 39; 37, 40; 37, 41; 40, 42; 40, 43; 41, 44; 41, 45; 44, 46; 44, 47; 46, 48; 46, 49
def writeSampleIndex(self, fp): """ Write a file of sample indices and names, sorted by index. @param fp: A file-like object, opened for writing. """ print('\n'.join( '%d %s' % (index, name) for (index, name) in sorted((index, name) for (name, index) in self._samples.items()) ), file=fp)
0, module; 1, function_definition; 2, function_name:writePathogenIndex; 3, parameters; 4, block; 5, identifier:self; 6, identifier:fp; 7, expression_statement; 8, expression_statement; 9, comment:""" Write a file of pathogen indices and names, sorted by index. @param fp: A file-like object, opened for writing. """; 10, call; 11, identifier:print; 12, argument_list; 13, call; 14, keyword_argument; 15, attribute; 16, generator_expression; 17, identifier:file; 18, identifier:fp; 19, string; 20, identifier:join; 21, binary_operator:'%d %s' % (index, name); 22, for_in_clause; 23, string_content; 24, string; 25, tuple; 26, tuple_pattern; 27, call; 28, escape_sequence:\n; 29, string_content:%d %s; 30, identifier:index; 31, identifier:name; 32, identifier:index; 33, identifier:name; 34, identifier:sorted; 35, generator_expression; 36, tuple; 37, for_in_clause; 38, identifier:index; 39, identifier:name; 40, tuple_pattern; 41, call; 42, identifier:name; 43, identifier:index; 44, attribute; 45, argument_list; 46, attribute; 47, identifier:items; 48, identifier:self; 49, identifier:_pathogens
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 10, 11; 10, 12; 12, 13; 12, 14; 13, 15; 13, 16; 14, 17; 14, 18; 15, 19; 15, 20; 16, 21; 16, 22; 19, 23; 21, 24; 21, 25; 22, 26; 22, 27; 23, 28; 24, 29; 25, 30; 25, 31; 26, 32; 26, 33; 27, 34; 27, 35; 35, 36; 35, 37; 36, 38; 36, 39; 37, 40; 37, 41; 40, 42; 40, 43; 41, 44; 41, 45; 44, 46; 44, 47; 46, 48; 46, 49
def writePathogenIndex(self, fp): """ Write a file of pathogen indices and names, sorted by index. @param fp: A file-like object, opened for writing. """ print('\n'.join( '%d %s' % (index, name) for (index, name) in sorted((index, name) for (name, index) in self._pathogens.items()) ), file=fp)
0, module; 1, function_definition; 2, function_name:_transform_chrom; 3, parameters; 4, block; 5, identifier:chrom; 6, expression_statement; 7, try_statement; 8, comment:"""Helper function to obtain specific sort order."""; 9, block; 10, except_clause; 11, else_clause; 12, expression_statement; 13, block; 14, comment:# make sure numbered chromosomes are sorted numerically; 15, block; 16, assignment; 17, if_statement; 18, return_statement; 19, identifier:c; 20, call; 21, comparison_operator:chrom in ['X', 'Y']; 22, block; 23, elif_clause; 24, else_clause; 25, binary_operator:'%02d' % c; 26, identifier:int; 27, argument_list; 28, identifier:chrom; 29, list; 30, return_statement; 31, comparison_operator:chrom == 'MT'; 32, block; 33, block; 34, string; 35, identifier:c; 36, identifier:chrom; 37, string; 38, string; 39, identifier:chrom; 40, identifier:chrom; 41, string; 42, return_statement; 43, comment:# sort to the end; 44, return_statement; 45, comment:# sort to the very end; 46, string_content:%02d; 47, string_content:X; 48, string_content:Y; 49, string_content:MT; 50, string; 51, binary_operator:'__' + chrom; 52, string_content:_MT; 53, string; 54, identifier:chrom; 55, string_content:__
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 7, 10; 7, 11; 9, 12; 10, 13; 11, 14; 11, 15; 12, 16; 13, 17; 15, 18; 16, 19; 16, 20; 17, 21; 17, 22; 17, 23; 17, 24; 18, 25; 20, 26; 20, 27; 21, 28; 21, 29; 22, 30; 23, 31; 23, 32; 24, 33; 25, 34; 25, 35; 27, 36; 29, 37; 29, 38; 30, 39; 31, 40; 31, 41; 32, 42; 32, 43; 33, 44; 33, 45; 34, 46; 37, 47; 38, 48; 41, 49; 42, 50; 44, 51; 50, 52; 51, 53; 51, 54; 53, 55
def _transform_chrom(chrom): """Helper function to obtain specific sort order.""" try: c = int(chrom) except: if chrom in ['X', 'Y']: return chrom elif chrom == 'MT': return '_MT' # sort to the end else: return '__' + chrom # sort to the very end else: # make sure numbered chromosomes are sorted numerically return '%02d' % c
0, module; 1, function_definition; 2, function_name:_show; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, return_statement; 9, comment:""" Return a list of unsorted bridge details. """; 10, assignment; 11, subscript; 12, identifier:p; 13, call; 14, call; 15, slice; 16, identifier:_runshell; 17, argument_list; 18, attribute; 19, argument_list; 20, integer:7; 21, list; 22, binary_operator:"Could not show %s." % self.name; 23, call; 24, identifier:split; 25, identifier:brctlexe; 26, string; 27, attribute; 28, string:"Could not show %s."; 29, attribute; 30, attribute; 31, argument_list; 32, string_content:show; 33, identifier:self; 34, identifier:name; 35, identifier:self; 36, identifier:name; 37, attribute; 38, identifier:read; 39, identifier:p; 40, identifier:stdout
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 10, 12; 10, 13; 11, 14; 11, 15; 13, 16; 13, 17; 14, 18; 14, 19; 15, 20; 17, 21; 17, 22; 18, 23; 18, 24; 21, 25; 21, 26; 21, 27; 22, 28; 22, 29; 23, 30; 23, 31; 26, 32; 27, 33; 27, 34; 29, 35; 29, 36; 30, 37; 30, 38; 37, 39; 37, 40
def _show(self): """ Return a list of unsorted bridge details. """ p = _runshell([brctlexe, 'show', self.name], "Could not show %s." % self.name) return p.stdout.read().split()[7:]
0, module; 1, function_definition; 2, function_name:get_assembly; 3, parameters; 4, block; 5, identifier:name; 6, expression_statement; 7, expression_statement; 8, return_statement; 9, comment:"""read a single assembly by name, returning a dictionary of assembly data >>> assy = get_assembly('GRCh37.p13') >>> assy['name'] 'GRCh37.p13' >>> assy['description'] 'Genome Reference Consortium Human Build 37 patch release 13 (GRCh37.p13)' >>> assy['refseq_ac'] 'GCF_000001405.25' >>> assy['genbank_ac'] 'GCA_000001405.14' >>> len(assy['sequences']) 297 >>> import pprint >>> pprint.pprint(assy['sequences'][0]) {'aliases': ['chr1'], 'assembly_unit': 'Primary Assembly', 'genbank_ac': 'CM000663.1', 'length': 249250621, 'name': '1', 'refseq_ac': 'NC_000001.10', 'relationship': '=', 'sequence_role': 'assembled-molecule'} """; 10, assignment; 11, call; 12, identifier:fn; 13, call; 14, attribute; 15, argument_list; 16, attribute; 17, argument_list; 18, identifier:json; 19, identifier:load; 20, call; 21, identifier:pkg_resources; 22, identifier:resource_filename; 23, identifier:__name__; 24, call; 25, attribute; 26, argument_list; 27, attribute; 28, argument_list; 29, identifier:gzip; 30, identifier:open; 31, identifier:fn; 32, keyword_argument; 33, keyword_argument; 34, identifier:_assy_path_fmt; 35, identifier:format; 36, keyword_argument; 37, identifier:mode; 38, string:"rt"; 39, identifier:encoding; 40, string:"utf-8"; 41, identifier:name; 42, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 10, 12; 10, 13; 11, 14; 11, 15; 13, 16; 13, 17; 14, 18; 14, 19; 15, 20; 16, 21; 16, 22; 17, 23; 17, 24; 20, 25; 20, 26; 24, 27; 24, 28; 25, 29; 25, 30; 26, 31; 26, 32; 26, 33; 27, 34; 27, 35; 28, 36; 32, 37; 32, 38; 33, 39; 33, 40; 36, 41; 36, 42
def get_assembly(name): """read a single assembly by name, returning a dictionary of assembly data >>> assy = get_assembly('GRCh37.p13') >>> assy['name'] 'GRCh37.p13' >>> assy['description'] 'Genome Reference Consortium Human Build 37 patch release 13 (GRCh37.p13)' >>> assy['refseq_ac'] 'GCF_000001405.25' >>> assy['genbank_ac'] 'GCA_000001405.14' >>> len(assy['sequences']) 297 >>> import pprint >>> pprint.pprint(assy['sequences'][0]) {'aliases': ['chr1'], 'assembly_unit': 'Primary Assembly', 'genbank_ac': 'CM000663.1', 'length': 249250621, 'name': '1', 'refseq_ac': 'NC_000001.10', 'relationship': '=', 'sequence_role': 'assembled-molecule'} """ fn = pkg_resources.resource_filename( __name__, _assy_path_fmt.format(name=name)) return json.load(gzip.open(fn, mode="rt", encoding="utf-8"))
0, module; 1, function_definition; 2, function_name:coverageInfo; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:""" Return information about the bases found at each location in our title sequence. @return: A C{dict} whose keys are C{int} subject offsets and whose values are unsorted lists of (score, base) 2-tuples, giving all the bases from reads that matched the subject at subject location, along with the bit score of the matching read. """; 11, assignment; 12, identifier:titleAlignment; 13, identifier:self; 14, block; 15, identifier:result; 16, identifier:result; 17, call; 18, for_statement; 19, identifier:defaultdict; 20, argument_list; 21, identifier:hsp; 22, attribute; 23, block; 24, identifier:list; 25, identifier:titleAlignment; 26, identifier:hsps; 27, expression_statement; 28, for_statement; 29, assignment; 30, tuple_pattern; 31, call; 32, block; 33, identifier:score; 34, attribute; 35, identifier:subjectOffset; 36, identifier:base; 37, identifier:_; 38, attribute; 39, argument_list; 40, expression_statement; 41, attribute; 42, identifier:score; 43, attribute; 44, identifier:walkHSP; 45, identifier:hsp; 46, keyword_argument; 47, call; 48, identifier:hsp; 49, identifier:score; 50, identifier:titleAlignment; 51, identifier:read; 52, identifier:includeWhiskers; 53, False; 54, attribute; 55, argument_list; 56, subscript; 57, identifier:append; 58, tuple; 59, identifier:result; 60, identifier:subjectOffset; 61, identifier:score; 62, identifier:base
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 6, 10; 7, 11; 8, 12; 8, 13; 8, 14; 9, 15; 11, 16; 11, 17; 14, 18; 17, 19; 17, 20; 18, 21; 18, 22; 18, 23; 20, 24; 22, 25; 22, 26; 23, 27; 23, 28; 27, 29; 28, 30; 28, 31; 28, 32; 29, 33; 29, 34; 30, 35; 30, 36; 30, 37; 31, 38; 31, 39; 32, 40; 34, 41; 34, 42; 38, 43; 38, 44; 39, 45; 39, 46; 40, 47; 41, 48; 41, 49; 43, 50; 43, 51; 46, 52; 46, 53; 47, 54; 47, 55; 54, 56; 54, 57; 55, 58; 56, 59; 56, 60; 58, 61; 58, 62
def coverageInfo(self): """ Return information about the bases found at each location in our title sequence. @return: A C{dict} whose keys are C{int} subject offsets and whose values are unsorted lists of (score, base) 2-tuples, giving all the bases from reads that matched the subject at subject location, along with the bit score of the matching read. """ result = defaultdict(list) for titleAlignment in self: for hsp in titleAlignment.hsps: score = hsp.score.score for (subjectOffset, base, _) in titleAlignment.read.walkHSP( hsp, includeWhiskers=False): result[subjectOffset].append((score, base)) return result
0, module; 1, function_definition; 2, function_name:filter; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, comment:# Use a ReadSetFilter only if we're checking that read sets are; 15, comment:# sufficiently new.; 16, if_statement; 17, expression_statement; 18, if_statement; 19, for_statement; 20, return_statement; 21, identifier:minMatchingReads; 22, None; 23, identifier:minMedianScore; 24, None; 25, identifier:withScoreBetterThan; 26, None; 27, identifier:minNewReads; 28, None; 29, identifier:minCoverage; 30, None; 31, identifier:maxTitles; 32, None; 33, identifier:sortOn; 34, string; 35, comment:""" Filter the titles in self to create another TitlesAlignments. @param minMatchingReads: titles that are matched by fewer reads are unacceptable. @param minMedianScore: sequences that are matched with a median bit score that is less are unacceptable. @param withScoreBetterThan: if the best score for a title is not as good as this value, the title is not acceptable. @param minNewReads: The C{float} fraction of its reads by which a new title's read set must differ from the read sets of all previously seen titles in order for this title to be considered acceptably different (and therefore interesting). @param minCoverage: The C{float} minimum fraction of the title sequence that must be matched by at least one read. @param maxTitles: A non-negative C{int} maximum number of titles to keep. If more titles than this are present, titles will be sorted (according to C{sortOn}) and only the best will be retained. @param sortOn: A C{str} attribute to sort on, used only if C{maxTitles} is not C{None}. See the C{sortTitles} method below for the legal values. @raise: C{ValueError} if C{maxTitles} is less than zero or the value of C{sortOn} is unknown. @return: A new L{TitlesAlignments} instance containing only the matching titles. """; 36, comparison_operator:minNewReads is None; 37, block; 38, else_clause; 39, assignment; 40, boolean_operator; 41, block; 42, else_clause; 43, identifier:title; 44, identifier:titles; 45, comment:# Test max titles up front, as it may be zero.; 46, block; 47, identifier:result; 48, string_content:maxScore; 49, identifier:minNewReads; 50, None; 51, expression_statement; 52, block; 53, identifier:result; 54, call; 55, comparison_operator:maxTitles is not None; 56, comparison_operator:len(self) > maxTitles; 57, if_statement; 58, block; 59, if_statement; 60, expression_statement; 61, if_statement; 62, comment:# To compare the median score with another score, we must; 63, comment:# convert both values to instances of the score class used in; 64, comment:# this data set so they can be compared without us needing to; 65, comment:# know if numerically greater scores are considered better or; 66, comment:# not.; 67, if_statement; 68, if_statement; 69, if_statement; 70, if_statement; 71, expression_statement; 72, assignment; 73, if_statement; 74, expression_statement; 75, identifier:TitlesAlignments; 76, argument_list; 77, identifier:maxTitles; 78, None; 79, call; 80, identifier:maxTitles; 81, comparison_operator:maxTitles < 0; 82, block; 83, else_clause; 84, expression_statement; 85, boolean_operator; 86, block; 87, assignment; 88, parenthesized_expression; 89, block; 90, parenthesized_expression; 91, block; 92, parenthesized_expression; 93, block; 94, parenthesized_expression; 95, block; 96, parenthesized_expression; 97, block; 98, call; 99, identifier:readSetFilter; 100, None; 101, comparison_operator:self.readSetFilter is None; 102, block; 103, assignment; 104, attribute; 105, attribute; 106, attribute; 107, keyword_argument; 108, identifier:len; 109, argument_list; 110, identifier:maxTitles; 111, integer:0; 112, raise_statement; 113, comment:# There are too many titles. Make a sorted list of them so; 114, comment:# we loop through them (below) in the desired order and can; 115, comment:# break when/if we've reached the maximum. We can't just; 116, comment:# take the first maxTitles titles from the sorted list now,; 117, comment:# as some of those titles might later be discarded by the; 118, comment:# filter and then we'd return a result with fewer titles; 119, comment:# than we should.; 120, block; 121, assignment; 122, comparison_operator:maxTitles is not None; 123, comparison_operator:len(result) == maxTitles; 124, break_statement; 125, identifier:titleAlignments; 126, subscript; 127, boolean_operator; 128, continue_statement; 129, boolean_operator; 130, continue_statement; 131, boolean_operator; 132, continue_statement; 133, boolean_operator; 134, continue_statement; 135, boolean_operator; 136, continue_statement; 137, attribute; 138, argument_list; 139, attribute; 140, None; 141, expression_statement; 142, identifier:readSetFilter; 143, attribute; 144, identifier:self; 145, identifier:readsAlignments; 146, identifier:self; 147, identifier:scoreClass; 148, identifier:self; 149, identifier:readSetFilter; 150, identifier:importReadsAlignmentsTitles; 151, False; 152, identifier:self; 153, call; 154, expression_statement; 155, identifier:titles; 156, call; 157, identifier:maxTitles; 158, None; 159, call; 160, identifier:maxTitles; 161, identifier:self; 162, identifier:title; 163, comparison_operator:minMatchingReads is not None; 164, comparison_operator:titleAlignments.readCount() < minMatchingReads; 165, comparison_operator:minMedianScore is not None; 166, comparison_operator:self.scoreClass(titleAlignments.medianScore()) < self.scoreClass(minMedianScore); 167, comparison_operator:withScoreBetterThan is not None; 168, not_operator; 169, comparison_operator:minCoverage is not None; 170, comparison_operator:titleAlignments.coverage() < minCoverage; 171, identifier:readSetFilter; 172, not_operator; 173, identifier:result; 174, identifier:addTitle; 175, identifier:title; 176, identifier:titleAlignments; 177, identifier:self; 178, identifier:readSetFilter; 179, assignment; 180, identifier:self; 181, identifier:readSetFilter; 182, identifier:ValueError; 183, argument_list; 184, assignment; 185, attribute; 186, argument_list; 187, identifier:len; 188, argument_list; 189, identifier:minMatchingReads; 190, None; 191, call; 192, identifier:minMatchingReads; 193, identifier:minMedianScore; 194, None; 195, call; 196, call; 197, identifier:withScoreBetterThan; 198, None; 199, call; 200, identifier:minCoverage; 201, None; 202, call; 203, identifier:minCoverage; 204, call; 205, attribute; 206, call; 207, binary_operator:'maxTitles (%r) cannot be negative.' % maxTitles; 208, identifier:titles; 209, call; 210, identifier:self; 211, identifier:keys; 212, identifier:result; 213, attribute; 214, argument_list; 215, attribute; 216, argument_list; 217, attribute; 218, argument_list; 219, attribute; 220, argument_list; 221, attribute; 222, argument_list; 223, attribute; 224, argument_list; 225, identifier:self; 226, identifier:readSetFilter; 227, identifier:ReadSetFilter; 228, argument_list; 229, string; 230, identifier:maxTitles; 231, attribute; 232, argument_list; 233, identifier:titleAlignments; 234, identifier:readCount; 235, identifier:self; 236, identifier:scoreClass; 237, call; 238, identifier:self; 239, identifier:scoreClass; 240, identifier:minMedianScore; 241, identifier:titleAlignments; 242, identifier:hasScoreBetterThan; 243, identifier:withScoreBetterThan; 244, identifier:titleAlignments; 245, identifier:coverage; 246, identifier:readSetFilter; 247, identifier:accept; 248, identifier:title; 249, identifier:titleAlignments; 250, identifier:minNewReads; 251, string_content:maxTitles (%r) cannot be negative.; 252, identifier:self; 253, identifier:sortTitles; 254, identifier:sortOn; 255, attribute; 256, argument_list; 257, identifier:titleAlignments; 258, identifier:medianScore
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 6, 21; 6, 22; 7, 23; 7, 24; 8, 25; 8, 26; 9, 27; 9, 28; 10, 29; 10, 30; 11, 31; 11, 32; 12, 33; 12, 34; 13, 35; 16, 36; 16, 37; 16, 38; 17, 39; 18, 40; 18, 41; 18, 42; 19, 43; 19, 44; 19, 45; 19, 46; 20, 47; 34, 48; 36, 49; 36, 50; 37, 51; 38, 52; 39, 53; 39, 54; 40, 55; 40, 56; 41, 57; 42, 58; 46, 59; 46, 60; 46, 61; 46, 62; 46, 63; 46, 64; 46, 65; 46, 66; 46, 67; 46, 68; 46, 69; 46, 70; 46, 71; 51, 72; 52, 73; 52, 74; 54, 75; 54, 76; 55, 77; 55, 78; 56, 79; 56, 80; 57, 81; 57, 82; 57, 83; 58, 84; 59, 85; 59, 86; 60, 87; 61, 88; 61, 89; 67, 90; 67, 91; 68, 92; 68, 93; 69, 94; 69, 95; 70, 96; 70, 97; 71, 98; 72, 99; 72, 100; 73, 101; 73, 102; 74, 103; 76, 104; 76, 105; 76, 106; 76, 107; 79, 108; 79, 109; 81, 110; 81, 111; 82, 112; 83, 113; 83, 114; 83, 115; 83, 116; 83, 117; 83, 118; 83, 119; 83, 120; 84, 121; 85, 122; 85, 123; 86, 124; 87, 125; 87, 126; 88, 127; 89, 128; 90, 129; 91, 130; 92, 131; 93, 132; 94, 133; 95, 134; 96, 135; 97, 136; 98, 137; 98, 138; 101, 139; 101, 140; 102, 141; 103, 142; 103, 143; 104, 144; 104, 145; 105, 146; 105, 147; 106, 148; 106, 149; 107, 150; 107, 151; 109, 152; 112, 153; 120, 154; 121, 155; 121, 156; 122, 157; 122, 158; 123, 159; 123, 160; 126, 161; 126, 162; 127, 163; 127, 164; 129, 165; 129, 166; 131, 167; 131, 168; 133, 169; 133, 170; 135, 171; 135, 172; 137, 173; 137, 174; 138, 175; 138, 176; 139, 177; 139, 178; 141, 179; 143, 180; 143, 181; 153, 182; 153, 183; 154, 184; 156, 185; 156, 186; 159, 187; 159, 188; 163, 189; 163, 190; 164, 191; 164, 192; 165, 193; 165, 194; 166, 195; 166, 196; 167, 197; 167, 198; 168, 199; 169, 200; 169, 201; 170, 202; 170, 203; 172, 204; 179, 205; 179, 206; 183, 207; 184, 208; 184, 209; 185, 210; 185, 211; 188, 212; 191, 213; 191, 214; 195, 215; 195, 216; 196, 217; 196, 218; 199, 219; 199, 220; 202, 221; 202, 222; 204, 223; 204, 224; 205, 225; 205, 226; 206, 227; 206, 228; 207, 229; 207, 230; 209, 231; 209, 232; 213, 233; 213, 234; 215, 235; 215, 236; 216, 237; 217, 238; 217, 239; 218, 240; 219, 241; 219, 242; 220, 243; 221, 244; 221, 245; 223, 246; 223, 247; 224, 248; 224, 249; 228, 250; 229, 251; 231, 252; 231, 253; 232, 254; 237, 255; 237, 256; 255, 257; 255, 258
def filter(self, minMatchingReads=None, minMedianScore=None, withScoreBetterThan=None, minNewReads=None, minCoverage=None, maxTitles=None, sortOn='maxScore'): """ Filter the titles in self to create another TitlesAlignments. @param minMatchingReads: titles that are matched by fewer reads are unacceptable. @param minMedianScore: sequences that are matched with a median bit score that is less are unacceptable. @param withScoreBetterThan: if the best score for a title is not as good as this value, the title is not acceptable. @param minNewReads: The C{float} fraction of its reads by which a new title's read set must differ from the read sets of all previously seen titles in order for this title to be considered acceptably different (and therefore interesting). @param minCoverage: The C{float} minimum fraction of the title sequence that must be matched by at least one read. @param maxTitles: A non-negative C{int} maximum number of titles to keep. If more titles than this are present, titles will be sorted (according to C{sortOn}) and only the best will be retained. @param sortOn: A C{str} attribute to sort on, used only if C{maxTitles} is not C{None}. See the C{sortTitles} method below for the legal values. @raise: C{ValueError} if C{maxTitles} is less than zero or the value of C{sortOn} is unknown. @return: A new L{TitlesAlignments} instance containing only the matching titles. """ # Use a ReadSetFilter only if we're checking that read sets are # sufficiently new. if minNewReads is None: readSetFilter = None else: if self.readSetFilter is None: self.readSetFilter = ReadSetFilter(minNewReads) readSetFilter = self.readSetFilter result = TitlesAlignments( self.readsAlignments, self.scoreClass, self.readSetFilter, importReadsAlignmentsTitles=False) if maxTitles is not None and len(self) > maxTitles: if maxTitles < 0: raise ValueError('maxTitles (%r) cannot be negative.' % maxTitles) else: # There are too many titles. Make a sorted list of them so # we loop through them (below) in the desired order and can # break when/if we've reached the maximum. We can't just # take the first maxTitles titles from the sorted list now, # as some of those titles might later be discarded by the # filter and then we'd return a result with fewer titles # than we should. titles = self.sortTitles(sortOn) else: titles = self.keys() for title in titles: # Test max titles up front, as it may be zero. if maxTitles is not None and len(result) == maxTitles: break titleAlignments = self[title] if (minMatchingReads is not None and titleAlignments.readCount() < minMatchingReads): continue # To compare the median score with another score, we must # convert both values to instances of the score class used in # this data set so they can be compared without us needing to # know if numerically greater scores are considered better or # not. if (minMedianScore is not None and self.scoreClass(titleAlignments.medianScore()) < self.scoreClass(minMedianScore)): continue if (withScoreBetterThan is not None and not titleAlignments.hasScoreBetterThan(withScoreBetterThan)): continue if (minCoverage is not None and titleAlignments.coverage() < minCoverage): continue if (readSetFilter and not readSetFilter.accept(title, titleAlignments)): continue result.addTitle(title, titleAlignments) return result
0, module; 1, function_definition; 2, function_name:sortTitles; 3, parameters; 4, block; 5, identifier:self; 6, identifier:by; 7, expression_statement; 8, comment:# First sort titles by the secondary key, which is always the title.; 9, expression_statement; 10, comment:# Then sort on the primary key (if any).; 11, if_statement; 12, if_statement; 13, if_statement; 14, if_statement; 15, if_statement; 16, raise_statement; 17, comment:""" Sort titles by a given attribute and then by title. @param by: A C{str}, one of 'length', 'maxScore', 'medianScore', 'readCount', or 'title'. @raise ValueError: If an unknown C{by} value is given. @return: A sorted C{list} of titles. """; 18, assignment; 19, comparison_operator:by == 'length'; 20, block; 21, comparison_operator:by == 'maxScore'; 22, block; 23, comparison_operator:by == 'medianScore'; 24, block; 25, comparison_operator:by == 'readCount'; 26, block; 27, comparison_operator:by == 'title'; 28, block; 29, call; 30, identifier:titles; 31, call; 32, identifier:by; 33, string; 34, return_statement; 35, identifier:by; 36, string; 37, return_statement; 38, identifier:by; 39, string; 40, return_statement; 41, identifier:by; 42, string; 43, return_statement; 44, identifier:by; 45, string; 46, return_statement; 47, identifier:ValueError; 48, argument_list; 49, identifier:sorted; 50, argument_list; 51, string_content:length; 52, call; 53, string_content:maxScore; 54, call; 55, string_content:medianScore; 56, call; 57, string_content:readCount; 58, call; 59, string_content:title; 60, identifier:titles; 61, concatenated_string; 62, call; 63, identifier:sorted; 64, argument_list; 65, identifier:sorted; 66, argument_list; 67, identifier:sorted; 68, argument_list; 69, identifier:sorted; 70, argument_list; 71, string:'Sort attribute must be one of "length", "maxScore", '; 72, string:'"medianScore", "readCount", "title".'; 73, identifier:iter; 74, argument_list; 75, identifier:titles; 76, keyword_argument; 77, keyword_argument; 78, identifier:titles; 79, keyword_argument; 80, keyword_argument; 81, identifier:titles; 82, keyword_argument; 83, keyword_argument; 84, identifier:titles; 85, keyword_argument; 86, keyword_argument; 87, identifier:self; 88, identifier:reverse; 89, True; 90, identifier:key; 91, lambda; 92, identifier:reverse; 93, True; 94, identifier:key; 95, lambda; 96, identifier:reverse; 97, True; 98, identifier:key; 99, lambda; 100, identifier:reverse; 101, True; 102, identifier:key; 103, lambda; 104, lambda_parameters; 105, attribute; 106, lambda_parameters; 107, call; 108, lambda_parameters; 109, call; 110, lambda_parameters; 111, call; 112, identifier:title; 113, subscript; 114, identifier:subjectLength; 115, identifier:title; 116, attribute; 117, argument_list; 118, identifier:title; 119, attribute; 120, argument_list; 121, identifier:title; 122, attribute; 123, argument_list; 124, identifier:self; 125, identifier:title; 126, subscript; 127, identifier:bestHsp; 128, identifier:self; 129, identifier:scoreClass; 130, call; 131, subscript; 132, identifier:readCount; 133, identifier:self; 134, identifier:title; 135, attribute; 136, argument_list; 137, identifier:self; 138, identifier:title; 139, subscript; 140, identifier:medianScore; 141, identifier:self; 142, identifier:title
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 7, 17; 9, 18; 11, 19; 11, 20; 12, 21; 12, 22; 13, 23; 13, 24; 14, 25; 14, 26; 15, 27; 15, 28; 16, 29; 18, 30; 18, 31; 19, 32; 19, 33; 20, 34; 21, 35; 21, 36; 22, 37; 23, 38; 23, 39; 24, 40; 25, 41; 25, 42; 26, 43; 27, 44; 27, 45; 28, 46; 29, 47; 29, 48; 31, 49; 31, 50; 33, 51; 34, 52; 36, 53; 37, 54; 39, 55; 40, 56; 42, 57; 43, 58; 45, 59; 46, 60; 48, 61; 50, 62; 52, 63; 52, 64; 54, 65; 54, 66; 56, 67; 56, 68; 58, 69; 58, 70; 61, 71; 61, 72; 62, 73; 62, 74; 64, 75; 64, 76; 64, 77; 66, 78; 66, 79; 66, 80; 68, 81; 68, 82; 68, 83; 70, 84; 70, 85; 70, 86; 74, 87; 76, 88; 76, 89; 77, 90; 77, 91; 79, 92; 79, 93; 80, 94; 80, 95; 82, 96; 82, 97; 83, 98; 83, 99; 85, 100; 85, 101; 86, 102; 86, 103; 91, 104; 91, 105; 95, 106; 95, 107; 99, 108; 99, 109; 103, 110; 103, 111; 104, 112; 105, 113; 105, 114; 106, 115; 107, 116; 107, 117; 108, 118; 109, 119; 109, 120; 110, 121; 111, 122; 111, 123; 113, 124; 113, 125; 116, 126; 116, 127; 119, 128; 119, 129; 120, 130; 122, 131; 122, 132; 126, 133; 126, 134; 130, 135; 130, 136; 131, 137; 131, 138; 135, 139; 135, 140; 139, 141; 139, 142
def sortTitles(self, by): """ Sort titles by a given attribute and then by title. @param by: A C{str}, one of 'length', 'maxScore', 'medianScore', 'readCount', or 'title'. @raise ValueError: If an unknown C{by} value is given. @return: A sorted C{list} of titles. """ # First sort titles by the secondary key, which is always the title. titles = sorted(iter(self)) # Then sort on the primary key (if any). if by == 'length': return sorted( titles, reverse=True, key=lambda title: self[title].subjectLength) if by == 'maxScore': return sorted( titles, reverse=True, key=lambda title: self[title].bestHsp()) if by == 'medianScore': return sorted( titles, reverse=True, key=lambda title: self.scoreClass(self[title].medianScore())) if by == 'readCount': return sorted( titles, reverse=True, key=lambda title: self[title].readCount()) if by == 'title': return titles raise ValueError('Sort attribute must be one of "length", "maxScore", ' '"medianScore", "readCount", "title".')
0, module; 1, function_definition; 2, function_name:summary; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, identifier:sortOn; 11, None; 12, comment:""" Summarize all the alignments for this title. @param sortOn: A C{str} attribute to sort titles on. One of 'length', 'maxScore', 'medianScore', 'readCount', or 'title'. @raise ValueError: If an unknown C{sortOn} value is given. @return: A generator that yields C{dict} instances as produced by C{TitleAlignments} (see class earlier in this file), sorted by C{sortOn}. """; 13, assignment; 14, identifier:title; 15, identifier:titles; 16, block; 17, identifier:titles; 18, conditional_expression:self if sortOn is None else self.sortTitles(sortOn); 19, expression_statement; 20, identifier:self; 21, comparison_operator:sortOn is None; 22, call; 23, yield; 24, identifier:sortOn; 25, None; 26, attribute; 27, argument_list; 28, call; 29, identifier:self; 30, identifier:sortTitles; 31, identifier:sortOn; 32, attribute; 33, argument_list; 34, subscript; 35, identifier:summary; 36, identifier:self; 37, identifier:title
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 6, 10; 6, 11; 7, 12; 8, 13; 9, 14; 9, 15; 9, 16; 13, 17; 13, 18; 16, 19; 18, 20; 18, 21; 18, 22; 19, 23; 21, 24; 21, 25; 22, 26; 22, 27; 23, 28; 26, 29; 26, 30; 27, 31; 28, 32; 28, 33; 32, 34; 32, 35; 34, 36; 34, 37
def summary(self, sortOn=None): """ Summarize all the alignments for this title. @param sortOn: A C{str} attribute to sort titles on. One of 'length', 'maxScore', 'medianScore', 'readCount', or 'title'. @raise ValueError: If an unknown C{sortOn} value is given. @return: A generator that yields C{dict} instances as produced by C{TitleAlignments} (see class earlier in this file), sorted by C{sortOn}. """ titles = self if sortOn is None else self.sortTitles(sortOn) for title in titles: yield self[title].summary()
0, module; 1, function_definition; 2, function_name:tabSeparatedSummary; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, comment:# The order of the fields returned here is somewhat arbitrary. The; 9, comment:# subject titles are last because they are so variable in length.; 10, comment:# Putting them last makes it more likely that the initial columns in; 11, comment:# printed output will be easier to read down.; 12, comment:#; 13, comment:# Note that post-processing scripts will be relying on the field; 14, comment:# ordering here. So you can't just add fields. It's probably safe; 15, comment:# to add them at the end, but be careful / think.; 16, comment:#; 17, comment:# A TAB-separated file can easily be read by awk using e.g.,; 18, comment:# awk 'BEGIN {FS = "\t"} ...'; 19, expression_statement; 20, for_statement; 21, return_statement; 22, identifier:sortOn; 23, None; 24, comment:""" Summarize all the alignments for this title as multi-line string with TAB-separated values on each line. @param sortOn: A C{str} attribute to sort titles on. One of 'length', 'maxScore', 'medianScore', 'readCount', or 'title'. @raise ValueError: If an unknown C{sortOn} value is given. @return: A newline-separated C{str}, each line with a summary of a title. Each summary line is TAB-separated. """; 25, assignment; 26, identifier:titleSummary; 27, call; 28, block; 29, call; 30, identifier:result; 31, list; 32, attribute; 33, argument_list; 34, expression_statement; 35, attribute; 36, argument_list; 37, identifier:self; 38, identifier:summary; 39, identifier:sortOn; 40, call; 41, string; 42, identifier:join; 43, identifier:result; 44, attribute; 45, argument_list; 46, string_content; 47, identifier:result; 48, identifier:append; 49, binary_operator:'\t'.join([ '%(coverage)f', '%(medianScore)f', '%(bestScore)f', '%(readCount)d', '%(hspCount)d', '%(subjectLength)d', '%(subjectTitle)s', ]) % titleSummary; 50, escape_sequence:\n; 51, call; 52, identifier:titleSummary; 53, attribute; 54, argument_list; 55, string; 56, identifier:join; 57, list; 58, string_content; 59, string; 60, string; 61, string; 62, string; 63, string; 64, string; 65, string; 66, escape_sequence:\t; 67, string_content:%(coverage)f; 68, string_content:%(medianScore)f; 69, string_content:%(bestScore)f; 70, string_content:%(readCount)d; 71, string_content:%(hspCount)d; 72, string_content:%(subjectLength)d; 73, string_content:%(subjectTitle)s
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 6, 22; 6, 23; 7, 24; 19, 25; 20, 26; 20, 27; 20, 28; 21, 29; 25, 30; 25, 31; 27, 32; 27, 33; 28, 34; 29, 35; 29, 36; 32, 37; 32, 38; 33, 39; 34, 40; 35, 41; 35, 42; 36, 43; 40, 44; 40, 45; 41, 46; 44, 47; 44, 48; 45, 49; 46, 50; 49, 51; 49, 52; 51, 53; 51, 54; 53, 55; 53, 56; 54, 57; 55, 58; 57, 59; 57, 60; 57, 61; 57, 62; 57, 63; 57, 64; 57, 65; 58, 66; 59, 67; 60, 68; 61, 69; 62, 70; 63, 71; 64, 72; 65, 73
def tabSeparatedSummary(self, sortOn=None): """ Summarize all the alignments for this title as multi-line string with TAB-separated values on each line. @param sortOn: A C{str} attribute to sort titles on. One of 'length', 'maxScore', 'medianScore', 'readCount', or 'title'. @raise ValueError: If an unknown C{sortOn} value is given. @return: A newline-separated C{str}, each line with a summary of a title. Each summary line is TAB-separated. """ # The order of the fields returned here is somewhat arbitrary. The # subject titles are last because they are so variable in length. # Putting them last makes it more likely that the initial columns in # printed output will be easier to read down. # # Note that post-processing scripts will be relying on the field # ordering here. So you can't just add fields. It's probably safe # to add them at the end, but be careful / think. # # A TAB-separated file can easily be read by awk using e.g., # awk 'BEGIN {FS = "\t"} ...' result = [] for titleSummary in self.summary(sortOn): result.append('\t'.join([ '%(coverage)f', '%(medianScore)f', '%(bestScore)f', '%(readCount)d', '%(hspCount)d', '%(subjectLength)d', '%(subjectTitle)s', ]) % titleSummary) return '\n'.join(result)
0, module; 1, function_definition; 2, function_name:infer_namespaces; 3, parameters; 4, block; 5, identifier:ac; 6, expression_statement; 7, return_statement; 8, comment:"""infer possible namespaces of given accession based on syntax Always returns a list, possibly empty >>> infer_namespaces("ENST00000530893.6") ['ensembl'] >>> infer_namespaces("ENST00000530893") ['ensembl'] >>> infer_namespaces("ENSQ00000530893") [] >>> infer_namespaces("NM_01234") ['refseq'] >>> infer_namespaces("NM_01234.5") ['refseq'] >>> infer_namespaces("NQ_01234.5") [] >>> infer_namespaces("A2BC19") ['uniprot'] >>> sorted(infer_namespaces("P12345")) ['insdc', 'uniprot'] >>> infer_namespaces("A0A022YWF9") ['uniprot'] """; 9, list_comprehension; 10, identifier:v; 11, for_in_clause; 12, if_clause; 13, pattern_list; 14, call; 15, call; 16, identifier:k; 17, identifier:v; 18, attribute; 19, argument_list; 20, attribute; 21, argument_list; 22, identifier:ac_namespace_regexps; 23, identifier:items; 24, identifier:k; 25, identifier:match; 26, identifier:ac
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 6, 8; 7, 9; 9, 10; 9, 11; 9, 12; 11, 13; 11, 14; 12, 15; 13, 16; 13, 17; 14, 18; 14, 19; 15, 20; 15, 21; 18, 22; 18, 23; 20, 24; 20, 25; 21, 26
def infer_namespaces(ac): """infer possible namespaces of given accession based on syntax Always returns a list, possibly empty >>> infer_namespaces("ENST00000530893.6") ['ensembl'] >>> infer_namespaces("ENST00000530893") ['ensembl'] >>> infer_namespaces("ENSQ00000530893") [] >>> infer_namespaces("NM_01234") ['refseq'] >>> infer_namespaces("NM_01234.5") ['refseq'] >>> infer_namespaces("NQ_01234.5") [] >>> infer_namespaces("A2BC19") ['uniprot'] >>> sorted(infer_namespaces("P12345")) ['insdc', 'uniprot'] >>> infer_namespaces("A0A022YWF9") ['uniprot'] """ return [v for k, v in ac_namespace_regexps.items() if k.match(ac)]
0, module; 1, function_definition; 2, function_name:to_digraph; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, comment:# TODO: make test for this; 10, expression_statement; 11, for_statement; 12, return_statement; 13, identifier:args; 14, identifier:kwargs; 15, comment:""" Compute a directed graph for the chemical system. Returns ------- digraph : `networkx.DiGraph` Graph nodes are reactants and/or products of chemical equations, while edges represent the equations themselves. Double ended edges are used to represent equilibria. Attributes are computed with `ChemicalEquation.to_series` for each equation (see examples below). Notes ----- Further arguments and keywords are passed directly to `ChemicalEquation.to_series`. Examples -------- >>> from pyrrole import ChemicalSystem >>> from pyrrole.atoms import create_data, read_cclib >>> data = create_data( ... read_cclib("data/acetate/acetic_acid.out", "AcOH(g)"), ... read_cclib("data/acetate/[email protected]", "AcOH(aq)")) >>> equilibrium = ChemicalSystem("AcOH(g) <=> AcOH(aq)", data) >>> digraph = equilibrium.to_digraph() >>> sorted(digraph.nodes(data='freeenergy')) [('AcOH(aq)', -228.57526805), ('AcOH(g)', -228.56450866)] >>> digraph.number_of_nodes() 2 >>> digraph.number_of_edges() 2 """; 16, assignment; 17, identifier:equation; 18, attribute; 19, block; 20, identifier:digraph; 21, identifier:digraph; 22, call; 23, identifier:self; 24, identifier:equations; 25, expression_statement; 26, try_statement; 27, expression_statement; 28, try_statement; 29, expression_statement; 30, try_statement; 31, expression_statement; 32, if_statement; 33, attribute; 34, argument_list; 35, assignment; 36, block; 37, except_clause; 38, call; 39, block; 40, except_clause; 41, call; 42, block; 43, except_clause; 44, call; 45, comparison_operator:arrow == '<=>'; 46, block; 47, identifier:_nx; 48, identifier:DiGraph; 49, pattern_list; 50, list_comprehension; 51, expression_statement; 52, identifier:ValueError; 53, block; 54, attribute; 55, argument_list; 56, expression_statement; 57, identifier:ValueError; 58, block; 59, attribute; 60, argument_list; 61, expression_statement; 62, identifier:ValueError; 63, block; 64, attribute; 65, argument_list; 66, identifier:arrow; 67, string; 68, expression_statement; 69, identifier:reactants; 70, identifier:arrow; 71, identifier:products; 72, call; 73, for_in_clause; 74, assignment; 75, expression_statement; 76, identifier:digraph; 77, identifier:add_node; 78, identifier:reactants; 79, dictionary_splat; 80, assignment; 81, expression_statement; 82, identifier:digraph; 83, identifier:add_node; 84, identifier:products; 85, dictionary_splat; 86, assignment; 87, expression_statement; 88, identifier:digraph; 89, identifier:add_edge; 90, identifier:reactants; 91, identifier:products; 92, dictionary_splat; 93, string_content:<=>; 94, call; 95, attribute; 96, argument_list; 97, identifier:value; 98, call; 99, identifier:attr; 100, call; 101, assignment; 102, identifier:attr; 103, identifier:attr; 104, call; 105, assignment; 106, identifier:attr; 107, identifier:attr; 108, call; 109, assignment; 110, identifier:attr; 111, attribute; 112, argument_list; 113, identifier:value; 114, identifier:strip; 115, identifier:_split_arrows; 116, argument_list; 117, attribute; 118, argument_list; 119, identifier:attr; 120, call; 121, attribute; 122, argument_list; 123, identifier:attr; 124, call; 125, attribute; 126, argument_list; 127, identifier:attr; 128, call; 129, identifier:digraph; 130, identifier:add_edge; 131, identifier:products; 132, identifier:reactants; 133, dictionary_splat; 134, call; 135, call; 136, identifier:to_dict; 137, identifier:dict; 138, argument_list; 139, call; 140, identifier:to_dict; 141, identifier:dict; 142, argument_list; 143, call; 144, identifier:to_dict; 145, identifier:dict; 146, argument_list; 147, identifier:attr; 148, identifier:str; 149, argument_list; 150, attribute; 151, argument_list; 152, attribute; 153, argument_list; 154, attribute; 155, argument_list; 156, identifier:equation; 157, identifier:equation; 158, identifier:to_series; 159, string:"reactants"; 160, list_splat; 161, dictionary_splat; 162, identifier:equation; 163, identifier:to_series; 164, string:"products"; 165, list_splat; 166, dictionary_splat; 167, identifier:equation; 168, identifier:to_series; 169, list_splat; 170, dictionary_splat; 171, identifier:args; 172, identifier:kwargs; 173, identifier:args; 174, identifier:kwargs; 175, identifier:args; 176, identifier:kwargs
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 6, 13; 7, 14; 8, 15; 10, 16; 11, 17; 11, 18; 11, 19; 12, 20; 16, 21; 16, 22; 18, 23; 18, 24; 19, 25; 19, 26; 19, 27; 19, 28; 19, 29; 19, 30; 19, 31; 19, 32; 22, 33; 22, 34; 25, 35; 26, 36; 26, 37; 27, 38; 28, 39; 28, 40; 29, 41; 30, 42; 30, 43; 31, 44; 32, 45; 32, 46; 33, 47; 33, 48; 35, 49; 35, 50; 36, 51; 37, 52; 37, 53; 38, 54; 38, 55; 39, 56; 40, 57; 40, 58; 41, 59; 41, 60; 42, 61; 43, 62; 43, 63; 44, 64; 44, 65; 45, 66; 45, 67; 46, 68; 49, 69; 49, 70; 49, 71; 50, 72; 50, 73; 51, 74; 53, 75; 54, 76; 54, 77; 55, 78; 55, 79; 56, 80; 58, 81; 59, 82; 59, 83; 60, 84; 60, 85; 61, 86; 63, 87; 64, 88; 64, 89; 65, 90; 65, 91; 65, 92; 67, 93; 68, 94; 72, 95; 72, 96; 73, 97; 73, 98; 74, 99; 74, 100; 75, 101; 79, 102; 80, 103; 80, 104; 81, 105; 85, 106; 86, 107; 86, 108; 87, 109; 92, 110; 94, 111; 94, 112; 95, 113; 95, 114; 98, 115; 98, 116; 100, 117; 100, 118; 101, 119; 101, 120; 104, 121; 104, 122; 105, 123; 105, 124; 108, 125; 108, 126; 109, 127; 109, 128; 111, 129; 111, 130; 112, 131; 112, 132; 112, 133; 116, 134; 117, 135; 117, 136; 120, 137; 120, 138; 121, 139; 121, 140; 124, 141; 124, 142; 125, 143; 125, 144; 128, 145; 128, 146; 133, 147; 134, 148; 134, 149; 135, 150; 135, 151; 139, 152; 139, 153; 143, 154; 143, 155; 149, 156; 150, 157; 150, 158; 151, 159; 151, 160; 151, 161; 152, 162; 152, 163; 153, 164; 153, 165; 153, 166; 154, 167; 154, 168; 155, 169; 155, 170; 160, 171; 161, 172; 165, 173; 166, 174; 169, 175; 170, 176
def to_digraph(self, *args, **kwargs): """ Compute a directed graph for the chemical system. Returns ------- digraph : `networkx.DiGraph` Graph nodes are reactants and/or products of chemical equations, while edges represent the equations themselves. Double ended edges are used to represent equilibria. Attributes are computed with `ChemicalEquation.to_series` for each equation (see examples below). Notes ----- Further arguments and keywords are passed directly to `ChemicalEquation.to_series`. Examples -------- >>> from pyrrole import ChemicalSystem >>> from pyrrole.atoms import create_data, read_cclib >>> data = create_data( ... read_cclib("data/acetate/acetic_acid.out", "AcOH(g)"), ... read_cclib("data/acetate/[email protected]", "AcOH(aq)")) >>> equilibrium = ChemicalSystem("AcOH(g) <=> AcOH(aq)", data) >>> digraph = equilibrium.to_digraph() >>> sorted(digraph.nodes(data='freeenergy')) [('AcOH(aq)', -228.57526805), ('AcOH(g)', -228.56450866)] >>> digraph.number_of_nodes() 2 >>> digraph.number_of_edges() 2 """ # TODO: make test for this digraph = _nx.DiGraph() for equation in self.equations: reactants, arrow, products = [value.strip() for value in _split_arrows(str(equation))] try: attr = equation.to_series("reactants", *args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_node(reactants, **attr) try: attr = equation.to_series("products", *args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_node(products, **attr) try: attr = equation.to_series(*args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_edge(reactants, products, **attr) if arrow == '<=>': digraph.add_edge(products, reactants, **attr) return digraph
0, module; 1, function_definition; 2, function_name:get_streams; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, identifier:game; 19, None; 20, identifier:channels; 21, None; 22, identifier:limit; 23, integer:25; 24, identifier:offset; 25, integer:0; 26, comment:"""Return a list of streams queried by a number of parameters sorted by number of viewers descending :param game: the game or name of the game :type game: :class:`str` | :class:`models.Game` :param channels: list of models.Channels or channel names (can be mixed) :type channels: :class:`list` of :class:`models.Channel` or :class:`str` :param limit: maximum number of results :type limit: :class:`int` :param offset: offset for pagination :type offset: :class:`int` :returns: A list of streams :rtype: :class:`list` of :class:`models.Stream` :raises: None """; 27, call; 28, block; 29, assignment; 30, assignment; 31, identifier:channels; 32, block; 33, assignment; 34, assignment; 35, call; 36, identifier:isinstance; 37, argument_list; 38, expression_statement; 39, identifier:channelnames; 40, list; 41, identifier:cparam; 42, None; 43, for_statement; 44, expression_statement; 45, identifier:params; 46, dictionary; 47, identifier:r; 48, call; 49, attribute; 50, argument_list; 51, identifier:game; 52, attribute; 53, assignment; 54, identifier:c; 55, identifier:channels; 56, block; 57, assignment; 58, pair; 59, pair; 60, pair; 61, pair; 62, attribute; 63, argument_list; 64, attribute; 65, identifier:wrap_search; 66, identifier:r; 67, identifier:models; 68, identifier:Game; 69, identifier:game; 70, attribute; 71, if_statement; 72, expression_statement; 73, identifier:cparam; 74, call; 75, string; 76, identifier:limit; 77, string; 78, identifier:offset; 79, string; 80, identifier:game; 81, string; 82, identifier:cparam; 83, identifier:self; 84, identifier:kraken_request; 85, string; 86, string; 87, keyword_argument; 88, identifier:models; 89, identifier:Stream; 90, identifier:game; 91, identifier:name; 92, call; 93, block; 94, call; 95, attribute; 96, argument_list; 97, string_content:limit; 98, string_content:offset; 99, string_content:game; 100, string_content:channel; 101, string_content:GET; 102, string_content:streams; 103, identifier:params; 104, identifier:params; 105, identifier:isinstance; 106, argument_list; 107, expression_statement; 108, attribute; 109, argument_list; 110, string; 111, identifier:join; 112, identifier:channelnames; 113, identifier:c; 114, attribute; 115, assignment; 116, identifier:channelnames; 117, identifier:append; 118, identifier:c; 119, string_content:,; 120, identifier:models; 121, identifier:Channel; 122, identifier:c; 123, attribute; 124, identifier:c; 125, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 6, 18; 6, 19; 7, 20; 7, 21; 8, 22; 8, 23; 9, 24; 9, 25; 10, 26; 11, 27; 11, 28; 12, 29; 13, 30; 14, 31; 14, 32; 15, 33; 16, 34; 17, 35; 27, 36; 27, 37; 28, 38; 29, 39; 29, 40; 30, 41; 30, 42; 32, 43; 32, 44; 33, 45; 33, 46; 34, 47; 34, 48; 35, 49; 35, 50; 37, 51; 37, 52; 38, 53; 43, 54; 43, 55; 43, 56; 44, 57; 46, 58; 46, 59; 46, 60; 46, 61; 48, 62; 48, 63; 49, 64; 49, 65; 50, 66; 52, 67; 52, 68; 53, 69; 53, 70; 56, 71; 56, 72; 57, 73; 57, 74; 58, 75; 58, 76; 59, 77; 59, 78; 60, 79; 60, 80; 61, 81; 61, 82; 62, 83; 62, 84; 63, 85; 63, 86; 63, 87; 64, 88; 64, 89; 70, 90; 70, 91; 71, 92; 71, 93; 72, 94; 74, 95; 74, 96; 75, 97; 77, 98; 79, 99; 81, 100; 85, 101; 86, 102; 87, 103; 87, 104; 92, 105; 92, 106; 93, 107; 94, 108; 94, 109; 95, 110; 95, 111; 96, 112; 106, 113; 106, 114; 107, 115; 108, 116; 108, 117; 109, 118; 110, 119; 114, 120; 114, 121; 115, 122; 115, 123; 123, 124; 123, 125
def get_streams(self, game=None, channels=None, limit=25, offset=0): """Return a list of streams queried by a number of parameters sorted by number of viewers descending :param game: the game or name of the game :type game: :class:`str` | :class:`models.Game` :param channels: list of models.Channels or channel names (can be mixed) :type channels: :class:`list` of :class:`models.Channel` or :class:`str` :param limit: maximum number of results :type limit: :class:`int` :param offset: offset for pagination :type offset: :class:`int` :returns: A list of streams :rtype: :class:`list` of :class:`models.Stream` :raises: None """ if isinstance(game, models.Game): game = game.name channelnames = [] cparam = None if channels: for c in channels: if isinstance(c, models.Channel): c = c.name channelnames.append(c) cparam = ','.join(channelnames) params = {'limit': limit, 'offset': offset, 'game': game, 'channel': cparam} r = self.kraken_request('GET', 'streams', params=params) return models.Stream.wrap_search(r)
0, module; 1, function_definition; 2, function_name:sort_queryset; 3, parameters; 4, block; 5, identifier:queryset; 6, identifier:request; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, return_statement; 12, identifier:context; 13, None; 14, comment:""" Returns a sorted queryset The context argument is only used in the template tag """; 15, assignment; 16, identifier:sort_by; 17, block; 18, identifier:queryset; 19, identifier:sort_by; 20, call; 21, if_statement; 22, attribute; 23, argument_list; 24, comparison_operator:sort_by in [el.name for el in queryset.model._meta.fields]; 25, block; 26, else_clause; 27, attribute; 28, identifier:get; 29, string; 30, identifier:sort_by; 31, list_comprehension; 32, expression_statement; 33, block; 34, identifier:request; 35, identifier:GET; 36, string_content:sort_by; 37, attribute; 38, for_in_clause; 39, assignment; 40, if_statement; 41, identifier:el; 42, identifier:name; 43, identifier:el; 44, attribute; 45, identifier:queryset; 46, call; 47, comparison_operator:sort_by in request.session; 48, block; 49, comment:# added else to fix a bug when using changelist; 50, comment:# TODO: use less ifs and more standard sorting; 51, elif_clause; 52, attribute; 53, identifier:fields; 54, attribute; 55, argument_list; 56, identifier:sort_by; 57, attribute; 58, expression_statement; 59, try_statement; 60, comparison_operator:context is not None; 61, comment:# sorted ascending; 62, block; 63, attribute; 64, identifier:_meta; 65, identifier:queryset; 66, identifier:order_by; 67, identifier:sort_by; 68, identifier:request; 69, identifier:session; 70, assignment; 71, block; 72, except_clause; 73, identifier:context; 74, None; 75, if_statement; 76, expression_statement; 77, identifier:queryset; 78, identifier:model; 79, identifier:sort_by; 80, subscript; 81, expression_statement; 82, block; 83, comparison_operator:sort_by[0] != '-'; 84, block; 85, comment:# sorted descending; 86, else_clause; 87, assignment; 88, attribute; 89, identifier:sort_by; 90, assignment; 91, raise_statement; 92, subscript; 93, string; 94, expression_statement; 95, block; 96, identifier:queryset; 97, call; 98, identifier:request; 99, identifier:session; 100, identifier:queryset; 101, call; 102, identifier:sort_by; 103, integer:0; 104, string_content:-; 105, assignment; 106, expression_statement; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, identifier:sort_by; 112, subscript; 113, assignment; 114, identifier:queryset; 115, identifier:order_by; 116, identifier:sort_by; 117, identifier:queryset; 118, identifier:order_by; 119, identifier:sort_by; 120, attribute; 121, binary_operator:int(sort_by) - 1; 122, identifier:sort_by; 123, binary_operator:'-' + context['cl'].list_display[abs(int(sort_by)) - 1]; 124, subscript; 125, identifier:list_display; 126, call; 127, integer:1; 128, string; 129, subscript; 130, identifier:context; 131, string; 132, identifier:int; 133, argument_list; 134, string_content:-; 135, attribute; 136, binary_operator:abs(int(sort_by)) - 1; 137, string_content:cl; 138, identifier:sort_by; 139, subscript; 140, identifier:list_display; 141, call; 142, integer:1; 143, identifier:context; 144, string; 145, identifier:abs; 146, argument_list; 147, string_content:cl; 148, call; 149, identifier:int; 150, argument_list; 151, identifier:sort_by
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 7, 13; 8, 14; 9, 15; 10, 16; 10, 17; 11, 18; 15, 19; 15, 20; 17, 21; 20, 22; 20, 23; 21, 24; 21, 25; 21, 26; 22, 27; 22, 28; 23, 29; 24, 30; 24, 31; 25, 32; 26, 33; 27, 34; 27, 35; 29, 36; 31, 37; 31, 38; 32, 39; 33, 40; 37, 41; 37, 42; 38, 43; 38, 44; 39, 45; 39, 46; 40, 47; 40, 48; 40, 49; 40, 50; 40, 51; 44, 52; 44, 53; 46, 54; 46, 55; 47, 56; 47, 57; 48, 58; 48, 59; 51, 60; 51, 61; 51, 62; 52, 63; 52, 64; 54, 65; 54, 66; 55, 67; 57, 68; 57, 69; 58, 70; 59, 71; 59, 72; 60, 73; 60, 74; 62, 75; 62, 76; 63, 77; 63, 78; 70, 79; 70, 80; 71, 81; 72, 82; 75, 83; 75, 84; 75, 85; 75, 86; 76, 87; 80, 88; 80, 89; 81, 90; 82, 91; 83, 92; 83, 93; 84, 94; 86, 95; 87, 96; 87, 97; 88, 98; 88, 99; 90, 100; 90, 101; 92, 102; 92, 103; 93, 104; 94, 105; 95, 106; 97, 107; 97, 108; 101, 109; 101, 110; 105, 111; 105, 112; 106, 113; 107, 114; 107, 115; 108, 116; 109, 117; 109, 118; 110, 119; 112, 120; 112, 121; 113, 122; 113, 123; 120, 124; 120, 125; 121, 126; 121, 127; 123, 128; 123, 129; 124, 130; 124, 131; 126, 132; 126, 133; 128, 134; 129, 135; 129, 136; 131, 137; 133, 138; 135, 139; 135, 140; 136, 141; 136, 142; 139, 143; 139, 144; 141, 145; 141, 146; 144, 147; 146, 148; 148, 149; 148, 150; 150, 151
def sort_queryset(queryset, request, context=None): """ Returns a sorted queryset The context argument is only used in the template tag """ sort_by = request.GET.get('sort_by') if sort_by: if sort_by in [el.name for el in queryset.model._meta.fields]: queryset = queryset.order_by(sort_by) else: if sort_by in request.session: sort_by = request.session[sort_by] try: queryset = queryset.order_by(sort_by) except: raise # added else to fix a bug when using changelist # TODO: use less ifs and more standard sorting elif context is not None: # sorted ascending if sort_by[0] != '-': sort_by = context['cl'].list_display[int(sort_by) - 1] # sorted descending else: sort_by = '-' + context['cl'].list_display[abs(int(sort_by)) - 1] queryset = queryset.order_by(sort_by) return queryset
0, module; 1, function_definition; 2, function_name:percentile; 3, parameters; 4, block; 5, identifier:data; 6, identifier:n; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, return_statement; 12, comment:"""Return the n-th percentile of the given data Assume that the data are already sorted """; 13, assignment; 14, assignment; 15, boolean_operator; 16, block; 17, subscript; 18, identifier:size; 19, call; 20, identifier:idx; 21, binary_operator:(n / 100.0) * size - 0.5; 22, comparison_operator:idx < 0; 23, comparison_operator:idx > size; 24, raise_statement; 25, identifier:data; 26, call; 27, identifier:len; 28, argument_list; 29, binary_operator:(n / 100.0) * size; 30, float:0.5; 31, identifier:idx; 32, integer:0; 33, identifier:idx; 34, identifier:size; 35, call; 36, identifier:int; 37, argument_list; 38, identifier:data; 39, parenthesized_expression; 40, identifier:size; 41, identifier:StatisticsError; 42, argument_list; 43, identifier:idx; 44, binary_operator:n / 100.0; 45, call; 46, identifier:n; 47, float:100.0; 48, attribute; 49, argument_list; 50, string:"Too few data points ({}) for {}th percentile"; 51, identifier:format; 52, identifier:size; 53, identifier:n
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 7, 12; 8, 13; 9, 14; 10, 15; 10, 16; 11, 17; 13, 18; 13, 19; 14, 20; 14, 21; 15, 22; 15, 23; 16, 24; 17, 25; 17, 26; 19, 27; 19, 28; 21, 29; 21, 30; 22, 31; 22, 32; 23, 33; 23, 34; 24, 35; 26, 36; 26, 37; 28, 38; 29, 39; 29, 40; 35, 41; 35, 42; 37, 43; 39, 44; 42, 45; 44, 46; 44, 47; 45, 48; 45, 49; 48, 50; 48, 51; 49, 52; 49, 53
def percentile(data, n): """Return the n-th percentile of the given data Assume that the data are already sorted """ size = len(data) idx = (n / 100.0) * size - 0.5 if idx < 0 or idx > size: raise StatisticsError("Too few data points ({}) for {}th percentile".format(size, n)) return data[int(idx)]
0, module; 1, function_definition; 2, function_name:get_histogram; 3, parameters; 4, block; 5, identifier:data; 6, expression_statement; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, return_statement; 16, comment:"""Return the histogram relative to the given data Assume that the data are already sorted """; 17, assignment; 18, comparison_operator:count < 2; 19, block; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, assignment; 25, identifier:value; 26, identifier:data; 27, block; 28, call; 29, identifier:count; 30, call; 31, identifier:count; 32, integer:2; 33, raise_statement; 34, identifier:min_; 35, subscript; 36, identifier:max_; 37, subscript; 38, identifier:std; 39, call; 40, identifier:bins; 41, call; 42, identifier:res; 43, dictionary_comprehension; 44, for_statement; 45, identifier:sorted; 46, argument_list; 47, identifier:len; 48, argument_list; 49, call; 50, identifier:data; 51, integer:0; 52, identifier:data; 53, unary_operator; 54, identifier:stdev; 55, argument_list; 56, identifier:get_histogram_bins; 57, argument_list; 58, pair; 59, for_in_clause; 60, identifier:bin_; 61, identifier:bins; 62, block; 63, call; 64, identifier:data; 65, identifier:StatisticsError; 66, argument_list; 67, integer:1; 68, identifier:data; 69, identifier:min_; 70, identifier:max_; 71, identifier:std; 72, identifier:count; 73, identifier:x; 74, integer:0; 75, identifier:x; 76, identifier:bins; 77, if_statement; 78, identifier:iteritems; 79, argument_list; 80, call; 81, comparison_operator:value <= bin_; 82, block; 83, identifier:res; 84, attribute; 85, argument_list; 86, identifier:value; 87, identifier:bin_; 88, expression_statement; 89, break_statement; 90, string; 91, identifier:format; 92, identifier:count; 93, augmented_assignment; 94, string_content:Too few data points ({}) for get_histogram; 95, subscript; 96, integer:1; 97, identifier:res; 98, identifier:bin_
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 6, 16; 7, 17; 8, 18; 8, 19; 9, 20; 10, 21; 11, 22; 12, 23; 13, 24; 14, 25; 14, 26; 14, 27; 15, 28; 17, 29; 17, 30; 18, 31; 18, 32; 19, 33; 20, 34; 20, 35; 21, 36; 21, 37; 22, 38; 22, 39; 23, 40; 23, 41; 24, 42; 24, 43; 27, 44; 28, 45; 28, 46; 30, 47; 30, 48; 33, 49; 35, 50; 35, 51; 37, 52; 37, 53; 39, 54; 39, 55; 41, 56; 41, 57; 43, 58; 43, 59; 44, 60; 44, 61; 44, 62; 46, 63; 48, 64; 49, 65; 49, 66; 53, 67; 55, 68; 57, 69; 57, 70; 57, 71; 57, 72; 58, 73; 58, 74; 59, 75; 59, 76; 62, 77; 63, 78; 63, 79; 66, 80; 77, 81; 77, 82; 79, 83; 80, 84; 80, 85; 81, 86; 81, 87; 82, 88; 82, 89; 84, 90; 84, 91; 85, 92; 88, 93; 90, 94; 93, 95; 93, 96; 95, 97; 95, 98
def get_histogram(data): """Return the histogram relative to the given data Assume that the data are already sorted """ count = len(data) if count < 2: raise StatisticsError('Too few data points ({}) for get_histogram'.format(count)) min_ = data[0] max_ = data[-1] std = stdev(data) bins = get_histogram_bins(min_, max_, std, count) res = {x: 0 for x in bins} for value in data: for bin_ in bins: if value <= bin_: res[bin_] += 1 break return sorted(iteritems(res))
0, module; 1, function_definition; 2, function_name:make_geohash_tables; 3, parameters; 4, block; 5, identifier:table; 6, identifier:listofprecisions; 7, dictionary_splat_pattern; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# logic for accepting kwarg inputs; 12, for_statement; 13, comment:# getting header; 14, expression_statement; 15, comment:# getting columns; 16, expression_statement; 17, comment:# getting original table; 18, expression_statement; 19, if_statement; 20, expression_statement; 21, comment:# making total table to hold a list of dfs; 22, if_statement; 23, for_statement; 24, if_statement; 25, identifier:kwargs; 26, string; 27, assignment; 28, assignment; 29, pattern_list; 30, call; 31, block; 32, assignment; 33, assignment; 34, assignment; 35, not_operator; 36, block; 37, assignment; 38, boolean_operator; 39, block; 40, elif_clause; 41, identifier:row; 42, identifier:listofprecisions; 43, block; 44, comparison_operator:return_squares == True; 45, block; 46, else_clause; 47, string_content:sort_by - field to sort by for each group return_squares - boolean arg if true returns a list of squares instead of writing out to table; 48, identifier:return_squares; 49, False; 50, identifier:sort_by; 51, string; 52, identifier:key; 53, identifier:value; 54, attribute; 55, argument_list; 56, if_statement; 57, if_statement; 58, identifier:header; 59, subscript; 60, identifier:columns; 61, subscript; 62, identifier:originaltable; 63, identifier:table; 64, comparison_operator:sort_by == 'COUNT'; 65, expression_statement; 66, identifier:listofprecisions; 67, call; 68, comparison_operator:return_squares == True; 69, comparison_operator:listofprecisions[-1] == 8; 70, expression_statement; 71, comparison_operator:return_squares == True; 72, block; 73, expression_statement; 74, expression_statement; 75, expression_statement; 76, expression_statement; 77, expression_statement; 78, expression_statement; 79, expression_statement; 80, comment:# iterating through each square here; 81, for_statement; 82, comment:# taking newsquares to dataframe; 83, expression_statement; 84, if_statement; 85, identifier:return_squares; 86, True; 87, return_statement; 88, block; 89, string_content:COUNT; 90, identifier:kwargs; 91, identifier:iteritems; 92, comparison_operator:key == 'sort_by'; 93, block; 94, comparison_operator:key == 'return_squares'; 95, block; 96, call; 97, integer:0; 98, identifier:header; 99, slice; 100, identifier:sort_by; 101, string; 102, assignment; 103, identifier:sorted; 104, argument_list; 105, identifier:return_squares; 106, True; 107, subscript; 108, integer:8; 109, assignment; 110, identifier:return_squares; 111, True; 112, expression_statement; 113, assignment; 114, assignment; 115, assignment; 116, assignment; 117, assignment; 118, assignment; 119, assignment; 120, identifier:row; 121, subscript; 122, comment:# getting points; 123, block; 124, assignment; 125, comparison_operator:return_squares == True; 126, block; 127, else_clause; 128, identifier:total_list; 129, print_statement; 130, identifier:key; 131, string; 132, expression_statement; 133, identifier:key; 134, string; 135, expression_statement; 136, identifier:df2list; 137, argument_list; 138, integer:10; 139, string_content:COUNT; 140, identifier:originaltable; 141, call; 142, identifier:listofprecisions; 143, keyword_argument; 144, identifier:listofprecisions; 145, unary_operator; 146, identifier:total_list; 147, list; 148, assignment; 149, identifier:precision; 150, call; 151, identifier:table; 152, identifier:originaltable; 153, subscript; 154, subscript; 155, identifier:table; 156, call; 157, identifier:table; 158, call; 159, identifier:table; 160, call; 161, identifier:newsquares; 162, list; 163, call; 164, slice; 165, expression_statement; 166, comment:# making new row; 167, expression_statement; 168, comment:# appending to newsquares; 169, expression_statement; 170, identifier:table; 171, call; 172, identifier:return_squares; 173, True; 174, expression_statement; 175, block; 176, string; 177, string_content:sort_by; 178, assignment; 179, string_content:return_squares; 180, assignment; 181, identifier:table; 182, attribute; 183, argument_list; 184, identifier:reverse; 185, True; 186, integer:1; 187, identifier:table; 188, identifier:total_list; 189, list; 190, identifier:int; 191, argument_list; 192, identifier:table; 193, string; 194, attribute; 195, slice; 196, attribute; 197, argument_list; 198, attribute; 199, argument_list; 200, attribute; 201, argument_list; 202, identifier:header; 203, identifier:df2list; 204, argument_list; 205, integer:1; 206, assignment; 207, assignment; 208, call; 209, identifier:list2df; 210, argument_list; 211, call; 212, expression_statement; 213, string_content:Wrote output squares tables to csv files.; 214, identifier:sort_by; 215, identifier:value; 216, identifier:return_squares; 217, identifier:value; 218, identifier:originaltable; 219, identifier:sort; 220, list; 221, keyword_argument; 222, identifier:row; 223, string_content:GEOHASH; 224, attribute; 225, identifier:str; 226, identifier:precision; 227, call; 228, identifier:sum; 229, identifier:table; 230, identifier:sort; 231, list; 232, keyword_argument; 233, identifier:table; 234, identifier:reset_index; 235, identifier:table; 236, identifier:points; 237, call; 238, identifier:newrow; 239, binary_operator:[row[0]] + points + row[1:]; 240, attribute; 241, argument_list; 242, identifier:newsquares; 243, attribute; 244, argument_list; 245, call; 246, identifier:sort_by; 247, identifier:ascending; 248, list; 249, identifier:table; 250, identifier:GEOHASH; 251, attribute; 252, argument_list; 253, identifier:sort_by; 254, identifier:ascending; 255, list; 256, identifier:get_points_geohash; 257, argument_list; 258, binary_operator:[row[0]] + points; 259, subscript; 260, identifier:newsquares; 261, identifier:append; 262, identifier:newrow; 263, identifier:total_list; 264, identifier:append; 265, identifier:table; 266, attribute; 267, argument_list; 268, integer:0; 269, subscript; 270, identifier:groupby; 271, list; 272, keyword_argument; 273, integer:0; 274, subscript; 275, list; 276, identifier:points; 277, identifier:row; 278, slice; 279, identifier:table; 280, identifier:to_csv; 281, binary_operator:'squares' + str(precision) + '.csv'; 282, keyword_argument; 283, identifier:table; 284, binary_operator:['GEOHASH','COUNT']+columns; 285, string; 286, identifier:sort; 287, True; 288, identifier:row; 289, integer:0; 290, subscript; 291, integer:1; 292, binary_operator:'squares' + str(precision); 293, string; 294, identifier:index; 295, False; 296, list; 297, identifier:columns; 298, string_content:GEOHASH; 299, identifier:row; 300, integer:0; 301, string; 302, call; 303, string_content:.csv; 304, string; 305, string; 306, string_content:squares; 307, identifier:str; 308, argument_list; 309, string_content:GEOHASH; 310, string_content:COUNT; 311, identifier:precision
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 7, 25; 8, 26; 9, 27; 10, 28; 12, 29; 12, 30; 12, 31; 14, 32; 16, 33; 18, 34; 19, 35; 19, 36; 20, 37; 22, 38; 22, 39; 22, 40; 23, 41; 23, 42; 23, 43; 24, 44; 24, 45; 24, 46; 26, 47; 27, 48; 27, 49; 28, 50; 28, 51; 29, 52; 29, 53; 30, 54; 30, 55; 31, 56; 31, 57; 32, 58; 32, 59; 33, 60; 33, 61; 34, 62; 34, 63; 35, 64; 36, 65; 37, 66; 37, 67; 38, 68; 38, 69; 39, 70; 40, 71; 40, 72; 43, 73; 43, 74; 43, 75; 43, 76; 43, 77; 43, 78; 43, 79; 43, 80; 43, 81; 43, 82; 43, 83; 43, 84; 44, 85; 44, 86; 45, 87; 46, 88; 51, 89; 54, 90; 54, 91; 56, 92; 56, 93; 57, 94; 57, 95; 59, 96; 59, 97; 61, 98; 61, 99; 64, 100; 64, 101; 65, 102; 67, 103; 67, 104; 68, 105; 68, 106; 69, 107; 69, 108; 70, 109; 71, 110; 71, 111; 72, 112; 73, 113; 74, 114; 75, 115; 76, 116; 77, 117; 78, 118; 79, 119; 81, 120; 81, 121; 81, 122; 81, 123; 83, 124; 84, 125; 84, 126; 84, 127; 87, 128; 88, 129; 92, 130; 92, 131; 93, 132; 94, 133; 94, 134; 95, 135; 96, 136; 96, 137; 99, 138; 101, 139; 102, 140; 102, 141; 104, 142; 104, 143; 107, 144; 107, 145; 109, 146; 109, 147; 112, 148; 113, 149; 113, 150; 114, 151; 114, 152; 115, 153; 115, 154; 116, 155; 116, 156; 117, 157; 117, 158; 118, 159; 118, 160; 119, 161; 119, 162; 121, 163; 121, 164; 123, 165; 123, 166; 123, 167; 123, 168; 123, 169; 124, 170; 124, 171; 125, 172; 125, 173; 126, 174; 127, 175; 129, 176; 131, 177; 132, 178; 134, 179; 135, 180; 137, 181; 141, 182; 141, 183; 143, 184; 143, 185; 145, 186; 147, 187; 148, 188; 148, 189; 150, 190; 150, 191; 153, 192; 153, 193; 154, 194; 154, 195; 156, 196; 156, 197; 158, 198; 158, 199; 160, 200; 160, 201; 162, 202; 163, 203; 163, 204; 164, 205; 165, 206; 167, 207; 169, 208; 171, 209; 171, 210; 174, 211; 175, 212; 176, 213; 178, 214; 178, 215; 180, 216; 180, 217; 182, 218; 182, 219; 183, 220; 183, 221; 191, 222; 193, 223; 194, 224; 194, 225; 195, 226; 196, 227; 196, 228; 198, 229; 198, 230; 199, 231; 199, 232; 200, 233; 200, 234; 204, 235; 206, 236; 206, 237; 207, 238; 207, 239; 208, 240; 208, 241; 210, 242; 211, 243; 211, 244; 212, 245; 220, 246; 221, 247; 221, 248; 224, 249; 224, 250; 227, 251; 227, 252; 231, 253; 232, 254; 232, 255; 237, 256; 237, 257; 239, 258; 239, 259; 240, 260; 240, 261; 241, 262; 243, 263; 243, 264; 244, 265; 245, 266; 245, 267; 248, 268; 251, 269; 251, 270; 252, 271; 252, 272; 255, 273; 257, 274; 258, 275; 258, 276; 259, 277; 259, 278; 266, 279; 266, 280; 267, 281; 267, 282; 269, 283; 269, 284; 271, 285; 272, 286; 272, 287; 274, 288; 274, 289; 275, 290; 278, 291; 281, 292; 281, 293; 282, 294; 282, 295; 284, 296; 284, 297; 285, 298; 290, 299; 290, 300; 292, 301; 292, 302; 293, 303; 296, 304; 296, 305; 301, 306; 302, 307; 302, 308; 304, 309; 305, 310; 308, 311
def make_geohash_tables(table,listofprecisions,**kwargs): ''' sort_by - field to sort by for each group return_squares - boolean arg if true returns a list of squares instead of writing out to table ''' return_squares = False sort_by = 'COUNT' # logic for accepting kwarg inputs for key,value in kwargs.iteritems(): if key == 'sort_by': sort_by = value if key == 'return_squares': return_squares = value # getting header header = df2list(table)[0] # getting columns columns = header[10:] # getting original table originaltable = table if not sort_by == 'COUNT': originaltable = originaltable.sort([sort_by],ascending=[0]) listofprecisions = sorted(listofprecisions,reverse=True) # making total table to hold a list of dfs if return_squares == True and listofprecisions[-1] == 8: total_list = [table] elif return_squares == True: total_list = [] for row in listofprecisions: precision = int(row) table = originaltable table['GEOHASH'] = table.GEOHASH.str[:precision] table = table[['GEOHASH','COUNT']+columns].groupby(['GEOHASH'],sort=True).sum() table = table.sort([sort_by],ascending=[0]) table = table.reset_index() newsquares = [header] # iterating through each square here for row in df2list(table)[1:]: # getting points points = get_points_geohash(row[0]) # making new row newrow = [row[0]] + points + row[1:] # appending to newsquares newsquares.append(newrow) # taking newsquares to dataframe table = list2df(newsquares) if return_squares == True: total_list.append(table) else: table.to_csv('squares' + str(precision) + '.csv',index=False) if return_squares == True: return total_list else: print 'Wrote output squares tables to csv files.'
0, module; 1, function_definition; 2, function_name:coercer; 3, parameters; 4, block; 5, identifier:self; 6, identifier:dataSets; 7, expression_statement; 8, comment:# Xxx - This does a slightly complex (hey, it's like 20 lines, how; 9, comment:# complex could it really be?) thing to figure out which elements are; 10, comment:# newly created, which elements were edited, and which elements no; 11, comment:# longer exist. It might be simpler if the client kept track of this; 12, comment:# and passed a three-tuple of lists (or whatever - some separate data; 13, comment:# structures) to the server, so everything would be all figured out; 14, comment:# already. This would require the client; 15, comment:# (Mantissa.LiveForm.RepeatableForm) to be more aware of what events; 16, comment:# the user is triggering in the browser so that it could keep state for; 17, comment:# adds/deletes/edits separately from DOM and widget objects. This; 18, comment:# would remove the need for RepeatedLiveFormWrapper.; 19, function_definition; 20, expression_statement; 21, expression_statement; 22, expression_statement; 23, function_definition; 24, expression_statement; 25, return_statement; 26, comment:""" Coerce all of the repetitions and sort them into creations, edits and deletions. @rtype: L{ListChanges} @return: An object describing all of the creations, modifications, and deletions represented by C{dataSets}. """; 27, function_name:makeSetter; 28, parameters; 29, block; 30, assignment; 31, assignment; 32, assignment; 33, function_name:cbCoerced; 34, parameters; 35, block; 36, call; 37, identifier:coerceDeferred; 38, identifier:identifier; 39, identifier:values; 40, function_definition; 41, return_statement; 42, identifier:created; 43, call; 44, identifier:edited; 45, call; 46, identifier:coerceDeferred; 47, call; 48, tuple_pattern; 49, expression_statement; 50, expression_statement; 51, for_statement; 52, expression_statement; 53, for_statement; 54, expression_statement; 55, for_statement; 56, return_statement; 57, attribute; 58, argument_list; 59, function_name:setter; 60, parameters; 61, block; 62, identifier:setter; 63, attribute; 64, argument_list; 65, attribute; 66, argument_list; 67, identifier:gatherResults; 68, argument_list; 69, identifier:created; 70, identifier:edited; 71, assignment; 72, assignment; 73, tuple_pattern; 74, identifier:created; 75, block; 76, assignment; 77, tuple_pattern; 78, identifier:edited; 79, block; 80, assignment; 81, identifier:identifier; 82, binary_operator:set(self._idsToObjects) - receivedIdentifiers; 83, block; 84, call; 85, identifier:coerceDeferred; 86, identifier:addCallback; 87, identifier:cbCoerced; 88, identifier:defaultObject; 89, expression_statement; 90, expression_statement; 91, identifier:self; 92, identifier:_coerceAll; 93, call; 94, identifier:self; 95, identifier:_coerceAll; 96, call; 97, list; 98, identifier:receivedIdentifiers; 99, call; 100, identifier:createObjects; 101, list; 102, identifier:identifier; 103, identifier:dataSet; 104, expression_statement; 105, expression_statement; 106, identifier:editObjects; 107, list; 108, identifier:identifier; 109, identifier:dataSet; 110, expression_statement; 111, expression_statement; 112, if_statement; 113, identifier:deleted; 114, list; 115, call; 116, identifier:receivedIdentifiers; 117, expression_statement; 118, if_statement; 119, expression_statement; 120, identifier:ListChanges; 121, argument_list; 122, assignment; 123, assignment; 124, attribute; 125, argument_list; 126, attribute; 127, argument_list; 128, identifier:created; 129, identifier:edited; 130, identifier:set; 131, argument_list; 132, call; 133, call; 134, call; 135, assignment; 136, comparison_operator:dataSet != lastValues; 137, block; 138, identifier:set; 139, argument_list; 140, assignment; 141, comparison_operator:existing is not self._NO_OBJECT_MARKER; 142, block; 143, call; 144, identifier:createObjects; 145, identifier:editObjects; 146, identifier:deleted; 147, subscript; 148, identifier:defaultObject; 149, subscript; 150, identifier:values; 151, identifier:self; 152, identifier:_extractCreations; 153, identifier:dataSets; 154, identifier:self; 155, identifier:_extractEdits; 156, identifier:dataSets; 157, attribute; 158, argument_list; 159, attribute; 160, argument_list; 161, attribute; 162, argument_list; 163, identifier:lastValues; 164, subscript; 165, identifier:dataSet; 166, identifier:lastValues; 167, expression_statement; 168, expression_statement; 169, expression_statement; 170, attribute; 171, identifier:existing; 172, call; 173, identifier:existing; 174, attribute; 175, expression_statement; 176, attribute; 177, argument_list; 178, attribute; 179, identifier:identifier; 180, attribute; 181, identifier:identifier; 182, identifier:receivedIdentifiers; 183, identifier:add; 184, identifier:identifier; 185, identifier:createObjects; 186, identifier:append; 187, call; 188, identifier:receivedIdentifiers; 189, identifier:add; 190, identifier:identifier; 191, attribute; 192, identifier:identifier; 193, assignment; 194, call; 195, assignment; 196, identifier:self; 197, identifier:_idsToObjects; 198, attribute; 199, argument_list; 200, identifier:self; 201, identifier:_NO_OBJECT_MARKER; 202, call; 203, attribute; 204, identifier:pop; 205, identifier:identifier; 206, identifier:self; 207, identifier:_idsToObjects; 208, identifier:self; 209, identifier:_lastValues; 210, identifier:CreateObject; 211, argument_list; 212, identifier:self; 213, identifier:_lastValues; 214, identifier:modelObject; 215, call; 216, attribute; 217, argument_list; 218, subscript; 219, identifier:dataSet; 220, identifier:self; 221, identifier:_objectFromID; 222, identifier:identifier; 223, attribute; 224, argument_list; 225, identifier:self; 226, identifier:_idsToObjects; 227, identifier:dataSet; 228, call; 229, attribute; 230, argument_list; 231, identifier:editObjects; 232, identifier:append; 233, call; 234, attribute; 235, identifier:identifier; 236, identifier:deleted; 237, identifier:append; 238, identifier:existing; 239, identifier:makeSetter; 240, argument_list; 241, identifier:self; 242, identifier:_objectFromID; 243, identifier:identifier; 244, identifier:EditObject; 245, argument_list; 246, identifier:self; 247, identifier:_lastValues; 248, identifier:identifier; 249, identifier:dataSet; 250, identifier:modelObject; 251, identifier:dataSet
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 7, 26; 19, 27; 19, 28; 19, 29; 20, 30; 21, 31; 22, 32; 23, 33; 23, 34; 23, 35; 24, 36; 25, 37; 28, 38; 28, 39; 29, 40; 29, 41; 30, 42; 30, 43; 31, 44; 31, 45; 32, 46; 32, 47; 34, 48; 35, 49; 35, 50; 35, 51; 35, 52; 35, 53; 35, 54; 35, 55; 35, 56; 36, 57; 36, 58; 40, 59; 40, 60; 40, 61; 41, 62; 43, 63; 43, 64; 45, 65; 45, 66; 47, 67; 47, 68; 48, 69; 48, 70; 49, 71; 50, 72; 51, 73; 51, 74; 51, 75; 52, 76; 53, 77; 53, 78; 53, 79; 54, 80; 55, 81; 55, 82; 55, 83; 56, 84; 57, 85; 57, 86; 58, 87; 60, 88; 61, 89; 61, 90; 63, 91; 63, 92; 64, 93; 65, 94; 65, 95; 66, 96; 68, 97; 71, 98; 71, 99; 72, 100; 72, 101; 73, 102; 73, 103; 75, 104; 75, 105; 76, 106; 76, 107; 77, 108; 77, 109; 79, 110; 79, 111; 79, 112; 80, 113; 80, 114; 82, 115; 82, 116; 83, 117; 83, 118; 83, 119; 84, 120; 84, 121; 89, 122; 90, 123; 93, 124; 93, 125; 96, 126; 96, 127; 97, 128; 97, 129; 99, 130; 99, 131; 104, 132; 105, 133; 110, 134; 111, 135; 112, 136; 112, 137; 115, 138; 115, 139; 117, 140; 118, 141; 118, 142; 119, 143; 121, 144; 121, 145; 121, 146; 122, 147; 122, 148; 123, 149; 123, 150; 124, 151; 124, 152; 125, 153; 126, 154; 126, 155; 127, 156; 132, 157; 132, 158; 133, 159; 133, 160; 134, 161; 134, 162; 135, 163; 135, 164; 136, 165; 136, 166; 137, 167; 137, 168; 137, 169; 139, 170; 140, 171; 140, 172; 141, 173; 141, 174; 142, 175; 143, 176; 143, 177; 147, 178; 147, 179; 149, 180; 149, 181; 157, 182; 157, 183; 158, 184; 159, 185; 159, 186; 160, 187; 161, 188; 161, 189; 162, 190; 164, 191; 164, 192; 167, 193; 168, 194; 169, 195; 170, 196; 170, 197; 172, 198; 172, 199; 174, 200; 174, 201; 175, 202; 176, 203; 176, 204; 177, 205; 178, 206; 178, 207; 180, 208; 180, 209; 187, 210; 187, 211; 191, 212; 191, 213; 193, 214; 193, 215; 194, 216; 194, 217; 195, 218; 195, 219; 198, 220; 198, 221; 199, 222; 202, 223; 202, 224; 203, 225; 203, 226; 211, 227; 211, 228; 215, 229; 215, 230; 216, 231; 216, 232; 217, 233; 218, 234; 218, 235; 223, 236; 223, 237; 224, 238; 228, 239; 228, 240; 229, 241; 229, 242; 230, 243; 233, 244; 233, 245; 234, 246; 234, 247; 240, 248; 240, 249; 245, 250; 245, 251
def coercer(self, dataSets): """ Coerce all of the repetitions and sort them into creations, edits and deletions. @rtype: L{ListChanges} @return: An object describing all of the creations, modifications, and deletions represented by C{dataSets}. """ # Xxx - This does a slightly complex (hey, it's like 20 lines, how # complex could it really be?) thing to figure out which elements are # newly created, which elements were edited, and which elements no # longer exist. It might be simpler if the client kept track of this # and passed a three-tuple of lists (or whatever - some separate data # structures) to the server, so everything would be all figured out # already. This would require the client # (Mantissa.LiveForm.RepeatableForm) to be more aware of what events # the user is triggering in the browser so that it could keep state for # adds/deletes/edits separately from DOM and widget objects. This # would remove the need for RepeatedLiveFormWrapper. def makeSetter(identifier, values): def setter(defaultObject): self._idsToObjects[identifier] = defaultObject self._lastValues[identifier] = values return setter created = self._coerceAll(self._extractCreations(dataSets)) edited = self._coerceAll(self._extractEdits(dataSets)) coerceDeferred = gatherResults([created, edited]) def cbCoerced((created, edited)): receivedIdentifiers = set() createObjects = [] for (identifier, dataSet) in created: receivedIdentifiers.add(identifier) createObjects.append( CreateObject(dataSet, makeSetter(identifier, dataSet))) editObjects = [] for (identifier, dataSet) in edited: receivedIdentifiers.add(identifier) lastValues = self._lastValues[identifier] if dataSet != lastValues: modelObject = self._objectFromID(identifier) editObjects.append(EditObject(modelObject, dataSet)) self._lastValues[identifier] = dataSet deleted = [] for identifier in set(self._idsToObjects) - receivedIdentifiers: existing = self._objectFromID(identifier) if existing is not self._NO_OBJECT_MARKER: deleted.append(existing) self._idsToObjects.pop(identifier) return ListChanges(createObjects, editObjects, deleted) coerceDeferred.addCallback(cbCoerced) return coerceDeferred
0, module; 1, function_definition; 2, function_name:zcard; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, expression_statement; 8, with_statement; 9, comment:""" Returns the cardinality of the SortedSet. :param name: str the name of the redis key :return: Future() """; 10, with_clause; 11, block; 12, with_item; 13, return_statement; 14, as_pattern; 15, call; 16, attribute; 17, as_pattern_target; 18, attribute; 19, argument_list; 20, identifier:self; 21, identifier:pipe; 22, identifier:pipe; 23, identifier:pipe; 24, identifier:zcard; 25, call; 26, attribute; 27, argument_list; 28, identifier:self; 29, identifier:redis_key; 30, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 7, 9; 8, 10; 8, 11; 10, 12; 11, 13; 12, 14; 13, 15; 14, 16; 14, 17; 15, 18; 15, 19; 16, 20; 16, 21; 17, 22; 18, 23; 18, 24; 19, 25; 25, 26; 25, 27; 26, 28; 26, 29; 27, 30
def zcard(self, name): """ Returns the cardinality of the SortedSet. :param name: str the name of the redis key :return: Future() """ with self.pipe as pipe: return pipe.zcard(self.redis_key(name))
0, module; 1, function_definition; 2, function_name:zscore; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, identifier:value; 8, expression_statement; 9, with_statement; 10, comment:""" Return the score of an element :param name: str the name of the redis key :param value: the element in the sorted set key :return: Future() """; 11, with_clause; 12, block; 13, with_item; 14, return_statement; 15, as_pattern; 16, call; 17, attribute; 18, as_pattern_target; 19, attribute; 20, argument_list; 21, identifier:self; 22, identifier:pipe; 23, identifier:pipe; 24, identifier:pipe; 25, identifier:zscore; 26, call; 27, call; 28, attribute; 29, argument_list; 30, attribute; 31, argument_list; 32, identifier:self; 33, identifier:redis_key; 34, identifier:name; 35, attribute; 36, identifier:encode; 37, identifier:value; 38, identifier:self; 39, identifier:valueparse
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 9, 12; 11, 13; 12, 14; 13, 15; 14, 16; 15, 17; 15, 18; 16, 19; 16, 20; 17, 21; 17, 22; 18, 23; 19, 24; 19, 25; 20, 26; 20, 27; 26, 28; 26, 29; 27, 30; 27, 31; 28, 32; 28, 33; 29, 34; 30, 35; 30, 36; 31, 37; 35, 38; 35, 39
def zscore(self, name, value): """ Return the score of an element :param name: str the name of the redis key :param value: the element in the sorted set key :return: Future() """ with self.pipe as pipe: return pipe.zscore(self.redis_key(name), self.valueparse.encode(value))
0, module; 1, function_definition; 2, function_name:zrank; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, identifier:value; 8, expression_statement; 9, with_statement; 10, comment:""" Returns the rank of the element. :param name: str the name of the redis key :param value: the element in the sorted set """; 11, with_clause; 12, block; 13, with_item; 14, expression_statement; 15, return_statement; 16, as_pattern; 17, assignment; 18, call; 19, attribute; 20, as_pattern_target; 21, identifier:value; 22, call; 23, attribute; 24, argument_list; 25, identifier:self; 26, identifier:pipe; 27, identifier:pipe; 28, attribute; 29, argument_list; 30, identifier:pipe; 31, identifier:zrank; 32, call; 33, identifier:value; 34, attribute; 35, identifier:encode; 36, identifier:value; 37, attribute; 38, argument_list; 39, identifier:self; 40, identifier:valueparse; 41, identifier:self; 42, identifier:redis_key; 43, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 8, 10; 9, 11; 9, 12; 11, 13; 12, 14; 12, 15; 13, 16; 14, 17; 15, 18; 16, 19; 16, 20; 17, 21; 17, 22; 18, 23; 18, 24; 19, 25; 19, 26; 20, 27; 22, 28; 22, 29; 23, 30; 23, 31; 24, 32; 24, 33; 28, 34; 28, 35; 29, 36; 32, 37; 32, 38; 34, 39; 34, 40; 37, 41; 37, 42; 38, 43
def zrank(self, name, value): """ Returns the rank of the element. :param name: str the name of the redis key :param value: the element in the sorted set """ with self.pipe as pipe: value = self.valueparse.encode(value) return pipe.zrank(self.redis_key(name), value)
0, module; 1, function_definition; 2, function_name:zlexcount; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, identifier:min; 8, identifier:max; 9, expression_statement; 10, with_statement; 11, comment:""" Return the number of items in the sorted set between the lexicographical range ``min`` and ``max``. :param name: str the name of the redis key :param min: int or '-inf' :param max: int or '+inf' :return: Future() """; 12, with_clause; 13, block; 14, with_item; 15, return_statement; 16, as_pattern; 17, call; 18, attribute; 19, as_pattern_target; 20, attribute; 21, argument_list; 22, identifier:self; 23, identifier:pipe; 24, identifier:pipe; 25, identifier:pipe; 26, identifier:zlexcount; 27, call; 28, identifier:min; 29, identifier:max; 30, attribute; 31, argument_list; 32, identifier:self; 33, identifier:redis_key; 34, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 9, 11; 10, 12; 10, 13; 12, 14; 13, 15; 14, 16; 15, 17; 16, 18; 16, 19; 17, 20; 17, 21; 18, 22; 18, 23; 19, 24; 20, 25; 20, 26; 21, 27; 21, 28; 21, 29; 27, 30; 27, 31; 30, 32; 30, 33; 31, 34
def zlexcount(self, name, min, max): """ Return the number of items in the sorted set between the lexicographical range ``min`` and ``max``. :param name: str the name of the redis key :param min: int or '-inf' :param max: int or '+inf' :return: Future() """ with self.pipe as pipe: return pipe.zlexcount(self.redis_key(name), min, max)
0, module; 1, function_definition; 2, function_name:zrevrangebylex; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, identifier:max; 8, identifier:min; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, with_statement; 13, identifier:start; 14, None; 15, identifier:num; 16, None; 17, comment:""" Return the reversed lexicographical range of values from the sorted set between ``max`` and ``min``. If ``start`` and ``num`` are specified, then return a slice of the range. :param name: str the name of the redis key :param max: int or '+inf' :param min: int or '-inf' :param start: int :param num: int :return: Future() """; 18, with_clause; 19, block; 20, with_item; 21, expression_statement; 22, expression_statement; 23, function_definition; 24, expression_statement; 25, return_statement; 26, as_pattern; 27, assignment; 28, assignment; 29, function_name:cb; 30, parameters; 31, block; 32, call; 33, identifier:f; 34, attribute; 35, as_pattern_target; 36, identifier:f; 37, call; 38, identifier:res; 39, call; 40, expression_statement; 41, attribute; 42, argument_list; 43, identifier:self; 44, identifier:pipe; 45, identifier:pipe; 46, identifier:Future; 47, argument_list; 48, attribute; 49, argument_list; 50, call; 51, identifier:pipe; 52, identifier:on_execute; 53, identifier:cb; 54, identifier:pipe; 55, identifier:zrevrangebylex; 56, call; 57, identifier:max; 58, identifier:min; 59, keyword_argument; 60, keyword_argument; 61, attribute; 62, argument_list; 63, attribute; 64, argument_list; 65, identifier:start; 66, identifier:start; 67, identifier:num; 68, identifier:num; 69, identifier:f; 70, identifier:set; 71, list_comprehension; 72, identifier:self; 73, identifier:redis_key; 74, identifier:name; 75, call; 76, for_in_clause; 77, attribute; 78, argument_list; 79, identifier:v; 80, identifier:res; 81, attribute; 82, identifier:decode; 83, identifier:v; 84, identifier:self; 85, identifier:valueparse
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, 11; 4, 12; 9, 13; 9, 14; 10, 15; 10, 16; 11, 17; 12, 18; 12, 19; 18, 20; 19, 21; 19, 22; 19, 23; 19, 24; 19, 25; 20, 26; 21, 27; 22, 28; 23, 29; 23, 30; 23, 31; 24, 32; 25, 33; 26, 34; 26, 35; 27, 36; 27, 37; 28, 38; 28, 39; 31, 40; 32, 41; 32, 42; 34, 43; 34, 44; 35, 45; 37, 46; 37, 47; 39, 48; 39, 49; 40, 50; 41, 51; 41, 52; 42, 53; 48, 54; 48, 55; 49, 56; 49, 57; 49, 58; 49, 59; 49, 60; 50, 61; 50, 62; 56, 63; 56, 64; 59, 65; 59, 66; 60, 67; 60, 68; 61, 69; 61, 70; 62, 71; 63, 72; 63, 73; 64, 74; 71, 75; 71, 76; 75, 77; 75, 78; 76, 79; 76, 80; 77, 81; 77, 82; 78, 83; 81, 84; 81, 85
def zrevrangebylex(self, name, max, min, start=None, num=None): """ Return the reversed lexicographical range of values from the sorted set between ``max`` and ``min``. If ``start`` and ``num`` are specified, then return a slice of the range. :param name: str the name of the redis key :param max: int or '+inf' :param min: int or '-inf' :param start: int :param num: int :return: Future() """ with self.pipe as pipe: f = Future() res = pipe.zrevrangebylex(self.redis_key(name), max, min, start=start, num=num) def cb(): f.set([self.valueparse.decode(v) for v in res]) pipe.on_execute(cb) return f
0, module; 1, function_definition; 2, function_name:zremrangebylex; 3, parameters; 4, block; 5, identifier:self; 6, identifier:name; 7, identifier:min; 8, identifier:max; 9, expression_statement; 10, with_statement; 11, comment:""" Remove all elements in the sorted set between the lexicographical range specified by ``min`` and ``max``. Returns the number of elements removed. :param name: str the name of the redis key :param min: int or -inf :param max: into or +inf :return: Future() """; 12, with_clause; 13, block; 14, with_item; 15, return_statement; 16, as_pattern; 17, call; 18, attribute; 19, as_pattern_target; 20, attribute; 21, argument_list; 22, identifier:self; 23, identifier:pipe; 24, identifier:pipe; 25, identifier:pipe; 26, identifier:zremrangebylex; 27, call; 28, identifier:min; 29, identifier:max; 30, attribute; 31, argument_list; 32, identifier:self; 33, identifier:redis_key; 34, identifier:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, 9; 4, 10; 9, 11; 10, 12; 10, 13; 12, 14; 13, 15; 14, 16; 15, 17; 16, 18; 16, 19; 17, 20; 17, 21; 18, 22; 18, 23; 19, 24; 20, 25; 20, 26; 21, 27; 21, 28; 21, 29; 27, 30; 27, 31; 30, 32; 30, 33; 31, 34
def zremrangebylex(self, name, min, max): """ Remove all elements in the sorted set between the lexicographical range specified by ``min`` and ``max``. Returns the number of elements removed. :param name: str the name of the redis key :param min: int or -inf :param max: into or +inf :return: Future() """ with self.pipe as pipe: return pipe.zremrangebylex(self.redis_key(name), min, max)
0, module; 1, function_definition; 2, function_name:resort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:attributeID; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, if_statement; 13, expression_statement; 14, expression_statement; 15, identifier:isAscending; 16, None; 17, comment:"""Sort by one of my specified columns, identified by attributeID """; 18, comparison_operator:isAscending is None; 19, block; 20, assignment; 21, comparison_operator:newSortColumn.sortAttribute() is None; 22, block; 23, comparison_operator:self.currentSortColumn == newSortColumn; 24, comment:# if this query is to be re-sorted on the same column, but in the; 25, comment:# opposite direction to our last query, then use the first item in; 26, comment:# the result set as the marker; 27, block; 28, else_clause; 29, assignment; 30, call; 31, identifier:isAscending; 32, None; 33, expression_statement; 34, identifier:newSortColumn; 35, subscript; 36, call; 37, None; 38, raise_statement; 39, attribute; 40, identifier:newSortColumn; 41, if_statement; 42, block; 43, attribute; 44, identifier:isAscending; 45, attribute; 46, argument_list; 47, assignment; 48, attribute; 49, identifier:attributeID; 50, attribute; 51, argument_list; 52, call; 53, identifier:self; 54, identifier:currentSortColumn; 55, comparison_operator:self.isAscending == isAscending; 56, block; 57, else_clause; 58, expression_statement; 59, expression_statement; 60, identifier:self; 61, identifier:isAscending; 62, identifier:self; 63, identifier:_updateResults; 64, call; 65, True; 66, identifier:isAscending; 67, attribute; 68, identifier:self; 69, identifier:columns; 70, identifier:newSortColumn; 71, identifier:sortAttribute; 72, identifier:Unsortable; 73, argument_list; 74, attribute; 75, identifier:isAscending; 76, expression_statement; 77, comment:# otherwise use the last; 78, block; 79, assignment; 80, assignment; 81, attribute; 82, argument_list; 83, identifier:self; 84, identifier:defaultSortAscending; 85, binary_operator:'column %r has no sort attribute' % (attributeID,); 86, identifier:self; 87, identifier:isAscending; 88, assignment; 89, expression_statement; 90, identifier:offset; 91, integer:0; 92, attribute; 93, identifier:newSortColumn; 94, identifier:self; 95, identifier:_sortAttributeValue; 96, identifier:offset; 97, string; 98, tuple; 99, identifier:offset; 100, integer:0; 101, assignment; 102, identifier:self; 103, identifier:currentSortColumn; 104, string_content:column %r has no sort attribute; 105, identifier:attributeID; 106, identifier:offset; 107, unary_operator; 108, integer:1
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 7, 15; 7, 16; 8, 17; 9, 18; 9, 19; 10, 20; 11, 21; 11, 22; 12, 23; 12, 24; 12, 25; 12, 26; 12, 27; 12, 28; 13, 29; 14, 30; 18, 31; 18, 32; 19, 33; 20, 34; 20, 35; 21, 36; 21, 37; 22, 38; 23, 39; 23, 40; 27, 41; 28, 42; 29, 43; 29, 44; 30, 45; 30, 46; 33, 47; 35, 48; 35, 49; 36, 50; 36, 51; 38, 52; 39, 53; 39, 54; 41, 55; 41, 56; 41, 57; 42, 58; 42, 59; 43, 60; 43, 61; 45, 62; 45, 63; 46, 64; 46, 65; 47, 66; 47, 67; 48, 68; 48, 69; 50, 70; 50, 71; 52, 72; 52, 73; 55, 74; 55, 75; 56, 76; 57, 77; 57, 78; 58, 79; 59, 80; 64, 81; 64, 82; 67, 83; 67, 84; 73, 85; 74, 86; 74, 87; 76, 88; 78, 89; 79, 90; 79, 91; 80, 92; 80, 93; 81, 94; 81, 95; 82, 96; 85, 97; 85, 98; 88, 99; 88, 100; 89, 101; 92, 102; 92, 103; 97, 104; 98, 105; 101, 106; 101, 107; 107, 108
def resort(self, attributeID, isAscending=None): """Sort by one of my specified columns, identified by attributeID """ if isAscending is None: isAscending = self.defaultSortAscending newSortColumn = self.columns[attributeID] if newSortColumn.sortAttribute() is None: raise Unsortable('column %r has no sort attribute' % (attributeID,)) if self.currentSortColumn == newSortColumn: # if this query is to be re-sorted on the same column, but in the # opposite direction to our last query, then use the first item in # the result set as the marker if self.isAscending == isAscending: offset = 0 else: # otherwise use the last offset = -1 else: offset = 0 self.currentSortColumn = newSortColumn self.isAscending = isAscending self._updateResults(self._sortAttributeValue(offset), True)
0, module; 1, function_definition; 2, function_name:_sortAttributeValue; 3, parameters; 4, block; 5, identifier:self; 6, identifier:offset; 7, expression_statement; 8, if_statement; 9, return_statement; 10, comment:""" return the value of the sort attribute for the item at 'offset' in the results of the last query, otherwise None. """; 11, attribute; 12, block; 13, else_clause; 14, identifier:pageStart; 15, identifier:self; 16, identifier:_currentResults; 17, expression_statement; 18, block; 19, assignment; 20, expression_statement; 21, identifier:pageStart; 22, tuple; 23, assignment; 24, subscript; 25, attribute; 26, identifier:pageStart; 27, None; 28, subscript; 29, attribute; 30, subscript; 31, identifier:storeID; 32, attribute; 33, identifier:offset; 34, attribute; 35, identifier:attributeID; 36, subscript; 37, string; 38, identifier:self; 39, identifier:_currentResults; 40, identifier:self; 41, identifier:currentSortColumn; 42, attribute; 43, identifier:offset; 44, string_content:__item__; 45, identifier:self; 46, identifier:_currentResults
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 7, 10; 8, 11; 8, 12; 8, 13; 9, 14; 11, 15; 11, 16; 12, 17; 13, 18; 17, 19; 18, 20; 19, 21; 19, 22; 20, 23; 22, 24; 22, 25; 23, 26; 23, 27; 24, 28; 24, 29; 25, 30; 25, 31; 28, 32; 28, 33; 29, 34; 29, 35; 30, 36; 30, 37; 32, 38; 32, 39; 34, 40; 34, 41; 36, 42; 36, 43; 37, 44; 42, 45; 42, 46
def _sortAttributeValue(self, offset): """ return the value of the sort attribute for the item at 'offset' in the results of the last query, otherwise None. """ if self._currentResults: pageStart = (self._currentResults[offset][ self.currentSortColumn.attributeID], self._currentResults[offset][ '__item__'].storeID) else: pageStart = None return pageStart
0, module; 1, function_definition; 2, function_name:resort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:columnName; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, comment:""" Re-sort the table. @param columnName: the name of the column to sort by. This is a string because it is passed from the browser. """; 14, assignment; 15, assignment; 16, comparison_operator:newSortColumn is None; 17, block; 18, comparison_operator:csc is newSortColumn; 19, block; 20, else_clause; 21, attribute; 22, identifier:csc; 23, attribute; 24, identifier:newSortColumn; 25, subscript; 26, identifier:newSortColumn; 27, None; 28, raise_statement; 29, identifier:csc; 30, identifier:newSortColumn; 31, expression_statement; 32, block; 33, identifier:self; 34, identifier:isAscending; 35, identifier:self; 36, identifier:currentSortColumn; 37, attribute; 38, identifier:columnName; 39, call; 40, assignment; 41, expression_statement; 42, expression_statement; 43, identifier:self; 44, identifier:columns; 45, identifier:Unsortable; 46, argument_list; 47, attribute; 48, not_operator; 49, assignment; 50, assignment; 51, binary_operator:'column %r has no sort attribute' % (columnName,); 52, identifier:self; 53, identifier:isAscending; 54, attribute; 55, attribute; 56, identifier:newSortColumn; 57, attribute; 58, True; 59, string; 60, tuple; 61, identifier:self; 62, identifier:isAscending; 63, identifier:self; 64, identifier:currentSortColumn; 65, identifier:self; 66, identifier:isAscending; 67, string_content:column %r has no sort attribute; 68, identifier:columnName
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 7, 13; 8, 14; 9, 15; 10, 16; 10, 17; 11, 18; 11, 19; 11, 20; 12, 21; 14, 22; 14, 23; 15, 24; 15, 25; 16, 26; 16, 27; 17, 28; 18, 29; 18, 30; 19, 31; 20, 32; 21, 33; 21, 34; 23, 35; 23, 36; 25, 37; 25, 38; 28, 39; 31, 40; 32, 41; 32, 42; 37, 43; 37, 44; 39, 45; 39, 46; 40, 47; 40, 48; 41, 49; 42, 50; 46, 51; 47, 52; 47, 53; 48, 54; 49, 55; 49, 56; 50, 57; 50, 58; 51, 59; 51, 60; 54, 61; 54, 62; 55, 63; 55, 64; 57, 65; 57, 66; 59, 67; 60, 68
def resort(self, columnName): """ Re-sort the table. @param columnName: the name of the column to sort by. This is a string because it is passed from the browser. """ csc = self.currentSortColumn newSortColumn = self.columns[columnName] if newSortColumn is None: raise Unsortable('column %r has no sort attribute' % (columnName,)) if csc is newSortColumn: self.isAscending = not self.isAscending else: self.currentSortColumn = newSortColumn self.isAscending = True return self.isAscending
0, module; 1, function_definition; 2, function_name:rowsAfterValue; 3, parameters; 4, block; 5, identifier:self; 6, identifier:value; 7, identifier:count; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:""" Retrieve some rows at or after a given sort-column value. @param value: Starting value in the index for the current sort column at which to start returning results. Rows with a column value for the current sort column which is greater than or equal to this value will be returned. @type value: Some type compatible with the current sort column, or None, to specify the beginning of the data. @param count: The maximum number of rows to return. @type count: C{int} @return: A list of row data, ordered by the current sort column, beginning at C{value} and containing at most C{count} elements. """; 12, comparison_operator:value is None; 13, block; 14, else_clause; 15, call; 16, identifier:value; 17, None; 18, expression_statement; 19, block; 20, attribute; 21, argument_list; 22, assignment; 23, expression_statement; 24, expression_statement; 25, expression_statement; 26, identifier:self; 27, identifier:constructRows; 28, identifier:query; 29, identifier:query; 30, call; 31, assignment; 32, assignment; 33, assignment; 34, attribute; 35, argument_list; 36, identifier:pyvalue; 37, call; 38, identifier:currentSortAttribute; 39, call; 40, identifier:query; 41, call; 42, identifier:self; 43, identifier:inequalityQuery; 44, None; 45, identifier:count; 46, True; 47, attribute; 48, argument_list; 49, attribute; 50, argument_list; 51, attribute; 52, argument_list; 53, identifier:self; 54, identifier:_toComparableValue; 55, identifier:value; 56, attribute; 57, identifier:sortAttribute; 58, identifier:self; 59, identifier:inequalityQuery; 60, comparison_operator:currentSortAttribute >= pyvalue; 61, identifier:count; 62, True; 63, identifier:self; 64, identifier:currentSortColumn; 65, identifier:currentSortAttribute; 66, identifier:pyvalue
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 8, 11; 9, 12; 9, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 14, 19; 15, 20; 15, 21; 18, 22; 19, 23; 19, 24; 19, 25; 20, 26; 20, 27; 21, 28; 22, 29; 22, 30; 23, 31; 24, 32; 25, 33; 30, 34; 30, 35; 31, 36; 31, 37; 32, 38; 32, 39; 33, 40; 33, 41; 34, 42; 34, 43; 35, 44; 35, 45; 35, 46; 37, 47; 37, 48; 39, 49; 39, 50; 41, 51; 41, 52; 47, 53; 47, 54; 48, 55; 49, 56; 49, 57; 51, 58; 51, 59; 52, 60; 52, 61; 52, 62; 56, 63; 56, 64; 60, 65; 60, 66
def rowsAfterValue(self, value, count): """ Retrieve some rows at or after a given sort-column value. @param value: Starting value in the index for the current sort column at which to start returning results. Rows with a column value for the current sort column which is greater than or equal to this value will be returned. @type value: Some type compatible with the current sort column, or None, to specify the beginning of the data. @param count: The maximum number of rows to return. @type count: C{int} @return: A list of row data, ordered by the current sort column, beginning at C{value} and containing at most C{count} elements. """ if value is None: query = self.inequalityQuery(None, count, True) else: pyvalue = self._toComparableValue(value) currentSortAttribute = self.currentSortColumn.sortAttribute() query = self.inequalityQuery(currentSortAttribute >= pyvalue, count, True) return self.constructRows(query)
0, module; 1, function_definition; 2, function_name:rowsBeforeValue; 3, parameters; 4, block; 5, identifier:self; 6, identifier:value; 7, identifier:count; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:""" Retrieve display data for rows with sort-column values less than the given value. @type value: Some type compatible with the current sort column. @param value: Starting value in the index for the current sort column at which to start returning results. Rows with a column value for the current sort column which is less than this value will be returned. @type count: C{int} @param count: The number of rows to return. @return: A list of row data, ordered by the current sort column, ending at C{value} and containing at most C{count} elements. """; 12, comparison_operator:value is None; 13, block; 14, else_clause; 15, subscript; 16, identifier:value; 17, None; 18, expression_statement; 19, block; 20, call; 21, slice; 22, assignment; 23, expression_statement; 24, expression_statement; 25, expression_statement; 26, attribute; 27, argument_list; 28, unary_operator; 29, identifier:query; 30, call; 31, assignment; 32, assignment; 33, assignment; 34, identifier:self; 35, identifier:constructRows; 36, identifier:query; 37, integer:1; 38, attribute; 39, argument_list; 40, identifier:pyvalue; 41, call; 42, identifier:currentSortAttribute; 43, call; 44, identifier:query; 45, call; 46, identifier:self; 47, identifier:inequalityQuery; 48, None; 49, identifier:count; 50, False; 51, attribute; 52, argument_list; 53, attribute; 54, argument_list; 55, attribute; 56, argument_list; 57, identifier:self; 58, identifier:_toComparableValue; 59, identifier:value; 60, attribute; 61, identifier:sortAttribute; 62, identifier:self; 63, identifier:inequalityQuery; 64, comparison_operator:currentSortAttribute < pyvalue; 65, identifier:count; 66, False; 67, identifier:self; 68, identifier:currentSortColumn; 69, identifier:currentSortAttribute; 70, identifier:pyvalue
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 8, 11; 9, 12; 9, 13; 9, 14; 10, 15; 12, 16; 12, 17; 13, 18; 14, 19; 15, 20; 15, 21; 18, 22; 19, 23; 19, 24; 19, 25; 20, 26; 20, 27; 21, 28; 22, 29; 22, 30; 23, 31; 24, 32; 25, 33; 26, 34; 26, 35; 27, 36; 28, 37; 30, 38; 30, 39; 31, 40; 31, 41; 32, 42; 32, 43; 33, 44; 33, 45; 38, 46; 38, 47; 39, 48; 39, 49; 39, 50; 41, 51; 41, 52; 43, 53; 43, 54; 45, 55; 45, 56; 51, 57; 51, 58; 52, 59; 53, 60; 53, 61; 55, 62; 55, 63; 56, 64; 56, 65; 56, 66; 60, 67; 60, 68; 64, 69; 64, 70
def rowsBeforeValue(self, value, count): """ Retrieve display data for rows with sort-column values less than the given value. @type value: Some type compatible with the current sort column. @param value: Starting value in the index for the current sort column at which to start returning results. Rows with a column value for the current sort column which is less than this value will be returned. @type count: C{int} @param count: The number of rows to return. @return: A list of row data, ordered by the current sort column, ending at C{value} and containing at most C{count} elements. """ if value is None: query = self.inequalityQuery(None, count, False) else: pyvalue = self._toComparableValue(value) currentSortAttribute = self.currentSortColumn.sortAttribute() query = self.inequalityQuery( currentSortAttribute < pyvalue, count, False) return self.constructRows(query)[::-1]
0, module; 1, function_definition; 2, function_name:rowsBeforeItem; 3, parameters; 4, block; 5, identifier:self; 6, identifier:item; 7, identifier:count; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, return_statement; 16, comment:""" The inverse of rowsAfterItem. @param item: then L{Item} to request rows before. @type item: this L{InequalityModel}'s L{itemType} attribute. @param count: The maximum number of rows to return. @type count: L{int} @return: A list of row data, ordered by the current sort column, beginning immediately after C{item}. """; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, augmented_assignment; 22, identifier:count; 23, block; 24, subscript; 25, identifier:currentSortAttribute; 26, call; 27, identifier:value; 28, call; 29, identifier:firstQuery; 30, call; 31, identifier:results; 32, call; 33, identifier:count; 34, call; 35, expression_statement; 36, expression_statement; 37, identifier:results; 38, slice; 39, attribute; 40, argument_list; 41, attribute; 42, argument_list; 43, attribute; 44, argument_list; 45, attribute; 46, argument_list; 47, identifier:len; 48, argument_list; 49, assignment; 50, call; 51, unary_operator; 52, attribute; 53, identifier:sortAttribute; 54, identifier:currentSortAttribute; 55, identifier:__get__; 56, identifier:item; 57, call; 58, identifier:self; 59, identifier:inequalityQuery; 60, call; 61, identifier:count; 62, False; 63, identifier:self; 64, identifier:constructRows; 65, identifier:firstQuery; 66, identifier:results; 67, identifier:secondQuery; 68, call; 69, attribute; 70, argument_list; 71, integer:1; 72, identifier:self; 73, identifier:currentSortColumn; 74, identifier:type; 75, argument_list; 76, identifier:AND; 77, argument_list; 78, attribute; 79, argument_list; 80, identifier:results; 81, identifier:extend; 82, call; 83, identifier:item; 84, comparison_operator:currentSortAttribute == value; 85, comparison_operator:self.itemType.storeID < item.storeID; 86, identifier:self; 87, identifier:inequalityQuery; 88, comparison_operator:currentSortAttribute < value; 89, identifier:count; 90, False; 91, attribute; 92, argument_list; 93, identifier:currentSortAttribute; 94, identifier:value; 95, attribute; 96, attribute; 97, identifier:currentSortAttribute; 98, identifier:value; 99, identifier:self; 100, identifier:constructRows; 101, identifier:secondQuery; 102, attribute; 103, identifier:storeID; 104, identifier:item; 105, identifier:storeID; 106, identifier:self; 107, identifier:itemType
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 4, 8; 4, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 8, 16; 9, 17; 10, 18; 11, 19; 12, 20; 13, 21; 14, 22; 14, 23; 15, 24; 17, 25; 17, 26; 18, 27; 18, 28; 19, 29; 19, 30; 20, 31; 20, 32; 21, 33; 21, 34; 23, 35; 23, 36; 24, 37; 24, 38; 26, 39; 26, 40; 28, 41; 28, 42; 30, 43; 30, 44; 32, 45; 32, 46; 34, 47; 34, 48; 35, 49; 36, 50; 38, 51; 39, 52; 39, 53; 41, 54; 41, 55; 42, 56; 42, 57; 43, 58; 43, 59; 44, 60; 44, 61; 44, 62; 45, 63; 45, 64; 46, 65; 48, 66; 49, 67; 49, 68; 50, 69; 50, 70; 51, 71; 52, 72; 52, 73; 57, 74; 57, 75; 60, 76; 60, 77; 68, 78; 68, 79; 69, 80; 69, 81; 70, 82; 75, 83; 77, 84; 77, 85; 78, 86; 78, 87; 79, 88; 79, 89; 79, 90; 82, 91; 82, 92; 84, 93; 84, 94; 85, 95; 85, 96; 88, 97; 88, 98; 91, 99; 91, 100; 92, 101; 95, 102; 95, 103; 96, 104; 96, 105; 102, 106; 102, 107
def rowsBeforeItem(self, item, count): """ The inverse of rowsAfterItem. @param item: then L{Item} to request rows before. @type item: this L{InequalityModel}'s L{itemType} attribute. @param count: The maximum number of rows to return. @type count: L{int} @return: A list of row data, ordered by the current sort column, beginning immediately after C{item}. """ currentSortAttribute = self.currentSortColumn.sortAttribute() value = currentSortAttribute.__get__(item, type(item)) firstQuery = self.inequalityQuery( AND(currentSortAttribute == value, self.itemType.storeID < item.storeID), count, False) results = self.constructRows(firstQuery) count -= len(results) if count: secondQuery = self.inequalityQuery(currentSortAttribute < value, count, False) results.extend(self.constructRows(secondQuery)) return results[::-1]
0, module; 1, function_definition; 2, function_name:getTableMetadata; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, if_statement; 10, return_statement; 11, comment:""" Retrieve a description of the various properties of this scrolltable. @return: A sequence containing 5 elements. They are, in order, a list of the names of the columns present, a mapping of column names to two-tuples of their type and a boolean indicating their sortability, the total number of rows in the scrolltable, the name of the default sort column, and a boolean indicating whether or not the current sort order is ascending. """; 12, assignment; 13, tuple_pattern; 14, call; 15, block; 16, attribute; 17, block; 18, else_clause; 19, list; 20, identifier:coltypes; 21, dictionary; 22, identifier:colname; 23, identifier:column; 24, attribute; 25, argument_list; 26, expression_statement; 27, expression_statement; 28, if_statement; 29, expression_statement; 30, identifier:self; 31, identifier:currentSortColumn; 32, expression_statement; 33, block; 34, attribute; 35, identifier:coltypes; 36, call; 37, identifier:csc; 38, attribute; 39, attribute; 40, identifier:iteritems; 41, assignment; 42, assignment; 43, comparison_operator:coltype is not None; 44, block; 45, assignment; 46, assignment; 47, expression_statement; 48, identifier:self; 49, identifier:columnNames; 50, attribute; 51, argument_list; 52, identifier:self; 53, identifier:isAscending; 54, identifier:self; 55, identifier:columns; 56, identifier:sortable; 57, comparison_operator:column.sortAttribute() is not None; 58, identifier:coltype; 59, call; 60, identifier:coltype; 61, None; 62, expression_statement; 63, subscript; 64, tuple; 65, identifier:csc; 66, call; 67, assignment; 68, identifier:self; 69, identifier:requestCurrentSize; 70, call; 71, None; 72, attribute; 73, argument_list; 74, assignment; 75, identifier:coltypes; 76, identifier:colname; 77, identifier:coltype; 78, identifier:sortable; 79, identifier:unicode; 80, argument_list; 81, identifier:csc; 82, None; 83, attribute; 84, argument_list; 85, identifier:column; 86, identifier:getType; 87, identifier:coltype; 88, call; 89, attribute; 90, string; 91, identifier:column; 92, identifier:sortAttribute; 93, identifier:unicode; 94, argument_list; 95, call; 96, identifier:attrname; 97, string_content:ascii; 98, identifier:coltype; 99, string; 100, attribute; 101, argument_list; 102, string_content:ascii; 103, attribute; 104, identifier:sortAttribute; 105, identifier:self; 106, identifier:currentSortColumn
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 4, 9; 4, 10; 6, 11; 7, 12; 8, 13; 8, 14; 8, 15; 9, 16; 9, 17; 9, 18; 10, 19; 12, 20; 12, 21; 13, 22; 13, 23; 14, 24; 14, 25; 15, 26; 15, 27; 15, 28; 15, 29; 16, 30; 16, 31; 17, 32; 18, 33; 19, 34; 19, 35; 19, 36; 19, 37; 19, 38; 24, 39; 24, 40; 26, 41; 27, 42; 28, 43; 28, 44; 29, 45; 32, 46; 33, 47; 34, 48; 34, 49; 36, 50; 36, 51; 38, 52; 38, 53; 39, 54; 39, 55; 41, 56; 41, 57; 42, 58; 42, 59; 43, 60; 43, 61; 44, 62; 45, 63; 45, 64; 46, 65; 46, 66; 47, 67; 50, 68; 50, 69; 57, 70; 57, 71; 59, 72; 59, 73; 62, 74; 63, 75; 63, 76; 64, 77; 64, 78; 66, 79; 66, 80; 67, 81; 67, 82; 70, 83; 70, 84; 72, 85; 72, 86; 74, 87; 74, 88; 80, 89; 80, 90; 83, 91; 83, 92; 88, 93; 88, 94; 89, 95; 89, 96; 90, 97; 94, 98; 94, 99; 95, 100; 95, 101; 99, 102; 100, 103; 100, 104; 103, 105; 103, 106
def getTableMetadata(self): """ Retrieve a description of the various properties of this scrolltable. @return: A sequence containing 5 elements. They are, in order, a list of the names of the columns present, a mapping of column names to two-tuples of their type and a boolean indicating their sortability, the total number of rows in the scrolltable, the name of the default sort column, and a boolean indicating whether or not the current sort order is ascending. """ coltypes = {} for (colname, column) in self.columns.iteritems(): sortable = column.sortAttribute() is not None coltype = column.getType() if coltype is not None: coltype = unicode(coltype, 'ascii') coltypes[colname] = (coltype, sortable) if self.currentSortColumn: csc = unicode(self.currentSortColumn.sortAttribute().attrname, 'ascii') else: csc = None return [self.columnNames, coltypes, self.requestCurrentSize(), csc, self.isAscending]
0, module; 1, function_definition; 2, function_name:getInitialArguments; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, return_statement; 9, comment:""" Return the constructor arguments required for the JavaScript client class, Mantissa.ScrollTable.ScrollTable. @return: a 3-tuple of:: - The unicode attribute ID of my current sort column - A list of dictionaries with 'name' and 'type' keys which are strings describing the name and type of all the columns in this table. - A bool indicating whether the sort direction is initially ascending. """; 10, assignment; 11, list; 12, identifier:ic; 13, call; 14, call; 15, call; 16, attribute; 17, identifier:IColumn; 18, argument_list; 19, attribute; 20, argument_list; 21, attribute; 22, argument_list; 23, identifier:self; 24, identifier:isAscending; 25, attribute; 26, attribute; 27, identifier:decode; 28, string; 29, identifier:self; 30, identifier:_getColumnList; 31, identifier:self; 32, identifier:currentSortColumn; 33, identifier:ic; 34, identifier:attributeID; 35, string_content:ascii
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 4, 6; 4, 7; 4, 8; 6, 9; 7, 10; 8, 11; 10, 12; 10, 13; 11, 14; 11, 15; 11, 16; 13, 17; 13, 18; 14, 19; 14, 20; 15, 21; 15, 22; 16, 23; 16, 24; 18, 25; 19, 26; 19, 27; 20, 28; 21, 29; 21, 30; 25, 31; 25, 32; 26, 33; 26, 34; 28, 35
def getInitialArguments(self): """ Return the constructor arguments required for the JavaScript client class, Mantissa.ScrollTable.ScrollTable. @return: a 3-tuple of:: - The unicode attribute ID of my current sort column - A list of dictionaries with 'name' and 'type' keys which are strings describing the name and type of all the columns in this table. - A bool indicating whether the sort direction is initially ascending. """ ic = IColumn(self.currentSortColumn) return [ic.attributeID.decode('ascii'), self._getColumnList(), self.isAscending]
0, module; 1, function_definition; 2, function_name:build_database_sortmerna; 3, parameters; 4, block; 5, identifier:fasta_path; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, comment:# Instantiate the object; 17, expression_statement; 18, comment:# The parameter --ref STRING must follow the format where; 19, comment:# STRING = /path/to/ref.fasta,/path/to/ref.idx; 20, expression_statement; 21, comment:# Set temporary directory; 22, expression_statement; 23, comment:# Override --max_pos parameter; 24, if_statement; 25, comment:# Run indexdb_rna; 26, expression_statement; 27, comment:# Return all output files (by indexdb_rna) as a list,; 28, comment:# first however remove the StdErr and StdOut filepaths; 29, comment:# as they files will be destroyed at the exit from; 30, comment:# this function (IndexDB is a local instance); 31, expression_statement; 32, return_statement; 33, identifier:max_pos; 34, None; 35, identifier:output_dir; 36, None; 37, identifier:temp_dir; 38, call; 39, identifier:HALT_EXEC; 40, False; 41, comment:""" Build sortmerna db from fasta_path; return db name and list of files created Parameters ---------- fasta_path : string path to fasta file of sequences to build database. max_pos : integer, optional maximum positions to store per seed in index [default: 10000]. output_dir : string, optional directory where output should be written [default: same directory as fasta_path] HALT_EXEC : boolean, optional halt just before running the indexdb_rna command and print the command -- useful for debugging [default: False]. Return ------ db_name : string filepath to indexed database. db_filepaths : list output files by indexdb_rna """; 42, comparison_operator:fasta_path is None; 43, block; 44, assignment; 45, not_operator; 46, block; 47, assignment; 48, assignment; 49, assignment; 50, call; 51, call; 52, comparison_operator:max_pos is not None; 53, block; 54, assignment; 55, assignment; 56, expression_list; 57, attribute; 58, argument_list; 59, identifier:fasta_path; 60, None; 61, raise_statement; 62, pattern_list; 63, call; 64, identifier:output_dir; 65, expression_statement; 66, comment:# Will cd to this directory, so just pass the filename; 67, comment:# so the app is not confused by relative paths; 68, expression_statement; 69, identifier:index_basename; 70, subscript; 71, identifier:db_name; 72, call; 73, identifier:sdb; 74, call; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, identifier:max_pos; 80, None; 81, expression_statement; 82, identifier:app_result; 83, call; 84, identifier:db_filepaths; 85, list_comprehension; 86, identifier:db_name; 87, identifier:db_filepaths; 88, identifier:tempfile; 89, identifier:gettempdir; 90, call; 91, identifier:fasta_dir; 92, identifier:fasta_filename; 93, identifier:split; 94, argument_list; 95, assignment; 96, assignment; 97, call; 98, integer:0; 99, identifier:join; 100, argument_list; 101, identifier:IndexDB; 102, argument_list; 103, subscript; 104, identifier:on; 105, binary_operator:"%s,%s" % (fasta_path, db_name); 106, subscript; 107, identifier:on; 108, identifier:temp_dir; 109, call; 110, identifier:sdb; 111, argument_list; 112, attribute; 113, for_in_clause; 114, if_clause; 115, identifier:ValueError; 116, argument_list; 117, identifier:fasta_path; 118, identifier:output_dir; 119, boolean_operator; 120, identifier:fasta_path; 121, identifier:fasta_filename; 122, identifier:splitext; 123, argument_list; 124, identifier:output_dir; 125, identifier:index_basename; 126, keyword_argument; 127, keyword_argument; 128, attribute; 129, string; 130, string:"%s,%s"; 131, tuple; 132, attribute; 133, string; 134, attribute; 135, argument_list; 136, identifier:v; 137, identifier:name; 138, pattern_list; 139, call; 140, boolean_operator; 141, concatenated_string; 142, identifier:fasta_dir; 143, string; 144, identifier:fasta_filename; 145, identifier:WorkingDir; 146, identifier:output_dir; 147, identifier:HALT_EXEC; 148, identifier:HALT_EXEC; 149, identifier:sdb; 150, identifier:Parameters; 151, string_content:--ref; 152, identifier:fasta_path; 153, identifier:db_name; 154, identifier:sdb; 155, identifier:Parameters; 156, string_content:--tmpdir; 157, subscript; 158, identifier:on; 159, identifier:max_pos; 160, identifier:k; 161, identifier:v; 162, attribute; 163, argument_list; 164, comparison_operator:k not in {'StdErr', 'StdOut'}; 165, call; 166, string:"Error: path to fasta reference "; 167, string:"sequences must exist."; 168, string_content:.; 169, attribute; 170, string; 171, identifier:app_result; 172, identifier:items; 173, identifier:k; 174, set; 175, identifier:hasattr; 176, argument_list; 177, identifier:sdb; 178, identifier:Parameters; 179, string_content:--max_pos; 180, string; 181, string; 182, identifier:v; 183, string; 184, string_content:StdErr; 185, string_content:StdOut; 186, string_content:name
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, 10; 4, 11; 4, 12; 4, 13; 4, 14; 4, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 6, 33; 6, 34; 7, 35; 7, 36; 8, 37; 8, 38; 9, 39; 9, 40; 10, 41; 11, 42; 11, 43; 12, 44; 13, 45; 13, 46; 14, 47; 15, 48; 17, 49; 20, 50; 22, 51; 24, 52; 24, 53; 26, 54; 31, 55; 32, 56; 38, 57; 38, 58; 42, 59; 42, 60; 43, 61; 44, 62; 44, 63; 45, 64; 46, 65; 46, 66; 46, 67; 46, 68; 47, 69; 47, 70; 48, 71; 48, 72; 49, 73; 49, 74; 50, 75; 50, 76; 51, 77; 51, 78; 52, 79; 52, 80; 53, 81; 54, 82; 54, 83; 55, 84; 55, 85; 56, 86; 56, 87; 57, 88; 57, 89; 61, 90; 62, 91; 62, 92; 63, 93; 63, 94; 65, 95; 68, 96; 70, 97; 70, 98; 72, 99; 72, 100; 74, 101; 74, 102; 75, 103; 75, 104; 76, 105; 77, 106; 77, 107; 78, 108; 81, 109; 83, 110; 83, 111; 85, 112; 85, 113; 85, 114; 90, 115; 90, 116; 94, 117; 95, 118; 95, 119; 96, 120; 96, 121; 97, 122; 97, 123; 100, 124; 100, 125; 102, 126; 102, 127; 103, 128; 103, 129; 105, 130; 105, 131; 106, 132; 106, 133; 109, 134; 109, 135; 112, 136; 112, 137; 113, 138; 113, 139; 114, 140; 116, 141; 119, 142; 119, 143; 123, 144; 126, 145; 126, 146; 127, 147; 127, 148; 128, 149; 128, 150; 129, 151; 131, 152; 131, 153; 132, 154; 132, 155; 133, 156; 134, 157; 134, 158; 135, 159; 138, 160; 138, 161; 139, 162; 139, 163; 140, 164; 140, 165; 141, 166; 141, 167; 143, 168; 157, 169; 157, 170; 162, 171; 162, 172; 164, 173; 164, 174; 165, 175; 165, 176; 169, 177; 169, 178; 170, 179; 174, 180; 174, 181; 176, 182; 176, 183; 180, 184; 181, 185; 183, 186
def build_database_sortmerna(fasta_path, max_pos=None, output_dir=None, temp_dir=tempfile.gettempdir(), HALT_EXEC=False): """ Build sortmerna db from fasta_path; return db name and list of files created Parameters ---------- fasta_path : string path to fasta file of sequences to build database. max_pos : integer, optional maximum positions to store per seed in index [default: 10000]. output_dir : string, optional directory where output should be written [default: same directory as fasta_path] HALT_EXEC : boolean, optional halt just before running the indexdb_rna command and print the command -- useful for debugging [default: False]. Return ------ db_name : string filepath to indexed database. db_filepaths : list output files by indexdb_rna """ if fasta_path is None: raise ValueError("Error: path to fasta reference " "sequences must exist.") fasta_dir, fasta_filename = split(fasta_path) if not output_dir: output_dir = fasta_dir or '.' # Will cd to this directory, so just pass the filename # so the app is not confused by relative paths fasta_path = fasta_filename index_basename = splitext(fasta_filename)[0] db_name = join(output_dir, index_basename) # Instantiate the object sdb = IndexDB(WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) # The parameter --ref STRING must follow the format where # STRING = /path/to/ref.fasta,/path/to/ref.idx sdb.Parameters['--ref'].on("%s,%s" % (fasta_path, db_name)) # Set temporary directory sdb.Parameters['--tmpdir'].on(temp_dir) # Override --max_pos parameter if max_pos is not None: sdb.Parameters['--max_pos'].on(max_pos) # Run indexdb_rna app_result = sdb() # Return all output files (by indexdb_rna) as a list, # first however remove the StdErr and StdOut filepaths # as they files will be destroyed at the exit from # this function (IndexDB is a local instance) db_filepaths = [v.name for k, v in app_result.items() if k not in {'StdErr', 'StdOut'} and hasattr(v, 'name')] return db_name, db_filepaths
0, module; 1, function_definition; 2, function_name:sortmerna_ref_cluster; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, expression_statement; 17, comment:# Instantiate the object; 18, expression_statement; 19, comment:# Set input query sequences path; 20, if_statement; 21, comment:# Set the input reference sequence + indexed database path; 22, if_statement; 23, if_statement; 24, comment:# Set output results path (for Blast alignments, clusters and failures); 25, expression_statement; 26, if_statement; 27, comment:# Set E-value threshold; 28, if_statement; 29, comment:# Set similarity threshold; 30, if_statement; 31, comment:# Set query coverage threshold; 32, if_statement; 33, comment:# Set number of best alignments to output; 34, if_statement; 35, comment:# Set Blast tabular output; 36, comment:# The option --blast 3 represents an; 37, comment:# m8 blast tabular output + two extra; 38, comment:# columns containing the CIGAR string; 39, comment:# and the query coverage; 40, if_statement; 41, comment:# Set number of threads; 42, if_statement; 43, comment:# Run sortmerna; 44, expression_statement; 45, comment:# Put clusters into a map of lists; 46, expression_statement; 47, expression_statement; 48, expression_statement; 49, comment:# Put failures into a list; 50, expression_statement; 51, expression_statement; 52, comment:# remove the aligned FASTA file and failures FASTA file; 53, comment:# (currently these are re-constructed using pick_rep_set.py; 54, comment:# further in the OTU-picking pipeline); 55, expression_statement; 56, return_statement; 57, identifier:seq_path; 58, None; 59, identifier:sortmerna_db; 60, None; 61, identifier:refseqs_fp; 62, None; 63, identifier:result_path; 64, None; 65, identifier:tabular; 66, False; 67, identifier:max_e_value; 68, integer:1; 69, identifier:similarity; 70, float:0.97; 71, identifier:coverage; 72, float:0.97; 73, identifier:threads; 74, integer:1; 75, identifier:best; 76, integer:1; 77, identifier:HALT_EXEC; 78, False; 79, comment:"""Launch sortmerna OTU picker Parameters ---------- seq_path : str filepath to query sequences. sortmerna_db : str indexed reference database. refseqs_fp : str filepath of reference sequences. result_path : str filepath to output OTU map. max_e_value : float, optional E-value threshold [default: 1]. similarity : float, optional similarity %id threshold [default: 0.97]. coverage : float, optional query coverage % threshold [default: 0.97]. threads : int, optional number of threads to use (OpenMP) [default: 1]. tabular : bool, optional output BLAST tabular alignments [default: False]. best : int, optional number of best alignments to output per read [default: 1]. Returns ------- clusters : dict of lists OTU ids and reads mapping to them failures : list reads which did not align """; 80, assignment; 81, comparison_operator:seq_path is not None; 82, block; 83, else_clause; 84, comparison_operator:sortmerna_db is not None; 85, block; 86, else_clause; 87, comparison_operator:result_path is None; 88, block; 89, assignment; 90, comparison_operator:output_dir is not None; 91, block; 92, comparison_operator:max_e_value is not None; 93, block; 94, comparison_operator:similarity is not None; 95, block; 96, comparison_operator:coverage is not None; 97, block; 98, comparison_operator:best is not None; 99, block; 100, identifier:tabular; 101, block; 102, comparison_operator:threads is not None; 103, block; 104, assignment; 105, assignment; 106, assignment; 107, assignment; 108, assignment; 109, assignment; 110, assignment; 111, expression_list; 112, identifier:smr; 113, call; 114, identifier:seq_path; 115, None; 116, expression_statement; 117, block; 118, identifier:sortmerna_db; 119, None; 120, expression_statement; 121, block; 122, identifier:result_path; 123, None; 124, raise_statement; 125, identifier:output_dir; 126, call; 127, identifier:output_dir; 128, None; 129, expression_statement; 130, expression_statement; 131, identifier:max_e_value; 132, None; 133, expression_statement; 134, identifier:similarity; 135, None; 136, expression_statement; 137, identifier:coverage; 138, None; 139, expression_statement; 140, identifier:best; 141, None; 142, expression_statement; 143, expression_statement; 144, identifier:threads; 145, None; 146, expression_statement; 147, identifier:app_result; 148, call; 149, identifier:f_otumap; 150, subscript; 151, identifier:rows; 152, generator_expression; 153, identifier:clusters; 154, dictionary_comprehension; 155, identifier:f_failure; 156, subscript; 157, identifier:failures; 158, list_comprehension; 159, identifier:smr_files_to_remove; 160, list; 161, identifier:clusters; 162, identifier:failures; 163, identifier:smr_files_to_remove; 164, identifier:Sortmerna; 165, argument_list; 166, call; 167, raise_statement; 168, call; 169, raise_statement; 170, call; 171, identifier:dirname; 172, argument_list; 173, assignment; 174, call; 175, call; 176, call; 177, call; 178, call; 179, call; 180, call; 181, identifier:smr; 182, argument_list; 183, identifier:app_result; 184, string; 185, call; 186, for_in_clause; 187, pair; 188, for_in_clause; 189, identifier:app_result; 190, string; 191, subscript; 192, for_in_clause; 193, attribute; 194, attribute; 195, attribute; 196, keyword_argument; 197, attribute; 198, argument_list; 199, call; 200, attribute; 201, argument_list; 202, call; 203, identifier:ValueError; 204, argument_list; 205, identifier:result_path; 206, identifier:output_file; 207, call; 208, attribute; 209, argument_list; 210, attribute; 211, argument_list; 212, attribute; 213, argument_list; 214, attribute; 215, argument_list; 216, attribute; 217, argument_list; 218, attribute; 219, argument_list; 220, attribute; 221, argument_list; 222, string_content:OtuMap; 223, attribute; 224, argument_list; 225, identifier:line; 226, identifier:f_otumap; 227, subscript; 228, subscript; 229, identifier:r; 230, identifier:rows; 231, string_content:FastaForDenovo; 232, call; 233, integer:0; 234, pattern_list; 235, call; 236, subscript; 237, identifier:name; 238, subscript; 239, identifier:name; 240, subscript; 241, identifier:name; 242, identifier:HALT_EXEC; 243, identifier:HALT_EXEC; 244, subscript; 245, identifier:on; 246, identifier:seq_path; 247, identifier:ValueError; 248, argument_list; 249, subscript; 250, identifier:on; 251, binary_operator:"%s,%s" % (refseqs_fp, sortmerna_db); 252, identifier:ValueError; 253, argument_list; 254, string:"Error: the result path must be set."; 255, identifier:join; 256, argument_list; 257, subscript; 258, identifier:on; 259, identifier:output_file; 260, subscript; 261, identifier:on; 262, identifier:max_e_value; 263, subscript; 264, identifier:on; 265, identifier:similarity; 266, subscript; 267, identifier:on; 268, identifier:coverage; 269, subscript; 270, identifier:on; 271, identifier:best; 272, subscript; 273, identifier:on; 274, string:"3"; 275, subscript; 276, identifier:on; 277, identifier:threads; 278, call; 279, identifier:split; 280, string; 281, identifier:r; 282, integer:0; 283, identifier:r; 284, slice; 285, attribute; 286, argument_list; 287, identifier:label; 288, identifier:seq; 289, identifier:parse_fasta; 290, argument_list; 291, identifier:app_result; 292, string; 293, identifier:app_result; 294, string; 295, identifier:app_result; 296, string; 297, attribute; 298, string; 299, string:"Error: a read file is mandatory input."; 300, attribute; 301, string; 302, string:"%s,%s"; 303, tuple; 304, binary_operator:"Error: an indexed database for reference set %s must" " already exist.\nUse indexdb_rna to index the" " database." % refseqs_fp; 305, identifier:output_dir; 306, string:"sortmerna_otus"; 307, attribute; 308, string; 309, attribute; 310, string; 311, attribute; 312, string; 313, attribute; 314, string; 315, attribute; 316, string; 317, attribute; 318, string; 319, attribute; 320, string; 321, attribute; 322, argument_list; 323, string_content; 324, integer:1; 325, identifier:re; 326, identifier:split; 327, string; 328, identifier:label; 329, identifier:f_failure; 330, string_content:FastaForDenovo; 331, string_content:FastaMatches; 332, string_content:OtuMap; 333, identifier:smr; 334, identifier:Parameters; 335, string_content:--reads; 336, identifier:smr; 337, identifier:Parameters; 338, string_content:--ref; 339, identifier:refseqs_fp; 340, identifier:sortmerna_db; 341, concatenated_string; 342, identifier:refseqs_fp; 343, identifier:smr; 344, identifier:Parameters; 345, string_content:--aligned; 346, identifier:smr; 347, identifier:Parameters; 348, string_content:-e; 349, identifier:smr; 350, identifier:Parameters; 351, string_content:--id; 352, identifier:smr; 353, identifier:Parameters; 354, string_content:--coverage; 355, identifier:smr; 356, identifier:Parameters; 357, string_content:--best; 358, identifier:smr; 359, identifier:Parameters; 360, string_content:--blast; 361, identifier:smr; 362, identifier:Parameters; 363, string_content:-a; 364, identifier:line; 365, identifier:strip; 366, escape_sequence:\t; 367, string_content:>|; 368, string:"Error: an indexed database for reference set %s must"; 369, string:" already exist.\nUse indexdb_rna to index the"; 370, string:" database."
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 4, 34; 4, 35; 4, 36; 4, 37; 4, 38; 4, 39; 4, 40; 4, 41; 4, 42; 4, 43; 4, 44; 4, 45; 4, 46; 4, 47; 4, 48; 4, 49; 4, 50; 4, 51; 4, 52; 4, 53; 4, 54; 4, 55; 4, 56; 5, 57; 5, 58; 6, 59; 6, 60; 7, 61; 7, 62; 8, 63; 8, 64; 9, 65; 9, 66; 10, 67; 10, 68; 11, 69; 11, 70; 12, 71; 12, 72; 13, 73; 13, 74; 14, 75; 14, 76; 15, 77; 15, 78; 16, 79; 18, 80; 20, 81; 20, 82; 20, 83; 22, 84; 22, 85; 22, 86; 23, 87; 23, 88; 25, 89; 26, 90; 26, 91; 28, 92; 28, 93; 30, 94; 30, 95; 32, 96; 32, 97; 34, 98; 34, 99; 40, 100; 40, 101; 42, 102; 42, 103; 44, 104; 46, 105; 47, 106; 48, 107; 50, 108; 51, 109; 55, 110; 56, 111; 80, 112; 80, 113; 81, 114; 81, 115; 82, 116; 83, 117; 84, 118; 84, 119; 85, 120; 86, 121; 87, 122; 87, 123; 88, 124; 89, 125; 89, 126; 90, 127; 90, 128; 91, 129; 91, 130; 92, 131; 92, 132; 93, 133; 94, 134; 94, 135; 95, 136; 96, 137; 96, 138; 97, 139; 98, 140; 98, 141; 99, 142; 101, 143; 102, 144; 102, 145; 103, 146; 104, 147; 104, 148; 105, 149; 105, 150; 106, 151; 106, 152; 107, 153; 107, 154; 108, 155; 108, 156; 109, 157; 109, 158; 110, 159; 110, 160; 111, 161; 111, 162; 111, 163; 113, 164; 113, 165; 116, 166; 117, 167; 120, 168; 121, 169; 124, 170; 126, 171; 126, 172; 129, 173; 130, 174; 133, 175; 136, 176; 139, 177; 142, 178; 143, 179; 146, 180; 148, 181; 148, 182; 150, 183; 150, 184; 152, 185; 152, 186; 154, 187; 154, 188; 156, 189; 156, 190; 158, 191; 158, 192; 160, 193; 160, 194; 160, 195; 165, 196; 166, 197; 166, 198; 167, 199; 168, 200; 168, 201; 169, 202; 170, 203; 170, 204; 172, 205; 173, 206; 173, 207; 174, 208; 174, 209; 175, 210; 175, 211; 176, 212; 176, 213; 177, 214; 177, 215; 178, 216; 178, 217; 179, 218; 179, 219; 180, 220; 180, 221; 184, 222; 185, 223; 185, 224; 186, 225; 186, 226; 187, 227; 187, 228; 188, 229; 188, 230; 190, 231; 191, 232; 191, 233; 192, 234; 192, 235; 193, 236; 193, 237; 194, 238; 194, 239; 195, 240; 195, 241; 196, 242; 196, 243; 197, 244; 197, 245; 198, 246; 199, 247; 199, 248; 200, 249; 200, 250; 201, 251; 202, 252; 202, 253; 204, 254; 207, 255; 207, 256; 208, 257; 208, 258; 209, 259; 210, 260; 210, 261; 211, 262; 212, 263; 212, 264; 213, 265; 214, 266; 214, 267; 215, 268; 216, 269; 216, 270; 217, 271; 218, 272; 218, 273; 219, 274; 220, 275; 220, 276; 221, 277; 223, 278; 223, 279; 224, 280; 227, 281; 227, 282; 228, 283; 228, 284; 232, 285; 232, 286; 234, 287; 234, 288; 235, 289; 235, 290; 236, 291; 236, 292; 238, 293; 238, 294; 240, 295; 240, 296; 244, 297; 244, 298; 248, 299; 249, 300; 249, 301; 251, 302; 251, 303; 253, 304; 256, 305; 256, 306; 257, 307; 257, 308; 260, 309; 260, 310; 263, 311; 263, 312; 266, 313; 266, 314; 269, 315; 269, 316; 272, 317; 272, 318; 275, 319; 275, 320; 278, 321; 278, 322; 280, 323; 284, 324; 285, 325; 285, 326; 286, 327; 286, 328; 290, 329; 292, 330; 294, 331; 296, 332; 297, 333; 297, 334; 298, 335; 300, 336; 300, 337; 301, 338; 303, 339; 303, 340; 304, 341; 304, 342; 307, 343; 307, 344; 308, 345; 309, 346; 309, 347; 310, 348; 311, 349; 311, 350; 312, 351; 313, 352; 313, 353; 314, 354; 315, 355; 315, 356; 316, 357; 317, 358; 317, 359; 318, 360; 319, 361; 319, 362; 320, 363; 321, 364; 321, 365; 323, 366; 327, 367; 341, 368; 341, 369; 341, 370
def sortmerna_ref_cluster(seq_path=None, sortmerna_db=None, refseqs_fp=None, result_path=None, tabular=False, max_e_value=1, similarity=0.97, coverage=0.97, threads=1, best=1, HALT_EXEC=False ): """Launch sortmerna OTU picker Parameters ---------- seq_path : str filepath to query sequences. sortmerna_db : str indexed reference database. refseqs_fp : str filepath of reference sequences. result_path : str filepath to output OTU map. max_e_value : float, optional E-value threshold [default: 1]. similarity : float, optional similarity %id threshold [default: 0.97]. coverage : float, optional query coverage % threshold [default: 0.97]. threads : int, optional number of threads to use (OpenMP) [default: 1]. tabular : bool, optional output BLAST tabular alignments [default: False]. best : int, optional number of best alignments to output per read [default: 1]. Returns ------- clusters : dict of lists OTU ids and reads mapping to them failures : list reads which did not align """ # Instantiate the object smr = Sortmerna(HALT_EXEC=HALT_EXEC) # Set input query sequences path if seq_path is not None: smr.Parameters['--reads'].on(seq_path) else: raise ValueError("Error: a read file is mandatory input.") # Set the input reference sequence + indexed database path if sortmerna_db is not None: smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db)) else: raise ValueError("Error: an indexed database for reference set %s must" " already exist.\nUse indexdb_rna to index the" " database." % refseqs_fp) if result_path is None: raise ValueError("Error: the result path must be set.") # Set output results path (for Blast alignments, clusters and failures) output_dir = dirname(result_path) if output_dir is not None: output_file = join(output_dir, "sortmerna_otus") smr.Parameters['--aligned'].on(output_file) # Set E-value threshold if max_e_value is not None: smr.Parameters['-e'].on(max_e_value) # Set similarity threshold if similarity is not None: smr.Parameters['--id'].on(similarity) # Set query coverage threshold if coverage is not None: smr.Parameters['--coverage'].on(coverage) # Set number of best alignments to output if best is not None: smr.Parameters['--best'].on(best) # Set Blast tabular output # The option --blast 3 represents an # m8 blast tabular output + two extra # columns containing the CIGAR string # and the query coverage if tabular: smr.Parameters['--blast'].on("3") # Set number of threads if threads is not None: smr.Parameters['-a'].on(threads) # Run sortmerna app_result = smr() # Put clusters into a map of lists f_otumap = app_result['OtuMap'] rows = (line.strip().split('\t') for line in f_otumap) clusters = {r[0]: r[1:] for r in rows} # Put failures into a list f_failure = app_result['FastaForDenovo'] failures = [re.split('>| ', label)[0] for label, seq in parse_fasta(f_failure)] # remove the aligned FASTA file and failures FASTA file # (currently these are re-constructed using pick_rep_set.py # further in the OTU-picking pipeline) smr_files_to_remove = [app_result['FastaForDenovo'].name, app_result['FastaMatches'].name, app_result['OtuMap'].name] return clusters, failures, smr_files_to_remove
0, module; 1, function_definition; 2, function_name:sortmerna_map; 3, parameters; 4, block; 5, identifier:seq_path; 6, identifier:output_dir; 7, identifier:refseqs_fp; 8, identifier:sortmerna_db; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, expression_statement; 19, if_statement; 20, if_statement; 21, comment:# Instantiate the object; 22, expression_statement; 23, comment:# Set the input reference sequence + indexed database path; 24, expression_statement; 25, comment:# Set input query sequences path; 26, expression_statement; 27, comment:# Set Blast tabular output; 28, comment:# The option --blast 3 represents an; 29, comment:# m8 blast tabular output + two extra; 30, comment:# columns containing the CIGAR string; 31, comment:# and the query coverage; 32, if_statement; 33, comment:# Output alignments in SAM format; 34, if_statement; 35, comment:# Turn on NULL string alignment output; 36, if_statement; 37, comment:# Set output results path (for Blast alignments and log file); 38, expression_statement; 39, expression_statement; 40, comment:# Set E-value threshold; 41, if_statement; 42, comment:# Set number of best alignments to output per read; 43, if_statement; 44, comment:# Set number of first alignments passing E-value threshold; 45, comment:# to output per read; 46, if_statement; 47, comment:# Set number of threads; 48, if_statement; 49, comment:# Turn off parameters related to OTU-picking; 50, expression_statement; 51, expression_statement; 52, expression_statement; 53, expression_statement; 54, expression_statement; 55, comment:# Run sortmerna; 56, expression_statement; 57, return_statement; 58, identifier:e_value; 59, integer:1; 60, identifier:threads; 61, integer:1; 62, identifier:best; 63, None; 64, identifier:num_alignments; 65, None; 66, identifier:HALT_EXEC; 67, False; 68, identifier:output_sam; 69, False; 70, identifier:sam_SQ_tags; 71, False; 72, identifier:blast_format; 73, integer:3; 74, identifier:print_all_reads; 75, True; 76, comment:"""Launch sortmerna mapper Parameters ---------- seq_path : str filepath to reads. output_dir : str dirpath to sortmerna output. refseqs_fp : str filepath of reference sequences. sortmerna_db : str indexed reference database. e_value : float, optional E-value threshold [default: 1]. threads : int, optional number of threads to use (OpenMP) [default: 1]. best : int, optional number of best alignments to output per read [default: None]. num_alignments : int, optional number of first alignments passing E-value threshold to output per read [default: None]. HALT_EXEC : bool, debugging parameter If passed, will exit just before the sortmerna command is issued and will print out the command that would have been called to stdout [default: False]. output_sam : bool, optional flag to set SAM output format [default: False]. sam_SQ_tags : bool, optional add SQ field to SAM output (if output_SAM is True) [default: False]. blast_format : int, optional Output Blast m8 tabular + 2 extra columns for CIGAR string and query coverge [default: 3]. print_all_reads : bool, optional output NULL alignments for non-aligned reads [default: True]. Returns ------- dict of result paths set in _get_result_paths() """; 77, not_operator; 78, block; 79, parenthesized_expression; 80, block; 81, assignment; 82, call; 83, call; 84, identifier:blast_format; 85, block; 86, identifier:output_sam; 87, block; 88, identifier:print_all_reads; 89, block; 90, assignment; 91, call; 92, comparison_operator:e_value is not None; 93, block; 94, comparison_operator:best is not None; 95, block; 96, comparison_operator:num_alignments is not None; 97, block; 98, comparison_operator:threads is not None; 99, block; 100, call; 101, call; 102, call; 103, call; 104, call; 105, assignment; 106, identifier:app_result; 107, parenthesized_expression; 108, raise_statement; 109, boolean_operator; 110, raise_statement; 111, identifier:smr; 112, call; 113, attribute; 114, argument_list; 115, attribute; 116, argument_list; 117, expression_statement; 118, expression_statement; 119, if_statement; 120, expression_statement; 121, identifier:output_file; 122, call; 123, attribute; 124, argument_list; 125, identifier:e_value; 126, None; 127, expression_statement; 128, identifier:best; 129, None; 130, expression_statement; 131, identifier:num_alignments; 132, None; 133, expression_statement; 134, identifier:threads; 135, None; 136, expression_statement; 137, attribute; 138, argument_list; 139, attribute; 140, argument_list; 141, attribute; 142, argument_list; 143, attribute; 144, argument_list; 145, attribute; 146, argument_list; 147, identifier:app_result; 148, call; 149, boolean_operator; 150, call; 151, identifier:best; 152, identifier:num_alignments; 153, call; 154, identifier:Sortmerna; 155, argument_list; 156, subscript; 157, identifier:on; 158, binary_operator:"%s,%s" % (refseqs_fp, sortmerna_db); 159, subscript; 160, identifier:on; 161, identifier:seq_path; 162, call; 163, call; 164, identifier:sam_SQ_tags; 165, block; 166, call; 167, identifier:join; 168, argument_list; 169, subscript; 170, identifier:on; 171, identifier:output_file; 172, call; 173, call; 174, call; 175, call; 176, subscript; 177, identifier:off; 178, subscript; 179, identifier:off; 180, subscript; 181, identifier:off; 182, subscript; 183, identifier:off; 184, subscript; 185, identifier:off; 186, identifier:smr; 187, argument_list; 188, identifier:blast_format; 189, identifier:output_sam; 190, identifier:ValueError; 191, argument_list; 192, identifier:ValueError; 193, argument_list; 194, keyword_argument; 195, attribute; 196, string; 197, string:"%s,%s"; 198, tuple; 199, attribute; 200, string; 201, attribute; 202, argument_list; 203, attribute; 204, argument_list; 205, expression_statement; 206, attribute; 207, argument_list; 208, identifier:output_dir; 209, string:"sortmerna_map"; 210, attribute; 211, string; 212, attribute; 213, argument_list; 214, attribute; 215, argument_list; 216, attribute; 217, argument_list; 218, attribute; 219, argument_list; 220, attribute; 221, string; 222, attribute; 223, string; 224, attribute; 225, string; 226, attribute; 227, string; 228, attribute; 229, string; 230, concatenated_string; 231, concatenated_string; 232, identifier:HALT_EXEC; 233, identifier:HALT_EXEC; 234, identifier:smr; 235, identifier:Parameters; 236, string_content:--ref; 237, identifier:refseqs_fp; 238, identifier:sortmerna_db; 239, identifier:smr; 240, identifier:Parameters; 241, string_content:--reads; 242, subscript; 243, identifier:on; 244, identifier:blast_format; 245, subscript; 246, identifier:on; 247, call; 248, subscript; 249, identifier:on; 250, identifier:smr; 251, identifier:Parameters; 252, string_content:--aligned; 253, subscript; 254, identifier:on; 255, identifier:e_value; 256, subscript; 257, identifier:on; 258, identifier:best; 259, subscript; 260, identifier:on; 261, identifier:num_alignments; 262, subscript; 263, identifier:on; 264, identifier:threads; 265, identifier:smr; 266, identifier:Parameters; 267, string_content:--fastx; 268, identifier:smr; 269, identifier:Parameters; 270, string_content:--otu_map; 271, identifier:smr; 272, identifier:Parameters; 273, string_content:--de_novo_otu; 274, identifier:smr; 275, identifier:Parameters; 276, string_content:--id; 277, identifier:smr; 278, identifier:Parameters; 279, string_content:--coverage; 280, string:"Either Blast or SAM output alignment "; 281, string:"format must be chosen."; 282, string:"Only one of --best or --num_alignments "; 283, string:"options must be chosen."; 284, attribute; 285, string; 286, attribute; 287, string; 288, attribute; 289, argument_list; 290, attribute; 291, string; 292, attribute; 293, string; 294, attribute; 295, string; 296, attribute; 297, string; 298, attribute; 299, string; 300, identifier:smr; 301, identifier:Parameters; 302, string_content:--blast; 303, identifier:smr; 304, identifier:Parameters; 305, string_content:--sam; 306, subscript; 307, identifier:on; 308, identifier:smr; 309, identifier:Parameters; 310, string_content:--print_all_reads; 311, identifier:smr; 312, identifier:Parameters; 313, string_content:-e; 314, identifier:smr; 315, identifier:Parameters; 316, string_content:--best; 317, identifier:smr; 318, identifier:Parameters; 319, string_content:--num_alignments; 320, identifier:smr; 321, identifier:Parameters; 322, string_content:-a; 323, attribute; 324, string; 325, identifier:smr; 326, identifier:Parameters; 327, string_content:--SQ
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 16; 3, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 4, 34; 4, 35; 4, 36; 4, 37; 4, 38; 4, 39; 4, 40; 4, 41; 4, 42; 4, 43; 4, 44; 4, 45; 4, 46; 4, 47; 4, 48; 4, 49; 4, 50; 4, 51; 4, 52; 4, 53; 4, 54; 4, 55; 4, 56; 4, 57; 9, 58; 9, 59; 10, 60; 10, 61; 11, 62; 11, 63; 12, 64; 12, 65; 13, 66; 13, 67; 14, 68; 14, 69; 15, 70; 15, 71; 16, 72; 16, 73; 17, 74; 17, 75; 18, 76; 19, 77; 19, 78; 20, 79; 20, 80; 22, 81; 24, 82; 26, 83; 32, 84; 32, 85; 34, 86; 34, 87; 36, 88; 36, 89; 38, 90; 39, 91; 41, 92; 41, 93; 43, 94; 43, 95; 46, 96; 46, 97; 48, 98; 48, 99; 50, 100; 51, 101; 52, 102; 53, 103; 54, 104; 56, 105; 57, 106; 77, 107; 78, 108; 79, 109; 80, 110; 81, 111; 81, 112; 82, 113; 82, 114; 83, 115; 83, 116; 85, 117; 87, 118; 87, 119; 89, 120; 90, 121; 90, 122; 91, 123; 91, 124; 92, 125; 92, 126; 93, 127; 94, 128; 94, 129; 95, 130; 96, 131; 96, 132; 97, 133; 98, 134; 98, 135; 99, 136; 100, 137; 100, 138; 101, 139; 101, 140; 102, 141; 102, 142; 103, 143; 103, 144; 104, 145; 104, 146; 105, 147; 105, 148; 107, 149; 108, 150; 109, 151; 109, 152; 110, 153; 112, 154; 112, 155; 113, 156; 113, 157; 114, 158; 115, 159; 115, 160; 116, 161; 117, 162; 118, 163; 119, 164; 119, 165; 120, 166; 122, 167; 122, 168; 123, 169; 123, 170; 124, 171; 127, 172; 130, 173; 133, 174; 136, 175; 137, 176; 137, 177; 139, 178; 139, 179; 141, 180; 141, 181; 143, 182; 143, 183; 145, 184; 145, 185; 148, 186; 148, 187; 149, 188; 149, 189; 150, 190; 150, 191; 153, 192; 153, 193; 155, 194; 156, 195; 156, 196; 158, 197; 158, 198; 159, 199; 159, 200; 162, 201; 162, 202; 163, 203; 163, 204; 165, 205; 166, 206; 166, 207; 168, 208; 168, 209; 169, 210; 169, 211; 172, 212; 172, 213; 173, 214; 173, 215; 174, 216; 174, 217; 175, 218; 175, 219; 176, 220; 176, 221; 178, 222; 178, 223; 180, 224; 180, 225; 182, 226; 182, 227; 184, 228; 184, 229; 191, 230; 193, 231; 194, 232; 194, 233; 195, 234; 195, 235; 196, 236; 198, 237; 198, 238; 199, 239; 199, 240; 200, 241; 201, 242; 201, 243; 202, 244; 203, 245; 203, 246; 205, 247; 206, 248; 206, 249; 210, 250; 210, 251; 211, 252; 212, 253; 212, 254; 213, 255; 214, 256; 214, 257; 215, 258; 216, 259; 216, 260; 217, 261; 218, 262; 218, 263; 219, 264; 220, 265; 220, 266; 221, 267; 222, 268; 222, 269; 223, 270; 224, 271; 224, 272; 225, 273; 226, 274; 226, 275; 227, 276; 228, 277; 228, 278; 229, 279; 230, 280; 230, 281; 231, 282; 231, 283; 242, 284; 242, 285; 245, 286; 245, 287; 247, 288; 247, 289; 248, 290; 248, 291; 253, 292; 253, 293; 256, 294; 256, 295; 259, 296; 259, 297; 262, 298; 262, 299; 284, 300; 284, 301; 285, 302; 286, 303; 286, 304; 287, 305; 288, 306; 288, 307; 290, 308; 290, 309; 291, 310; 292, 311; 292, 312; 293, 313; 294, 314; 294, 315; 295, 316; 296, 317; 296, 318; 297, 319; 298, 320; 298, 321; 299, 322; 306, 323; 306, 324; 323, 325; 323, 326; 324, 327
def sortmerna_map(seq_path, output_dir, refseqs_fp, sortmerna_db, e_value=1, threads=1, best=None, num_alignments=None, HALT_EXEC=False, output_sam=False, sam_SQ_tags=False, blast_format=3, print_all_reads=True, ): """Launch sortmerna mapper Parameters ---------- seq_path : str filepath to reads. output_dir : str dirpath to sortmerna output. refseqs_fp : str filepath of reference sequences. sortmerna_db : str indexed reference database. e_value : float, optional E-value threshold [default: 1]. threads : int, optional number of threads to use (OpenMP) [default: 1]. best : int, optional number of best alignments to output per read [default: None]. num_alignments : int, optional number of first alignments passing E-value threshold to output per read [default: None]. HALT_EXEC : bool, debugging parameter If passed, will exit just before the sortmerna command is issued and will print out the command that would have been called to stdout [default: False]. output_sam : bool, optional flag to set SAM output format [default: False]. sam_SQ_tags : bool, optional add SQ field to SAM output (if output_SAM is True) [default: False]. blast_format : int, optional Output Blast m8 tabular + 2 extra columns for CIGAR string and query coverge [default: 3]. print_all_reads : bool, optional output NULL alignments for non-aligned reads [default: True]. Returns ------- dict of result paths set in _get_result_paths() """ if not (blast_format or output_sam): raise ValueError("Either Blast or SAM output alignment " "format must be chosen.") if (best and num_alignments): raise ValueError("Only one of --best or --num_alignments " "options must be chosen.") # Instantiate the object smr = Sortmerna(HALT_EXEC=HALT_EXEC) # Set the input reference sequence + indexed database path smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db)) # Set input query sequences path smr.Parameters['--reads'].on(seq_path) # Set Blast tabular output # The option --blast 3 represents an # m8 blast tabular output + two extra # columns containing the CIGAR string # and the query coverage if blast_format: smr.Parameters['--blast'].on(blast_format) # Output alignments in SAM format if output_sam: smr.Parameters['--sam'].on() if sam_SQ_tags: smr.Parameters['--SQ'].on() # Turn on NULL string alignment output if print_all_reads: smr.Parameters['--print_all_reads'].on() # Set output results path (for Blast alignments and log file) output_file = join(output_dir, "sortmerna_map") smr.Parameters['--aligned'].on(output_file) # Set E-value threshold if e_value is not None: smr.Parameters['-e'].on(e_value) # Set number of best alignments to output per read if best is not None: smr.Parameters['--best'].on(best) # Set number of first alignments passing E-value threshold # to output per read if num_alignments is not None: smr.Parameters['--num_alignments'].on(num_alignments) # Set number of threads if threads is not None: smr.Parameters['-a'].on(threads) # Turn off parameters related to OTU-picking smr.Parameters['--fastx'].off() smr.Parameters['--otu_map'].off() smr.Parameters['--de_novo_otu'].off() smr.Parameters['--id'].off() smr.Parameters['--coverage'].off() # Run sortmerna app_result = smr() return app_result
0, module; 1, function_definition; 2, function_name:_dict_values_sorted_by_key; 3, parameters; 4, comment:# This should be a yield from instead.; 5, block; 6, identifier:dictionary; 7, expression_statement; 8, for_statement; 9, comment:"""Internal helper to return the values of a dictionary, sorted by key. """; 10, pattern_list; 11, call; 12, block; 13, identifier:_; 14, identifier:value; 15, identifier:sorted; 16, argument_list; 17, expression_statement; 18, call; 19, keyword_argument; 20, yield; 21, attribute; 22, argument_list; 23, identifier:key; 24, call; 25, identifier:value; 26, identifier:dictionary; 27, identifier:iteritems; 28, attribute; 29, argument_list; 30, identifier:operator; 31, identifier:itemgetter; 32, integer:0
0, 1; 1, 2; 1, 3; 1, 4; 1, 5; 3, 6; 5, 7; 5, 8; 7, 9; 8, 10; 8, 11; 8, 12; 10, 13; 10, 14; 11, 15; 11, 16; 12, 17; 16, 18; 16, 19; 17, 20; 18, 21; 18, 22; 19, 23; 19, 24; 20, 25; 21, 26; 21, 27; 24, 28; 24, 29; 28, 30; 28, 31; 29, 32
def _dict_values_sorted_by_key(dictionary): # This should be a yield from instead. """Internal helper to return the values of a dictionary, sorted by key. """ for _, value in sorted(dictionary.iteritems(), key=operator.itemgetter(0)): yield value
0, module; 1, function_definition; 2, function_name:uclust_cluster_from_sorted_fasta_filepath; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, default_parameter; 21, expression_statement; 22, expression_statement; 23, if_statement; 24, expression_statement; 25, expression_statement; 26, comment:# Set any additional parameters specified by the user; 27, if_statement; 28, if_statement; 29, if_statement; 30, if_statement; 31, if_statement; 32, if_statement; 33, if_statement; 34, expression_statement; 35, return_statement; 36, identifier:uc_save_filepath; 37, None; 38, identifier:percent_ID; 39, float:0.97; 40, identifier:max_accepts; 41, integer:1; 42, identifier:max_rejects; 43, integer:8; 44, identifier:stepwords; 45, integer:8; 46, identifier:word_length; 47, integer:8; 48, identifier:optimal; 49, False; 50, identifier:exact; 51, False; 52, identifier:suppress_sort; 53, False; 54, identifier:enable_rev_strand_matching; 55, False; 56, identifier:subject_fasta_filepath; 57, None; 58, identifier:suppress_new_clusters; 59, False; 60, identifier:stable_sort; 61, False; 62, identifier:tmp_dir; 63, call; 64, identifier:HALT_EXEC; 65, False; 66, comment:""" Returns clustered uclust file from sorted fasta"""; 67, assignment; 68, not_operator; 69, block; 70, assignment; 71, assignment; 72, identifier:enable_rev_strand_matching; 73, block; 74, identifier:optimal; 75, block; 76, identifier:exact; 77, block; 78, identifier:suppress_sort; 79, block; 80, identifier:subject_fasta_filepath; 81, block; 82, identifier:suppress_new_clusters; 83, block; 84, identifier:stable_sort; 85, block; 86, assignment; 87, identifier:app_result; 88, identifier:gettempdir; 89, argument_list; 90, identifier:output_filepath; 91, identifier:uc_save_filepath; 92, identifier:output_filepath; 93, expression_statement; 94, identifier:params; 95, dictionary; 96, identifier:app; 97, call; 98, expression_statement; 99, expression_statement; 100, expression_statement; 101, expression_statement; 102, expression_statement; 103, expression_statement; 104, expression_statement; 105, identifier:app_result; 106, call; 107, assignment; 108, pair; 109, pair; 110, pair; 111, pair; 112, pair; 113, pair; 114, identifier:Uclust; 115, argument_list; 116, call; 117, call; 118, call; 119, call; 120, call; 121, call; 122, call; 123, identifier:app; 124, argument_list; 125, pattern_list; 126, call; 127, string; 128, identifier:percent_ID; 129, string; 130, identifier:max_accepts; 131, string; 132, identifier:max_rejects; 133, string; 134, identifier:stepwords; 135, string; 136, identifier:word_length; 137, string; 138, identifier:tmp_dir; 139, identifier:params; 140, keyword_argument; 141, keyword_argument; 142, attribute; 143, argument_list; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, attribute; 149, argument_list; 150, attribute; 151, argument_list; 152, attribute; 153, argument_list; 154, attribute; 155, argument_list; 156, dictionary; 157, identifier:_; 158, identifier:output_filepath; 159, identifier:mkstemp; 160, argument_list; 161, string_content:--id; 162, string_content:--maxaccepts; 163, string_content:--maxrejects; 164, string_content:--stepwords; 165, string_content:--w; 166, string_content:--tmpdir; 167, identifier:TmpDir; 168, identifier:tmp_dir; 169, identifier:HALT_EXEC; 170, identifier:HALT_EXEC; 171, subscript; 172, identifier:on; 173, subscript; 174, identifier:on; 175, subscript; 176, identifier:on; 177, subscript; 178, identifier:on; 179, subscript; 180, identifier:on; 181, identifier:subject_fasta_filepath; 182, subscript; 183, identifier:on; 184, subscript; 185, identifier:on; 186, pair; 187, pair; 188, keyword_argument; 189, keyword_argument; 190, keyword_argument; 191, attribute; 192, string; 193, attribute; 194, string; 195, attribute; 196, string; 197, attribute; 198, string; 199, attribute; 200, string; 201, attribute; 202, string; 203, attribute; 204, string; 205, string; 206, identifier:fasta_filepath; 207, string; 208, identifier:output_filepath; 209, identifier:dir; 210, identifier:tmp_dir; 211, identifier:prefix; 212, string; 213, identifier:suffix; 214, string; 215, identifier:app; 216, identifier:Parameters; 217, string_content:--rev; 218, identifier:app; 219, identifier:Parameters; 220, string_content:--optimal; 221, identifier:app; 222, identifier:Parameters; 223, string_content:--exact; 224, identifier:app; 225, identifier:Parameters; 226, string_content:--usersort; 227, identifier:app; 228, identifier:Parameters; 229, string_content:--lib; 230, identifier:app; 231, identifier:Parameters; 232, string_content:--libonly; 233, identifier:app; 234, identifier:Parameters; 235, string_content:--stable_sort; 236, string_content:--input; 237, string_content:--uc; 238, string_content:uclust_clusters; 239, string_content:.uc
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 16; 3, 17; 3, 18; 3, 19; 3, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 4, 34; 4, 35; 6, 36; 6, 37; 7, 38; 7, 39; 8, 40; 8, 41; 9, 42; 9, 43; 10, 44; 10, 45; 11, 46; 11, 47; 12, 48; 12, 49; 13, 50; 13, 51; 14, 52; 14, 53; 15, 54; 15, 55; 16, 56; 16, 57; 17, 58; 17, 59; 18, 60; 18, 61; 19, 62; 19, 63; 20, 64; 20, 65; 21, 66; 22, 67; 23, 68; 23, 69; 24, 70; 25, 71; 27, 72; 27, 73; 28, 74; 28, 75; 29, 76; 29, 77; 30, 78; 30, 79; 31, 80; 31, 81; 32, 82; 32, 83; 33, 84; 33, 85; 34, 86; 35, 87; 63, 88; 63, 89; 67, 90; 67, 91; 68, 92; 69, 93; 70, 94; 70, 95; 71, 96; 71, 97; 73, 98; 75, 99; 77, 100; 79, 101; 81, 102; 83, 103; 85, 104; 86, 105; 86, 106; 93, 107; 95, 108; 95, 109; 95, 110; 95, 111; 95, 112; 95, 113; 97, 114; 97, 115; 98, 116; 99, 117; 100, 118; 101, 119; 102, 120; 103, 121; 104, 122; 106, 123; 106, 124; 107, 125; 107, 126; 108, 127; 108, 128; 109, 129; 109, 130; 110, 131; 110, 132; 111, 133; 111, 134; 112, 135; 112, 136; 113, 137; 113, 138; 115, 139; 115, 140; 115, 141; 116, 142; 116, 143; 117, 144; 117, 145; 118, 146; 118, 147; 119, 148; 119, 149; 120, 150; 120, 151; 121, 152; 121, 153; 122, 154; 122, 155; 124, 156; 125, 157; 125, 158; 126, 159; 126, 160; 127, 161; 129, 162; 131, 163; 133, 164; 135, 165; 137, 166; 140, 167; 140, 168; 141, 169; 141, 170; 142, 171; 142, 172; 144, 173; 144, 174; 146, 175; 146, 176; 148, 177; 148, 178; 150, 179; 150, 180; 151, 181; 152, 182; 152, 183; 154, 184; 154, 185; 156, 186; 156, 187; 160, 188; 160, 189; 160, 190; 171, 191; 171, 192; 173, 193; 173, 194; 175, 195; 175, 196; 177, 197; 177, 198; 179, 199; 179, 200; 182, 201; 182, 202; 184, 203; 184, 204; 186, 205; 186, 206; 187, 207; 187, 208; 188, 209; 188, 210; 189, 211; 189, 212; 190, 213; 190, 214; 191, 215; 191, 216; 192, 217; 193, 218; 193, 219; 194, 220; 195, 221; 195, 222; 196, 223; 197, 224; 197, 225; 198, 226; 199, 227; 199, 228; 200, 229; 201, 230; 201, 231; 202, 232; 203, 233; 203, 234; 204, 235; 205, 236; 207, 237; 212, 238; 214, 239
def uclust_cluster_from_sorted_fasta_filepath( fasta_filepath, uc_save_filepath=None, percent_ID=0.97, max_accepts=1, max_rejects=8, stepwords=8, word_length=8, optimal=False, exact=False, suppress_sort=False, enable_rev_strand_matching=False, subject_fasta_filepath=None, suppress_new_clusters=False, stable_sort=False, tmp_dir=gettempdir(), HALT_EXEC=False): """ Returns clustered uclust file from sorted fasta""" output_filepath = uc_save_filepath if not output_filepath: _, output_filepath = mkstemp(dir=tmp_dir, prefix='uclust_clusters', suffix='.uc') params = {'--id': percent_ID, '--maxaccepts': max_accepts, '--maxrejects': max_rejects, '--stepwords': stepwords, '--w': word_length, '--tmpdir': tmp_dir} app = Uclust(params, TmpDir=tmp_dir, HALT_EXEC=HALT_EXEC) # Set any additional parameters specified by the user if enable_rev_strand_matching: app.Parameters['--rev'].on() if optimal: app.Parameters['--optimal'].on() if exact: app.Parameters['--exact'].on() if suppress_sort: app.Parameters['--usersort'].on() if subject_fasta_filepath: app.Parameters['--lib'].on(subject_fasta_filepath) if suppress_new_clusters: app.Parameters['--libonly'].on() if stable_sort: app.Parameters['--stable_sort'].on() app_result = app({'--input': fasta_filepath, '--uc': output_filepath}) return app_result
0, module; 1, function_definition; 2, function_name:get_clusters_from_fasta_filepath; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, identifier:original_fasta_path; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, default_parameter; 21, default_parameter; 22, default_parameter; 23, default_parameter; 24, expression_statement; 25, comment:# Create readable intermediate filenames if they are to be kept; 26, expression_statement; 27, expression_statement; 28, expression_statement; 29, if_statement; 30, if_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, comment:# Error check in case any app controller fails; 35, expression_statement; 36, try_statement; 37, comment:# Get list of lists for each cluster; 38, expression_statement; 39, comment:# Remove temp files unless user specifies output filepath; 40, if_statement; 41, if_statement; 42, identifier:percent_ID; 43, float:0.97; 44, identifier:max_accepts; 45, integer:1; 46, identifier:max_rejects; 47, integer:8; 48, identifier:stepwords; 49, integer:8; 50, identifier:word_length; 51, integer:8; 52, identifier:optimal; 53, False; 54, identifier:exact; 55, False; 56, identifier:suppress_sort; 57, False; 58, identifier:output_dir; 59, None; 60, identifier:enable_rev_strand_matching; 61, False; 62, identifier:subject_fasta_filepath; 63, None; 64, identifier:suppress_new_clusters; 65, False; 66, identifier:return_cluster_maps; 67, False; 68, identifier:stable_sort; 69, False; 70, identifier:tmp_dir; 71, call; 72, identifier:save_uc_files; 73, True; 74, identifier:HALT_EXEC; 75, False; 76, comment:""" Main convenience wrapper for using uclust to generate cluster files A source fasta file is required for the fasta_filepath. This will be sorted to be in order of longest to shortest length sequences. Following this, the sorted fasta file is used to generate a cluster file in the uclust (.uc) format. Next the .uc file is converted to cd-hit format (.clstr). Finally this file is parsed and returned as a list of lists, where each sublist a cluster of sequences. If an output_dir is specified, the intermediate files will be preserved, otherwise all files created are temporary and will be deleted at the end of this function The percent_ID parameter specifies the percent identity for a clusters, i.e., if 99% were the parameter, all sequences that were 99% identical would be grouped as a cluster. """; 77, assignment; 78, assignment; 79, assignment; 80, boolean_operator; 81, block; 82, identifier:save_uc_files; 83, block; 84, else_clause; 85, assignment; 86, assignment; 87, assignment; 88, assignment; 89, block; 90, except_clause; 91, except_clause; 92, assignment; 93, not_operator; 94, block; 95, identifier:return_cluster_maps; 96, block; 97, else_clause; 98, identifier:gettempdir; 99, argument_list; 100, identifier:fasta_output_filepath; 101, None; 102, identifier:uc_output_filepath; 103, None; 104, identifier:cd_hit_filepath; 105, None; 106, identifier:output_dir; 107, not_operator; 108, expression_statement; 109, expression_statement; 110, block; 111, identifier:sorted_fasta_filepath; 112, string:""; 113, identifier:uc_filepath; 114, string:""; 115, identifier:clstr_filepath; 116, string:""; 117, identifier:files_to_remove; 118, list; 119, if_statement; 120, comment:# Generate uclust cluster file (.uc format); 121, expression_statement; 122, comment:# Get cluster file name from application wrapper; 123, expression_statement; 124, identifier:ApplicationError; 125, block; 126, identifier:ApplicationNotFoundError; 127, block; 128, pattern_list; 129, line_continuation:\; 130, call; 131, identifier:save_uc_files; 132, expression_statement; 133, return_statement; 134, block; 135, call; 136, augmented_assignment; 137, assignment; 138, expression_statement; 139, not_operator; 140, comment:# Sort fasta input file from largest to smallest sequence; 141, block; 142, else_clause; 143, assignment; 144, call; 145, expression_statement; 146, raise_statement; 147, expression_statement; 148, raise_statement; 149, identifier:clusters; 150, identifier:failures; 151, identifier:seeds; 152, identifier:clusters_from_uc_file; 153, argument_list; 154, call; 155, expression_list; 156, return_statement; 157, attribute; 158, argument_list; 159, identifier:output_dir; 160, string; 161, identifier:uc_save_filepath; 162, call; 163, assignment; 164, identifier:suppress_sort; 165, expression_statement; 166, comment:# Get sorted fasta name from application wrapper; 167, expression_statement; 168, expression_statement; 169, block; 170, identifier:uclust_cluster; 171, call; 172, identifier:remove_files; 173, argument_list; 174, call; 175, call; 176, call; 177, call; 178, subscript; 179, attribute; 180, argument_list; 181, identifier:clusters; 182, identifier:failures; 183, identifier:seeds; 184, expression_list; 185, identifier:output_dir; 186, identifier:endswith; 187, string; 188, string_content:/; 189, identifier:get_output_filepaths; 190, argument_list; 191, identifier:uc_save_filepath; 192, None; 193, assignment; 194, assignment; 195, call; 196, expression_statement; 197, expression_statement; 198, identifier:uclust_cluster_from_sorted_fasta_filepath; 199, argument_list; 200, identifier:files_to_remove; 201, identifier:remove_files; 202, argument_list; 203, identifier:ApplicationError; 204, argument_list; 205, identifier:remove_files; 206, argument_list; 207, identifier:ApplicationNotFoundError; 208, argument_list; 209, identifier:uclust_cluster; 210, string; 211, identifier:uclust_cluster; 212, identifier:cleanUp; 213, call; 214, identifier:failures; 215, identifier:seeds; 216, string_content:/; 217, identifier:output_dir; 218, identifier:original_fasta_path; 219, identifier:sort_fasta; 220, call; 221, identifier:sorted_fasta_filepath; 222, attribute; 223, attribute; 224, argument_list; 225, assignment; 226, assignment; 227, identifier:sorted_fasta_filepath; 228, identifier:uc_save_filepath; 229, keyword_argument; 230, keyword_argument; 231, keyword_argument; 232, keyword_argument; 233, keyword_argument; 234, keyword_argument; 235, keyword_argument; 236, keyword_argument; 237, keyword_argument; 238, keyword_argument; 239, keyword_argument; 240, keyword_argument; 241, keyword_argument; 242, keyword_argument; 243, identifier:files_to_remove; 244, concatenated_string; 245, identifier:files_to_remove; 246, binary_operator:'uclust not found, is it properly ' + 'installed?'; 247, string_content:ClusterFile; 248, attribute; 249, argument_list; 250, identifier:uclust_fasta_sort_from_filepath; 251, argument_list; 252, subscript; 253, identifier:name; 254, identifier:files_to_remove; 255, identifier:append; 256, identifier:sorted_fasta_filepath; 257, identifier:sort_fasta; 258, None; 259, identifier:sorted_fasta_filepath; 260, identifier:fasta_filepath; 261, identifier:percent_ID; 262, identifier:percent_ID; 263, identifier:max_accepts; 264, identifier:max_accepts; 265, identifier:max_rejects; 266, identifier:max_rejects; 267, identifier:stepwords; 268, identifier:stepwords; 269, identifier:word_length; 270, identifier:word_length; 271, identifier:optimal; 272, identifier:optimal; 273, identifier:exact; 274, identifier:exact; 275, identifier:suppress_sort; 276, identifier:suppress_sort; 277, identifier:enable_rev_strand_matching; 278, identifier:enable_rev_strand_matching; 279, identifier:subject_fasta_filepath; 280, identifier:subject_fasta_filepath; 281, identifier:suppress_new_clusters; 282, identifier:suppress_new_clusters; 283, identifier:stable_sort; 284, identifier:stable_sort; 285, identifier:tmp_dir; 286, identifier:tmp_dir; 287, identifier:HALT_EXEC; 288, identifier:HALT_EXEC; 289, string; 290, string; 291, string; 292, string; 293, string; 294, identifier:clusters; 295, identifier:values; 296, identifier:fasta_filepath; 297, keyword_argument; 298, identifier:sort_fasta; 299, string; 300, string_content:Error running uclust. Possible causes are; 301, string_content:unsupported version (current supported version is v1.2.22) is installed or; 302, string_content:improperly formatted input file was provided; 303, string_content:uclust not found, is it properly; 304, string_content:installed?; 305, identifier:output_filepath; 306, identifier:fasta_output_filepath; 307, string_content:Output
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 16; 3, 17; 3, 18; 3, 19; 3, 20; 3, 21; 3, 22; 3, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 4, 31; 4, 32; 4, 33; 4, 34; 4, 35; 4, 36; 4, 37; 4, 38; 4, 39; 4, 40; 4, 41; 7, 42; 7, 43; 8, 44; 8, 45; 9, 46; 9, 47; 10, 48; 10, 49; 11, 50; 11, 51; 12, 52; 12, 53; 13, 54; 13, 55; 14, 56; 14, 57; 15, 58; 15, 59; 16, 60; 16, 61; 17, 62; 17, 63; 18, 64; 18, 65; 19, 66; 19, 67; 20, 68; 20, 69; 21, 70; 21, 71; 22, 72; 22, 73; 23, 74; 23, 75; 24, 76; 26, 77; 27, 78; 28, 79; 29, 80; 29, 81; 30, 82; 30, 83; 30, 84; 31, 85; 32, 86; 33, 87; 35, 88; 36, 89; 36, 90; 36, 91; 38, 92; 40, 93; 40, 94; 41, 95; 41, 96; 41, 97; 71, 98; 71, 99; 77, 100; 77, 101; 78, 102; 78, 103; 79, 104; 79, 105; 80, 106; 80, 107; 81, 108; 83, 109; 84, 110; 85, 111; 85, 112; 86, 113; 86, 114; 87, 115; 87, 116; 88, 117; 88, 118; 89, 119; 89, 120; 89, 121; 89, 122; 89, 123; 90, 124; 90, 125; 91, 126; 91, 127; 92, 128; 92, 129; 92, 130; 93, 131; 94, 132; 96, 133; 97, 134; 107, 135; 108, 136; 109, 137; 110, 138; 119, 139; 119, 140; 119, 141; 119, 142; 121, 143; 123, 144; 125, 145; 125, 146; 127, 147; 127, 148; 128, 149; 128, 150; 128, 151; 130, 152; 130, 153; 132, 154; 133, 155; 134, 156; 135, 157; 135, 158; 136, 159; 136, 160; 137, 161; 137, 162; 138, 163; 139, 164; 141, 165; 141, 166; 141, 167; 141, 168; 142, 169; 143, 170; 143, 171; 144, 172; 144, 173; 145, 174; 146, 175; 147, 176; 148, 177; 153, 178; 154, 179; 154, 180; 155, 181; 155, 182; 155, 183; 156, 184; 157, 185; 157, 186; 158, 187; 160, 188; 162, 189; 162, 190; 163, 191; 163, 192; 165, 193; 167, 194; 168, 195; 169, 196; 169, 197; 171, 198; 171, 199; 173, 200; 174, 201; 174, 202; 175, 203; 175, 204; 176, 205; 176, 206; 177, 207; 177, 208; 178, 209; 178, 210; 179, 211; 179, 212; 184, 213; 184, 214; 184, 215; 187, 216; 190, 217; 190, 218; 193, 219; 193, 220; 194, 221; 194, 222; 195, 223; 195, 224; 196, 225; 197, 226; 199, 227; 199, 228; 199, 229; 199, 230; 199, 231; 199, 232; 199, 233; 199, 234; 199, 235; 199, 236; 199, 237; 199, 238; 199, 239; 199, 240; 199, 241; 199, 242; 202, 243; 204, 244; 206, 245; 208, 246; 210, 247; 213, 248; 213, 249; 220, 250; 220, 251; 222, 252; 222, 253; 223, 254; 223, 255; 224, 256; 225, 257; 225, 258; 226, 259; 226, 260; 229, 261; 229, 262; 230, 263; 230, 264; 231, 265; 231, 266; 232, 267; 232, 268; 233, 269; 233, 270; 234, 271; 234, 272; 235, 273; 235, 274; 236, 275; 236, 276; 237, 277; 237, 278; 238, 279; 238, 280; 239, 281; 239, 282; 240, 283; 240, 284; 241, 285; 241, 286; 242, 287; 242, 288; 244, 289; 244, 290; 244, 291; 246, 292; 246, 293; 248, 294; 248, 295; 251, 296; 251, 297; 252, 298; 252, 299; 289, 300; 290, 301; 291, 302; 292, 303; 293, 304; 297, 305; 297, 306; 299, 307
def get_clusters_from_fasta_filepath( fasta_filepath, original_fasta_path, percent_ID=0.97, max_accepts=1, max_rejects=8, stepwords=8, word_length=8, optimal=False, exact=False, suppress_sort=False, output_dir=None, enable_rev_strand_matching=False, subject_fasta_filepath=None, suppress_new_clusters=False, return_cluster_maps=False, stable_sort=False, tmp_dir=gettempdir(), save_uc_files=True, HALT_EXEC=False): """ Main convenience wrapper for using uclust to generate cluster files A source fasta file is required for the fasta_filepath. This will be sorted to be in order of longest to shortest length sequences. Following this, the sorted fasta file is used to generate a cluster file in the uclust (.uc) format. Next the .uc file is converted to cd-hit format (.clstr). Finally this file is parsed and returned as a list of lists, where each sublist a cluster of sequences. If an output_dir is specified, the intermediate files will be preserved, otherwise all files created are temporary and will be deleted at the end of this function The percent_ID parameter specifies the percent identity for a clusters, i.e., if 99% were the parameter, all sequences that were 99% identical would be grouped as a cluster. """ # Create readable intermediate filenames if they are to be kept fasta_output_filepath = None uc_output_filepath = None cd_hit_filepath = None if output_dir and not output_dir.endswith('/'): output_dir += '/' if save_uc_files: uc_save_filepath = get_output_filepaths( output_dir, original_fasta_path) else: uc_save_filepath = None sorted_fasta_filepath = "" uc_filepath = "" clstr_filepath = "" # Error check in case any app controller fails files_to_remove = [] try: if not suppress_sort: # Sort fasta input file from largest to smallest sequence sort_fasta = uclust_fasta_sort_from_filepath(fasta_filepath, output_filepath=fasta_output_filepath) # Get sorted fasta name from application wrapper sorted_fasta_filepath = sort_fasta['Output'].name files_to_remove.append(sorted_fasta_filepath) else: sort_fasta = None sorted_fasta_filepath = fasta_filepath # Generate uclust cluster file (.uc format) uclust_cluster = uclust_cluster_from_sorted_fasta_filepath( sorted_fasta_filepath, uc_save_filepath, percent_ID=percent_ID, max_accepts=max_accepts, max_rejects=max_rejects, stepwords=stepwords, word_length=word_length, optimal=optimal, exact=exact, suppress_sort=suppress_sort, enable_rev_strand_matching=enable_rev_strand_matching, subject_fasta_filepath=subject_fasta_filepath, suppress_new_clusters=suppress_new_clusters, stable_sort=stable_sort, tmp_dir=tmp_dir, HALT_EXEC=HALT_EXEC) # Get cluster file name from application wrapper remove_files(files_to_remove) except ApplicationError: remove_files(files_to_remove) raise ApplicationError('Error running uclust. Possible causes are ' 'unsupported version (current supported version is v1.2.22) is installed or ' 'improperly formatted input file was provided') except ApplicationNotFoundError: remove_files(files_to_remove) raise ApplicationNotFoundError('uclust not found, is it properly ' + 'installed?') # Get list of lists for each cluster clusters, failures, seeds = \ clusters_from_uc_file(uclust_cluster['ClusterFile']) # Remove temp files unless user specifies output filepath if not save_uc_files: uclust_cluster.cleanUp() if return_cluster_maps: return clusters, failures, seeds else: return clusters.values(), failures, seeds
0, module; 1, function_definition; 2, function_name:ls; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, return_statement; 12, identifier:startswith; 13, None; 14, string:''' List all cubes available to the calling client. :param startswith: string to use in a simple "startswith" query filter :returns list: sorted list of cube names '''; 15, call; 16, assignment; 17, assignment; 18, identifier:tables; 19, attribute; 20, argument_list; 21, identifier:startswith; 22, call; 23, identifier:tables; 24, call; 25, identifier:logger; 26, identifier:info; 27, binary_operator:'Listing cubes starting with "%s")' % startswith; 28, identifier:unicode; 29, argument_list; 30, identifier:sorted; 31, generator_expression; 32, string:'Listing cubes starting with "%s")'; 33, identifier:startswith; 34, boolean_operator; 35, identifier:name; 36, for_in_clause; 37, if_clause; 38, identifier:startswith; 39, string; 40, identifier:name; 41, attribute; 42, call; 43, identifier:self; 44, identifier:db_tables; 45, attribute; 46, argument_list; 47, identifier:name; 48, identifier:startswith; 49, identifier:startswith
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 4, 7; 4, 8; 4, 9; 4, 10; 4, 11; 6, 12; 6, 13; 7, 14; 8, 15; 9, 16; 10, 17; 11, 18; 15, 19; 15, 20; 16, 21; 16, 22; 17, 23; 17, 24; 19, 25; 19, 26; 20, 27; 22, 28; 22, 29; 24, 30; 24, 31; 27, 32; 27, 33; 29, 34; 31, 35; 31, 36; 31, 37; 34, 38; 34, 39; 36, 40; 36, 41; 37, 42; 41, 43; 41, 44; 42, 45; 42, 46; 45, 47; 45, 48; 46, 49
def ls(self, startswith=None): ''' List all cubes available to the calling client. :param startswith: string to use in a simple "startswith" query filter :returns list: sorted list of cube names ''' logger.info('Listing cubes starting with "%s")' % startswith) startswith = unicode(startswith or '') tables = sorted(name for name in self.db_tables if name.startswith(startswith)) return tables
0, module; 1, function_definition; 2, function_name:usearch_sort_by_abundance; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, expression_statement; 17, if_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, if_statement; 22, if_statement; 23, if_statement; 24, if_statement; 25, expression_statement; 26, if_statement; 27, comment:# Can have no data following this filter step, which will raise an; 28, comment:# application error, try to catch it here to raise meaningful message.; 29, try_statement; 30, return_statement; 31, identifier:output_filepath; 32, None; 33, identifier:sizein; 34, True; 35, identifier:sizeout; 36, True; 37, identifier:minsize; 38, integer:0; 39, identifier:log_name; 40, string:"abundance_sort.log"; 41, identifier:usersort; 42, False; 43, identifier:HALT_EXEC; 44, False; 45, identifier:save_intermediate_files; 46, False; 47, identifier:remove_usearch_logs; 48, False; 49, identifier:working_dir; 50, None; 51, comment:""" Sorts fasta file by abundance fasta_filepath = input fasta file, generally a dereplicated fasta output_filepath = output abundance sorted fasta filepath sizein = not defined in usearch helpstring sizeout = not defined in usearch helpstring minsize = minimum size of cluster to retain. log_name = string to specify log filename usersort = Use if not sorting by abundance or usearch will raise an error HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """; 52, not_operator; 53, block; 54, assignment; 55, assignment; 56, assignment; 57, identifier:usersort; 58, block; 59, identifier:minsize; 60, block; 61, identifier:sizein; 62, block; 63, identifier:sizeout; 64, block; 65, assignment; 66, not_operator; 67, block; 68, block; 69, except_clause; 70, expression_list; 71, identifier:output_filepath; 72, expression_statement; 73, identifier:log_filepath; 74, call; 75, identifier:params; 76, dictionary; 77, identifier:app; 78, call; 79, expression_statement; 80, expression_statement; 81, expression_statement; 82, expression_statement; 83, identifier:data; 84, dictionary; 85, identifier:remove_usearch_logs; 86, expression_statement; 87, expression_statement; 88, identifier:ApplicationError; 89, block; 90, identifier:app_result; 91, identifier:output_filepath; 92, assignment; 93, identifier:join; 94, argument_list; 95, identifier:Usearch; 96, argument_list; 97, call; 98, call; 99, call; 100, call; 101, pair; 102, pair; 103, assignment; 104, assignment; 105, raise_statement; 106, pattern_list; 107, call; 108, identifier:working_dir; 109, binary_operator:"minsize_" + str(minsize) + "_" + log_name; 110, identifier:params; 111, keyword_argument; 112, keyword_argument; 113, attribute; 114, argument_list; 115, attribute; 116, argument_list; 117, attribute; 118, argument_list; 119, attribute; 120, argument_list; 121, string; 122, identifier:fasta_filepath; 123, string; 124, identifier:output_filepath; 125, subscript; 126, identifier:log_filepath; 127, identifier:app_result; 128, call; 129, call; 130, identifier:_; 131, identifier:output_filepath; 132, identifier:mkstemp; 133, argument_list; 134, binary_operator:"minsize_" + str(minsize) + "_"; 135, identifier:log_name; 136, identifier:WorkingDir; 137, identifier:working_dir; 138, identifier:HALT_EXEC; 139, identifier:HALT_EXEC; 140, subscript; 141, identifier:on; 142, subscript; 143, identifier:on; 144, identifier:minsize; 145, subscript; 146, identifier:on; 147, subscript; 148, identifier:on; 149, string_content:--sortsize; 150, string_content:--output; 151, identifier:data; 152, string; 153, identifier:app; 154, argument_list; 155, identifier:ValueError; 156, argument_list; 157, keyword_argument; 158, keyword_argument; 159, binary_operator:"minsize_" + str(minsize); 160, string:"_"; 161, attribute; 162, string; 163, attribute; 164, string; 165, attribute; 166, string; 167, attribute; 168, string; 169, string_content:--log; 170, identifier:data; 171, binary_operator:'No data following filter steps, please check ' + 'parameter settings for usearch_qf.'; 172, identifier:prefix; 173, string; 174, identifier:suffix; 175, string; 176, string:"minsize_"; 177, call; 178, identifier:app; 179, identifier:Parameters; 180, string_content:--usersort; 181, identifier:app; 182, identifier:Parameters; 183, string_content:--minsize; 184, identifier:app; 185, identifier:Parameters; 186, string_content:--sizein; 187, identifier:app; 188, identifier:Parameters; 189, string_content:--sizeout; 190, string; 191, string; 192, string_content:usearch_abundance_sorted; 193, string_content:.fasta; 194, identifier:str; 195, argument_list; 196, string_content:No data following filter steps, please check; 197, string_content:parameter settings for usearch_qf.; 198, identifier:minsize
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 4, 16; 4, 17; 4, 18; 4, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 6, 31; 6, 32; 7, 33; 7, 34; 8, 35; 8, 36; 9, 37; 9, 38; 10, 39; 10, 40; 11, 41; 11, 42; 12, 43; 12, 44; 13, 45; 13, 46; 14, 47; 14, 48; 15, 49; 15, 50; 16, 51; 17, 52; 17, 53; 18, 54; 19, 55; 20, 56; 21, 57; 21, 58; 22, 59; 22, 60; 23, 61; 23, 62; 24, 63; 24, 64; 25, 65; 26, 66; 26, 67; 29, 68; 29, 69; 30, 70; 52, 71; 53, 72; 54, 73; 54, 74; 55, 75; 55, 76; 56, 77; 56, 78; 58, 79; 60, 80; 62, 81; 64, 82; 65, 83; 65, 84; 66, 85; 67, 86; 68, 87; 69, 88; 69, 89; 70, 90; 70, 91; 72, 92; 74, 93; 74, 94; 78, 95; 78, 96; 79, 97; 80, 98; 81, 99; 82, 100; 84, 101; 84, 102; 86, 103; 87, 104; 89, 105; 92, 106; 92, 107; 94, 108; 94, 109; 96, 110; 96, 111; 96, 112; 97, 113; 97, 114; 98, 115; 98, 116; 99, 117; 99, 118; 100, 119; 100, 120; 101, 121; 101, 122; 102, 123; 102, 124; 103, 125; 103, 126; 104, 127; 104, 128; 105, 129; 106, 130; 106, 131; 107, 132; 107, 133; 109, 134; 109, 135; 111, 136; 111, 137; 112, 138; 112, 139; 113, 140; 113, 141; 115, 142; 115, 143; 116, 144; 117, 145; 117, 146; 119, 147; 119, 148; 121, 149; 123, 150; 125, 151; 125, 152; 128, 153; 128, 154; 129, 155; 129, 156; 133, 157; 133, 158; 134, 159; 134, 160; 140, 161; 140, 162; 142, 163; 142, 164; 145, 165; 145, 166; 147, 167; 147, 168; 152, 169; 154, 170; 156, 171; 157, 172; 157, 173; 158, 174; 158, 175; 159, 176; 159, 177; 161, 178; 161, 179; 162, 180; 163, 181; 163, 182; 164, 183; 165, 184; 165, 185; 166, 186; 167, 187; 167, 188; 168, 189; 171, 190; 171, 191; 173, 192; 175, 193; 177, 194; 177, 195; 190, 196; 191, 197; 195, 198
def usearch_sort_by_abundance( fasta_filepath, output_filepath=None, sizein=True, sizeout=True, minsize=0, log_name="abundance_sort.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): """ Sorts fasta file by abundance fasta_filepath = input fasta file, generally a dereplicated fasta output_filepath = output abundance sorted fasta filepath sizein = not defined in usearch helpstring sizeout = not defined in usearch helpstring minsize = minimum size of cluster to retain. log_name = string to specify log filename usersort = Use if not sorting by abundance or usearch will raise an error HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """ if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_abundance_sorted', suffix='.fasta') log_filepath = join( working_dir, "minsize_" + str(minsize) + "_" + log_name) params = {} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() if minsize: app.Parameters['--minsize'].on(minsize) if sizein: app.Parameters['--sizein'].on() if sizeout: app.Parameters['--sizeout'].on() data = {'--sortsize': fasta_filepath, '--output': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath # Can have no data following this filter step, which will raise an # application error, try to catch it here to raise meaningful message. try: app_result = app(data) except ApplicationError: raise ValueError('No data following filter steps, please check ' + 'parameter settings for usearch_qf.') return app_result, output_filepath
0, module; 1, function_definition; 2, function_name:usearch_cluster_error_correction; 3, parameters; 4, block; 5, identifier:fasta_filepath; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, expression_statement; 21, if_statement; 22, expression_statement; 23, expression_statement; 24, expression_statement; 25, if_statement; 26, expression_statement; 27, if_statement; 28, if_statement; 29, expression_statement; 30, return_statement; 31, identifier:output_filepath; 32, None; 33, identifier:output_uc_filepath; 34, None; 35, identifier:percent_id_err; 36, float:0.97; 37, identifier:sizein; 38, True; 39, identifier:sizeout; 40, True; 41, identifier:w; 42, integer:64; 43, identifier:slots; 44, integer:16769023; 45, identifier:maxrejects; 46, integer:64; 47, identifier:log_name; 48, string:"usearch_cluster_err_corrected.log"; 49, identifier:usersort; 50, False; 51, identifier:HALT_EXEC; 52, False; 53, identifier:save_intermediate_files; 54, False; 55, identifier:remove_usearch_logs; 56, False; 57, identifier:working_dir; 58, None; 59, comment:""" Cluster for err. correction at percent_id_err, output consensus fasta fasta_filepath = input fasta file, generally a dereplicated fasta output_filepath = output error corrected fasta filepath percent_id_err = minimum identity percent. sizein = not defined in usearch helpstring sizeout = not defined in usearch helpstring w = Word length for U-sorting slots = Size of compressed index table. Should be prime, e.g. 40000003. Should also specify --w, typical is --w 16 or --w 32. maxrejects = Max rejected targets, 0=ignore, default 32. log_name = string specifying output log name usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """; 60, not_operator; 61, block; 62, assignment; 63, assignment; 64, assignment; 65, identifier:usersort; 66, block; 67, assignment; 68, not_operator; 69, block; 70, identifier:output_uc_filepath; 71, block; 72, assignment; 73, expression_list; 74, identifier:output_filepath; 75, expression_statement; 76, identifier:log_filepath; 77, call; 78, identifier:params; 79, dictionary; 80, identifier:app; 81, call; 82, expression_statement; 83, identifier:data; 84, dictionary; 85, identifier:remove_usearch_logs; 86, expression_statement; 87, expression_statement; 88, identifier:app_result; 89, call; 90, identifier:app_result; 91, identifier:output_filepath; 92, assignment; 93, identifier:join; 94, argument_list; 95, pair; 96, pair; 97, pair; 98, pair; 99, pair; 100, pair; 101, identifier:Usearch; 102, argument_list; 103, call; 104, pair; 105, pair; 106, assignment; 107, assignment; 108, identifier:app; 109, argument_list; 110, pattern_list; 111, call; 112, identifier:working_dir; 113, identifier:log_name; 114, string; 115, identifier:sizein; 116, string; 117, identifier:sizeout; 118, string; 119, identifier:percent_id_err; 120, string; 121, identifier:w; 122, string; 123, identifier:slots; 124, string; 125, identifier:maxrejects; 126, identifier:params; 127, keyword_argument; 128, keyword_argument; 129, attribute; 130, argument_list; 131, string; 132, identifier:fasta_filepath; 133, string; 134, identifier:output_filepath; 135, subscript; 136, identifier:log_filepath; 137, subscript; 138, identifier:output_uc_filepath; 139, identifier:data; 140, identifier:_; 141, identifier:output_filepath; 142, identifier:mkstemp; 143, argument_list; 144, string_content:--sizein; 145, string_content:--sizeout; 146, string_content:--id; 147, string_content:--w; 148, string_content:--slots; 149, string_content:--maxrejects; 150, identifier:WorkingDir; 151, identifier:working_dir; 152, identifier:HALT_EXEC; 153, identifier:HALT_EXEC; 154, subscript; 155, identifier:on; 156, string_content:--cluster; 157, string_content:--consout; 158, identifier:data; 159, string; 160, identifier:data; 161, string; 162, keyword_argument; 163, keyword_argument; 164, attribute; 165, string; 166, string_content:--log; 167, string_content:--uc; 168, identifier:prefix; 169, string; 170, identifier:suffix; 171, string; 172, identifier:app; 173, identifier:Parameters; 174, string_content:--usersort; 175, string_content:usearch_cluster_err_corrected; 176, string_content:.fasta
0, 1; 1, 2; 1, 3; 1, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 16; 3, 17; 3, 18; 3, 19; 4, 20; 4, 21; 4, 22; 4, 23; 4, 24; 4, 25; 4, 26; 4, 27; 4, 28; 4, 29; 4, 30; 6, 31; 6, 32; 7, 33; 7, 34; 8, 35; 8, 36; 9, 37; 9, 38; 10, 39; 10, 40; 11, 41; 11, 42; 12, 43; 12, 44; 13, 45; 13, 46; 14, 47; 14, 48; 15, 49; 15, 50; 16, 51; 16, 52; 17, 53; 17, 54; 18, 55; 18, 56; 19, 57; 19, 58; 20, 59; 21, 60; 21, 61; 22, 62; 23, 63; 24, 64; 25, 65; 25, 66; 26, 67; 27, 68; 27, 69; 28, 70; 28, 71; 29, 72; 30, 73; 60, 74; 61, 75; 62, 76; 62, 77; 63, 78; 63, 79; 64, 80; 64, 81; 66, 82; 67, 83; 67, 84; 68, 85; 69, 86; 71, 87; 72, 88; 72, 89; 73, 90; 73, 91; 75, 92; 77, 93; 77, 94; 79, 95; 79, 96; 79, 97; 79, 98; 79, 99; 79, 100; 81, 101; 81, 102; 82, 103; 84, 104; 84, 105; 86, 106; 87, 107; 89, 108; 89, 109; 92, 110; 92, 111; 94, 112; 94, 113; 95, 114; 95, 115; 96, 116; 96, 117; 97, 118; 97, 119; 98, 120; 98, 121; 99, 122; 99, 123; 100, 124; 100, 125; 102, 126; 102, 127; 102, 128; 103, 129; 103, 130; 104, 131; 104, 132; 105, 133; 105, 134; 106, 135; 106, 136; 107, 137; 107, 138; 109, 139; 110, 140; 110, 141; 111, 142; 111, 143; 114, 144; 116, 145; 118, 146; 120, 147; 122, 148; 124, 149; 127, 150; 127, 151; 128, 152; 128, 153; 129, 154; 129, 155; 131, 156; 133, 157; 135, 158; 135, 159; 137, 160; 137, 161; 143, 162; 143, 163; 154, 164; 154, 165; 159, 166; 161, 167; 162, 168; 162, 169; 163, 170; 163, 171; 164, 172; 164, 173; 165, 174; 169, 175; 171, 176
def usearch_cluster_error_correction( fasta_filepath, output_filepath=None, output_uc_filepath=None, percent_id_err=0.97, sizein=True, sizeout=True, w=64, slots=16769023, maxrejects=64, log_name="usearch_cluster_err_corrected.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): """ Cluster for err. correction at percent_id_err, output consensus fasta fasta_filepath = input fasta file, generally a dereplicated fasta output_filepath = output error corrected fasta filepath percent_id_err = minimum identity percent. sizein = not defined in usearch helpstring sizeout = not defined in usearch helpstring w = Word length for U-sorting slots = Size of compressed index table. Should be prime, e.g. 40000003. Should also specify --w, typical is --w 16 or --w 32. maxrejects = Max rejected targets, 0=ignore, default 32. log_name = string specifying output log name usersort = Enable if input fasta not sorted by length purposefully, lest usearch will raise an error. HALT_EXEC: Used for debugging app controller save_intermediate_files: Preserve all intermediate files created. """ if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_cluster_err_corrected', suffix='.fasta') log_filepath = join(working_dir, log_name) params = {'--sizein': sizein, '--sizeout': sizeout, '--id': percent_id_err, '--w': w, '--slots': slots, '--maxrejects': maxrejects} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() data = {'--cluster': fasta_filepath, '--consout': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath if output_uc_filepath: data['--uc'] = output_uc_filepath app_result = app(data) return app_result, output_filepath