idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
48,900 | def ks_unif_durbin_matrix ( samples , statistic ) : h , k = modf ( samples * statistic ) k = int ( k ) h = 1 - h m = 2 * k + 1 A = tri ( m , k = 1 ) hs = h ** arange ( 1 , m + 1 ) A [ : , 0 ] -= hs A [ - 1 ] -= hs [ : : - 1 ] if h > .5 : A [ - 1 , 0 ] += ( 2 * h - 1 ) ** m A /= fromfunction ( lambda i , j : gamma ( fma... | Calculates the probability that the statistic is less than the given value using a fairly accurate implementation of the Durbin s matrix formula . |
48,901 | def ks_unif_durbin_recurrence_rational ( samples , statistic ) : t = statistic * samples ft1 = int ( floor ( t ) ) + 1 fmt1 = int ( floor ( - t ) ) + 1 fdt1 = int ( floor ( 2 * t ) ) + 1 qs = [ Fraction ( i ** i , factorial ( i ) ) for i in range ( ft1 ) ] qs . extend ( Fraction ( i ** i , factorial ( i ) ) - 2 * t * s... | Calculates the probability that the statistic is less than the given value using Durbin s recurrence and employing the standard fractions module . |
48,902 | def ks_unif_pelz_good ( samples , statistic ) : x = 1 / statistic r2 = 1 / samples rx = sqrt ( r2 ) * x r2x = r2 * x r2x2 = r2x * x r4x = r2x * r2 r4x2 = r2x2 * r2 r4x3 = r2x2 * r2x r5x3 = r4x2 * rx r5x4 = r4x3 * rx r6x3 = r4x2 * r2x r7x5 = r5x4 * r2x r9x6 = r7x5 * r2x r11x8 = r9x6 * r2x2 a1 = rx * ( - r6x3 / 108 + r4x... | Approximates the statistic distribution by a transformed Li - Chien formula . |
48,903 | def activate ( self , * , filter_func = None ) : if self . active : raise RuntimeError ( "Type safety check already active" ) self . __module_finder = ModuleFinder ( Validator . decorate ) if filter_func is not None : self . __module_finder . set_filter ( filter_func ) self . __module_finder . install ( ) | Activate the type safety checker . After the call all functions that need to be checked will be . |
48,904 | def audit ( ** kwargs ) : def wrap ( fn ) : @ functools . wraps ( fn ) def advice ( parent_object , * args , ** kw ) : request = parent_object . request wijziging = request . audit_manager . create_revision ( ) result = fn ( parent_object , * args , ** kw ) if hasattr ( request , 'user' ) and request . user is not None... | use this decorator to audit an operation |
48,905 | def audit_with_request ( ** kwargs ) : def wrap ( fn ) : @ audit ( ** kwargs ) def operation ( parent_object , * args , ** kw ) : return fn ( parent_object . request , * args , ** kw ) @ functools . wraps ( fn ) def advice_with_request ( the_request , * args , ** kw ) : class ParentObject : request = the_request return... | use this decorator to audit an operation with a request as input variable |
48,906 | def cross_validation_lock ( obj ) : orig = getattr ( obj , '_cross_validation_lock' , False ) try : obj . _cross_validation_lock = True yield finally : obj . _cross_validation_lock = orig | A contextmanager for holding Traited object s cross - validators . |
48,907 | def copy_and_replace ( file_in , file_out , mapping , ** kwargs ) : separator = '@@' if 'separator' in kwargs : separator = kwargs [ 'separator' ] file_in = open ( file_in , 'r' ) file_out = open ( file_out , 'w' ) s = file_in . read ( ) for find , replace in mapping : find = separator + find + separator print ( u'Repl... | Copy a file and replace some placeholders with new values . |
48,908 | def coerce ( cls , key , value ) : if not isinstance ( value , MutableList ) : if isinstance ( value , list ) : return MutableList ( value ) return Mutable . coerce ( key , value ) else : return value | Convert plain list to MutableList . |
48,909 | def registerWorker ( self , name , worker ) : if not isinstance ( worker , multiprocessing . Process ) : self . logger . error ( "Process {0} is not actually a Process!" . format ( name ) ) raise Exception ( "Process {0} is not actually a Process!" . format ( name ) ) if name in self . worker_list : self . logger . err... | Register a new Worker under the given descriptive name . |
48,910 | def getWorker ( self , name ) : if not name in self . worker_list : self . logger . error ( "Worker {0} is not registered!" . format ( name ) ) raise Exception ( "Worker {0} is not registered!" . format ( name ) ) return self . worker_list [ name ] | Retrieve the Worker registered under the given name . |
48,911 | def unregisterWorker ( self , name ) : if not name in self . worker_list : self . logger . error ( "Worker {0} is not registered!" . format ( name ) ) raise Exception ( "Worker {0} is not registered!" . format ( name ) ) del self . worker_list [ name ] self . logger . debug ( "Unregistered worker {0}" . format ( name )... | Unregister the Worker registered under the given name . |
48,912 | def startAll ( self ) : self . logger . info ( "Starting all workers..." ) for worker in self . getWorkers ( ) : process = self . getWorker ( worker ) self . logger . debug ( "Starting {0}" . format ( process . name ) ) process . start ( ) self . logger . info ( "Started all workers" ) | Start all registered Workers . |
48,913 | def cast_datetime_filter ( value ) : if isinstance ( value , str ) : dtime = parse_datetime ( value ) elif isinstance ( value , datetime ) : dtime = value else : raise ValueError ( 'Received value of type {0}' . format ( type ( value ) ) ) return dtime . isoformat ( ) | Cast a datetime filter value . |
48,914 | def filter_args_to_dict ( filter_dict , accepted_filter_keys = [ ] ) : out_dict = { } for k , v in filter_dict . items ( ) : if k not in accepted_filter_keys or v is None : logger . debug ( 'Filter was not in accepted_filter_keys or value is None.' ) continue filter_type = filter_type_map . get ( k , None ) if filter_t... | Cast and validate filter args . |
48,915 | def bencode ( obj ) : if isinstance ( obj , int ) : return "i" + str ( obj ) + "e" if isinstance ( obj , str ) : if not obj : return None return str ( len ( obj ) ) + ":" + obj if isinstance ( obj , list ) : res = "l" for elem in obj : elem = bencode ( elem ) if elem : res += elem return res + "e" if isinstance ( obj ,... | Bencodes obj and returns it as a string |
48,916 | def bdecode ( text ) : text = text . decode ( 'utf-8' ) def bdecode_next ( start ) : if text [ start ] == 'i' : end = text . find ( 'e' , start ) return int ( text [ start + 1 : end ] , 10 ) , end + 1 if text [ start ] == 'l' : res = [ ] start += 1 while text [ start ] != 'e' : elem , start = bdecode_next ( start ) res... | Decodes a bencoded bytearray and returns it as a python object |
48,917 | def change_password ( ) : basic_auth = '%s:%s' % ( DEFAULT_USERNAME , DEFAULT_PASSWORD ) try : auth = base64 . encodestring ( basic_auth ) except TypeError : auth = base64 . encodestring ( bytes ( basic_auth , 'utf-8' ) ) . decode ( ) headers = { "Content-Type" : "application/json" , "Accept" : "application/json" , "Au... | Changes the standard password from neo4j to testing to be able to run the test suite . |
48,918 | def get_default_config_file ( argparser , suppress = None , default_override = None ) : if not suppress : suppress = [ ] if not default_override : default_override = { } lines = [ ] seen_arguments = [ ] for arg in argparser . _actions : if arg . dest in suppress : continue if arg . dest in seen_arguments : continue def... | Turn an ArgumentParser into a ConfigObj compatible configuration file . |
48,919 | def _perform_binds ( self , binds ) : for bind in binds : self . logger . debug ( "Binding queue {0} to exchange {1} with key {2}" . format ( bind [ 'queue' ] , bind [ 'exchange' ] , bind [ 'routing_key' ] ) ) self . channel . queue_bind ( ** bind ) | Binds queues to exchanges . |
48,920 | def _perform_unbinds ( self , binds ) : for bind in binds : self . logger . debug ( "Unbinding queue {0} from exchange {1} with key {2}" . format ( bind [ 'queue' ] , bind [ 'exchange' ] , bind [ 'routing_key' ] ) ) self . channel . queue_unbind ( ** bind ) | Unbinds queues from exchanges . |
48,921 | def close ( self ) : self . cancel ( ) self . logger . debug ( "Closing AMQP connection" ) try : self . connection . close ( ) except Exception , eee : self . logger . warning ( "Received an error while trying to close AMQP connection: " + str ( eee ) ) | Closes the internal connection . |
48,922 | def cancel ( self , consumer_tag = None ) : if not consumer_tag : if not hasattr ( self , "consumer_tag" ) : return consumer_tag = self . consumer_tag self . channel . basic_cancel ( consumer_tag ) | Cancels the current consuming action by using the stored consumer_tag . If a consumer_tag is given that one is used instead . |
48,923 | def json_get ( parsed_json , key ) : if key not in parsed_json : raise ValueError ( "JSON does not contain a {} field" . format ( key ) ) return parsed_json [ key ] | Retrieves the key from a parsed_json dictionary or raises an exception if the key is not present |
48,924 | def readme ( fname ) : md = open ( os . path . join ( os . path . dirname ( __file__ ) , fname ) ) . read ( ) output = md try : import pypandoc output = pypandoc . convert ( md , 'rst' , format = 'md' ) except ImportError : pass return output | Reads a markdown file and returns the contents formatted as rst |
48,925 | def get_config ( config_base , custom_file = None , configspec = None ) : logger = logging . getLogger ( __name__ ) logger . debug ( "Expanding variables" ) home = os . path . expanduser ( "~" ) loc = os . path . dirname ( os . path . abspath ( inspect . getfile ( inspect . currentframe ( ) ) ) ) logger . debug ( "Crea... | Loads a configuration file from multiple locations and merge the results into one . |
48,926 | def get_config_dir ( path , pattern = "*.config" , configspec = None , allow_errors = False ) : logger = logging . getLogger ( __name__ ) logger . debug ( "Loading all files matching {0} in {1}" . format ( pattern , path ) ) files = Globber ( path , include = [ pattern ] , recursive = False ) . glob ( ) files = sorted ... | Load an entire directory of configuration files merging them into one . |
48,927 | def resolve ( self , * pargs , ** kwargs ) : self . _cached = ( pargs , kwargs ) self . _try_then ( ) | Resolve the promise . |
48,928 | def _try_then ( self ) : if self . _cached is not None and self . _callback is not None : self . _callback ( * self . _cached [ 0 ] , ** self . _cached [ 1 ] ) | Check to see if self has been resolved yet if so invoke then . |
48,929 | def wait_for ( self , timeout = 3000 ) : results = [ None ] results_called = [ False ] def results_callback ( val ) : results [ 0 ] = val results_called [ 0 ] = True self . then ( results_callback ) start = time . time ( ) while not results_called [ 0 ] : if time . time ( ) - start > timeout / 1000. : raise Exception (... | Hault execution until self resolves . |
48,930 | def _is_primitive ( thing ) : primitive = ( int , str , bool , float ) return isinstance ( thing , primitive ) | Determine if the value is a primitive |
48,931 | def _guess_type ( val ) : if isinstance ( val , bool ) : return "choice" elif isinstance ( val , int ) : return "number" elif isinstance ( val , float ) : return "number" elif isinstance ( val , str ) : return "text" elif hasattr ( val , 'read' ) : return "file" else : return "text" | Guess the input type of the parameter based off the default value if unknown use text |
48,932 | def _params ( sig ) : params = [ ] for p in sig . parameters : param = sig . parameters [ p ] optional = param . default != inspect . Signature . empty default = UIBuilder . _safe_default ( param . default ) if param . default != inspect . Signature . empty else '' annotation = param . annotation if param . annotation ... | Read params values and annotations from the signature |
48,933 | def _import ( func ) : func_name = func . __name__ if func_name in globals ( ) : return func_name module_name = func . __module__ submodules = module_name . split ( '.' ) if submodules [ 0 ] in globals ( ) : return module_name + '.' + func_name for i in range ( len ( submodules ) ) : m = submodules [ i ] if m in global... | Return the namespace path to the function |
48,934 | def get_logger ( name = None , level = logging . NOTSET , handlers = None ) : logger = logging . getLogger ( name ) if name is None : name = "root" if handlers is None : handlers = [ ] logger . setLevel ( level ) if len ( handlers ) != 0 : logger . handlers = [ ] if "console" in handlers : if not isinstance ( handlers ... | Create a Python logging Logger for the given name . A special case is when the name is None as this will represent the root Logger object . |
48,935 | def _attach_endpoints ( self ) : for name , value in inspect . getmembers ( self ) : if inspect . isclass ( value ) and issubclass ( value , self . _Endpoint ) and ( value is not self . _Endpoint ) : endpoint_instance = value ( self . requester ) setattr ( self , endpoint_instance . endpoint_base , endpoint_instance ) ... | Dynamically attaches endpoint callables to this client |
48,936 | def registerThread ( self , name , thread ) : if not isinstance ( thread , threading . Thread ) : self . logger . error ( "Thread {0} is not actually a Thread!" . format ( name ) ) raise Exception ( "Thread {0} is not actually a Thread!" . format ( name ) ) if name in self . thread_list : self . logger . error ( "Threa... | Register a new Thread under the given descriptive name . |
48,937 | def getThread ( self , name ) : if not name in self . thread_list : self . logger . error ( "Thread {0} is not registered!" . format ( name ) ) raise Exception ( "Thread {0} is not registered!" . format ( name ) ) return self . thread_list [ name ] | Retrieve the Thread registered under the given name . |
48,938 | def unregisterThread ( self , name ) : if not name in self . thread_list : self . logger . error ( "Thread {0} is not registered!" . format ( name ) ) raise Exception ( "Thread {0} is not registered!" . format ( name ) ) del self . thread_list [ name ] self . logger . debug ( "Unregistered thread {0}" . format ( name )... | Unregister the Thread registered under the given name . |
48,939 | def startAll ( self ) : self . logger . info ( "Starting all threads..." ) for thread in self . getThreads ( ) : thr = self . getThread ( thread ) self . logger . debug ( "Starting {0}" . format ( thr . name ) ) thr . start ( ) self . logger . info ( "Started all threads" ) | Start all registered Threads . |
48,940 | def usersettings ( request ) : if hasattr ( request , 'usersettings' ) : usersettings = request . usersettings else : from . shortcuts import get_current_usersettings usersettings = get_current_usersettings ( ) return { 'usersettings' : usersettings } | Returns the current UserSettings based on the SITE_ID in the project s settings as context variables |
48,941 | def check_ensembl_api_version ( self ) : self . attempt = 0 headers = { "content-type" : "application/json" } ext = "/info/rest" r = self . ensembl_request ( ext , headers ) response = json . loads ( r ) self . cache . set_ensembl_api_version ( response [ "release" ] ) | check the ensembl api version matches a currently working version This function is included so when the api version changes we notice the change and we can manually check the responses for the new version . |
48,942 | def open_url ( self , url , headers ) : data = self . cache . get_cached_data ( url ) if data is not None : return data , 200 , headers self . rate_limit_ensembl_requests ( ) req = request . Request ( url , headers = headers ) try : handler = request . urlopen ( req ) except HTTPError as error : handler = error except ... | open url with python libraries |
48,943 | def ensembl_request ( self , ext , headers ) : self . attempt += 1 if self . attempt > 5 : raise ValueError ( "too many attempts, figure out why its failing" ) response , status , requested_headers = self . open_url ( self . server + ext , headers = headers ) if status == 429 : if "retry-after" in requested_headers : t... | obtain sequence via the ensembl REST API |
48,944 | def get_genes_for_hgnc_id ( self , hgnc_symbol ) : headers = { "content-type" : "application/json" } self . attempt = 0 ext = "/xrefs/symbol/homo_sapiens/{}" . format ( hgnc_symbol ) r = self . ensembl_request ( ext , headers ) genes = [ ] for item in json . loads ( r ) : if item [ "type" ] == "gene" : genes . append (... | obtain the ensembl gene IDs that correspond to a HGNC symbol |
48,945 | def get_genomic_seq_for_region ( self , chrom , start_pos , end_pos ) : headers = { "content-type" : "text/plain" } self . attempt = 0 ext = "/sequence/region/human/{}:{}..{}:1" . format ( chrom , start_pos , end_pos ) return self . ensembl_request ( ext , headers ) | obtain the sequence for a genomic region |
48,946 | def rate_limit_ensembl_requests ( self ) : current_time = time . time ( ) diff_time = current_time - self . prior_time if diff_time < self . rate_limit : time . sleep ( self . rate_limit - diff_time ) self . prior_time = time . time ( ) | limit ensembl requests to one per 0 . 067 s |
48,947 | def call_simple_cli ( command , cwd = None , universal_newlines = False , redirect_stderr = False ) : return SimpleCliTool ( ) . _call_cli ( command , cwd , universal_newlines , redirect_stderr ) | Simple wrapper around SimpleCliTool . Simple . |
48,948 | def _on_msg ( self , msg ) : data = msg [ 'content' ] [ 'data' ] if 'callback' in data : guid = data [ 'callback' ] callback = callback_registry [ guid ] args = data [ 'arguments' ] args = [ self . deserialize ( a ) for a in args ] index = data [ 'index' ] results = callback ( * args ) return self . serialize ( self . ... | Handle messages from the front - end |
48,949 | def serialize ( self , obj ) : if hasattr ( obj , '_jsid' ) : return { 'immutable' : False , 'value' : obj . _jsid } else : obj_json = { 'immutable' : True } try : json . dumps ( obj ) obj_json [ 'value' ] = obj except : pass if callable ( obj ) : guid = str ( uuid . uuid4 ( ) ) callback_registry [ guid ] = obj obj_jso... | Serialize an object for sending to the front - end . |
48,950 | def deserialize ( self , obj ) : if obj [ 'immutable' ] : return obj [ 'value' ] else : guid = obj [ 'value' ] if not guid in object_registry : instance = JSObject ( self , guid ) object_registry [ guid ] = instance return object_registry [ guid ] | Deserialize an object from the front - end . |
48,951 | def _send ( self , method , ** parameters ) : msg = { 'index' : self . _calls , 'method' : method , } msg . update ( parameters ) promise = SimplePromise ( ) self . _callbacks [ self . _calls ] = promise self . _calls += 1 self . _comm . send ( msg ) return promise | Sends a message to the front - end and returns a promise . |
48,952 | def register_response ( self , correlation_id = None ) : if not correlation_id : correlation_id = str ( uuid . uuid1 ( ) ) if correlation_id in self . responses : raise KeyError ( "Correlation_id {0} was already registered, and therefor not unique." . format ( correlation_id ) ) self . responses [ correlation_id ] = No... | Register the receiving of a RPC response . Will return the given correlation_id after registering or if correlation_id is None will generate a correlation_id and return it after registering . If the given correlation_id has already been used an KeyError will be raised . |
48,953 | def retrieve_response ( self , correlation_id ) : if correlation_id not in self . responses : raise KeyError ( "Given RPC response correlation_id was not registered." ) if not self . responses [ correlation_id ] : return None response = self . responses [ correlation_id ] del ( self . responses [ correlation_id ] ) ret... | Retrieve a registered RPC response . If the correlation_id was not registered an KeyError will the raised . If not value has been received yet None will be returned . After retrieving the response the value will be unset internally . |
48,954 | def request_response ( self , exchange , routing_key , message , properties = None , correlation_id = None , timeout = 6 ) : if not properties : properties = { } properties [ 'correlation_id' ] = self . register_response ( correlation_id ) properties [ 'reply_to' ] = self . rpc_queue_name if not self . publish ( exchan... | This function wraps publish and sets the properties necessary to allow end - to - end communication using the Rpc paradigm . |
48,955 | def get_current ( self ) : from django . conf import settings try : site_id = settings . SITE_ID except AttributeError : raise ImproperlyConfigured ( 'You\'re using the Django "sites framework" without having ' 'set the SITE_ID setting. Create a site in your database and ' 'set the SITE_ID setting to fix this error.' )... | Returns the current UserSettings based on the SITE_ID in the project s settings . The UserSettings object is cached the first time it s retrieved from the database . |
48,956 | def append_url ( base_url , path ) : if base_url [ - 1 ] != "/" : base_url += "/" if path [ 0 ] == "/" : path = path [ 1 : ] return urljoin ( base_url , path ) | Append path to base_url in a sensible way . |
48,957 | def _randomString ( ) : return '' . join ( random . choice ( string . ascii_uppercase + string . digits ) for x in range ( 10 ) ) | Random string for message signing |
48,958 | def _callFunc ( session , funcName , password , args ) : txid = _randomString ( ) sock = session . socket sock . send ( bytearray ( 'd1:q6:cookie4:txid10:%se' % txid , 'utf-8' ) ) msg = _getMessage ( session , txid ) cookie = msg [ 'cookie' ] txid = _randomString ( ) tohash = ( password + cookie ) . encode ( 'utf-8' ) ... | Call custom cjdns admin function |
48,959 | def _receiverThread ( session ) : timeOfLastSend = time . time ( ) timeOfLastRecv = time . time ( ) try : while True : if timeOfLastSend + KEEPALIVE_INTERVAL_SECONDS < time . time ( ) : if timeOfLastRecv + 10 < time . time ( ) : raise exceptions . PingTimeout ( ) session . socket . send ( b'd1:q18:Admin_asyncEnabled4:t... | Receiving messages from cjdns admin server |
48,960 | def _getMessage ( session , txid ) : while True : if txid in session . messages : msg = session . messages [ txid ] del session . messages [ txid ] return msg else : try : nextMessage = session . queue . get ( timeout = 100 ) except queue . Empty : continue if 'txid' in nextMessage : session . messages [ nextMessage [ ... | Getting message associated with txid |
48,961 | def _functionFabric ( func_name , argList , oargList , password ) : def functionHandler ( self , * args , ** kwargs ) : call_args = { } for ( key , value ) in oargList . items ( ) : call_args [ key ] = value for i , arg in enumerate ( argList ) : if i < len ( args ) : call_args [ arg ] = args [ i ] for ( key , value ) ... | Function fabric for Session class |
48,962 | def connect ( ipAddr , port , password ) : sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) sock . connect ( ( ipAddr , port ) ) sock . settimeout ( 2 ) sock . send ( b'd1:q4:pinge' ) data = sock . recv ( BUFFER_SIZE ) if not data . endswith ( b'1:q4:ponge' ) : raise exceptions . NotACjdnsAdminSocket (... | Connect to cjdns admin with this attributes |
48,963 | def connectWithAdminInfo ( path = None ) : if path is None : path = os . path . expanduser ( '~/.cjdnsadmin' ) try : with open ( path , 'r' ) as adminInfo : data = json . load ( adminInfo ) except IOError : logger . info ( '~/.cjdnsadmin not found; using default credentials' , file = sys . stderr ) data = { 'password' ... | Connect to cjdns admin with data from user file |
48,964 | def get_options ( ) : parser = argparse . ArgumentParser ( description = 'denovonear cli interface' ) parent = argparse . ArgumentParser ( add_help = False ) parent . add_argument ( "--out" , help = "output filename" ) parent . add_argument ( "--rates" , help = "Path to file containing sequence context-based mutation r... | get the command line switches |
48,965 | def to_ipv6 ( key ) : if key [ - 2 : ] != '.k' : raise ValueError ( 'Key does not end with .k' ) key_bytes = base32 . decode ( key [ : - 2 ] ) hash_one = sha512 ( key_bytes ) . digest ( ) hash_two = sha512 ( hash_one ) . hexdigest ( ) return ':' . join ( [ hash_two [ i : i + 4 ] for i in range ( 0 , 32 , 4 ) ] ) | Get IPv6 address from a public key . |
48,966 | def glob ( self ) : matches = [ ] for root , dirnames , filenames in os . walk ( self . path ) : if not self . recursive : while len ( dirnames ) > 0 : dirnames . pop ( ) for include in self . include : for filename in fnmatch . filter ( filenames , include ) : matches . append ( os . path . join ( root , filename ) ) ... | Traverse directory and return all absolute filenames of files that match the globbing patterns . |
48,967 | def select_site_view ( self , request , form_url = '' ) : if not self . has_add_permission ( request ) : raise PermissionDenied extra_qs = '' if request . META [ 'QUERY_STRING' ] : extra_qs = '&' + request . META [ 'QUERY_STRING' ] site_choices = self . get_site_choices ( ) if len ( site_choices ) == 1 : return HttpRes... | Display a choice form to select which site to add settings . |
48,968 | def render_select_site_form ( self , request , context , form_url = '' ) : app_label = self . opts . app_label context . update ( { 'has_change_permission' : self . has_change_permission ( request ) , 'form_url' : mark_safe ( form_url ) , 'opts' : self . opts , 'add' : True , 'save_on_top' : self . save_on_top , } ) re... | Render the site choice form . |
48,969 | def xauth ( base_url_template = DEFAULT_READER_URL_TEMPLATE , ** xargs ) : consumer_key = xargs . get ( 'consumer_key' ) or required_from_env ( 'READABILITY_CONSUMER_KEY' ) consumer_secret = xargs . get ( 'consumer_secret' ) or required_from_env ( 'READABILITY_CONSUMER_SECRET' ) username = xargs . get ( 'username' ) or... | Returns an OAuth token tuple that can be used with clients . ReaderClient . |
48,970 | def log_transform ( rates ) : transformed = [ ] for key in [ 'missense' , 'nonsense' , 'splice_lof' , 'splice_region' , 'synonymous' ] : try : value = math . log10 ( rates [ key ] ) except ValueError : value = "NA" except KeyError : continue transformed . append ( value ) return '\t' . join ( map ( str , transformed ) ... | log transform a numeric value unless it is zero or negative |
48,971 | def get_usersettings_model ( ) : try : from django . apps import apps get_model = apps . get_model except ImportError : from django . db . models . loading import get_model try : app_label , model_name = settings . USERSETTINGS_MODEL . split ( '.' ) except ValueError : raise ImproperlyConfigured ( 'USERSETTINGS_MODEL m... | Returns the UserSettings model that is active in this project . |
48,972 | def get_current_usersettings ( ) : USERSETTINGS_MODEL = get_usersettings_model ( ) try : current_usersettings = USERSETTINGS_MODEL . objects . get_current ( ) except USERSETTINGS_MODEL . DoesNotExist : current_usersettings = USERSETTINGS_MODEL . get_default ( ) return current_usersettings | Returns the current UserSettings based on the SITE_ID in the project s settings |
48,973 | def get_options ( ) : parser = argparse . ArgumentParser ( description = "Script to batch process de" "novo clustering." ) parser . add_argument ( "--in" , dest = "input" , required = True , help = "Path to" "file listing known mutations in genes. See example file in data folder" "for format." ) parser . add_argument (... | get the command line options |
48,974 | def count_missense_per_gene ( lines ) : counts = { } for x in lines : x = x . split ( "\t" ) gene = x [ 0 ] consequence = x [ 3 ] if gene not in counts : counts [ gene ] = 0 if consequence != "missense_variant" : continue counts [ gene ] += 1 return counts | count the number of missense variants in each gene . |
48,975 | def split_denovos ( denovo_path , temp_dir ) : with open ( denovo_path , "r" ) as handle : lines = handle . readlines ( ) header = lines . pop ( 0 ) basename = os . path . basename ( denovo_path ) counts = count_missense_per_gene ( lines ) counts = dict ( ( k , v ) for k , v in counts . items ( ) if v > 1 ) genes = set... | split de novos from an input file into files one for each gene |
48,976 | def get_random_string ( ) : hash_string = "%8x" % random . getrandbits ( 32 ) hash_string = hash_string . strip ( ) while is_number ( hash_string ) : hash_string = "%8x" % random . getrandbits ( 32 ) hash_string = hash_string . strip ( ) return hash_string | make a random string which we can use for bsub job IDs so that different jobs do not have the same job IDs . |
48,977 | def batch_process ( de_novo_path , temp_dir , output_path ) : temp_dir = tempfile . mkdtemp ( dir = temp_dir ) count = split_denovos ( de_novo_path , temp_dir ) job_name = "denovonear" job_id = "{0}[1-{1}]%20" . format ( job_name , count ) basename = os . path . basename ( de_novo_path ) infile = os . path . join ( tem... | sets up a lsf job array |
48,978 | def authenticated_user ( self , auth ) : response = self . get ( "/user" , auth = auth ) return GogsUser . from_json ( response . json ( ) ) | Returns the user authenticated by auth |
48,979 | def get_tokens ( self , auth , username = None ) : if username is None : username = self . authenticated_user ( auth ) . username response = self . get ( "/users/{u}/tokens" . format ( u = username ) , auth = auth ) return [ Token . from_json ( o ) for o in response . json ( ) ] | Returns the tokens owned by the specified user . If no user is specified uses the user authenticated by auth . |
48,980 | def create_token ( self , auth , name , username = None ) : if username is None : username = self . authenticated_user ( auth ) . username data = { "name" : name } response = self . post ( "/users/{u}/tokens" . format ( u = username ) , auth = auth , data = data ) return Token . from_json ( response . json ( ) ) | Creates a new token with the specified name for the specified user . If no user is specified uses user authenticated by auth . |
48,981 | def ensure_token ( self , auth , name , username = None ) : if username is None : username = self . authenticated_user ( auth ) . username tokens = [ token for token in self . get_tokens ( auth , username ) if token . name == name ] if len ( tokens ) > 0 : return tokens [ 0 ] return self . create_token ( auth , name , ... | Ensures the existence of a token with the specified name for the specified user . Creates a new token if none exists . If no user is specified uses user authenticated by auth . |
48,982 | def create_repo ( self , auth , name , description = None , private = False , auto_init = False , gitignore_templates = None , license_template = None , readme_template = None , organization = None ) : gitignores = None if gitignore_templates is None else "," . join ( gitignore_templates ) data = { "name" : name , "des... | Creates a new repository and returns the created repository . |
48,983 | def repo_exists ( self , auth , username , repo_name ) : path = "/repos/{u}/{r}" . format ( u = username , r = repo_name ) return self . _get ( path , auth = auth ) . ok | Returns whether a repository with name repo_name owned by the user with username username exists . |
48,984 | def get_repo ( self , auth , username , repo_name ) : path = "/repos/{u}/{r}" . format ( u = username , r = repo_name ) response = self . get ( path , auth = auth ) return GogsRepo . from_json ( response . json ( ) ) | Returns a the repository with name repo_name owned by the user with username username . |
48,985 | def get_user_repos ( self , auth , username ) : path = "/users/{u}/repos" . format ( u = username ) response = self . get ( path , auth = auth ) return [ GogsRepo . from_json ( repo_json ) for repo_json in response . json ( ) ] | Returns the repositories owned by the user with username username . |
48,986 | def get_branch ( self , auth , username , repo_name , branch_name ) : path = "/repos/{u}/{r}/branches/{b}" . format ( u = username , r = repo_name , b = branch_name ) response = self . get ( path , auth = auth ) return GogsBranch . from_json ( response . json ( ) ) | Returns the branch with name branch_name in the repository with name repo_name owned by the user with username username . |
48,987 | def get_branches ( self , auth , username , repo_name ) : path = "/repos/{u}/{r}/branches" . format ( u = username , r = repo_name ) response = self . get ( path , auth = auth ) return [ GogsBranch . from_json ( branch_json ) for branch_json in response . json ( ) ] | Returns the branches in the repository with name repo_name owned by the user with username username . |
48,988 | def delete_repo ( self , auth , username , repo_name ) : path = "/repos/{u}/{r}" . format ( u = username , r = repo_name ) self . delete ( path , auth = auth ) | Deletes the repository with name repo_name owned by the user with username username . |
48,989 | def migrate_repo ( self , auth , clone_addr , uid , repo_name , auth_username = None , auth_password = None , mirror = False , private = False , description = None ) : data = { "clone_addr" : clone_addr , "uid" : uid , "repo_name" : repo_name , "mirror" : mirror , "private" : private , "description" : description , } d... | Migrate a repository from another Git hosting source for the authenticated user . |
48,990 | def create_user ( self , auth , login_name , username , email , password , send_notify = False ) : data = { "login_name" : login_name , "username" : username , "email" : email , "password" : password , "send_notify" : send_notify } response = self . post ( "/admin/users" , auth = auth , data = data ) return GogsUser . ... | Creates a new user and returns the created user . |
48,991 | def user_exists ( self , username ) : path = "/users/{}" . format ( username ) return self . _get ( path ) . ok | Returns whether a user with username username exists . |
48,992 | def search_users ( self , username_keyword , limit = 10 ) : params = { "q" : username_keyword , "limit" : limit } response = self . get ( "/users/search" , params = params ) return [ GogsUser . from_json ( user_json ) for user_json in response . json ( ) [ "data" ] ] | Searches for users whose username matches username_keyword and returns a list of matched users . |
48,993 | def get_user ( self , auth , username ) : path = "/users/{}" . format ( username ) response = self . get ( path , auth = auth ) return GogsUser . from_json ( response . json ( ) ) | Returns a representing the user with username username . |
48,994 | def update_user ( self , auth , username , update ) : path = "/admin/users/{}" . format ( username ) response = self . patch ( path , auth = auth , data = update . as_dict ( ) ) return GogsUser . from_json ( response . json ( ) ) | Updates the user with username username according to update . |
48,995 | def delete_user ( self , auth , username ) : path = "/admin/users/{}" . format ( username ) self . delete ( path , auth = auth ) | Deletes the user with username username . Should only be called if the to - be - deleted user has no repositories . |
48,996 | def get_repo_hooks ( self , auth , username , repo_name ) : path = "/repos/{u}/{r}/hooks" . format ( u = username , r = repo_name ) response = self . get ( path , auth = auth ) return [ GogsRepo . Hook . from_json ( hook ) for hook in response . json ( ) ] | Returns all hooks of repository with name repo_name owned by the user with username username . |
48,997 | def create_hook ( self , auth , repo_name , hook_type , config , events = None , organization = None , active = False ) : if events is None : events = [ "push" ] data = { "type" : hook_type , "config" : config , "events" : events , "active" : active } url = "/repos/{o}/{r}/hooks" . format ( o = organization , r = repo_... | Creates a new hook and returns the created hook . |
48,998 | def update_hook ( self , auth , repo_name , hook_id , update , organization = None ) : if organization is not None : path = "/repos/{o}/{r}/hooks/{i}" . format ( o = organization , r = repo_name , i = hook_id ) else : path = "/repos/{r}/hooks/{i}" . format ( r = repo_name , i = hook_id ) response = self . _patch ( path... | Updates hook with id hook_id according to update . |
48,999 | def delete_hook ( self , auth , username , repo_name , hook_id ) : path = "/repos/{u}/{r}/hooks/{i}" . format ( u = username , r = repo_name , i = hook_id ) self . delete ( path , auth = auth ) | Deletes the hook with id hook_id for repo with name repo_name owned by the user with username username . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.