query stringlengths 5 1.23k | positive stringlengths 53 15.2k | id_ int64 0 252k | task_name stringlengths 87 242 | negative listlengths 20 553 |
|---|---|---|---|---|
Show stats when pings are done | def dump_stats ( myStats ) : print ( "\n----%s PYTHON PING Statistics----" % ( myStats . thisIP ) ) if myStats . pktsSent > 0 : myStats . fracLoss = ( myStats . pktsSent - myStats . pktsRcvd ) / myStats . pktsSent print ( ( "%d packets transmitted, %d packets received, " "%0.1f%% packet loss" ) % ( myStats . pktsSent ,... | 100 | https://github.com/jay-johnson/network-pipeline/blob/4e53ae13fe12085e0cf2e5e1aff947368f4f1ffa/network_pipeline/scripts/icmp_send_msg.py#L470-L495 | [
"def",
"slice_reStructuredText",
"(",
"input",
",",
"output",
")",
":",
"LOGGER",
".",
"info",
"(",
"\"{0} | Slicing '{1}' file!\"",
".",
"format",
"(",
"slice_reStructuredText",
".",
"__name__",
",",
"input",
")",
")",
"file",
"=",
"File",
"(",
"input",
")",
... |
bootstrap - py package updatable? . | def updatable ( self ) : if self . latest_version > self . current_version : updatable_version = self . latest_version else : updatable_version = False return updatable_version | 101 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/update.py#L29-L35 | [
"def",
"delete_binding",
"(",
"self",
",",
"vhost",
",",
"exchange",
",",
"queue",
",",
"rt_key",
")",
":",
"vhost",
"=",
"quote",
"(",
"vhost",
",",
"''",
")",
"exchange",
"=",
"quote",
"(",
"exchange",
",",
"''",
")",
"queue",
"=",
"quote",
"(",
... |
Show message updatable . | def show_message ( self ) : print ( 'current version: {current_version}\n' 'latest version : {latest_version}' . format ( current_version = self . current_version , latest_version = self . latest_version ) ) | 102 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/update.py#L37-L43 | [
"def",
"verify",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"database",
".",
"cursor",
"(",
")",
"non_exist",
"=",
"set",
"(",
")",
"no_db_entry",
"=",
"set",
"(",
"os",
".",
"listdir",
"(",
"self",
".",
"cache_dir",
")",
")",
"try",
":",
"no_... |
Traverse the input otu - sequence file collect the non - unique OTU IDs and file the sequences associated with then under the unique OTU ID as defined by the input matrix . | def condense_otus ( otuF , nuniqueF ) : uniqueOTUs = set ( ) nuOTUs = { } # parse non-unique otu matrix for line in nuniqueF : line = line . split ( ) uOTU = line [ 0 ] for nuOTU in line [ 1 : ] : nuOTUs [ nuOTU ] = uOTU uniqueOTUs . add ( uOTU ) otuFilter = defaultdict ( list ) # parse otu sequence file for line in ot... | 103 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/pick_otus_condense.py#L14-L51 | [
"def",
"set_energy_range",
"(",
"self",
",",
"logemin",
",",
"logemax",
")",
":",
"if",
"logemin",
"is",
"None",
":",
"logemin",
"=",
"self",
".",
"log_energies",
"[",
"0",
"]",
"if",
"logemax",
"is",
"None",
":",
"logemax",
"=",
"self",
".",
"log_ener... |
determine if read overlaps with rna if so count bases | def rna_bases ( rna_cov , scaffold , bases , line ) : start = int ( line [ 3 ] ) stop = start + bases - 1 if scaffold not in rna_cov : return rna_cov for pos in rna_cov [ scaffold ] [ 2 ] : ol = get_overlap ( [ start , stop ] , pos ) rna_cov [ scaffold ] [ 0 ] += ol return rna_cov | 104 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_copies.py#L18-L29 | [
"def",
"_create_download_failed_message",
"(",
"exception",
",",
"url",
")",
":",
"message",
"=",
"'Failed to download from:\\n{}\\nwith {}:\\n{}'",
".",
"format",
"(",
"url",
",",
"exception",
".",
"__class__",
".",
"__name__",
",",
"exception",
")",
"if",
"_is_tem... |
parse ggKbase scaffold - to - bin mapping - scaffolds - to - bins and bins - to - scaffolds | def parse_s2bins ( s2bins ) : s2b = { } b2s = { } for line in s2bins : line = line . strip ( ) . split ( ) s , b = line [ 0 ] , line [ 1 ] if 'UNK' in b : continue if len ( line ) > 2 : g = ' ' . join ( line [ 2 : ] ) else : g = 'n/a' b = '%s\t%s' % ( b , g ) s2b [ s ] = b if b not in b2s : b2s [ b ] = [ ] b2s [ b ] . ... | 105 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_copies.py#L31-L52 | [
"def",
"parse_stats_file",
"(",
"self",
",",
"file_name",
")",
":",
"stats",
"=",
"{",
"}",
"try",
":",
"with",
"open",
"(",
"file_name",
",",
"\"r\"",
")",
"as",
"fhandle",
":",
"fbuffer",
"=",
"[",
"]",
"save_buffer",
"=",
"False",
"for",
"line",
"... |
remove any bins that don t have 16S | def filter_missing_rna ( s2bins , bins2s , rna_cov ) : for bin , scaffolds in list ( bins2s . items ( ) ) : c = 0 for s in scaffolds : if s in rna_cov : c += 1 if c == 0 : del bins2s [ bin ] for scaffold , bin in list ( s2bins . items ( ) ) : if bin not in bins2s : del s2bins [ scaffold ] return s2bins , bins2s | 106 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_copies.py#L76-L90 | [
"def",
"_parse_ftp_error",
"(",
"error",
")",
":",
"# type: (ftplib.Error) -> Tuple[Text, Text]",
"code",
",",
"_",
",",
"message",
"=",
"text_type",
"(",
"error",
")",
".",
"partition",
"(",
"\" \"",
")",
"return",
"code",
",",
"message"
] |
calculate bin coverage | def calc_bin_cov ( scaffolds , cov ) : bases = sum ( [ cov [ i ] [ 0 ] for i in scaffolds if i in cov ] ) length = sum ( [ cov [ i ] [ 1 ] for i in scaffolds if i in cov ] ) if length == 0 : return 0 return float ( float ( bases ) / float ( length ) ) | 107 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_copies.py#L92-L100 | [
"def",
"follow",
"(",
"resources",
",",
"*",
"*",
"kwargs",
")",
":",
"# subscribe",
"client",
"=",
"redis",
".",
"Redis",
"(",
"decode_responses",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"resources",
"=",
"resources",
"if",
"resources",
"else",
"find... |
Make sure there is at least a translation has been filled in . If a default language has been specified make sure that it exists amongst translations . | def clean ( self ) : # First make sure the super's clean method is called upon. super ( TranslationFormSet , self ) . clean ( ) if settings . HIDE_LANGUAGE : return if len ( self . forms ) > 0 : # If a default language has been provided, make sure a translation # is available if settings . DEFAULT_LANGUAGE and not any ... | 108 | https://github.com/dokterbob/django-multilingual-model/blob/2479b2c3d6f7b697e95aa1e082c8bc8699f1f638/multilingual_model/forms.py#L19-L58 | [
"def",
"remove_handlers_bound_to_instance",
"(",
"self",
",",
"obj",
")",
":",
"for",
"handler",
"in",
"self",
".",
"handlers",
":",
"if",
"handler",
".",
"im_self",
"==",
"obj",
":",
"self",
"-=",
"handler"
] |
If a default language has been set and is still available in self . available_languages return it and remove it from the list . | def _get_default_language ( self ) : assert hasattr ( self , 'available_languages' ) , 'No available languages have been generated.' assert len ( self . available_languages ) > 0 , 'No available languages to select from.' if ( settings . DEFAULT_LANGUAGE and settings . DEFAULT_LANGUAGE in self . available_languages ) o... | 109 | https://github.com/dokterbob/django-multilingual-model/blob/2479b2c3d6f7b697e95aa1e082c8bc8699f1f638/multilingual_model/forms.py#L68-L94 | [
"def",
"compute_busiest_date",
"(",
"feed",
":",
"\"Feed\"",
",",
"dates",
":",
"List",
"[",
"str",
"]",
")",
"->",
"str",
":",
"f",
"=",
"feed",
".",
"compute_trip_activity",
"(",
"dates",
")",
"s",
"=",
"[",
"(",
"f",
"[",
"c",
"]",
".",
"sum",
... |
Construct the form overriding the initial value for language_code . | def _construct_form ( self , i , * * kwargs ) : if not settings . HIDE_LANGUAGE : self . _construct_available_languages ( ) form = super ( TranslationFormSet , self ) . _construct_form ( i , * * kwargs ) if settings . HIDE_LANGUAGE : form . instance . language_code = settings . DEFAULT_LANGUAGE else : language_code = f... | 110 | https://github.com/dokterbob/django-multilingual-model/blob/2479b2c3d6f7b697e95aa1e082c8bc8699f1f638/multilingual_model/forms.py#L96-L128 | [
"def",
"_count_devices",
"(",
"self",
")",
":",
"number_of_devices",
"=",
"ctypes",
".",
"c_uint",
"(",
")",
"if",
"ctypes",
".",
"windll",
".",
"user32",
".",
"GetRawInputDeviceList",
"(",
"ctypes",
".",
"POINTER",
"(",
"ctypes",
".",
"c_int",
")",
"(",
... |
merge separate fastq files | def fq_merge ( R1 , R2 ) : c = itertools . cycle ( [ 1 , 2 , 3 , 4 ] ) for r1 , r2 in zip ( R1 , R2 ) : n = next ( c ) if n == 1 : pair = [ [ ] , [ ] ] pair [ 0 ] . append ( r1 . strip ( ) ) pair [ 1 ] . append ( r2 . strip ( ) ) if n == 4 : yield pair | 111 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/fastq_merge.py#L13-L25 | [
"def",
"AddSession",
"(",
"self",
",",
"session_id",
",",
"seat",
",",
"uid",
",",
"username",
",",
"active",
")",
":",
"seat_path",
"=",
"dbus",
".",
"ObjectPath",
"(",
"'/org/freedesktop/login1/seat/'",
"+",
"seat",
")",
"if",
"seat_path",
"not",
"in",
"... |
Creates hash ring . | def _build_circle ( self ) : total_weight = 0 for node in self . _nodes : total_weight += self . _weights . get ( node , 1 ) for node in self . _nodes : weight = self . _weights . get ( node , 1 ) ks = math . floor ( ( 40 * len ( self . _nodes ) * weight ) / total_weight ) for i in xrange ( 0 , int ( ks ) ) : b_key = s... | 112 | https://github.com/disqus/nydus/blob/9b505840da47a34f758a830c3992fa5dcb7bb7ad/nydus/contrib/ketama.py#L35-L60 | [
"def",
"libvlc_video_set_subtitle_file",
"(",
"p_mi",
",",
"psz_subtitle",
")",
":",
"f",
"=",
"_Cfunctions",
".",
"get",
"(",
"'libvlc_video_set_subtitle_file'",
",",
"None",
")",
"or",
"_Cfunction",
"(",
"'libvlc_video_set_subtitle_file'",
",",
"(",
"(",
"1",
",... |
Return long integer for a given key that represent it place on the hash ring . | def _gen_key ( self , key ) : b_key = self . _md5_digest ( key ) return self . _hashi ( b_key , lambda x : x ) | 113 | https://github.com/disqus/nydus/blob/9b505840da47a34f758a830c3992fa5dcb7bb7ad/nydus/contrib/ketama.py#L78-L84 | [
"def",
"evaluate",
"(",
"self",
",",
"verbose",
"=",
"False",
",",
"decode",
"=",
"True",
",",
"passes",
"=",
"None",
",",
"num_threads",
"=",
"1",
",",
"apply_experimental_transforms",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"weld_e... |
Returns True if there exists a custom image for app_id . | def has_custom_image ( user_context , app_id ) : possible_paths = _valid_custom_image_paths ( user_context , app_id ) return any ( map ( os . path . exists , possible_paths ) ) | 114 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/grid.py#L32-L35 | [
"def",
"add_worksheet_progress_percentage",
"(",
"portal",
")",
":",
"add_metadata",
"(",
"portal",
",",
"CATALOG_WORKSHEET_LISTING",
",",
"\"getProgressPercentage\"",
")",
"logger",
".",
"info",
"(",
"\"Reindexing Worksheets ...\"",
")",
"query",
"=",
"dict",
"(",
"p... |
Returns the custom image associated with a given app . If there are multiple candidate images on disk one is chosen arbitrarily . | def get_custom_image ( user_context , app_id ) : possible_paths = _valid_custom_image_paths ( user_context , app_id ) existing_images = filter ( os . path . exists , possible_paths ) if len ( existing_images ) > 0 : return existing_images [ 0 ] | 115 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/grid.py#L37-L43 | [
"def",
"console_wait_for_keypress",
"(",
"flush",
":",
"bool",
")",
"->",
"Key",
":",
"key",
"=",
"Key",
"(",
")",
"lib",
".",
"TCOD_console_wait_for_keypress_wrapper",
"(",
"key",
".",
"key_p",
",",
"flush",
")",
"return",
"key"
] |
Sets the custom image for app_id to be the image located at image_path . If there already exists a custom image for app_id it will be deleted . Returns True is setting the image was successful . | def set_custom_image ( user_context , app_id , image_path ) : if image_path is None : return False if not os . path . exists ( image_path ) : return False ( root , ext ) = os . path . splitext ( image_path ) if not is_valid_extension ( ext ) : # TODO: Maybe log that this happened? return False # If we don't remove the ... | 116 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/grid.py#L45-L70 | [
"def",
"seconds_passed",
"(",
"self",
")",
":",
"return",
"int",
"(",
"(",
"Date",
"(",
"self",
")",
".",
"datetime",
"-",
"self",
".",
"_STARTDATE",
".",
"datetime",
")",
".",
"total_seconds",
"(",
")",
")"
] |
Read an orthography profile from a metadata file or a default tab - separated profile file . | def from_file ( cls , fname , form = None ) : try : tg = TableGroup . from_file ( fname ) opfname = None except JSONDecodeError : tg = TableGroup . fromvalue ( cls . MD ) opfname = fname if len ( tg . tables ) != 1 : raise ValueError ( 'profile description must contain exactly one table' ) metadata = tg . common_props ... | 117 | https://github.com/cldf/segments/blob/9136a4ec89555bf9b574399ffbb07f3cc9a9f45f/src/segments/profile.py#L100-L117 | [
"def",
"fixpointmethod",
"(",
"self",
",",
"cfg_node",
")",
":",
"JOIN",
"=",
"self",
".",
"join",
"(",
"cfg_node",
")",
"# Assignment check",
"if",
"isinstance",
"(",
"cfg_node",
",",
"AssignmentNode",
")",
":",
"arrow_result",
"=",
"JOIN",
"# Reassignment ch... |
Create a Profile instance from the Unicode graphemes found in text . | def from_text ( cls , text , mapping = 'mapping' ) : graphemes = Counter ( grapheme_pattern . findall ( text ) ) specs = [ OrderedDict ( [ ( cls . GRAPHEME_COL , grapheme ) , ( 'frequency' , frequency ) , ( mapping , grapheme ) ] ) for grapheme , frequency in graphemes . most_common ( ) ] return cls ( * specs ) | 118 | https://github.com/cldf/segments/blob/9136a4ec89555bf9b574399ffbb07f3cc9a9f45f/src/segments/profile.py#L120-L141 | [
"def",
"step",
"(",
"self",
",",
"state",
",",
"clamping",
")",
":",
"ns",
"=",
"state",
".",
"copy",
"(",
")",
"for",
"var",
"in",
"state",
":",
"if",
"clamping",
".",
"has_variable",
"(",
"var",
")",
":",
"ns",
"[",
"var",
"]",
"=",
"int",
"(... |
split fasta file into separate fasta files based on list of scaffolds that belong to each separate file | def split_fasta ( f , id2f ) : opened = { } for seq in parse_fasta ( f ) : id = seq [ 0 ] . split ( '>' ) [ 1 ] . split ( ) [ 0 ] if id not in id2f : continue fasta = id2f [ id ] if fasta not in opened : opened [ fasta ] = '%s.fa' % fasta seq [ 1 ] += '\n' with open ( opened [ fasta ] , 'a+' ) as f_out : f_out . write ... | 119 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/name2fasta.py#L7-L22 | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"return",
"Event",
".",
"objects",
".",
"filter",
"(",
"Q",
"(",
"startTime__gte",
"=",
"timezone",
".",
"now",
"(",
")",
"-",
"timedelta",
"(",
"days",
"=",
"90",
")",
")",
"&",
"(",
"Q",
"(",
"series_... |
Check whether pathname is a valid user data directory | def _is_user_directory ( self , pathname ) : fullpath = os . path . join ( self . userdata_location ( ) , pathname ) # SteamOS puts a directory named 'anonymous' in the userdata directory # by default. Since we assume that pathname is a userID, ignore any name # that can't be converted to a number return os . path . is... | 120 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/legacy/steam.py#L47-L58 | [
"def",
"pad_decr",
"(",
"ids",
")",
":",
"if",
"len",
"(",
"ids",
")",
"<",
"1",
":",
"return",
"list",
"(",
"ids",
")",
"if",
"not",
"any",
"(",
"ids",
")",
":",
"return",
"[",
"]",
"# all padding.",
"idx",
"=",
"-",
"1",
"while",
"not",
"ids"... |
Returns an array of user ids for users on the filesystem | def local_users ( self ) : # Any users on the machine will have an entry inside of the userdata # folder. As such, the easiest way to find a list of all users on the # machine is to just list the folders inside userdata userdirs = filter ( self . _is_user_directory , os . listdir ( self . userdata_location ( ) ) ) # Ex... | 121 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/legacy/steam.py#L80-L87 | [
"def",
"change_thickness",
"(",
"self",
",",
"element",
",",
"thickness",
")",
":",
"if",
"element",
"==",
"\"header\"",
":",
"self",
".",
"data",
".",
"append",
"(",
"Command",
"(",
"\"renewcommand\"",
",",
"arguments",
"=",
"[",
"NoEscape",
"(",
"r\"\\he... |
Calculates degree days starting with a series of temperature equivalent values | def _calculate_degree_days ( temperature_equivalent , base_temperature , cooling = False ) : if cooling : ret = temperature_equivalent - base_temperature else : ret = base_temperature - temperature_equivalent # degree days cannot be negative ret [ ret < 0 ] = 0 prefix = 'CDD' if cooling else 'HDD' ret . name = '{}_{}' ... | 122 | https://github.com/opengridcc/opengrid/blob/69b8da3c8fcea9300226c45ef0628cd6d4307651/opengrid/library/weather.py#L31-L59 | [
"def",
"undefine",
"(",
"self",
")",
":",
"if",
"lib",
".",
"EnvUndefmessageHandler",
"(",
"self",
".",
"_env",
",",
"self",
".",
"_cls",
",",
"self",
".",
"_idx",
")",
"!=",
"1",
":",
"raise",
"CLIPSError",
"(",
"self",
".",
"_env",
")",
"self",
"... |
Development status . | def status ( self ) : return { self . _acronym_status ( l ) : l for l in self . resp_text . split ( '\n' ) if l . startswith ( self . prefix_status ) } | 123 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/classifiers.py#L33-L36 | [
"def",
"on_response",
"(",
"self",
",",
"ch",
",",
"method_frame",
",",
"props",
",",
"body",
")",
":",
"LOGGER",
".",
"debug",
"(",
"\"rabbitmq.Requester.on_response\"",
")",
"if",
"self",
".",
"corr_id",
"==",
"props",
".",
"correlation_id",
":",
"self",
... |
OSI Approved license . | def licenses ( self ) : return { self . _acronym_lic ( l ) : l for l in self . resp_text . split ( '\n' ) if l . startswith ( self . prefix_lic ) } | 124 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/classifiers.py#L43-L46 | [
"async",
"def",
"logs",
"(",
"self",
",",
"service_id",
":",
"str",
",",
"*",
",",
"details",
":",
"bool",
"=",
"False",
",",
"follow",
":",
"bool",
"=",
"False",
",",
"stdout",
":",
"bool",
"=",
"False",
",",
"stderr",
":",
"bool",
"=",
"False",
... |
Remove prefix . | def licenses_desc ( self ) : return { self . _acronym_lic ( l ) : l . split ( self . prefix_lic ) [ 1 ] for l in self . resp_text . split ( '\n' ) if l . startswith ( self . prefix_lic ) } | 125 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/classifiers.py#L48-L52 | [
"def",
"_add_dependency",
"(",
"self",
",",
"dependency",
",",
"var_name",
"=",
"None",
")",
":",
"if",
"var_name",
"is",
"None",
":",
"var_name",
"=",
"next",
"(",
"self",
".",
"temp_var_names",
")",
"# Don't add duplicate dependencies",
"if",
"(",
"dependenc... |
Convert license acronym . | def _acronym_lic ( self , license_statement ) : pat = re . compile ( r'\(([\w+\W?\s?]+)\)' ) if pat . search ( license_statement ) : lic = pat . search ( license_statement ) . group ( 1 ) if lic . startswith ( 'CNRI' ) : acronym_licence = lic [ : 4 ] else : acronym_licence = lic . replace ( ' ' , '' ) else : acronym_li... | 126 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/classifiers.py#L54-L67 | [
"def",
"volumes_delete",
"(",
"storage_pool",
",",
"logger",
")",
":",
"try",
":",
"for",
"vol_name",
"in",
"storage_pool",
".",
"listVolumes",
"(",
")",
":",
"try",
":",
"vol",
"=",
"storage_pool",
".",
"storageVolLookupByName",
"(",
"vol_name",
")",
"vol",... |
calc MD5 based on path | def calcMD5 ( path ) : # check that file exists if os . path . exists ( path ) is False : yield False else : command = [ 'md5sum' , path ] p = Popen ( command , stdout = PIPE ) for line in p . communicate ( ) [ 0 ] . splitlines ( ) : yield line . decode ( 'ascii' ) . strip ( ) . split ( ) [ 0 ] p . wait ( ) yield False | 127 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L18-L31 | [
"async",
"def",
"release_name_async",
"(",
"self",
",",
"bus_name",
",",
"error",
"=",
"None",
",",
"timeout",
"=",
"DBUS",
".",
"TIMEOUT_USE_DEFAULT",
")",
":",
"assert",
"self",
".",
"loop",
"!=",
"None",
",",
"\"no event loop to attach coroutine to\"",
"retur... |
download files with wget | def wget ( ftp , f = False , exclude = False , name = False , md5 = False , tries = 10 ) : # file name if f is False : f = ftp . rsplit ( '/' , 1 ) [ - 1 ] # downloaded file if it does not already exist # check md5s on server (optional) t = 0 while md5check ( f , ftp , md5 , exclude ) is not True : t += 1 if name is no... | 128 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L74-L97 | [
"def",
"get_listing",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'listing'",
")",
":",
"allEvents",
"=",
"self",
".",
"get_allEvents",
"(",
")",
"openEvents",
"=",
"allEvents",
".",
"filter",
"(",
"registrationOpen",
"=",
"True",
"... |
check that at least one of queries is in list l | def check ( line , queries ) : line = line . strip ( ) spLine = line . replace ( '.' , ' ' ) . split ( ) matches = set ( spLine ) . intersection ( queries ) if len ( matches ) > 0 : return matches , line . split ( '\t' ) return matches , False | 129 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L99-L109 | [
"def",
"_OpenFile",
"(",
"self",
",",
"path",
")",
":",
"if",
"not",
"self",
".",
"_registry_file_reader",
":",
"return",
"None",
"return",
"self",
".",
"_registry_file_reader",
".",
"Open",
"(",
"path",
",",
"ascii_codepage",
"=",
"self",
".",
"_ascii_codep... |
search entrez using specified database and accession | def entrez ( db , acc ) : c1 = [ 'esearch' , '-db' , db , '-query' , acc ] c2 = [ 'efetch' , '-db' , 'BioSample' , '-format' , 'docsum' ] p1 = Popen ( c1 , stdout = PIPE , stderr = PIPE ) p2 = Popen ( c2 , stdin = p1 . stdout , stdout = PIPE , stderr = PIPE ) return p2 . communicate ( ) | 130 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L111-L120 | [
"def",
"parse_units",
"(",
"units_str",
")",
":",
"if",
"not",
"len",
"(",
"units_str",
")",
":",
"return",
"units_str",
",",
"(",
"None",
",",
"None",
")",
"if",
"units_str",
"[",
"-",
"1",
"]",
"==",
"']'",
":",
"units",
",",
"lims",
"=",
"units_... |
attempt to use NCBI Entrez to get BioSample ID | def searchAccession ( acc ) : # try genbank file # genome database out , error = entrez ( 'genome' , acc ) for line in out . splitlines ( ) : line = line . decode ( 'ascii' ) . strip ( ) if 'Assembly_Accession' in line or 'BioSample' in line : newAcc = line . split ( '>' ) [ 1 ] . split ( '<' ) [ 0 ] . split ( '.' ) [ ... | 131 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L122-L156 | [
"def",
"_evictStaleDevices",
"(",
"self",
")",
":",
"while",
"self",
".",
"running",
":",
"expiredDeviceIds",
"=",
"[",
"key",
"for",
"key",
",",
"value",
"in",
"self",
".",
"devices",
".",
"items",
"(",
")",
"if",
"value",
".",
"hasExpired",
"(",
")",... |
download genome info from NCBI | def getFTPs ( accessions , ftp , search , exclude , convert = False , threads = 1 , attempt = 1 , max_attempts = 2 ) : info = wget ( ftp ) [ 0 ] allMatches = [ ] for genome in open ( info , encoding = 'utf8' ) : genome = str ( genome ) matches , genomeInfo = check ( genome , accessions ) if genomeInfo is not False : f ... | 132 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L158-L195 | [
"def",
"start_transmit",
"(",
"self",
",",
"blocking",
"=",
"False",
",",
"start_packet_groups",
"=",
"True",
",",
"*",
"ports",
")",
":",
"port_list",
"=",
"self",
".",
"set_ports_list",
"(",
"*",
"ports",
")",
"if",
"start_packet_groups",
":",
"port_list_f... |
download genomes from NCBI | def download ( args ) : accessions , infoFTP = set ( args [ 'g' ] ) , args [ 'i' ] search , exclude = args [ 's' ] , args [ 'e' ] FTPs = getFTPs ( accessions , infoFTP , search , exclude , threads = args [ 't' ] , convert = args [ 'convert' ] ) if args [ 'test' ] is True : for genome in FTPs : print ( 'found:' , ';' . ... | 133 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/ncbi_download.py#L204-L221 | [
"def",
"one_cycle_scheduler",
"(",
"lr_max",
":",
"float",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"OneCycleScheduler",
":",
"return",
"partial",
"(",
"OneCycleScheduler",
",",
"lr_max",
"=",
"lr_max",
",",
"*",
"*",
"kwargs",
")"
] |
remove pesky characters from fasta file header | def fix_fasta ( fasta ) : for seq in parse_fasta ( fasta ) : seq [ 0 ] = remove_char ( seq [ 0 ] ) if len ( seq [ 1 ] ) > 0 : yield seq | 134 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/fix_fasta.py#L18-L25 | [
"def",
"remove_server",
"(",
"self",
",",
"server_id",
")",
":",
"# Validate server_id",
"server",
"=",
"self",
".",
"_get_server",
"(",
"server_id",
")",
"# Delete any instances we recorded to be cleaned up",
"if",
"server_id",
"in",
"self",
".",
"_owned_subscriptions"... |
Compute a DataFrame summary of a Stats object . | def _calc_frames ( stats ) : timings = [ ] callers = [ ] for key , values in iteritems ( stats . stats ) : timings . append ( pd . Series ( key + values [ : - 1 ] , index = timing_colnames , ) ) for caller_key , caller_values in iteritems ( values [ - 1 ] ) : callers . append ( pd . Series ( key + caller_key + caller_v... | 135 | https://github.com/ssanderson/pstats-view/blob/62148d4e01765806bc5e6bb40628cdb186482c05/pstatsviewer/viewer.py#L40-L66 | [
"def",
"unbind",
"(",
"self",
",",
"devices_to_unbind",
")",
":",
"if",
"self",
".",
"entity_api_key",
"==",
"\"\"",
":",
"return",
"{",
"'status'",
":",
"'failure'",
",",
"'response'",
":",
"'No API key found in request'",
"}",
"url",
"=",
"self",
".",
"bas... |
get unmapped reads | def unmapped ( sam , mates ) : for read in sam : if read . startswith ( '@' ) is True : continue read = read . strip ( ) . split ( ) if read [ 2 ] == '*' and read [ 6 ] == '*' : yield read elif mates is True : if read [ 2 ] == '*' or read [ 6 ] == '*' : yield read for i in read : if i == 'YT:Z:UP' : yield read | 136 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/unmapped.py#L11-L26 | [
"def",
"syzygyJD",
"(",
"jd",
")",
":",
"sun",
"=",
"swe",
".",
"sweObjectLon",
"(",
"const",
".",
"SUN",
",",
"jd",
")",
"moon",
"=",
"swe",
".",
"sweObjectLon",
"(",
"const",
".",
"MOON",
",",
"jd",
")",
"dist",
"=",
"angle",
".",
"distance",
"... |
execute jobs in processes using N threads | def parallel ( processes , threads ) : pool = multithread ( threads ) pool . map ( run_process , processes ) pool . close ( ) pool . join ( ) | 137 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/parallel.py#L19-L26 | [
"def",
"missing_any",
"(",
"da",
",",
"freq",
",",
"*",
"*",
"kwds",
")",
":",
"c",
"=",
"da",
".",
"notnull",
"(",
")",
".",
"resample",
"(",
"time",
"=",
"freq",
")",
".",
"sum",
"(",
"dim",
"=",
"'time'",
")",
"if",
"'-'",
"in",
"freq",
":... |
the final log processor that structlog requires to render . | def define_log_renderer ( fmt , fpath , quiet ) : # it must accept a logger, method_name and event_dict (just like processors) # but must return the rendered string, not a dictionary. # TODO tty logic if fmt : return structlog . processors . JSONRenderer ( ) if fpath is not None : return structlog . processors . JSONRe... | 138 | https://github.com/deep-compute/basescript/blob/f7233963c5291530fcb2444a7f45b556e6407b90/basescript/log.py#L239-L256 | [
"def",
"right_click_specimen_equalarea",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"LeftIsDown",
"(",
")",
"or",
"event",
".",
"ButtonDClick",
"(",
")",
":",
"return",
"elif",
"self",
".",
"specimen_EA_setting",
"==",
"\"Zoom\"",
":",
"self",
... |
Add unique id type and hostname | def _structlog_default_keys_processor ( logger_class , log_method , event ) : global HOSTNAME if 'id' not in event : event [ 'id' ] = '%s_%s' % ( datetime . utcnow ( ) . strftime ( '%Y%m%dT%H%M%S' ) , uuid . uuid1 ( ) . hex ) if 'type' not in event : event [ 'type' ] = 'log' event [ 'host' ] = HOSTNAME return event | 139 | https://github.com/deep-compute/basescript/blob/f7233963c5291530fcb2444a7f45b556e6407b90/basescript/log.py#L258-L273 | [
"def",
"_openResources",
"(",
"self",
")",
":",
"try",
":",
"rate",
",",
"data",
"=",
"scipy",
".",
"io",
".",
"wavfile",
".",
"read",
"(",
"self",
".",
"_fileName",
",",
"mmap",
"=",
"True",
")",
"except",
"Exception",
"as",
"ex",
":",
"logger",
"... |
log processors that structlog executes before final rendering | def define_log_processors ( ) : # these processors should accept logger, method_name and event_dict # and return a new dictionary which will be passed as event_dict to the next one. return [ structlog . processors . TimeStamper ( fmt = "iso" ) , _structlog_default_keys_processor , structlog . stdlib . PositionalArgumen... | 140 | https://github.com/deep-compute/basescript/blob/f7233963c5291530fcb2444a7f45b556e6407b90/basescript/log.py#L352-L364 | [
"def",
"new_pin",
"(",
"self",
",",
"min_length",
"=",
"4",
",",
"min_common",
"=",
"1000",
",",
"timeout",
"=",
"20",
",",
"refresh_timeout",
"=",
"3",
")",
":",
"self",
".",
"refresh",
"(",
"count_common",
"=",
"min_length",
",",
"min_common",
"=",
"... |
configures a logger when required write to stderr or a file | def _configure_logger ( fmt , quiet , level , fpath , pre_hooks , post_hooks , metric_grouping_interval ) : # NOTE not thread safe. Multiple BaseScripts cannot be instantiated concurrently. level = getattr ( logging , level . upper ( ) ) global _GLOBAL_LOG_CONFIGURED if _GLOBAL_LOG_CONFIGURED : return # since the hooks... | 141 | https://github.com/deep-compute/basescript/blob/f7233963c5291530fcb2444a7f45b556e6407b90/basescript/log.py#L366-L447 | [
"def",
"_get_aggregated_info",
"(",
"self",
")",
":",
"agg_results",
"=",
"{",
"}",
"for",
"key",
"in",
"self",
".",
"aggregated_info",
"[",
"'occurrences'",
"]",
":",
"agg_results",
"[",
"key",
"]",
"=",
"{",
"'occurrences'",
":",
"self",
".",
"aggregated... |
Instead of using a processor adding basic information like caller filename etc here . | def _add_base_info ( self , event_dict ) : f = sys . _getframe ( ) level_method_frame = f . f_back caller_frame = level_method_frame . f_back return event_dict | 142 | https://github.com/deep-compute/basescript/blob/f7233963c5291530fcb2444a7f45b556e6407b90/basescript/log.py#L121-L129 | [
"def",
"_clamp_string",
"(",
"self",
",",
"row_item",
",",
"column_index",
",",
"delimiter",
"=",
"''",
")",
":",
"width",
"=",
"(",
"self",
".",
"_table",
".",
"column_widths",
"[",
"column_index",
"]",
"-",
"self",
".",
"_table",
".",
"left_padding_width... |
Propagate a method call to the wrapped logger . | def _proxy_to_logger ( self , method_name , event , * event_args , * * event_kw ) : if isinstance ( event , bytes ) : event = event . decode ( 'utf-8' ) if event_args : event_kw [ 'positional_args' ] = event_args return super ( BoundLevelLogger , self ) . _proxy_to_logger ( method_name , event = event , * * event_kw ) | 143 | https://github.com/deep-compute/basescript/blob/f7233963c5291530fcb2444a7f45b556e6407b90/basescript/log.py#L211-L229 | [
"def",
"calculateOverlapCurve",
"(",
"sp",
",",
"inputVectors",
")",
":",
"columnNumber",
"=",
"np",
".",
"prod",
"(",
"sp",
".",
"getColumnDimensions",
"(",
")",
")",
"numInputVector",
",",
"inputSize",
"=",
"inputVectors",
".",
"shape",
"outputColumns",
"=",... |
Given four points of a rectangle translate the rectangle to the specified x and y coordinates and optionally change the width . | def translate ( rect , x , y , width = 1 ) : return ( ( rect [ 0 ] [ 0 ] + x , rect [ 0 ] [ 1 ] + y ) , ( rect [ 1 ] [ 0 ] + x , rect [ 1 ] [ 1 ] + y ) , ( rect [ 2 ] [ 0 ] + x + width , rect [ 2 ] [ 1 ] + y ) , ( rect [ 3 ] [ 0 ] + x + width , rect [ 3 ] [ 1 ] + y ) ) | 144 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/core_overlap_plot.py#L57-L74 | [
"def",
"render_unregistered",
"(",
"error",
"=",
"None",
")",
":",
"return",
"template",
"(",
"read_index_template",
"(",
")",
",",
"registered",
"=",
"False",
",",
"error",
"=",
"error",
",",
"seeder_data",
"=",
"None",
",",
"url_id",
"=",
"None",
",",
... |
remove problem characters from string | def remove_bad ( string ) : remove = [ ':' , ',' , '(' , ')' , ' ' , '|' , ';' , '\'' ] for c in remove : string = string . replace ( c , '_' ) return string | 145 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rax.py#L43-L50 | [
"def",
"getAssociation",
"(",
"self",
",",
"server_url",
",",
"handle",
"=",
"None",
")",
":",
"if",
"handle",
"is",
"None",
":",
"handle",
"=",
"''",
"# The filename with the empty handle is a prefix of all other",
"# associations for the given server URL.",
"filename",
... |
make copy of sequences with short identifier | def get_ids ( a ) : a_id = '%s.id.fa' % ( a . rsplit ( '.' , 1 ) [ 0 ] ) a_id_lookup = '%s.id.lookup' % ( a . rsplit ( '.' , 1 ) [ 0 ] ) if check ( a_id ) is True : return a_id , a_id_lookup a_id_f = open ( a_id , 'w' ) a_id_lookup_f = open ( a_id_lookup , 'w' ) ids = [ ] for seq in parse_fasta ( open ( a ) ) : id = id... | 146 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rax.py#L55-L76 | [
"def",
"face_index",
"(",
"vertices",
")",
":",
"new_verts",
"=",
"[",
"]",
"face_indices",
"=",
"[",
"]",
"for",
"wall",
"in",
"vertices",
":",
"face_wall",
"=",
"[",
"]",
"for",
"vert",
"in",
"wall",
":",
"if",
"new_verts",
":",
"if",
"not",
"np",
... |
convert fasta to phylip because RAxML is ridiculous | def convert2phylip ( convert ) : out = '%s.phy' % ( convert . rsplit ( '.' , 1 ) [ 0 ] ) if check ( out ) is False : convert = open ( convert , 'rU' ) out_f = open ( out , 'w' ) alignments = AlignIO . parse ( convert , "fasta" ) AlignIO . write ( alignments , out , "phylip" ) return out | 147 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rax.py#L78-L88 | [
"def",
"set_item",
"(",
"key",
",",
"value",
")",
":",
"CACHED_KEY_FILE",
"=",
"os",
".",
"path",
".",
"join",
"(",
"CURRENT_DIR",
",",
"key",
")",
"open",
"(",
"CACHED_KEY_FILE",
",",
"\"wb\"",
")",
".",
"write",
"(",
"json",
".",
"dumps",
"(",
"{",... |
run IQ - Tree | def run_iqtree ( phy , model , threads , cluster , node ) : # set ppn based on threads if threads > 24 : ppn = 24 else : ppn = threads tree = '%s.treefile' % ( phy ) if check ( tree ) is False : if model is False : model = 'TEST' dir = os . getcwd ( ) command = 'iqtree-omp -s %s -m %s -nt %s -quiet' % ( phy , model , t... | 148 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rax.py#L163-L190 | [
"def",
"private_messenger",
"(",
")",
":",
"while",
"__websocket_server_running__",
":",
"pipein",
"=",
"open",
"(",
"PRIVATE_PIPE",
",",
"'r'",
")",
"line",
"=",
"pipein",
".",
"readline",
"(",
")",
".",
"replace",
"(",
"'\\n'",
",",
"''",
")",
".",
"re... |
get the names for sequences in the raxml tree | def fix_tree ( tree , a_id_lookup , out ) : if check ( out ) is False and check ( tree ) is True : tree = open ( tree ) . read ( ) for line in open ( a_id_lookup ) : id , name , header = line . strip ( ) . split ( '\t' ) tree = tree . replace ( id + ':' , name + ':' ) out_f = open ( out , 'w' ) print ( tree . strip ( )... | 149 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rax.py#L192-L203 | [
"def",
"start",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"is_running",
"(",
")",
":",
"self",
".",
"websock_url",
"=",
"self",
".",
"chrome",
".",
"start",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"websock",
"="... |
Creates a new Nydus cluster from the given settings . | def create_cluster ( settings ) : # Pull in our client settings = copy . deepcopy ( settings ) backend = settings . pop ( 'engine' , settings . pop ( 'backend' , None ) ) if isinstance ( backend , basestring ) : Conn = import_string ( backend ) elif backend : Conn = backend else : raise KeyError ( 'backend' ) # Pull in... | 150 | https://github.com/disqus/nydus/blob/9b505840da47a34f758a830c3992fa5dcb7bb7ad/nydus/db/__init__.py#L28-L82 | [
"def",
"libvlc_media_player_has_vout",
"(",
"p_mi",
")",
":",
"f",
"=",
"_Cfunctions",
".",
"get",
"(",
"'libvlc_media_player_has_vout'",
",",
"None",
")",
"or",
"_Cfunction",
"(",
"'libvlc_media_player_has_vout'",
",",
"(",
"(",
"1",
",",
")",
",",
")",
",",
... |
Gets the translation of a specific field for a specific language code . | def _get_translation ( self , field , code ) : if not code in self . _translation_cache : translations = self . translations . select_related ( ) logger . debug ( u'Matched with field %s for language %s. Attempting lookup.' , field , code ) try : translation_obj = translations . get ( language_code = code ) except Obje... | 151 | https://github.com/dokterbob/django-multilingual-model/blob/2479b2c3d6f7b697e95aa1e082c8bc8699f1f638/multilingual_model/models.py#L44-L90 | [
"def",
"on_open",
"(",
"self",
",",
"func",
")",
":",
"self",
".",
"_on_open",
"=",
"func",
"if",
"self",
".",
"opened",
":",
"# pragma: no cover",
"self",
".",
"_on_open",
"(",
"self",
")",
"return",
"func"
] |
Wrapper to allow for easy unicode representation of an object by the specified property . If this wrapper is not able to find the right translation of the specified property it will return the default value instead . | def unicode_wrapper ( self , property , default = ugettext ( 'Untitled' ) ) : # TODO: Test coverage! try : value = getattr ( self , property ) except ValueError : logger . warn ( u'ValueError rendering unicode for %s object.' , self . _meta . object_name ) value = None if not value : value = default return value | 152 | https://github.com/dokterbob/django-multilingual-model/blob/2479b2c3d6f7b697e95aa1e082c8bc8699f1f638/multilingual_model/models.py#L202-L228 | [
"def",
"color",
"(",
"requestContext",
",",
"seriesList",
",",
"theColor",
")",
":",
"for",
"series",
"in",
"seriesList",
":",
"series",
".",
"color",
"=",
"theColor",
"return",
"seriesList"
] |
remove insertion columns from aligned fasta file | def strip_inserts ( fasta ) : for seq in parse_fasta ( fasta ) : seq [ 1 ] = '' . join ( [ b for b in seq [ 1 ] if b == '-' or b . isupper ( ) ] ) yield seq | 153 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/strip_align_inserts.py#L12-L18 | [
"def",
"bucket",
"(",
"self",
",",
"experiment",
",",
"user_id",
",",
"bucketing_id",
")",
":",
"if",
"not",
"experiment",
":",
"return",
"None",
"# Determine if experiment is in a mutually exclusive group",
"if",
"experiment",
".",
"groupPolicy",
"in",
"GROUP_POLICIE... |
Transform a string s graphemes into the mappings given in a different column in the orthography profile . | def transform ( self , word , column = Profile . GRAPHEME_COL , error = errors . replace ) : assert self . op , 'method can only be called with orthography profile.' if column != Profile . GRAPHEME_COL and column not in self . op . column_labels : raise ValueError ( "Column {0} not found in profile." . format ( column ... | 154 | https://github.com/cldf/segments/blob/9136a4ec89555bf9b574399ffbb07f3cc9a9f45f/src/segments/tokenizer.py#L231-L270 | [
"def",
"match_published_date",
"(",
"self",
",",
"start",
",",
"end",
",",
"match",
")",
":",
"self",
".",
"_match_minimum_date_time",
"(",
"'publishedDate'",
",",
"start",
",",
"match",
")",
"self",
".",
"_match_maximum_date_time",
"(",
"'publishedDate'",
",",
... |
Function to tokenize input string and return output of str with ortho rules applied . | def rules ( self , word ) : return self . _rules . apply ( word ) if self . _rules else word | 155 | https://github.com/cldf/segments/blob/9136a4ec89555bf9b574399ffbb07f3cc9a9f45f/src/segments/tokenizer.py#L272-L288 | [
"def",
"lv_grid_generators_bus_bar",
"(",
"nd",
")",
":",
"lv_stats",
"=",
"{",
"}",
"for",
"la",
"in",
"nd",
".",
"_mv_grid_districts",
"[",
"0",
"]",
".",
"lv_load_areas",
"(",
")",
":",
"for",
"lvgd",
"in",
"la",
".",
"lv_grid_districts",
"(",
")",
... |
Given a string that is space - delimited on Unicode grapheme clusters group Unicode modifier letters with their preceding base characters deal with tie bars etc . | def combine_modifiers ( self , graphemes ) : result = [ ] temp = "" count = len ( graphemes ) for grapheme in reversed ( graphemes ) : count -= 1 if len ( grapheme ) == 1 and unicodedata . category ( grapheme ) == "Lm" and not ord ( grapheme ) in [ 712 , 716 ] : temp = grapheme + temp # hack for the cases where a space... | 156 | https://github.com/cldf/segments/blob/9136a4ec89555bf9b574399ffbb07f3cc9a9f45f/src/segments/tokenizer.py#L290-L349 | [
"def",
"save_model",
"(",
"self",
",",
"file_name",
"=",
"None",
")",
":",
"if",
"file_name",
"is",
"None",
":",
"logger",
".",
"error",
"(",
"'Missing file name'",
")",
"return",
"pcc",
".",
"model_to_owl",
"(",
"self",
".",
"model",
",",
"file_name",
"... |
parse catalytic RNAs to gff format | def parse_catalytic ( insertion , gff ) : offset = insertion [ 'offset' ] GeneStrand = insertion [ 'strand' ] if type ( insertion [ 'intron' ] ) is not str : return gff for intron in parse_fasta ( insertion [ 'intron' ] . split ( '|' ) ) : ID , annot , strand , pos = intron [ 0 ] . split ( '>' ) [ 1 ] . split ( ) Start... | 157 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_insertions_gff.py#L13-L40 | [
"def",
"communityvisibilitystate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_communityvisibilitystate",
"==",
"None",
":",
"return",
"None",
"elif",
"self",
".",
"_communityvisibilitystate",
"in",
"self",
".",
"VisibilityState",
":",
"return",
"self",
".",
"Vi... |
parse ORF to gff format | def parse_orf ( insertion , gff ) : offset = insertion [ 'offset' ] if type ( insertion [ 'orf' ] ) is not str : return gff for orf in parse_fasta ( insertion [ 'orf' ] . split ( '|' ) ) : ID = orf [ 0 ] . split ( '>' ) [ 1 ] . split ( ) [ 0 ] Start , End , strand = [ int ( i ) for i in orf [ 0 ] . split ( ' # ' ) [ 1 ... | 158 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_insertions_gff.py#L42-L76 | [
"def",
"list_blobs",
"(",
"call",
"=",
"None",
",",
"kwargs",
"=",
"None",
")",
":",
"# pylint: disable=unused-argument",
"if",
"kwargs",
"is",
"None",
":",
"kwargs",
"=",
"{",
"}",
"if",
"'container'",
"not",
"in",
"kwargs",
":",
"raise",
"SaltCloudSystemEx... |
parse insertion to gff format | def parse_insertion ( insertion , gff ) : offset = insertion [ 'offset' ] for ins in parse_fasta ( insertion [ 'insertion sequence' ] . split ( '|' ) ) : strand = insertion [ 'strand' ] ID = ins [ 0 ] . split ( '>' ) [ 1 ] . split ( ) [ 0 ] Start , End = [ int ( i ) for i in ins [ 0 ] . split ( 'gene-pos=' , 1 ) [ 1 ] ... | 159 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_insertions_gff.py#L78-L99 | [
"def",
"update_cluster",
"(",
"cluster_ref",
",",
"cluster_spec",
")",
":",
"cluster_name",
"=",
"get_managed_object_name",
"(",
"cluster_ref",
")",
"log",
".",
"trace",
"(",
"'Updating cluster \\'%s\\''",
",",
"cluster_name",
")",
"try",
":",
"task",
"=",
"cluste... |
parse rRNA to gff format | def parse_rRNA ( insertion , seq , gff ) : offset = insertion [ 'offset' ] strand = insertion [ 'strand' ] for rRNA in parse_masked ( seq , 0 ) [ 0 ] : rRNA = '' . join ( rRNA ) Start = seq [ 1 ] . find ( rRNA ) + 1 End = Start + len ( rRNA ) - 1 if strand == '-' : Start , End = End - 2 , Start - 2 pos = ( abs ( Start ... | 160 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_insertions_gff.py#L122-L147 | [
"def",
"get_owned_subscriptions",
"(",
"self",
",",
"server_id",
")",
":",
"# Validate server_id",
"self",
".",
"_get_server",
"(",
"server_id",
")",
"return",
"list",
"(",
"self",
".",
"_owned_subscriptions",
"[",
"server_id",
"]",
")"
] |
convert iTable to gff file | def iTable2GFF ( iTable , fa , contig = False ) : columns = [ '#seqname' , 'source' , 'feature' , 'start' , 'end' , 'score' , 'strand' , 'frame' , 'attribute' ] gff = { c : [ ] for c in columns } for insertion in iTable . iterrows ( ) : insertion = insertion [ 1 ] if insertion [ 'ID' ] not in fa : continue # rRNA stran... | 161 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/rRNA_insertions_gff.py#L149-L197 | [
"def",
"get_owned_subscriptions",
"(",
"self",
",",
"server_id",
")",
":",
"# Validate server_id",
"self",
".",
"_get_server",
"(",
"server_id",
")",
"return",
"list",
"(",
"self",
".",
"_owned_subscriptions",
"[",
"server_id",
"]",
")"
] |
Given an abundance table group the counts by every taxonomic level . | def summarize_taxa ( biom ) : tamtcounts = defaultdict ( int ) tot_seqs = 0.0 for row , col , amt in biom [ 'data' ] : tot_seqs += amt rtax = biom [ 'rows' ] [ row ] [ 'metadata' ] [ 'taxonomy' ] for i , t in enumerate ( rtax ) : t = t . strip ( ) if i == len ( rtax ) - 1 and len ( t ) > 3 and len ( rtax [ - 1 ] ) > 3 ... | 162 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/biom_phyla_summary.py#L27-L46 | [
"async",
"def",
"async_init",
"(",
"self",
")",
"->",
"None",
":",
"if",
"not",
"self",
".",
"_client_established",
":",
"await",
"self",
".",
"request",
"(",
"'put'",
",",
"'clients/{0}'",
".",
"format",
"(",
"self",
".",
"client_uuid",
")",
",",
"data"... |
Returns the path to the custom image set for this game or None if no image is set | def custom_image ( self , user ) : for ext in self . valid_custom_image_extensions ( ) : image_location = self . _custom_image_path ( user , ext ) if os . path . isfile ( image_location ) : return image_location return None | 163 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/legacy/game.py#L41-L48 | [
"def",
"wncond",
"(",
"left",
",",
"right",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
"left",
")",
"... |
Sets a custom image for the game . image_path should refer to an image file on disk | def set_image ( self , user , image_path ) : _ , ext = os . path . splitext ( image_path ) shutil . copy ( image_path , self . _custom_image_path ( user , ext ) ) | 164 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/legacy/game.py#L50-L54 | [
"def",
"_update",
"(",
"self",
")",
":",
"self",
".",
"clear",
"(",
")",
"self",
".",
"_set_boutons_communs",
"(",
")",
"if",
"self",
".",
"interface",
":",
"self",
".",
"addSeparator",
"(",
")",
"l_actions",
"=",
"self",
".",
"interface",
".",
"get_ac... |
get a list of mapped reads | def sam_list ( sam ) : list = [ ] for file in sam : for line in file : if line . startswith ( '@' ) is False : line = line . strip ( ) . split ( ) id , map = line [ 0 ] , int ( line [ 1 ] ) if map != 4 and map != 8 : list . append ( id ) return set ( list ) | 165 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/filter_fastq_sam.py#L7-L19 | [
"def",
"search",
"(",
"query",
",",
"team",
"=",
"None",
")",
":",
"if",
"team",
"is",
"None",
":",
"team",
"=",
"_find_logged_in_team",
"(",
")",
"if",
"team",
"is",
"not",
"None",
":",
"session",
"=",
"_get_session",
"(",
"team",
")",
"response",
"... |
get a list of mapped reads require that both pairs are mapped in the sam file in order to remove the reads | def sam_list_paired ( sam ) : list = [ ] pair = [ '1' , '2' ] prev = '' for file in sam : for line in file : if line . startswith ( '@' ) is False : line = line . strip ( ) . split ( ) id , map = line [ 0 ] , int ( line [ 1 ] ) if map != 4 and map != 8 : read = id . rsplit ( '/' ) [ 0 ] if read == prev : list . append ... | 166 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/filter_fastq_sam.py#L21-L39 | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"startTime",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"configure",
"(",
"text",
"=",
"'{0:<d} s'",
".",
"format",
"(",
"0",
")",
")",
"self",
".",
"update",
"(",
")"
] |
require that both pairs are mapped in the sam file in order to remove the reads | def filter_paired ( list ) : pairs = { } filtered = [ ] for id in list : read = id . rsplit ( '/' ) [ 0 ] if read not in pairs : pairs [ read ] = [ ] pairs [ read ] . append ( id ) for read in pairs : ids = pairs [ read ] if len ( ids ) == 2 : filtered . extend ( ids ) return set ( filtered ) | 167 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/filter_fastq_sam.py#L41-L56 | [
"def",
"_retry_until_powered_on",
"(",
"self",
",",
"power",
")",
":",
"# If the system is in the same power state as",
"# requested by the user, it gives the error",
"# InvalidOperationForSystemState. To avoid this error",
"# the power state is checked before power on",
"# operation is perf... |
print fastq from sam | def sam2fastq ( line ) : fastq = [ ] fastq . append ( '@%s' % line [ 0 ] ) fastq . append ( line [ 9 ] ) fastq . append ( '+%s' % line [ 0 ] ) fastq . append ( line [ 10 ] ) return fastq | 168 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/mapped.py#L13-L22 | [
"def",
"_createDatabase",
"(",
"self",
")",
":",
"# create experiment metadata table",
"command",
"=",
"\"\"\"\n CREATE TABLE {tn} (\n {k} INT PRIMARY KEY NOT NULL,\n START_TIME INT NOT NULL,\n END_TIM... |
- check to see if the read maps with < = threshold number of mismatches - mm_option = one or both depending on whether or not one or both reads in a pair need to pass the mismatch threshold - pair can be False if read does not have a pair - make sure alignment score is not 0 which would indicate that the read was not a... | def check_mismatches ( read , pair , mismatches , mm_option , req_map ) : # if read is not paired, make sure it is mapped and that mm <= thresh if pair is False : mm = count_mismatches ( read ) if mm is False : return False # if no threshold is supplied, return True if mismatches is False : return True # passes thresho... | 169 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/mapped.py#L36-L84 | [
"async",
"def",
"chain",
"(",
"*",
"sources",
")",
":",
"for",
"source",
"in",
"sources",
":",
"async",
"with",
"streamcontext",
"(",
"source",
")",
"as",
"streamer",
":",
"async",
"for",
"item",
"in",
"streamer",
":",
"yield",
"item"
] |
determine whether or not reads map to specific region of scaffold | def check_region ( read , pair , region ) : if region is False : return True for mapping in read , pair : if mapping is False : continue start , length = int ( mapping [ 3 ] ) , len ( mapping [ 9 ] ) r = [ start , start + length - 1 ] if get_overlap ( r , region ) > 0 : return True return False | 170 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/mapped.py#L92-L105 | [
"def",
"Run",
"(",
"self",
")",
":",
"global",
"DB",
"# pylint: disable=global-statement",
"global",
"REL_DB",
"# pylint: disable=global-statement",
"global",
"BLOBS",
"# pylint: disable=global-statement",
"if",
"flags",
".",
"FLAGS",
".",
"list_storage",
":",
"self",
"... |
Returns a Steam object representing the current Steam installation on the users computer . If the user doesn t have Steam installed returns None . | def get_steam ( ) : # Helper function which checks if the potential userdata directory exists # and returns a new Steam instance with that userdata directory if it does. # If the directory doesnt exist it returns None instead helper = lambda udd : Steam ( udd ) if os . path . exists ( udd ) else None # For both OS X an... | 171 | https://github.com/scottrice/pysteam/blob/1eb2254b5235a053a953e596fa7602d0b110245d/pysteam/steam.py#L12-L43 | [
"def",
"delete_binding",
"(",
"self",
",",
"vhost",
",",
"exchange",
",",
"queue",
",",
"rt_key",
")",
":",
"vhost",
"=",
"quote",
"(",
"vhost",
",",
"''",
")",
"exchange",
"=",
"quote",
"(",
"exchange",
",",
"''",
")",
"queue",
"=",
"quote",
"(",
... |
normalize from zero to one for row or table | def zero_to_one ( table , option ) : if option == 'table' : m = min ( min ( table ) ) ma = max ( max ( table ) ) t = [ ] for row in table : t_row = [ ] if option != 'table' : m , ma = min ( row ) , max ( row ) for i in row : if ma == m : t_row . append ( 0 ) else : t_row . append ( ( i - m ) / ( ma - m ) ) t . append (... | 172 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L18-L36 | [
"def",
"create_stream_subscription",
"(",
"self",
",",
"stream",
",",
"on_data",
",",
"timeout",
"=",
"60",
")",
":",
"options",
"=",
"rest_pb2",
".",
"StreamSubscribeRequest",
"(",
")",
"options",
".",
"stream",
"=",
"stream",
"manager",
"=",
"WebSocketSubscr... |
calculate percent of total | def pertotal ( table , option ) : if option == 'table' : total = sum ( [ i for line in table for i in line ] ) t = [ ] for row in table : t_row = [ ] if option != 'table' : total = sum ( row ) for i in row : if total == 0 : t_row . append ( 0 ) else : t_row . append ( i / total * 100 ) t . append ( t_row ) return t | 173 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L38-L55 | [
"def",
"mod_repo",
"(",
"repo",
",",
"*",
"*",
"kwargs",
")",
":",
"repos",
"=",
"list_repos",
"(",
")",
"found",
"=",
"False",
"uri",
"=",
"''",
"if",
"'uri'",
"in",
"kwargs",
":",
"uri",
"=",
"kwargs",
"[",
"'uri'",
"]",
"for",
"repository",
"in"... |
scale table based on the column with the largest sum | def scale ( table ) : t = [ ] columns = [ [ ] for i in table [ 0 ] ] for row in table : for i , v in enumerate ( row ) : columns [ i ] . append ( v ) sums = [ float ( sum ( i ) ) for i in columns ] scale_to = float ( max ( sums ) ) scale_factor = [ scale_to / i for i in sums if i != 0 ] for row in table : t . append ( ... | 174 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L79-L93 | [
"def",
"disable_paging",
"(",
"self",
",",
"delay_factor",
"=",
"1",
")",
":",
"check_command",
"=",
"\"get system status | grep Virtual\"",
"output",
"=",
"self",
".",
"send_command_timing",
"(",
"check_command",
")",
"self",
".",
"allow_disable_global",
"=",
"True... |
fit to normal distribution | def norm ( table ) : print ( '# norm dist is broken' , file = sys . stderr ) exit ( ) from matplotlib . pyplot import hist as hist t = [ ] for i in table : t . append ( np . ndarray . tolist ( hist ( i , bins = len ( i ) , normed = True ) [ 0 ] ) ) return t | 175 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L95-L105 | [
"def",
"scan_posts",
"(",
"self",
",",
"really",
"=",
"True",
",",
"ignore_quit",
"=",
"False",
",",
"quiet",
"=",
"True",
")",
":",
"while",
"(",
"self",
".",
"db",
".",
"exists",
"(",
"'site:lock'",
")",
"and",
"int",
"(",
"self",
".",
"db",
".",... |
log transform each value in table | def log_trans ( table ) : t = [ ] all = [ item for sublist in table for item in sublist ] if min ( all ) == 0 : scale = min ( [ i for i in all if i != 0 ] ) * 10e-10 else : scale = 0 for i in table : t . append ( np . ndarray . tolist ( np . log10 ( [ j + scale for j in i ] ) ) ) return t | 176 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L107-L119 | [
"def",
"update_dvportgroup",
"(",
"portgroup_ref",
",",
"spec",
")",
":",
"pg_name",
"=",
"get_managed_object_name",
"(",
"portgroup_ref",
")",
"log",
".",
"trace",
"(",
"'Updating portgrouo %s'",
",",
"pg_name",
")",
"try",
":",
"task",
"=",
"portgroup_ref",
".... |
box - cox transform table | def box_cox ( table ) : from scipy . stats import boxcox as bc t = [ ] for i in table : if min ( i ) == 0 : scale = min ( [ j for j in i if j != 0 ] ) * 10e-10 else : scale = 0 t . append ( np . ndarray . tolist ( bc ( np . array ( [ j + scale for j in i ] ) ) [ 0 ] ) ) return t | 177 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L121-L133 | [
"def",
"users",
"(",
"self",
",",
"start",
"=",
"1",
",",
"num",
"=",
"10",
",",
"sortField",
"=",
"\"fullName\"",
",",
"sortOrder",
"=",
"\"asc\"",
",",
"role",
"=",
"None",
")",
":",
"users",
"=",
"[",
"]",
"url",
"=",
"self",
".",
"_url",
"+",... |
inverse hyperbolic sine transformation | def inh ( table ) : t = [ ] for i in table : t . append ( np . ndarray . tolist ( np . arcsinh ( i ) ) ) return t | 178 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L135-L142 | [
"def",
"_index_audio_cmu",
"(",
"self",
",",
"basename",
"=",
"None",
",",
"replace_already_indexed",
"=",
"False",
")",
":",
"self",
".",
"_prepare_audio",
"(",
"basename",
"=",
"basename",
",",
"replace_already_indexed",
"=",
"replace_already_indexed",
")",
"for... |
from SparCC - randomly draw from the corresponding posterior Dirichlet distribution with a uniform prior | def diri ( table ) : t = [ ] for i in table : a = [ j + 1 for j in i ] t . append ( np . ndarray . tolist ( np . random . mtrand . dirichlet ( a ) ) ) return t | 179 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/transform.py#L144-L153 | [
"def",
"_ParseKeysFromFindSpecs",
"(",
"self",
",",
"parser_mediator",
",",
"win_registry",
",",
"find_specs",
")",
":",
"searcher",
"=",
"dfwinreg_registry_searcher",
".",
"WinRegistrySearcher",
"(",
"win_registry",
")",
"for",
"registry_key_path",
"in",
"iter",
"(",... |
Given a list of sample IDs generate unique n - base barcodes for each . Note that only 4^n unique barcodes are possible . | def generate_barcodes ( nIds , codeLen = 12 ) : def next_code ( b , c , i ) : return c [ : i ] + b + ( c [ i + 1 : ] if i < - 1 else '' ) def rand_base ( ) : return random . choice ( [ 'A' , 'T' , 'C' , 'G' ] ) def rand_seq ( n ) : return '' . join ( [ rand_base ( ) for _ in range ( n ) ] ) # homopolymer filter regex: ... | 180 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/sanger_qiimify.py#L94-L128 | [
"def",
"_optimize_providers",
"(",
"self",
",",
"providers",
")",
":",
"new_providers",
"=",
"{",
"}",
"provider_by_driver",
"=",
"{",
"}",
"for",
"alias",
",",
"driver",
"in",
"six",
".",
"iteritems",
"(",
"providers",
")",
":",
"for",
"name",
",",
"dat... |
Given a sample ID and a mapping modify a Sanger FASTA file to include the barcode and primer in the sequence data and change the description line as needed . | def scrobble_data_dir ( dataDir , sampleMap , outF , qualF = None , idopt = None , utf16 = False ) : seqcount = 0 outfiles = [ osp . split ( outF . name ) [ 1 ] ] if qualF : outfiles . append ( osp . split ( qualF . name ) [ 1 ] ) for item in os . listdir ( dataDir ) : if item in outfiles or not osp . isfile ( os . pat... | 181 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/sanger_qiimify.py#L158-L199 | [
"def",
"num_fails",
"(",
"self",
")",
":",
"n",
"=",
"len",
"(",
"self",
".",
"failed_phase_list",
")",
"if",
"self",
".",
"phase_stack",
"[",
"-",
"1",
"]",
".",
"status",
"in",
"(",
"SolverStatus",
".",
"failed",
",",
"SolverStatus",
".",
"cyclic",
... |
Uses the built - in argparse module to handle command - line options for the program . | def handle_program_options ( ) : parser = argparse . ArgumentParser ( description = "Convert Sanger-sequencing \
derived data files for use with the \
metagenomics analysis program QIIME, by \
extracting Sampl... | 182 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/sanger_qiimify.py#L202-L271 | [
"def",
"checkIsConsistent",
"(",
"self",
")",
":",
"if",
"is_an_array",
"(",
"self",
".",
"mask",
")",
"and",
"self",
".",
"mask",
".",
"shape",
"!=",
"self",
".",
"data",
".",
"shape",
":",
"raise",
"ConsistencyError",
"(",
"\"Shape mismatch mask={}, data={... |
Applies the arcsine square root transform to the given BIOM - format table | def arcsin_sqrt ( biom_tbl ) : arcsint = lambda data , id_ , md : np . arcsin ( np . sqrt ( data ) ) tbl_relabd = relative_abd ( biom_tbl ) tbl_asin = tbl_relabd . transform ( arcsint , inplace = False ) return tbl_asin | 183 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/transform_biom.py#L78-L88 | [
"def",
"create_reservation",
"(",
"self",
",",
"username",
",",
"domain",
",",
"email",
"=",
"None",
")",
":",
"password",
"=",
"self",
".",
"get_random_password",
"(",
")",
"self",
".",
"create",
"(",
"username",
"=",
"username",
",",
"domain",
"=",
"do... |
parse sam file and check mapping quality | def parse_sam ( sam , qual ) : for line in sam : if line . startswith ( '@' ) : continue line = line . strip ( ) . split ( ) if int ( line [ 4 ] ) == 0 or int ( line [ 4 ] ) < qual : continue yield line | 184 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L23-L33 | [
"def",
"_parse_box_list",
"(",
"self",
",",
"output",
")",
":",
"# Parse box list output",
"boxes",
"=",
"[",
"]",
"# initialize box values",
"name",
"=",
"provider",
"=",
"version",
"=",
"None",
"for",
"timestamp",
",",
"target",
",",
"kind",
",",
"data",
"... |
reverse completement stats | def rc_stats ( stats ) : rc_nucs = { 'A' : 'T' , 'T' : 'A' , 'G' : 'C' , 'C' : 'G' , 'N' : 'N' } rcs = [ ] for pos in reversed ( stats ) : rc = { } rc [ 'reference frequencey' ] = pos [ 'reference frequency' ] rc [ 'consensus frequencey' ] = pos [ 'consensus frequency' ] rc [ 'In' ] = pos [ 'In' ] rc [ 'Del' ] = pos [ ... | 185 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L138-L156 | [
"def",
"load_projects",
"(",
"self",
")",
":",
"server_config",
"=",
"Config",
".",
"instance",
"(",
")",
".",
"get_section_config",
"(",
"\"Server\"",
")",
"projects_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"server_config",
".",
"get",
"(",
... |
parse codon nucleotide positions in range start - > end wrt strand | def parse_codons ( ref , start , end , strand ) : codon = [ ] c = cycle ( [ 1 , 2 , 3 ] ) ref = ref [ start - 1 : end ] if strand == - 1 : ref = rc_stats ( ref ) for pos in ref : n = next ( c ) codon . append ( pos ) if n == 3 : yield codon codon = [ ] | 186 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L158-L172 | [
"def",
"dump",
"(",
"self",
")",
":",
"data",
"=",
"dict",
"(",
"# Sessions",
"sessions_active",
"=",
"self",
".",
"sess_active",
",",
"# Connections",
"connections_active",
"=",
"self",
".",
"conn_active",
",",
"connections_ps",
"=",
"self",
".",
"conn_ps",
... |
calculate coverage for positions in range start - > end | def calc_coverage ( ref , start , end , length , nucs ) : ref = ref [ start - 1 : end ] bases = 0 for pos in ref : for base , count in list ( pos . items ( ) ) : if base in nucs : bases += count return float ( bases ) / float ( length ) | 187 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L174-L184 | [
"def",
"catalogFactory",
"(",
"name",
",",
"*",
"*",
"kwargs",
")",
":",
"fn",
"=",
"lambda",
"member",
":",
"inspect",
".",
"isclass",
"(",
"member",
")",
"and",
"member",
".",
"__module__",
"==",
"__name__",
"catalogs",
"=",
"odict",
"(",
"inspect",
... |
parse gbk file | def parse_gbk ( gbks ) : for gbk in gbks : for record in SeqIO . parse ( open ( gbk ) , 'genbank' ) : for feature in record . features : if feature . type == 'gene' : try : locus = feature . qualifiers [ 'locus_tag' ] [ 0 ] except : continue if feature . type == 'CDS' : try : locus = feature . qualifiers [ 'locus_tag' ... | 188 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L186-L213 | [
"def",
"indication",
"(",
"self",
",",
"apdu",
")",
":",
"if",
"_debug",
":",
"ServerSSM",
".",
"_debug",
"(",
"\"indication %r\"",
",",
"apdu",
")",
"if",
"self",
".",
"state",
"==",
"IDLE",
":",
"self",
".",
"idle",
"(",
"apdu",
")",
"elif",
"self"... |
parse gene call information from Prodigal fasta output | def parse_fasta_annotations ( fastas , annot_tables , trans_table ) : if annot_tables is not False : annots = { } for table in annot_tables : for cds in open ( table ) : ID , start , end , strand = cds . strip ( ) . split ( ) annots [ ID ] = [ start , end , int ( strand ) ] for fasta in fastas : for seq in parse_fasta ... | 189 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L215-L252 | [
"def",
"initialize_communities_bucket",
"(",
")",
":",
"bucket_id",
"=",
"UUID",
"(",
"current_app",
".",
"config",
"[",
"'COMMUNITIES_BUCKET_UUID'",
"]",
")",
"if",
"Bucket",
".",
"query",
".",
"get",
"(",
"bucket_id",
")",
":",
"raise",
"FilesException",
"("... |
parse annotations in either gbk or Prodigal fasta format | def parse_annotations ( annots , fmt , annot_tables , trans_table ) : annotations = { } # annotations[contig] = [features] # gbk format if fmt is False : for contig , feature in parse_gbk ( annots ) : if contig not in annotations : annotations [ contig ] = [ ] annotations [ contig ] . append ( feature ) # fasta format ... | 190 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L254-L271 | [
"def",
"delayed_close",
"(",
"self",
")",
":",
"self",
".",
"state",
"=",
"SESSION_STATE",
".",
"CLOSING",
"reactor",
".",
"callLater",
"(",
"0",
",",
"self",
".",
"close",
")"
] |
convert codon to amino acid | def codon2aa ( codon , trans_table ) : return Seq ( '' . join ( codon ) , IUPAC . ambiguous_dna ) . translate ( table = trans_table ) [ 0 ] | 191 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L311-L315 | [
"def",
"process_config",
"(",
"config",
",",
"config_data",
")",
":",
"if",
"'components'",
"in",
"config_data",
":",
"process_components_config_section",
"(",
"config",
",",
"config_data",
"[",
"'components'",
"]",
")",
"if",
"'data'",
"in",
"config_data",
":",
... |
find consensus base based on nucleotide frequencies | def find_consensus ( bases ) : nucs = [ 'A' , 'T' , 'G' , 'C' , 'N' ] total = sum ( [ bases [ nuc ] for nuc in nucs if nuc in bases ] ) # save most common base as consensus (random nuc if there is a tie) try : top = max ( [ bases [ nuc ] for nuc in nucs if nuc in bases ] ) except : bases [ 'consensus' ] = ( 'N' , 'n/a'... | 192 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L371-L402 | [
"def",
"_create_download_failed_message",
"(",
"exception",
",",
"url",
")",
":",
"message",
"=",
"'Failed to download from:\\n{}\\nwith {}:\\n{}'",
".",
"format",
"(",
"url",
",",
"exception",
".",
"__class__",
".",
"__name__",
",",
"exception",
")",
"if",
"_is_tem... |
print consensensus sequences for each genome and sample | def print_consensus ( genomes ) : # generate consensus sequences cons = { } # cons[genome][sample][contig] = consensus for genome , contigs in list ( genomes . items ( ) ) : cons [ genome ] = { } for contig , samples in list ( contigs . items ( ) ) : for sample , stats in list ( samples . items ( ) ) : if sample not in... | 193 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_variation.py#L451-L478 | [
"def",
"delete_datapoints_in_time_range",
"(",
"self",
",",
"start_dt",
"=",
"None",
",",
"end_dt",
"=",
"None",
")",
":",
"start_dt",
"=",
"to_none_or_dt",
"(",
"validate_type",
"(",
"start_dt",
",",
"datetime",
".",
"datetime",
",",
"type",
"(",
"None",
")... |
calculate genome coverage from scaffold coverage table | def parse_cov ( cov_table , scaffold2genome ) : size = { } # size[genome] = genome size mapped = { } # mapped[genome][sample] = mapped bases # parse coverage files for line in open ( cov_table ) : line = line . strip ( ) . split ( '\t' ) if line [ 0 ] . startswith ( '#' ) : samples = line [ 1 : ] samples = [ i . rsplit... | 194 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_coverage.py#L13-L50 | [
"def",
"get_api_v1_info",
"(",
"api_prefix",
")",
":",
"websocket_root",
"=",
"base_ws_uri",
"(",
")",
"+",
"EVENTS_ENDPOINT",
"docs_url",
"=",
"[",
"'https://docs.bigchaindb.com/projects/server/en/v'",
",",
"version",
".",
"__version__",
",",
"'/http-client-server-api.ht... |
calculate genome coverage from scaffold coverage | def genome_coverage ( covs , s2b ) : COV = [ ] for cov in covs : COV . append ( parse_cov ( cov , s2b ) ) return pd . concat ( COV ) | 195 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_coverage.py#L52-L59 | [
"def",
"on_websocket_message",
"(",
"message",
":",
"str",
")",
"->",
"None",
":",
"msgs",
"=",
"json",
".",
"loads",
"(",
"message",
")",
"for",
"msg",
"in",
"msgs",
":",
"if",
"not",
"isinstance",
"(",
"msg",
",",
"dict",
")",
":",
"logger",
".",
... |
convert s2b files to dictionary | def parse_s2bs ( s2bs ) : s2b = { } for s in s2bs : for line in open ( s ) : line = line . strip ( ) . split ( '\t' ) s , b = line [ 0 ] , line [ 1 ] s2b [ s ] = b return s2b | 196 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_coverage.py#L61-L71 | [
"def",
"surrounding_nodes",
"(",
"self",
",",
"position",
")",
":",
"n_node_index",
",",
"n_node_position",
",",
"n_node_error",
"=",
"self",
".",
"nearest_node",
"(",
"position",
")",
"if",
"n_node_error",
"==",
"0.0",
":",
"index_mod",
"=",
"[",
"]",
"for"... |
convert fastas to s2b dictionary | def fa2s2b ( fastas ) : s2b = { } for fa in fastas : for seq in parse_fasta ( fa ) : s = seq [ 0 ] . split ( '>' , 1 ) [ 1 ] . split ( ) [ 0 ] s2b [ s ] = fa . rsplit ( '/' , 1 ) [ - 1 ] . rsplit ( '.' , 1 ) [ 0 ] return s2b | 197 | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/genome_coverage.py#L73-L82 | [
"def",
"BuildChecks",
"(",
"self",
",",
"request",
")",
":",
"result",
"=",
"[",
"]",
"if",
"request",
".",
"HasField",
"(",
"\"start_time\"",
")",
"or",
"request",
".",
"HasField",
"(",
"\"end_time\"",
")",
":",
"def",
"FilterTimestamp",
"(",
"file_stat",... |
Filters out sequences with too much ambiguity as defined by the method parameters . | def filter_ambiguity ( records , percent = 0.5 ) : # , repeats=6) seqs = [ ] # Ns = ''.join(['N' for _ in range(repeats)]) count = 0 for record in records : if record . seq . count ( 'N' ) / float ( len ( record ) ) < percent : # pos = record.seq.find(Ns) # if pos >= 0: # record.seq... | 198 | https://github.com/smdabdoub/phylotoast/blob/0b74ef171e6a84761710548501dfac71285a58a3/bin/filter_ambiguity.py#L16-L41 | [
"def",
"delete_datapoint",
"(",
"self",
",",
"datapoint",
")",
":",
"datapoint",
"=",
"validate_type",
"(",
"datapoint",
",",
"DataPoint",
")",
"self",
".",
"_conn",
".",
"delete",
"(",
"\"/ws/DataPoint/{stream_id}/{datapoint_id}\"",
".",
"format",
"(",
"stream_id... |
Search package . | def package_existent ( name ) : try : response = requests . get ( PYPI_URL . format ( name ) ) if response . ok : msg = ( '[error] "{0}" is registered already in PyPI.\n' '\tSpecify another package name.' ) . format ( name ) raise Conflict ( msg ) except ( socket . gaierror , Timeout , ConnectionError , HTTPError ) as ... | 199 | https://github.com/mkouhei/bootstrap-py/blob/95d56ed98ef409fd9f019dc352fd1c3711533275/bootstrap_py/pypi.py#L12-L33 | [
"def",
"_add_dependency",
"(",
"self",
",",
"dependency",
",",
"var_name",
"=",
"None",
")",
":",
"if",
"var_name",
"is",
"None",
":",
"var_name",
"=",
"next",
"(",
"self",
".",
"temp_var_names",
")",
"# Don't add duplicate dependencies",
"if",
"(",
"dependenc... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.