idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
9,100 | def export_to_file ( self , filepath , level_prefix = ' ' ) : xmldom = self . export_to_dom ( ) xmlstr = xmldom . toprettyxml ( level_prefix , '\n' , ) f = open ( filepath , 'w' ) f . write ( xmlstr ) f . close ( ) | Exports this model to a file . | 77 | 8 |
9,101 | def resolve ( self ) : model = self . copy ( ) for ct in model . component_types : model . resolve_component_type ( ct ) for c in model . components : if c . id not in model . fat_components : model . add ( model . fatten_component ( c ) ) for c in ct . constants : c2 = c . copy ( ) c2 . numeric_value = model . get_num... | Resolves references in this model . | 119 | 7 |
9,102 | def resolve_component_type ( self , component_type ) : # Resolve component type from base types if present. if component_type . extends : try : base_ct = self . component_types [ component_type . extends ] except : raise ModelError ( "Component type '{0}' trying to extend unknown component type '{1}'" , component_type ... | Resolves references in the specified component type . | 145 | 9 |
9,103 | def merge_component_types ( self , ct , base_ct ) : #merge_maps(ct.parameters, base_ct.parameters) for parameter in base_ct . parameters : if parameter . name in ct . parameters : p = ct . parameters [ parameter . name ] basep = base_ct . parameters [ parameter . name ] if p . fixed : p . value = p . fixed_value p . di... | Merge various maps in the given component type from a base component type . | 755 | 15 |
9,104 | def resolve_simulation ( self , fc , ct ) : for run in ct . simulation . runs : try : run2 = Run ( fc . component_references [ run . component ] . referenced_component , run . variable , fc . parameters [ run . increment ] . numeric_value , fc . parameters [ run . total ] . numeric_value ) except : raise ModelError ( "... | Resolve simulation specifications . | 669 | 5 |
9,105 | def get_numeric_value ( self , value_str , dimension = None ) : n = None i = len ( value_str ) while n is None : try : part = value_str [ 0 : i ] nn = float ( part ) n = nn s = value_str [ i : ] except ValueError : i = i - 1 number = n sym = s numeric_value = None if sym == '' : numeric_value = number else : if sym in ... | Get the numeric value for a parameter value specification . | 251 | 10 |
9,106 | def start_msstitch ( exec_drivers , sysargs ) : parser = populate_parser ( exec_drivers ) args = parser . parse_args ( sysargs [ 1 : ] ) args . func ( * * vars ( args ) ) | Passed all drivers of executable checks which command is passed to the executable and then gets the options for a driver parses them from command line and runs the driver | 52 | 32 |
9,107 | def merged ( * dicts , * * kwargs ) : if not dicts : return Struct ( ) result = dict ( ) for d in dicts : result . update ( d ) result . update ( kwargs ) struct_type = type ( dicts [ 0 ] ) return struct_type ( * * result ) | Merge dictionaries . Later keys overwrite . | 69 | 9 |
9,108 | def order_derived_parameters ( component ) : if len ( component . derived_parameters ) == 0 : return [ ] ordering = [ ] dps = [ ] for dp in component . derived_parameters : dps . append ( dp . name ) maxcount = 5 count = maxcount while count > 0 and dps != [ ] : count = count - 1 for dp1 in dps : #exp_tree = regime.der... | Finds ordering of derived_parameters . | 230 | 9 |
9,109 | def order_derived_variables ( regime ) : ordering = [ ] dvs = [ ] dvsnoexp = [ ] maxcount = 5 for dv in regime . derived_variables : if dv . expression_tree == None : dvsnoexp . append ( dv . name ) else : dvs . append ( dv . name ) for dv in regime . conditional_derived_variables : if len ( dv . cases ) == 0 : dvsnoex... | Finds ordering of derived_variables . | 423 | 9 |
9,110 | def build ( self ) : self . sim = Simulation ( ) for component_id in self . model . targets : if component_id not in self . model . components : raise SimBuildError ( "Unable to find target component '{0}'" , component_id ) component = self . model . fat_components [ component_id ] runnable = self . build_runnable ( co... | Build the simulation components from the model . | 105 | 8 |
9,111 | def build_event_connections ( self , component , runnable , structure ) : if self . debug : print ( "\n++++++++ Calling build_event_connections of %s with runnable %s, parent %s" % ( component . id , runnable . id , runnable . parent ) ) # Process event connections for ec in structure . event_connections : if self . de... | Adds event connections to a runnable component based on the structure specifications in the component model . | 524 | 19 |
9,112 | def build_structure ( self , component , runnable , structure ) : if self . debug : print ( "\n++++++++ Calling build_structure of %s with runnable %s, parent %s" % ( component . id , runnable . id , runnable . parent ) ) # Process single-child instantiations for ch in structure . child_instances : child_runnable = sel... | Adds structure to a runnable component based on the structure specifications in the component model . | 299 | 18 |
9,113 | def build_foreach ( self , component , runnable , foreach , name_mappings = { } ) : if self . debug : print ( "\n++++++++ Calling build_foreach of %s with runnable %s, parent %s, name_mappings: %s" % ( component . id , runnable . id , runnable . parent , name_mappings ) ) target_array = runnable . resolve_path ( foreac... | Iterate over ForEach constructs and process nested elements . | 558 | 11 |
9,114 | def process_simulation_specs ( self , component , runnable , simulation ) : # Process runs for run in simulation . runs : cid = run . component . id + '_' + component . id target = self . build_runnable ( run . component , runnable , cid ) self . sim . add_runnable ( target ) self . current_record_target = target targe... | Process simulation - related aspects to a runnable component based on the dynamics specifications in the component model . | 102 | 21 |
9,115 | def build_expression_from_tree ( self , runnable , regime , tree_node ) : component_type = self . model . component_types [ runnable . component . type ] dynamics = component_type . dynamics if tree_node . type == ExprNode . VALUE : if tree_node . value [ 0 ] . isalpha ( ) : if tree_node . value == 't' : return 'self.t... | Recursively builds a Python expression from a parsed expression tree . | 484 | 13 |
9,116 | def build_event_handler ( self , runnable , regime , event_handler ) : if isinstance ( event_handler , OnCondition ) : return self . build_on_condition ( runnable , regime , event_handler ) elif isinstance ( event_handler , OnEvent ) : return self . build_on_event ( runnable , regime , event_handler ) elif isinstance (... | Build event handler code . | 152 | 5 |
9,117 | def build_on_condition ( self , runnable , regime , on_condition ) : on_condition_code = [ ] on_condition_code += [ 'if {0}:' . format ( self . build_expression_from_tree ( runnable , regime , on_condition . expression_tree ) ) ] for action in on_condition . actions : code = self . build_action ( runnable , regime , ac... | Build OnCondition event handler code . | 118 | 7 |
9,118 | def build_on_event ( self , runnable , regime , on_event ) : on_event_code = [ ] if self . debug : on_event_code += [ 'print("Maybe handling something for %s ("+str(id(self))+")")' % ( runnable . id ) , 'print("EICs ("+str(id(self))+"): "+str(self.event_in_counters))' ] on_event_code += [ 'count = self.event_in_counter... | Build OnEvent event handler code . | 247 | 7 |
9,119 | def build_on_start ( self , runnable , regime , on_start ) : on_start_code = [ ] for action in on_start . actions : code = self . build_action ( runnable , regime , action ) for line in code : on_start_code += [ line ] return on_start_code | Build OnStart start handler code . | 73 | 7 |
9,120 | def build_on_entry ( self , runnable , regime , on_entry ) : on_entry_code = [ ] on_entry_code += [ 'if self.current_regime != self.last_regime:' ] on_entry_code += [ ' self.last_regime = self.current_regime' ] for action in on_entry . actions : code = self . build_action ( runnable , regime , action ) for line in code... | Build OnEntry start handler code . | 123 | 7 |
9,121 | def build_action ( self , runnable , regime , action ) : if isinstance ( action , StateAssignment ) : return self . build_state_assignment ( runnable , regime , action ) if isinstance ( action , EventOut ) : return self . build_event_out ( action ) if isinstance ( action , Transition ) : return self . build_transition ... | Build event handler action code . | 93 | 6 |
9,122 | def build_state_assignment ( self , runnable , regime , state_assignment ) : return [ 'self.{0} = {1}' . format ( state_assignment . variable , self . build_expression_from_tree ( runnable , regime , state_assignment . expression_tree ) ) ] | Build state assignment code . | 72 | 5 |
9,123 | def build_event_out ( self , event_out ) : event_out_code = [ 'if "{0}" in self.event_out_callbacks:' . format ( event_out . port ) , ' for c in self.event_out_callbacks[\'{0}\']:' . format ( event_out . port ) , ' c()' ] return event_out_code | Build event out code . | 87 | 5 |
9,124 | def build_reduce_code ( self , result , select , reduce ) : select = select . replace ( '/' , '.' ) select = select . replace ( ' ' , '' ) if reduce == 'add' : reduce_op = '+' acc_start = 0 else : reduce_op = '*' acc_start = 1 #bits = select.split('[*]') bits = re . split ( '\[.*\]' , select ) seps = re . findall ( '\[... | Builds a reduce operation on the selected target range . | 601 | 11 |
9,125 | def add_recording_behavior ( self , component , runnable ) : simulation = component . simulation for rec in simulation . records : rec . id = runnable . id self . current_record_target . add_variable_recorder ( self . current_data_output , rec ) | Adds recording - related dynamics to a runnable component based on the dynamics specifications in the component model . | 63 | 21 |
9,126 | def check_static_member_vars ( class_ , fpath = None , only_init = True ) : #import ast #import astor import utool as ut if isinstance ( class_ , six . string_types ) : classname = class_ if fpath is None : raise Exception ( 'must specify fpath' ) else : # We were given a live object if not isinstance ( class_ , type )... | class_ can either be live object or a classname | 817 | 11 |
9,127 | def get_funcnames_from_modpath ( modpath , include_methods = True ) : import utool as ut if True : import jedi source = ut . read_from ( modpath ) #script = jedi.Script(source=source, source_path=modpath, line=source.count('\n') + 1) definition_list = jedi . names ( source ) funcname_list = [ definition . name for defi... | Get all functions defined in module | 297 | 6 |
9,128 | def help_members ( obj , use_other = False ) : import utool as ut attrnames = dir ( obj ) attr_list = [ getattr ( obj , attrname ) for attrname in attrnames ] attr_types = ut . lmap ( ut . type_str , map ( type , attr_list ) ) unique_types , groupxs = ut . group_indices ( attr_types ) type_to_items = ut . dzip ( unique... | r Inspects members of a class | 563 | 7 |
9,129 | def is_defined_by_module ( item , module , parent = None ) : flag = False if isinstance ( item , types . ModuleType ) : if not hasattr ( item , '__file__' ) : try : # hack for cv2 and xfeatures2d import utool as ut name = ut . get_modname_from_modpath ( module . __file__ ) flag = name in str ( item ) except : flag = Fa... | Check if item is directly defined by a module . This check may be prone to errors . | 477 | 18 |
9,130 | def is_bateries_included ( item ) : flag = False if hasattr ( item , '__call__' ) and hasattr ( item , '__module__' ) : if item . __module__ is not None : module = sys . modules [ item . __module__ ] if module == builtins : flag = True elif hasattr ( module , '__file__' ) : flag = LIB_PATH == dirname ( module . __file_... | Returns if a value is a python builtin function | 103 | 10 |
9,131 | def dummy_func ( arg1 , arg2 , arg3 = None , arg4 = [ 1 , 2 , 3 ] , arg5 = { } , * * kwargs ) : foo = kwargs . get ( 'foo' , None ) bar = kwargs . pop ( 'bar' , 4 ) foo2 = kwargs [ 'foo2' ] foobar = str ( foo ) + str ( bar ) + str ( foo2 ) return foobar | test func for kwargs parseing | 101 | 8 |
9,132 | def get_docstr ( func_or_class ) : import utool as ut try : docstr_ = func_or_class . func_doc except AttributeError : docstr_ = func_or_class . __doc__ if docstr_ is None : docstr_ = '' docstr = ut . unindent ( docstr_ ) return docstr | Get the docstring from a live object | 79 | 8 |
9,133 | def find_funcs_called_with_kwargs ( sourcecode , target_kwargs_name = 'kwargs' ) : import ast sourcecode = 'from __future__ import print_function\n' + sourcecode pt = ast . parse ( sourcecode ) child_funcnamess = [ ] debug = False or VERYVERB_INSPECT if debug : print ( '\nInput:' ) print ( 'target_kwargs_name = %r' % (... | r Finds functions that are called with the keyword kwargs variable | 814 | 14 |
9,134 | def get_func_argspec ( func ) : if hasattr ( func , '_utinfo' ) : argspec = func . _utinfo [ 'orig_argspec' ] return argspec if isinstance ( func , property ) : func = func . fget try : argspec = inspect . getargspec ( func ) except Exception : argspec = inspect . getfullargspec ( func ) return argspec | wrapper around inspect . getargspec but takes into account utool decorators | 89 | 15 |
9,135 | def parse_func_kwarg_keys ( func , with_vals = False ) : sourcecode = get_func_sourcecode ( func , strip_docstr = True , strip_comments = True ) kwkeys = parse_kwarg_keys ( sourcecode , with_vals = with_vals ) #ut.get_func_kwargs TODO return kwkeys | hacky inference of kwargs keys | 81 | 8 |
9,136 | def get_func_kwargs ( func , recursive = True ) : import utool as ut argspec = ut . get_func_argspec ( func ) if argspec . defaults is None : header_kw = { } else : header_kw = dict ( zip ( argspec . args [ : : - 1 ] , argspec . defaults [ : : - 1 ] ) ) if argspec . keywords is not None : header_kw . update ( dict ( ut... | func = ibeis . run_experiment | 115 | 10 |
9,137 | def argparse_funckw ( func , defaults = { } , * * kwargs ) : import utool as ut funckw_ = ut . get_funckw ( func , recursive = True ) funckw_ . update ( defaults ) funckw = ut . argparse_dict ( funckw_ , * * kwargs ) return funckw | allows kwargs to be specified on the commandline from testfuncs | 81 | 15 |
9,138 | def toggle ( self , key ) : val = self [ key ] assert isinstance ( val , bool ) , 'key[%r] = %r is not a bool' % ( key , val ) self . pref_update ( key , not val ) | Toggles a boolean key | 54 | 5 |
9,139 | def change_combo_val ( self , new_val ) : choice_obj = self . _intern . value assert isinstance ( self . _intern . value , PrefChoice ) , 'must be a choice' return choice_obj . get_tuple ( ) | Checks to see if a selection is a valid index or choice of a combo preference | 57 | 17 |
9,140 | def iteritems ( self ) : for ( key , val ) in six . iteritems ( self . __dict__ ) : if key in self . _printable_exclude : continue yield ( key , val ) | Wow this class is messed up . I had to overwrite items when moving to python3 just because I haden t called it yet | 45 | 26 |
9,141 | def to_dict ( self , split_structs_bit = False ) : pref_dict = { } struct_dict = { } for ( key , val ) in six . iteritems ( self ) : if split_structs_bit and isinstance ( val , Pref ) : struct_dict [ key ] = val continue pref_dict [ key ] = val if split_structs_bit : return ( pref_dict , struct_dict ) return pref_dict | Converts prefeters to a dictionary . Children Pref can be optionally separated | 99 | 14 |
9,142 | def save ( self ) : fpath = self . get_fpath ( ) if fpath in [ '' , None ] : if self . _tree . parent is not None : if VERBOSE_PREF : print ( '[pref.save] Can my parent save me?' ) # ...to disk return self . _tree . parent . save ( ) if VERBOSE_PREF : print ( '[pref.save] I cannot be saved. I have no parents.' ) return... | Saves prefs to disk in dict format | 169 | 9 |
9,143 | def load ( self ) : if VERBOSE_PREF : print ( '[pref.load()]' ) #if not os.path.exists(self._intern.fpath): # msg = '[pref] fpath=%r does not exist' % (self._intern.fpath) # return msg fpath = self . get_fpath ( ) try : with open ( fpath , 'rb' ) as f : if VERBOSE_PREF : print ( 'load: %r' % fpath ) pref_dict = pickle ... | Read pref dict stored on disk . Overwriting current values . | 267 | 12 |
9,144 | def full_name ( self ) : if self . _tree . parent is None : return self . _intern . name return self . _tree . parent . full_name ( ) + '.' + self . _intern . name | returns name all the way up the tree | 48 | 9 |
9,145 | def pref_update ( self , key , new_val ) : print ( 'Update and save pref from: %s=%r, to: %s=%r' % ( key , six . text_type ( self [ key ] ) , key , six . text_type ( new_val ) ) ) self . __setattr__ ( key , new_val ) return self . save ( ) | Changes a preference value and saves it to disk | 86 | 9 |
9,146 | def __get_permissions ( self , res , * * kwargs ) : response = res . _ ( * * kwargs ) return response . get ( 'permissions' , None ) | This call returns current login user s permissions . | 42 | 9 |
9,147 | def inject_all_external_modules ( self , classname = None , allow_override = 'override+warn' , strict = True ) : #import utool as ut if classname is None : classname = self . __class__ . __name__ #import utool as ut #ut.embed() NEW = True if NEW : classkey_list = [ key for key in __CLASSTYPE_ATTRIBUTES__ if key [ 0 ] =... | dynamically injects registered module methods into a class instance | 224 | 12 |
9,148 | def decorate_class_method ( func , classkey = None , skipmain = False ) : #import utool as ut global __CLASSTYPE_ATTRIBUTES__ assert classkey is not None , 'must specify classkey' #if not (skipmain and ut.get_caller_modname() == '__main__'): __CLASSTYPE_ATTRIBUTES__ [ classkey ] . append ( func ) return func | Will inject all decorated function as methods of classkey | 102 | 10 |
9,149 | def decorate_postinject ( func , classkey = None , skipmain = False ) : #import utool as ut global __CLASSTYPE_POSTINJECT_FUNCS__ assert classkey is not None , 'must specify classkey' #if not (skipmain and ut.get_caller_modname() == '__main__'): __CLASSTYPE_POSTINJECT_FUNCS__ [ classkey ] . append ( func ) return func | Will perform func with argument self after inject_instance is called on classkey | 104 | 15 |
9,150 | def inject_func_as_method ( self , func , method_name = None , class_ = None , allow_override = False , allow_main = False , verbose = True , override = None , force = False ) : if override is not None : # TODO depcirate allow_override allow_override = override if method_name is None : method_name = get_funcname ( func... | Injects a function into an object as a method | 689 | 11 |
9,151 | def inject_func_as_unbound_method ( class_ , func , method_name = None ) : if method_name is None : method_name = get_funcname ( func ) setattr ( class_ , method_name , func ) | This is actually quite simple | 54 | 5 |
9,152 | def reloading_meta_metaclass_factory ( BASE_TYPE = type ) : class ReloadingMetaclass2 ( BASE_TYPE ) : def __init__ ( metaself , name , bases , dct ) : super ( ReloadingMetaclass2 , metaself ) . __init__ ( name , bases , dct ) #print('Making rrr for %r' % (name,)) metaself . rrr = reload_class return ReloadingMetaclass2 | hack for pyqt | 107 | 4 |
9,153 | def reload_class ( self , verbose = True , reload_module = True ) : import utool as ut verbose = verbose or VERBOSE_CLASS classname = self . __class__ . __name__ try : modname = self . __class__ . __module__ if verbose : print ( '[class] reloading ' + classname + ' from ' + modname ) # --HACK-- if hasattr ( self , '_on... | special class reloading function This function is often injected as rrr of classes | 805 | 15 |
9,154 | def reload_class_methods ( self , class_ , verbose = True ) : if verbose : print ( '[util_class] Reloading self=%r as class_=%r' % ( self , class_ ) ) self . __class__ = class_ for key in dir ( class_ ) : # Get unbound reloaded method func = getattr ( class_ , key ) if isinstance ( func , types . MethodType ) : # injec... | rebinds all class methods | 135 | 6 |
9,155 | def remove_private_obfuscation ( self ) : classname = self . __class__ . __name__ attrlist = [ attr for attr in dir ( self ) if attr . startswith ( '_' + classname + '__' ) ] for attr in attrlist : method = getattr ( self , attr ) truename = attr . replace ( '_' + classname + '__' , '__' ) setattr ( self , truename , m... | removes the python obfuscation of class privates so they can be executed as they appear in class source . Useful when playing with IPython . | 110 | 29 |
9,156 | def create_peptidequant_lookup ( fns , pqdb , poolnames , pepseq_colnr , ms1_qcolpattern = None , isobqcolpattern = None , psmnrpattern = None , fdrcolpattern = None , pepcolpattern = None ) : patterns = [ ms1_qcolpattern , fdrcolpattern , pepcolpattern ] storefuns = [ pqdb . store_precursor_quants , pqdb . store_fdr ,... | Calls lower level function to create a peptide quant lookup | 169 | 12 |
9,157 | def create_proteinquant_lookup ( fns , pqdb , poolnames , protacc_colnr , ms1_qcolpattern = None , isobqcolpattern = None , psmnrpattern = None , probcolpattern = None , fdrcolpattern = None , pepcolpattern = None ) : patterns = [ ms1_qcolpattern , probcolpattern , fdrcolpattern , pepcolpattern ] storefuns = [ pqdb . s... | Calls lower level function to create a protein quant lookup | 187 | 11 |
9,158 | def create_pep_protein_quant_lookup ( fns , pqdb , poolnames , featcolnr , patterns , storefuns , isobqcolpattern = None , psmnrpattern = None ) : tablefn_map = create_tablefn_map ( fns , pqdb , poolnames ) feat_map = pqdb . get_feature_map ( ) for pattern , storefun in zip ( patterns , storefuns ) : if pattern is None... | Does the work when creating peptide and protein quant lookups . This loops through storing options and parses columns passing on to the storing functions | 275 | 28 |
9,159 | def store_single_col_data ( fns , prottable_id_map , pacc_map , pqdbmethod , protacc_colnr , colmap ) : to_store = [ ] for fn , header , pquant in tsvreader . generate_tsv_pep_protein_quants ( fns ) : pacc_id = pacc_map [ pquant [ header [ protacc_colnr ] ] ] pqdata = ( pacc_id , prottable_id_map [ fn ] , pquant [ colm... | General method to store single column data from protein tables in lookup | 173 | 12 |
9,160 | def map_psmnrcol_to_quantcol ( quantcols , psmcols , tablefn_map ) : if not psmcols : for fn in quantcols : for qcol in quantcols [ fn ] : yield ( tablefn_map [ fn ] , qcol ) else : for fn in quantcols : for qcol , psmcol in zip ( quantcols [ fn ] , psmcols [ fn ] ) : yield ( tablefn_map [ fn ] , qcol , psmcol ) | This function yields tuples of table filename isobaric quant column and if necessary number - of - PSM column | 118 | 23 |
9,161 | def avl_release_kids ( node ) : left , right = node . left , node . right if left is not None : # assert left.parent is node left . parent = None if right is not None : # assert right.parent is node right . parent = None node . balance = 0 node . left = None node . right = None return node , left , right | splits a node from its kids maintaining parent pointers | 79 | 10 |
9,162 | def avl_release_parent ( node ) : parent = node . parent if parent is not None : if parent . right is node : parent . right = None elif parent . left is node : parent . left = None else : raise AssertionError ( 'impossible state' ) node . parent = None parent . balance = max ( height ( parent . right ) , height ( paren... | removes the parent of a child | 92 | 7 |
9,163 | def avl_join ( t1 , t2 , node ) : if DEBUG_JOIN : print ( '-- JOIN node=%r' % ( node , ) ) if t1 is None and t2 is None : if DEBUG_JOIN : print ( 'Join Case 1' ) top = node elif t1 is None : # FIXME keep track of count if possible if DEBUG_JOIN : print ( 'Join Case 2' ) top = avl_insert_dir ( t2 , node , 0 ) elif t2 is... | Joins two trees t1 and t1 with an intermediate key - value pair | 354 | 16 |
9,164 | def avl_split_last ( root ) : if root is None : raise IndexError ( 'Empty tree has no maximum element' ) root , left , right = avl_release_kids ( root ) if right is None : new_root , last_node = left , root else : new_right , last_node = avl_split_last ( right ) new_root = avl_join ( left , new_right , root ) return ( ... | Removes the maximum element from the tree | 106 | 8 |
9,165 | def avl_split_first ( root ) : if root is None : raise IndexError ( 'Empty tree has no maximum element' ) root , left , right = avl_release_kids ( root ) if left is None : new_root , first_node = right , root else : new_left , first_node = avl_split_first ( left ) new_root = avl_join ( new_left , right , root ) return ... | Removes the minimum element from the tree | 106 | 8 |
9,166 | def avl_join2 ( t1 , t2 ) : if t1 is None and t2 is None : new_root = None elif t2 is None : new_root = t1 elif t1 is None : new_root = t2 else : new_left , last_node = avl_split_last ( t1 ) debug = 0 if debug : EulerTourTree ( root = new_left ) . _assert_nodes ( 'new_left' ) EulerTourTree ( root = last_node ) . _asser... | join two trees without any intermediate key | 301 | 7 |
9,167 | def to_networkx ( self , labels = None , edge_labels = False ) : import networkx as nx graph = nx . DiGraph ( ) for node in self . _traverse_nodes ( ) : u = node . key graph . add_node ( u ) # Minor redundancy # Set node properties graph . nodes [ u ] [ 'value' ] = node . value if labels is not None : label = ',' . joi... | Get a networkx representation of the binary search tree . | 243 | 11 |
9,168 | def repr_tree ( self ) : import utool as ut import networkx as nx repr_tree = nx . DiGraph ( ) for u , v in ut . itertwo ( self . values ( ) ) : if not repr_tree . has_edge ( v , u ) : repr_tree . add_edge ( u , v ) return repr_tree | reconstruct represented tree as a DiGraph to preserve the current rootedness | 79 | 14 |
9,169 | def unixjoin ( * args ) : isabs_list = list ( map ( isabs , args ) ) if any ( isabs_list ) : poslist = [ count for count , flag in enumerate ( isabs_list ) if flag ] pos = poslist [ - 1 ] return '/' . join ( args [ pos : ] ) else : return '/' . join ( args ) | Like os . path . join but uses forward slashes on win32 | 84 | 14 |
9,170 | def create_merge_psm_map ( peptides , ns ) : psmmap = { } for peptide in peptides : seq = reader . get_peptide_seq ( peptide , ns ) psm_ids = reader . get_psm_ids_from_peptide ( peptide , ns ) for psm_id in psm_ids : try : psmmap [ seq ] [ psm_id . text ] = 1 except KeyError : psmmap [ seq ] = { psm_id . text : 2 } for... | Loops through peptides stores sequences mapped to PSM ids . | 163 | 14 |
9,171 | def create_pool_b ( dsn = None , * , min_size = 10 , max_size = 10 , max_queries = 50000 , max_inactive_connection_lifetime = 300.0 , setup = None , init = None , loop = None , connection_class = BuildPgConnection , * * connect_kwargs , ) : return BuildPgPool ( dsn , connection_class = connection_class , min_size = min... | Create a connection pool . | 159 | 5 |
9,172 | def add_runnable ( self , runnable ) : if runnable . id in self . runnables : raise SimError ( 'Duplicate runnable component {0}' . format ( runnable . id ) ) self . runnables [ runnable . id ] = runnable | Adds a runnable component to the list of runnable components in this simulation . | 69 | 18 |
9,173 | def run ( self ) : self . init_run ( ) if self . debug : self . dump ( "AfterInit: " ) #print("++++++++++++++++ Time: %f"%self.current_time) while self . step ( ) : #self.dump("Time: %f"%self.current_time) #print("++++++++++++++++ Time: %f"%self.current_time) pass | Runs the simulation . | 85 | 5 |
9,174 | def controller_creatr ( filename ) : if not check ( ) : click . echo ( Fore . RED + 'ERROR: Ensure you are in a bast app to run the create:controller command' ) return path = os . path . abspath ( '.' ) + '/controller' if not os . path . exists ( path ) : os . makedirs ( path ) # if os.path.isfile(path + ) file_name = ... | Name of the controller file to be created | 229 | 8 |
9,175 | def view_creatr ( filename ) : if not check ( ) : click . echo ( Fore . RED + 'ERROR: Ensure you are in a bast app to run the create:view command' ) return path = os . path . abspath ( '.' ) + '/public/templates' if not os . path . exists ( path ) : os . makedirs ( path ) filename_ = str ( filename + ".html" ) . lower ... | Name of the View File to be created | 155 | 8 |
9,176 | def migration_creatr ( migration_file , create , table ) : if not check ( ) : click . echo ( Fore . RED + 'ERROR: Ensure you are in a bast app to run the create:migration command' ) return migration = CreateMigration ( ) if table is None : table = snake_case ( migration_file ) file = migration . create_file ( snake_cas... | Name of the migration file | 117 | 5 |
9,177 | def quit ( self ) : logging . info ( "quiting sock server" ) if self . __quit is not None : self . __quit . set ( ) self . join ( ) return | Quit socket server | 40 | 4 |
9,178 | def get_quantcols ( pattern , oldheader , coltype ) : if pattern is None : return False if coltype == 'precur' : return reader . get_cols_in_file ( pattern , oldheader , single_col = True ) | Searches for quantification columns using pattern and header list . Calls reader function to do regexp . Returns a single column for precursor quant . | 55 | 29 |
9,179 | def get_peptide_quant ( quantdata , quanttype ) : parsefnx = { 'precur' : max } quantfloats = [ ] for q in quantdata : try : quantfloats . append ( float ( q ) ) except ( TypeError , ValueError ) : pass if not quantfloats : return 'NA' return str ( parsefnx [ quanttype ] ( quantfloats ) ) | Parses lists of quantdata and returns maxvalue from them . Strips NA | 89 | 17 |
9,180 | def read_csv ( fpath ) : import csv import utool as ut #csvfile = open(fpath, 'rb') with open ( fpath , 'rb' ) as csvfile : row_iter = csv . reader ( csvfile , delimiter = str ( ',' ) , quotechar = str ( '|' ) ) row_list = [ ut . lmap ( ut . ensure_unicode , row ) for row in row_iter ] return row_list | reads csv in unicode | 106 | 6 |
9,181 | def get_caller_name ( N = 0 , strict = True ) : if isinstance ( N , ( list , tuple ) ) : name_list = [ ] for N_ in N : try : name_list . append ( get_caller_name ( N_ ) ) except AssertionError : name_list . append ( 'X' ) return '[' + '][' . join ( name_list ) + ']' # <get_parent_frame> parent_frame = get_stack_frame (... | Standalone version of get_caller_name | 244 | 11 |
9,182 | def _handle_ping ( self , packet , protocol ) : if 'payload' in packet : is_valid_node = True node_ids = list ( packet [ 'payload' ] . values ( ) ) for node_id in node_ids : if self . _repository . get_node ( node_id ) is None : is_valid_node = False break if is_valid_node : self . _pong ( packet , protocol ) else : se... | Responds to pings from registry_client only if the node_ids present in the ping payload are registered | 111 | 22 |
9,183 | def set_features ( self ) : allpsms_str = readers . generate_psms_multiple_fractions_strings ( self . mergefiles , self . ns ) allpeps = preparation . merge_peptides ( self . mergefiles , self . ns ) self . features = { 'psm' : allpsms_str , 'peptide' : allpeps } | Merge all psms and peptides | 84 | 8 |
9,184 | def git_sequence_editor_squash ( fpath ) : # print(sys.argv) import utool as ut text = ut . read_from ( fpath ) # print('fpath = %r' % (fpath,)) print ( text ) # Doesnt work because of fixed witdth requirement # search = (ut.util_regex.positive_lookbehind('[a-z]* [a-z0-9]* wip\n') + 'pick ' + # ut.reponamed_field('hash... | r squashes wip messages | 792 | 5 |
9,185 | def std_build_command ( repo = '.' ) : import utool as ut print ( '+**** stdbuild *******' ) print ( 'repo = %r' % ( repo , ) ) if sys . platform . startswith ( 'win32' ) : # vtool --rebuild-sver didnt work with this line #scriptname = './mingw_build.bat' scriptname = 'mingw_build.bat' else : scriptname = './unix_build... | DEPRICATE My standard build script names . | 213 | 10 |
9,186 | def wait_for_import ( self , connection_id , wait_interval ) : self . stdout . write ( self . style . NOTICE ( 'Waiting for import' ) , ending = '' ) state = utils . ConnectionStates . IMPORT_CONFIGURATION while state == utils . ConnectionStates . IMPORT_CONFIGURATION : # before you get the first state, the API can be ... | Wait until connection state is no longer IMPORT_CONFIGURATION . | 191 | 15 |
9,187 | def setup ( self ) : if self . dry_run is not True : self . client = self . _get_client ( ) self . _disable_access_key ( ) | Method runs the plugin | 38 | 4 |
9,188 | def validate ( self ) : try : response = self . client . get_access_key_last_used ( AccessKeyId = self . access_key_id ) username = response [ 'UserName' ] access_keys = self . client . list_access_keys ( UserName = username ) for key in access_keys [ 'AccessKeyMetadata' ] : if ( key [ 'AccessKeyId' ] == self . access_... | Returns whether this plugin does what it claims to have done | 167 | 11 |
9,189 | def _disable_access_key ( self , force_disable_self = False ) : client = self . client if self . validate is True : return else : try : client . update_access_key ( UserName = self . _search_user_for_key ( ) , AccessKeyId = self . access_key_id , Status = 'Inactive' ) logger . info ( "Access key {id} has " "been disabl... | This function first checks to see if the key is already disabled \ | 155 | 13 |
9,190 | def generate_master_proteins ( psms , protcol ) : master_proteins = { } if not protcol : protcol = mzidtsvdata . HEADER_MASTER_PROT for psm in psms : protacc = psm [ protcol ] if ';' in protacc : continue master_proteins [ protacc ] = 1 if 'NA' in master_proteins : master_proteins . pop ( 'NA' ) if '' in master_protein... | Fed with a psms generator this returns the master proteins present in the PSM table . PSMs with multiple master proteins are excluded . | 152 | 27 |
9,191 | def prepare_percolator_output ( self , fn ) : ns = xml . get_namespace ( fn ) static = readers . get_percolator_static_xml ( fn , ns ) return ns , static | Returns namespace and static xml from percolator output file | 47 | 11 |
9,192 | def git_available ( func ) : def inner ( * args ) : os . chdir ( APISettings . GIT_DIR ) if call ( [ 'git' , 'rev-parse' ] ) == 0 : return func ( * args ) Shell . fail ( 'There is no git repository!' ) return exit ( 1 ) return inner | Check if a git repository exists in the given folder . | 72 | 11 |
9,193 | def _cuda_get_gpu_spec_string ( gpu_ids = None ) : if gpu_ids is None : return '' if isinstance ( gpu_ids , list ) : return ',' . join ( str ( gpu_id ) for gpu_id in gpu_ids ) if isinstance ( gpu_ids , int ) : return str ( gpu_ids ) return gpu_ids | Build a GPU id string to be used for CUDA_VISIBLE_DEVICES . | 92 | 18 |
9,194 | def write_error ( self , status_code , * * kwargs ) : reason = self . _reason if self . settings . get ( "serve_traceback" ) and "exc_info" in kwargs : error = [ ] for line in traceback . format_exception ( * kwargs [ "exc_info" ] ) : error . append ( line ) else : error = None data = { '_traceback' : error , 'message'... | Handle Exceptions from the server . Formats the HTML into readable form | 133 | 14 |
9,195 | def view ( self , template_name , kwargs = None ) : if kwargs is None : kwargs = dict ( ) self . add_ ( 'session' , self . session ) content = self . render_template ( template_name , * * kwargs ) self . write ( content ) | Used to render template to view | 67 | 6 |
9,196 | def initialize ( self , method , middleware , request_type ) : self . method = method self . middleware = middleware self . request_type = request_type | Overridden initialize method from Tornado . Assigns the controller method and middleware attached to the route being executed to global variables to be used | 36 | 28 |
9,197 | def only ( self , arguments ) : data = { } if not isinstance ( arguments , list ) : arguments = list ( arguments ) for i in arguments : data [ i ] = self . get_argument ( i ) return data | returns the key value pair of the arguments passed as a dict object | 48 | 14 |
9,198 | def all ( self ) : data = { } args = self . request . arguments for key , value in args . items ( ) : data [ key ] = self . get_argument ( key ) return data | Returns all the arguments passed with the request | 43 | 8 |
9,199 | def except_ ( self , arguments ) : if not isinstance ( arguments , list ) : arguments = list ( arguments ) args = self . request . arguments data = { } for key , value in args . items ( ) : if key not in arguments : data [ key ] = self . get_argument ( key ) return data | returns the arguments passed to the route except that set by user | 68 | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.