idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
28,900 | def resname_in_proximity ( resname , model , chains , resnums , threshold = 5 ) : residues = [ r for r in model . get_residues ( ) if r . get_resname ( ) == resname ] chains = ssbio . utils . force_list ( chains ) resnums = ssbio . utils . force_list ( resnums ) for chain in chains : for resnum in resnums : my_residue_... | Search within the proximity of a defined list of residue numbers and their chains for any specifed residue name . |
28,901 | def match_structure_sequence ( orig_seq , new_seq , match = 'X' , fill_with = 'X' , ignore_excess = False ) : if len ( orig_seq ) == len ( new_seq ) : log . debug ( 'Lengths already equal, nothing to fill in' ) return new_seq if not ignore_excess : if len ( orig_seq ) < len ( new_seq ) : raise ValueError ( 'Original se... | Correct a sequence to match inserted X s in a structure sequence |
28,902 | def manual_get_pfam_annotations ( seq , outpath , searchtype = 'phmmer' , force_rerun = False ) : if op . exists ( outpath ) : with open ( outpath , 'r' ) as f : json_results = json . loads ( json . load ( f ) ) else : fseq = '>Seq\n' + seq if searchtype == 'phmmer' : parameters = { 'seqdb' : 'pdb' , 'seq' : fseq } if ... | Retrieve and download PFAM results from the HMMER search tool . |
28,903 | def is_ipynb ( ) : try : shell = get_ipython ( ) . __class__ . __name__ if shell == 'ZMQInteractiveShell' : return True elif shell == 'TerminalInteractiveShell' : return False else : return False except NameError : return False | Return True if the module is running in IPython kernel False if in IPython shell or other Python shell . |
28,904 | def clean_single_dict ( indict , prepend_to_keys = None , remove_keys_containing = None ) : if not prepend_to_keys : prepend_to_keys = '' outdict = { } for k , v in indict . items ( ) : if remove_keys_containing : if remove_keys_containing in k : continue outdict [ prepend_to_keys + k ] = v [ 0 ] return outdict | Clean a dict with values that contain single item iterators to single items |
28,905 | def double_check_attribute ( object , setter , backup_attribute , custom_error_text = None ) : if not setter : next_checker = getattr ( object , backup_attribute ) if not next_checker : if custom_error_text : raise ValueError ( custom_error_text ) else : raise ValueError ( 'Attribute replacing "{}" must be specified' .... | Check if a parameter to be used is None if it is then check the specified backup attribute and throw an error if it is also None . |
28,906 | def split_folder_and_path ( filepath ) : dirname = op . dirname ( filepath ) filename = op . basename ( filepath ) splitext = op . splitext ( filename ) filename_without_extension = splitext [ 0 ] extension = splitext [ 1 ] return dirname , filename_without_extension , extension | Split a file path into its folder filename and extension |
28,907 | def outfile_maker ( inname , outext = '.out' , outname = '' , outdir = '' , append_to_name = '' ) : orig_dir , orig_name , orig_ext = split_folder_and_path ( inname ) if not outname : outname = orig_name if not outdir : outdir = orig_dir if append_to_name : outname += append_to_name final_outfile = op . join ( outdir ,... | Create a default name for an output file based on the inname name unless a output name is specified . |
28,908 | def force_rerun ( flag , outfile ) : if flag : return True elif not flag and not op . exists ( outfile ) : return True elif not flag and not is_non_zero_file ( outfile ) : return True else : return False | Check if we should force rerunning of a command if an output file exists . |
28,909 | def gunzip_file ( infile , outfile = None , outdir = None , delete_original = False , force_rerun_flag = False ) : if not outfile : outfile = infile . replace ( '.gz' , '' ) if not outdir : outdir = '' else : outdir = op . dirname ( infile ) outfile = op . join ( outdir , op . basename ( outfile ) ) if force_rerun ( fl... | Decompress a gzip file and optionally set output values . |
28,910 | def request_file ( link , outfile , force_rerun_flag = False ) : if force_rerun ( flag = force_rerun_flag , outfile = outfile ) : req = requests . get ( link ) if req . status_code == 200 : with open ( outfile , 'w' ) as f : f . write ( req . text ) log . debug ( 'Loaded and saved {} to {}' . format ( link , outfile ) ... | Download a file given a URL if the outfile does not exist already . |
28,911 | def request_json ( link , outfile , force_rerun_flag , outdir = None ) : if not outdir : outdir = '' outfile = op . join ( outdir , outfile ) if force_rerun ( flag = force_rerun_flag , outfile = outfile ) : text_raw = requests . get ( link ) my_dict = text_raw . json ( ) with open ( outfile , 'w' ) as f : json . dump (... | Download a file in JSON format from a web request |
28,912 | def command_runner ( shell_command , force_rerun_flag , outfile_checker , cwd = None , silent = False ) : program_and_args = shlex . split ( shell_command ) if not program_exists ( program_and_args [ 0 ] ) : raise OSError ( '{}: program not installed' . format ( program_and_args [ 0 ] ) ) if cwd : outfile_checker = op ... | Run a shell command with subprocess with additional options to check if output file exists and printing stdout . |
28,913 | def dict_head ( d , N = 5 ) : return { k : d [ k ] for k in list ( d . keys ( ) ) [ : N ] } | Return the head of a dictionary . It will be random! |
28,914 | def rank_dated_files ( pattern , dir , descending = True ) : files = glob . glob ( op . join ( dir , pattern ) ) return sorted ( files , reverse = descending ) | Search a directory for files that match a pattern . Return an ordered list of these files by filename . |
28,915 | def find ( lst , a , case_sensitive = True ) : a = force_list ( a ) if not case_sensitive : lst = [ x . lower ( ) for x in lst ] a = [ y . lower ( ) for y in a ] return [ i for i , x in enumerate ( lst ) if x in a ] | Return indices of a list which have elements that match an object or list of objects |
28,916 | def filter_list ( lst , takeout , case_sensitive = True ) : takeout = force_list ( takeout ) if not case_sensitive : lst = [ x . lower ( ) for x in lst ] takeout = [ y . lower ( ) for y in takeout ] return [ x for x in lst if x not in takeout ] | Return a modified list removing items specified . |
28,917 | def filter_list_by_indices ( lst , indices ) : return [ x for i , x in enumerate ( lst ) if i in indices ] | Return a modified list containing only the indices indicated . |
28,918 | def force_string ( val = None ) : if val is None : return '' if isinstance ( val , list ) : newval = [ str ( x ) for x in val ] return ';' . join ( newval ) if isinstance ( val , str ) : return val else : return str ( val ) | Force a string representation of an object |
28,919 | def force_list ( val = None ) : if val is None : return [ ] if isinstance ( val , pd . Series ) : return val . tolist ( ) return val if isinstance ( val , list ) else [ val ] | Force a list representation of an object |
28,920 | def split_list_by_n ( l , n ) : n = max ( 1 , n ) return list ( l [ i : i + n ] for i in range ( 0 , len ( l ) , n ) ) | Split a list into lists of size n . |
28,921 | def input_list_parser ( infile_list ) : final_list_of_files = [ ] for x in infile_list : if op . isdir ( x ) : os . chdir ( x ) final_list_of_files . extend ( glob . glob ( '*' ) ) if op . isfile ( x ) : final_list_of_files . append ( x ) return final_list_of_files | Always return a list of files with varying input . |
28,922 | def flatlist_dropdup ( list_of_lists ) : return list ( set ( [ str ( item ) for sublist in list_of_lists for item in sublist ] ) ) | Make a single list out of a list of lists and drop all duplicates . |
28,923 | def scale_calculator ( multiplier , elements , rescale = None ) : if isinstance ( elements , list ) : unique_elements = list ( set ( elements ) ) scales = { } for x in unique_elements : count = elements . count ( x ) scales [ x ] = multiplier * count elif isinstance ( elements , dict ) : scales = { } for k , count in e... | Get a dictionary of scales for each element in elements . |
28,924 | def label_sequential_regions ( inlist ) : import more_itertools as mit df = pd . DataFrame ( inlist ) . set_index ( 0 ) labeled = { } for label in df [ 1 ] . unique ( ) : iterable = df [ df [ 1 ] == label ] . index . tolist ( ) labeled . update ( { '{}{}' . format ( label , i + 1 ) : items for i , items in enumerate ( ... | Input a list of labeled tuples and return a dictionary of sequentially labeled regions . |
28,925 | def sequence_path ( self , fasta_path ) : if not fasta_path : self . sequence_dir = None self . sequence_file = None else : if not op . exists ( fasta_path ) : raise OSError ( '{}: file does not exist' . format ( fasta_path ) ) if not op . dirname ( fasta_path ) : self . sequence_dir = '.' else : self . sequence_dir = ... | Provide pointers to the paths of the FASTA file |
28,926 | def feature_path ( self , gff_path ) : if not gff_path : self . feature_dir = None self . feature_file = None else : if not op . exists ( gff_path ) : raise OSError ( '{}: file does not exist!' . format ( gff_path ) ) if not op . dirname ( gff_path ) : self . feature_dir = '.' else : self . feature_dir = op . dirname (... | Load a GFF file with information on a single sequence and store features in the features attribute |
28,927 | def feature_path_unset ( self ) : if not self . feature_file : raise IOError ( 'No feature file to unset' ) with open ( self . feature_path ) as handle : feats = list ( GFF . parse ( handle ) ) if len ( feats ) > 1 : log . warning ( 'Too many sequences in GFF' ) else : tmp = feats [ 0 ] . features self . feature_dir = ... | Copy features to memory and remove the association of the feature file . |
28,928 | def get_dict ( self , only_attributes = None , exclude_attributes = None , df_format = False ) : if not only_attributes : keys = list ( self . __dict__ . keys ( ) ) else : keys = ssbio . utils . force_list ( only_attributes ) if exclude_attributes : exclude_attributes = ssbio . utils . force_list ( exclude_attributes )... | Get a dictionary of this object s attributes . Optional format for storage in a Pandas DataFrame . |
28,929 | def equal_to ( self , seq_prop ) : if not self . seq or not seq_prop or not seq_prop . seq : return False return self . seq == seq_prop . seq | Test if the sequence is equal to another SeqProp s sequence |
28,930 | def write_fasta_file ( self , outfile , force_rerun = False ) : if ssbio . utils . force_rerun ( flag = force_rerun , outfile = outfile ) : SeqIO . write ( self , outfile , "fasta" ) self . sequence_path = outfile | Write a FASTA file for the protein sequence seq will now load directly from this file . |
28,931 | def write_gff_file ( self , outfile , force_rerun = False ) : if ssbio . utils . force_rerun ( outfile = outfile , flag = force_rerun ) : with open ( outfile , "w" ) as out_handle : GFF . write ( [ self ] , out_handle ) self . feature_path = outfile | Write a GFF file for the protein features features will now load directly from this file . |
28,932 | def add_point_feature ( self , resnum , feat_type = None , feat_id = None , qualifiers = None ) : if self . feature_file : raise ValueError ( 'Feature file associated with sequence, please remove file association to append ' 'additional features.' ) if not feat_type : feat_type = 'Manually added protein sequence single... | Add a feature to the features list describing a single residue . |
28,933 | def add_region_feature ( self , start_resnum , end_resnum , feat_type = None , feat_id = None , qualifiers = None ) : if self . feature_file : raise ValueError ( 'Feature file associated with sequence, please remove file association to append ' 'additional features.' ) if not feat_type : feat_type = 'Manually added pro... | Add a feature to the features list describing a region of the protein sequence . |
28,934 | def get_subsequence ( self , resnums , new_id = None , copy_letter_annotations = True ) : biop_compound_list = [ ] for resnum in resnums : feat = FeatureLocation ( resnum - 1 , resnum ) biop_compound_list . append ( feat ) if len ( biop_compound_list ) == 0 : log . debug ( 'Zero length subsequence' ) return elif len ( ... | Get a subsequence as a new SeqProp object given a list of residue numbers |
28,935 | def get_subsequence_from_property ( self , property_key , property_value , condition , return_resnums = False , copy_letter_annotations = True ) : if property_key not in self . letter_annotations : log . error ( '{}: {} not contained in the letter annotations' . format ( self . id , property_key ) ) return if condition... | Get a subsequence as a new SeqProp object given a certain property you want to find in the original SeqProp s letter_annotation |
28,936 | def get_biopython_pepstats ( self , clean_seq = False ) : if self . seq : if clean_seq : seq = self . seq_str . replace ( 'X' , '' ) . replace ( 'U' , '' ) else : seq = self . seq_str try : pepstats = ssbio . protein . sequence . properties . residues . biopython_protein_analysis ( seq ) except KeyError as e : log . er... | Run Biopython s built in ProteinAnalysis module and store statistics in the annotations attribute . |
28,937 | def get_emboss_pepstats ( self ) : if not self . sequence_file : raise IOError ( 'FASTA file needs to be written for EMBOSS pepstats to be run' ) outfile = ssbio . protein . sequence . properties . residues . emboss_pepstats_on_fasta ( infile = self . sequence_path ) pepstats = ssbio . protein . sequence . properties .... | Run the EMBOSS pepstats program on the protein sequence . |
28,938 | def get_sliding_window_properties ( self , scale , window ) : if self . seq : try : prop = ssbio . protein . sequence . properties . residues . biopython_protein_scale ( self . seq_str , scale = scale , window = window ) except KeyError as e : log . error ( '{}: unable to run ProteinAnalysis module, unknown amino acid ... | Run a property calculator given a sliding window size |
28,939 | def blast_pdb ( self , seq_ident_cutoff = 0 , evalue = 0.0001 , display_link = False , outdir = None , force_rerun = False ) : if not outdir : outdir = self . sequence_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) if not self . seq_str : log . error ( '{}: no sequence loaded' . format ( ... | BLAST this sequence to the PDB |
28,940 | def get_residue_annotations ( self , start_resnum , end_resnum = None ) : if not end_resnum : end_resnum = start_resnum f = SeqFeature ( FeatureLocation ( start_resnum - 1 , end_resnum ) ) return f . extract ( self ) . letter_annotations | Retrieve letter annotations for a residue or a range of residues |
28,941 | def get_aggregation_propensity ( self , email , password , cutoff_v = 5 , cutoff_n = 5 , run_amylmuts = False , outdir = None ) : if not outdir : outdir = self . sequence_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) import ssbio . protein . sequence . properties . aggregation_propensity... | Run the AMYLPRED2 web server to calculate the aggregation propensity of this protein sequence which is the number of aggregation - prone segments on the unfolded protein sequence . |
28,942 | def get_thermostability ( self , at_temp ) : import ssbio . protein . sequence . properties . thermostability as ts dG = ts . get_dG_at_T ( seq = self , temp = at_temp ) self . annotations [ 'thermostability_{}_C-{}' . format ( at_temp , dG [ 2 ] . lower ( ) ) ] = ( dG [ 0 ] , dG [ 1 ] ) | Run the thermostability calculator using either the Dill or Oobatake methods . |
28,943 | def store_iupred_disorder_predictions ( seqprop , iupred_path , iupred_exec , prediction_type , force_rerun = False ) : os . environ [ 'IUPred_PATH' ] = iupred_path stored_key = 'disorder-{}-iupred' . format ( prediction_type ) if stored_key not in seqprop . letter_annotations or force_rerun : if not seqprop . sequence... | Scores above 0 . 5 indicate disorder |
28,944 | def run_scratch ( self , path_to_scratch , num_cores = 1 , outname = None , outdir = None , force_rerun = False ) : if not outname : outname = self . project_name if not outdir : outdir = '' outname = op . join ( outdir , outname ) self . out_sspro = '{}.ss' . format ( outname ) self . out_sspro8 = '{}.ss8' . format ( ... | Run SCRATCH on the sequence_file that was loaded into the class . |
28,945 | def sspro_results ( self ) : return ssbio . protein . sequence . utils . fasta . load_fasta_file_as_dict_of_seqs ( self . out_sspro ) | Parse the SSpro output file and return a dict of secondary structure compositions . |
28,946 | def sspro_summary ( self ) : summary = { } records = ssbio . protein . sequence . utils . fasta . load_fasta_file ( self . out_sspro ) for r in records : seq_summary = { } seq_summary [ 'percent_H-sspro' ] = r . seq . count ( 'H' ) / float ( len ( r ) ) seq_summary [ 'percent_E-sspro' ] = r . seq . count ( 'E' ) / floa... | Parse the SSpro output file and return a summary of secondary structure composition . |
28,947 | def sspro8_results ( self ) : return ssbio . protein . sequence . utils . fasta . load_fasta_file_as_dict_of_seqs ( self . out_sspro8 ) | Parse the SSpro8 output file and return a dict of secondary structure compositions . |
28,948 | def sspro8_summary ( self ) : summary = { } records = ssbio . protein . sequence . utils . fasta . load_fasta_file ( self . out_sspro8 ) for r in records : seq_summary = { } seq_summary [ 'percent_H-sspro8' ] = r . seq . count ( 'H' ) / float ( len ( r ) ) seq_summary [ 'percent_G-sspro8' ] = r . seq . count ( 'G' ) / ... | Parse the SSpro8 output file and return a summary of secondary structure composition . |
28,949 | def accpro_results ( self ) : return ssbio . protein . sequence . utils . fasta . load_fasta_file_as_dict_of_seqs ( self . out_accpro ) | Parse the ACCpro output file and return a dict of secondary structure compositions . |
28,950 | def model_loader ( gem_file_path , gem_file_type ) : if gem_file_type . lower ( ) == 'xml' or gem_file_type . lower ( ) == 'sbml' : model = read_sbml_model ( gem_file_path ) elif gem_file_type . lower ( ) == 'mat' : model = load_matlab_model ( gem_file_path ) elif gem_file_type . lower ( ) == 'json' : model = load_json... | Consolidated function to load a GEM using COBRApy . Specify the file type being loaded . |
28,951 | def filter_out_spontaneous_genes ( genes , custom_spont_id = None ) : new_genes = DictList ( ) for gene in genes : if not is_spontaneous ( gene , custom_id = custom_spont_id ) : new_genes . append ( gene ) return new_genes | Return the DictList of genes that are not spontaneous in a model . |
28,952 | def true_num_genes ( model , custom_spont_id = None ) : true_num = 0 for gene in model . genes : if not is_spontaneous ( gene , custom_id = custom_spont_id ) : true_num += 1 return true_num | Return the number of genes in a model ignoring spontaneously labeled genes . |
28,953 | def true_num_reactions ( model , custom_spont_id = None ) : true_num = 0 for rxn in model . reactions : if len ( rxn . genes ) == 0 : continue if len ( rxn . genes ) == 1 and is_spontaneous ( list ( rxn . genes ) [ 0 ] , custom_id = custom_spont_id ) : continue else : true_num += 1 return true_num | Return the number of reactions associated with a gene . |
28,954 | def _smcra_to_str ( self , smcra , temp_dir = '/tmp/' ) : temp_path = tempfile . mktemp ( '.pdb' , dir = temp_dir ) io = PDBIO ( ) io . set_structure ( smcra ) io . save ( temp_path ) f = open ( temp_path , 'r' ) string = f . read ( ) f . close ( ) os . remove ( temp_path ) return string | WHATIF s input are PDB format files . Converts a SMCRA object to a PDB formatted string . |
28,955 | def is_alive ( self ) : u = urllib . urlopen ( "http://wiws.cmbi.ru.nl/rest/TestEmpty/id/1crn/" ) x = xml . dom . minidom . parse ( u ) self . alive = len ( x . getElementsByTagName ( "TestEmptyResponse" ) ) return self . alive | Test Function to check WHAT IF servers are up and running . |
28,956 | def PDBasXMLwithSymwithPolarH ( self , id ) : print _WARNING h_s_xml = urllib . urlopen ( "http://www.cmbi.ru.nl/wiwsd/rest/PDBasXMLwithSymwithPolarH/id/" + id ) self . raw = h_s_xml p = self . parser h_s_smcra = p . read ( h_s_xml , 'WHATIF_Output' ) return h_s_smcra | Adds Hydrogen Atoms to a Structure . |
28,957 | def get_pdbs_for_gene ( bigg_model , bigg_gene , cache_dir = tempfile . gettempdir ( ) , force_rerun = False ) : my_structures = [ ] gene = ssbio . utils . request_json ( link = 'http://bigg.ucsd.edu/api/v2/models/{}/genes/{}' . format ( bigg_model , bigg_gene ) , outfile = '{}_{}.json' . format ( bigg_model , bigg_gen... | Attempt to get a rank - ordered list of available PDB structures for a BiGG Model and its gene . |
28,958 | def get_dssp_df_on_file ( pdb_file , outfile = None , outdir = None , outext = '_dssp.df' , force_rerun = False ) : outfile = ssbio . utils . outfile_maker ( inname = pdb_file , outname = outfile , outdir = outdir , outext = outext ) if ssbio . utils . force_rerun ( flag = force_rerun , outfile = outfile ) : try : d = ... | Run DSSP directly on a structure file with the Biopython method Bio . PDB . DSSP . dssp_dict_from_pdb_file |
28,959 | def secondary_structure_summary ( dssp_df ) : chains = dssp_df . chain . unique ( ) infodict = { } for chain in chains : expoinfo = defaultdict ( int ) chain_df = dssp_df [ dssp_df . chain == chain ] counts = chain_df . ss . value_counts ( ) total = float ( len ( chain_df ) ) for ss , count in iteritems ( counts ) : if... | Summarize the secondary structure content of the DSSP dataframe for each chain . |
28,960 | def calc_surface_buried ( dssp_df ) : SN = 0 BN = 0 SP = 0 SNP = 0 SPo = 0 SNe = 0 BNP = 0 BP = 0 BPo = 0 BNe = 0 Total = 0 sbinfo = { } df_min = dssp_df [ [ 'aa_three' , 'exposure_asa' ] ] if len ( df_min ) == 0 : return sbinfo else : for i , r in df_min . iterrows ( ) : res = r . aa_three area = r . exposure_asa if r... | Calculates the percent of residues that are in the surface or buried as well as if they are polar or nonpolar . Returns a dictionary of this . |
28,961 | def calc_sasa ( dssp_df ) : infodict = { 'ssb_sasa' : dssp_df . exposure_asa . sum ( ) , 'ssb_mean_rel_exposed' : dssp_df . exposure_rsa . mean ( ) , 'ssb_size' : len ( dssp_df ) } return infodict | Calculation of SASA utilizing the DSSP program . |
28,962 | def get_ss_class ( pdb_file , dssp_file , chain ) : prag = pr . parsePDB ( pdb_file ) pr . parseDSSP ( dssp_file , prag ) alpha , threeTen , beta = get_dssp_ss_content_multiplechains ( prag , chain ) if alpha == 0 and beta > 0 : classification = 'all-beta' elif beta == 0 and alpha > 0 : classification = 'all-alpha' eli... | Define the secondary structure class of a PDB file at the specific chain |
28,963 | def parse_uniprot_xml_metadata ( sr ) : xref_dbs_to_keep = [ 'GO' , 'KEGG' , 'PDB' , 'PROSITE' , 'Pfam' , 'RefSeq' ] infodict = { } infodict [ 'alt_uniprots' ] = list ( set ( sr . annotations [ 'accessions' ] ) . difference ( [ sr . id ] ) ) infodict [ 'gene_name' ] = None if 'gene_name_primary' in sr . annotations : i... | Load relevant attributes and dbxrefs from a parsed UniProt XML file in a SeqRecord . |
28,964 | def is_valid_uniprot_id ( instring ) : valid_id = re . compile ( "[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2}" ) if valid_id . match ( str ( instring ) ) : return True else : return False | Check if a string is a valid UniProt ID . |
28,965 | def uniprot_reviewed_checker ( uniprot_id ) : query_string = 'id:' + uniprot_id uni_rev_raw = StringIO ( bsup . search ( query_string , columns = 'id,reviewed' , frmt = 'tab' ) ) uni_rev_df = pd . read_table ( uni_rev_raw , sep = '\t' , index_col = 0 ) uni_rev_df = uni_rev_df . fillna ( False ) uni_rev_df = uni_rev_df ... | Check if a single UniProt ID is reviewed or not . |
28,966 | def uniprot_reviewed_checker_batch ( uniprot_ids ) : uniprot_ids = ssbio . utils . force_list ( uniprot_ids ) invalid_ids = [ i for i in uniprot_ids if not is_valid_uniprot_id ( i ) ] uniprot_ids = [ i for i in uniprot_ids if is_valid_uniprot_id ( i ) ] if invalid_ids : warnings . warn ( "Invalid UniProt IDs {} will be... | Batch check if uniprot IDs are reviewed or not |
28,967 | def uniprot_ec ( uniprot_id ) : r = requests . post ( 'http://www.uniprot.org/uniprot/?query=%s&columns=ec&format=tab' % uniprot_id ) ec = r . content . decode ( 'utf-8' ) . splitlines ( ) [ 1 ] if len ( ec ) == 0 : ec = None return ec | Retrieve the EC number annotation for a UniProt ID . |
28,968 | def uniprot_sites ( uniprot_id ) : r = requests . post ( 'http://www.uniprot.org/uniprot/%s.gff' % uniprot_id ) gff = StringIO ( r . content . decode ( 'utf-8' ) ) feats = list ( GFF . parse ( gff ) ) if len ( feats ) > 1 : log . warning ( 'Too many sequences in GFF' ) else : return feats [ 0 ] . features | Retrieve a list of UniProt sites parsed from the feature file |
28,969 | def parse_uniprot_txt_file ( infile ) : uniprot_metadata_dict = { } metadata = old_parse_uniprot_txt_file ( infile ) metadata_keys = list ( metadata . keys ( ) ) if metadata_keys : metadata_key = metadata_keys [ 0 ] else : return uniprot_metadata_dict uniprot_metadata_dict [ 'seq_len' ] = len ( str ( metadata [ metadat... | Parse a raw UniProt metadata file and return a dictionary . |
28,970 | def metadata_path_unset ( self ) : if not self . metadata_file : raise IOError ( 'No metadata file to unset' ) log . debug ( '{}: reading from metadata file {}' . format ( self . id , self . metadata_path ) ) tmp_sr = SeqIO . read ( self . metadata_path , 'uniprot-xml' ) tmp_feats = tmp_sr . features self . metadata_di... | Copy features to memory and remove the association of the metadata file . |
28,971 | def download_seq_file ( self , outdir , force_rerun = False ) : uniprot_fasta_file = download_uniprot_file ( uniprot_id = self . id , filetype = 'fasta' , outdir = outdir , force_rerun = force_rerun ) self . sequence_path = uniprot_fasta_file | Download and load the UniProt FASTA file |
28,972 | def download_metadata_file ( self , outdir , force_rerun = False ) : uniprot_xml_file = download_uniprot_file ( uniprot_id = self . id , outdir = outdir , filetype = 'xml' , force_rerun = force_rerun ) self . metadata_path = uniprot_xml_file | Download and load the UniProt XML file |
28,973 | def save_dataframes ( self , outdir , prefix = 'df_' ) : dfs = list ( filter ( lambda x : x . startswith ( prefix ) , dir ( self ) ) ) counter = 0 for df in dfs : outpath = ssbio . utils . outfile_maker ( inname = df , outext = '.csv' , outdir = outdir ) my_df = getattr ( self , df ) if not isinstance ( my_df , pd . Da... | Save all attributes that start with df into a specified directory . |
28,974 | def _build_bonding_network ( self ) : self . bonds = { } self . selection = { } missing = 0 for residue in self . nh_structure . get_residues ( ) : bond_dict = self . bonds [ residue ] = { } atom_dict = residue . child_dict atom_names = set ( atom_dict . keys ( ) ) for name in atom_names : bond_dict [ name ] = [ [ ] , ... | Evaluates atoms per residue for missing and known bonded partners . Based on bond_amber . A better alternative would be to iterate over the entire list of residues and use NeighborSearch to probe neighbors for atom X in residue i i - 1 and i + 1 |
28,975 | def _exclude_ss_bonded_cysteines ( self ) : ss_bonds = self . nh_structure . search_ss_bonds ( ) for cys_pair in ss_bonds : cys1 , cys2 = cys_pair cys1 . resname = 'CYX' cys2 . resname = 'CYX' | Pre - compute ss bonds to discard cystines for H - adding . |
28,976 | def _find_secondary_anchors ( self , residue , heavy_atom , anchor ) : for secondary in self . bonds [ residue ] [ anchor . name ] [ 1 ] : for tertiary in self . bonds [ residue ] [ secondary . name ] [ 1 ] : if ( tertiary . name != heavy_atom . name and tertiary . name != anchor . name ) : return ( secondary , tertiar... | Searches through the bond network for atoms bound to the anchor . Returns a secondary and tertiary anchors . Example for CA returns C and O . |
28,977 | def parse_results_mol2 ( mol2_outpath ) : docked_ligands = pd . DataFrame ( ) lines = [ line . strip ( ) for line in open ( mol2_outpath , 'r' ) ] props = { } for i , line in enumerate ( lines ) : if line . startswith ( '########## Name:' ) : ligand = line . strip ( ) . strip ( '##########' ) . replace ( ' ' , '' ) . r... | Parse a DOCK6 mol2 output file return a Pandas DataFrame of the results . |
28,978 | def structure_path ( self , path ) : if not path : self . structure_dir = None self . structure_file = None else : if not op . exists ( path ) : raise OSError ( '{}: file does not exist!' . format ( path ) ) if not op . dirname ( path ) : self . structure_dir = '.' else : self . structure_dir = op . dirname ( path ) se... | Provide pointers to the paths of the structure file |
28,979 | def dockprep ( self , force_rerun = False ) : log . debug ( '{}: running dock preparation...' . format ( self . id ) ) prep_mol2 = op . join ( self . dock_dir , '{}_prep.mol2' . format ( self . id ) ) prep_py = op . join ( self . dock_dir , "prep.py" ) if ssbio . utils . force_rerun ( flag = force_rerun , outfile = pre... | Prepare a PDB file for docking by first converting it to mol2 format . |
28,980 | def protein_only_and_noH ( self , keep_ligands = None , force_rerun = False ) : log . debug ( '{}: running protein receptor isolation...' . format ( self . id ) ) if not self . dockprep_path : return ValueError ( 'Please run dockprep' ) receptor_mol2 = op . join ( self . dock_dir , '{}_receptor.mol2' . format ( self . ... | Isolate the receptor by stripping everything except protein and specified ligands . |
28,981 | def binding_site_mol2 ( self , residues , force_rerun = False ) : log . debug ( '{}: running binding site isolation...' . format ( self . id ) ) if not self . receptorpdb_path : return ValueError ( 'Please run protein_only_and_noH' ) prefix = self . id + '_' + 'binding_residues' mol2maker = op . join ( self . dock_dir ... | Create mol2 of only binding site residues from the receptor |
28,982 | def sphere_selector_using_residues ( self , radius , force_rerun = False ) : log . debug ( '{}: running sphere selector...' . format ( self . id ) ) if not self . sphgen_path or not self . bindingsite_path : return ValueError ( 'Please run sphgen and binding_site_mol2' ) selsph = op . join ( self . dock_dir , '{}_selsp... | Select spheres based on binding site residues |
28,983 | def showbox ( self , force_rerun = False ) : log . debug ( '{}: running box maker...' . format ( self . id ) ) if not self . sphsel_path : return ValueError ( 'Please run sphere_selector_using_residues' ) boxfile = op . join ( self . dock_dir , "{}_box.pdb" . format ( self . id ) ) boxscript = op . join ( self . dock_d... | Create the dummy PDB box around the selected spheres . |
28,984 | def auto_flexdock ( self , binding_residues , radius , ligand_path = None , force_rerun = False ) : log . debug ( '\n{}: running DOCK6...\n' '\tBinding residues: {}\n' '\tBinding residues radius: {}\n' '\tLigand to dock: {}\n' . format ( self . id , binding_residues , radius , op . basename ( ligand_path ) ) ) self . d... | Run DOCK6 on a PDB file given its binding residues and a radius around them . |
28,985 | def get_metalpdb_info ( metalpdb_lig_file ) : pdb_metals = [ 'CU' , 'ZN' , 'MN' , 'FE' , 'MG' , 'CO' , 'SE' , 'YB' , 'SF4' , 'FES' , 'F3S' , 'NI' , 'FE2' ] coordination_number = 0 endogenous_ligands = [ ] exogenous_ligands = [ ] ss = StructProp ( ident = 'metalpdb' , structure_path = metalpdb_lig_file , file_type = 'pd... | Parse a MetalPDB . lig file and return a tuple of the chain ID it represents along with metal binding information . |
28,986 | def pairwise_sequence_alignment ( a_seq , b_seq , engine , a_seq_id = None , b_seq_id = None , gapopen = 10 , gapextend = 0.5 , outfile = None , outdir = None , force_rerun = False ) : engine = engine . lower ( ) if engine not in [ 'biopython' , 'needle' ] : raise ValueError ( '{}: invalid engine' . format ( engine ) )... | Run a global pairwise sequence alignment between two sequence strings . |
28,987 | def run_needle_alignment ( seq_a , seq_b , gapopen = 10 , gapextend = 0.5 , write_outfile = True , outdir = None , outfile = None , force_rerun = False ) : if not outdir : outdir = '' if write_outfile : seq_a = ssbio . protein . sequence . utils . cast_to_str ( seq_a ) seq_b = ssbio . protein . sequence . utils . cast_... | Run the needle alignment program for two strings and return the raw alignment result . |
28,988 | def run_needle_alignment_on_files ( id_a , faa_a , id_b , faa_b , gapopen = 10 , gapextend = 0.5 , outdir = '' , outfile = '' , force_rerun = False ) : if not outfile : outfile = op . join ( outdir , '{}_{}.needle' . format ( id_a , id_b ) ) else : outfile = op . join ( outdir , outfile ) if op . exists ( outfile ) and... | Run the needle alignment program for two fasta files and return the raw alignment result . |
28,989 | def get_percent_identity ( a_aln_seq , b_aln_seq ) : if len ( a_aln_seq ) != len ( b_aln_seq ) : raise ValueError ( 'Sequence lengths not equal - was an alignment run?' ) count = 0 gaps = 0 for n in range ( 0 , len ( a_aln_seq ) ) : if a_aln_seq [ n ] == b_aln_seq [ n ] : if a_aln_seq [ n ] != "-" : count += 1 else : g... | Get the percent identity between two alignment strings |
28,990 | def get_alignment_df ( a_aln_seq , b_aln_seq , a_seq_id = None , b_seq_id = None ) : if len ( a_aln_seq ) != len ( b_aln_seq ) : raise ValueError ( 'Sequence lengths not equal - was an alignment run?' ) if not a_seq_id : a_seq_id = 'a_seq' if not b_seq_id : b_seq_id = 'b_seq' a_aln_seq = ssbio . protein . sequence . ut... | Summarize two alignment strings in a dataframe . |
28,991 | def get_alignment_df_from_file ( alignment_file , a_seq_id = None , b_seq_id = None ) : alignments = list ( AlignIO . parse ( alignment_file , "emboss" ) ) alignment_df = pd . DataFrame ( columns = [ 'id_a' , 'id_b' , 'type' , 'id_a_aa' , 'id_a_pos' , 'id_b_aa' , 'id_b_pos' ] ) for alignment in alignments : if not a_se... | Get a Pandas DataFrame of the Needle alignment results . Contains all positions of the sequences . |
28,992 | def get_deletions ( aln_df ) : deletion_df = aln_df [ aln_df [ 'type' ] == 'deletion' ] if not deletion_df . empty : deletion_df [ 'id_a_pos' ] = deletion_df [ 'id_a_pos' ] . astype ( int ) deletions = [ ] for k , g in groupby ( deletion_df . index , key = lambda n , c = count ( ) : n - next ( c ) ) : tmp = list ( g ) ... | Get a list of tuples indicating the first and last residues of a deletion region as well as the length of the deletion . |
28,993 | def get_insertions ( aln_df ) : insertion_df = aln_df [ aln_df [ 'type' ] == 'insertion' ] insertions = [ ] for k , g in groupby ( insertion_df . index , key = lambda n , c = count ( ) : n - next ( c ) ) : tmp = list ( g ) insertion_indices = ( min ( tmp ) , max ( tmp ) ) insertion_start = insertion_indices [ 0 ] - 1 i... | Get a list of tuples indicating the first and last residues of a insertion region as well as the length of the insertion . |
28,994 | def map_resnum_a_to_resnum_b ( resnums , a_aln , b_aln ) : resnums = ssbio . utils . force_list ( resnums ) aln_df = get_alignment_df ( a_aln , b_aln ) maps = aln_df [ aln_df . id_a_pos . isin ( resnums ) ] able_to_map_to_b = maps [ pd . notnull ( maps . id_b_pos ) ] successful_map_from_a = able_to_map_to_b . id_a_pos ... | Map a residue number in a sequence to the corresponding residue number in an aligned sequence . |
28,995 | def pairwise_alignment_stats ( reference_seq_aln , other_seq_aln ) : if len ( reference_seq_aln ) != len ( other_seq_aln ) : raise ValueError ( 'Sequence lengths not equal - was an alignment run?' ) reference_seq_aln = ssbio . protein . sequence . utils . cast_to_str ( reference_seq_aln ) other_seq_aln = ssbio . protei... | Get a report of a pairwise alignment . |
28,996 | def needle_statistics ( infile ) : alignments = list ( AlignIO . parse ( infile , "emboss" ) ) alignment_properties = defaultdict ( dict ) with open ( infile ) as f : line = f . readline ( ) for i in range ( len ( alignments ) ) : while line . rstrip ( ) != "#=======================================" : line = f . readli... | Reads in a needle alignment file and spits out statistics of the alignment . |
28,997 | def needle_statistics_alignio ( infile ) : alignments = list ( AlignIO . parse ( infile , "emboss" ) ) if len ( alignments ) > 1 : raise ValueError ( 'Alignment file contains more than one pairwise alignment' ) alignment = alignments [ 0 ] with open ( infile ) as f : line = f . readline ( ) for i in range ( len ( align... | Reads in a needle alignment file and returns an AlignIO object with annotations |
28,998 | def run_repair_pdb ( self , silent = False , force_rerun = False ) : foldx_repair_pdb = 'foldx --command=RepairPDB --pdb={}' . format ( self . pdb_file ) foldx_repair_outfile = '{}_Repair.pdb' . format ( op . splitext ( self . pdb_file ) [ 0 ] ) ssbio . utils . command_runner ( shell_command = foldx_repair_pdb , force_... | Run FoldX RepairPDB on this PDB file . |
28,999 | def create_mutation_file ( self , list_of_tuples ) : self . mutation_infile = op . join ( self . foldx_dir , 'individual_list.txt' ) idx = 1 with open ( self . mutation_infile , 'w' ) as f : for mutant_group in list_of_tuples : mutstring = '' . join ( list ( map ( lambda x : '{}{}{}{};' . format ( x [ 0 ] , x [ 1 ] , x... | Create the FoldX file individual_list . txt to run BuildModel upon . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.