sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_findRedundantProteins; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:protToPeps; 5, identifier:pepToProts; 6, default_parameter; 6, 7; 6, 8; 7, identifier:proteins; 8, None; 9, block; 9, 10; 9, 22; 9, 29; 9, 36; 9, 45; 9, 54; 9, 60; 9, 91; 9, 97; 9, 168; 9, 185; 9, 191; 9, 234; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:proteins; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:proteins; 18, call; 18, 19; 18, 20; 19, identifier:viewkeys; 20, argument_list; 20, 21; 21, identifier:protToPeps; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:pepFrequency; 25, call; 25, 26; 25, 27; 26, identifier:_getValueCounts; 27, argument_list; 27, 28; 28, identifier:pepToProts; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:protPepCounts; 32, call; 32, 33; 32, 34; 33, identifier:_getValueCounts; 34, argument_list; 34, 35; 35, identifier:protToPeps; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:getCount; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:operator; 42, identifier:itemgetter; 43, argument_list; 43, 44; 44, integer:1; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:getProt; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:operator; 51, identifier:itemgetter; 52, argument_list; 52, 53; 53, integer:0; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:proteinTuples; 57, call; 57, 58; 57, 59; 58, identifier:list; 59, argument_list; 60, for_statement; 60, 61; 60, 62; 60, 63; 61, identifier:protein; 62, identifier:proteins; 63, block; 63, 64; 64, if_statement; 64, 65; 64, 70; 64, 78; 65, call; 65, 66; 65, 67; 66, identifier:isinstance; 67, argument_list; 67, 68; 67, 69; 68, identifier:protein; 69, identifier:tuple; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:proteinTuples; 75, identifier:append; 76, argument_list; 76, 77; 77, identifier:protein; 78, else_clause; 78, 79; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:proteinTuples; 84, identifier:append; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:tuple; 88, argument_list; 88, 89; 89, list:[protein]; 89, 90; 90, identifier:protein; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:sort; 94, call; 94, 95; 94, 96; 95, identifier:list; 96, argument_list; 97, for_statement; 97, 98; 97, 99; 97, 106; 98, identifier:protein; 99, call; 99, 100; 99, 101; 100, identifier:sorted; 101, argument_list; 101, 102; 101, 103; 102, identifier:proteinTuples; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:reverse; 105, True; 106, block; 106, 107; 106, 121; 106, 133; 107, if_statement; 107, 108; 107, 114; 108, comparison_operator:==; 108, 109; 108, 113; 109, call; 109, 110; 109, 111; 110, identifier:len; 111, argument_list; 111, 112; 112, identifier:protein; 113, integer:1; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:protein; 118, subscript; 118, 119; 118, 120; 119, identifier:protein; 120, integer:0; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:protPepFreq; 124, list_comprehension; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:pepFrequency; 127, identifier:pep; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:pep; 130, subscript; 130, 131; 130, 132; 131, identifier:protToPeps; 132, identifier:protein; 133, if_statement; 133, 134; 133, 140; 134, comparison_operator:>; 134, 135; 134, 139; 135, call; 135, 136; 135, 137; 136, identifier:min; 137, argument_list; 137, 138; 138, identifier:protPepFreq; 139, integer:1; 140, block; 140, 141; 140, 159; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:sortValue; 144, tuple; 144, 145; 144, 152; 145, binary_operator:*; 145, 146; 145, 150; 146, call; 146, 147; 146, 148; 147, identifier:len; 148, argument_list; 148, 149; 149, identifier:protPepFreq; 150, unary_operator:-; 150, 151; 151, integer:1; 152, call; 152, 153; 152, 154; 153, identifier:sorted; 154, argument_list; 154, 155; 154, 156; 155, identifier:protPepFreq; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:reverse; 158, True; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:sort; 163, identifier:append; 164, argument_list; 164, 165; 165, tuple; 165, 166; 165, 167; 166, identifier:protein; 167, identifier:sortValue; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:sortedProteins; 171, call; 171, 172; 171, 173; 172, identifier:map; 173, argument_list; 173, 174; 173, 175; 174, identifier:getProt; 175, call; 175, 176; 175, 177; 176, identifier:sorted; 177, argument_list; 177, 178; 177, 179; 177, 182; 178, identifier:sort; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:key; 181, identifier:getCount; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:reverse; 184, True; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:redundantProteins; 188, call; 188, 189; 188, 190; 189, identifier:set; 190, argument_list; 191, for_statement; 191, 192; 191, 193; 191, 194; 192, identifier:protein; 193, identifier:sortedProteins; 194, block; 194, 195; 195, for_statement; 195, 196; 195, 197; 195, 200; 195, 209; 196, identifier:pep; 197, subscript; 197, 198; 197, 199; 198, identifier:protToPeps; 199, identifier:protein; 200, block; 200, 201; 201, if_statement; 201, 202; 201, 207; 202, comparison_operator:<=; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:pepFrequency; 205, identifier:pep; 206, integer:1; 207, block; 207, 208; 208, break_statement; 209, else_clause; 209, 210; 210, block; 210, 211; 210, 220; 210, 227; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:protPepFrequency; 214, call; 214, 215; 214, 216; 215, identifier:Counter; 216, argument_list; 216, 217; 217, subscript; 217, 218; 217, 219; 218, identifier:protToPeps; 219, identifier:protein; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:pepFrequency; 224, identifier:subtract; 225, argument_list; 225, 226; 226, identifier:protPepFrequency; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:redundantProteins; 231, identifier:add; 232, argument_list; 232, 233; 233, identifier:protein; 234, return_statement; 234, 235; 235, identifier:redundantProteins | def _findRedundantProteins(protToPeps, pepToProts, proteins=None):
if proteins is None:
proteins = viewkeys(protToPeps)
pepFrequency = _getValueCounts(pepToProts)
protPepCounts = _getValueCounts(protToPeps)
getCount = operator.itemgetter(1)
getProt = operator.itemgetter(0)
proteinTuples = list()
for protein in proteins:
if isinstance(protein, tuple):
proteinTuples.append(protein)
else:
proteinTuples.append(tuple([protein]))
sort = list()
for protein in sorted(proteinTuples, reverse=True):
if len(protein) == 1:
protein = protein[0]
protPepFreq = [pepFrequency[pep] for pep in protToPeps[protein]]
if min(protPepFreq) > 1:
sortValue = (len(protPepFreq)*-1, sorted(protPepFreq, reverse=True))
sort.append((protein, sortValue))
sortedProteins = map(getProt, sorted(sort, key=getCount, reverse=True))
redundantProteins = set()
for protein in sortedProteins:
for pep in protToPeps[protein]:
if pepFrequency[pep] <= 1:
break
else:
protPepFrequency = Counter(protToPeps[protein])
pepFrequency.subtract(protPepFrequency)
redundantProteins.add(protein)
return redundantProteins |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_mergeProteinEntries; 3, parameters; 3, 4; 3, 5; 4, identifier:proteinLists; 5, identifier:protToPeps; 6, block; 6, 7; 6, 14; 6, 47; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:mergedProtToPeps; 10, call; 10, 11; 10, 12; 11, identifier:dict; 12, argument_list; 12, 13; 13, identifier:protToPeps; 14, for_statement; 14, 15; 14, 16; 14, 17; 15, identifier:proteins; 16, identifier:proteinLists; 17, block; 17, 18; 17, 31; 17, 41; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:protein; 20, identifier:proteins; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:peptides; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:mergedProtToPeps; 28, identifier:pop; 29, argument_list; 29, 30; 30, identifier:protein; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:mergedProtein; 34, call; 34, 35; 34, 36; 35, identifier:tuple; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:sorted; 39, argument_list; 39, 40; 40, identifier:proteins; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:mergedProtToPeps; 45, identifier:mergedProtein; 46, identifier:peptides; 47, return_statement; 47, 48; 48, identifier:mergedProtToPeps | def _mergeProteinEntries(proteinLists, protToPeps):
mergedProtToPeps = dict(protToPeps)
for proteins in proteinLists:
for protein in proteins:
peptides = mergedProtToPeps.pop(protein)
mergedProtein = tuple(sorted(proteins))
mergedProtToPeps[mergedProtein] = peptides
return mergedProtToPeps |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:foldername; 7, string:"INBOX"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:since; 13, None; 14, block; 14, 15; 14, 33; 14, 51; 14, 68; 14, 84; 14, 97; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:folder; 18, conditional_expression:if; 18, 19; 18, 22; 18, 23; 18, 26; 18, 27; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:folder; 22, line_continuation:\; 23, comparison_operator:==; 23, 24; 23, 25; 24, identifier:foldername; 25, string:"INBOX"; 26, line_continuation:\; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_getfolder; 31, argument_list; 31, 32; 32, identifier:foldername; 33, function_definition; 33, 34; 33, 35; 33, 37; 34, function_name:sortcmp; 35, parameters; 35, 36; 36, identifier:d; 37, block; 37, 38; 38, try_statement; 38, 39; 38, 46; 39, block; 39, 40; 40, return_statement; 40, 41; 41, attribute; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:d; 44, integer:1; 45, identifier:date; 46, except_clause; 46, 47; 47, block; 47, 48; 48, return_statement; 48, 49; 49, unary_operator:-; 49, 50; 50, integer:1; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:lst; 54, conditional_expression:if; 54, 55; 54, 60; 54, 62; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:folder; 58, identifier:items; 59, argument_list; 60, not_operator; 60, 61; 61, identifier:since; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:folder; 65, identifier:items_since; 66, argument_list; 66, 67; 67, identifier:since; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:sorted_lst; 71, call; 71, 72; 71, 73; 72, identifier:sorted; 73, argument_list; 73, 74; 73, 75; 73, 78; 74, identifier:lst; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:key; 77, identifier:sortcmp; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:reverse; 80, conditional_expression:if; 80, 81; 80, 82; 80, 83; 81, integer:1; 82, identifier:reverse; 83, integer:0; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:itemlist; 87, list_comprehension; 87, 88; 87, 92; 88, tuple; 88, 89; 88, 90; 88, 91; 89, identifier:folder; 90, identifier:key; 91, identifier:msg; 92, for_in_clause; 92, 93; 92, 96; 93, pattern_list; 93, 94; 93, 95; 94, identifier:key; 95, identifier:msg; 96, identifier:sorted_lst; 97, return_statement; 97, 98; 98, identifier:itemlist | def _list(self, foldername="INBOX", reverse=False, since=None):
folder = self.folder \
if foldername == "INBOX" \
else self._getfolder(foldername)
def sortcmp(d):
try:
return d[1].date
except:
return -1
lst = folder.items() if not since else folder.items_since(since)
sorted_lst = sorted(lst, key=sortcmp, reverse=1 if reverse else 0)
itemlist = [(folder, key, msg) for key,msg in sorted_lst]
return itemlist |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_entries; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 9, 13; 9, 18; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:data; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:key; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:sort_func; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:reverse; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:get_reverse; 24, argument_list | def sort_entries(self):
return sorted(self.data, key=self.sort_func, reverse=self.get_reverse()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:expectedLabelPosition; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:peptide; 5, identifier:labelStateInfo; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sequence; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:modPositions; 11, None; 12, block; 12, 13; 12, 32; 12, 48; 12, 54; 12, 136; 12, 217; 12, 238; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:modPositions; 16, None; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:modPositions; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:maspy; 25, identifier:peptidemethods; 26, identifier:returnModPositions; 27, argument_list; 27, 28; 27, 29; 28, identifier:peptide; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:indexStart; 31, integer:0; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:sequence; 35, None; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:sequence; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:maspy; 44, identifier:peptidemethods; 45, identifier:removeModifications; 46, argument_list; 46, 47; 47, identifier:peptide; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:currLabelMods; 51, call; 51, 52; 51, 53; 52, identifier:dict; 53, argument_list; 54, for_statement; 54, 55; 54, 58; 54, 64; 55, pattern_list; 55, 56; 55, 57; 56, identifier:labelPosition; 57, identifier:labelSymbols; 58, call; 58, 59; 58, 60; 59, identifier:viewitems; 60, argument_list; 60, 61; 61, subscript; 61, 62; 61, 63; 62, identifier:labelStateInfo; 63, string:'aminoAcidLabels'; 64, block; 64, 65; 64, 74; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:labelSymbols; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:aux; 71, identifier:toList; 72, argument_list; 72, 73; 73, identifier:labelSymbols; 74, if_statement; 74, 75; 74, 79; 74, 81; 74, 105; 75, comparison_operator:==; 75, 76; 75, 77; 76, identifier:labelSymbols; 77, list:['']; 77, 78; 78, string:''; 79, block; 79, 80; 80, pass_statement; 81, elif_clause; 81, 82; 81, 85; 82, comparison_operator:==; 82, 83; 82, 84; 83, identifier:labelPosition; 84, string:'nTerm'; 85, block; 85, 86; 85, 96; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:currLabelMods; 90, identifier:setdefault; 91, argument_list; 91, 92; 91, 93; 92, integer:0; 93, call; 93, 94; 93, 95; 94, identifier:list; 95, argument_list; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:currLabelMods; 101, integer:0; 102, identifier:extend; 103, argument_list; 103, 104; 104, identifier:labelSymbols; 105, else_clause; 105, 106; 106, block; 106, 107; 107, for_statement; 107, 108; 107, 109; 107, 116; 108, identifier:sequencePosition; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:aux; 112, identifier:findAllSubstrings; 113, argument_list; 113, 114; 113, 115; 114, identifier:sequence; 115, identifier:labelPosition; 116, block; 116, 117; 116, 127; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:currLabelMods; 121, identifier:setdefault; 122, argument_list; 122, 123; 122, 124; 123, identifier:sequencePosition; 124, call; 124, 125; 124, 126; 125, identifier:list; 126, argument_list; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:currLabelMods; 132, identifier:sequencePosition; 133, identifier:extend; 134, argument_list; 134, 135; 135, identifier:labelSymbols; 136, if_statement; 136, 137; 136, 142; 137, comparison_operator:is; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:labelStateInfo; 140, string:'excludingModifications'; 141, None; 142, block; 142, 143; 143, for_statement; 143, 144; 143, 147; 143, 153; 144, pattern_list; 144, 145; 144, 146; 145, identifier:excludingMod; 146, identifier:excludedLabelSymbol; 147, call; 147, 148; 147, 149; 148, identifier:viewitems; 149, argument_list; 149, 150; 150, subscript; 150, 151; 150, 152; 151, identifier:labelStateInfo; 152, string:'excludingModifications'; 153, block; 153, 154; 153, 160; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:not; 155, 156; 155, 157; 156, identifier:excludingMod; 157, identifier:modPositions; 158, block; 158, 159; 159, continue_statement; 160, for_statement; 160, 161; 160, 162; 160, 165; 161, identifier:excludingModPos; 162, subscript; 162, 163; 162, 164; 163, identifier:modPositions; 164, identifier:excludingMod; 165, block; 165, 166; 165, 172; 165, 180; 166, if_statement; 166, 167; 166, 170; 167, comparison_operator:not; 167, 168; 167, 169; 168, identifier:excludingModPos; 169, identifier:currLabelMods; 170, block; 170, 171; 171, continue_statement; 172, if_statement; 172, 173; 172, 178; 173, comparison_operator:not; 173, 174; 173, 175; 174, identifier:excludedLabelSymbol; 175, subscript; 175, 176; 175, 177; 176, identifier:currLabelMods; 177, identifier:excludingModPos; 178, block; 178, 179; 179, continue_statement; 180, if_statement; 180, 181; 180, 189; 180, 195; 181, comparison_operator:==; 181, 182; 181, 188; 182, call; 182, 183; 182, 184; 183, identifier:len; 184, argument_list; 184, 185; 185, subscript; 185, 186; 185, 187; 186, identifier:currLabelMods; 187, identifier:excludingModPos; 188, integer:1; 189, block; 189, 190; 190, delete_statement; 190, 191; 191, parenthesized_expression; 191, 192; 192, subscript; 192, 193; 192, 194; 193, identifier:currLabelMods; 194, identifier:excludingModPos; 195, else_clause; 195, 196; 196, block; 196, 197; 196, 208; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:excludedModIndex; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:currLabelMods; 204, identifier:excludingModPos; 205, identifier:index; 206, argument_list; 206, 207; 207, identifier:excludedLabelSymbol; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:currLabelMods; 213, identifier:excludingModPos; 214, identifier:pop; 215, argument_list; 215, 216; 216, identifier:excludedModIndex; 217, for_statement; 217, 218; 217, 219; 217, 226; 218, identifier:sequencePosition; 219, call; 219, 220; 219, 221; 220, identifier:list; 221, argument_list; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:viewkeys; 224, argument_list; 224, 225; 225, identifier:currLabelMods; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:currLabelMods; 231, identifier:sequencePosition; 232, call; 232, 233; 232, 234; 233, identifier:sorted; 234, argument_list; 234, 235; 235, subscript; 235, 236; 235, 237; 236, identifier:currLabelMods; 237, identifier:sequencePosition; 238, return_statement; 238, 239; 239, identifier:currLabelMods | def expectedLabelPosition(peptide, labelStateInfo, sequence=None,
modPositions=None):
if modPositions is None:
modPositions = maspy.peptidemethods.returnModPositions(peptide,
indexStart=0
)
if sequence is None:
sequence = maspy.peptidemethods.removeModifications(peptide)
currLabelMods = dict()
for labelPosition, labelSymbols in viewitems(labelStateInfo['aminoAcidLabels']):
labelSymbols = aux.toList(labelSymbols)
if labelSymbols == ['']:
pass
elif labelPosition == 'nTerm':
currLabelMods.setdefault(0, list())
currLabelMods[0].extend(labelSymbols)
else:
for sequencePosition in aux.findAllSubstrings(sequence,
labelPosition):
currLabelMods.setdefault(sequencePosition, list())
currLabelMods[sequencePosition].extend(labelSymbols)
if labelStateInfo['excludingModifications'] is not None:
for excludingMod, excludedLabelSymbol in viewitems(labelStateInfo['excludingModifications']):
if excludingMod not in modPositions:
continue
for excludingModPos in modPositions[excludingMod]:
if excludingModPos not in currLabelMods:
continue
if excludedLabelSymbol not in currLabelMods[excludingModPos]:
continue
if len(currLabelMods[excludingModPos]) == 1:
del(currLabelMods[excludingModPos])
else:
excludedModIndex = currLabelMods[excludingModPos].index(excludedLabelSymbol)
currLabelMods[excludingModPos].pop(excludedModIndex)
for sequencePosition in list(viewkeys(currLabelMods)):
currLabelMods[sequencePosition] = sorted(currLabelMods[sequencePosition])
return currLabelMods |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:rank; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:member; 6, block; 6, 7; 6, 29; 7, if_statement; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:reversed; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_client; 18, identifier:zrevrank; 19, argument_list; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:key_prefix; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_dumps; 27, argument_list; 27, 28; 28, identifier:member; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_client; 35, identifier:zrank; 36, argument_list; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:key_prefix; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_dumps; 44, argument_list; 44, 45; 45, identifier:member | def rank(self, member):
if self.reversed:
return self._client.zrevrank(self.key_prefix, self._dumps(member))
return self._client.zrank(self.key_prefix, self._dumps(member)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:prepareSiiImport; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:siiContainer; 5, identifier:specfile; 6, identifier:path; 7, identifier:qcAttr; 8, identifier:qcLargerBetter; 9, identifier:qcCutoff; 10, identifier:rankAttr; 11, identifier:rankLargerBetter; 12, block; 12, 13; 12, 35; 12, 45; 12, 55; 12, 65; 12, 75; 13, if_statement; 13, 14; 13, 19; 13, 28; 14, comparison_operator:not; 14, 15; 14, 16; 15, identifier:specfile; 16, attribute; 16, 17; 16, 18; 17, identifier:siiContainer; 18, identifier:info; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:siiContainer; 24, identifier:addSpecfile; 25, argument_list; 25, 26; 25, 27; 26, identifier:specfile; 27, identifier:path; 28, else_clause; 28, 29; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:Exception; 33, argument_list; 33, 34; 34, string:'...'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 44; 37, subscript; 37, 38; 37, 43; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:siiContainer; 41, identifier:info; 42, identifier:specfile; 43, string:'qcAttr'; 44, identifier:qcAttr; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 54; 47, subscript; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:siiContainer; 51, identifier:info; 52, identifier:specfile; 53, string:'qcLargerBetter'; 54, identifier:qcLargerBetter; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 64; 57, subscript; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:siiContainer; 61, identifier:info; 62, identifier:specfile; 63, string:'qcCutoff'; 64, identifier:qcCutoff; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 74; 67, subscript; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:siiContainer; 71, identifier:info; 72, identifier:specfile; 73, string:'rankAttr'; 74, identifier:rankAttr; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 84; 77, subscript; 77, 78; 77, 83; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:siiContainer; 81, identifier:info; 82, identifier:specfile; 83, string:'rankLargerBetter'; 84, identifier:rankLargerBetter | def prepareSiiImport(siiContainer, specfile, path, qcAttr, qcLargerBetter,
qcCutoff, rankAttr, rankLargerBetter):
if specfile not in siiContainer.info:
siiContainer.addSpecfile(specfile, path)
else:
raise Exception('...')
siiContainer.info[specfile]['qcAttr'] = qcAttr
siiContainer.info[specfile]['qcLargerBetter'] = qcLargerBetter
siiContainer.info[specfile]['qcCutoff'] = qcCutoff
siiContainer.info[specfile]['rankAttr'] = rankAttr
siiContainer.info[specfile]['rankLargerBetter'] = rankLargerBetter |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 14; 2, function_name:find_nearest; 3, parameters; 3, 4; 3, 5; 4, identifier:x; 5, identifier:x0; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Tuple; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:int; 12, type; 12, 13; 13, identifier:Any; 14, block; 14, 15; 14, 24; 14, 33; 14, 51; 14, 65; 14, 77; 14, 137; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:x; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:asanyarray; 22, argument_list; 22, 23; 23, identifier:x; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:x0; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:np; 30, identifier:atleast_1d; 31, argument_list; 31, 32; 32, identifier:x0; 33, if_statement; 33, 34; 33, 45; 34, boolean_operator:or; 34, 35; 34, 40; 35, comparison_operator:==; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:x; 38, identifier:size; 39, integer:0; 40, comparison_operator:==; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:x0; 43, identifier:size; 44, integer:0; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:ValueError; 49, argument_list; 49, 50; 50, string:'empty input(s)'; 51, if_statement; 51, 52; 51, 59; 52, comparison_operator:not; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:x0; 55, identifier:ndim; 56, tuple; 56, 57; 56, 58; 57, integer:0; 58, integer:1; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:ValueError; 63, argument_list; 63, 64; 64, string:'2-D x0 not handled yet'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:ind; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:np; 71, identifier:empty_like; 72, argument_list; 72, 73; 72, 74; 73, identifier:x0; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:dtype; 76, identifier:int; 77, for_statement; 77, 78; 77, 81; 77, 85; 78, pattern_list; 78, 79; 78, 80; 79, identifier:i; 80, identifier:xi; 81, call; 81, 82; 81, 83; 82, identifier:enumerate; 83, argument_list; 83, 84; 84, identifier:x0; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 113; 86, 130; 87, boolean_operator:and; 87, 88; 87, 91; 88, comparison_operator:is; 88, 89; 88, 90; 89, identifier:xi; 90, None; 91, parenthesized_expression; 91, 92; 92, boolean_operator:or; 92, 93; 92, 107; 93, call; 93, 94; 93, 95; 94, identifier:isinstance; 95, argument_list; 95, 96; 95, 97; 96, identifier:xi; 97, tuple; 97, 98; 97, 101; 97, 104; 98, attribute; 98, 99; 98, 100; 99, identifier:datetime; 100, identifier:datetime; 101, attribute; 101, 102; 101, 103; 102, identifier:datetime; 103, identifier:date; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:datetime64; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:isfinite; 111, argument_list; 111, 112; 112, identifier:xi; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:ind; 118, identifier:i; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:np; 122, identifier:nanargmin; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:abs; 126, argument_list; 126, 127; 127, binary_operator:-; 127, 128; 127, 129; 128, identifier:x; 129, identifier:xi; 130, else_clause; 130, 131; 131, block; 131, 132; 132, raise_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:ValueError; 135, argument_list; 135, 136; 136, string:'x0 must NOT be None or NaN to avoid surprising None return value'; 137, return_statement; 137, 138; 138, expression_list; 138, 139; 138, 146; 139, subscript; 139, 140; 139, 145; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:ind; 143, identifier:squeeze; 144, argument_list; 145, tuple; 146, subscript; 146, 147; 146, 154; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:x; 151, identifier:ind; 152, identifier:squeeze; 153, argument_list; 154, tuple | def find_nearest(x, x0) -> Tuple[int, Any]:
x = np.asanyarray(x)
x0 = np.atleast_1d(x0)
if x.size == 0 or x0.size == 0:
raise ValueError('empty input(s)')
if x0.ndim not in (0, 1):
raise ValueError('2-D x0 not handled yet')
ind = np.empty_like(x0, dtype=int)
for i, xi in enumerate(x0):
if xi is not None and (isinstance(xi, (datetime.datetime, datetime.date, np.datetime64)) or np.isfinite(xi)):
ind[i] = np.nanargmin(abs(x-xi))
else:
raise ValueError('x0 must NOT be None or NaN to avoid surprising None return value')
return ind.squeeze()[()], x[ind].squeeze()[()] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:primary_mrna; 3, parameters; 3, 4; 3, 5; 4, identifier:entrystream; 5, default_parameter; 5, 6; 5, 7; 6, identifier:parenttype; 7, string:'gene'; 8, block; 8, 9; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:entry; 11, identifier:entrystream; 12, block; 12, 13; 12, 27; 12, 73; 13, if_statement; 13, 14; 13, 22; 14, not_operator; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:entry; 19, attribute; 19, 20; 19, 21; 20, identifier:tag; 21, identifier:Feature; 22, block; 22, 23; 22, 26; 23, expression_statement; 23, 24; 24, yield; 24, 25; 25, identifier:entry; 26, continue_statement; 27, for_statement; 27, 28; 27, 29; 27, 41; 28, identifier:parent; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:tag; 33, identifier:select; 34, identifier:features; 35, argument_list; 35, 36; 35, 37; 35, 38; 36, identifier:entry; 37, identifier:parenttype; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:traverse; 40, True; 41, block; 41, 42; 41, 58; 41, 67; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:mrnas; 45, list_comprehension; 45, 46; 45, 47; 45, 52; 46, identifier:f; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:f; 49, attribute; 49, 50; 49, 51; 50, identifier:parent; 51, identifier:children; 52, if_clause; 52, 53; 53, comparison_operator:==; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:f; 56, identifier:type; 57, string:'mRNA'; 58, if_statement; 58, 59; 58, 65; 59, comparison_operator:==; 59, 60; 59, 64; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:mrnas; 64, integer:0; 65, block; 65, 66; 66, continue_statement; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:_emplace_pmrna; 70, argument_list; 70, 71; 70, 72; 71, identifier:mrnas; 72, identifier:parent; 73, expression_statement; 73, 74; 74, yield; 74, 75; 75, identifier:entry | def primary_mrna(entrystream, parenttype='gene'):
for entry in entrystream:
if not isinstance(entry, tag.Feature):
yield entry
continue
for parent in tag.select.features(entry, parenttype, traverse=True):
mrnas = [f for f in parent.children if f.type == 'mRNA']
if len(mrnas) == 0:
continue
_emplace_pmrna(mrnas, parent)
yield entry |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:notes; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:public_only; 7, False; 8, block; 8, 9; 8, 28; 8, 40; 8, 54; 8, 69; 8, 129; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:tag_index; 12, call; 12, 13; 12, 14; 13, identifier:dict; 14, generator_expression; 14, 15; 14, 18; 15, tuple; 15, 16; 15, 17; 16, identifier:tag; 17, identifier:i; 18, for_in_clause; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:i; 21, identifier:tag; 22, call; 22, 23; 22, 24; 23, identifier:enumerate; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:Note; 27, identifier:TAGS; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:notes; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:note_set; 36, identifier:order_by; 37, argument_list; 37, 38; 37, 39; 38, string:'-sort_num'; 39, string:'created'; 40, if_statement; 40, 41; 40, 42; 41, identifier:public_only; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:notes; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:notes; 49, identifier:filter; 50, argument_list; 50, 51; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:is_public; 53, True; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:known_issues; 57, list_comprehension; 57, 58; 57, 59; 57, 62; 58, identifier:n; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:n; 61, identifier:notes; 62, if_clause; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:n; 66, identifier:is_known_issue_for; 67, argument_list; 67, 68; 68, identifier:self; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:new_features; 72, call; 72, 73; 72, 74; 73, identifier:sorted; 74, argument_list; 74, 75; 74, 105; 74, 126; 75, call; 75, 76; 75, 77; 76, identifier:sorted; 77, argument_list; 77, 78; 77, 91; 78, generator_expression; 78, 79; 78, 80; 78, 83; 79, identifier:n; 80, for_in_clause; 80, 81; 80, 82; 81, identifier:n; 82, identifier:notes; 83, if_clause; 83, 84; 84, not_operator; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:n; 88, identifier:is_known_issue_for; 89, argument_list; 89, 90; 90, identifier:self; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:key; 93, lambda; 93, 94; 93, 96; 94, lambda_parameters; 94, 95; 95, identifier:note; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:tag_index; 99, identifier:get; 100, argument_list; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:note; 103, identifier:tag; 104, integer:0; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:key; 107, lambda; 107, 108; 107, 110; 108, lambda_parameters; 108, 109; 109, identifier:n; 110, boolean_operator:and; 110, 111; 110, 116; 111, comparison_operator:==; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:n; 114, identifier:tag; 115, string:'Fixed'; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:n; 120, identifier:note; 121, identifier:startswith; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:version; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:reverse; 128, True; 129, return_statement; 129, 130; 130, expression_list; 130, 131; 130, 132; 131, identifier:new_features; 132, identifier:known_issues | def notes(self, public_only=False):
tag_index = dict((tag, i) for i, tag in enumerate(Note.TAGS))
notes = self.note_set.order_by('-sort_num', 'created')
if public_only:
notes = notes.filter(is_public=True)
known_issues = [n for n in notes if n.is_known_issue_for(self)]
new_features = sorted(
sorted(
(n for n in notes if not n.is_known_issue_for(self)),
key=lambda note: tag_index.get(note.tag, 0)),
key=lambda n: n.tag == 'Fixed' and n.note.startswith(self.version),
reverse=True)
return new_features, known_issues |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:dispatchlist; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, keyword_separator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:author; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:category; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:subcategory; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:sort; 17, string:'new'; 18, block; 18, 19; 18, 26; 18, 35; 18, 89; 18, 119; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:params; 22, dictionary; 22, 23; 23, pair; 23, 24; 23, 25; 24, string:'sort'; 25, identifier:sort; 26, if_statement; 26, 27; 26, 28; 27, identifier:author; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:params; 33, string:'dispatchauthor'; 34, identifier:author; 35, if_statement; 35, 36; 35, 39; 35, 63; 35, 82; 36, boolean_operator:and; 36, 37; 36, 38; 37, identifier:category; 38, identifier:subcategory; 39, block; 39, 40; 39, 57; 40, if_statement; 40, 41; 40, 51; 41, parenthesized_expression; 41, 42; 42, boolean_operator:or; 42, 43; 42, 46; 43, comparison_operator:not; 43, 44; 43, 45; 44, identifier:category; 45, identifier:dispatch_categories; 46, comparison_operator:not; 46, 47; 46, 48; 47, identifier:subcategory; 48, subscript; 48, 49; 48, 50; 49, identifier:dispatch_categories; 50, identifier:category; 51, block; 51, 52; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:ValueError; 55, argument_list; 55, 56; 56, string:'Invalid category/subcategory'; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, subscript; 59, 60; 59, 61; 60, identifier:params; 61, string:'dispatchcategory'; 62, string:f'{category}:{subcategory}'; 63, elif_clause; 63, 64; 63, 65; 64, identifier:category; 65, block; 65, 66; 65, 76; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:not; 67, 68; 67, 69; 68, identifier:category; 69, identifier:dispatch_categories; 70, block; 70, 71; 71, raise_statement; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:ValueError; 74, argument_list; 74, 75; 75, string:'Invalid category'; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:params; 80, string:'dispatchcategory'; 81, identifier:category; 82, else_clause; 82, 83; 83, block; 83, 84; 84, raise_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:ValueError; 87, argument_list; 87, 88; 88, string:'Cannot request subcategory without category'; 89, decorated_definition; 89, 90; 89, 97; 90, decorator; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:api_query; 93, argument_list; 93, 94; 93, 95; 94, string:'dispatchlist'; 95, dictionary_splat; 95, 96; 96, identifier:params; 97, function_definition; 97, 98; 97, 99; 97, 102; 98, function_name:result; 99, parameters; 99, 100; 99, 101; 100, identifier:_; 101, identifier:root; 102, block; 102, 103; 103, return_statement; 103, 104; 104, list_comprehension; 104, 105; 104, 111; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:DispatchThumbnail; 108, identifier:_from_elem; 109, argument_list; 109, 110; 110, identifier:elem; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:elem; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:root; 116, identifier:find; 117, argument_list; 117, 118; 118, string:'DISPATCHLIST'; 119, return_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:result; 122, argument_list; 122, 123; 123, identifier:self | def dispatchlist(self, *, author=None, category=None,
subcategory=None, sort='new'):
params = {'sort': sort}
if author:
params['dispatchauthor'] = author
if category and subcategory:
if (category not in dispatch_categories or
subcategory not in dispatch_categories[category]):
raise ValueError('Invalid category/subcategory')
params['dispatchcategory'] = f'{category}:{subcategory}'
elif category:
if category not in dispatch_categories:
raise ValueError('Invalid category')
params['dispatchcategory'] = category
else:
raise ValueError('Cannot request subcategory without category')
@api_query('dispatchlist', **params)
async def result(_, root):
return [
DispatchThumbnail._from_elem(elem)
for elem in root.find('DISPATCHLIST')
]
return result(self) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 10; 2, function_name:have_cycle; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:graph; 6, type; 6, 7; 7, identifier:dict; 8, type; 8, 9; 9, identifier:frozenset; 10, block; 10, 11; 10, 17; 10, 45; 10, 52; 10, 57; 10, 103; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:walked; 14, call; 14, 15; 14, 16; 15, identifier:set; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:nodes; 20, call; 20, 21; 20, 22; 21, identifier:frozenset; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:it; 26, identifier:chain; 27, argument_list; 27, 28; 27, 40; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:it; 32, identifier:chain; 33, identifier:from_iterable; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:graph; 38, identifier:values; 39, argument_list; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:graph; 43, identifier:keys; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:preds; 48, call; 48, 49; 48, 50; 49, identifier:reversed_graph; 50, argument_list; 50, 51; 51, identifier:graph; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:last_walked_len; 55, unary_operator:-; 55, 56; 56, integer:1; 57, while_statement; 57, 58; 57, 64; 58, comparison_operator:!=; 58, 59; 58, 60; 59, identifier:last_walked_len; 60, call; 60, 61; 60, 62; 61, identifier:len; 62, argument_list; 62, 63; 63, identifier:walked; 64, block; 64, 65; 64, 72; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:last_walked_len; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:walked; 72, for_statement; 72, 73; 72, 74; 72, 77; 73, identifier:node; 74, binary_operator:-; 74, 75; 74, 76; 75, identifier:nodes; 76, identifier:walked; 77, block; 77, 78; 78, if_statement; 78, 79; 78, 95; 79, comparison_operator:==; 79, 80; 79, 94; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, binary_operator:-; 83, 84; 83, 93; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:preds; 87, identifier:get; 88, argument_list; 88, 89; 88, 90; 89, identifier:node; 90, call; 90, 91; 90, 92; 91, identifier:set; 92, argument_list; 93, identifier:walked; 94, integer:0; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:walked; 100, identifier:add; 101, argument_list; 101, 102; 102, identifier:node; 103, return_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:frozenset; 106, argument_list; 106, 107; 107, binary_operator:-; 107, 108; 107, 109; 108, identifier:nodes; 109, identifier:walked | def have_cycle(graph:dict) -> frozenset:
walked = set()
nodes = frozenset(it.chain(it.chain.from_iterable(graph.values()), graph.keys()))
preds = reversed_graph(graph)
last_walked_len = -1
while last_walked_len != len(walked):
last_walked_len = len(walked)
for node in nodes - walked:
if len(preds.get(node, set()) - walked) == 0:
walked.add(node)
return frozenset(nodes - walked) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:time_pipeline; 3, parameters; 3, 4; 3, 5; 4, identifier:iterable; 5, list_splat_pattern; 5, 6; 6, identifier:steps; 7, block; 7, 8; 7, 10; 7, 56; 7, 67; 7, 71; 7, 75; 7, 197; 7, 204; 7, 211; 7, 221; 8, expression_statement; 8, 9; 9, string:'''
This times the steps in a pipeline. Give it an iterable to test against
followed by the steps of the pipeline seperated in individual functions.
Example Usage:
```
from random import choice, randint
l = [randint(0,50) for i in range(100)]
step1 = lambda iterable:(i for i in iterable if i%5==0)
step2 = lambda iterable:(i for i in iterable if i%8==3)
step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
print('filter first')
time_pipeline(l, step1, step2, step3, step4)
print('process first')
time_pipeline(l, step3, step4, step1, step2)
print('filter, process, filter, process')
time_pipeline(l, step1, step3, step2, step4)
```
Outputs:
filter first
step 1 | 2.0427s | step1 = lambda iterable:(i for i in iterable if i%5==0)
step 2 | 2.0510s | step2 = lambda iterable:(i for i in iterable if i%8==3)
step 3 | 2.4839s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step 4 | 2.8446s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
process first
step 1 | 7.5291s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step 2 | 20.6732s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
step 3 | 16.8470s | step1 = lambda iterable:(i for i in iterable if i%5==0)
step 4 | 16.8269s | step2 = lambda iterable:(i for i in iterable if i%8==3)
filter, process, filter, process
step 1 | 2.0528s | step1 = lambda iterable:(i for i in iterable if i%5==0)
step 2 | 3.3039s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step 3 | 3.1385s | step2 = lambda iterable:(i for i in iterable if i%8==3)
step 4 | 3.1489s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
'''; 10, if_statement; 10, 11; 10, 15; 10, 36; 11, call; 11, 12; 11, 13; 12, identifier:callable; 13, argument_list; 13, 14; 14, identifier:iterable; 15, block; 15, 16; 16, try_statement; 16, 17; 16, 29; 17, block; 17, 18; 17, 25; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:iter; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:iterable; 24, argument_list; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:callable_base; 28, True; 29, except_clause; 29, 30; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:TypeError; 34, argument_list; 34, 35; 35, string:'time_pipeline needs the first argument to be an iterable or a function that produces an iterable.'; 36, else_clause; 36, 37; 37, block; 37, 38; 38, try_statement; 38, 39; 38, 49; 39, block; 39, 40; 39, 45; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:iter; 43, argument_list; 43, 44; 44, identifier:iterable; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:callable_base; 48, False; 49, except_clause; 49, 50; 50, block; 50, 51; 51, raise_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:TypeError; 54, argument_list; 54, 55; 55, string:'time_pipeline needs the first argument to be an iterable or a function that produces an iterable.'; 56, if_statement; 56, 57; 56, 59; 57, not_operator; 57, 58; 58, identifier:callable_base; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:iterable; 63, call; 63, 64; 63, 65; 64, identifier:tuple; 65, argument_list; 65, 66; 66, identifier:iterable; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:durations; 70, list:[]; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:results; 74, list:[]; 75, for_statement; 75, 76; 75, 79; 75, 83; 76, pattern_list; 76, 77; 76, 78; 77, identifier:i; 78, identifier:_; 79, call; 79, 80; 79, 81; 80, identifier:enumerate; 81, argument_list; 81, 82; 82, identifier:steps; 83, block; 83, 84; 83, 94; 83, 98; 83, 156; 83, 163; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:current_tasks; 87, subscript; 87, 88; 87, 89; 88, identifier:steps; 89, slice; 89, 90; 89, 91; 90, colon; 91, binary_operator:+; 91, 92; 91, 93; 92, identifier:i; 93, integer:1; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:duration; 97, float:0.0; 98, for_statement; 98, 99; 98, 100; 98, 104; 99, identifier:t; 100, call; 100, 101; 100, 102; 101, identifier:range; 102, argument_list; 102, 103; 103, integer:100000; 104, block; 104, 105; 104, 120; 104, 126; 104, 137; 104, 148; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:test_generator; 108, conditional_expression:if; 108, 109; 108, 115; 108, 116; 109, call; 109, 110; 109, 111; 110, identifier:iter; 111, argument_list; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:iterable; 114, argument_list; 115, identifier:callable_base; 116, call; 116, 117; 116, 118; 117, identifier:iter; 118, argument_list; 118, 119; 119, identifier:iterable; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:start; 123, call; 123, 124; 123, 125; 124, identifier:ts; 125, argument_list; 126, for_statement; 126, 127; 126, 128; 126, 129; 127, identifier:task; 128, identifier:current_tasks; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:test_generator; 133, call; 133, 134; 133, 135; 134, identifier:task; 135, argument_list; 135, 136; 136, identifier:test_generator; 137, for_statement; 137, 138; 137, 139; 137, 146; 138, identifier:i; 139, call; 139, 140; 139, 144; 140, subscript; 140, 141; 140, 142; 141, identifier:current_tasks; 142, unary_operator:-; 142, 143; 143, integer:1; 144, argument_list; 144, 145; 145, identifier:test_generator; 146, block; 146, 147; 147, pass_statement; 148, expression_statement; 148, 149; 149, augmented_assignment:+=; 149, 150; 149, 151; 150, identifier:duration; 151, binary_operator:-; 151, 152; 151, 155; 152, call; 152, 153; 152, 154; 153, identifier:ts; 154, argument_list; 155, identifier:start; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:durations; 160, identifier:append; 161, argument_list; 161, 162; 162, identifier:duration; 163, if_statement; 163, 164; 163, 170; 163, 180; 164, comparison_operator:==; 164, 165; 164, 169; 165, call; 165, 166; 165, 167; 166, identifier:len; 167, argument_list; 167, 168; 168, identifier:durations; 169, integer:1; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:results; 175, identifier:append; 176, argument_list; 176, 177; 177, subscript; 177, 178; 177, 179; 178, identifier:durations; 179, integer:0; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:results; 186, identifier:append; 187, argument_list; 187, 188; 188, binary_operator:-; 188, 189; 188, 193; 189, subscript; 189, 190; 189, 191; 190, identifier:durations; 191, unary_operator:-; 191, 192; 192, integer:1; 193, subscript; 193, 194; 193, 195; 194, identifier:durations; 195, unary_operator:-; 195, 196; 196, integer:2; 197, assert_statement; 197, 198; 198, comparison_operator:>; 198, 199; 198, 203; 199, call; 199, 200; 199, 201; 200, identifier:sum; 201, argument_list; 201, 202; 202, identifier:results; 203, integer:0; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:resultsum; 207, call; 207, 208; 207, 209; 208, identifier:sum; 209, argument_list; 209, 210; 210, identifier:results; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:ratios; 214, list_comprehension; 214, 215; 214, 218; 215, binary_operator:/; 215, 216; 215, 217; 216, identifier:i; 217, identifier:resultsum; 218, for_in_clause; 218, 219; 218, 220; 219, identifier:i; 220, identifier:results; 221, for_statement; 221, 222; 221, 223; 221, 230; 222, identifier:i; 223, call; 223, 224; 223, 225; 224, identifier:range; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:len; 228, argument_list; 228, 229; 229, identifier:ratios; 230, block; 230, 231; 230, 267; 231, try_statement; 231, 232; 231, 252; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:s; 236, call; 236, 237; 236, 251; 237, attribute; 237, 238; 237, 250; 238, subscript; 238, 239; 238, 249; 239, call; 239, 240; 239, 248; 240, attribute; 240, 241; 240, 247; 241, call; 241, 242; 241, 243; 242, identifier:getsource; 243, argument_list; 243, 244; 244, subscript; 244, 245; 244, 246; 245, identifier:steps; 246, identifier:i; 247, identifier:splitlines; 248, argument_list; 249, integer:0; 250, identifier:strip; 251, argument_list; 252, except_clause; 252, 253; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:s; 257, call; 257, 258; 257, 266; 258, attribute; 258, 259; 258, 265; 259, call; 259, 260; 259, 261; 260, identifier:repr; 261, argument_list; 261, 262; 262, subscript; 262, 263; 262, 264; 263, identifier:steps; 264, identifier:i; 265, identifier:strip; 266, argument_list; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:print; 270, argument_list; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, string:'step {} | {:2.4f}s | {}'; 274, identifier:format; 275, argument_list; 275, 276; 275, 279; 275, 282; 276, binary_operator:+; 276, 277; 276, 278; 277, identifier:i; 278, integer:1; 279, subscript; 279, 280; 279, 281; 280, identifier:durations; 281, identifier:i; 282, identifier:s | def time_pipeline(iterable, *steps):
'''
This times the steps in a pipeline. Give it an iterable to test against
followed by the steps of the pipeline seperated in individual functions.
Example Usage:
```
from random import choice, randint
l = [randint(0,50) for i in range(100)]
step1 = lambda iterable:(i for i in iterable if i%5==0)
step2 = lambda iterable:(i for i in iterable if i%8==3)
step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
print('filter first')
time_pipeline(l, step1, step2, step3, step4)
print('process first')
time_pipeline(l, step3, step4, step1, step2)
print('filter, process, filter, process')
time_pipeline(l, step1, step3, step2, step4)
```
Outputs:
filter first
step 1 | 2.0427s | step1 = lambda iterable:(i for i in iterable if i%5==0)
step 2 | 2.0510s | step2 = lambda iterable:(i for i in iterable if i%8==3)
step 3 | 2.4839s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step 4 | 2.8446s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
process first
step 1 | 7.5291s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step 2 | 20.6732s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
step 3 | 16.8470s | step1 = lambda iterable:(i for i in iterable if i%5==0)
step 4 | 16.8269s | step2 = lambda iterable:(i for i in iterable if i%8==3)
filter, process, filter, process
step 1 | 2.0528s | step1 = lambda iterable:(i for i in iterable if i%5==0)
step 2 | 3.3039s | step3 = lambda iterable:sorted((1.0*i)/50 for i in iterable)
step 3 | 3.1385s | step2 = lambda iterable:(i for i in iterable if i%8==3)
step 4 | 3.1489s | step4 = lambda iterable:(float(float(float(float(i*3)))) for i in iterable)
'''
if callable(iterable):
try:
iter(iterable())
callable_base = True
except:
raise TypeError('time_pipeline needs the first argument to be an iterable or a function that produces an iterable.')
else:
try:
iter(iterable)
callable_base = False
except:
raise TypeError('time_pipeline needs the first argument to be an iterable or a function that produces an iterable.')
if not callable_base:
iterable = tuple(iterable)
durations = []
results = []
for i,_ in enumerate(steps):
current_tasks = steps[:i+1]
duration = 0.0
for t in range(100000):
test_generator = iter(iterable()) if callable_base else iter(iterable)
start = ts()
for task in current_tasks:
test_generator = task(test_generator)
for i in current_tasks[-1](test_generator):
pass
duration += ts() - start
durations.append(duration)
if len(durations) == 1:
results.append(durations[0])
else:
results.append(durations[-1]-durations[-2])
assert sum(results) > 0
resultsum = sum(results)
ratios = [i/resultsum for i in results]
for i in range(len(ratios)):
try:
s = getsource(steps[i]).splitlines()[0].strip()
except:
s = repr(steps[i]).strip()
print('step {} | {:2.4f}s | {}'.format(i+1, durations[i], s)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_matches; 3, parameters; 3, 4; 4, identifier:matches; 5, block; 5, 6; 5, 8; 5, 30; 5, 54; 6, expression_statement; 6, 7; 7, string:'''Sorts a ``list`` of matches best to worst'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:multipliers; 11, dictionary; 11, 12; 11, 17; 11, 22; 11, 27; 12, pair; 12, 13; 12, 14; 13, string:'exact'; 14, binary_operator:**; 14, 15; 14, 16; 15, integer:10; 16, integer:5; 17, pair; 17, 18; 17, 19; 18, string:'fname'; 19, binary_operator:**; 19, 20; 19, 21; 20, integer:10; 21, integer:4; 22, pair; 22, 23; 22, 24; 23, string:'fuzzy'; 24, binary_operator:**; 24, 25; 24, 26; 25, integer:10; 26, integer:2; 27, pair; 27, 28; 27, 29; 28, string:'fuzzy_fragment'; 29, integer:1; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:matches; 33, list_comprehension; 33, 34; 33, 51; 34, tuple; 34, 35; 34, 50; 35, binary_operator:*; 35, 36; 35, 41; 36, subscript; 36, 37; 36, 38; 37, identifier:multipliers; 38, attribute; 38, 39; 38, 40; 39, identifier:x; 40, identifier:type; 41, parenthesized_expression; 41, 42; 42, conditional_expression:if; 42, 43; 42, 46; 42, 49; 43, attribute; 43, 44; 43, 45; 44, identifier:x; 45, identifier:amount; 46, attribute; 46, 47; 46, 48; 47, identifier:x; 48, identifier:amount; 49, integer:1; 50, identifier:x; 51, for_in_clause; 51, 52; 51, 53; 52, identifier:x; 53, identifier:matches; 54, return_statement; 54, 55; 55, list_comprehension; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:x; 58, integer:1; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:x; 61, call; 61, 62; 61, 63; 62, identifier:sorted; 63, argument_list; 63, 64; 63, 65; 64, identifier:matches; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:reverse; 67, True | def sort_matches(matches):
'''Sorts a ``list`` of matches best to worst'''
multipliers = {'exact':10**5,'fname':10**4,'fuzzy':10**2,'fuzzy_fragment':1}
matches = [(multipliers[x.type]*(x.amount if x.amount else 1),x) for x in matches]
return [x[1] for x in sorted(matches,reverse=True)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_sorted_iterator; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:iterator; 6, block; 6, 7; 6, 17; 6, 40; 6, 43; 6, 51; 6, 66; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:lines; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:next; 15, argument_list; 15, 16; 16, identifier:iterator; 17, if_statement; 17, 18; 17, 26; 18, comparison_operator:<; 18, 19; 18, 23; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:lines; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:max_lines; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:iter; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:sorted; 33, argument_list; 33, 34; 33, 35; 34, identifier:lines; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:key; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:key; 40, import_statement; 40, 41; 41, dotted_name; 41, 42; 42, identifier:tempfile; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:tmp_dir; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:tempfile; 49, identifier:mkdtemp; 50, argument_list; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:fnames; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_split; 58, argument_list; 58, 59; 58, 65; 59, call; 59, 60; 59, 61; 60, identifier:chain; 61, argument_list; 61, 62; 61, 64; 62, list:[lines]; 62, 63; 63, identifier:lines; 64, identifier:iterator; 65, identifier:tmp_dir; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:SortedIteratorMerger; 69, argument_list; 69, 70; 69, 82; 70, list_comprehension; 70, 71; 70, 79; 71, call; 71, 72; 71, 73; 72, identifier:unpickle_iter; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:open; 76, argument_list; 76, 77; 76, 78; 77, identifier:fname; 78, string:'rb'; 79, for_in_clause; 79, 80; 79, 81; 80, identifier:fname; 81, identifier:fnames; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:key | def _get_sorted_iterator(self, iterator):
lines = list(next(iterator))
if len(lines) < self.max_lines:
return iter(sorted(lines, key=self.key))
import tempfile
tmp_dir = tempfile.mkdtemp()
fnames = self._split(chain([lines], iterator), tmp_dir)
return SortedIteratorMerger([unpickle_iter(open(fname, 'rb')) for fname in fnames], self.key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_split; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:iterator; 6, identifier:tmp_dir; 7, block; 7, 8; 7, 12; 7, 75; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:fnames; 11, list:[]; 12, for_statement; 12, 13; 12, 16; 12, 20; 13, pattern_list; 13, 14; 13, 15; 14, identifier:i; 15, identifier:lines; 16, call; 16, 17; 16, 18; 17, identifier:enumerate; 18, argument_list; 18, 19; 19, identifier:iterator; 20, block; 20, 21; 20, 28; 20, 49; 20, 57; 20, 64; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:lines; 24, call; 24, 25; 24, 26; 25, identifier:list; 26, argument_list; 26, 27; 27, identifier:lines; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:out_fname; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:os; 35, identifier:path; 36, identifier:join; 37, argument_list; 37, 38; 37, 39; 38, identifier:tmp_dir; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:TMP_FNAME; 44, identifier:format; 45, argument_list; 45, 46; 46, binary_operator:+; 46, 47; 46, 48; 47, identifier:i; 48, integer:1; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_write; 54, argument_list; 54, 55; 54, 56; 55, identifier:lines; 56, identifier:out_fname; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:fnames; 61, identifier:append; 62, argument_list; 62, 63; 63, identifier:out_fname; 64, if_statement; 64, 65; 64, 73; 65, comparison_operator:<; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:lines; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:max_lines; 73, block; 73, 74; 74, break_statement; 75, return_statement; 75, 76; 76, identifier:fnames | def _split(self, iterator, tmp_dir):
fnames = []
for i, lines in enumerate(iterator):
lines = list(lines)
out_fname = os.path.join(tmp_dir, self.TMP_FNAME.format(i + 1))
self._write(lines, out_fname)
fnames.append(out_fname)
if len(lines) < self.max_lines:
break
return fnames |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_write; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:lines; 6, identifier:fname; 7, block; 7, 8; 8, with_statement; 8, 9; 8, 19; 9, with_clause; 9, 10; 10, with_item; 10, 11; 11, as_pattern; 11, 12; 11, 17; 12, call; 12, 13; 12, 14; 13, identifier:open; 14, argument_list; 14, 15; 14, 16; 15, identifier:fname; 16, string:'wb'; 17, as_pattern_target; 17, 18; 18, identifier:out_fhndl; 19, block; 19, 20; 20, for_statement; 20, 21; 20, 22; 20, 31; 21, identifier:line; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 24, 26; 25, identifier:lines; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:key; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:key; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:pickle; 36, identifier:dump; 37, argument_list; 37, 38; 37, 39; 38, identifier:line; 39, identifier:out_fhndl | def _write(self, lines, fname):
with open(fname, 'wb') as out_fhndl:
for line in sorted(lines, key=self.key):
pickle.dump(line, out_fhndl) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:add; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:interval; 6, identifier:offset; 7, block; 7, 8; 7, 19; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, pattern_list; 10, 11; 10, 12; 11, identifier:start; 12, identifier:stop; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:get_start_stop; 17, argument_list; 17, 18; 18, identifier:interval; 19, if_statement; 19, 20; 19, 28; 19, 77; 20, comparison_operator:>; 20, 21; 20, 27; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:starts; 27, integer:0; 28, block; 28, 29; 28, 55; 28, 66; 29, if_statement; 29, 30; 29, 49; 30, boolean_operator:or; 30, 31; 30, 39; 31, comparison_operator:<; 31, 32; 31, 33; 32, identifier:start; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:starts; 37, unary_operator:-; 37, 38; 38, integer:1; 39, comparison_operator:<=; 39, 40; 39, 41; 40, identifier:offset; 41, subscript; 41, 42; 41, 48; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:offsets; 46, unary_operator:-; 46, 47; 47, integer:1; 48, integer:1; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ValueError; 53, argument_list; 53, 54; 54, string:'intervals and offsets must be added in-order'; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 65; 57, subscript; 57, 58; 57, 64; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:offsets; 62, unary_operator:-; 62, 63; 63, integer:1; 64, integer:1; 65, identifier:offset; 66, expression_statement; 66, 67; 67, augmented_assignment:+=; 67, 68; 67, 76; 68, subscript; 68, 69; 68, 75; 69, subscript; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:offsets; 73, unary_operator:-; 73, 74; 74, integer:1; 75, integer:2; 76, integer:1; 77, else_clause; 77, 78; 78, block; 78, 79; 78, 88; 78, 97; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:starts; 85, identifier:append; 86, argument_list; 86, 87; 87, identifier:start; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:stops; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:stop; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:offsets; 103, identifier:append; 104, argument_list; 104, 105; 105, list:[offset, offset, 1]; 105, 106; 105, 107; 105, 108; 106, identifier:offset; 107, identifier:offset; 108, integer:1 | def add(self, interval, offset):
start, stop = self.get_start_stop(interval)
if len(self.starts) > 0:
if start < self.starts[-1] or offset <= self.offsets[-1][1]:
raise ValueError('intervals and offsets must be added in-order')
self.offsets[-1][1] = offset
self.offsets[-1][2] += 1
else:
self.starts.append(start)
self.stops.append(stop)
self.offsets.append([offset, offset, 1]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_collection_documents_generator; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:client; 5, identifier:database_name; 6, identifier:collection_name; 7, identifier:spec; 8, identifier:latest_n; 9, identifier:sort_key; 10, block; 10, 11; 10, 17; 10, 23; 10, 30; 10, 108; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:mongo_database; 14, subscript; 14, 15; 14, 16; 15, identifier:client; 16, identifier:database_name; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:collection; 20, subscript; 20, 21; 20, 22; 21, identifier:mongo_database; 22, identifier:collection_name; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:collection; 27, identifier:create_index; 28, argument_list; 28, 29; 29, identifier:sort_key; 30, if_statement; 30, 31; 30, 34; 30, 87; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:latest_n; 33, None; 34, block; 34, 35; 34, 45; 34, 60; 34, 79; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:skip_n; 38, binary_operator:-; 38, 39; 38, 44; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:collection; 42, identifier:count; 43, argument_list; 44, identifier:latest_n; 45, if_statement; 45, 46; 45, 55; 46, comparison_operator:<; 46, 47; 46, 54; 47, binary_operator:-; 47, 48; 47, 53; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:collection; 51, identifier:count; 52, argument_list; 53, identifier:latest_n; 54, integer:0; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:skip_n; 59, integer:0; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:cursor; 63, call; 63, 64; 63, 74; 64, attribute; 64, 65; 64, 73; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:collection; 68, identifier:find; 69, argument_list; 69, 70; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:filter; 72, identifier:spec; 73, identifier:sort; 74, argument_list; 74, 75; 75, list:[(sort_key, ASCENDING), ]; 75, 76; 76, tuple; 76, 77; 76, 78; 77, identifier:sort_key; 78, identifier:ASCENDING; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:cursor; 82, subscript; 82, 83; 82, 84; 83, identifier:cursor; 84, slice; 84, 85; 84, 86; 85, identifier:skip_n; 86, colon; 87, else_clause; 87, 88; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:cursor; 92, call; 92, 93; 92, 103; 93, attribute; 93, 94; 93, 102; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:collection; 97, identifier:find; 98, argument_list; 98, 99; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:filter; 101, identifier:spec; 102, identifier:sort; 103, argument_list; 103, 104; 104, list:[(sort_key, ASCENDING), ]; 104, 105; 105, tuple; 105, 106; 105, 107; 106, identifier:sort_key; 107, identifier:ASCENDING; 108, for_statement; 108, 109; 108, 110; 108, 111; 109, identifier:document; 110, identifier:cursor; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, yield; 113, 114; 114, identifier:document | def get_collection_documents_generator(client, database_name, collection_name, spec, latest_n, sort_key):
mongo_database = client[database_name]
collection = mongo_database[collection_name]
collection.create_index(sort_key)
if latest_n is not None:
skip_n = collection.count() - latest_n
if collection.count() - latest_n < 0:
skip_n = 0
cursor = collection.find(filter=spec).sort([(sort_key, ASCENDING), ])
cursor = cursor[skip_n:]
else:
cursor = collection.find(filter=spec).sort([(sort_key, ASCENDING), ])
for document in cursor:
yield document |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:save; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 27; 9, 44; 10, if_statement; 10, 11; 10, 15; 11, not_operator; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:target; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:target; 21, call; 21, 22; 21, 23; 22, identifier:str; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:content_object; 27, if_statement; 27, 28; 27, 32; 28, not_operator; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:actor_name; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:actor_name; 38, call; 38, 39; 38, 40; 39, identifier:str; 40, argument_list; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:actor; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 53; 46, attribute; 46, 47; 46, 52; 47, call; 47, 48; 47, 49; 48, identifier:super; 49, argument_list; 49, 50; 49, 51; 50, identifier:Activity; 51, identifier:self; 52, identifier:save; 53, argument_list | def save(self, *args, **kwargs):
if not self.target:
self.target = str(self.content_object)
if not self.actor_name:
self.actor_name = str(self.actor)
super(Activity, self).save() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort_modules; 3, parameters; 3, 4; 4, identifier:mods; 5, block; 5, 6; 5, 56; 6, function_definition; 6, 7; 6, 8; 6, 11; 7, function_name:compare; 8, parameters; 8, 9; 8, 10; 9, identifier:x; 10, identifier:y; 11, block; 11, 12; 11, 18; 11, 24; 11, 31; 11, 40; 11, 54; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:x; 15, subscript; 15, 16; 15, 17; 16, identifier:x; 17, integer:1; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:y; 21, subscript; 21, 22; 21, 23; 22, identifier:y; 23, integer:1; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:==; 25, 26; 25, 27; 26, identifier:x; 27, identifier:y; 28, block; 28, 29; 29, return_statement; 29, 30; 30, integer:0; 31, if_statement; 31, 32; 31, 37; 32, comparison_operator:==; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:y; 35, identifier:stem; 36, string:"__init__.py"; 37, block; 37, 38; 38, return_statement; 38, 39; 39, integer:1; 40, if_statement; 40, 41; 40, 50; 41, boolean_operator:or; 41, 42; 41, 47; 42, comparison_operator:==; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:x; 45, identifier:stem; 46, string:"__init__.py"; 47, comparison_operator:<; 47, 48; 47, 49; 48, identifier:x; 49, identifier:y; 50, block; 50, 51; 51, return_statement; 51, 52; 52, unary_operator:-; 52, 53; 53, integer:1; 54, return_statement; 54, 55; 55, integer:1; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:sorted; 59, argument_list; 59, 60; 59, 61; 60, identifier:mods; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:key; 63, call; 63, 64; 63, 65; 64, identifier:cmp_to_key; 65, argument_list; 65, 66; 66, identifier:compare | def _sort_modules(mods):
def compare(x, y):
x = x[1]
y = y[1]
if x == y:
return 0
if y.stem == "__init__.py":
return 1
if x.stem == "__init__.py" or x < y:
return -1
return 1
return sorted(mods, key=cmp_to_key(compare)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_sort_results; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:results; 6, block; 6, 7; 6, 11; 6, 15; 6, 79; 6, 83; 6, 109; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:parents; 10, list:[]; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:groups; 14, list:[]; 15, for_statement; 15, 16; 15, 17; 15, 18; 16, identifier:result; 17, identifier:results; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 30; 19, 61; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:_in_list; 25, argument_list; 25, 26; 25, 27; 26, identifier:parents; 27, attribute; 27, 28; 27, 29; 28, identifier:result; 29, identifier:parent; 30, block; 30, 31; 30, 40; 30, 47; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:parents; 35, identifier:append; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:result; 39, identifier:parent; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:groups; 44, identifier:append; 45, argument_list; 45, 46; 46, list:[]; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 59; 49, attribute; 49, 50; 49, 58; 50, subscript; 50, 51; 50, 52; 51, identifier:groups; 52, binary_operator:-; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:groups; 57, integer:1; 58, identifier:append; 59, argument_list; 59, 60; 60, identifier:result; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 77; 65, attribute; 65, 66; 65, 76; 66, subscript; 66, 67; 66, 68; 67, identifier:groups; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:parents; 71, identifier:index; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:result; 75, identifier:parent; 76, identifier:append; 77, argument_list; 77, 78; 78, identifier:result; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:array; 82, list:[]; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:group; 85, identifier:groups; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, augmented_assignment:+=; 88, 89; 88, 90; 89, identifier:array; 90, call; 90, 91; 90, 92; 91, identifier:sorted; 92, argument_list; 92, 93; 92, 94; 93, identifier:group; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:key; 96, lambda; 96, 97; 96, 99; 97, lambda_parameters; 97, 98; 98, identifier:element; 99, call; 99, 100; 99, 107; 100, attribute; 100, 101; 100, 106; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:element; 104, identifier:parent; 105, identifier:contents; 106, identifier:index; 107, argument_list; 107, 108; 108, identifier:element; 109, return_statement; 109, 110; 110, identifier:array | def _sort_results(self, results):
parents = []
groups = []
for result in results:
if not self._in_list(parents, result.parent):
parents.append(result.parent)
groups.append([])
groups[len(groups) - 1].append(result)
else:
groups[parents.index(result.parent)].append(result)
array = []
for group in groups:
array += sorted(
group,
key=lambda element: element.parent.contents.index(element)
)
return array |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_update_sorting; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 18; 5, 24; 5, 30; 5, 82; 5, 92; 5, 107; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:key; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:key; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:sorted_tops; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:sorted_tops; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:tops; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:tops; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:iterators; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:iterators; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:idx; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:idxs; 35, block; 35, 36; 36, try_statement; 36, 37; 36, 78; 37, block; 37, 38; 37, 49; 37, 58; 37, 69; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:tops; 42, identifier:idx; 43, call; 43, 44; 43, 45; 44, identifier:next; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 48; 47, identifier:iterators; 48, identifier:idx; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:top_key; 52, call; 52, 53; 52, 54; 53, identifier:key; 54, argument_list; 54, 55; 55, subscript; 55, 56; 55, 57; 56, identifier:tops; 57, identifier:idx; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:not; 59, 60; 59, 61; 60, identifier:top_key; 61, identifier:sorted_tops; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:sorted_tops; 67, identifier:top_key; 68, list:[]; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:sorted_tops; 74, identifier:top_key; 75, identifier:append; 76, argument_list; 76, 77; 77, identifier:idx; 78, except_clause; 78, 79; 78, 80; 79, identifier:StopIteration; 80, block; 80, 81; 81, pass_statement; 82, if_statement; 82, 83; 82, 89; 83, comparison_operator:==; 83, 84; 83, 88; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, identifier:sorted_tops; 88, integer:0; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, identifier:StopIteration; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 99; 94, pattern_list; 94, 95; 94, 96; 95, identifier:key; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:idxs; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:sorted_tops; 102, identifier:popitem; 103, argument_list; 103, 104; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:last; 106, False; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:c_idx; 112, integer:0 | def _update_sorting(self):
key = self.key
sorted_tops = self.sorted_tops
tops = self.tops
iterators = self.iterators
for idx in self.idxs:
try:
tops[idx] = next(iterators[idx])
top_key = key(tops[idx])
if top_key not in sorted_tops:
sorted_tops[top_key] = []
sorted_tops[top_key].append(idx)
except StopIteration:
pass
if len(sorted_tops) == 0:
raise StopIteration
key, self.idxs = sorted_tops.popitem(last=False)
self.c_idx = 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:domain_user_stats; 3, parameters; 4, block; 4, 5; 4, 24; 4, 42; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:fname; 8, call; 8, 9; 8, 14; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:os; 12, identifier:path; 13, identifier:join; 14, argument_list; 14, 15; 14, 23; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:os; 19, identifier:path; 20, identifier:dirname; 21, argument_list; 21, 22; 22, identifier:__file__; 23, string:"email_domain_users.csv"; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:stats; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:pd; 30, identifier:read_csv; 31, argument_list; 31, 32; 31, 33; 31, 36; 31, 39; 32, identifier:fname; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:header; 35, integer:0; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:squeeze; 38, True; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:index_col; 41, integer:0; 42, return_statement; 42, 43; 43, subscript; 43, 44; 43, 45; 44, identifier:stats; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:pd; 48, identifier:notnull; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:stats; 52, identifier:index | def domain_user_stats():
fname = os.path.join(os.path.dirname(__file__), "email_domain_users.csv")
stats = pd.read_csv(fname, header=0, squeeze=True, index_col=0)
return stats[pd.notnull(stats.index)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_topological_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 20; 5, 33; 5, 76; 5, 93; 5, 109; 5, 156; 5, 178; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sorted_graph; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:node_map; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_graph; 18, identifier:get_nodes; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:nodes; 23, list_comprehension; 23, 24; 23, 30; 24, call; 24, 25; 24, 26; 25, identifier:NodeVisitor; 26, argument_list; 26, 27; 27, subscript; 27, 28; 27, 29; 28, identifier:node_map; 29, identifier:node; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:node; 32, identifier:node_map; 33, function_definition; 33, 34; 33, 35; 33, 37; 34, function_name:get_pointers_for_edge_nodes; 35, parameters; 35, 36; 36, identifier:visitor_decorated_node; 37, block; 37, 38; 37, 42; 37, 54; 37, 74; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:edges; 41, list:[]; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:edge_ids; 45, call; 45, 46; 45, 53; 46, attribute; 46, 47; 46, 52; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:visitor_decorated_node; 50, identifier:get_node; 51, argument_list; 52, identifier:get_edges; 53, argument_list; 54, for_statement; 54, 55; 54, 56; 54, 57; 55, identifier:node; 56, identifier:nodes; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 66; 59, comparison_operator:in; 59, 60; 59, 65; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:node; 63, identifier:get_id; 64, argument_list; 65, identifier:edge_ids; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:edges; 71, identifier:append; 72, argument_list; 72, 73; 73, identifier:node; 74, return_statement; 74, 75; 75, identifier:edges; 76, for_statement; 76, 77; 76, 78; 76, 79; 77, identifier:node; 78, identifier:nodes; 79, block; 79, 80; 80, for_statement; 80, 81; 80, 82; 80, 86; 81, identifier:edge; 82, call; 82, 83; 82, 84; 83, identifier:get_pointers_for_edge_nodes; 84, argument_list; 84, 85; 85, identifier:node; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:edge; 91, identifier:increment; 92, argument_list; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:resolved; 96, list_comprehension; 96, 97; 96, 98; 96, 101; 97, identifier:node; 98, for_in_clause; 98, 99; 98, 100; 99, identifier:node; 100, identifier:nodes; 101, if_clause; 101, 102; 102, comparison_operator:==; 102, 103; 102, 108; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:node; 106, identifier:get_weight; 107, argument_list; 108, integer:0; 109, while_statement; 109, 110; 109, 111; 110, identifier:resolved; 111, block; 111, 112; 111, 120; 111, 127; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:node; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:resolved; 118, identifier:pop; 119, argument_list; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:sorted_graph; 124, identifier:append; 125, argument_list; 125, 126; 126, identifier:node; 127, for_statement; 127, 128; 127, 129; 127, 133; 128, identifier:edge; 129, call; 129, 130; 129, 131; 130, identifier:get_pointers_for_edge_nodes; 131, argument_list; 131, 132; 132, identifier:node; 133, block; 133, 134; 133, 140; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:edge; 138, identifier:decrement; 139, argument_list; 140, if_statement; 140, 141; 140, 148; 141, comparison_operator:==; 141, 142; 141, 147; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:edge; 145, identifier:get_weight; 146, argument_list; 147, integer:0; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:resolved; 153, identifier:append; 154, argument_list; 154, 155; 155, identifier:edge; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_circular_dependencies; 161, list_comprehension; 161, 162; 161, 167; 161, 170; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:node; 165, identifier:get_node; 166, argument_list; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:node; 169, identifier:nodes; 170, if_clause; 170, 171; 171, comparison_operator:>; 171, 172; 171, 177; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:node; 175, identifier:get_weight; 176, argument_list; 177, integer:0; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:_sorted_nodes; 183, call; 183, 184; 183, 185; 184, identifier:list; 185, argument_list; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:reversed; 188, argument_list; 188, 189; 189, list_comprehension; 189, 190; 189, 195; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:node; 193, identifier:get_node; 194, argument_list; 195, for_in_clause; 195, 196; 195, 197; 196, identifier:node; 197, identifier:sorted_graph | def _topological_sort(self):
sorted_graph = []
node_map = self._graph.get_nodes()
nodes = [NodeVisitor(node_map[node]) for node in node_map]
def get_pointers_for_edge_nodes(visitor_decorated_node):
edges = []
edge_ids = visitor_decorated_node.get_node().get_edges()
for node in nodes:
if node.get_id() in edge_ids:
edges.append(node)
return edges
for node in nodes:
for edge in get_pointers_for_edge_nodes(node):
edge.increment()
resolved = [node for node in nodes if node.get_weight() == 0]
while resolved:
node = resolved.pop()
sorted_graph.append(node)
for edge in get_pointers_for_edge_nodes(node):
edge.decrement()
if edge.get_weight() == 0:
resolved.append(edge)
self._circular_dependencies = [
node.get_node() for node in nodes if node.get_weight() > 0]
self._sorted_nodes = list(reversed(
[node.get_node() for node in sorted_graph])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:plugins; 3, parameters; 3, 4; 3, 5; 4, identifier:group; 5, default_parameter; 5, 6; 5, 7; 6, identifier:spec; 7, None; 8, block; 8, 9; 8, 11; 8, 18; 8, 29; 8, 41; 9, expression_statement; 9, 10; 10, string:'''
Returns a `PluginSet` object for the specified setuptools-style
entrypoint `group`. This is just a wrapper around
`pkg_resources.iter_entry_points` that allows the plugins to sort
and override themselves.
The optional `spec` parameter controls how and what plugins are
loaded. If it is ``None`` or the special value ``'*'``, then the
normal plugin loading will occur, i.e. all registered plugins will
be loaded and their self-declared ordering and dependencies will be
applied.
Otherwise, the `spec` is taken as a comma- or whitespace-separated
list of plugins to load. In this mode, the `spec` can either specify
an exact list of plugins to load, in the specified order, referred
to as an "absolute" spec. Otherwise, it is a "relative" spec, which
indicates that it only adjusts the standard registered plugin
loading. A spec is a list of either absolute or relative
instructions, and they cannot be mixed.
In either mode, a plugin is identified either by name for registered
plugins (e.g. ``foo``), or by fully-qualified Python module and
symbol name for unregistered plugins
(e.g. ``package.module.symbol``).
Plugins in an absolute spec are loaded in the order specified and
can be optionally prefixed with the following special characters:
* ``'?'`` : the specified plugin should be loaded if available. If
it is not registered, cannot be found, or cannot be loaded, then
it is ignored (a DEBUG log message will be emitted, however).
Plugins in a relative spec are always prefixed with at least one of
the following special characters:
* ``'-'`` : removes the specified plugin; this does not affect
plugin ordering, it only removes the plugin from the loaded
list. If the plugin does not exist, no error is thrown.
* ``'+'`` : adds or requires the specified plugin to the loaded
set. If the plugin is not a named/registered plugin, then it will
be loaded as an asset-symbol, i.e. a Python-dotted module and
symbol name. If the plugin does not exist or cannot be loaded,
this will throw an error. It does not affect the plugin ordering
of registered plugins.
* ``'/'`` : the plugin name is taken as a regular expression that
will be used to match plugin names and it must terminate in a
slash. Note that this must be the **last** element in the spec
list.
Examples:
* ``'*'`` : load all registered plugins.
* ``'foo,bar'`` : load the "foo" plugin, then the "bar" plugin.
* ``'foo,?bar'`` : load the "foo" plugin and if the "bar" plugin
exists, load it too.
* ``'-zig'`` : load all registered plugins except the "zig" plugin.
* ``'+pkg.foo.bar'`` : load all registered plugins and then load
the "pkg.foo.bar" Python symbol.
* ``'pkg.foo.bar'`` : load only the "pkg.foo.bar" Python symbol.
'''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:pspec; 14, call; 14, 15; 14, 16; 15, identifier:_parse_spec; 16, argument_list; 16, 17; 17, identifier:spec; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:plugs; 21, call; 21, 22; 21, 23; 22, identifier:list; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:_get_registered_plugins; 26, argument_list; 26, 27; 26, 28; 27, identifier:group; 28, identifier:pspec; 29, expression_statement; 29, 30; 30, augmented_assignment:+=; 30, 31; 30, 32; 31, identifier:plugs; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:_get_unregistered_plugins; 37, argument_list; 37, 38; 37, 39; 37, 40; 38, identifier:group; 39, identifier:plugs; 40, identifier:pspec; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:PluginSet; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:group; 46, identifier:spec; 47, call; 47, 48; 47, 49; 48, identifier:list; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:_sort_plugins; 52, argument_list; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:group; 54, identifier:plugs; 55, identifier:pspec; 56, identifier:spec | def plugins(group, spec=None):
'''
Returns a `PluginSet` object for the specified setuptools-style
entrypoint `group`. This is just a wrapper around
`pkg_resources.iter_entry_points` that allows the plugins to sort
and override themselves.
The optional `spec` parameter controls how and what plugins are
loaded. If it is ``None`` or the special value ``'*'``, then the
normal plugin loading will occur, i.e. all registered plugins will
be loaded and their self-declared ordering and dependencies will be
applied.
Otherwise, the `spec` is taken as a comma- or whitespace-separated
list of plugins to load. In this mode, the `spec` can either specify
an exact list of plugins to load, in the specified order, referred
to as an "absolute" spec. Otherwise, it is a "relative" spec, which
indicates that it only adjusts the standard registered plugin
loading. A spec is a list of either absolute or relative
instructions, and they cannot be mixed.
In either mode, a plugin is identified either by name for registered
plugins (e.g. ``foo``), or by fully-qualified Python module and
symbol name for unregistered plugins
(e.g. ``package.module.symbol``).
Plugins in an absolute spec are loaded in the order specified and
can be optionally prefixed with the following special characters:
* ``'?'`` : the specified plugin should be loaded if available. If
it is not registered, cannot be found, or cannot be loaded, then
it is ignored (a DEBUG log message will be emitted, however).
Plugins in a relative spec are always prefixed with at least one of
the following special characters:
* ``'-'`` : removes the specified plugin; this does not affect
plugin ordering, it only removes the plugin from the loaded
list. If the plugin does not exist, no error is thrown.
* ``'+'`` : adds or requires the specified plugin to the loaded
set. If the plugin is not a named/registered plugin, then it will
be loaded as an asset-symbol, i.e. a Python-dotted module and
symbol name. If the plugin does not exist or cannot be loaded,
this will throw an error. It does not affect the plugin ordering
of registered plugins.
* ``'/'`` : the plugin name is taken as a regular expression that
will be used to match plugin names and it must terminate in a
slash. Note that this must be the **last** element in the spec
list.
Examples:
* ``'*'`` : load all registered plugins.
* ``'foo,bar'`` : load the "foo" plugin, then the "bar" plugin.
* ``'foo,?bar'`` : load the "foo" plugin and if the "bar" plugin
exists, load it too.
* ``'-zig'`` : load all registered plugins except the "zig" plugin.
* ``'+pkg.foo.bar'`` : load all registered plugins and then load
the "pkg.foo.bar" Python symbol.
* ``'pkg.foo.bar'`` : load only the "pkg.foo.bar" Python symbol.
'''
pspec = _parse_spec(spec)
plugs = list(_get_registered_plugins(group, pspec))
plugs += list(_get_unregistered_plugins(group, plugs, pspec))
return PluginSet(group, spec, list(_sort_plugins(group, plugs, pspec, spec))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:match_any_string; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:strings; 6, default_parameter; 6, 7; 6, 8; 7, identifier:word; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:offset; 11, integer:0; 12, block; 12, 13; 12, 32; 12, 36; 12, 40; 12, 44; 12, 77; 13, if_statement; 13, 14; 13, 15; 14, identifier:word; 15, block; 15, 16; 15, 25; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:current; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:get_string; 23, argument_list; 23, 24; 24, identifier:offset; 25, return_statement; 25, 26; 26, conditional_expression:if; 26, 27; 26, 28; 26, 31; 27, identifier:current; 28, comparison_operator:in; 28, 29; 28, 30; 29, identifier:current; 30, identifier:strings; 31, string:''; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:current; 35, string:''; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:currentlength; 39, integer:0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:length; 43, integer:0; 44, for_statement; 44, 45; 44, 46; 44, 47; 45, identifier:string; 46, identifier:strings; 47, block; 47, 48; 47, 55; 47, 70; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:length; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:string; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:!=; 56, 57; 56, 58; 57, identifier:length; 58, identifier:currentlength; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:current; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:get_length; 67, argument_list; 67, 68; 67, 69; 68, identifier:length; 69, identifier:offset; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:==; 71, 72; 71, 73; 72, identifier:string; 73, identifier:current; 74, block; 74, 75; 75, return_statement; 75, 76; 76, identifier:string; 77, return_statement; 77, 78; 78, string:'' | def match_any_string(self, strings, word=0, offset=0):
if word:
current = self.get_string(offset)
return current if current in strings else ''
current = ''
currentlength = 0
length = 0
for string in strings:
length = len(string)
if length != currentlength:
current = self.get_length(length, offset)
if string == current:
return string
return '' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:decide_which_users_to_annotate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:centrality_vector; 5, identifier:number_to_annotate; 6, identifier:already_annotated; 7, identifier:node_to_id; 8, block; 8, 9; 8, 18; 8, 32; 8, 66; 8, 72; 8, 78; 8, 82; 8, 112; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:centrality_vector; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:asarray; 16, argument_list; 16, 17; 17, identifier:centrality_vector; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:ind; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:argsort; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:np; 29, identifier:squeeze; 30, argument_list; 30, 31; 31, identifier:centrality_vector; 32, if_statement; 32, 33; 32, 38; 32, 49; 33, comparison_operator:>; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:centrality_vector; 36, identifier:size; 37, integer:1; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:reversed_ind; 42, subscript; 42, 43; 42, 44; 43, identifier:ind; 44, slice; 44, 45; 44, 46; 44, 47; 45, colon; 46, colon; 47, unary_operator:-; 47, 48; 48, integer:1; 49, else_clause; 49, 50; 50, block; 50, 51; 50, 57; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:reversed_ind; 54, call; 54, 55; 54, 56; 55, identifier:list; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:reversed_ind; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:reversed_ind; 63, identifier:append; 64, argument_list; 64, 65; 65, identifier:ind; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:user_id_list; 69, call; 69, 70; 69, 71; 70, identifier:list; 71, argument_list; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:append_user_id; 75, attribute; 75, 76; 75, 77; 76, identifier:user_id_list; 77, identifier:append; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:counter; 81, integer:0; 82, for_statement; 82, 83; 82, 84; 82, 85; 83, identifier:node; 84, identifier:reversed_ind; 85, block; 85, 86; 85, 92; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:user_twitter_id; 89, subscript; 89, 90; 89, 91; 90, identifier:node_to_id; 91, identifier:node; 92, if_statement; 92, 93; 92, 96; 93, comparison_operator:not; 93, 94; 93, 95; 94, identifier:user_twitter_id; 95, identifier:already_annotated; 96, block; 96, 97; 96, 102; 96, 106; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:append_user_id; 100, argument_list; 100, 101; 101, identifier:user_twitter_id; 102, expression_statement; 102, 103; 103, augmented_assignment:+=; 103, 104; 103, 105; 104, identifier:counter; 105, integer:1; 106, if_statement; 106, 107; 106, 110; 107, comparison_operator:>=; 107, 108; 107, 109; 108, identifier:counter; 109, identifier:number_to_annotate; 110, block; 110, 111; 111, break_statement; 112, return_statement; 112, 113; 113, identifier:user_id_list | def decide_which_users_to_annotate(centrality_vector,
number_to_annotate,
already_annotated,
node_to_id):
centrality_vector = np.asarray(centrality_vector)
ind = np.argsort(np.squeeze(centrality_vector))
if centrality_vector.size > 1:
reversed_ind = ind[::-1]
else:
reversed_ind = list()
reversed_ind = reversed_ind.append(ind)
user_id_list = list()
append_user_id = user_id_list.append
counter = 0
for node in reversed_ind:
user_twitter_id = node_to_id[node]
if user_twitter_id not in already_annotated:
append_user_id(user_twitter_id)
counter += 1
if counter >= number_to_annotate:
break
return user_id_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 24; 4, identifier:self; 5, identifier:query; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort_map; 8, dictionary; 8, 9; 8, 12; 8, 15; 8, 18; 8, 21; 9, pair; 9, 10; 9, 11; 10, string:'BoxSet'; 11, integer:0; 12, pair; 12, 13; 12, 14; 13, string:'Series'; 14, integer:1; 15, pair; 15, 16; 15, 17; 16, string:'Movie'; 17, integer:2; 18, pair; 18, 19; 18, 20; 19, string:'Audio'; 20, integer:3; 21, pair; 21, 22; 21, 23; 22, string:'Person'; 23, integer:4; 24, default_parameter; 24, 25; 24, 26; 25, identifier:strict_sort; 26, False; 27, block; 27, 28; 27, 30; 27, 40; 27, 58; 27, 72; 27, 84; 27, 91; 27, 112; 28, expression_statement; 28, 29; 29, string:'''Sends a search request to emby, returns results
|coro|
Parameters
----------
query : str
the search string to send to emby
sort_map : dict
is a dict of strings to ints. Strings should be item types, and
the ints are the priority of those types(for sorting).
lower valued(0) will appear first.
strict_sort : bool
if True, then only item types in the keys of sortmap will be
included in the results
Returns
-------
list
list of emby objects
'''; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:search_params; 33, dictionary; 33, 34; 33, 37; 34, pair; 34, 35; 34, 36; 35, string:'remote'; 36, False; 37, pair; 37, 38; 37, 39; 38, string:'searchTerm'; 39, identifier:query; 40, if_statement; 40, 41; 40, 42; 41, identifier:strict_sort; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:search_params; 47, string:'IncludeItemTypes'; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, string:','; 51, identifier:join; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:sort_map; 56, identifier:keys; 57, argument_list; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:json; 61, await; 61, 62; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:connector; 67, identifier:getJson; 68, argument_list; 68, 69; 68, 70; 69, string:'/Search/Hints/'; 70, dictionary_splat; 70, 71; 71, identifier:search_params; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:items; 75, await; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:process; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 83; 82, identifier:json; 83, string:"SearchHints"; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:m_size; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:sort_map; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:items; 94, call; 94, 95; 94, 96; 95, identifier:sorted; 96, argument_list; 96, 97; 96, 98; 97, identifier:items; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:key; 100, lambda; 100, 101; 100, 103; 101, lambda_parameters; 101, 102; 102, identifier:x; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:sort_map; 106, identifier:get; 107, argument_list; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:x; 110, identifier:type; 111, identifier:m_size; 112, return_statement; 112, 113; 113, identifier:items | async def search(self, query,
sort_map = {'BoxSet':0,'Series':1,'Movie':2,'Audio':3,'Person':4},
strict_sort = False):
'''Sends a search request to emby, returns results
|coro|
Parameters
----------
query : str
the search string to send to emby
sort_map : dict
is a dict of strings to ints. Strings should be item types, and
the ints are the priority of those types(for sorting).
lower valued(0) will appear first.
strict_sort : bool
if True, then only item types in the keys of sortmap will be
included in the results
Returns
-------
list
list of emby objects
'''
search_params = {
'remote' : False,
'searchTerm' : query
}
if strict_sort:
search_params['IncludeItemTypes'] = ','.join(sort_map.keys())
json = await self.connector.getJson('/Search/Hints/', **search_params)
items = await self.process(json["SearchHints"])
m_size = len(sort_map)
items = sorted(items, key = lambda x : sort_map.get(x.type, m_size))
return items |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:set_attribute_string; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:target; 5, identifier:name; 6, identifier:value; 7, block; 7, 8; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:set_attribute; 11, argument_list; 11, 12; 11, 13; 11, 14; 12, identifier:target; 13, identifier:name; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:np; 17, identifier:bytes_; 18, argument_list; 18, 19; 19, identifier:value | def set_attribute_string(target, name, value):
set_attribute(target, name, np.bytes_(value)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:__calculate_edge_weights; 3, parameters; 3, 4; 4, identifier:dfs_data; 5, block; 5, 6; 5, 12; 5, 16; 5, 38; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:graph; 9, subscript; 9, 10; 9, 11; 10, identifier:dfs_data; 11, string:'graph'; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:weights; 15, dictionary; 16, for_statement; 16, 17; 16, 18; 16, 23; 17, identifier:edge_id; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:graph; 21, identifier:get_all_edge_ids; 22, argument_list; 23, block; 23, 24; 23, 32; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:edge_weight; 27, call; 27, 28; 27, 29; 28, identifier:__edge_weight; 29, argument_list; 29, 30; 29, 31; 30, identifier:edge_id; 31, identifier:dfs_data; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:weights; 36, identifier:edge_id; 37, identifier:edge_weight; 38, return_statement; 38, 39; 39, identifier:weights | def __calculate_edge_weights(dfs_data):
graph = dfs_data['graph']
weights = {}
for edge_id in graph.get_all_edge_ids():
edge_weight = __edge_weight(edge_id, dfs_data)
weights[edge_id] = edge_weight
return weights |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:__sort_adjacency_lists; 3, parameters; 3, 4; 4, identifier:dfs_data; 5, block; 5, 6; 5, 10; 5, 16; 5, 22; 5, 28; 5, 121; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:new_adjacency_lists; 9, dictionary; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:adjacency_lists; 13, subscript; 13, 14; 13, 15; 14, identifier:dfs_data; 15, string:'adj'; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:edge_weights; 19, subscript; 19, 20; 19, 21; 20, identifier:dfs_data; 21, string:'edge_weights'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:edge_lookup; 25, subscript; 25, 26; 25, 27; 26, identifier:dfs_data; 27, string:'edge_lookup'; 28, for_statement; 28, 29; 28, 32; 28, 40; 29, pattern_list; 29, 30; 29, 31; 30, identifier:node_id; 31, identifier:adj_list; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:adjacency_lists; 38, identifier:items; 39, argument_list; 40, block; 40, 41; 40, 45; 40, 49; 40, 86; 40, 101; 40, 115; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:node_weight_lookup; 44, dictionary; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:frond_lookup; 48, dictionary; 49, for_statement; 49, 50; 49, 51; 49, 52; 50, identifier:node_b; 51, identifier:adj_list; 52, block; 52, 53; 52, 65; 52, 73; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:edge_id; 56, call; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:dfs_data; 60, string:'graph'; 61, identifier:get_first_edge_id_by_node_ids; 62, argument_list; 62, 63; 62, 64; 63, identifier:node_id; 64, identifier:node_b; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:node_weight_lookup; 69, identifier:node_b; 70, subscript; 70, 71; 70, 72; 71, identifier:edge_weights; 72, identifier:edge_id; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:frond_lookup; 77, identifier:node_b; 78, conditional_expression:if; 78, 79; 78, 80; 78, 85; 79, integer:1; 80, comparison_operator:==; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:edge_lookup; 83, identifier:edge_id; 84, string:'backedge'; 85, integer:2; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:new_list; 89, call; 89, 90; 89, 91; 90, identifier:sorted; 91, argument_list; 91, 92; 91, 93; 92, identifier:adj_list; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:key; 95, lambda; 95, 96; 95, 98; 96, lambda_parameters; 96, 97; 97, identifier:n; 98, subscript; 98, 99; 98, 100; 99, identifier:frond_lookup; 100, identifier:n; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:new_list; 105, identifier:sort; 106, argument_list; 106, 107; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:key; 109, lambda; 109, 110; 109, 112; 110, lambda_parameters; 110, 111; 111, identifier:n; 112, subscript; 112, 113; 112, 114; 113, identifier:node_weight_lookup; 114, identifier:n; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:new_adjacency_lists; 119, identifier:node_id; 120, identifier:new_list; 121, return_statement; 121, 122; 122, identifier:new_adjacency_lists | def __sort_adjacency_lists(dfs_data):
new_adjacency_lists = {}
adjacency_lists = dfs_data['adj']
edge_weights = dfs_data['edge_weights']
edge_lookup = dfs_data['edge_lookup']
for node_id, adj_list in list(adjacency_lists.items()):
node_weight_lookup = {}
frond_lookup = {}
for node_b in adj_list:
edge_id = dfs_data['graph'].get_first_edge_id_by_node_ids(node_id, node_b)
node_weight_lookup[node_b] = edge_weights[edge_id]
frond_lookup[node_b] = 1 if edge_lookup[edge_id] == 'backedge' else 2
new_list = sorted(adj_list, key=lambda n: frond_lookup[n])
new_list.sort(key=lambda n: node_weight_lookup[n])
new_adjacency_lists[node_id] = new_list
return new_adjacency_lists |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__edge_weight; 3, parameters; 3, 4; 3, 5; 4, identifier:edge_id; 5, identifier:dfs_data; 6, block; 6, 7; 6, 13; 6, 19; 6, 28; 6, 36; 6, 44; 6, 52; 6, 60; 6, 68; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:graph; 10, subscript; 10, 11; 10, 12; 11, identifier:dfs_data; 12, string:'graph'; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:edge_lookup; 16, subscript; 16, 17; 16, 18; 17, identifier:dfs_data; 18, string:'edge_lookup'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:edge; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:graph; 25, identifier:get_edge; 26, argument_list; 26, 27; 27, identifier:edge_id; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, pattern_list; 30, 31; 30, 32; 31, identifier:u; 32, identifier:v; 33, subscript; 33, 34; 33, 35; 34, identifier:edge; 35, string:'vertices'; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:d_u; 39, call; 39, 40; 39, 41; 40, identifier:D; 41, argument_list; 41, 42; 41, 43; 42, identifier:u; 43, identifier:dfs_data; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:d_v; 47, call; 47, 48; 47, 49; 48, identifier:D; 49, argument_list; 49, 50; 49, 51; 50, identifier:v; 51, identifier:dfs_data; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:lp_1; 55, call; 55, 56; 55, 57; 56, identifier:L1; 57, argument_list; 57, 58; 57, 59; 58, identifier:v; 59, identifier:dfs_data; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:d_lp_1; 63, call; 63, 64; 63, 65; 64, identifier:D; 65, argument_list; 65, 66; 65, 67; 66, identifier:lp_1; 67, identifier:dfs_data; 68, if_statement; 68, 69; 68, 78; 68, 83; 68, 95; 68, 109; 69, boolean_operator:and; 69, 70; 69, 75; 70, comparison_operator:==; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:edge_lookup; 73, identifier:edge_id; 74, string:'backedge'; 75, comparison_operator:<; 75, 76; 75, 77; 76, identifier:d_v; 77, identifier:d_u; 78, block; 78, 79; 79, return_statement; 79, 80; 80, binary_operator:*; 80, 81; 80, 82; 81, integer:2; 82, identifier:d_v; 83, elif_clause; 83, 84; 83, 90; 84, call; 84, 85; 84, 86; 85, identifier:is_type_I_branch; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, identifier:u; 88, identifier:v; 89, identifier:dfs_data; 90, block; 90, 91; 91, return_statement; 91, 92; 92, binary_operator:*; 92, 93; 92, 94; 93, integer:2; 94, identifier:d_lp_1; 95, elif_clause; 95, 96; 95, 102; 96, call; 96, 97; 96, 98; 97, identifier:is_type_II_branch; 98, argument_list; 98, 99; 98, 100; 98, 101; 99, identifier:u; 100, identifier:v; 101, identifier:dfs_data; 102, block; 102, 103; 103, return_statement; 103, 104; 104, binary_operator:+; 104, 105; 104, 108; 105, binary_operator:*; 105, 106; 105, 107; 106, integer:2; 107, identifier:d_lp_1; 108, integer:1; 109, else_clause; 109, 110; 110, block; 110, 111; 111, return_statement; 111, 112; 112, binary_operator:+; 112, 113; 112, 120; 113, binary_operator:*; 113, 114; 113, 115; 114, integer:2; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:graph; 118, identifier:num_nodes; 119, argument_list; 120, integer:1 | def __edge_weight(edge_id, dfs_data):
graph = dfs_data['graph']
edge_lookup = dfs_data['edge_lookup']
edge = graph.get_edge(edge_id)
u, v = edge['vertices']
d_u = D(u, dfs_data)
d_v = D(v, dfs_data)
lp_1 = L1(v, dfs_data)
d_lp_1 = D(lp_1, dfs_data)
if edge_lookup[edge_id] == 'backedge' and d_v < d_u:
return 2*d_v
elif is_type_I_branch(u, v, dfs_data):
return 2*d_lp_1
elif is_type_II_branch(u, v, dfs_data):
return 2*d_lp_1 + 1
else:
return 2*graph.num_nodes() + 1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:classify_segmented_recording; 3, parameters; 3, 4; 3, 5; 4, identifier:recording; 5, default_parameter; 5, 6; 5, 7; 6, identifier:result_format; 7, None; 8, block; 8, 9; 8, 11; 8, 22; 9, global_statement; 9, 10; 10, identifier:single_symbol_classifier; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:single_symbol_classifier; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:single_symbol_classifier; 19, call; 19, 20; 19, 21; 20, identifier:SingleClassificer; 21, argument_list; 22, return_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:single_symbol_classifier; 26, identifier:predict; 27, argument_list; 27, 28; 27, 29; 28, identifier:recording; 29, identifier:result_format | def classify_segmented_recording(recording, result_format=None):
global single_symbol_classifier
if single_symbol_classifier is None:
single_symbol_classifier = SingleClassificer()
return single_symbol_classifier.predict(recording, result_format) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by_formula_id; 3, parameters; 3, 4; 4, identifier:raw_datasets; 5, block; 5, 6; 5, 13; 5, 32; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:by_formula_id; 9, call; 9, 10; 9, 11; 10, identifier:defaultdict; 11, argument_list; 11, 12; 12, identifier:list; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:el; 15, identifier:raw_datasets; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 28; 19, attribute; 19, 20; 19, 27; 20, subscript; 20, 21; 20, 22; 21, identifier:by_formula_id; 22, attribute; 22, 23; 22, 26; 23, subscript; 23, 24; 23, 25; 24, identifier:el; 25, string:'handwriting'; 26, identifier:formula_id; 27, identifier:append; 28, argument_list; 28, 29; 29, subscript; 29, 30; 29, 31; 30, identifier:el; 31, string:'handwriting'; 32, return_statement; 32, 33; 33, identifier:by_formula_id | def sort_by_formula_id(raw_datasets):
by_formula_id = defaultdict(list)
for el in raw_datasets:
by_formula_id[el['handwriting'].formula_id].append(el['handwriting'])
return by_formula_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_sorted_pointlist; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 43; 5, 60; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:pointlist; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:get_pointlist; 13, argument_list; 14, for_statement; 14, 15; 14, 16; 14, 23; 15, identifier:i; 16, call; 16, 17; 16, 18; 17, identifier:range; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:pointlist; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:pointlist; 28, identifier:i; 29, call; 29, 30; 29, 31; 30, identifier:sorted; 31, argument_list; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:pointlist; 34, identifier:i; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:key; 37, lambda; 37, 38; 37, 40; 38, lambda_parameters; 38, 39; 39, identifier:p; 40, subscript; 40, 41; 40, 42; 41, identifier:p; 42, string:'time'; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:pointlist; 46, call; 46, 47; 46, 48; 47, identifier:sorted; 48, argument_list; 48, 49; 48, 50; 49, identifier:pointlist; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:key; 52, lambda; 52, 53; 52, 55; 53, lambda_parameters; 53, 54; 54, identifier:stroke; 55, subscript; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:stroke; 58, integer:0; 59, string:'time'; 60, return_statement; 60, 61; 61, identifier:pointlist | def get_sorted_pointlist(self):
pointlist = self.get_pointlist()
for i in range(len(pointlist)):
pointlist[i] = sorted(pointlist[i], key=lambda p: p['time'])
pointlist = sorted(pointlist, key=lambda stroke: stroke[0]['time'])
return pointlist |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_name; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:use_alias; 7, True; 8, block; 8, 9; 8, 24; 8, 41; 9, if_statement; 9, 10; 9, 13; 9, 18; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:desc; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:direction; 17, string:'DESC'; 18, else_clause; 18, 19; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:direction; 23, string:'ASC'; 24, if_statement; 24, 25; 24, 26; 25, identifier:use_alias; 26, block; 26, 27; 27, return_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:'{0} {1}'; 31, identifier:format; 32, argument_list; 32, 33; 32, 40; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:field; 38, identifier:get_identifier; 39, argument_list; 40, identifier:direction; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:'{0} {1}'; 45, identifier:format; 46, argument_list; 46, 47; 46, 54; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:field; 52, identifier:get_select_sql; 53, argument_list; 54, identifier:direction | def get_name(self, use_alias=True):
if self.desc:
direction = 'DESC'
else:
direction = 'ASC'
if use_alias:
return '{0} {1}'.format(self.field.get_identifier(), direction)
return '{0} {1}'.format(self.field.get_select_sql(), direction) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:order_by; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:field; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:table; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:desc; 13, False; 14, block; 14, 15; 14, 35; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:sorters; 21, identifier:append; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:Sorter; 25, argument_list; 25, 26; 25, 29; 25, 32; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:field; 28, identifier:field; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:table; 31, identifier:table; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:desc; 34, identifier:desc; 35, return_statement; 35, 36; 36, identifier:self | def order_by(self, field=None, table=None, desc=False):
self.sorters.append(Sorter(
field=field,
table=table,
desc=desc
))
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_by_tag; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:tag; 6, block; 6, 7; 7, return_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:AmpalContainer; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:sorted; 13, argument_list; 13, 14; 13, 15; 14, identifier:self; 15, keyword_argument; 15, 16; 15, 17; 16, identifier:key; 17, lambda; 17, 18; 17, 20; 18, lambda_parameters; 18, 19; 19, identifier:x; 20, subscript; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:x; 23, identifier:tags; 24, identifier:tag | def sort_by_tag(self, tag):
return AmpalContainer(sorted(self, key=lambda x: x.tags[tag])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:fit_heptad_register; 3, parameters; 3, 4; 4, identifier:crangles; 5, block; 5, 6; 5, 21; 5, 45; 5, 70; 5, 79; 5, 88; 5, 92; 5, 146; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:crangles; 9, list_comprehension; 9, 10; 9, 18; 10, conditional_expression:if; 10, 11; 10, 12; 10, 15; 11, identifier:x; 12, comparison_operator:>; 12, 13; 12, 14; 13, identifier:x; 14, integer:0; 15, binary_operator:+; 15, 16; 15, 17; 16, integer:360; 17, identifier:x; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:x; 20, identifier:crangles; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:hept_p; 24, list_comprehension; 24, 25; 24, 39; 25, binary_operator:+; 25, 26; 25, 32; 26, binary_operator:*; 26, 27; 26, 28; 27, identifier:x; 28, parenthesized_expression; 28, 29; 29, binary_operator:/; 29, 30; 29, 31; 30, float:360.0; 31, float:7.0; 32, parenthesized_expression; 32, 33; 33, binary_operator:/; 33, 34; 33, 38; 34, parenthesized_expression; 34, 35; 35, binary_operator:/; 35, 36; 35, 37; 36, float:360.0; 37, float:7.0; 38, float:2.0; 39, for_in_clause; 39, 40; 39, 41; 40, identifier:x; 41, call; 41, 42; 41, 43; 42, identifier:range; 43, argument_list; 43, 44; 44, integer:7; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:ideal_crangs; 48, list:[
hept_p[0],
hept_p[2],
hept_p[4],
hept_p[6],
hept_p[1],
hept_p[3],
hept_p[5]
]; 48, 49; 48, 52; 48, 55; 48, 58; 48, 61; 48, 64; 48, 67; 49, subscript; 49, 50; 49, 51; 50, identifier:hept_p; 51, integer:0; 52, subscript; 52, 53; 52, 54; 53, identifier:hept_p; 54, integer:2; 55, subscript; 55, 56; 55, 57; 56, identifier:hept_p; 57, integer:4; 58, subscript; 58, 59; 58, 60; 59, identifier:hept_p; 60, integer:6; 61, subscript; 61, 62; 61, 63; 62, identifier:hept_p; 63, integer:1; 64, subscript; 64, 65; 64, 66; 65, identifier:hept_p; 66, integer:3; 67, subscript; 67, 68; 67, 69; 68, identifier:hept_p; 69, integer:5; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:full_hept; 73, binary_operator://; 73, 74; 73, 78; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, identifier:crangles; 78, integer:7; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:ideal_crang_list; 82, binary_operator:*; 82, 83; 82, 84; 83, identifier:ideal_crangs; 84, parenthesized_expression; 84, 85; 85, binary_operator:+; 85, 86; 85, 87; 86, identifier:full_hept; 87, integer:2; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:fitting; 91, list:[]; 92, for_statement; 92, 93; 92, 94; 92, 98; 93, identifier:i; 94, call; 94, 95; 94, 96; 95, identifier:range; 96, argument_list; 96, 97; 97, integer:7; 98, block; 98, 99; 98, 111; 98, 126; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:ang_pairs; 102, call; 102, 103; 102, 104; 103, identifier:zip; 104, argument_list; 104, 105; 104, 106; 105, identifier:crangles; 106, subscript; 106, 107; 106, 108; 107, identifier:ideal_crang_list; 108, slice; 108, 109; 108, 110; 109, identifier:i; 110, colon; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:ang_diffs; 114, list_comprehension; 114, 115; 114, 121; 115, call; 115, 116; 115, 117; 116, identifier:abs; 117, argument_list; 117, 118; 118, binary_operator:-; 118, 119; 118, 120; 119, identifier:y; 120, identifier:x; 121, for_in_clause; 121, 122; 121, 125; 122, pattern_list; 122, 123; 122, 124; 123, identifier:x; 124, identifier:y; 125, identifier:ang_pairs; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:fitting; 130, identifier:append; 131, argument_list; 131, 132; 132, tuple; 132, 133; 132, 134; 132, 140; 133, identifier:i; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:numpy; 137, identifier:mean; 138, argument_list; 138, 139; 139, identifier:ang_diffs; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:numpy; 143, identifier:std; 144, argument_list; 144, 145; 145, identifier:ang_diffs; 146, return_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:sorted; 149, argument_list; 149, 150; 149, 151; 150, identifier:fitting; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:key; 153, lambda; 153, 154; 153, 156; 154, lambda_parameters; 154, 155; 155, identifier:x; 156, subscript; 156, 157; 156, 158; 157, identifier:x; 158, integer:1 | def fit_heptad_register(crangles):
crangles = [x if x > 0 else 360 + x for x in crangles]
hept_p = [x * (360.0 / 7.0) + ((360.0 / 7.0) / 2.0) for x in range(7)]
ideal_crangs = [
hept_p[0],
hept_p[2],
hept_p[4],
hept_p[6],
hept_p[1],
hept_p[3],
hept_p[5]
]
full_hept = len(crangles) // 7
ideal_crang_list = ideal_crangs * (full_hept + 2)
fitting = []
for i in range(7):
ang_pairs = zip(crangles, ideal_crang_list[i:])
ang_diffs = [abs(y - x) for x, y in ang_pairs]
fitting.append((i, numpy.mean(ang_diffs), numpy.std(ang_diffs)))
return sorted(fitting, key=lambda x: x[1]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:simplify; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 13; 5, 27; 5, 37; 5, 45; 5, 53; 5, 66; 5, 70; 5, 88; 5, 100; 5, 128; 5, 146; 5, 150; 5, 376; 5, 385; 5, 397; 5, 403; 5, 413; 5, 419; 6, if_statement; 6, 7; 6, 10; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:iscanonical; 10, block; 10, 11; 11, return_statement; 11, 12; 12, identifier:self; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:args; 16, list_comprehension; 16, 17; 16, 22; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:arg; 20, identifier:simplify; 21, argument_list; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:arg; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:args; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:expr; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:__class__; 34, argument_list; 34, 35; 35, list_splat; 35, 36; 36, identifier:args; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:expr; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:expr; 43, identifier:literalize; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:expr; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:expr; 51, identifier:flatten; 52, argument_list; 53, if_statement; 53, 54; 53, 61; 54, comparison_operator:in; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:annihilator; 58, attribute; 58, 59; 58, 60; 59, identifier:expr; 60, identifier:args; 61, block; 61, 62; 62, return_statement; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:annihilator; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:args; 69, list:[]; 70, for_statement; 70, 71; 70, 72; 70, 75; 71, identifier:arg; 72, attribute; 72, 73; 72, 74; 73, identifier:expr; 74, identifier:args; 75, block; 75, 76; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:not; 77, 78; 77, 79; 78, identifier:arg; 79, identifier:args; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:args; 85, identifier:append; 86, argument_list; 86, 87; 87, identifier:arg; 88, if_statement; 88, 89; 88, 95; 89, comparison_operator:==; 89, 90; 89, 94; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, identifier:args; 94, integer:1; 95, block; 95, 96; 96, return_statement; 96, 97; 97, subscript; 97, 98; 97, 99; 98, identifier:args; 99, integer:0; 100, if_statement; 100, 101; 100, 106; 101, comparison_operator:in; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:identity; 105, identifier:args; 106, block; 106, 107; 106, 116; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:args; 111, identifier:remove; 112, argument_list; 112, 113; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:identity; 116, if_statement; 116, 117; 116, 123; 117, comparison_operator:==; 117, 118; 117, 122; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, identifier:args; 122, integer:1; 123, block; 123, 124; 124, return_statement; 124, 125; 125, subscript; 125, 126; 125, 127; 126, identifier:args; 127, integer:0; 128, for_statement; 128, 129; 128, 130; 128, 131; 129, identifier:arg; 130, identifier:args; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 141; 133, comparison_operator:in; 133, 134; 133, 140; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:NOT; 138, argument_list; 138, 139; 139, identifier:arg; 140, identifier:args; 141, block; 141, 142; 142, return_statement; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:annihilator; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:i; 149, integer:0; 150, while_statement; 150, 151; 150, 159; 151, comparison_operator:<; 151, 152; 151, 153; 152, identifier:i; 153, binary_operator:-; 153, 154; 153, 158; 154, call; 154, 155; 154, 156; 155, identifier:len; 156, argument_list; 156, 157; 157, identifier:args; 158, integer:1; 159, block; 159, 160; 159, 166; 159, 172; 159, 187; 159, 372; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:j; 163, binary_operator:+; 163, 164; 163, 165; 164, identifier:i; 165, integer:1; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:ai; 169, subscript; 169, 170; 169, 171; 170, identifier:args; 171, identifier:i; 172, if_statement; 172, 173; 172, 181; 173, not_operator; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:isinstance; 176, argument_list; 176, 177; 176, 178; 177, identifier:ai; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:dual; 181, block; 181, 182; 181, 186; 182, expression_statement; 182, 183; 183, augmented_assignment:+=; 183, 184; 183, 185; 184, identifier:i; 185, integer:1; 186, continue_statement; 187, while_statement; 187, 188; 187, 194; 188, comparison_operator:<; 188, 189; 188, 190; 189, identifier:j; 190, call; 190, 191; 190, 192; 191, identifier:len; 192, argument_list; 192, 193; 193, identifier:args; 194, block; 194, 195; 194, 201; 194, 230; 194, 234; 194, 287; 194, 368; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:aj; 198, subscript; 198, 199; 198, 200; 199, identifier:args; 200, identifier:j; 201, if_statement; 201, 202; 201, 224; 202, boolean_operator:or; 202, 203; 202, 211; 203, not_operator; 203, 204; 204, call; 204, 205; 204, 206; 205, identifier:isinstance; 206, argument_list; 206, 207; 206, 208; 207, identifier:aj; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:dual; 211, comparison_operator:!=; 211, 212; 211, 218; 212, call; 212, 213; 212, 214; 213, identifier:len; 214, argument_list; 214, 215; 215, attribute; 215, 216; 215, 217; 216, identifier:ai; 217, identifier:args; 218, call; 218, 219; 218, 220; 219, identifier:len; 220, argument_list; 220, 221; 221, attribute; 221, 222; 221, 223; 222, identifier:aj; 223, identifier:args; 224, block; 224, 225; 224, 229; 225, expression_statement; 225, 226; 226, augmented_assignment:+=; 226, 227; 226, 228; 227, identifier:j; 228, integer:1; 229, continue_statement; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:negated; 233, None; 234, for_statement; 234, 235; 234, 236; 234, 239; 235, identifier:arg; 236, attribute; 236, 237; 236, 238; 237, identifier:ai; 238, identifier:args; 239, block; 239, 240; 240, if_statement; 240, 241; 240, 246; 240, 248; 240, 280; 241, comparison_operator:in; 241, 242; 241, 243; 242, identifier:arg; 243, attribute; 243, 244; 243, 245; 244, identifier:aj; 245, identifier:args; 246, block; 246, 247; 247, pass_statement; 248, elif_clause; 248, 249; 248, 263; 249, comparison_operator:in; 249, 250; 249, 260; 250, call; 250, 251; 250, 259; 251, attribute; 251, 252; 251, 258; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:NOT; 256, argument_list; 256, 257; 257, identifier:arg; 258, identifier:cancel; 259, argument_list; 260, attribute; 260, 261; 260, 262; 261, identifier:aj; 262, identifier:args; 263, block; 263, 264; 264, if_statement; 264, 265; 264, 268; 264, 273; 265, comparison_operator:is; 265, 266; 265, 267; 266, identifier:negated; 267, None; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:negated; 272, identifier:arg; 273, else_clause; 273, 274; 274, block; 274, 275; 274, 279; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:negated; 278, None; 279, break_statement; 280, else_clause; 280, 281; 281, block; 281, 282; 281, 286; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:negated; 285, None; 286, break_statement; 287, if_statement; 287, 288; 287, 291; 288, comparison_operator:is; 288, 289; 288, 290; 289, identifier:negated; 290, None; 291, block; 291, 292; 291, 296; 291, 305; 291, 312; 291, 342; 292, delete_statement; 292, 293; 293, subscript; 293, 294; 293, 295; 294, identifier:args; 295, identifier:j; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:aiargs; 299, call; 299, 300; 299, 301; 300, identifier:list; 301, argument_list; 301, 302; 302, attribute; 302, 303; 302, 304; 303, identifier:ai; 304, identifier:args; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:aiargs; 309, identifier:remove; 310, argument_list; 310, 311; 311, identifier:negated; 312, if_statement; 312, 313; 312, 319; 312, 328; 313, comparison_operator:==; 313, 314; 313, 318; 314, call; 314, 315; 314, 316; 315, identifier:len; 316, argument_list; 316, 317; 317, identifier:aiargs; 318, integer:1; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 325; 322, subscript; 322, 323; 322, 324; 323, identifier:args; 324, identifier:i; 325, subscript; 325, 326; 325, 327; 326, identifier:aiargs; 327, integer:0; 328, else_clause; 328, 329; 329, block; 329, 330; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 335; 332, subscript; 332, 333; 332, 334; 333, identifier:args; 334, identifier:i; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:dual; 339, argument_list; 339, 340; 340, list_splat; 340, 341; 341, identifier:aiargs; 342, if_statement; 342, 343; 342, 349; 342, 354; 343, comparison_operator:==; 343, 344; 343, 348; 344, call; 344, 345; 344, 346; 345, identifier:len; 346, argument_list; 346, 347; 347, identifier:args; 348, integer:1; 349, block; 349, 350; 350, return_statement; 350, 351; 351, subscript; 351, 352; 351, 353; 352, identifier:args; 353, integer:0; 354, else_clause; 354, 355; 355, block; 355, 356; 356, return_statement; 356, 357; 357, call; 357, 358; 357, 367; 358, attribute; 358, 359; 358, 366; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:self; 362, identifier:__class__; 363, argument_list; 363, 364; 364, list_splat; 364, 365; 365, identifier:args; 366, identifier:simplify; 367, argument_list; 368, expression_statement; 368, 369; 369, augmented_assignment:+=; 369, 370; 369, 371; 370, identifier:j; 371, integer:1; 372, expression_statement; 372, 373; 373, augmented_assignment:+=; 373, 374; 373, 375; 374, identifier:i; 375, integer:1; 376, expression_statement; 376, 377; 377, assignment; 377, 378; 377, 379; 378, identifier:args; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:self; 382, identifier:absorb; 383, argument_list; 383, 384; 384, identifier:args; 385, if_statement; 385, 386; 385, 392; 386, comparison_operator:==; 386, 387; 386, 391; 387, call; 387, 388; 387, 389; 388, identifier:len; 389, argument_list; 389, 390; 390, identifier:args; 391, integer:1; 392, block; 392, 393; 393, return_statement; 393, 394; 394, subscript; 394, 395; 394, 396; 395, identifier:args; 396, integer:0; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:args; 401, identifier:sort; 402, argument_list; 403, expression_statement; 403, 404; 404, assignment; 404, 405; 404, 406; 405, identifier:expr; 406, call; 406, 407; 406, 410; 407, attribute; 407, 408; 407, 409; 408, identifier:self; 409, identifier:__class__; 410, argument_list; 410, 411; 411, list_splat; 411, 412; 412, identifier:args; 413, expression_statement; 413, 414; 414, assignment; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, identifier:expr; 417, identifier:iscanonical; 418, True; 419, return_statement; 419, 420; 420, identifier:expr | def simplify(self):
if self.iscanonical:
return self
args = [arg.simplify() for arg in self.args]
expr = self.__class__(*args)
expr = expr.literalize()
expr = expr.flatten()
if self.annihilator in expr.args:
return self.annihilator
args = []
for arg in expr.args:
if arg not in args:
args.append(arg)
if len(args) == 1:
return args[0]
if self.identity in args:
args.remove(self.identity)
if len(args) == 1:
return args[0]
for arg in args:
if self.NOT(arg) in args:
return self.annihilator
i = 0
while i < len(args) - 1:
j = i + 1
ai = args[i]
if not isinstance(ai, self.dual):
i += 1
continue
while j < len(args):
aj = args[j]
if not isinstance(aj, self.dual) or len(ai.args) != len(aj.args):
j += 1
continue
negated = None
for arg in ai.args:
if arg in aj.args:
pass
elif self.NOT(arg).cancel() in aj.args:
if negated is None:
negated = arg
else:
negated = None
break
else:
negated = None
break
if negated is not None:
del args[j]
aiargs = list(ai.args)
aiargs.remove(negated)
if len(aiargs) == 1:
args[i] = aiargs[0]
else:
args[i] = self.dual(*aiargs)
if len(args) == 1:
return args[0]
else:
return self.__class__(*args).simplify()
j += 1
i += 1
args = self.absorb(args)
if len(args) == 1:
return args[0]
args.sort()
expr = self.__class__(*args)
expr.iscanonical = True
return expr |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_recordAndPrintHeadline; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:test; 6, identifier:error_class; 7, identifier:artifact; 8, block; 8, 9; 8, 13; 8, 62; 8, 83; 8, 90; 8, 104; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:is_error_class; 12, False; 13, for_statement; 13, 14; 13, 20; 13, 27; 14, pattern_list; 14, 15; 14, 16; 15, identifier:cls; 16, tuple_pattern; 16, 17; 16, 18; 16, 19; 17, identifier:storage; 18, identifier:label; 19, identifier:is_failure; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:errorClasses; 25, identifier:items; 26, argument_list; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 39; 29, boolean_operator:and; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:isclass; 32, argument_list; 32, 33; 33, identifier:error_class; 34, call; 34, 35; 34, 36; 35, identifier:issubclass; 36, argument_list; 36, 37; 36, 38; 37, identifier:error_class; 38, identifier:cls; 39, block; 39, 40; 39, 49; 39, 58; 40, if_statement; 40, 41; 40, 42; 41, identifier:is_failure; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:test; 47, identifier:passed; 48, False; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:storage; 53, identifier:append; 54, argument_list; 54, 55; 55, tuple; 55, 56; 55, 57; 56, identifier:test; 57, identifier:artifact; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:is_error_class; 61, True; 62, if_statement; 62, 63; 62, 65; 63, not_operator; 63, 64; 64, identifier:is_error_class; 65, block; 65, 66; 65, 77; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:errors; 72, identifier:append; 73, argument_list; 73, 74; 74, tuple; 74, 75; 74, 76; 75, identifier:test; 76, identifier:artifact; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:test; 81, identifier:passed; 82, False; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:is_any_failure; 86, boolean_operator:or; 86, 87; 86, 89; 87, not_operator; 87, 88; 88, identifier:is_error_class; 89, identifier:is_failure; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_printHeadline; 95, argument_list; 95, 96; 95, 100; 95, 101; 96, conditional_expression:if; 96, 97; 96, 98; 96, 99; 97, identifier:label; 98, identifier:is_error_class; 99, string:'ERROR'; 100, identifier:test; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:is_failure; 103, identifier:is_any_failure; 104, return_statement; 104, 105; 105, identifier:is_any_failure | def _recordAndPrintHeadline(self, test, error_class, artifact):
is_error_class = False
for cls, (storage, label, is_failure) in self.errorClasses.items():
if isclass(error_class) and issubclass(error_class, cls):
if is_failure:
test.passed = False
storage.append((test, artifact))
is_error_class = True
if not is_error_class:
self.errors.append((test, artifact))
test.passed = False
is_any_failure = not is_error_class or is_failure
self._printHeadline(label if is_error_class else 'ERROR',
test,
is_failure=is_any_failure)
return is_any_failure |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_decode_filename_to_unicode; 3, parameters; 3, 4; 4, identifier:f; 5, block; 5, 6; 5, 8; 5, 19; 5, 28; 6, expression_statement; 6, 7; 7, string:'''Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is'''; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:log; 12, identifier:debug; 13, argument_list; 13, 14; 13, 15; 14, string:'_decode_filename_to_unicode(%s)'; 15, call; 15, 16; 15, 17; 16, identifier:repr; 17, argument_list; 17, 18; 18, identifier:f; 19, if_statement; 19, 20; 19, 25; 20, call; 20, 21; 20, 22; 21, identifier:isinstance; 22, argument_list; 22, 23; 22, 24; 23, identifier:f; 24, identifier:unicode; 25, block; 25, 26; 26, return_statement; 26, 27; 27, identifier:f; 28, try_statement; 28, 29; 28, 41; 29, block; 29, 30; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:f; 34, identifier:decode; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:sys; 39, identifier:getfilesystemencoding; 40, argument_list; 41, except_clause; 41, 42; 41, 43; 42, identifier:UnicodeDecodeError; 43, block; 43, 44; 43, 53; 43, 62; 43, 84; 43, 93; 43, 101; 43, 114; 43, 122; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:charguess; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:chardet; 50, identifier:detect; 51, argument_list; 51, 52; 52, identifier:f; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:log; 57, identifier:debug; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, string:"chardet filename: %r -> %r"; 60, identifier:f; 61, identifier:charguess; 62, if_statement; 62, 63; 62, 68; 63, comparison_operator:is; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:charguess; 66, string:'encoding'; 67, None; 68, block; 68, 69; 69, try_statement; 69, 70; 69, 80; 70, block; 70, 71; 71, return_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:f; 75, identifier:decode; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:charguess; 79, string:'encoding'; 80, except_clause; 80, 81; 80, 82; 81, identifier:UnicodeDecodeError; 82, block; 82, 83; 83, pass_statement; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:log; 88, identifier:warning; 89, argument_list; 89, 90; 89, 91; 89, 92; 90, string:'Cannot understand decoding of this filename: %r (guessed %r, but was wrong)'; 91, identifier:f; 92, identifier:charguess; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:log; 97, identifier:debug; 98, argument_list; 98, 99; 98, 100; 99, string:'Trying utf-8 to decode %r'; 100, identifier:f; 101, try_statement; 101, 102; 101, 110; 102, block; 102, 103; 103, return_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:f; 107, identifier:decode; 108, argument_list; 108, 109; 109, string:'utf-8'; 110, except_clause; 110, 111; 110, 112; 111, identifier:UnicodeDecodeError; 112, block; 112, 113; 113, pass_statement; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:log; 118, identifier:debug; 119, argument_list; 119, 120; 119, 121; 120, string:'Trying latin1 to decode %r'; 121, identifier:f; 122, try_statement; 122, 123; 122, 131; 123, block; 123, 124; 124, return_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:f; 128, identifier:decode; 129, argument_list; 129, 130; 130, string:'latin1'; 131, except_clause; 131, 132; 131, 133; 132, identifier:UnicodeDecodeError; 133, block; 133, 134; 133, 142; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:log; 138, identifier:warning; 139, argument_list; 139, 140; 139, 141; 140, string:'Exhausted all options. Decoding %r to safe ascii'; 141, identifier:f; 142, return_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:f; 146, identifier:decode; 147, argument_list; 147, 148; 147, 149; 148, string:'ascii'; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:errors; 151, string:'ignore' | def _decode_filename_to_unicode(f):
'''Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is'''
log.debug('_decode_filename_to_unicode(%s)', repr(f))
if isinstance(f, unicode):
return f
try:
return f.decode(sys.getfilesystemencoding())
except UnicodeDecodeError:
charguess = chardet.detect(f)
log.debug("chardet filename: %r -> %r", f, charguess)
if charguess['encoding'] is not None:
try:
return f.decode(charguess['encoding'])
except UnicodeDecodeError:
pass
log.warning('Cannot understand decoding of this filename: %r (guessed %r, but was wrong)',
f, charguess)
log.debug('Trying utf-8 to decode %r', f)
try:
return f.decode('utf-8')
except UnicodeDecodeError:
pass
log.debug('Trying latin1 to decode %r', f)
try:
return f.decode('latin1')
except UnicodeDecodeError:
log.warning('Exhausted all options. Decoding %r to safe ascii', f)
return f.decode('ascii', errors='ignore') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sortBy; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:val; 7, None; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 13; 9, 66; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:val; 12, None; 13, block; 13, 14; 14, if_statement; 14, 15; 14, 23; 14, 49; 15, call; 15, 16; 15, 22; 16, attribute; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:_; 19, argument_list; 19, 20; 20, identifier:val; 21, identifier:isString; 22, argument_list; 23, block; 23, 24; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_wrap; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:sorted; 32, argument_list; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:obj; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:key; 38, lambda; 38, 39; 38, 43; 39, lambda_parameters; 39, 40; 39, 41; 40, identifier:x; 41, list_splat_pattern; 41, 42; 42, identifier:args; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:x; 46, identifier:get; 47, argument_list; 47, 48; 48, identifier:val; 49, else_clause; 49, 50; 50, block; 50, 51; 51, return_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_wrap; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:sorted; 59, argument_list; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:obj; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:key; 65, identifier:val; 66, else_clause; 66, 67; 67, block; 67, 68; 68, return_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_wrap; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:sorted; 76, argument_list; 76, 77; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:obj | def sortBy(self, val=None):
if val is not None:
if _(val).isString():
return self._wrap(sorted(self.obj, key=lambda x,
*args: x.get(val)))
else:
return self._wrap(sorted(self.obj, key=val))
else:
return self._wrap(sorted(self.obj)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:sortedIndex; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:obj; 6, default_parameter; 6, 7; 6, 8; 7, identifier:iterator; 8, lambda; 8, 9; 8, 11; 9, lambda_parameters; 9, 10; 10, identifier:x; 11, identifier:x; 12, block; 12, 13; 12, 19; 12, 26; 12, 30; 12, 37; 12, 73; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:array; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:obj; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:value; 22, call; 22, 23; 22, 24; 23, identifier:iterator; 24, argument_list; 24, 25; 25, identifier:obj; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:low; 29, integer:0; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:high; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, identifier:array; 37, while_statement; 37, 38; 37, 41; 38, comparison_operator:<; 38, 39; 38, 40; 39, identifier:low; 40, identifier:high; 41, block; 41, 42; 41, 51; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:mid; 45, binary_operator:>>; 45, 46; 45, 50; 46, parenthesized_expression; 46, 47; 47, binary_operator:+; 47, 48; 47, 49; 48, identifier:low; 49, identifier:high; 50, integer:1; 51, if_statement; 51, 52; 51, 60; 51, 67; 52, comparison_operator:<; 52, 53; 52, 59; 53, call; 53, 54; 53, 55; 54, identifier:iterator; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:array; 58, identifier:mid; 59, identifier:value; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:low; 64, binary_operator:+; 64, 65; 64, 66; 65, identifier:mid; 66, integer:1; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:high; 72, identifier:mid; 73, return_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_wrap; 78, argument_list; 78, 79; 79, identifier:low | def sortedIndex(self, obj, iterator=lambda x: x):
array = self.obj
value = iterator(obj)
low = 0
high = len(array)
while low < high:
mid = (low + high) >> 1
if iterator(array[mid]) < value:
low = mid + 1
else:
high = mid
return self._wrap(low) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:uniq; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:isSorted; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:iterator; 10, None; 11, block; 11, 12; 11, 20; 11, 26; 11, 34; 11, 40; 11, 59; 11, 116; 11, 126; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ns; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:Namespace; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:ns; 24, identifier:results; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:ns; 30, identifier:array; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:obj; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:initial; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:obj; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:iterator; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:initial; 48, call; 48, 49; 48, 57; 49, attribute; 49, 50; 49, 56; 50, call; 50, 51; 50, 52; 51, identifier:_; 52, argument_list; 52, 53; 53, attribute; 53, 54; 53, 55; 54, identifier:ns; 55, identifier:array; 56, identifier:map; 57, argument_list; 57, 58; 58, identifier:iterator; 59, function_definition; 59, 60; 59, 61; 59, 65; 60, function_name:by; 61, parameters; 61, 62; 61, 63; 61, 64; 62, identifier:memo; 63, identifier:value; 64, identifier:index; 65, block; 65, 66; 65, 114; 66, if_statement; 66, 67; 66, 93; 67, parenthesized_expression; 67, 68; 68, conditional_expression:if; 68, 69; 68, 84; 68, 85; 69, parenthesized_expression; 69, 70; 70, boolean_operator:or; 70, 71; 70, 79; 71, comparison_operator:!=; 71, 72; 71, 78; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:_; 75, identifier:last; 76, argument_list; 76, 77; 77, identifier:memo; 78, identifier:value; 79, not_operator; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:memo; 84, identifier:isSorted; 85, not_operator; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:_; 89, identifier:include; 90, argument_list; 90, 91; 90, 92; 91, identifier:memo; 92, identifier:value; 93, block; 93, 94; 93, 101; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:memo; 98, identifier:append; 99, argument_list; 99, 100; 100, identifier:value; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:ns; 106, identifier:results; 107, identifier:append; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:ns; 112, identifier:array; 113, identifier:index; 114, return_statement; 114, 115; 115, identifier:memo; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:ret; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:_; 122, identifier:reduce; 123, argument_list; 123, 124; 123, 125; 124, identifier:initial; 125, identifier:by; 126, return_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:_wrap; 131, argument_list; 131, 132; 132, identifier:ret | def uniq(self, isSorted=False, iterator=None):
ns = self.Namespace()
ns.results = []
ns.array = self.obj
initial = self.obj
if iterator is not None:
initial = _(ns.array).map(iterator)
def by(memo, value, index):
if ((_.last(memo) != value or
not len(memo)) if isSorted else not _.include(memo, value)):
memo.append(value)
ns.results.append(ns.array[index])
return memo
ret = _.reduce(initial, by)
return self._wrap(ret) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:functions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 42; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:names; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 20; 11, pattern_list; 11, 12; 11, 13; 12, identifier:i; 13, identifier:k; 14, call; 14, 15; 14, 16; 15, identifier:enumerate; 16, argument_list; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:obj; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 34; 22, call; 22, 23; 22, 33; 23, attribute; 23, 24; 23, 32; 24, call; 24, 25; 24, 26; 25, identifier:_; 26, argument_list; 26, 27; 27, subscript; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:obj; 31, identifier:k; 32, identifier:isCallable; 33, argument_list; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:names; 39, identifier:append; 40, argument_list; 40, 41; 41, identifier:k; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_wrap; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:sorted; 50, argument_list; 50, 51; 51, identifier:names | def functions(self):
names = []
for i, k in enumerate(self.obj):
if _(self.obj[k]).isCallable():
names.append(k)
return self._wrap(sorted(names)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:createMSBWTFromBam; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:bamFNs; 5, identifier:outputDir; 6, identifier:numProcs; 7, identifier:areUniform; 8, identifier:logger; 9, block; 9, 10; 9, 12; 9, 19; 9, 25; 9, 31; 9, 37; 9, 43; 9, 50; 9, 60; 10, expression_statement; 10, 11; 11, string:'''
This function takes a fasta filename and creates the BWT using the technique from Cox and Bauer
@param bamFNs - a list of BAM filenames to extract sequences from, READS MUST BE SORTED BY NAME
@param outputDir - the directory for all of the bwt related data
@param numProcs - the number of processes it's allowed to use
@areUniform - true if all the sequences passed into the function are of equal length
'''; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:logger; 16, identifier:info; 17, argument_list; 17, 18; 18, string:'Saving sorted sequences...'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:seqFN; 22, binary_operator:+; 22, 23; 22, 24; 23, identifier:outputDir; 24, string:'/seqs.npy'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:offsetFN; 28, binary_operator:+; 28, 29; 28, 30; 29, identifier:outputDir; 30, string:'/offsets.npy'; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:abtFN; 34, binary_operator:+; 34, 35; 34, 36; 35, identifier:outputDir; 36, string:'/about.npy'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:bwtFN; 40, binary_operator:+; 40, 41; 40, 42; 41, identifier:outputDir; 42, string:'/msbwt.npy'; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:MSBWTGen; 47, identifier:clearAuxiliaryData; 48, argument_list; 48, 49; 49, identifier:outputDir; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:preprocessBams; 53, argument_list; 53, 54; 53, 55; 53, 56; 53, 57; 53, 58; 53, 59; 54, identifier:bamFNs; 55, identifier:seqFN; 56, identifier:offsetFN; 57, identifier:abtFN; 58, identifier:areUniform; 59, identifier:logger; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:MSBWTGen; 64, identifier:createFromSeqs; 65, argument_list; 65, 66; 65, 67; 65, 68; 65, 69; 65, 70; 65, 71; 66, identifier:seqFN; 67, identifier:offsetFN; 68, identifier:bwtFN; 69, identifier:numProcs; 70, identifier:areUniform; 71, identifier:logger | def createMSBWTFromBam(bamFNs, outputDir, numProcs, areUniform, logger):
'''
This function takes a fasta filename and creates the BWT using the technique from Cox and Bauer
@param bamFNs - a list of BAM filenames to extract sequences from, READS MUST BE SORTED BY NAME
@param outputDir - the directory for all of the bwt related data
@param numProcs - the number of processes it's allowed to use
@areUniform - true if all the sequences passed into the function are of equal length
'''
logger.info('Saving sorted sequences...')
seqFN = outputDir+'/seqs.npy'
offsetFN = outputDir+'/offsets.npy'
abtFN = outputDir+'/about.npy'
bwtFN = outputDir+'/msbwt.npy'
MSBWTGen.clearAuxiliaryData(outputDir)
preprocessBams(bamFNs, seqFN, offsetFN, abtFN, areUniform, logger)
MSBWTGen.createFromSeqs(seqFN, offsetFN, bwtFN, numProcs, areUniform, logger) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:append_responder; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 8; 4, identifier:self; 5, identifier:matcher; 6, list_splat_pattern; 6, 7; 7, identifier:args; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_insert_responder; 16, argument_list; 16, 17; 16, 18; 16, 19; 16, 21; 17, string:"bottom"; 18, identifier:matcher; 19, list_splat; 19, 20; 20, identifier:args; 21, dictionary_splat; 21, 22; 22, identifier:kwargs | def append_responder(self, matcher, *args, **kwargs):
return self._insert_responder("bottom", matcher, *args, **kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:unique_list_dicts; 3, parameters; 3, 4; 3, 5; 4, identifier:dlist; 5, identifier:key; 6, block; 6, 7; 7, return_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:list; 10, argument_list; 10, 11; 11, call; 11, 12; 11, 25; 12, attribute; 12, 13; 12, 24; 13, call; 13, 14; 13, 15; 14, identifier:dict; 15, generator_expression; 15, 16; 15, 21; 16, tuple; 16, 17; 16, 20; 17, subscript; 17, 18; 17, 19; 18, identifier:val; 19, identifier:key; 20, identifier:val; 21, for_in_clause; 21, 22; 21, 23; 22, identifier:val; 23, identifier:dlist; 24, identifier:values; 25, argument_list | def unique_list_dicts(dlist, key):
return list(dict((val[key], val) for val in dlist).values()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_bmu; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:activations; 6, block; 6, 7; 6, 19; 6, 29; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:==; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:argfunc; 12, string:'argmax'; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:activations; 17, unary_operator:-; 17, 18; 18, identifier:activations; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:sort; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:np; 25, identifier:argsort; 26, argument_list; 26, 27; 26, 28; 27, identifier:activations; 28, integer:1; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:sort; 33, identifier:argsort; 34, argument_list | def _get_bmu(self, activations):
if self.argfunc == 'argmax':
activations = -activations
sort = np.argsort(activations, 1)
return sort.argsort() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:sort_versions; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:versions; 6, tuple; 7, default_parameter; 7, 8; 7, 9; 8, identifier:reverse; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sep; 12, string:u'.'; 13, block; 13, 14; 13, 21; 13, 25; 13, 47; 13, 54; 13, 68; 13, 232; 13, 236; 13, 246; 13, 280; 13, 287; 13, 359; 13, 369; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:==; 15, 16; 15, 17; 16, identifier:versions; 17, list:[]; 18, block; 18, 19; 19, return_statement; 19, 20; 20, list:[]; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:digits; 24, string:u'0123456789'; 25, function_definition; 25, 26; 25, 27; 25, 29; 26, function_name:toint; 27, parameters; 27, 28; 28, identifier:x; 29, block; 29, 30; 29, 45; 30, try_statement; 30, 31; 30, 39; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:n; 35, call; 35, 36; 35, 37; 36, identifier:int; 37, argument_list; 37, 38; 38, identifier:x; 39, except_clause; 39, 40; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:n; 44, identifier:x; 45, return_statement; 45, 46; 46, identifier:n; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:versions; 50, call; 50, 51; 50, 52; 51, identifier:list; 52, argument_list; 52, 53; 53, identifier:versions; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 60; 56, pattern_list; 56, 57; 56, 58; 56, 59; 57, identifier:new_versions; 58, identifier:alpha; 59, identifier:sizes; 60, expression_list; 60, 61; 60, 62; 60, 65; 61, list:[]; 62, call; 62, 63; 62, 64; 63, identifier:set; 64, argument_list; 65, call; 65, 66; 65, 67; 66, identifier:set; 67, argument_list; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:item; 70, identifier:versions; 71, block; 71, 72; 71, 81; 71, 85; 71, 215; 71, 225; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:it; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:item; 78, identifier:split; 79, argument_list; 79, 80; 80, identifier:sep; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:temp; 84, list:[]; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:i; 87, identifier:it; 88, block; 88, 89; 88, 96; 88, 211; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:x; 92, call; 92, 93; 92, 94; 93, identifier:toint; 94, argument_list; 94, 95; 95, identifier:i; 96, if_statement; 96, 97; 96, 103; 96, 204; 97, not_operator; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:isinstance; 100, argument_list; 100, 101; 100, 102; 101, identifier:x; 102, identifier:int; 103, block; 103, 104; 103, 111; 103, 125; 103, 143; 103, 161; 103, 168; 103, 175; 103, 187; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:x; 107, call; 107, 108; 107, 109; 108, identifier:u; 109, argument_list; 109, 110; 110, identifier:x; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:middle; 114, call; 114, 115; 114, 123; 115, attribute; 115, 116; 115, 122; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:x; 119, identifier:lstrip; 120, argument_list; 120, 121; 121, identifier:digits; 122, identifier:rstrip; 123, argument_list; 123, 124; 124, identifier:digits; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:tail; 128, call; 128, 129; 128, 130; 129, identifier:toint; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 140; 132, attribute; 132, 133; 132, 139; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:x; 136, identifier:lstrip; 137, argument_list; 137, 138; 138, identifier:digits; 139, identifier:replace; 140, argument_list; 140, 141; 140, 142; 141, identifier:middle; 142, string:u''; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:head; 146, call; 146, 147; 146, 148; 147, identifier:toint; 148, argument_list; 148, 149; 149, call; 149, 150; 149, 158; 150, attribute; 150, 151; 150, 157; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:x; 154, identifier:rstrip; 155, argument_list; 155, 156; 156, identifier:digits; 157, identifier:replace; 158, argument_list; 158, 159; 158, 160; 159, identifier:middle; 160, string:u''; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:middle; 164, call; 164, 165; 164, 166; 165, identifier:toint; 166, argument_list; 166, 167; 167, identifier:middle; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:res; 171, list:[head, middle, tail]; 171, 172; 171, 173; 171, 174; 172, identifier:head; 173, identifier:middle; 174, identifier:tail; 175, while_statement; 175, 176; 175, 179; 176, comparison_operator:in; 176, 177; 176, 178; 177, string:u''; 178, identifier:res; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:res; 184, identifier:remove; 185, argument_list; 185, 186; 186, string:u''; 187, for_statement; 187, 188; 187, 189; 187, 190; 188, identifier:r; 189, identifier:res; 190, block; 190, 191; 191, if_statement; 191, 192; 191, 196; 192, call; 192, 193; 192, 194; 193, identifier:is_unicode; 194, argument_list; 194, 195; 195, identifier:r; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:alpha; 201, identifier:add; 202, argument_list; 202, 203; 203, identifier:r; 204, else_clause; 204, 205; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:res; 209, list:[x]; 209, 210; 210, identifier:x; 211, expression_statement; 211, 212; 212, augmented_assignment:+=; 212, 213; 212, 214; 213, identifier:temp; 214, identifier:res; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:sizes; 219, identifier:add; 220, argument_list; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:len; 223, argument_list; 223, 224; 224, identifier:temp; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:new_versions; 229, identifier:append; 230, argument_list; 230, 231; 231, identifier:temp; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:replace_dic; 235, dictionary; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:alpha; 239, call; 239, 240; 239, 241; 240, identifier:sorted; 241, argument_list; 241, 242; 241, 243; 242, identifier:alpha; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:reverse; 245, True; 246, if_statement; 246, 247; 246, 251; 247, call; 247, 248; 247, 249; 248, identifier:len; 249, argument_list; 249, 250; 250, identifier:alpha; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:replace_dic; 255, call; 255, 256; 255, 257; 256, identifier:dict; 257, argument_list; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:zip; 260, argument_list; 260, 261; 260, 262; 261, identifier:alpha; 262, call; 262, 263; 262, 264; 263, identifier:list; 264, argument_list; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:range; 267, argument_list; 267, 268; 267, 270; 267, 278; 268, unary_operator:-; 268, 269; 269, integer:1; 270, unary_operator:-; 270, 271; 271, parenthesized_expression; 271, 272; 272, binary_operator:+; 272, 273; 272, 277; 273, call; 273, 274; 273, 275; 274, identifier:len; 275, argument_list; 275, 276; 276, identifier:alpha; 277, integer:1; 278, unary_operator:-; 278, 279; 279, integer:1; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:nmax; 283, call; 283, 284; 283, 285; 284, identifier:max; 285, argument_list; 285, 286; 286, identifier:sizes; 287, for_statement; 287, 288; 287, 289; 287, 296; 288, identifier:i; 289, call; 289, 290; 289, 291; 290, identifier:range; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:len; 294, argument_list; 294, 295; 295, identifier:new_versions; 296, block; 296, 297; 296, 301; 296, 330; 296, 339; 296, 346; 296, 353; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:item; 300, list:[]; 301, for_statement; 301, 302; 301, 303; 301, 306; 302, identifier:z; 303, subscript; 303, 304; 303, 305; 304, identifier:new_versions; 305, identifier:i; 306, block; 306, 307; 307, if_statement; 307, 308; 307, 311; 307, 321; 308, comparison_operator:in; 308, 309; 308, 310; 309, identifier:z; 310, identifier:replace_dic; 311, block; 311, 312; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:item; 316, identifier:append; 317, argument_list; 317, 318; 318, subscript; 318, 319; 318, 320; 319, identifier:replace_dic; 320, identifier:z; 321, else_clause; 321, 322; 322, block; 322, 323; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:item; 327, identifier:append; 328, argument_list; 328, 329; 329, identifier:z; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 333; 332, identifier:nzeros; 333, binary_operator:-; 333, 334; 333, 335; 334, identifier:nmax; 335, call; 335, 336; 335, 337; 336, identifier:len; 337, argument_list; 337, 338; 338, identifier:item; 339, expression_statement; 339, 340; 340, augmented_assignment:+=; 340, 341; 340, 342; 341, identifier:item; 342, binary_operator:*; 342, 343; 342, 345; 343, list:[0]; 343, 344; 344, integer:0; 345, identifier:nzeros; 346, expression_statement; 346, 347; 347, augmented_assignment:+=; 347, 348; 347, 349; 348, identifier:item; 349, list:[versions[i]]; 349, 350; 350, subscript; 350, 351; 350, 352; 351, identifier:versions; 352, identifier:i; 353, expression_statement; 353, 354; 354, assignment; 354, 355; 354, 358; 355, subscript; 355, 356; 355, 357; 356, identifier:new_versions; 357, identifier:i; 358, identifier:item; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 362; 361, identifier:new_versions; 362, call; 362, 363; 362, 364; 363, identifier:sorted; 364, argument_list; 364, 365; 364, 366; 365, identifier:new_versions; 366, keyword_argument; 366, 367; 366, 368; 367, identifier:reverse; 368, identifier:reverse; 369, return_statement; 369, 370; 370, list_comprehension; 370, 371; 370, 375; 371, subscript; 371, 372; 371, 373; 372, identifier:n; 373, unary_operator:-; 373, 374; 374, integer:1; 375, for_in_clause; 375, 376; 375, 377; 376, identifier:n; 377, identifier:new_versions | def sort_versions(versions=(), reverse=False, sep=u'.'):
if versions == []:
return []
digits = u'0123456789'
def toint(x):
try:
n = int(x)
except:
n = x
return n
versions = list(versions)
new_versions, alpha, sizes = [], set(), set()
for item in versions:
it = item.split(sep)
temp = []
for i in it:
x = toint(i)
if not isinstance(x, int):
x = u(x)
middle = x.lstrip(digits).rstrip(digits)
tail = toint(x.lstrip(digits).replace(middle, u''))
head = toint(x.rstrip(digits).replace(middle, u''))
middle = toint(middle)
res = [head, middle, tail]
while u'' in res:
res.remove(u'')
for r in res:
if is_unicode(r):
alpha.add(r)
else:
res = [x]
temp += res
sizes.add(len(temp))
new_versions.append(temp)
replace_dic = {}
alpha = sorted(alpha, reverse=True)
if len(alpha):
replace_dic = dict(zip(alpha, list(range(-1, -(len(alpha)+1), -1))))
nmax = max(sizes)
for i in range(len(new_versions)):
item = []
for z in new_versions[i]:
if z in replace_dic:
item.append(replace_dic[z])
else:
item.append(z)
nzeros = nmax - len(item)
item += [0]*nzeros
item += [versions[i]]
new_versions[i] = item
new_versions = sorted(new_versions, reverse=reverse)
return [n[-1] for n in new_versions] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:make_qq_plot; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:kev; 5, identifier:obs; 6, identifier:mdl; 7, identifier:unit; 8, identifier:key_text; 9, block; 9, 10; 9, 15; 9, 24; 9, 33; 9, 42; 9, 51; 9, 60; 9, 74; 9, 82; 9, 95; 9, 104; 9, 129; 9, 135; 9, 141; 9, 254; 9, 266; 9, 274; 10, import_statement; 10, 11; 11, aliased_import; 11, 12; 11, 14; 12, dotted_name; 12, 13; 13, identifier:omega; 14, identifier:om; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:kev; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:asarray; 22, argument_list; 22, 23; 23, identifier:kev; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:obs; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:np; 30, identifier:asarray; 31, argument_list; 31, 32; 32, identifier:obs; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:mdl; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:asarray; 40, argument_list; 40, 41; 41, identifier:mdl; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:c_obs; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:np; 48, identifier:cumsum; 49, argument_list; 49, 50; 50, identifier:obs; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:c_mdl; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:np; 57, identifier:cumsum; 58, argument_list; 58, 59; 59, identifier:mdl; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:mx; 63, call; 63, 64; 63, 65; 64, identifier:max; 65, argument_list; 65, 66; 65, 70; 66, subscript; 66, 67; 66, 68; 67, identifier:c_obs; 68, unary_operator:-; 68, 69; 69, integer:1; 70, subscript; 70, 71; 70, 72; 71, identifier:c_mdl; 72, unary_operator:-; 72, 73; 73, integer:1; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:p; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:om; 80, identifier:RectPlot; 81, argument_list; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:p; 86, identifier:addXY; 87, argument_list; 87, 88; 87, 91; 87, 94; 88, list:[0, mx]; 88, 89; 88, 90; 89, integer:0; 90, identifier:mx; 91, list:[0, mx]; 91, 92; 91, 93; 92, integer:0; 93, identifier:mx; 94, string:'1:1'; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:p; 99, identifier:addXY; 100, argument_list; 100, 101; 100, 102; 100, 103; 101, identifier:c_mdl; 102, identifier:c_obs; 103, identifier:key_text; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:locs; 107, binary_operator:*; 107, 108; 107, 123; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:np; 111, identifier:array; 112, argument_list; 112, 113; 113, list:[0, 0.05, 0.08, 0.11, 0.17, 0.3, 0.4, 0.7, 1]; 113, 114; 113, 115; 113, 116; 113, 117; 113, 118; 113, 119; 113, 120; 113, 121; 113, 122; 114, integer:0; 115, float:0.05; 116, float:0.08; 117, float:0.11; 118, float:0.17; 119, float:0.3; 120, float:0.4; 121, float:0.7; 122, integer:1; 123, parenthesized_expression; 123, 124; 124, binary_operator:-; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:kev; 127, identifier:size; 128, integer:2; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:c0; 132, binary_operator:*; 132, 133; 132, 134; 133, identifier:mx; 134, float:1.05; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:c1; 138, binary_operator:*; 138, 139; 138, 140; 139, identifier:mx; 140, float:1.1; 141, for_statement; 141, 142; 141, 143; 141, 144; 142, identifier:loc; 143, identifier:locs; 144, block; 144, 145; 144, 157; 144, 163; 144, 182; 144, 201; 144, 220; 144, 238; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:i0; 148, call; 148, 149; 148, 150; 149, identifier:int; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:np; 154, identifier:floor; 155, argument_list; 155, 156; 156, identifier:loc; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:frac; 160, binary_operator:-; 160, 161; 160, 162; 161, identifier:loc; 162, identifier:i0; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:kevval; 166, binary_operator:+; 166, 167; 166, 175; 167, binary_operator:*; 167, 168; 167, 172; 168, parenthesized_expression; 168, 169; 169, binary_operator:-; 169, 170; 169, 171; 170, integer:1; 171, identifier:frac; 172, subscript; 172, 173; 172, 174; 173, identifier:kev; 174, identifier:i0; 175, binary_operator:*; 175, 176; 175, 177; 176, identifier:frac; 177, subscript; 177, 178; 177, 179; 178, identifier:kev; 179, binary_operator:+; 179, 180; 179, 181; 180, identifier:i0; 181, integer:1; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:mdlval; 185, binary_operator:+; 185, 186; 185, 194; 186, binary_operator:*; 186, 187; 186, 191; 187, parenthesized_expression; 187, 188; 188, binary_operator:-; 188, 189; 188, 190; 189, integer:1; 190, identifier:frac; 191, subscript; 191, 192; 191, 193; 192, identifier:c_mdl; 193, identifier:i0; 194, binary_operator:*; 194, 195; 194, 196; 195, identifier:frac; 196, subscript; 196, 197; 196, 198; 197, identifier:c_mdl; 198, binary_operator:+; 198, 199; 198, 200; 199, identifier:i0; 200, integer:1; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:obsval; 204, binary_operator:+; 204, 205; 204, 213; 205, binary_operator:*; 205, 206; 205, 210; 206, parenthesized_expression; 206, 207; 207, binary_operator:-; 207, 208; 207, 209; 208, integer:1; 209, identifier:frac; 210, subscript; 210, 211; 210, 212; 211, identifier:c_obs; 212, identifier:i0; 213, binary_operator:*; 213, 214; 213, 215; 214, identifier:frac; 215, subscript; 215, 216; 215, 217; 216, identifier:c_obs; 217, binary_operator:+; 217, 218; 217, 219; 218, identifier:i0; 219, integer:1; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:p; 224, identifier:addXY; 225, argument_list; 225, 226; 225, 229; 225, 232; 225, 235; 226, list:[mdlval, mdlval]; 226, 227; 226, 228; 227, identifier:mdlval; 228, identifier:mdlval; 229, list:[c0, c1]; 229, 230; 229, 231; 230, identifier:c0; 231, identifier:c1; 232, binary_operator:%; 232, 233; 232, 234; 233, string:'%.2f keV'; 234, identifier:kevval; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:dsn; 237, integer:2; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:p; 242, identifier:addXY; 243, argument_list; 243, 244; 243, 247; 243, 250; 243, 251; 244, list:[c0, c1]; 244, 245; 244, 246; 245, identifier:c0; 246, identifier:c1; 247, list:[obsval, obsval]; 247, 248; 247, 249; 248, identifier:obsval; 249, identifier:obsval; 250, None; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:dsn; 253, integer:2; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:p; 258, identifier:setLabels; 259, argument_list; 259, 260; 259, 263; 260, binary_operator:+; 260, 261; 260, 262; 261, string:'Cumulative model '; 262, identifier:unit; 263, binary_operator:+; 263, 264; 263, 265; 264, string:'Cumulative data '; 265, identifier:unit; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 273; 268, attribute; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:p; 271, identifier:defaultKeyOverlay; 272, identifier:vAlign; 273, float:0.3; 274, return_statement; 274, 275; 275, identifier:p | def make_qq_plot(kev, obs, mdl, unit, key_text):
import omega as om
kev = np.asarray(kev)
obs = np.asarray(obs)
mdl = np.asarray(mdl)
c_obs = np.cumsum(obs)
c_mdl = np.cumsum(mdl)
mx = max(c_obs[-1], c_mdl[-1])
p = om.RectPlot()
p.addXY([0, mx], [0, mx], '1:1')
p.addXY(c_mdl, c_obs, key_text)
locs = np.array([0, 0.05, 0.08, 0.11, 0.17, 0.3, 0.4, 0.7, 1]) * (kev.size - 2)
c0 = mx * 1.05
c1 = mx * 1.1
for loc in locs:
i0 = int(np.floor(loc))
frac = loc - i0
kevval = (1 - frac) * kev[i0] + frac * kev[i0+1]
mdlval = (1 - frac) * c_mdl[i0] + frac * c_mdl[i0+1]
obsval = (1 - frac) * c_obs[i0] + frac * c_obs[i0+1]
p.addXY([mdlval, mdlval], [c0, c1], '%.2f keV' % kevval, dsn=2)
p.addXY([c0, c1], [obsval, obsval], None, dsn=2)
p.setLabels('Cumulative model ' + unit, 'Cumulative data ' + unit)
p.defaultKeyOverlay.vAlign = 0.3
return p |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_qr_factor_full; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:dtype; 7, attribute; 7, 8; 7, 9; 8, identifier:np; 9, identifier:float; 10, block; 10, 11; 10, 19; 10, 32; 10, 43; 10, 73; 10, 82; 10, 91; 10, 152; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, pattern_list; 13, 14; 13, 15; 14, identifier:n; 15, identifier:m; 16, attribute; 16, 17; 16, 18; 17, identifier:a; 18, identifier:shape; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 26; 20, 27; 21, pattern_list; 21, 22; 21, 23; 21, 24; 21, 25; 22, identifier:packed; 23, identifier:pmut; 24, identifier:rdiag; 25, identifier:acnorm; 26, line_continuation:\; 27, call; 27, 28; 27, 29; 28, identifier:_manual_qr_factor_packed; 29, argument_list; 29, 30; 29, 31; 30, identifier:a; 31, identifier:dtype; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:r; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:np; 38, identifier:zeros; 39, argument_list; 39, 40; 40, tuple; 40, 41; 40, 42; 41, identifier:n; 42, identifier:m; 43, for_statement; 43, 44; 43, 45; 43, 49; 44, identifier:i; 45, call; 45, 46; 45, 47; 46, identifier:range; 47, argument_list; 47, 48; 48, identifier:n; 49, block; 49, 50; 49, 64; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 58; 52, subscript; 52, 53; 52, 54; 52, 55; 53, identifier:r; 54, identifier:i; 55, slice; 55, 56; 55, 57; 56, colon; 57, identifier:i; 58, subscript; 58, 59; 58, 60; 58, 61; 59, identifier:packed; 60, identifier:i; 61, slice; 61, 62; 61, 63; 62, colon; 63, identifier:i; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 70; 66, subscript; 66, 67; 66, 68; 66, 69; 67, identifier:r; 68, identifier:i; 69, identifier:i; 70, subscript; 70, 71; 70, 72; 71, identifier:rdiag; 72, identifier:i; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:q; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:np; 79, identifier:eye; 80, argument_list; 80, 81; 81, identifier:m; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:v; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:empty; 89, argument_list; 89, 90; 90, identifier:m; 91, for_statement; 91, 92; 91, 93; 91, 97; 92, identifier:i; 93, call; 93, 94; 93, 95; 94, identifier:range; 95, argument_list; 95, 96; 96, identifier:n; 97, block; 97, 98; 97, 107; 97, 115; 97, 142; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 104; 100, subscript; 100, 101; 100, 102; 101, identifier:v; 102, slice; 102, 103; 103, colon; 104, subscript; 104, 105; 104, 106; 105, identifier:packed; 106, identifier:i; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 114; 109, subscript; 109, 110; 109, 111; 110, identifier:v; 111, slice; 111, 112; 111, 113; 112, colon; 113, identifier:i; 114, integer:0; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:hhm; 118, binary_operator:-; 118, 119; 118, 125; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:np; 122, identifier:eye; 123, argument_list; 123, 124; 124, identifier:m; 125, binary_operator:/; 125, 126; 125, 135; 126, binary_operator:*; 126, 127; 126, 128; 127, integer:2; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:np; 131, identifier:outer; 132, argument_list; 132, 133; 132, 134; 133, identifier:v; 134, identifier:v; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:np; 138, identifier:dot; 139, argument_list; 139, 140; 139, 141; 140, identifier:v; 141, identifier:v; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:q; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:np; 148, identifier:dot; 149, argument_list; 149, 150; 149, 151; 150, identifier:hhm; 151, identifier:q; 152, return_statement; 152, 153; 153, expression_list; 153, 154; 153, 155; 153, 156; 154, identifier:q; 155, identifier:r; 156, identifier:pmut | def _qr_factor_full(a, dtype=np.float):
n, m = a.shape
packed, pmut, rdiag, acnorm = \
_manual_qr_factor_packed(a, dtype)
r = np.zeros((n, m))
for i in range(n):
r[i,:i] = packed[i,:i]
r[i,i] = rdiag[i]
q = np.eye(m)
v = np.empty(m)
for i in range(n):
v[:] = packed[i]
v[:i] = 0
hhm = np.eye(m) - 2 * np.outer(v, v) / np.dot(v, v)
q = np.dot(hhm, q)
return q, r, pmut |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_qrd_solve_full; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:a; 5, identifier:b; 6, identifier:ddiag; 7, default_parameter; 7, 8; 7, 9; 8, identifier:dtype; 9, attribute; 9, 10; 9, 11; 10, identifier:np; 11, identifier:float; 12, block; 12, 13; 12, 23; 12, 33; 12, 43; 12, 51; 12, 55; 12, 62; 12, 69; 12, 79; 12, 91; 12, 115; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:a; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:np; 19, identifier:asarray; 20, argument_list; 20, 21; 20, 22; 21, identifier:a; 22, identifier:dtype; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:b; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:np; 29, identifier:asarray; 30, argument_list; 30, 31; 30, 32; 31, identifier:b; 32, identifier:dtype; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:ddiag; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:asarray; 40, argument_list; 40, 41; 40, 42; 41, identifier:ddiag; 42, identifier:dtype; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, pattern_list; 45, 46; 45, 47; 46, identifier:n; 47, identifier:m; 48, attribute; 48, 49; 48, 50; 49, identifier:a; 50, identifier:shape; 51, assert_statement; 51, 52; 52, comparison_operator:>=; 52, 53; 52, 54; 53, identifier:m; 54, identifier:n; 55, assert_statement; 55, 56; 56, comparison_operator:==; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:b; 59, identifier:shape; 60, tuple; 60, 61; 61, identifier:m; 62, assert_statement; 62, 63; 63, comparison_operator:==; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:ddiag; 66, identifier:shape; 67, tuple; 67, 68; 68, identifier:n; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 75; 71, pattern_list; 71, 72; 71, 73; 71, 74; 72, identifier:q; 73, identifier:r; 74, identifier:pmut; 75, call; 75, 76; 75, 77; 76, identifier:_qr_factor_full; 77, argument_list; 77, 78; 78, identifier:a; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:bqt; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:np; 85, identifier:dot; 86, argument_list; 86, 87; 86, 88; 87, identifier:b; 88, attribute; 88, 89; 88, 90; 89, identifier:q; 90, identifier:T; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, pattern_list; 93, 94; 93, 95; 94, identifier:x; 95, identifier:s; 96, call; 96, 97; 96, 98; 97, identifier:_manual_qrd_solve; 98, argument_list; 98, 99; 98, 106; 98, 107; 98, 108; 98, 109; 98, 112; 99, subscript; 99, 100; 99, 101; 99, 103; 100, identifier:r; 101, slice; 101, 102; 102, colon; 103, slice; 103, 104; 103, 105; 104, colon; 105, identifier:n; 106, identifier:pmut; 107, identifier:ddiag; 108, identifier:bqt; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:dtype; 111, identifier:dtype; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:build_s; 114, True; 115, return_statement; 115, 116; 116, expression_list; 116, 117; 116, 118; 116, 119; 117, identifier:x; 118, identifier:s; 119, identifier:pmut | def _qrd_solve_full(a, b, ddiag, dtype=np.float):
a = np.asarray(a, dtype)
b = np.asarray(b, dtype)
ddiag = np.asarray(ddiag, dtype)
n, m = a.shape
assert m >= n
assert b.shape == (m, )
assert ddiag.shape == (n, )
q, r, pmut = _qr_factor_full(a)
bqt = np.dot(b, q.T)
x, s = _manual_qrd_solve(r[:,:n], pmut, ddiag, bqt,
dtype=dtype, build_s=True)
return x, s, pmut |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:concat; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:invises; 5, identifier:outvis; 6, default_parameter; 6, 7; 6, 8; 7, identifier:timesort; 8, False; 9, block; 9, 10; 9, 20; 9, 30; 9, 47; 9, 69; 9, 81; 9, 97; 9, 103; 9, 116; 9, 148; 9, 160; 9, 182; 9, 204; 9, 213; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:tb; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:util; 17, identifier:tools; 18, identifier:table; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:ms; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:util; 27, identifier:tools; 28, identifier:ms; 29, argument_list; 30, if_statement; 30, 31; 30, 39; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:os; 35, identifier:path; 36, identifier:exists; 37, argument_list; 37, 38; 38, identifier:outvis; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:RuntimeError; 43, argument_list; 43, 44; 44, binary_operator:%; 44, 45; 44, 46; 45, string:'output "%s" already exists'; 46, identifier:outvis; 47, for_statement; 47, 48; 47, 49; 47, 50; 48, identifier:invis; 49, identifier:invises; 50, block; 50, 51; 51, if_statement; 51, 52; 51, 61; 52, not_operator; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:os; 57, identifier:path; 58, identifier:isdir; 59, argument_list; 59, 60; 60, identifier:invis; 61, block; 61, 62; 62, raise_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:RuntimeError; 65, argument_list; 65, 66; 66, binary_operator:%; 66, 67; 66, 68; 67, string:'input "%s" does not exist'; 68, identifier:invis; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:tb; 73, identifier:open; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:b; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 79, identifier:invises; 80, integer:0; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:tb; 85, identifier:copy; 86, argument_list; 86, 87; 86, 91; 86, 94; 87, call; 87, 88; 87, 89; 88, identifier:b; 89, argument_list; 89, 90; 90, identifier:outvis; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:deep; 93, True; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:valuecopy; 96, True; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:tb; 101, identifier:close; 102, argument_list; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:ms; 107, identifier:open; 108, argument_list; 108, 109; 108, 113; 109, call; 109, 110; 109, 111; 110, identifier:b; 111, argument_list; 111, 112; 112, identifier:outvis; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:nomodify; 115, False; 116, for_statement; 116, 117; 116, 118; 116, 123; 117, identifier:invis; 118, subscript; 118, 119; 118, 120; 119, identifier:invises; 120, slice; 120, 121; 120, 122; 121, integer:1; 122, colon; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:ms; 128, identifier:concatenate; 129, argument_list; 129, 130; 129, 136; 129, 142; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:msfile; 132, call; 132, 133; 132, 134; 133, identifier:b; 134, argument_list; 134, 135; 135, identifier:invis; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:freqtol; 138, call; 138, 139; 138, 140; 139, identifier:b; 140, argument_list; 140, 141; 141, identifier:concat_freqtol; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:dirtol; 144, call; 144, 145; 144, 146; 145, identifier:b; 146, argument_list; 146, 147; 147, identifier:concat_dirtol; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:ms; 152, identifier:writehistory; 153, argument_list; 153, 154; 153, 157; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:message; 156, string:b'taskname=tasklib.concat'; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:origin; 159, string:b'tasklib.concat'; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:ms; 164, identifier:writehistory; 165, argument_list; 165, 166; 165, 179; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:message; 168, call; 168, 169; 168, 170; 169, identifier:b; 170, argument_list; 170, 171; 171, binary_operator:+; 171, 172; 171, 173; 172, string:'vis = '; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, string:', '; 176, identifier:join; 177, argument_list; 177, 178; 178, identifier:invises; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:origin; 181, string:b'tasklib.concat'; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:ms; 186, identifier:writehistory; 187, argument_list; 187, 188; 187, 201; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:message; 190, call; 190, 191; 190, 192; 191, identifier:b; 192, argument_list; 192, 193; 193, binary_operator:+; 193, 194; 193, 195; 194, string:'timesort = '; 195, subscript; 195, 196; 195, 197; 196, string:'FT'; 197, call; 197, 198; 197, 199; 198, identifier:int; 199, argument_list; 199, 200; 200, identifier:timesort; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:origin; 203, string:b'tasklib.concat'; 204, if_statement; 204, 205; 204, 206; 205, identifier:timesort; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:ms; 211, identifier:timesort; 212, argument_list; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:ms; 217, identifier:close; 218, argument_list | def concat(invises, outvis, timesort=False):
tb = util.tools.table()
ms = util.tools.ms()
if os.path.exists(outvis):
raise RuntimeError('output "%s" already exists' % outvis)
for invis in invises:
if not os.path.isdir(invis):
raise RuntimeError('input "%s" does not exist' % invis)
tb.open(b(invises[0]))
tb.copy(b(outvis), deep=True, valuecopy=True)
tb.close()
ms.open(b(outvis), nomodify=False)
for invis in invises[1:]:
ms.concatenate(msfile=b(invis), freqtol=b(concat_freqtol),
dirtol=b(concat_dirtol))
ms.writehistory(message=b'taskname=tasklib.concat', origin=b'tasklib.concat')
ms.writehistory(message=b('vis = ' + ', '.join(invises)), origin=b'tasklib.concat')
ms.writehistory(message=b('timesort = ' + 'FT'[int(timesort)]), origin=b'tasklib.concat')
if timesort:
ms.timesort()
ms.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_zones_of_account; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:account_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:q; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 20; 11, 28; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:uri; 15, binary_operator:+; 15, 16; 15, 19; 16, binary_operator:+; 16, 17; 16, 18; 17, string:"/v1/accounts/"; 18, identifier:account_name; 19, string:"/zones"; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:params; 23, call; 23, 24; 23, 25; 24, identifier:build_params; 25, argument_list; 25, 26; 25, 27; 26, identifier:q; 27, identifier:kwargs; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:rest_api_connection; 34, identifier:get; 35, argument_list; 35, 36; 35, 37; 36, identifier:uri; 37, identifier:params | def get_zones_of_account(self, account_name, q=None, **kwargs):
uri = "/v1/accounts/" + account_name + "/zones"
params = build_params(q, kwargs)
return self.rest_api_connection.get(uri, params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_zones; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:q; 7, None; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 10, 15; 10, 23; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:uri; 14, string:"/v1/zones"; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:params; 18, call; 18, 19; 18, 20; 19, identifier:build_params; 20, argument_list; 20, 21; 20, 22; 21, identifier:q; 22, identifier:kwargs; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:rest_api_connection; 29, identifier:get; 30, argument_list; 30, 31; 30, 32; 31, identifier:uri; 32, identifier:params | def get_zones(self, q=None, **kwargs):
uri = "/v1/zones"
params = build_params(q, kwargs)
return self.rest_api_connection.get(uri, params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_rrsets; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:zone_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:q; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 20; 11, 28; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:uri; 15, binary_operator:+; 15, 16; 15, 19; 16, binary_operator:+; 16, 17; 16, 18; 17, string:"/v1/zones/"; 18, identifier:zone_name; 19, string:"/rrsets"; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:params; 23, call; 23, 24; 23, 25; 24, identifier:build_params; 25, argument_list; 25, 26; 25, 27; 26, identifier:q; 27, identifier:kwargs; 28, return_statement; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:rest_api_connection; 34, identifier:get; 35, argument_list; 35, 36; 35, 37; 36, identifier:uri; 37, identifier:params | def get_rrsets(self, zone_name, q=None, **kwargs):
uri = "/v1/zones/" + zone_name + "/rrsets"
params = build_params(q, kwargs)
return self.rest_api_connection.get(uri, params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:nested_tuple; 3, parameters; 3, 4; 4, identifier:container; 5, block; 5, 6; 5, 26; 5, 49; 5, 107; 6, if_statement; 6, 7; 6, 12; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:container; 11, identifier:OrderedDict; 12, block; 12, 13; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:tuple; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:map; 19, argument_list; 19, 20; 19, 21; 20, identifier:nested_tuple; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:container; 24, identifier:items; 25, argument_list; 26, if_statement; 26, 27; 26, 32; 27, call; 27, 28; 27, 29; 28, identifier:isinstance; 29, argument_list; 29, 30; 29, 31; 30, identifier:container; 31, identifier:Mapping; 32, block; 32, 33; 33, return_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:tuple; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:sorted_if_possible; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:map; 42, argument_list; 42, 43; 42, 44; 43, identifier:nested_tuple; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:container; 47, identifier:items; 48, argument_list; 49, if_statement; 49, 50; 49, 58; 50, not_operator; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:isinstance; 53, argument_list; 53, 54; 53, 55; 54, identifier:container; 55, tuple; 55, 56; 55, 57; 56, identifier:str; 57, identifier:bytes; 58, block; 58, 59; 58, 75; 59, if_statement; 59, 60; 59, 65; 60, call; 60, 61; 60, 62; 61, identifier:isinstance; 62, argument_list; 62, 63; 62, 64; 63, identifier:container; 64, identifier:Sequence; 65, block; 65, 66; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:tuple; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:map; 72, argument_list; 72, 73; 72, 74; 73, identifier:nested_tuple; 74, identifier:container; 75, if_statement; 75, 76; 75, 94; 76, parenthesized_expression; 76, 77; 77, boolean_operator:and; 77, 78; 77, 89; 78, boolean_operator:and; 78, 79; 78, 84; 79, call; 79, 80; 79, 81; 80, identifier:isinstance; 81, argument_list; 81, 82; 81, 83; 82, identifier:container; 83, identifier:Container; 84, call; 84, 85; 84, 86; 85, identifier:isinstance; 86, argument_list; 86, 87; 86, 88; 87, identifier:container; 88, identifier:Iterable; 89, call; 89, 90; 89, 91; 90, identifier:isinstance; 91, argument_list; 91, 92; 91, 93; 92, identifier:container; 93, identifier:Sized; 94, block; 94, 95; 95, return_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:tuple; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:sorted_if_possible; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:map; 104, argument_list; 104, 105; 104, 106; 105, identifier:nested_tuple; 106, identifier:container; 107, return_statement; 107, 108; 108, identifier:container | def nested_tuple(container):
if isinstance(container, OrderedDict):
return tuple(map(nested_tuple, container.items()))
if isinstance(container, Mapping):
return tuple(sorted_if_possible(map(nested_tuple, container.items())))
if not isinstance(container, (str, bytes)):
if isinstance(container, Sequence):
return tuple(map(nested_tuple, container))
if (
isinstance(container, Container)
and isinstance(container, Iterable)
and isinstance(container, Sized)
):
return tuple(sorted_if_possible(map(nested_tuple, container)))
return container |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_ranges_key; 3, parameters; 3, 4; 3, 5; 4, identifier:r; 5, identifier:delta_indices; 6, block; 6, 7; 6, 13; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:idx; 10, attribute; 10, 11; 10, 12; 11, identifier:r; 12, identifier:index_symbol; 13, if_statement; 13, 14; 13, 17; 13, 30; 14, comparison_operator:in; 14, 15; 14, 16; 15, identifier:idx; 16, identifier:delta_indices; 17, block; 17, 18; 18, return_statement; 18, 19; 19, tuple; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:r; 23, identifier:index_symbol; 24, identifier:primed; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:r; 28, identifier:index_symbol; 29, identifier:name; 30, else_clause; 30, 31; 31, block; 31, 32; 32, return_statement; 32, 33; 33, tuple; 33, 34; 33, 35; 34, integer:0; 35, string:' ' | def _ranges_key(r, delta_indices):
idx = r.index_symbol
if idx in delta_indices:
return (r.index_symbol.primed, r.index_symbol.name)
else:
return (0, ' ') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:plot; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:x; 6, default_parameter; 6, 7; 6, 8; 7, identifier:row_order; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:imshow_kwargs; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:strip; 14, True; 15, block; 15, 16; 15, 26; 15, 40; 15, 54; 15, 67; 15, 76; 15, 91; 15, 101; 15, 132; 15, 147; 15, 155; 15, 172; 15, 217; 15, 224; 15, 245; 15, 254; 15, 316; 15, 328; 15, 334; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:nrows; 19, subscript; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:diffed_array; 24, identifier:shape; 25, integer:0; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:row_order; 29, None; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:row_order; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:arange; 38, argument_list; 38, 39; 39, identifier:nrows; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:extent; 43, tuple; 43, 44; 43, 48; 43, 52; 43, 53; 44, call; 44, 45; 44, 46; 45, identifier:min; 46, argument_list; 46, 47; 47, identifier:x; 48, call; 48, 49; 48, 50; 49, identifier:max; 50, argument_list; 50, 51; 51, identifier:x; 52, integer:0; 53, identifier:nrows; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:axes_info; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:metaseq; 61, identifier:plotutils; 62, identifier:matrix_and_line_shell; 63, argument_list; 63, 64; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:strip; 66, identifier:strip; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 75; 69, pattern_list; 69, 70; 69, 71; 69, 72; 69, 73; 69, 74; 70, identifier:fig; 71, identifier:matrix_ax; 72, identifier:line_ax; 73, identifier:strip_ax; 74, identifier:cbar_ax; 75, identifier:axes_info; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:_imshow_kwargs; 79, call; 79, 80; 79, 81; 80, identifier:dict; 81, argument_list; 81, 82; 81, 85; 81, 88; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:aspect; 84, string:'auto'; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:extent; 87, identifier:extent; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:interpolation; 90, string:'nearest'; 91, if_statement; 91, 92; 91, 93; 92, identifier:imshow_kwargs; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:_imshow_kwargs; 98, identifier:update; 99, argument_list; 99, 100; 100, identifier:imshow_kwargs; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:not; 102, 103; 102, 104; 103, string:'cmap'; 104, identifier:_imshow_kwargs; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:_imshow_kwargs; 110, string:'cmap'; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:metaseq; 115, identifier:colormap_adjust; 116, identifier:smart_colormap; 117, argument_list; 117, 118; 117, 125; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:diffed_array; 123, identifier:min; 124, argument_list; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:diffed_array; 130, identifier:max; 131, argument_list; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:mappable; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:matrix_ax; 138, identifier:imshow; 139, argument_list; 139, 140; 139, 145; 140, subscript; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:diffed_array; 144, identifier:row_order; 145, dictionary_splat; 145, 146; 146, identifier:_imshow_kwargs; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:plt; 151, identifier:colorbar; 152, argument_list; 152, 153; 152, 154; 153, identifier:mappable; 154, identifier:cbar_ax; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:line_ax; 159, identifier:plot; 160, argument_list; 160, 161; 160, 162; 161, identifier:x; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:diffed_array; 167, identifier:mean; 168, argument_list; 168, 169; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:axis; 171, integer:0; 172, if_statement; 172, 173; 172, 174; 173, identifier:strip_ax; 174, block; 174, 175; 174, 203; 174, 211; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 179; 177, pattern_list; 177, 178; 178, identifier:line; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:strip_ax; 182, identifier:plot; 183, argument_list; 183, 184; 183, 191; 183, 199; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:np; 187, identifier:zeros; 188, argument_list; 188, 189; 189, tuple; 189, 190; 190, identifier:nrows; 191, binary_operator:+; 191, 192; 191, 198; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:np; 195, identifier:arange; 196, argument_list; 196, 197; 197, identifier:nrows; 198, float:0.5; 199, dictionary_splat; 199, 200; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:_strip_kwargs; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:line; 207, identifier:features; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:features; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:line; 215, identifier:ind; 216, identifier:row_order; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:matrix_ax; 221, identifier:axis; 222, argument_list; 222, 223; 223, string:'tight'; 224, if_statement; 224, 225; 224, 226; 225, identifier:strip_ax; 226, block; 226, 227; 226, 236; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:strip_ax; 232, identifier:xaxis; 233, identifier:set_visible; 234, argument_list; 234, 235; 235, False; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 243; 238, attribute; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:matrix_ax; 241, identifier:yaxis; 242, identifier:set_visible; 243, argument_list; 243, 244; 244, False; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:matrix_ax; 250, identifier:xaxis; 251, identifier:set_visible; 252, argument_list; 252, 253; 253, False; 254, if_statement; 254, 255; 254, 258; 254, 289; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:db; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:minibrowser; 264, call; 264, 265; 264, 266; 265, identifier:GeneChipseqMiniBrowser; 266, argument_list; 266, 267; 266, 274; 266, 279; 266, 284; 267, list:[self.ip, self.control]; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:ip; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:control; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:db; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:db; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:plotting_kwargs; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:browser_plotting_kwargs; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:local_coverage_kwargs; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:browser_local_coverage_kwargs; 289, else_clause; 289, 290; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:minibrowser; 296, call; 296, 297; 296, 298; 297, identifier:SignalChipseqMiniBrowser; 298, argument_list; 298, 299; 298, 306; 298, 311; 299, list:[self.ip, self.control]; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:ip; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:control; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:plotting_kwargs; 308, attribute; 308, 309; 308, 310; 309, identifier:self; 310, identifier:browser_plotting_kwargs; 311, keyword_argument; 311, 312; 311, 313; 312, identifier:local_coverage_kwargs; 313, attribute; 313, 314; 313, 315; 314, identifier:self; 315, identifier:browser_local_coverage_kwargs; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 323; 318, attribute; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:fig; 321, identifier:canvas; 322, identifier:mpl_connect; 323, argument_list; 323, 324; 323, 325; 324, string:'pick_event'; 325, attribute; 325, 326; 325, 327; 326, identifier:self; 327, identifier:callback; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:fig; 333, identifier:fig; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:axes; 339, dictionary; 339, 340; 339, 343; 339, 346; 339, 349; 340, pair; 340, 341; 340, 342; 341, string:'matrix_ax'; 342, identifier:matrix_ax; 343, pair; 343, 344; 343, 345; 344, string:'strip_ax'; 345, identifier:strip_ax; 346, pair; 346, 347; 346, 348; 347, string:'line_ax'; 348, identifier:line_ax; 349, pair; 349, 350; 349, 351; 350, string:'cbar_ax'; 351, identifier:cbar_ax | def plot(self, x, row_order=None, imshow_kwargs=None, strip=True):
nrows = self.diffed_array.shape[0]
if row_order is None:
row_order = np.arange(nrows)
extent = (min(x), max(x), 0, nrows)
axes_info = metaseq.plotutils.matrix_and_line_shell(strip=strip)
fig, matrix_ax, line_ax, strip_ax, cbar_ax = axes_info
_imshow_kwargs = dict(
aspect='auto', extent=extent, interpolation='nearest')
if imshow_kwargs:
_imshow_kwargs.update(imshow_kwargs)
if 'cmap' not in _imshow_kwargs:
_imshow_kwargs['cmap'] = metaseq.colormap_adjust.smart_colormap(
self.diffed_array.min(),
self.diffed_array.max()
)
mappable = matrix_ax.imshow(
self.diffed_array[row_order],
**_imshow_kwargs)
plt.colorbar(mappable, cbar_ax)
line_ax.plot(x, self.diffed_array.mean(axis=0))
if strip_ax:
line, = strip_ax.plot(np.zeros((nrows,)), np.arange(nrows) + 0.5,
**self._strip_kwargs)
line.features = self.features
line.ind = row_order
matrix_ax.axis('tight')
if strip_ax:
strip_ax.xaxis.set_visible(False)
matrix_ax.yaxis.set_visible(False)
matrix_ax.xaxis.set_visible(False)
if self.db:
self.minibrowser = GeneChipseqMiniBrowser(
[self.ip, self.control],
db=self.db,
plotting_kwargs=self.browser_plotting_kwargs,
local_coverage_kwargs=self.browser_local_coverage_kwargs)
else:
self.minibrowser = SignalChipseqMiniBrowser(
[self.ip, self.control],
plotting_kwargs=self.browser_plotting_kwargs,
local_coverage_kwargs=self.browser_local_coverage_kwargs)
fig.canvas.mpl_connect('pick_event', self.callback)
self.fig = fig
self.axes = {
'matrix_ax': matrix_ax,
'strip_ax': strip_ax,
'line_ax': line_ax,
'cbar_ax': cbar_ax
} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_restricted_growth_notation; 3, parameters; 3, 4; 4, identifier:l; 5, block; 5, 6; 5, 13; 5, 20; 5, 38; 5, 45; 5, 74; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:list_length; 9, call; 9, 10; 9, 11; 10, identifier:len; 11, argument_list; 11, 12; 12, identifier:l; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:d; 16, call; 16, 17; 16, 18; 17, identifier:defaultdict; 18, argument_list; 18, 19; 19, identifier:list; 20, for_statement; 20, 21; 20, 24; 20, 28; 21, tuple_pattern; 21, 22; 21, 23; 22, identifier:i; 23, identifier:element; 24, call; 24, 25; 24, 26; 25, identifier:enumerate; 26, argument_list; 26, 27; 27, identifier:l; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:d; 34, identifier:element; 35, identifier:append; 36, argument_list; 36, 37; 37, identifier:i; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:l2; 41, binary_operator:*; 41, 42; 41, 44; 42, list:[None]; 42, 43; 43, None; 44, identifier:list_length; 45, for_statement; 45, 46; 45, 49; 45, 63; 46, tuple_pattern; 46, 47; 46, 48; 47, identifier:name; 48, identifier:index_list; 49, call; 49, 50; 49, 51; 50, identifier:enumerate; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:sorted; 54, argument_list; 54, 55; 54, 60; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:d; 58, identifier:values; 59, argument_list; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:key; 62, identifier:min; 63, block; 63, 64; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:index; 66, identifier:index_list; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:l2; 72, identifier:index; 73, identifier:name; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:tuple; 77, argument_list; 77, 78; 78, identifier:l2 | def _restricted_growth_notation(l):
list_length = len(l)
d = defaultdict(list)
for (i, element) in enumerate(l):
d[element].append(i)
l2 = [None] * list_length
for (name, index_list) in enumerate(sorted(d.values(), key=min)):
for index in index_list:
l2[index] = name
return tuple(l2) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:insort_no_dup; 3, parameters; 3, 4; 3, 5; 4, identifier:lst; 5, identifier:item; 6, block; 6, 7; 6, 10; 6, 20; 7, import_statement; 7, 8; 8, dotted_name; 8, 9; 9, identifier:bisect; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:ix; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:bisect; 16, identifier:bisect_left; 17, argument_list; 17, 18; 17, 19; 18, identifier:lst; 19, identifier:item; 20, if_statement; 20, 21; 20, 26; 21, comparison_operator:!=; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:lst; 24, identifier:ix; 25, identifier:item; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 35; 29, subscript; 29, 30; 29, 31; 30, identifier:lst; 31, slice; 31, 32; 31, 33; 31, 34; 32, identifier:ix; 33, colon; 34, identifier:ix; 35, list:[item]; 35, 36; 36, identifier:item | def insort_no_dup(lst, item):
import bisect
ix = bisect.bisect_left(lst, item)
if lst[ix] != item:
lst[ix:ix] = [item] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:records; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, list_comprehension; 7, 8; 7, 13; 8, subscript; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_records; 12, identifier:i; 13, for_in_clause; 13, 14; 13, 15; 14, identifier:i; 15, call; 15, 16; 15, 17; 16, identifier:range; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_records | def records(self):
return [self._records[i] for i in range(len(self._records))] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:score; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:phone_number; 6, identifier:account_lifecycle_event; 7, dictionary_splat_pattern; 7, 8; 8, identifier:params; 9, block; 9, 10; 10, return_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:post; 15, argument_list; 15, 16; 15, 24; 15, 27; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:SCORE_RESOURCE; 19, identifier:format; 20, argument_list; 20, 21; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:phone_number; 23, identifier:phone_number; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:account_lifecycle_event; 26, identifier:account_lifecycle_event; 27, dictionary_splat; 27, 28; 28, identifier:params | def score(self, phone_number, account_lifecycle_event, **params):
return self.post(SCORE_RESOURCE.format(phone_number=phone_number),
account_lifecycle_event=account_lifecycle_event,
**params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted_members; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 5, 26; 5, 57; 5, 83; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:members; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:collections; 12, identifier:OrderedDict; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:required_names; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:metadata; 22, identifier:get; 23, argument_list; 23, 24; 23, 25; 24, string:"required"; 25, tuple; 26, for_statement; 26, 27; 26, 30; 26, 37; 27, pattern_list; 27, 28; 27, 29; 28, identifier:name; 29, identifier:shape; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:members; 35, identifier:items; 36, argument_list; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:members; 42, identifier:name; 43, call; 43, 44; 43, 45; 44, identifier:AbShapeMember; 45, argument_list; 45, 46; 45, 49; 45, 52; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:name; 48, identifier:name; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:shape; 51, identifier:shape; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:is_required; 54, comparison_operator:in; 54, 55; 54, 56; 55, identifier:name; 56, identifier:required_names; 57, if_statement; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:is_output_shape; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, yield; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:AbShapeMember; 66, argument_list; 66, 67; 66, 70; 66, 80; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:name; 69, string:"ResponseMetadata"; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:shape; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_shape_resolver; 77, identifier:get_shape_by_name; 78, argument_list; 78, 79; 79, string:"ResponseMetadata"; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:is_required; 82, True; 83, expression_statement; 83, 84; 84, yield; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:sorted; 87, argument_list; 87, 88; 87, 93; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:members; 91, identifier:values; 92, argument_list; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:key; 95, lambda; 95, 96; 95, 98; 96, lambda_parameters; 96, 97; 97, identifier:m; 98, not_operator; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:m; 101, identifier:is_required | def sorted_members(self):
members = collections.OrderedDict()
required_names = self.metadata.get("required", ())
for name, shape in self.members.items():
members[name] = AbShapeMember(name=name, shape=shape, is_required=name in required_names)
if self.is_output_shape:
yield AbShapeMember(
name="ResponseMetadata",
shape=self._shape_resolver.get_shape_by_name("ResponseMetadata"),
is_required=True,
)
yield from sorted(members.values(), key=lambda m: not m.is_required) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:threshold_brier_score; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:observations; 5, identifier:forecasts; 6, identifier:threshold; 7, default_parameter; 7, 8; 7, 9; 8, identifier:issorted; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier:axis; 12, unary_operator:-; 12, 13; 13, integer:1; 14, block; 14, 15; 14, 24; 14, 33; 14, 42; 14, 56; 14, 74; 14, 97; 14, 105; 14, 117; 14, 144; 14, 162; 14, 179; 14, 188; 14, 203; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:observations; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:asarray; 22, argument_list; 22, 23; 23, identifier:observations; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:threshold; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:np; 30, identifier:asarray; 31, argument_list; 31, 32; 32, identifier:threshold; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:forecasts; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:asarray; 40, argument_list; 40, 41; 41, identifier:forecasts; 42, if_statement; 42, 43; 42, 47; 43, comparison_operator:!=; 43, 44; 43, 45; 44, identifier:axis; 45, unary_operator:-; 45, 46; 46, integer:1; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:forecasts; 51, call; 51, 52; 51, 53; 52, identifier:move_axis_to_end; 53, argument_list; 53, 54; 53, 55; 54, identifier:forecasts; 55, identifier:axis; 56, if_statement; 56, 57; 56, 64; 57, comparison_operator:==; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:forecasts; 60, identifier:shape; 61, attribute; 61, 62; 61, 63; 62, identifier:observations; 63, identifier:shape; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:forecasts; 68, subscript; 68, 69; 68, 70; 68, 71; 69, identifier:forecasts; 70, ellipsis:...; 71, attribute; 71, 72; 71, 73; 72, identifier:np; 73, identifier:newaxis; 74, if_statement; 74, 75; 74, 87; 75, comparison_operator:!=; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:observations; 78, identifier:shape; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:forecasts; 82, identifier:shape; 83, slice; 83, 84; 83, 85; 84, colon; 85, unary_operator:-; 85, 86; 86, integer:1; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:ValueError; 91, argument_list; 91, 92; 92, binary_operator:%; 92, 93; 92, 96; 93, concatenated_string; 93, 94; 93, 95; 94, string:'observations and forecasts must have matching '; 95, string:'shapes or matching shapes except along `axis=%s`'; 96, identifier:axis; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:scalar_threshold; 100, comparison_operator:==; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:threshold; 103, identifier:ndim; 104, integer:0; 105, if_statement; 105, 106; 105, 111; 106, comparison_operator:>; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:threshold; 109, identifier:ndim; 110, integer:1; 111, block; 111, 112; 112, raise_statement; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:ValueError; 115, argument_list; 115, 116; 116, string:'threshold must be scalar or 1-dimensional'; 117, if_statement; 117, 118; 117, 138; 118, boolean_operator:and; 118, 119; 118, 124; 119, comparison_operator:==; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:threshold; 122, identifier:ndim; 123, integer:1; 124, not_operator; 124, 125; 125, call; 125, 126; 125, 137; 126, attribute; 126, 127; 126, 136; 127, parenthesized_expression; 127, 128; 128, comparison_operator:==; 128, 129; 128, 135; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:np; 132, identifier:sort; 133, argument_list; 133, 134; 134, identifier:threshold; 135, identifier:threshold; 136, identifier:all; 137, argument_list; 138, block; 138, 139; 139, raise_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:ValueError; 142, argument_list; 142, 143; 143, string:'1D thresholds must be sorted'; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:threshold; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:threshold; 150, identifier:reshape; 151, argument_list; 151, 152; 152, binary_operator:+; 152, 153; 152, 159; 153, binary_operator:*; 153, 154; 153, 156; 154, tuple; 154, 155; 155, integer:1; 156, attribute; 156, 157; 156, 158; 157, identifier:observations; 158, identifier:ndim; 159, tuple; 159, 160; 160, unary_operator:-; 160, 161; 161, integer:1; 162, if_statement; 162, 163; 162, 165; 163, not_operator; 163, 164; 164, identifier:issorted; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:forecasts; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:np; 172, identifier:sort; 173, argument_list; 173, 174; 173, 175; 174, identifier:forecasts; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:axis; 177, unary_operator:-; 177, 178; 178, integer:1; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:result; 182, call; 182, 183; 182, 184; 183, identifier:_threshold_brier_score_core; 184, argument_list; 184, 185; 184, 186; 184, 187; 185, identifier:observations; 186, identifier:forecasts; 187, identifier:threshold; 188, if_statement; 188, 189; 188, 190; 189, identifier:scalar_threshold; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:result; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:result; 197, identifier:squeeze; 198, argument_list; 198, 199; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:axis; 201, unary_operator:-; 201, 202; 202, integer:1; 203, return_statement; 203, 204; 204, identifier:result | def threshold_brier_score(observations, forecasts, threshold, issorted=False,
axis=-1):
observations = np.asarray(observations)
threshold = np.asarray(threshold)
forecasts = np.asarray(forecasts)
if axis != -1:
forecasts = move_axis_to_end(forecasts, axis)
if forecasts.shape == observations.shape:
forecasts = forecasts[..., np.newaxis]
if observations.shape != forecasts.shape[:-1]:
raise ValueError('observations and forecasts must have matching '
'shapes or matching shapes except along `axis=%s`'
% axis)
scalar_threshold = threshold.ndim == 0
if threshold.ndim > 1:
raise ValueError('threshold must be scalar or 1-dimensional')
if threshold.ndim == 1 and not (np.sort(threshold) == threshold).all():
raise ValueError('1D thresholds must be sorted')
threshold = threshold.reshape((1,) * observations.ndim + (-1,))
if not issorted:
forecasts = np.sort(forecasts, axis=-1)
result = _threshold_brier_score_core(observations, forecasts, threshold)
if scalar_threshold:
result = result.squeeze(axis=-1)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:run; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:N; 7, integer:1; 8, default_parameter; 8, 9; 8, 10; 9, identifier:trace_sort; 10, False; 11, block; 11, 12; 11, 14; 11, 21; 12, expression_statement; 12, 13; 13, string:'''Run the sampler, store the history of visited points into
the member variable ``self.samples`` and the importance weights
into ``self.weights``.
.. seealso::
:py:class:`pypmc.tools.History`
:param N:
Integer; the number of samples to be drawn.
:param trace_sort:
Bool; if True, return an array containing the responsible
component of ``self.proposal`` for each sample generated
during this run.
.. note::
This option only works for proposals of type
:py:class:`pypmc.density.mixture.MixtureDensity`
.. note::
If True, the samples will be ordered by the components.
'''; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:==; 15, 16; 15, 17; 16, identifier:N; 17, integer:0; 18, block; 18, 19; 19, return_statement; 19, 20; 20, integer:0; 21, if_statement; 21, 22; 21, 23; 21, 48; 22, identifier:trace_sort; 23, block; 23, 24; 23, 38; 23, 46; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:this_samples; 28, identifier:origin; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_get_samples; 33, argument_list; 33, 34; 33, 35; 34, identifier:N; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:trace_sort; 37, True; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_calculate_weights; 43, argument_list; 43, 44; 43, 45; 44, identifier:this_samples; 45, identifier:N; 46, return_statement; 46, 47; 47, identifier:origin; 48, else_clause; 48, 49; 49, block; 49, 50; 49, 62; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:this_samples; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_get_samples; 57, argument_list; 57, 58; 57, 59; 58, identifier:N; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:trace_sort; 61, False; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_calculate_weights; 67, argument_list; 67, 68; 67, 69; 68, identifier:this_samples; 69, identifier:N | def run(self, N=1, trace_sort=False):
'''Run the sampler, store the history of visited points into
the member variable ``self.samples`` and the importance weights
into ``self.weights``.
.. seealso::
:py:class:`pypmc.tools.History`
:param N:
Integer; the number of samples to be drawn.
:param trace_sort:
Bool; if True, return an array containing the responsible
component of ``self.proposal`` for each sample generated
during this run.
.. note::
This option only works for proposals of type
:py:class:`pypmc.density.mixture.MixtureDensity`
.. note::
If True, the samples will be ordered by the components.
'''
if N == 0:
return 0
if trace_sort:
this_samples, origin = self._get_samples(N, trace_sort=True)
self._calculate_weights(this_samples, N)
return origin
else:
this_samples = self._get_samples(N, trace_sort=False)
self._calculate_weights(this_samples, N) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_get_samples; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:N; 6, identifier:trace_sort; 7, block; 7, 8; 7, 19; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:this_run; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:samples; 16, identifier:append; 17, argument_list; 17, 18; 18, identifier:N; 19, if_statement; 19, 20; 19, 21; 19, 51; 20, identifier:trace_sort; 21, block; 21, 22; 21, 47; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 30; 24, pattern_list; 24, 25; 24, 29; 25, subscript; 25, 26; 25, 27; 26, identifier:this_run; 27, slice; 27, 28; 28, colon; 29, identifier:origin; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:proposal; 35, identifier:propose; 36, argument_list; 36, 37; 36, 38; 36, 41; 36, 44; 37, identifier:N; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:rng; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:trace; 43, True; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:shuffle; 46, False; 47, return_statement; 47, 48; 48, expression_list; 48, 49; 48, 50; 49, identifier:this_run; 50, identifier:origin; 51, else_clause; 51, 52; 52, block; 52, 53; 52, 70; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 59; 55, subscript; 55, 56; 55, 57; 56, identifier:this_run; 57, slice; 57, 58; 58, colon; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:proposal; 64, identifier:propose; 65, argument_list; 65, 66; 65, 67; 66, identifier:N; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:rng; 70, return_statement; 70, 71; 71, identifier:this_run | def _get_samples(self, N, trace_sort):
this_run = self.samples.append(N)
if trace_sort:
this_run[:], origin = self.proposal.propose(N, self.rng, trace=True, shuffle=False)
return this_run, origin
else:
this_run[:] = self.proposal.propose(N, self.rng)
return this_run |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:argsort_indices; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, unary_operator:-; 7, 8; 8, integer:1; 9, block; 9, 10; 9, 19; 9, 43; 9, 54; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:a; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:np; 16, identifier:asarray; 17, argument_list; 17, 18; 18, identifier:a; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:ind; 22, call; 22, 23; 22, 24; 23, identifier:list; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:ix_; 29, argument_list; 29, 30; 30, list_splat; 30, 31; 31, list_comprehension; 31, 32; 31, 38; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:np; 35, identifier:arange; 36, argument_list; 36, 37; 37, identifier:d; 38, for_in_clause; 38, 39; 38, 40; 39, identifier:d; 40, attribute; 40, 41; 40, 42; 41, identifier:a; 42, identifier:shape; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:ind; 47, identifier:axis; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:a; 51, identifier:argsort; 52, argument_list; 52, 53; 53, identifier:axis; 54, return_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:tuple; 57, argument_list; 57, 58; 58, identifier:ind | def argsort_indices(a, axis=-1):
a = np.asarray(a)
ind = list(np.ix_(*[np.arange(d) for d in a.shape]))
ind[axis] = a.argsort(axis)
return tuple(ind) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted; 3, parameters; 3, 4; 4, identifier:collection; 5, block; 5, 6; 5, 16; 5, 40; 5, 99; 6, if_statement; 6, 7; 6, 13; 7, comparison_operator:<; 7, 8; 7, 12; 8, call; 8, 9; 8, 10; 9, identifier:len; 10, argument_list; 10, 11; 11, identifier:collection; 12, integer:1; 13, block; 13, 14; 14, return_statement; 14, 15; 15, identifier:collection; 16, if_statement; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:collection; 21, identifier:dict; 22, block; 22, 23; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:sorted; 26, argument_list; 26, 27; 26, 32; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:collection; 30, identifier:items; 31, argument_list; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:key; 34, lambda; 34, 35; 34, 37; 35, lambda_parameters; 35, 36; 36, identifier:x; 37, subscript; 37, 38; 37, 39; 38, identifier:x; 39, integer:0; 40, if_statement; 40, 41; 40, 51; 40, 61; 40, 87; 41, call; 41, 42; 41, 43; 42, identifier:isinstance; 43, argument_list; 43, 44; 43, 50; 44, subscript; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:list; 47, argument_list; 47, 48; 48, identifier:collection; 49, integer:0; 50, identifier:Operation; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:key; 55, lambda; 55, 56; 55, 58; 56, lambda_parameters; 56, 57; 57, identifier:x; 58, attribute; 58, 59; 58, 60; 59, identifier:x; 60, identifier:operation_id; 61, elif_clause; 61, 62; 61, 72; 62, call; 62, 63; 62, 64; 63, identifier:isinstance; 64, argument_list; 64, 65; 64, 71; 65, subscript; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:list; 68, argument_list; 68, 69; 69, identifier:collection; 70, integer:0; 71, identifier:str; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:key; 76, lambda; 76, 77; 76, 79; 77, lambda_parameters; 77, 78; 78, identifier:x; 79, attribute; 79, 80; 79, 86; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:SchemaObjects; 83, identifier:get; 84, argument_list; 84, 85; 85, identifier:x; 86, identifier:name; 87, else_clause; 87, 88; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:TypeError; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:type; 95, argument_list; 95, 96; 96, subscript; 96, 97; 96, 98; 97, identifier:collection; 98, integer:0; 99, return_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:sorted; 102, argument_list; 102, 103; 102, 104; 103, identifier:collection; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:key; 106, identifier:key | def sorted(collection):
if len(collection) < 1:
return collection
if isinstance(collection, dict):
return sorted(collection.items(), key=lambda x: x[0])
if isinstance(list(collection)[0], Operation):
key = lambda x: x.operation_id
elif isinstance(list(collection)[0], str):
key = lambda x: SchemaObjects.get(x).name
else:
raise TypeError(type(collection[0]))
return sorted(collection, key=key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_schemas; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:schema_types; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort; 10, True; 11, block; 11, 12; 11, 32; 11, 50; 11, 66; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:result; 15, call; 15, 16; 15, 17; 16, identifier:filter; 17, argument_list; 17, 18; 17, 25; 18, lambda; 18, 19; 18, 21; 19, lambda_parameters; 19, 20; 20, identifier:x; 21, not_operator; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:x; 24, identifier:is_inline_array; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:cls; 29, identifier:_schemas; 30, identifier:values; 31, argument_list; 32, if_statement; 32, 33; 32, 34; 33, identifier:schema_types; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:result; 38, call; 38, 39; 38, 40; 39, identifier:filter; 40, argument_list; 40, 41; 40, 49; 41, lambda; 41, 42; 41, 44; 42, lambda_parameters; 42, 43; 43, identifier:x; 44, comparison_operator:in; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:x; 47, identifier:schema_type; 48, identifier:schema_types; 49, identifier:result; 50, if_statement; 50, 51; 50, 52; 51, identifier:sort; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:result; 56, call; 56, 57; 56, 58; 57, identifier:sorted; 58, argument_list; 58, 59; 58, 60; 59, identifier:result; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:key; 62, call; 62, 63; 62, 64; 63, identifier:attrgetter; 64, argument_list; 64, 65; 65, string:'name'; 66, return_statement; 66, 67; 67, identifier:result | def get_schemas(cls, schema_types=None, sort=True):
result = filter(lambda x: not x.is_inline_array, cls._schemas.values())
if schema_types:
result = filter(lambda x: x.schema_type in schema_types, result)
if sort:
result = sorted(result, key=attrgetter('name'))
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:to_molden; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:cartesian_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:buf; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_index; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:overwrite; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:float_format; 16, attribute; 16, 17; 16, 18; 17, string:'{:.6f}'; 18, identifier:format; 19, block; 19, 20; 19, 35; 19, 64; 19, 73; 19, 92; 19, 103; 19, 118; 19, 136; 19, 147; 20, if_statement; 20, 21; 20, 22; 21, identifier:sort_index; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:cartesian_list; 26, list_comprehension; 26, 27; 26, 32; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:molecule; 30, identifier:sort_index; 31, argument_list; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:molecule; 34, identifier:cartesian_list; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:give_header; 38, attribute; 38, 39; 38, 63; 39, parenthesized_expression; 39, 40; 40, binary_operator:+; 40, 41; 40, 62; 41, binary_operator:+; 41, 42; 41, 61; 42, binary_operator:+; 42, 43; 42, 60; 43, binary_operator:+; 43, 44; 43, 59; 44, binary_operator:+; 44, 45; 44, 58; 45, binary_operator:+; 45, 46; 45, 57; 46, binary_operator:+; 46, 47; 46, 50; 47, binary_operator:+; 47, 48; 47, 49; 48, string:"[MOLDEN FORMAT]\n"; 49, string:"[N_GEO]\n"; 50, call; 50, 51; 50, 52; 51, identifier:str; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:cartesian_list; 57, string:"\n"; 58, string:'[GEOCONV]\n'; 59, string:'energy\n{energy}'; 60, string:'max-force\n{max_force}'; 61, string:'rms-force\n{rms_force}'; 62, string:'[GEOMETRIES] (XYZ)\n'; 63, identifier:format; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:values; 67, binary_operator:*; 67, 68; 67, 72; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:cartesian_list; 72, string:'1\n'; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:energy; 76, list_comprehension; 76, 77; 76, 89; 77, call; 77, 78; 77, 79; 78, identifier:str; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:m; 84, identifier:metadata; 85, identifier:get; 86, argument_list; 86, 87; 86, 88; 87, string:'energy'; 88, integer:1; 89, for_in_clause; 89, 90; 89, 91; 90, identifier:m; 91, identifier:cartesian_list; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:energy; 95, binary_operator:+; 95, 96; 95, 102; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, string:'\n'; 99, identifier:join; 100, argument_list; 100, 101; 101, identifier:energy; 102, string:'\n'; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:header; 106, call; 106, 107; 106, 108; 107, identifier:give_header; 108, argument_list; 108, 109; 108, 112; 108, 115; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:energy; 111, identifier:energy; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:max_force; 114, identifier:values; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:rms_force; 117, identifier:values; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:coordinates; 121, list_comprehension; 121, 122; 121, 133; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:x; 125, identifier:to_xyz; 126, argument_list; 126, 127; 126, 130; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:sort_index; 129, identifier:sort_index; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:float_format; 132, identifier:float_format; 133, for_in_clause; 133, 134; 133, 135; 134, identifier:x; 135, identifier:cartesian_list; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:output; 139, binary_operator:+; 139, 140; 139, 141; 140, identifier:header; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, string:'\n'; 144, identifier:join; 145, argument_list; 145, 146; 146, identifier:coordinates; 147, if_statement; 147, 148; 147, 151; 147, 199; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:buf; 150, None; 151, block; 151, 152; 152, if_statement; 152, 153; 152, 154; 152, 176; 153, identifier:overwrite; 154, block; 154, 155; 155, with_statement; 155, 156; 155, 168; 156, with_clause; 156, 157; 157, with_item; 157, 158; 158, as_pattern; 158, 159; 158, 166; 159, call; 159, 160; 159, 161; 160, identifier:open; 161, argument_list; 161, 162; 161, 163; 162, identifier:buf; 163, keyword_argument; 163, 164; 163, 165; 164, identifier:mode; 165, string:'w'; 166, as_pattern_target; 166, 167; 167, identifier:f; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:f; 173, identifier:write; 174, argument_list; 174, 175; 175, identifier:output; 176, else_clause; 176, 177; 177, block; 177, 178; 178, with_statement; 178, 179; 178, 191; 179, with_clause; 179, 180; 180, with_item; 180, 181; 181, as_pattern; 181, 182; 181, 189; 182, call; 182, 183; 182, 184; 183, identifier:open; 184, argument_list; 184, 185; 184, 186; 185, identifier:buf; 186, keyword_argument; 186, 187; 186, 188; 187, identifier:mode; 188, string:'x'; 189, as_pattern_target; 189, 190; 190, identifier:f; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:f; 196, identifier:write; 197, argument_list; 197, 198; 198, identifier:output; 199, else_clause; 199, 200; 200, block; 200, 201; 201, return_statement; 201, 202; 202, identifier:output | def to_molden(cartesian_list, buf=None, sort_index=True,
overwrite=True, float_format='{:.6f}'.format):
if sort_index:
cartesian_list = [molecule.sort_index() for molecule in cartesian_list]
give_header = ("[MOLDEN FORMAT]\n"
+ "[N_GEO]\n"
+ str(len(cartesian_list)) + "\n"
+ '[GEOCONV]\n'
+ 'energy\n{energy}'
+ 'max-force\n{max_force}'
+ 'rms-force\n{rms_force}'
+ '[GEOMETRIES] (XYZ)\n').format
values = len(cartesian_list) * '1\n'
energy = [str(m.metadata.get('energy', 1)) for m in cartesian_list]
energy = '\n'.join(energy) + '\n'
header = give_header(energy=energy, max_force=values, rms_force=values)
coordinates = [x.to_xyz(sort_index=sort_index, float_format=float_format)
for x in cartesian_list]
output = header + '\n'.join(coordinates)
if buf is not None:
if overwrite:
with open(buf, mode='w') as f:
f.write(output)
else:
with open(buf, mode='x') as f:
f.write(output)
else:
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_inertia; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 143; 5, 152; 5, 162; 5, 172; 5, 181; 5, 190; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:calculate_inertia_tensor; 8, parameters; 8, 9; 9, identifier:molecule; 10, block; 10, 11; 10, 23; 10, 38; 10, 102; 10, 115; 10, 124; 10, 130; 10, 138; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:masses; 14, attribute; 14, 15; 14, 22; 15, subscript; 15, 16; 15, 19; 15, 21; 16, attribute; 16, 17; 16, 18; 17, identifier:molecule; 18, identifier:loc; 19, slice; 19, 20; 20, colon; 21, string:'mass'; 22, identifier:values; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:pos; 26, attribute; 26, 27; 26, 37; 27, subscript; 27, 28; 27, 31; 27, 33; 28, attribute; 28, 29; 28, 30; 29, identifier:molecule; 30, identifier:loc; 31, slice; 31, 32; 32, colon; 33, list:['x', 'y', 'z']; 33, 34; 33, 35; 33, 36; 34, string:'x'; 35, string:'y'; 36, string:'z'; 37, identifier:values; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:inertia; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:np; 44, identifier:sum; 45, argument_list; 45, 46; 45, 99; 46, binary_operator:*; 46, 47; 46, 53; 47, subscript; 47, 48; 47, 49; 47, 51; 47, 52; 48, identifier:masses; 49, slice; 49, 50; 50, colon; 51, None; 52, None; 53, parenthesized_expression; 53, 54; 54, binary_operator:-; 54, 55; 54, 84; 55, binary_operator:*; 55, 56; 55, 72; 56, subscript; 56, 57; 56, 68; 56, 70; 56, 71; 57, call; 57, 58; 57, 64; 58, attribute; 58, 59; 58, 63; 59, parenthesized_expression; 59, 60; 60, binary_operator:**; 60, 61; 60, 62; 61, identifier:pos; 62, integer:2; 63, identifier:sum; 64, argument_list; 64, 65; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:axis; 67, integer:1; 68, slice; 68, 69; 69, colon; 70, None; 71, None; 72, subscript; 72, 73; 72, 79; 72, 80; 72, 82; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:np; 76, identifier:identity; 77, argument_list; 77, 78; 78, integer:3; 79, None; 80, slice; 80, 81; 81, colon; 82, slice; 82, 83; 83, colon; 84, binary_operator:*; 84, 85; 84, 92; 85, subscript; 85, 86; 85, 87; 85, 89; 85, 91; 86, identifier:pos; 87, slice; 87, 88; 88, colon; 89, slice; 89, 90; 90, colon; 91, None; 92, subscript; 92, 93; 92, 94; 92, 96; 92, 97; 93, identifier:pos; 94, slice; 94, 95; 95, colon; 96, None; 97, slice; 97, 98; 98, colon; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:axis; 101, integer:0; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, pattern_list; 104, 105; 104, 106; 105, identifier:diag_inertia; 106, identifier:eig_v; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:np; 111, identifier:linalg; 112, identifier:eig; 113, argument_list; 113, 114; 114, identifier:inertia; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:sorted_index; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:np; 121, identifier:argsort; 122, argument_list; 122, 123; 123, identifier:diag_inertia; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:diag_inertia; 127, subscript; 127, 128; 127, 129; 128, identifier:diag_inertia; 129, identifier:sorted_index; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:eig_v; 133, subscript; 133, 134; 133, 135; 133, 137; 134, identifier:eig_v; 135, slice; 135, 136; 136, colon; 137, identifier:sorted_index; 138, return_statement; 138, 139; 139, expression_list; 139, 140; 139, 141; 139, 142; 140, identifier:inertia; 141, identifier:eig_v; 142, identifier:diag_inertia; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:molecule; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:add_data; 150, argument_list; 150, 151; 151, string:'mass'; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:molecule; 155, binary_operator:-; 155, 156; 155, 157; 156, identifier:molecule; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:molecule; 160, identifier:get_barycenter; 161, argument_list; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 168; 164, pattern_list; 164, 165; 164, 166; 164, 167; 165, identifier:inertia; 166, identifier:eig_v; 167, identifier:diag_inertia; 168, call; 168, 169; 168, 170; 169, identifier:calculate_inertia_tensor; 170, argument_list; 170, 171; 171, identifier:molecule; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:eig_v; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:xyz_functions; 178, identifier:orthonormalize_righthanded; 179, argument_list; 179, 180; 180, identifier:eig_v; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:molecule; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:molecule; 187, identifier:basistransform; 188, argument_list; 188, 189; 189, identifier:eig_v; 190, return_statement; 190, 191; 191, dictionary; 191, 192; 191, 195; 191, 198; 191, 201; 192, pair; 192, 193; 192, 194; 193, string:'transformed_Cartesian'; 194, identifier:molecule; 195, pair; 195, 196; 195, 197; 196, string:'eigenvectors'; 197, identifier:eig_v; 198, pair; 198, 199; 198, 200; 199, string:'diag_inertia_tensor'; 200, identifier:diag_inertia; 201, pair; 201, 202; 201, 203; 202, string:'inertia_tensor'; 203, identifier:inertia | def get_inertia(self):
def calculate_inertia_tensor(molecule):
masses = molecule.loc[:, 'mass'].values
pos = molecule.loc[:, ['x', 'y', 'z']].values
inertia = np.sum(
masses[:, None, None]
* ((pos**2).sum(axis=1)[:, None, None]
* np.identity(3)[None, :, :]
- pos[:, :, None] * pos[:, None, :]),
axis=0)
diag_inertia, eig_v = np.linalg.eig(inertia)
sorted_index = np.argsort(diag_inertia)
diag_inertia = diag_inertia[sorted_index]
eig_v = eig_v[:, sorted_index]
return inertia, eig_v, diag_inertia
molecule = self.add_data('mass')
molecule = molecule - molecule.get_barycenter()
inertia, eig_v, diag_inertia = calculate_inertia_tensor(molecule)
eig_v = xyz_functions.orthonormalize_righthanded(eig_v)
molecule = molecule.basistransform(eig_v)
return {'transformed_Cartesian': molecule, 'eigenvectors': eig_v,
'diag_inertia_tensor': diag_inertia, 'inertia_tensor': inertia} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:to_xyz; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 22; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:buf; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_index; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:index; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:header; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:float_format; 19, attribute; 19, 20; 19, 21; 20, string:'{:.6f}'; 21, identifier:format; 22, default_parameter; 22, 23; 22, 24; 23, identifier:overwrite; 24, True; 25, block; 25, 26; 25, 69; 25, 102; 25, 125; 26, if_statement; 26, 27; 26, 28; 26, 50; 27, identifier:sort_index; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:molecule_string; 32, call; 32, 33; 32, 40; 33, attribute; 33, 34; 33, 39; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:sort_index; 38, argument_list; 39, identifier:to_string; 40, argument_list; 40, 41; 40, 44; 40, 47; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:header; 43, identifier:header; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:index; 46, identifier:index; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:float_format; 49, identifier:float_format; 50, else_clause; 50, 51; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:molecule_string; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:to_string; 59, argument_list; 59, 60; 59, 63; 59, 66; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:header; 62, identifier:header; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:index; 65, identifier:index; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:float_format; 68, identifier:float_format; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:space; 72, binary_operator:*; 72, 73; 72, 74; 73, string:' '; 74, parenthesized_expression; 74, 75; 75, binary_operator:-; 75, 76; 75, 93; 76, call; 76, 77; 76, 92; 77, attribute; 77, 78; 77, 91; 78, call; 78, 79; 78, 90; 79, attribute; 79, 80; 79, 89; 80, attribute; 80, 81; 80, 88; 81, subscript; 81, 82; 81, 85; 81, 87; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:loc; 85, slice; 85, 86; 86, colon; 87, string:'atom'; 88, identifier:str; 89, identifier:len; 90, argument_list; 91, identifier:max; 92, argument_list; 93, call; 93, 94; 93, 95; 94, identifier:len; 95, argument_list; 95, 96; 96, subscript; 96, 97; 96, 100; 96, 101; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:iloc; 100, integer:0; 101, integer:0; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:output; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:'{n}\n{message}\n{alignment}{frame_string}'; 108, identifier:format; 109, argument_list; 109, 110; 109, 116; 109, 119; 109, 122; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:n; 112, call; 112, 113; 112, 114; 113, identifier:len; 114, argument_list; 114, 115; 115, identifier:self; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:alignment; 118, identifier:space; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:frame_string; 121, identifier:molecule_string; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:message; 124, string:'Created by chemcoord http://chemcoord.readthedocs.io/'; 125, if_statement; 125, 126; 125, 129; 125, 177; 126, comparison_operator:is; 126, 127; 126, 128; 127, identifier:buf; 128, None; 129, block; 129, 130; 130, if_statement; 130, 131; 130, 132; 130, 154; 131, identifier:overwrite; 132, block; 132, 133; 133, with_statement; 133, 134; 133, 146; 134, with_clause; 134, 135; 135, with_item; 135, 136; 136, as_pattern; 136, 137; 136, 144; 137, call; 137, 138; 137, 139; 138, identifier:open; 139, argument_list; 139, 140; 139, 141; 140, identifier:buf; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:mode; 143, string:'w'; 144, as_pattern_target; 144, 145; 145, identifier:f; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:f; 151, identifier:write; 152, argument_list; 152, 153; 153, identifier:output; 154, else_clause; 154, 155; 155, block; 155, 156; 156, with_statement; 156, 157; 156, 169; 157, with_clause; 157, 158; 158, with_item; 158, 159; 159, as_pattern; 159, 160; 159, 167; 160, call; 160, 161; 160, 162; 161, identifier:open; 162, argument_list; 162, 163; 162, 164; 163, identifier:buf; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:mode; 166, string:'x'; 167, as_pattern_target; 167, 168; 168, identifier:f; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:f; 174, identifier:write; 175, argument_list; 175, 176; 176, identifier:output; 177, else_clause; 177, 178; 178, block; 178, 179; 179, return_statement; 179, 180; 180, identifier:output | def to_xyz(self, buf=None, sort_index=True,
index=False, header=False, float_format='{:.6f}'.format,
overwrite=True):
if sort_index:
molecule_string = self.sort_index().to_string(
header=header, index=index, float_format=float_format)
else:
molecule_string = self.to_string(header=header, index=index,
float_format=float_format)
space = ' ' * (self.loc[:, 'atom'].str.len().max()
- len(self.iloc[0, 0]))
output = '{n}\n{message}\n{alignment}{frame_string}'.format(
n=len(self), alignment=space, frame_string=molecule_string,
message='Created by chemcoord http://chemcoord.readthedocs.io/')
if buf is not None:
if overwrite:
with open(buf, mode='w') as f:
f.write(output)
else:
with open(buf, mode='x') as f:
f.write(output)
else:
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:priority; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 23; 6, if_statement; 6, 7; 6, 16; 7, comparison_operator:==; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:compiled_type; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:const; 14, identifier:COMPILED_TYPE; 15, identifier:MARKER; 16, block; 16, 17; 17, return_statement; 17, 18; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:compiled; 22, identifier:priority; 23, return_statement; 23, 24; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:const; 27, identifier:compiled_type_priorities; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:compiled_type | def priority(self):
if self.compiled_type == const.COMPILED_TYPE.MARKER:
return self.compiled.priority
return const.compiled_type_priorities[self.compiled_type] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_schemas; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:schemas_list; 6, block; 6, 7; 7, return_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 10, 12; 10, 39; 11, identifier:schemas_list; 12, keyword_argument; 12, 13; 12, 14; 13, identifier:key; 14, lambda; 14, 15; 14, 17; 15, lambda_parameters; 15, 16; 16, identifier:x; 17, tuple; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:x; 20, identifier:priority; 21, conditional_expression:if; 21, 22; 21, 29; 21, 38; 22, attribute; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:x; 26, identifier:compiled; 27, identifier:key_schema; 28, identifier:priority; 29, comparison_operator:==; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:x; 32, identifier:compiled_type; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:const; 36, identifier:COMPILED_TYPE; 37, identifier:MARKER; 38, integer:0; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:reverse; 41, True | def sort_schemas(cls, schemas_list):
return sorted(schemas_list,
key=lambda x: (
x.priority,
x.compiled.key_schema.priority if x.compiled_type == const.COMPILED_TYPE.MARKER else 0
), reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:patch_cursor; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:cursor; 5, default_parameter; 5, 6; 5, 7; 6, identifier:batch_size; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:limit; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:skip; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort; 16, None; 17, dictionary_splat_pattern; 17, 18; 18, identifier:kwargs; 19, block; 19, 20; 19, 35; 19, 47; 19, 59; 20, if_statement; 20, 21; 20, 27; 21, comparison_operator:==; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:type; 24, argument_list; 24, 25; 25, identifier:batch_size; 26, identifier:int; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:cursor; 32, identifier:batch_size; 33, argument_list; 33, 34; 34, identifier:batch_size; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:limit; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:cursor; 44, identifier:limit; 45, argument_list; 45, 46; 46, identifier:limit; 47, if_statement; 47, 48; 47, 51; 48, comparison_operator:is; 48, 49; 48, 50; 49, identifier:sort; 50, None; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:cursor; 56, identifier:sort; 57, argument_list; 57, 58; 58, identifier:sort; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:skip; 62, None; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:cursor; 68, identifier:skip; 69, argument_list; 69, 70; 70, identifier:skip | def patch_cursor(cursor, batch_size=None, limit=None, skip=None, sort=None, **kwargs):
if type(batch_size) == int:
cursor.batch_size(batch_size)
if limit is not None:
cursor.limit(limit)
if sort is not None:
cursor.sort(sort)
if skip is not None:
cursor.skip(skip) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:add_interval; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:start; 6, identifier:end; 7, default_parameter; 7, 8; 7, 9; 8, identifier:data; 9, None; 10, block; 10, 11; 10, 13; 10, 22; 11, expression_statement; 11, 12; 12, string:'''
Inserts an interval to the tree.
Note that when inserting we do not maintain appropriate sorting of the "mid" data structure.
This should be done after all intervals are inserted.
'''; 13, if_statement; 13, 14; 13, 20; 14, comparison_operator:<=; 14, 15; 14, 19; 15, parenthesized_expression; 15, 16; 16, binary_operator:-; 16, 17; 16, 18; 17, identifier:end; 18, identifier:start; 19, integer:0; 20, block; 20, 21; 21, return_statement; 22, if_statement; 22, 23; 22, 28; 22, 38; 22, 54; 23, comparison_operator:is; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:single_interval; 27, None; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:single_interval; 34, tuple; 34, 35; 34, 36; 34, 37; 35, identifier:start; 36, identifier:end; 37, identifier:data; 38, elif_clause; 38, 39; 38, 44; 39, comparison_operator:==; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:single_interval; 43, integer:0; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_add_interval; 50, argument_list; 50, 51; 50, 52; 50, 53; 51, identifier:start; 52, identifier:end; 53, identifier:data; 54, else_clause; 54, 55; 55, block; 55, 56; 55, 66; 55, 72; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_add_interval; 61, argument_list; 61, 62; 62, list_splat; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:single_interval; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:single_interval; 71, integer:0; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_add_interval; 77, argument_list; 77, 78; 77, 79; 77, 80; 78, identifier:start; 79, identifier:end; 80, identifier:data | def add_interval(self, start, end, data=None):
'''
Inserts an interval to the tree.
Note that when inserting we do not maintain appropriate sorting of the "mid" data structure.
This should be done after all intervals are inserted.
'''
if (end - start) <= 0:
return
if self.single_interval is None:
self.single_interval = (start, end, data)
elif self.single_interval == 0:
self._add_interval(start, end, data)
else:
self._add_interval(*self.single_interval)
self.single_interval = 0
self._add_interval(start, end, data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:querydict; 6, block; 6, 7; 6, 49; 6, 129; 7, for_statement; 7, 8; 7, 9; 7, 14; 8, identifier:key; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:querydict; 12, identifier:keys; 13, argument_list; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 34; 16, not_operator; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:any; 19, argument_list; 19, 20; 20, tuple; 20, 21; 20, 26; 21, comparison_operator:in; 21, 22; 21, 23; 22, identifier:key; 23, attribute; 23, 24; 23, 25; 24, identifier:JSONAPIQueryDict; 25, identifier:_fields; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:cls; 30, identifier:RE_FIELDS; 31, identifier:match; 32, argument_list; 32, 33; 33, identifier:key; 34, block; 34, 35; 34, 44; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:msg; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, string:"Query parameter {} is not known"; 41, identifier:format; 42, argument_list; 42, 43; 43, identifier:key; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, identifier:msg; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:result; 52, call; 52, 53; 52, 54; 53, identifier:JSONAPIQueryDict; 54, argument_list; 54, 55; 54, 68; 54, 76; 54, 84; 54, 97; 54, 116; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:distinct; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:cls; 60, identifier:prepare_values; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:querydict; 65, identifier:getlist; 66, argument_list; 66, 67; 67, string:'distinct'; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:fields; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:cls; 73, identifier:parse_fields; 74, argument_list; 74, 75; 75, identifier:querydict; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:filter; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:querydict; 81, identifier:getlist; 82, argument_list; 82, 83; 83, string:'filter'; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:include; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:cls; 89, identifier:prepare_values; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:querydict; 94, identifier:getlist; 95, argument_list; 95, 96; 96, string:'include'; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:page; 99, conditional_expression:if; 99, 100; 99, 109; 99, 115; 100, call; 100, 101; 100, 102; 101, identifier:int; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:querydict; 106, identifier:get; 107, argument_list; 107, 108; 108, string:'page'; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:querydict; 112, identifier:get; 113, argument_list; 113, 114; 114, string:'page'; 115, None; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:sort; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:cls; 121, identifier:prepare_values; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:querydict; 126, identifier:getlist; 127, argument_list; 127, 128; 128, string:'sort'; 129, return_statement; 129, 130; 130, identifier:result | def parse(cls, querydict):
for key in querydict.keys():
if not any((key in JSONAPIQueryDict._fields,
cls.RE_FIELDS.match(key))):
msg = "Query parameter {} is not known".format(key)
raise ValueError(msg)
result = JSONAPIQueryDict(
distinct=cls.prepare_values(querydict.getlist('distinct')),
fields=cls.parse_fields(querydict),
filter=querydict.getlist('filter'),
include=cls.prepare_values(querydict.getlist('include')),
page=int(querydict.get('page')) if querydict.get('page') else None,
sort=cls.prepare_values(querydict.getlist('sort'))
)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_pcca_connected_isa; 3, parameters; 3, 4; 3, 5; 4, identifier:evec; 5, identifier:n_clusters; 6, block; 6, 7; 6, 15; 6, 46; 6, 73; 6, 82; 6, 91; 6, 105; 6, 114; 6, 118; 6, 132; 6, 172; 6, 181; 6, 290; 6, 303; 6, 313; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, tuple_pattern; 9, 10; 9, 11; 10, identifier:n; 11, identifier:m; 12, attribute; 12, 13; 12, 14; 13, identifier:evec; 14, identifier:shape; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:>; 16, 17; 16, 18; 17, identifier:n_clusters; 18, identifier:m; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:ValueError; 23, argument_list; 23, 24; 24, binary_operator:+; 24, 25; 24, 45; 25, binary_operator:+; 25, 26; 25, 41; 26, binary_operator:+; 26, 27; 26, 40; 27, binary_operator:+; 27, 28; 27, 36; 28, binary_operator:+; 28, 29; 28, 35; 29, binary_operator:+; 29, 30; 29, 31; 30, string:"Cannot cluster the ("; 31, call; 31, 32; 31, 33; 32, identifier:str; 33, argument_list; 33, 34; 34, identifier:n; 35, string:" x "; 36, call; 36, 37; 36, 38; 37, identifier:str; 38, argument_list; 38, 39; 39, identifier:m; 40, string:" eigenvector matrix to "; 41, call; 41, 42; 41, 43; 42, identifier:str; 43, argument_list; 43, 44; 44, identifier:n_clusters; 45, string:" clusters."; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:diffs; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:np; 52, identifier:abs; 53, argument_list; 53, 54; 54, binary_operator:-; 54, 55; 54, 64; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:np; 58, identifier:max; 59, argument_list; 59, 60; 59, 61; 60, identifier:evec; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:axis; 63, integer:0; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:np; 67, identifier:min; 68, argument_list; 68, 69; 68, 70; 69, identifier:evec; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:axis; 72, integer:0; 73, assert_statement; 73, 74; 73, 79; 74, comparison_operator:<; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:diffs; 77, integer:0; 78, float:1e-6; 79, concatenated_string; 79, 80; 79, 81; 80, string:"First eigenvector is not constant. This indicates that the transition matrix "; 81, string:"is not connected or the eigenvectors are incorrectly sorted. Cannot do PCCA."; 82, assert_statement; 82, 83; 82, 88; 83, comparison_operator:>; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:diffs; 86, integer:1; 87, float:1e-6; 88, concatenated_string; 88, 89; 88, 90; 89, string:"An eigenvector after the first one is constant. "; 90, string:"Probably the eigenvectors are incorrectly sorted. Cannot do PCCA."; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:c; 94, subscript; 94, 95; 94, 96; 94, 98; 95, identifier:evec; 96, slice; 96, 97; 97, colon; 98, call; 98, 99; 98, 100; 99, identifier:list; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:range; 103, argument_list; 103, 104; 104, identifier:n_clusters; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:ortho_sys; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:np; 111, identifier:copy; 112, argument_list; 112, 113; 113, identifier:c; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:max_dist; 117, float:0.0; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:ind; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:np; 124, identifier:zeros; 125, argument_list; 125, 126; 125, 127; 126, identifier:n_clusters; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:dtype; 129, attribute; 129, 130; 129, 131; 130, identifier:np; 131, identifier:int32; 132, for_statement; 132, 133; 132, 136; 132, 140; 133, tuple_pattern; 133, 134; 133, 135; 134, identifier:i; 135, identifier:row; 136, call; 136, 137; 136, 138; 137, identifier:enumerate; 138, argument_list; 138, 139; 139, identifier:c; 140, block; 140, 141; 141, if_statement; 141, 142; 141, 153; 142, comparison_operator:>; 142, 143; 142, 152; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:np; 147, identifier:linalg; 148, identifier:norm; 149, argument_list; 149, 150; 149, 151; 150, identifier:row; 151, integer:2; 152, identifier:max_dist; 153, block; 153, 154; 153, 166; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:max_dist; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:np; 161, identifier:linalg; 162, identifier:norm; 163, argument_list; 163, 164; 163, 165; 164, identifier:row; 165, integer:2; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:ind; 170, integer:0; 171, identifier:i; 172, expression_statement; 172, 173; 173, augmented_assignment:-=; 173, 174; 173, 175; 174, identifier:ortho_sys; 175, subscript; 175, 176; 175, 177; 175, 180; 176, identifier:c; 177, subscript; 177, 178; 177, 179; 178, identifier:ind; 179, integer:0; 180, None; 181, for_statement; 181, 182; 181, 183; 181, 188; 182, identifier:k; 183, call; 183, 184; 183, 185; 184, identifier:range; 185, argument_list; 185, 186; 185, 187; 186, integer:1; 187, identifier:n_clusters; 188, block; 188, 189; 188, 193; 188, 208; 188, 274; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:max_dist; 192, float:0.0; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:temp; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:np; 199, identifier:copy; 200, argument_list; 200, 201; 201, subscript; 201, 202; 201, 203; 202, identifier:ortho_sys; 203, subscript; 203, 204; 203, 205; 204, identifier:ind; 205, binary_operator:-; 205, 206; 205, 207; 206, identifier:k; 207, integer:1; 208, for_statement; 208, 209; 208, 212; 208, 216; 209, tuple_pattern; 209, 210; 209, 211; 210, identifier:i; 211, identifier:row; 212, call; 212, 213; 212, 214; 213, identifier:enumerate; 214, argument_list; 214, 215; 215, identifier:ortho_sys; 216, block; 216, 217; 216, 238; 216, 250; 217, expression_statement; 217, 218; 218, augmented_assignment:-=; 218, 219; 218, 220; 219, identifier:row; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:np; 223, identifier:dot; 224, argument_list; 224, 225; 224, 237; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:np; 228, identifier:dot; 229, argument_list; 229, 230; 229, 231; 230, identifier:temp; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:np; 234, identifier:transpose; 235, argument_list; 235, 236; 236, identifier:row; 237, identifier:temp; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:distt; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:np; 245, identifier:linalg; 246, identifier:norm; 247, argument_list; 247, 248; 247, 249; 248, identifier:row; 249, integer:2; 250, if_statement; 250, 251; 250, 263; 251, boolean_operator:and; 251, 252; 251, 255; 252, comparison_operator:>; 252, 253; 252, 254; 253, identifier:distt; 254, identifier:max_dist; 255, comparison_operator:not; 255, 256; 255, 257; 256, identifier:i; 257, subscript; 257, 258; 257, 259; 258, identifier:ind; 259, slice; 259, 260; 259, 261; 259, 262; 260, integer:0; 261, colon; 262, identifier:k; 263, block; 263, 264; 263, 268; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:max_dist; 267, identifier:distt; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 273; 270, subscript; 270, 271; 270, 272; 271, identifier:ind; 272, identifier:k; 273, identifier:i; 274, expression_statement; 274, 275; 275, augmented_assignment:/=; 275, 276; 275, 277; 276, identifier:ortho_sys; 277, call; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:np; 281, identifier:linalg; 282, identifier:norm; 283, argument_list; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 286; 285, identifier:ortho_sys; 286, subscript; 286, 287; 286, 288; 287, identifier:ind; 288, identifier:k; 289, integer:2; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:rot_mat; 293, call; 293, 294; 293, 299; 294, attribute; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:np; 297, identifier:linalg; 298, identifier:inv; 299, argument_list; 299, 300; 300, subscript; 300, 301; 300, 302; 301, identifier:c; 302, identifier:ind; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:chi; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:np; 309, identifier:dot; 310, argument_list; 310, 311; 310, 312; 311, identifier:c; 312, identifier:rot_mat; 313, return_statement; 313, 314; 314, tuple; 314, 315; 314, 316; 315, identifier:chi; 316, identifier:rot_mat | def _pcca_connected_isa(evec, n_clusters):
(n, m) = evec.shape
if n_clusters > m:
raise ValueError("Cannot cluster the (" + str(n) + " x " + str(m)
+ " eigenvector matrix to " + str(n_clusters) + " clusters.")
diffs = np.abs(np.max(evec, axis=0) - np.min(evec, axis=0))
assert diffs[0] < 1e-6, "First eigenvector is not constant. This indicates that the transition matrix " \
"is not connected or the eigenvectors are incorrectly sorted. Cannot do PCCA."
assert diffs[1] > 1e-6, "An eigenvector after the first one is constant. " \
"Probably the eigenvectors are incorrectly sorted. Cannot do PCCA."
c = evec[:, list(range(n_clusters))]
ortho_sys = np.copy(c)
max_dist = 0.0
ind = np.zeros(n_clusters, dtype=np.int32)
for (i, row) in enumerate(c):
if np.linalg.norm(row, 2) > max_dist:
max_dist = np.linalg.norm(row, 2)
ind[0] = i
ortho_sys -= c[ind[0], None]
for k in range(1, n_clusters):
max_dist = 0.0
temp = np.copy(ortho_sys[ind[k - 1]])
for (i, row) in enumerate(ortho_sys):
row -= np.dot(np.dot(temp, np.transpose(row)), temp)
distt = np.linalg.norm(row, 2)
if distt > max_dist and i not in ind[0:k]:
max_dist = distt
ind[k] = i
ortho_sys /= np.linalg.norm(ortho_sys[ind[k]], 2)
rot_mat = np.linalg.inv(c[ind])
chi = np.dot(c, rot_mat)
return (chi, rot_mat) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_opt_soft; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:eigvectors; 5, identifier:rot_matrix; 6, identifier:n_clusters; 7, block; 7, 8; 7, 18; 7, 32; 7, 40; 7, 52; 7, 119; 7, 125; 7, 140; 7, 152; 7, 160; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:eigvectors; 11, subscript; 11, 12; 11, 13; 11, 15; 12, identifier:eigvectors; 13, slice; 13, 14; 14, colon; 15, slice; 15, 16; 15, 17; 16, colon; 17, identifier:n_clusters; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:rot_crop_matrix; 21, subscript; 21, 22; 21, 27; 21, 29; 22, subscript; 22, 23; 22, 24; 23, identifier:rot_matrix; 24, slice; 24, 25; 24, 26; 25, integer:1; 26, colon; 27, slice; 27, 28; 28, colon; 29, slice; 29, 30; 29, 31; 30, integer:1; 31, colon; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, tuple_pattern; 34, 35; 34, 36; 35, identifier:x; 36, identifier:y; 37, attribute; 37, 38; 37, 39; 38, identifier:rot_crop_matrix; 39, identifier:shape; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:rot_crop_vec; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:reshape; 47, argument_list; 47, 48; 47, 49; 48, identifier:rot_crop_matrix; 49, binary_operator:*; 49, 50; 49, 51; 50, identifier:x; 51, identifier:y; 52, function_definition; 52, 53; 52, 54; 52, 57; 53, function_name:susanna_func; 54, parameters; 54, 55; 54, 56; 55, identifier:rot_crop_vec; 56, identifier:eigvectors; 57, block; 57, 58; 57, 70; 57, 78; 57, 82; 57, 116; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:rot_crop_matrix; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:np; 64, identifier:reshape; 65, argument_list; 65, 66; 65, 67; 66, identifier:rot_crop_vec; 67, tuple; 67, 68; 67, 69; 68, identifier:x; 69, identifier:y; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:rot_matrix; 73, call; 73, 74; 73, 75; 74, identifier:_fill_matrix; 75, argument_list; 75, 76; 75, 77; 76, identifier:rot_crop_matrix; 77, identifier:eigvectors; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:result; 81, integer:0; 82, for_statement; 82, 83; 82, 84; 82, 89; 83, identifier:i; 84, call; 84, 85; 84, 86; 85, identifier:range; 86, argument_list; 86, 87; 86, 88; 87, integer:0; 88, identifier:n_clusters; 89, block; 89, 90; 90, for_statement; 90, 91; 90, 92; 90, 97; 91, identifier:j; 92, call; 92, 93; 92, 94; 93, identifier:range; 94, argument_list; 94, 95; 94, 96; 95, integer:0; 96, identifier:n_clusters; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, augmented_assignment:+=; 99, 100; 99, 101; 100, identifier:result; 101, binary_operator:/; 101, 102; 101, 112; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:np; 105, identifier:power; 106, argument_list; 106, 107; 106, 111; 107, subscript; 107, 108; 107, 109; 107, 110; 108, identifier:rot_matrix; 109, identifier:j; 110, identifier:i; 111, integer:2; 112, subscript; 112, 113; 112, 114; 112, 115; 113, identifier:rot_matrix; 114, integer:0; 115, identifier:i; 116, return_statement; 116, 117; 117, unary_operator:-; 117, 118; 118, identifier:result; 119, import_from_statement; 119, 120; 119, 123; 120, dotted_name; 120, 121; 120, 122; 121, identifier:scipy; 122, identifier:optimize; 123, dotted_name; 123, 124; 124, identifier:fmin; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:rot_crop_vec_opt; 128, call; 128, 129; 128, 130; 129, identifier:fmin; 130, argument_list; 130, 131; 130, 132; 130, 133; 130, 137; 131, identifier:susanna_func; 132, identifier:rot_crop_vec; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:args; 135, tuple; 135, 136; 136, identifier:eigvectors; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:disp; 139, False; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:rot_crop_matrix; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:np; 146, identifier:reshape; 147, argument_list; 147, 148; 147, 149; 148, identifier:rot_crop_vec_opt; 149, tuple; 149, 150; 149, 151; 150, identifier:x; 151, identifier:y; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:rot_matrix; 155, call; 155, 156; 155, 157; 156, identifier:_fill_matrix; 157, argument_list; 157, 158; 157, 159; 158, identifier:rot_crop_matrix; 159, identifier:eigvectors; 160, return_statement; 160, 161; 161, identifier:rot_matrix | def _opt_soft(eigvectors, rot_matrix, n_clusters):
eigvectors = eigvectors[:, :n_clusters]
rot_crop_matrix = rot_matrix[1:][:, 1:]
(x, y) = rot_crop_matrix.shape
rot_crop_vec = np.reshape(rot_crop_matrix, x * y)
def susanna_func(rot_crop_vec, eigvectors):
rot_crop_matrix = np.reshape(rot_crop_vec, (x, y))
rot_matrix = _fill_matrix(rot_crop_matrix, eigvectors)
result = 0
for i in range(0, n_clusters):
for j in range(0, n_clusters):
result += np.power(rot_matrix[j, i], 2) / rot_matrix[0, i]
return -result
from scipy.optimize import fmin
rot_crop_vec_opt = fmin(susanna_func, rot_crop_vec, args=(eigvectors,), disp=False)
rot_crop_matrix = np.reshape(rot_crop_vec_opt, (x, y))
rot_matrix = _fill_matrix(rot_crop_matrix, eigvectors)
return rot_matrix |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:connected_sets; 3, parameters; 3, 4; 3, 5; 4, identifier:C; 5, default_parameter; 5, 6; 5, 7; 6, identifier:directed; 7, True; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, identifier:r; 11, if_statement; 11, 12; 11, 16; 11, 32; 12, call; 12, 13; 12, 14; 13, identifier:isdense; 14, argument_list; 14, 15; 15, identifier:C; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:sparse; 22, identifier:connectivity; 23, identifier:connected_sets; 24, argument_list; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:csr_matrix; 27, argument_list; 27, 28; 28, identifier:C; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:directed; 31, identifier:directed; 32, else_clause; 32, 33; 33, block; 33, 34; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:sparse; 39, identifier:connectivity; 40, identifier:connected_sets; 41, argument_list; 41, 42; 41, 43; 42, identifier:C; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:directed; 45, identifier:directed | def connected_sets(C, directed=True):
r
if isdense(C):
return sparse.connectivity.connected_sets(csr_matrix(C), directed=directed)
else:
return sparse.connectivity.connected_sets(C, directed=directed) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zcount; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:name; 6, identifier:score_start; 7, identifier:score_end; 8, block; 8, 9; 8, 17; 8, 25; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:score_start; 12, call; 12, 13; 12, 14; 13, identifier:get_integer_or_emptystring; 14, argument_list; 14, 15; 14, 16; 15, string:'score_start'; 16, identifier:score_start; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:score_end; 20, call; 20, 21; 20, 22; 21, identifier:get_integer_or_emptystring; 22, argument_list; 22, 23; 22, 24; 23, string:'score_end'; 24, identifier:score_end; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:execute_command; 30, argument_list; 30, 31; 30, 32; 30, 33; 30, 34; 31, string:'zcount'; 32, identifier:name; 33, identifier:score_start; 34, identifier:score_end | def zcount(self, name, score_start, score_end):
score_start = get_integer_or_emptystring('score_start', score_start)
score_end = get_integer_or_emptystring('score_end', score_end)
return self.execute_command('zcount', name, score_start, score_end) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:reload_index; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:progress_cb; 7, identifier:dummy_progress_cb; 8, block; 8, 9; 8, 19; 8, 23; 8, 45; 8, 54; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:nb_results; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:index; 17, identifier:start_reload_index; 18, argument_list; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:progress; 22, integer:0; 23, while_statement; 23, 24; 23, 31; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:index; 29, identifier:continue_reload_index; 30, argument_list; 31, block; 31, 32; 31, 41; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:progress_cb; 35, argument_list; 35, 36; 35, 37; 35, 38; 36, identifier:progress; 37, identifier:nb_results; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:INDEX_STEP_LOADING; 41, expression_statement; 41, 42; 42, augmented_assignment:+=; 42, 43; 42, 44; 43, identifier:progress; 44, integer:1; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:progress_cb; 48, argument_list; 48, 49; 48, 50; 48, 51; 49, integer:1; 50, integer:1; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:INDEX_STEP_LOADING; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:index; 60, identifier:end_reload_index; 61, argument_list | def reload_index(self, progress_cb=dummy_progress_cb):
nb_results = self.index.start_reload_index()
progress = 0
while self.index.continue_reload_index():
progress_cb(progress, nb_results, self.INDEX_STEP_LOADING)
progress += 1
progress_cb(1, 1, self.INDEX_STEP_LOADING)
self.index.end_reload_index() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__doc_cmp; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 15; 6, 26; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:other; 10, None; 11, block; 11, 12; 12, return_statement; 12, 13; 13, unary_operator:-; 13, 14; 14, integer:1; 15, if_statement; 15, 16; 15, 23; 16, boolean_operator:and; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:is_new; 20, attribute; 20, 21; 20, 22; 21, identifier:other; 22, identifier:is_new; 23, block; 23, 24; 24, return_statement; 24, 25; 25, integer:0; 26, if_statement; 26, 27; 26, 34; 26, 38; 26, 49; 27, comparison_operator:<; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:__docid; 31, attribute; 31, 32; 31, 33; 32, identifier:other; 33, identifier:__docid; 34, block; 34, 35; 35, return_statement; 35, 36; 36, unary_operator:-; 36, 37; 37, integer:1; 38, elif_clause; 38, 39; 38, 46; 39, comparison_operator:==; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:__docid; 43, attribute; 43, 44; 43, 45; 44, identifier:other; 45, identifier:__docid; 46, block; 46, 47; 47, return_statement; 47, 48; 48, integer:0; 49, else_clause; 49, 50; 50, block; 50, 51; 51, return_statement; 51, 52; 52, integer:1 | def __doc_cmp(self, other):
if other is None:
return -1
if self.is_new and other.is_new:
return 0
if self.__docid < other.__docid:
return -1
elif self.__docid == other.__docid:
return 0
else:
return 1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__label_cmp; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 15; 6, 28; 6, 41; 6, 60; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:is; 8, 9; 8, 10; 9, identifier:other; 10, None; 11, block; 11, 12; 12, return_statement; 12, 13; 13, unary_operator:-; 13, 14; 14, integer:1; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:label_name; 18, call; 18, 19; 18, 27; 19, attribute; 19, 20; 19, 26; 20, call; 20, 21; 20, 22; 21, identifier:strip_accents; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:name; 26, identifier:lower; 27, argument_list; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:other_name; 31, call; 31, 32; 31, 40; 32, attribute; 32, 33; 32, 39; 33, call; 33, 34; 33, 35; 34, identifier:strip_accents; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:other; 38, identifier:name; 39, identifier:lower; 40, argument_list; 41, if_statement; 41, 42; 41, 45; 41, 49; 41, 56; 42, comparison_operator:<; 42, 43; 42, 44; 43, identifier:label_name; 44, identifier:other_name; 45, block; 45, 46; 46, return_statement; 46, 47; 47, unary_operator:-; 47, 48; 48, integer:1; 49, elif_clause; 49, 50; 49, 53; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:label_name; 52, identifier:other_name; 53, block; 53, 54; 54, return_statement; 54, 55; 55, integer:0; 56, else_clause; 56, 57; 57, block; 57, 58; 58, return_statement; 58, 59; 59, integer:1; 60, if_statement; 60, 61; 60, 72; 60, 76; 60, 91; 61, comparison_operator:<; 61, 62; 61, 67; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:get_color_str; 66, argument_list; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:other; 70, identifier:get_color_str; 71, argument_list; 72, block; 72, 73; 73, return_statement; 73, 74; 74, unary_operator:-; 74, 75; 75, integer:1; 76, elif_clause; 76, 77; 76, 88; 77, comparison_operator:==; 77, 78; 77, 83; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:get_color_str; 82, argument_list; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:other; 86, identifier:get_color_str; 87, argument_list; 88, block; 88, 89; 89, return_statement; 89, 90; 90, integer:0; 91, else_clause; 91, 92; 92, block; 92, 93; 93, return_statement; 93, 94; 94, integer:1 | def __label_cmp(self, other):
if other is None:
return -1
label_name = strip_accents(self.name).lower()
other_name = strip_accents(other.name).lower()
if label_name < other_name:
return -1
elif label_name == other_name:
return 0
else:
return 1
if self.get_color_str() < other.get_color_str():
return -1
elif self.get_color_str() == other.get_color_str():
return 0
else:
return 1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:stop_sequence; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 9, 15; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:stop_times; 14, argument_list; 15, keyword_argument; 15, 16; 15, 17; 16, identifier:key; 17, lambda; 17, 18; 17, 20; 18, lambda_parameters; 18, 19; 19, identifier:x; 20, call; 20, 21; 20, 22; 21, identifier:int; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:x; 26, identifier:get; 27, argument_list; 27, 28; 28, string:'stop_sequence' | def stop_sequence(self):
return sorted(
self.stop_times(),
key=lambda x:int(x.get('stop_sequence'))
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:near; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 4, identifier:cls; 5, identifier:collection; 6, identifier:latitude; 7, identifier:longitude; 8, identifier:index_id; 9, default_parameter; 9, 10; 9, 11; 10, identifier:distance; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:skip; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:limit; 17, None; 18, block; 18, 19; 18, 41; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:kwargs; 22, dictionary; 22, 23; 22, 26; 22, 29; 22, 32; 22, 35; 22, 38; 23, pair; 23, 24; 23, 25; 24, string:'geo'; 25, identifier:index_id; 26, pair; 26, 27; 26, 28; 27, string:'latitude'; 28, identifier:latitude; 29, pair; 29, 30; 29, 31; 30, string:'longitude'; 31, identifier:longitude; 32, pair; 32, 33; 32, 34; 33, string:'distance'; 34, identifier:distance; 35, pair; 35, 36; 35, 37; 36, string:'skip'; 37, identifier:skip; 38, pair; 38, 39; 38, 40; 39, string:'limit'; 40, identifier:limit; 41, return_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:cls; 45, identifier:_construct_query; 46, argument_list; 46, 47; 46, 50; 46, 53; 46, 56; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:name; 49, string:'near'; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:collection; 52, identifier:collection; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:multiple; 55, True; 56, dictionary_splat; 56, 57; 57, identifier:kwargs | def near(cls, collection, latitude, longitude, index_id, distance=None, skip=None, limit=None):
kwargs = {
'geo': index_id,
'latitude': latitude,
'longitude': longitude,
'distance': distance,
'skip': skip,
'limit': limit,
}
return cls._construct_query(name='near',
collection=collection, multiple=True,
**kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:rank_targets; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:sample_frame; 5, identifier:ref_targets; 6, identifier:ref_sample; 7, block; 7, 8; 7, 17; 7, 27; 7, 42; 7, 49; 7, 56; 7, 60; 7, 64; 7, 185; 7, 194; 7, 200; 7, 206; 7, 215; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:table; 11, call; 11, 12; 11, 13; 12, identifier:collect_expression; 13, argument_list; 13, 14; 13, 15; 13, 16; 14, identifier:sample_frame; 15, identifier:ref_targets; 16, identifier:ref_sample; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:all_samples; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, subscript; 22, 23; 22, 24; 23, identifier:sample_frame; 24, string:'Sample'; 25, identifier:unique; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:t; 30, call; 30, 31; 30, 41; 31, attribute; 31, 32; 31, 40; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:table; 35, identifier:groupby; 36, argument_list; 36, 37; 37, list:['Sample', 'Target']; 37, 38; 37, 39; 38, string:'Sample'; 39, string:'Target'; 40, identifier:mean; 41, argument_list; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:logt; 45, call; 45, 46; 45, 47; 46, identifier:log2; 47, argument_list; 47, 48; 48, identifier:t; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:ref_targets; 52, call; 52, 53; 52, 54; 53, identifier:set; 54, argument_list; 54, 55; 55, identifier:ref_targets; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:worst; 59, list:[]; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:worst_m; 63, list:[]; 64, while_statement; 64, 65; 64, 76; 65, comparison_operator:>; 65, 66; 65, 75; 66, binary_operator:-; 66, 67; 66, 71; 67, call; 67, 68; 67, 69; 68, identifier:len; 69, argument_list; 69, 70; 70, identifier:ref_targets; 71, call; 71, 72; 71, 73; 72, identifier:len; 73, argument_list; 73, 74; 74, identifier:worst; 75, integer:1; 76, block; 76, 77; 76, 81; 76, 161; 76, 173; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:M; 80, list:[]; 81, for_statement; 81, 82; 81, 83; 81, 84; 82, identifier:test_target; 83, identifier:ref_targets; 84, block; 84, 85; 84, 91; 84, 95; 84, 136; 85, if_statement; 85, 86; 85, 89; 86, comparison_operator:in; 86, 87; 86, 88; 87, identifier:test_target; 88, identifier:worst; 89, block; 89, 90; 90, continue_statement; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:Vs; 94, list:[]; 95, for_statement; 95, 96; 95, 97; 95, 98; 96, identifier:ref_target; 97, identifier:ref_targets; 98, block; 98, 99; 98, 109; 98, 125; 99, if_statement; 99, 100; 99, 107; 100, boolean_operator:or; 100, 101; 100, 104; 101, comparison_operator:==; 101, 102; 101, 103; 102, identifier:ref_target; 103, identifier:test_target; 104, comparison_operator:in; 104, 105; 104, 106; 105, identifier:ref_target; 106, identifier:worst; 107, block; 107, 108; 108, continue_statement; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:A; 112, subscript; 112, 113; 112, 116; 112, 124; 113, attribute; 113, 114; 113, 115; 114, identifier:logt; 115, identifier:ix; 116, call; 116, 117; 116, 118; 117, identifier:zip; 118, argument_list; 118, 119; 118, 120; 119, identifier:all_samples; 120, call; 120, 121; 120, 122; 121, identifier:repeat; 122, argument_list; 122, 123; 123, identifier:test_target; 124, identifier:ref_target; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:Vs; 129, identifier:append; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:A; 134, identifier:std; 135, argument_list; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:M; 140, identifier:append; 141, argument_list; 141, 142; 142, tuple; 142, 143; 142, 160; 143, binary_operator:/; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:sum; 146, argument_list; 146, 147; 147, identifier:Vs; 148, parenthesized_expression; 148, 149; 149, binary_operator:-; 149, 150; 149, 159; 150, binary_operator:-; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:len; 153, argument_list; 153, 154; 154, identifier:ref_targets; 155, call; 155, 156; 155, 157; 156, identifier:len; 157, argument_list; 157, 158; 158, identifier:worst; 159, integer:1; 160, identifier:test_target; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:worst; 165, identifier:append; 166, argument_list; 166, 167; 167, subscript; 167, 168; 167, 172; 168, call; 168, 169; 168, 170; 169, identifier:max; 170, argument_list; 170, 171; 171, identifier:M; 172, integer:1; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:worst_m; 177, identifier:append; 178, argument_list; 178, 179; 179, subscript; 179, 180; 179, 184; 180, call; 180, 181; 180, 182; 181, identifier:max; 182, argument_list; 182, 183; 183, identifier:M; 184, integer:0; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:best; 188, binary_operator:-; 188, 189; 188, 190; 189, identifier:ref_targets; 190, call; 190, 191; 190, 192; 191, identifier:set; 192, argument_list; 192, 193; 193, identifier:worst; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:worst; 198, identifier:reverse; 199, argument_list; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:worst_m; 204, identifier:reverse; 205, argument_list; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:worst_m; 209, binary_operator:+; 209, 210; 209, 214; 210, list:[worst_m[0]]; 210, 211; 211, subscript; 211, 212; 211, 213; 212, identifier:worst_m; 213, integer:0; 214, identifier:worst_m; 215, return_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:pd; 219, identifier:DataFrame; 220, argument_list; 220, 221; 220, 233; 221, dictionary; 221, 222; 221, 230; 222, pair; 222, 223; 222, 224; 223, string:'Target'; 224, binary_operator:+; 224, 225; 224, 229; 225, call; 225, 226; 225, 227; 226, identifier:list; 227, argument_list; 227, 228; 228, identifier:best; 229, identifier:worst; 230, pair; 230, 231; 230, 232; 231, string:'M'; 232, identifier:worst_m; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:columns; 235, list:['Target', 'M']; 235, 236; 235, 237; 236, string:'Target'; 237, string:'M' | def rank_targets(sample_frame, ref_targets, ref_sample):
table = collect_expression(sample_frame, ref_targets, ref_sample)
all_samples = sample_frame['Sample'].unique()
t = table.groupby(['Sample', 'Target']).mean()
logt = log2(t)
ref_targets = set(ref_targets)
worst = []
worst_m = []
while len(ref_targets) - len(worst) > 1:
M = []
for test_target in ref_targets:
if test_target in worst: continue
Vs = []
for ref_target in ref_targets:
if ref_target == test_target or ref_target in worst: continue
A = logt.ix[zip(all_samples, repeat(test_target)), ref_target]
Vs.append(A.std())
M.append( (sum(Vs)/(len(ref_targets)-len(worst)-1), test_target) )
worst.append(max(M)[1])
worst_m.append(max(M)[0])
best = ref_targets - set(worst)
worst.reverse()
worst_m.reverse()
worst_m = [worst_m[0]] + worst_m
return pd.DataFrame({'Target': list(best) + worst, 'M': worst_m}, columns=['Target', 'M']) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:natural_sort_key; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 6, return_statement; 6, 7; 7, list_comprehension; 7, 8; 7, 19; 8, conditional_expression:if; 8, 9; 8, 13; 8, 18; 9, call; 9, 10; 9, 11; 10, identifier:int; 11, argument_list; 11, 12; 12, identifier:text; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:text; 16, identifier:isdigit; 17, argument_list; 18, identifier:text; 19, for_in_clause; 19, 20; 19, 21; 20, identifier:text; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:re; 24, identifier:split; 25, argument_list; 25, 26; 25, 27; 26, identifier:INTEGER_RE; 27, call; 27, 28; 27, 29; 28, identifier:str; 29, argument_list; 29, 30; 30, identifier:s | def natural_sort_key(s):
return [int(text) if text.isdigit() else text
for text in re.split(INTEGER_RE, str(s))] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:relabel_nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:G; 5, identifier:mapping; 6, default_parameter; 6, 7; 6, 8; 7, identifier:copy; 8, True; 9, block; 9, 10; 9, 39; 10, if_statement; 10, 11; 10, 17; 10, 33; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:hasattr; 14, argument_list; 14, 15; 14, 16; 15, identifier:mapping; 16, string:"__getitem__"; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:m; 21, call; 21, 22; 21, 23; 22, identifier:dict; 23, generator_expression; 23, 24; 23, 30; 24, tuple; 24, 25; 24, 26; 25, identifier:n; 26, call; 26, 27; 26, 28; 27, identifier:mapping; 28, argument_list; 28, 29; 29, identifier:n; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:n; 32, identifier:G; 33, else_clause; 33, 34; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:m; 38, identifier:mapping; 39, if_statement; 39, 40; 39, 41; 39, 48; 40, identifier:copy; 41, block; 41, 42; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:_relabel_copy; 45, argument_list; 45, 46; 45, 47; 46, identifier:G; 47, identifier:m; 48, else_clause; 48, 49; 49, block; 49, 50; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:_relabel_inplace; 53, argument_list; 53, 54; 53, 55; 54, identifier:G; 55, identifier:m | def relabel_nodes(G, mapping, copy=True):
if not hasattr(mapping, "__getitem__"):
m = dict((n, mapping(n)) for n in G)
else:
m = mapping
if copy:
return _relabel_copy(G, m)
else:
return _relabel_inplace(G, m) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:convert_node_labels_to_integers; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:G; 5, default_parameter; 5, 6; 5, 7; 6, identifier:first_label; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ordering; 10, string:"default"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:label_attribute; 13, None; 14, block; 14, 15; 14, 25; 14, 199; 14, 207; 14, 219; 14, 247; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:N; 18, binary_operator:+; 18, 19; 18, 24; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:G; 22, identifier:number_of_nodes; 23, argument_list; 24, identifier:first_label; 25, if_statement; 25, 26; 25, 29; 25, 49; 25, 83; 25, 131; 25, 185; 26, comparison_operator:==; 26, 27; 26, 28; 27, identifier:ordering; 28, string:"default"; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:mapping; 33, call; 33, 34; 33, 35; 34, identifier:dict; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:zip; 38, argument_list; 38, 39; 38, 44; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:G; 42, identifier:nodes; 43, argument_list; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 46, 48; 47, identifier:first_label; 48, identifier:N; 49, elif_clause; 49, 50; 49, 53; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:ordering; 52, string:"sorted"; 53, block; 53, 54; 53, 62; 53, 68; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:nlist; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:G; 60, identifier:nodes; 61, argument_list; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:nlist; 66, identifier:sort; 67, argument_list; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:mapping; 71, call; 71, 72; 71, 73; 72, identifier:dict; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:zip; 76, argument_list; 76, 77; 76, 78; 77, identifier:nlist; 78, call; 78, 79; 78, 80; 79, identifier:range; 80, argument_list; 80, 81; 80, 82; 81, identifier:first_label; 82, identifier:N; 83, elif_clause; 83, 84; 83, 87; 84, comparison_operator:==; 84, 85; 84, 86; 85, identifier:ordering; 86, string:"increasing degree"; 87, block; 87, 88; 87, 104; 87, 110; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:dv_pairs; 91, list_comprehension; 91, 92; 91, 95; 92, tuple; 92, 93; 92, 94; 93, identifier:d; 94, identifier:n; 95, for_in_clause; 95, 96; 95, 99; 96, tuple_pattern; 96, 97; 96, 98; 97, identifier:n; 98, identifier:d; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:G; 102, identifier:degree_iter; 103, argument_list; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:dv_pairs; 108, identifier:sort; 109, argument_list; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:mapping; 113, call; 113, 114; 113, 115; 114, identifier:dict; 115, argument_list; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:zip; 118, argument_list; 118, 119; 118, 126; 119, list_comprehension; 119, 120; 119, 121; 120, identifier:n; 121, for_in_clause; 121, 122; 121, 125; 122, pattern_list; 122, 123; 122, 124; 123, identifier:d; 124, identifier:n; 125, identifier:dv_pairs; 126, call; 126, 127; 126, 128; 127, identifier:range; 128, argument_list; 128, 129; 128, 130; 129, identifier:first_label; 130, identifier:N; 131, elif_clause; 131, 132; 131, 135; 132, comparison_operator:==; 132, 133; 132, 134; 133, identifier:ordering; 134, string:"decreasing degree"; 135, block; 135, 136; 135, 152; 135, 158; 135, 164; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:dv_pairs; 139, list_comprehension; 139, 140; 139, 143; 140, tuple; 140, 141; 140, 142; 141, identifier:d; 142, identifier:n; 143, for_in_clause; 143, 144; 143, 147; 144, tuple_pattern; 144, 145; 144, 146; 145, identifier:n; 146, identifier:d; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:G; 150, identifier:degree_iter; 151, argument_list; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:dv_pairs; 156, identifier:sort; 157, argument_list; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:dv_pairs; 162, identifier:reverse; 163, argument_list; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:mapping; 167, call; 167, 168; 167, 169; 168, identifier:dict; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:zip; 172, argument_list; 172, 173; 172, 180; 173, list_comprehension; 173, 174; 173, 175; 174, identifier:n; 175, for_in_clause; 175, 176; 175, 179; 176, pattern_list; 176, 177; 176, 178; 177, identifier:d; 178, identifier:n; 179, identifier:dv_pairs; 180, call; 180, 181; 180, 182; 181, identifier:range; 182, argument_list; 182, 183; 182, 184; 183, identifier:first_label; 184, identifier:N; 185, else_clause; 185, 186; 186, block; 186, 187; 187, raise_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:nx; 191, identifier:NetworkXError; 192, argument_list; 192, 193; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, string:'Unknown node ordering: {0}'; 196, identifier:format; 197, argument_list; 197, 198; 198, identifier:ordering; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:H; 202, call; 202, 203; 202, 204; 203, identifier:relabel_nodes; 204, argument_list; 204, 205; 204, 206; 205, identifier:G; 206, identifier:mapping; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:H; 211, identifier:name; 212, binary_operator:+; 212, 213; 212, 218; 213, binary_operator:+; 213, 214; 213, 215; 214, string:"("; 215, attribute; 215, 216; 215, 217; 216, identifier:G; 217, identifier:name; 218, string:")_with_int_labels"; 219, if_statement; 219, 220; 219, 223; 220, comparison_operator:is; 220, 221; 220, 222; 221, identifier:label_attribute; 222, None; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:nx; 228, identifier:set_node_attributes; 229, argument_list; 229, 230; 229, 231; 229, 232; 230, identifier:H; 231, identifier:label_attribute; 232, call; 232, 233; 232, 234; 233, identifier:dict; 234, generator_expression; 234, 235; 234, 238; 235, tuple; 235, 236; 235, 237; 236, identifier:v; 237, identifier:k; 238, for_in_clause; 238, 239; 238, 242; 239, pattern_list; 239, 240; 239, 241; 240, identifier:k; 241, identifier:v; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:mapping; 245, identifier:items; 246, argument_list; 247, return_statement; 247, 248; 248, identifier:H | def convert_node_labels_to_integers(G, first_label=0, ordering="default",
label_attribute=None):
N = G.number_of_nodes() + first_label
if ordering == "default":
mapping = dict(zip(G.nodes(), range(first_label, N)))
elif ordering == "sorted":
nlist = G.nodes()
nlist.sort()
mapping = dict(zip(nlist, range(first_label, N)))
elif ordering == "increasing degree":
dv_pairs = [(d, n) for (n, d) in G.degree_iter()]
dv_pairs.sort()
mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N)))
elif ordering == "decreasing degree":
dv_pairs = [(d, n) for (n, d) in G.degree_iter()]
dv_pairs.sort()
dv_pairs.reverse()
mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N)))
else:
raise nx.NetworkXError('Unknown node ordering: {0}'.format(ordering))
H = relabel_nodes(G, mapping)
H.name = "(" + G.name + ")_with_int_labels"
if label_attribute is not None:
nx.set_node_attributes(H, label_attribute,
dict((v, k) for k, v in mapping.items()))
return H |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_token_ids; 3, parameters; 3, 4; 4, identifier:tree; 5, block; 5, 6; 5, 22; 5, 31; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:tok2time; 8, parameters; 8, 9; 9, identifier:token_element; 10, block; 10, 11; 10, 13; 11, expression_statement; 11, 12; 12, string:'''
extracts the time (float) of a <tli> element
(i.e. the absolute position of a token in the document)
'''; 13, return_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:float; 16, argument_list; 16, 17; 17, subscript; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:token_element; 20, identifier:attrib; 21, string:'time'; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:timeline; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:tree; 28, identifier:find; 29, argument_list; 29, 30; 30, string:'//common-timeline'; 31, return_statement; 31, 32; 32, generator_expression; 32, 33; 32, 38; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:tok; 36, identifier:attrib; 37, string:'id'; 38, for_in_clause; 38, 39; 38, 40; 39, identifier:tok; 40, call; 40, 41; 40, 42; 41, identifier:sorted; 42, argument_list; 42, 43; 42, 52; 43, generator_expression; 43, 44; 43, 45; 44, identifier:tli; 45, for_in_clause; 45, 46; 45, 47; 46, identifier:tli; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:timeline; 50, identifier:iterchildren; 51, argument_list; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:key; 54, identifier:tok2time | def get_token_ids(tree):
def tok2time(token_element):
'''
extracts the time (float) of a <tli> element
(i.e. the absolute position of a token in the document)
'''
return float(token_element.attrib['time'])
timeline = tree.find('//common-timeline')
return (tok.attrib['id']
for tok in sorted((tli for tli in timeline.iterchildren()),
key=tok2time)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_span; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:docgraph; 5, identifier:node_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:debug; 8, False; 9, block; 9, 10; 9, 38; 9, 42; 9, 62; 9, 103; 10, if_statement; 10, 11; 10, 21; 11, boolean_operator:and; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:debug; 14, True; 15, comparison_operator:is; 15, 16; 15, 20; 16, call; 16, 17; 16, 18; 17, identifier:is_directed_acyclic_graph; 18, argument_list; 18, 19; 19, identifier:docgraph; 20, False; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:warnings; 26, identifier:warn; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 35; 29, attribute; 29, 30; 29, 34; 30, parenthesized_expression; 30, 31; 31, concatenated_string; 31, 32; 31, 33; 32, string:"Can't reliably extract span '{0}' from cyclical graph'{1}'."; 33, string:"Maximum recursion depth may be exceeded."; 34, identifier:format; 35, argument_list; 35, 36; 35, 37; 36, identifier:node_id; 37, identifier:docgraph; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:span; 41, list:[]; 42, if_statement; 42, 43; 42, 54; 43, comparison_operator:in; 43, 44; 43, 49; 44, binary_operator:+; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:docgraph; 47, identifier:ns; 48, string:':token'; 49, subscript; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:docgraph; 52, identifier:node; 53, identifier:node_id; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:span; 59, identifier:append; 60, argument_list; 60, 61; 61, identifier:node_id; 62, for_statement; 62, 63; 62, 67; 62, 76; 63, pattern_list; 63, 64; 63, 65; 63, 66; 64, identifier:src_id; 65, identifier:target_id; 66, identifier:edge_attribs; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:docgraph; 70, identifier:out_edges_iter; 71, argument_list; 71, 72; 71, 73; 72, identifier:node_id; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:data; 75, True; 76, block; 76, 77; 76, 83; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:==; 78, 79; 78, 80; 79, identifier:src_id; 80, identifier:target_id; 81, block; 81, 82; 82, continue_statement; 83, if_statement; 83, 84; 83, 91; 84, comparison_operator:!=; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:edge_attribs; 87, string:'edge_type'; 88, attribute; 88, 89; 88, 90; 89, identifier:EdgeTypes; 90, identifier:pointing_relation; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:span; 96, identifier:extend; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:get_span; 100, argument_list; 100, 101; 100, 102; 101, identifier:docgraph; 102, identifier:target_id; 103, return_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:sorted; 106, argument_list; 106, 107; 106, 108; 107, identifier:span; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:key; 110, identifier:natural_sort_key | def get_span(docgraph, node_id, debug=False):
if debug is True and is_directed_acyclic_graph(docgraph) is False:
warnings.warn(
("Can't reliably extract span '{0}' from cyclical graph'{1}'."
"Maximum recursion depth may be exceeded.").format(node_id,
docgraph))
span = []
if docgraph.ns+':token' in docgraph.node[node_id]:
span.append(node_id)
for src_id, target_id, edge_attribs in docgraph.out_edges_iter(node_id,
data=True):
if src_id == target_id:
continue
if edge_attribs['edge_type'] != EdgeTypes.pointing_relation:
span.extend(get_span(docgraph, target_id))
return sorted(span, key=natural_sort_key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_terminals_and_nonterminals; 3, parameters; 3, 4; 4, identifier:sentence_graph; 5, block; 5, 6; 5, 12; 5, 18; 5, 52; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:terminals; 9, call; 9, 10; 9, 11; 10, identifier:set; 11, argument_list; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:nonterminals; 15, call; 15, 16; 15, 17; 16, identifier:set; 17, argument_list; 18, for_statement; 18, 19; 18, 20; 18, 25; 19, identifier:node_id; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:sentence_graph; 23, identifier:nodes_iter; 24, argument_list; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 35; 26, 43; 27, comparison_operator:>; 27, 28; 27, 34; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:sentence_graph; 31, identifier:out_degree; 32, argument_list; 32, 33; 33, identifier:node_id; 34, integer:0; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:nonterminals; 40, identifier:add; 41, argument_list; 41, 42; 42, identifier:node_id; 43, else_clause; 43, 44; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:terminals; 49, identifier:add; 50, argument_list; 50, 51; 51, identifier:node_id; 52, return_statement; 52, 53; 53, expression_list; 53, 54; 53, 64; 53, 65; 54, call; 54, 55; 54, 56; 55, identifier:sorted; 56, argument_list; 56, 57; 56, 61; 57, call; 57, 58; 57, 59; 58, identifier:list; 59, argument_list; 59, 60; 60, identifier:terminals; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:key; 63, identifier:natural_sort_key; 64, line_continuation:\; 65, call; 65, 66; 65, 67; 66, identifier:sorted; 67, argument_list; 67, 68; 67, 72; 68, call; 68, 69; 68, 70; 69, identifier:list; 70, argument_list; 70, 71; 71, identifier:nonterminals; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:key; 74, identifier:natural_sort_key | def _get_terminals_and_nonterminals(sentence_graph):
terminals = set()
nonterminals = set()
for node_id in sentence_graph.nodes_iter():
if sentence_graph.out_degree(node_id) > 0:
nonterminals.add(node_id)
else:
terminals.add(node_id)
return sorted(list(terminals), key=natural_sort_key), \
sorted(list(nonterminals), key=natural_sort_key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:print_sorted_counter; 3, parameters; 3, 4; 3, 5; 4, identifier:counter; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tab; 7, integer:1; 8, block; 8, 9; 9, for_statement; 9, 10; 9, 13; 9, 30; 10, pattern_list; 10, 11; 10, 12; 11, identifier:key; 12, identifier:count; 13, call; 13, 14; 13, 15; 14, identifier:sorted; 15, argument_list; 15, 16; 15, 21; 15, 27; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:counter; 19, identifier:items; 20, argument_list; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, call; 23, 24; 23, 25; 24, identifier:itemgetter; 25, argument_list; 25, 26; 26, integer:1; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:reverse; 29, True; 30, block; 30, 31; 31, print_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, string:"{0}{1} - {2}"; 35, identifier:format; 36, argument_list; 36, 37; 36, 40; 36, 41; 37, binary_operator:*; 37, 38; 37, 39; 38, string:'\t'; 39, identifier:tab; 40, identifier:key; 41, identifier:count | def print_sorted_counter(counter, tab=1):
for key, count in sorted(counter.items(), key=itemgetter(1), reverse=True):
print "{0}{1} - {2}".format('\t'*tab, key, count) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sorted_bfs_edges; 3, parameters; 3, 4; 3, 5; 4, identifier:G; 5, default_parameter; 5, 6; 5, 7; 6, identifier:source; 7, None; 8, block; 8, 9; 8, 20; 8, 28; 8, 36; 8, 44; 8, 68; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:source; 12, None; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:source; 17, attribute; 17, 18; 17, 19; 18, identifier:G; 19, identifier:root; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:xpos; 23, call; 23, 24; 23, 25; 24, identifier:horizontal_positions; 25, argument_list; 25, 26; 25, 27; 26, identifier:G; 27, identifier:source; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:visited; 31, call; 31, 32; 31, 33; 32, identifier:set; 33, argument_list; 33, 34; 34, list:[source]; 34, 35; 35, identifier:source; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:source_children; 39, call; 39, 40; 39, 41; 40, identifier:get_child_nodes; 41, argument_list; 41, 42; 41, 43; 42, identifier:G; 43, identifier:source; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:queue; 47, call; 47, 48; 47, 49; 48, identifier:deque; 49, argument_list; 49, 50; 50, list:[(source, iter(sorted(source_children,
key=lambda x: xpos[x])))]; 50, 51; 51, tuple; 51, 52; 51, 53; 52, identifier:source; 53, call; 53, 54; 53, 55; 54, identifier:iter; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:sorted; 58, argument_list; 58, 59; 58, 60; 59, identifier:source_children; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:key; 62, lambda; 62, 63; 62, 65; 63, lambda_parameters; 63, 64; 64, identifier:x; 65, subscript; 65, 66; 65, 67; 66, identifier:xpos; 67, identifier:x; 68, while_statement; 68, 69; 68, 70; 69, identifier:queue; 70, block; 70, 71; 70, 79; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, pattern_list; 73, 74; 73, 75; 74, identifier:parent; 75, identifier:children; 76, subscript; 76, 77; 76, 78; 77, identifier:queue; 78, integer:0; 79, try_statement; 79, 80; 79, 136; 80, block; 80, 81; 80, 88; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:child; 84, call; 84, 85; 84, 86; 85, identifier:next; 86, argument_list; 86, 87; 87, identifier:children; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:not; 89, 90; 89, 91; 90, identifier:child; 91, identifier:visited; 92, block; 92, 93; 92, 98; 92, 105; 92, 113; 93, expression_statement; 93, 94; 94, yield; 94, 95; 95, expression_list; 95, 96; 95, 97; 96, identifier:parent; 97, identifier:child; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:visited; 102, identifier:add; 103, argument_list; 103, 104; 104, identifier:child; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:grandchildren; 108, call; 108, 109; 108, 110; 109, identifier:get_child_nodes; 110, argument_list; 110, 111; 110, 112; 111, identifier:G; 112, identifier:child; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:queue; 117, identifier:append; 118, argument_list; 118, 119; 119, tuple; 119, 120; 119, 121; 120, identifier:child; 121, call; 121, 122; 121, 123; 122, identifier:iter; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:sorted; 126, argument_list; 126, 127; 126, 128; 127, identifier:grandchildren; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:key; 130, lambda; 130, 131; 130, 133; 131, lambda_parameters; 131, 132; 132, identifier:x; 133, subscript; 133, 134; 133, 135; 134, identifier:xpos; 135, identifier:x; 136, except_clause; 136, 137; 136, 138; 137, identifier:StopIteration; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:queue; 143, identifier:popleft; 144, argument_list | def sorted_bfs_edges(G, source=None):
if source is None:
source = G.root
xpos = horizontal_positions(G, source)
visited = set([source])
source_children = get_child_nodes(G, source)
queue = deque([(source, iter(sorted(source_children,
key=lambda x: xpos[x])))])
while queue:
parent, children = queue[0]
try:
child = next(children)
if child not in visited:
yield parent, child
visited.add(child)
grandchildren = get_child_nodes(G, child)
queue.append((child, iter(sorted(grandchildren,
key=lambda x: xpos[x]))))
except StopIteration:
queue.popleft() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sorted_bfs_successors; 3, parameters; 3, 4; 3, 5; 4, identifier:G; 5, default_parameter; 5, 6; 5, 7; 6, identifier:source; 7, None; 8, block; 8, 9; 8, 20; 8, 27; 8, 46; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:source; 12, None; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:source; 17, attribute; 17, 18; 17, 19; 18, identifier:G; 19, identifier:root; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:successors; 23, call; 23, 24; 23, 25; 24, identifier:defaultdict; 25, argument_list; 25, 26; 26, identifier:list; 27, for_statement; 27, 28; 27, 31; 27, 36; 28, pattern_list; 28, 29; 28, 30; 29, identifier:src; 30, identifier:target; 31, call; 31, 32; 31, 33; 32, identifier:sorted_bfs_edges; 33, argument_list; 33, 34; 33, 35; 34, identifier:G; 35, identifier:source; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:successors; 42, identifier:src; 43, identifier:append; 44, argument_list; 44, 45; 45, identifier:target; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:dict; 49, argument_list; 49, 50; 50, identifier:successors | def sorted_bfs_successors(G, source=None):
if source is None:
source = G.root
successors = defaultdict(list)
for src, target in sorted_bfs_edges(G, source):
successors[src].append(target)
return dict(successors) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.