idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
29,000
def create_random_mutation_file ( self , list_of_tuples , original_sequence , randomize_resnums = False , randomize_resids = False , skip_resnums = None ) : import random def find ( s , ch ) : return [ i for i , ltr in enumerate ( s ) if ltr == ch ]
Create the FoldX file individual_list . txt but randomize the mutation numbers or residues that were input .
29,001
def run_build_model ( self , num_runs = 5 , silent = False , force_rerun = False ) : self . mutation_ddG_avg_outfile = 'Average_{}.fxout' . format ( op . splitext ( self . repaired_pdb_outfile ) [ 0 ] ) self . mutation_ddG_raw_outfile = 'Raw_{}.fxout' . format ( op . splitext ( self . repaired_pdb_outfile ) [ 0 ] ) fol...
Run FoldX BuildModel command with a mutant file input .
29,002
def get_ddG_results ( self ) : foldx_avg_df = self . df_mutation_ddG_avg foldx_avg_ddG = { } results = foldx_avg_df [ [ 'Pdb' , 'total energy' , 'SD' ] ] . T . to_dict ( ) . values ( ) for r in results : ident = r [ 'Pdb' ] . split ( '_' ) [ - 1 ] ddG = r [ 'total energy' ] ddG_sd = r [ 'SD' ] foldx_avg_ddG [ self . mu...
Parse the results from BuildModel and get the delta delta G s .
29,003
def clean_pdb ( pdb_file , out_suffix = '_clean' , outdir = None , force_rerun = False , remove_atom_alt = True , keep_atom_alt_id = 'A' , remove_atom_hydrogen = True , add_atom_occ = True , remove_res_hetero = True , keep_chemicals = None , keep_res_only = None , add_chain_id_if_empty = 'X' , keep_chains = None ) : ou...
Clean a PDB file .
29,004
def parse_mmtf_header ( infile ) : infodict = { } mmtf_decoder = mmtf . parse ( infile ) infodict [ 'date' ] = mmtf_decoder . deposition_date infodict [ 'release_date' ] = mmtf_decoder . release_date try : infodict [ 'experimental_method' ] = [ x . decode ( ) for x in mmtf_decoder . experimental_methods ] except Attrib...
Parse an MMTF file and return basic header - like information .
29,005
def download_mmcif_header ( pdb_id , outdir = '' , force_rerun = False ) : pdb_id = pdb_id . lower ( ) file_type = 'cif' folder = 'header' outfile = op . join ( outdir , '{}.header.{}' . format ( pdb_id , file_type ) ) if ssbio . utils . force_rerun ( flag = force_rerun , outfile = outfile ) : download_link = 'http://f...
Download a mmCIF header file from the RCSB PDB by ID .
29,006
def parse_mmcif_header ( infile ) : from Bio . PDB . MMCIF2Dict import MMCIF2Dict newdict = { } try : mmdict = MMCIF2Dict ( infile ) except ValueError as e : log . exception ( e ) return newdict chemical_ids_exclude = [ 'HOH' ] chemical_types_exclude = [ 'l-peptide linking' , 'peptide linking' ] if '_struct.title' in m...
Parse a couple important fields from the mmCIF file format with some manual curation of ligands .
29,007
def download_sifts_xml ( pdb_id , outdir = '' , force_rerun = False ) : baseURL = 'ftp://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/' filename = '{}.xml.gz' . format ( pdb_id . lower ( ) ) outfile = op . join ( outdir , filename . split ( '.' ) [ 0 ] + '.sifts.xml' ) if ssbio . utils . force_rerun ( flag = force_rerun ,...
Download the SIFTS file for a PDB ID .
29,008
def map_uniprot_resnum_to_pdb ( uniprot_resnum , chain_id , sifts_file ) : parser = etree . XMLParser ( ns_clean = True ) tree = etree . parse ( sifts_file , parser ) root = tree . getroot ( ) my_pdb_resnum = None my_pdb_annotation = False ent = './/{http://www.ebi.ac.uk/pdbe/docs/sifts/eFamily.xsd}entity' for chain in...
Map a UniProt residue number to its corresponding PDB residue number .
29,009
def best_structures ( uniprot_id , outname = None , outdir = None , seq_ident_cutoff = 0.0 , force_rerun = False ) : outfile = '' if not outdir : outdir = '' if not outname and outdir : outname = uniprot_id if outname : outname = op . join ( outdir , outname ) outfile = '{}.json' . format ( outname ) if not ssbio . uti...
Use the PDBe REST service to query for the best PDB structures for a UniProt ID .
29,010
def _property_table ( ) : url = 'http://www.rcsb.org/pdb/rest/customReport.csv?pdbids=*&customReportColumns=structureId,resolution,experimentalTechnique,releaseDate&service=wsfile&format=csv' r = requests . get ( url ) p = pd . read_csv ( StringIO ( r . text ) ) . set_index ( 'structureId' ) return p
Download the PDB - > resolution table directly from the RCSB PDB REST service .
29,011
def get_resolution ( pdb_id ) : pdb_id = pdb_id . upper ( ) if pdb_id not in _property_table ( ) . index : raise ValueError ( 'PDB ID not in property table' ) else : resolution = _property_table ( ) . ix [ pdb_id , 'resolution' ] if pd . isnull ( resolution ) : log . debug ( '{}: no resolution available, probably not a...
Quick way to get the resolution of a PDB ID using the table of results from the REST service
29,012
def get_release_date ( pdb_id ) : pdb_id = pdb_id . upper ( ) if pdb_id not in _property_table ( ) . index : raise ValueError ( 'PDB ID not in property table' ) else : release_date = _property_table ( ) . ix [ pdb_id , 'releaseDate' ] if pd . isnull ( release_date ) : log . debug ( '{}: no release date available' ) rel...
Quick way to get the release date of a PDB ID using the table of results from the REST service
29,013
def get_num_bioassemblies ( pdb_id , cache = False , outdir = None , force_rerun = False ) : parser = etree . XMLParser ( ns_clean = True ) if not outdir : outdir = os . getcwd ( ) outfile = op . join ( outdir , '{}_nrbiomols.xml' . format ( pdb_id ) ) if ssbio . utils . force_rerun ( force_rerun , outfile ) : page = '...
Check if there are bioassemblies using the PDB REST API and if there are get the number of bioassemblies available .
29,014
def get_bioassembly_info ( pdb_id , biomol_num , cache = False , outdir = None , force_rerun = False ) : parser = etree . XMLParser ( ns_clean = True )
Get metadata about a bioassembly from the RCSB PDB s REST API .
29,015
def download_structure ( pdb_id , file_type , outdir = '' , only_header = False , force_rerun = False ) : pdb_id = pdb_id . lower ( ) file_type = file_type . lower ( ) file_types = [ 'pdb' , 'pdb.gz' , 'mmcif' , 'cif' , 'cif.gz' , 'xml.gz' , 'mmtf' , 'mmtf.gz' ] if file_type not in file_types : raise ValueError ( 'Inva...
Download a structure from the RCSB PDB by ID . Specify the file type desired .
29,016
def download_structure_file ( self , outdir , file_type = None , load_header_metadata = True , force_rerun = False ) : ssbio . utils . double_check_attribute ( object = self , setter = file_type , backup_attribute = 'file_type' , custom_error_text = 'Please set file type to be downloaded from the PDB: ' 'pdb, mmCif, xm...
Download a structure file from the PDB specifying an output directory and a file type . Optionally download the mmCIF header file and parse data from it to store within this object .
29,017
def parse_procheck ( quality_directory ) : procheck_summaries = glob . glob ( os . path . join ( quality_directory , '*.sum' ) ) if len ( procheck_summaries ) == 0 : return pd . DataFrame ( ) all_procheck = { } for summ in procheck_summaries : structure_id = os . path . basename ( summ ) . split ( '.sum' ) [ 0 ] proche...
Parses all PROCHECK files in a directory and returns a Pandas DataFrame of the results
29,018
def parse_psqs ( psqs_results_file ) : psqs_results = pd . read_csv ( psqs_results_file , sep = '\t' , header = None ) psqs_results [ 'pdb_file' ] = psqs_results [ 0 ] . apply ( lambda x : str ( x ) . strip ( './' ) . strip ( '.pdb' ) ) psqs_results = psqs_results . rename ( columns = { 1 : 'psqs_local' , 2 : 'psqs_bur...
Parse a PSQS result file and returns a Pandas DataFrame of the results
29,019
def protein_statistics ( self ) : d = { } d [ 'id' ] = self . id d [ 'sequences' ] = [ x . id for x in self . sequences ] d [ 'num_sequences' ] = self . num_sequences if self . representative_sequence : d [ 'representative_sequence' ] = self . representative_sequence . id d [ 'repseq_gene_name' ] = self . representativ...
Get a dictionary of basic statistics describing this protein
29,020
def filter_sequences ( self , seq_type ) : return DictList ( x for x in self . sequences if isinstance ( x , seq_type ) )
Return a DictList of only specified types in the sequences attribute .
29,021
def load_kegg ( self , kegg_id , kegg_organism_code = None , kegg_seq_file = None , kegg_metadata_file = None , set_as_representative = False , download = False , outdir = None , force_rerun = False ) : if download : if not outdir : outdir = self . sequence_dir if not outdir : raise ValueError ( 'Output directory must ...
Load a KEGG ID sequence and metadata files into the sequences attribute .
29,022
def load_manual_sequence_file ( self , ident , seq_file , copy_file = False , outdir = None , set_as_representative = False ) : if copy_file : if not outdir : outdir = self . sequence_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) shutil . copy ( seq_file , outdir ) seq_file = op . join (...
Load a manual sequence given as a FASTA file and optionally set it as the representative sequence . Also store it in the sequences attribute .
29,023
def load_manual_sequence ( self , seq , ident = None , write_fasta_file = False , outdir = None , set_as_representative = False , force_rewrite = False ) : if write_fasta_file : if not outdir : outdir = self . sequence_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) outfile = op . join ( o...
Load a manual sequence given as a string and optionally set it as the representative sequence . Also store it in the sequences attribute .
29,024
def write_all_sequences_file ( self , outname , outdir = None ) : if not outdir : outdir = self . sequence_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) outfile = op . join ( outdir , outname + '.faa' ) SeqIO . write ( self . sequences , outfile , "fasta" ) log . info ( '{}: wrote all pr...
Write all the stored sequences as a single FASTA file . By default sets IDs to model gene IDs .
29,025
def get_sequence_sliding_window_properties ( self , scale , window , representative_only = True ) : if representative_only : if not self . representative_sequence : log . warning ( '{}: no representative sequence set, cannot get sequence properties' . format ( self . id ) ) return if not self . representative_sequence ...
Run Biopython ProteinAnalysis with a sliding window to calculate a given property . Results are stored in the protein s respective SeqProp objects at . letter_annotations
29,026
def prep_itasser_modeling ( self , itasser_installation , itlib_folder , runtype , create_in_dir = None , execute_from_dir = None , print_exec = False , ** kwargs ) : if not create_in_dir : if not self . structure_dir : raise ValueError ( 'Output directory must be specified' ) self . homology_models_dir = op . join ( s...
Prepare to run I - TASSER homology modeling for the representative sequence .
29,027
def map_uniprot_to_pdb ( self , seq_ident_cutoff = 0.0 , outdir = None , force_rerun = False ) : if not self . representative_sequence : log . error ( '{}: no representative sequence set, cannot use best structures API' . format ( self . id ) ) return None uniprot_id = self . representative_sequence . uniprot if not un...
Map the representative sequence s UniProt ID to PDB IDs using the PDBe Best Structures API . Will save a JSON file of the results to the protein sequences folder .
29,028
def load_pdb ( self , pdb_id , mapped_chains = None , pdb_file = None , file_type = None , is_experimental = True , set_as_representative = False , representative_chain = None , force_rerun = False ) : if self . structures . has_id ( pdb_id ) : if force_rerun : existing = self . structures . get_by_id ( pdb_id ) self ....
Load a structure ID and optional structure file into the structures attribute .
29,029
def pdb_downloader_and_metadata ( self , outdir = None , pdb_file_type = None , force_rerun = False ) : if not outdir : outdir = self . structure_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) if not pdb_file_type : pdb_file_type = self . pdb_file_type if self . num_structures_experimenta...
Download ALL mapped experimental structures to the protein structures directory .
29,030
def _get_seqprop_to_seqprop_alignment ( self , seqprop1 , seqprop2 ) : if isinstance ( seqprop1 , str ) : seqprop1_id = seqprop1 else : seqprop1_id = seqprop1 . id if isinstance ( seqprop2 , str ) : seqprop2_id = seqprop2 else : seqprop2_id = seqprop2 . id aln_id = '{}_{}' . format ( seqprop1_id , seqprop2_id ) if self...
Return the alignment stored in self . sequence_alignments given a seqprop + another seqprop
29,031
def map_seqprop_resnums_to_seqprop_resnums ( self , resnums , seqprop1 , seqprop2 ) : resnums = ssbio . utils . force_list ( resnums ) alignment = self . _get_seqprop_to_seqprop_alignment ( seqprop1 = seqprop1 , seqprop2 = seqprop2 ) mapped = ssbio . protein . sequence . utils . alignment . map_resnum_a_to_resnum_b ( r...
Map a residue number in any SeqProp to another SeqProp using the pairwise alignment information .
29,032
def _get_seqprop_to_structprop_alignment ( self , seqprop , structprop , chain_id ) : full_structure_id = '{}-{}' . format ( structprop . id , chain_id ) aln_id = '{}_{}' . format ( seqprop . id , full_structure_id ) if self . sequence_alignments . has_id ( aln_id ) : alignment = self . sequence_alignments . get_by_id ...
Return the alignment stored in self . sequence_alignments given a seqprop structuprop and chain_id
29,033
def check_structure_chain_quality ( self , seqprop , structprop , chain_id , seq_ident_cutoff = 0.5 , allow_missing_on_termini = 0.2 , allow_mutants = True , allow_deletions = False , allow_insertions = False , allow_unresolved = True ) : alignment = self . _get_seqprop_to_structprop_alignment ( seqprop = seqprop , str...
Report if a structure s chain meets the defined cutoffs for sequence quality .
29,034
def find_representative_chain ( self , seqprop , structprop , chains_to_check = None , seq_ident_cutoff = 0.5 , allow_missing_on_termini = 0.2 , allow_mutants = True , allow_deletions = False , allow_insertions = False , allow_unresolved = True ) : if chains_to_check : chains_to_check = ssbio . utils . force_list ( cha...
Set and return the representative chain based on sequence quality checks to a reference sequence .
29,035
def _map_seqprop_resnums_to_structprop_chain_index ( self , resnums , seqprop = None , structprop = None , chain_id = None , use_representatives = False ) : resnums = ssbio . utils . force_list ( resnums ) if use_representatives : seqprop = self . representative_sequence structprop = self . representative_structure cha...
Map a residue number in any SeqProp to the mapping index in the StructProp + chain ID . This does not provide a mapping to residue number only a mapping to the index which then can be mapped to the structure resnum!
29,036
def map_seqprop_resnums_to_structprop_resnums ( self , resnums , seqprop = None , structprop = None , chain_id = None , use_representatives = False ) : resnums = ssbio . utils . force_list ( resnums ) if use_representatives : seqprop = self . representative_sequence structprop = self . representative_structure chain_id...
Map a residue number in any SeqProp to the structure s residue number for a specified chain .
29,037
def map_structprop_resnums_to_seqprop_resnums ( self , resnums , structprop = None , chain_id = None , seqprop = None , use_representatives = False ) : resnums = ssbio . utils . force_list ( resnums ) if use_representatives : seqprop = self . representative_sequence structprop = self . representative_structure chain_id...
Map a residue number in any StructProp + chain ID to any SeqProp s residue number .
29,038
def get_seqprop_subsequence_from_structchain_property ( self , property_key , property_value , condition , seqprop = None , structprop = None , chain_id = None , use_representatives = False , return_resnums = False ) : if use_representatives : seqprop = self . representative_sequence structprop = self . representative_...
Get a subsequence as a new SeqProp object given a certain property you want to find in the given StructProp s chain s letter_annotation
29,039
def _representative_structure_setter ( self , structprop , keep_chain , clean = True , keep_chemicals = None , out_suffix = '_clean' , outdir = None , force_rerun = False ) : if not outdir : outdir = self . structure_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) new_id = 'REP-{}' . forma...
Set the representative structure by 1 ) cleaning it and 2 ) copying over attributes of the original structure .
29,040
def get_residue_annotations ( self , seq_resnum , seqprop = None , structprop = None , chain_id = None , use_representatives = False ) : if use_representatives : if seqprop and structprop and chain_id : raise ValueError ( 'Overriding sequence, structure, and chain IDs with representatives. ' 'Set use_representatives to...
Get all residue - level annotations stored in the SeqProp letter_annotations field for a given residue number .
29,041
def sequence_mutation_summary ( self , alignment_ids = None , alignment_type = None ) : if alignment_ids : ssbio . utils . force_list ( alignment_ids ) if len ( self . sequence_alignments ) == 0 : log . error ( '{}: no sequence alignments' . format ( self . id ) ) return { } , { } fingerprint_counter = defaultdict ( li...
Summarize all mutations found in the sequence_alignments attribute .
29,042
def get_all_pdbflex_info ( self ) : log . debug ( '{}: representative sequence length' . format ( self . representative_sequence . seq_len ) ) for s in self . get_experimental_structures ( ) : log . debug ( '{};{}: chains matching protein {}' . format ( s . id , s . mapped_chains , self . id ) ) s . download_structure_...
Gets ALL PDBFlex entries for all mapped structures then stores the ones that match the repseq length
29,043
def get_generic_subseq_2D ( protein , cutoff , prop , condition ) : subseq , subseq_resnums = protein . representative_sequence . get_subsequence_from_property ( property_key = prop , property_value = cutoff , condition = condition , return_resnums = True ) or ( None , [ ] ) return { 'subseq_len' : len ( subseq_resnums...
Get a subsequence from REPSEQ based on a property stored in REPSEQ . letter_annotations
29,044
def get_generic_subseq_3D ( protein , cutoff , prop , condition ) : if not protein . representative_structure : log . error ( '{}: no representative structure, cannot search for subseq' . format ( protein . id ) ) return { 'subseq_len' : 0 , 'subseq' : None , 'subseq_resnums' : [ ] } subseq , subseq_resnums = protein ....
Get a subsequence from REPSEQ based on a property stored in REPSTRUCT . REPCHAIN . letter_annotations
29,045
def get_combo_subseq_within_2_5D ( protein , props , within , filter_resnums = None ) : if not protein . representative_structure : log . error ( '{}: no representative structure, cannot search for subseq' . format ( protein . id ) ) return { 'subseq_len' : 0 , 'subseq' : None , 'subseq_resnums' : [ ] } all_resnums = [...
Get a subsequence from REPSEQ based on multiple features stored in REPSEQ and within the set distance in REPSTRUCT . REPCHAIN
29,046
def get_surface_subseq_3D ( protein , depth_prop = 'RES_DEPTH-msms' , depth_cutoff = 2.5 , depth_condition = '<' , acc_prop = 'RSA_ALL-freesasa_het' , acc_cutoff = 25 , acc_condition = '>' ) : empty = { 'surface_3D' : { 'subseq_len' : 0 , 'subseq' : None , 'subseq_resnums' : [ ] } , 'notdeep_3D' : { 'subseq_len' : 0 , ...
SURFACE 3D = NOTDEEP + ACC
29,047
def get_disorder_subseq_3D ( protein , pdbflex_keys_file , disorder_cutoff = 2 , disorder_condition = '>' ) : with open ( pdbflex_keys_file , 'r' ) as f : pdbflex_keys = json . load ( f ) if protein . id not in pdbflex_keys : log . warning ( '{}: no PDBFlex info available' . format ( protein . id ) ) final_repseq_sub ,...
DISORDERED REGION 3D
29,048
def parse_init_dat ( infile ) : init_dict = { } log . debug ( '{}: reading file...' . format ( infile ) ) with open ( infile , 'r' ) as f : head = [ next ( f ) . strip ( ) for x in range ( 2 ) ] summary = head [ 0 ] . split ( ) difficulty = summary [ 1 ] top_template_info = head [ 1 ] . split ( ) top_template_pdbchain ...
Parse the main init . dat file which contains the modeling results
29,049
def parse_cscore ( infile ) : cscore_dict = { } with open ( infile , 'r' ) as f : for ll in f . readlines ( ) : if ll . lower ( ) . startswith ( 'model1' ) : l = ll . split ( ) cscore = l [ 1 ] tmscore_full = l [ 2 ] . split ( '+-' ) tmscore = tmscore_full [ 0 ] tmscore_err = tmscore_full [ 1 ] rmsd_full = l [ 3 ] . sp...
Parse the cscore file to return a dictionary of scores .
29,050
def parse_coach_bsites_inf ( infile ) : bsites_results = [ ] with open ( infile ) as pp : lines = list ( filter ( None , ( line . rstrip ( ) for line in pp ) ) ) for i in range ( len ( lines ) // 3 ) : bsites_site_dict = { } line1 = lines [ i * 3 ] . split ( '\t' ) line2 = lines [ i * 3 + 1 ] . split ( '\t' ) line3 = l...
Parse the Bsites . inf output file of COACH and return a list of rank - ordered binding site predictions
29,051
def parse_coach_ec_df ( infile ) : ec_df = pd . read_table ( infile , delim_whitespace = True , names = [ 'pdb_template' , 'tm_score' , 'rmsd' , 'seq_ident' , 'seq_coverage' , 'c_score' , 'ec_number' , 'binding_residues' ] ) ec_df [ 'pdb_template_id' ] = ec_df [ 'pdb_template' ] . apply ( lambda x : x [ : 4 ] ) ec_df [...
Parse the EC . dat output file of COACH and return a dataframe of results
29,052
def parse_coach_go ( infile ) : go_list = [ ] with open ( infile ) as go_file : for line in go_file . readlines ( ) : go_dict = { } go_split = line . split ( ) go_dict [ 'go_id' ] = go_split [ 0 ] go_dict [ 'c_score' ] = go_split [ 1 ] go_dict [ 'go_term' ] = ' ' . join ( go_split [ 2 : ] ) go_list . append ( go_dict )...
Parse a GO output file from COACH and return a rank - ordered list of GO term predictions
29,053
def copy_results ( self , copy_to_dir , rename_model_to = None , force_rerun = False ) : if not rename_model_to : rename_model_to = self . model_to_use new_model_path = op . join ( copy_to_dir , '{}.pdb' . format ( rename_model_to ) ) if self . structure_path : if ssbio . utils . force_rerun ( flag = force_rerun , outf...
Copy the raw information from I - TASSER modeling to a new folder .
29,054
def get_dict ( self , only_attributes = None , exclude_attributes = None , df_format = False ) : to_exclude = [ 'coach_bsites' , 'coach_ec' , 'coach_go_mf' , 'coach_go_bp' , 'coach_go_cc' ] if not exclude_attributes : excluder = to_exclude else : excluder = ssbio . utils . force_list ( exclude_attributes ) excluder . e...
Summarize the I - TASSER run in a dictionary containing modeling results and top predictions from COACH
29,055
def load_cobra_model ( self , model ) : self . model = ModelPro ( model ) for g in self . model . genes : if self . genes_dir : g . root_dir = self . genes_dir g . protein . pdb_file_type = self . pdb_file_type self . genes = self . model . genes log . info ( '{}: loaded model' . format ( model . id ) ) log . info ( '{...
Load a COBRApy Model object into the GEM - PRO project .
29,056
def add_gene_ids ( self , genes_list ) : orig_num_genes = len ( self . genes ) for g in list ( set ( genes_list ) ) : if not self . genes . has_id ( g ) : new_gene = GenePro ( id = g , pdb_file_type = self . pdb_file_type , root_dir = self . genes_dir ) if self . model : self . model . genes . append ( new_gene ) else ...
Add gene IDs manually into the GEM - PRO project .
29,057
def uniprot_mapping_and_metadata ( self , model_gene_source , custom_gene_mapping = None , outdir = None , set_as_representative = False , force_rerun = False ) : if custom_gene_mapping : genes_to_map = list ( custom_gene_mapping . values ( ) ) else : genes_to_map = [ x . id for x in self . genes ] genes_to_uniprots = ...
Map all genes in the model to UniProt IDs using the UniProt mapping service . Also download all metadata and sequences .
29,058
def write_representative_sequences_file ( self , outname , outdir = None , set_ids_from_model = True ) : if not outdir : outdir = self . data_dir if not outdir : raise ValueError ( 'Output directory must be specified' ) outfile = op . join ( outdir , outname + '.faa' ) tmp = [ ] for x in self . genes_with_a_representat...
Write all the model s sequences as a single FASTA file . By default sets IDs to model gene IDs .
29,059
def get_tmhmm_predictions ( self , tmhmm_results , custom_gene_mapping = None ) : tmhmm_dict = ssbio . protein . sequence . properties . tmhmm . parse_tmhmm_long ( tmhmm_results ) counter = 0 for g in tqdm ( self . genes_with_a_representative_sequence ) : if custom_gene_mapping : g_id = custom_gene_mapping [ g . id ] e...
Parse TMHMM results and store in the representative sequences .
29,060
def map_uniprot_to_pdb ( self , seq_ident_cutoff = 0.0 , outdir = None , force_rerun = False ) : all_representative_uniprots = [ ] for g in self . genes_with_a_representative_sequence : uniprot_id = g . protein . representative_sequence . uniprot if uniprot_id : if '-' in uniprot_id : uniprot_id = uniprot_id . split ( ...
Map all representative sequences UniProt ID to PDB IDs using the PDBe Best Structures API . Will save a JSON file of the results to each protein s sequences folder .
29,061
def get_manual_homology_models ( self , input_dict , outdir = None , clean = True , force_rerun = False ) : if outdir : outdir_set = True else : outdir_set = False counter = 0 for g in tqdm ( self . genes ) : if g . id not in input_dict : continue if not outdir_set : outdir = g . protein . structure_dir if not outdir :...
Copy homology models to the GEM - PRO project .
29,062
def get_itasser_models ( self , homology_raw_dir , custom_itasser_name_mapping = None , outdir = None , force_rerun = False ) : counter = 0 for g in tqdm ( self . genes ) : if custom_itasser_name_mapping and g . id in custom_itasser_name_mapping : hom_id = custom_itasser_name_mapping [ g . id ] if not op . exists ( op ...
Copy generated I - TASSER models from a directory to the GEM - PRO directory .
29,063
def set_representative_structure ( self , seq_outdir = None , struct_outdir = None , pdb_file_type = None , engine = 'needle' , always_use_homology = False , rez_cutoff = 0.0 , seq_ident_cutoff = 0.5 , allow_missing_on_termini = 0.2 , allow_mutants = True , allow_deletions = False , allow_insertions = False , allow_unr...
Set all representative structure for proteins from a structure in the structures attribute .
29,064
def prep_itasser_modeling ( self , itasser_installation , itlib_folder , runtype , create_in_dir = None , execute_from_dir = None , all_genes = False , print_exec = False , ** kwargs ) : if not create_in_dir : if not self . data_dir : raise ValueError ( 'Output directory must be specified' ) self . homology_models_dir ...
Prepare to run I - TASSER homology modeling for genes without structures or all genes .
29,065
def pdb_downloader_and_metadata ( self , outdir = None , pdb_file_type = None , force_rerun = False ) : if not pdb_file_type : pdb_file_type = self . pdb_file_type counter = 0 for g in tqdm ( self . genes ) : pdbs = g . protein . pdb_downloader_and_metadata ( outdir = outdir , pdb_file_type = pdb_file_type , force_reru...
Download ALL mapped experimental structures to each protein s structures directory .
29,066
def get_oligomeric_state ( swiss_model_path ) : oligo_info = { } with open ( swiss_model_path , 'r' ) as f : for line in f : if line . startswith ( 'REMARK 3 MODEL INFORMATION' ) : break for i in range ( 10 ) : line = f . readline ( ) if 'ENGIN' in line : oligo_info [ 'ENGIN' ] = line . rstrip ( ) . split ( ' ' ) [ -...
Parse the oligomeric prediction in a SWISS - MODEL repository file
29,067
def translate_ostat ( ostat ) : ostat_lower = ostat . strip ( ) . lower ( ) if ostat_lower == 'monomer' : return 1 elif ostat_lower == 'homo-dimer' : return 2 elif ostat_lower == 'homo-trimer' : return 3 elif ostat_lower == 'homo-tetramer' : return 4 elif ostat_lower == 'homo-pentamer' : return 5 elif ostat_lower == 'h...
Translate the OSTAT field to an integer .
29,068
def parse_metadata ( self ) : all_models = defaultdict ( list ) with open ( self . metadata_index_json ) as f : loaded = json . load ( f ) for m in loaded [ 'index' ] : all_models [ m [ 'uniprot_ac' ] ] . append ( m ) self . all_models = dict ( all_models )
Parse the INDEX_JSON file and reorganize it as a dictionary of lists .
29,069
def get_models ( self , uniprot_acc ) : if uniprot_acc in self . all_models : return self . all_models [ uniprot_acc ] else : log . error ( '{}: no SWISS-MODELs available' . format ( uniprot_acc ) ) return None
Return all available models for a UniProt accession number .
29,070
def get_model_filepath ( self , infodict ) : u = infodict [ 'uniprot_ac' ] original_filename = '{}_{}_{}_{}' . format ( infodict [ 'from' ] , infodict [ 'to' ] , infodict [ 'template' ] , infodict [ 'coordinate_id' ] ) file_path = op . join ( self . metadata_dir , u [ : 2 ] , u [ 2 : 4 ] , u [ 4 : 6 ] , 'swissmodel' , ...
Get the path to the homology model using information from the index dictionary for a single model .
29,071
def download_models ( self , uniprot_acc , outdir = '' , force_rerun = False ) : downloaded = [ ] subset = self . get_models ( uniprot_acc ) for entry in subset : ident = '{}_{}_{}_{}' . format ( uniprot_acc , entry [ 'template' ] , entry [ 'from' ] , entry [ 'to' ] ) outfile = op . join ( outdir , ident + '.pdb' ) if ...
Download all models available for a UniProt accession number .
29,072
def organize_models ( self , outdir , force_rerun = False ) : uniprot_to_swissmodel = defaultdict ( list ) for u , models in self . all_models . items ( ) : for m in models : original_filename = '{}_{}_{}_{}' . format ( m [ 'from' ] , m [ 'to' ] , m [ 'template' ] , m [ 'coordinate_id' ] ) file_path = op . join ( self ...
Organize and rename SWISS - MODEL models to a single folder with a name containing template information .
29,073
def get_dG_at_T ( seq , temp ) : r_cal = scipy . constants . R / scipy . constants . calorie seq = ssbio . protein . sequence . utils . cast_to_str ( seq ) oobatake = { } for t in range ( 20 , 51 ) : oobatake [ t ] = calculate_oobatake_dG ( seq , t ) stable = [ i for i in oobatake . values ( ) if i > 0 ] if len ( stabl...
Predict dG at temperature T using best predictions from Dill or Oobatake methods .
29,074
def run_ppm_server ( pdb_file , outfile , force_rerun = False ) : if ssbio . utils . force_rerun ( outfile = outfile , flag = force_rerun ) : url = 'http://sunshine.phar.umich.edu/upload_file.php' files = { 'userfile' : open ( pdb_file , 'rb' ) } r = requests . post ( url , files = files ) info = r . text with open ( o...
Run the PPM server from OPM to predict transmembrane residues .
29,075
def cctop_submit ( seq_str ) : url = 'http://cctop.enzim.ttk.mta.hu/php/submit.php?sequence={}&tmFilter&signalPred' . format ( seq_str ) r = requests . post ( url ) jobid = r . text . split ( 'ID: ' ) [ 1 ] return jobid
Submit a protein sequence string to CCTOP and return the job ID .
29,076
def cctop_check_status ( jobid ) : status = 'http://cctop.enzim.ttk.mta.hu/php/poll.php?jobId={}' . format ( jobid ) status_text = requests . post ( status ) return status_text . text
Check the status of a CCTOP job ID .
29,077
def cctop_save_xml ( jobid , outpath ) : status = cctop_check_status ( jobid = jobid ) if status == 'Finished' : result = 'http://cctop.enzim.ttk.mta.hu/php/result.php?jobId={}' . format ( jobid ) result_text = requests . post ( result ) with open ( outpath , 'w' ) as f : f . write ( result_text . text ) return outpath...
Save the CCTOP results file in XML format .
29,078
def load_feather ( protein_feather , length_filter_pid = None , copynum_scale = False , copynum_df = None ) : protein_df = pd . read_feather ( protein_feather ) . set_index ( 'index' ) from ssbio . protein . sequence . properties . residues import _aa_property_dict_one , EXTENDED_AA_PROPERTY_DICT_ONE aggregators = { 'a...
Load a feather of amino acid counts for a protein .
29,079
def get_proteome_counts_impute_missing ( prots_filtered_feathers , outpath , length_filter_pid = None , copynum_scale = False , copynum_df = None , force_rerun = False ) : if ssbio . utils . force_rerun ( flag = force_rerun , outfile = outpath ) : big_strain_counts_df = pd . DataFrame ( ) first = True for feather in pr...
Get counts uses the mean feature vector to fill in missing proteins for a strain
29,080
def get_proteome_correct_percentages ( prots_filtered_feathers , outpath , length_filter_pid = None , copynum_scale = False , copynum_df = None , force_rerun = False ) : if ssbio . utils . force_rerun ( flag = force_rerun , outfile = outpath ) : prot_tracker = defaultdict ( int ) big_strain_counts_df = pd . DataFrame (...
Get counts and normalize by number of proteins providing percentages
29,081
def run_all2 ( protgroup , memornot , subsequences , base_outdir , protgroup_dict , protein_feathers_dir , date , errfile , impute_counts = True , cutoff_num_proteins = 0 , core_only_genes = None , length_filter_pid = .8 , remove_correlated_feats = True , force_rerun_counts = False , force_rerun_percentages = False , f...
run_all but ignoring observations before pca
29,082
def make_contribplot ( self , pc_to_look_at = 1 , sigadder = 0.01 , outpath = None , dpi = 150 , return_top_contribs = False ) : cont = pd . DataFrame ( self . pca . components_ , columns = self . features_df . index , index = self . pc_names_list ) tmp_df = pd . DataFrame ( cont . iloc [ pc_to_look_at - 1 ] ) . reset_...
Make a plot showing contributions of properties to a PC
29,083
def _change_height ( self , ax , new_value ) : for patch in ax . patches : current_height = patch . get_height ( ) diff = current_height - new_value patch . set_height ( new_value ) patch . set_y ( patch . get_y ( ) + diff * .5 )
Make bars in horizontal bar chart thinner
29,084
def write_merged_bioassembly ( inpath , outdir , outname , force_rerun = False ) : outpath = outfile = op . join ( outdir , outname + '.pdb' ) if ssbio . utils . force_rerun ( flag = force_rerun , outfile = op . join ( outdir , outname + '.pdb' ) ) : s = StructProp ( 'Model merging' , structure_path = inpath , file_typ...
Utility to take as input a bioassembly file and merge all its models into multiple chains in a single model .
29,085
def save_json ( obj , outfile , allow_nan = True , compression = False ) : if compression : with open ( outfile , 'wb' ) as f : dump ( obj , f , allow_nan = allow_nan , compression = compression ) else : with open ( outfile , 'w' ) as f : dump ( obj , f , allow_nan = allow_nan , compression = compression ) log . info (...
Save an ssbio object as a JSON file using json_tricks
29,086
def load_json ( file , new_root_dir = None , decompression = False ) : if decompression : with open ( file , 'rb' ) as f : my_object = load ( f , decompression = decompression ) else : with open ( file , 'r' ) as f : my_object = load ( f , decompression = decompression ) if new_root_dir : my_object . root_dir = new_roo...
Load a JSON file using json_tricks
29,087
def save_pickle ( obj , outfile , protocol = 2 ) : with open ( outfile , 'wb' ) as f : pickle . dump ( obj , f , protocol = protocol ) return outfile
Save the object as a pickle file
29,088
def load_pickle ( file , encoding = None ) : if encoding : with open ( file , 'rb' ) as f : return pickle . load ( f , encoding = encoding ) with open ( file , 'rb' ) as f : return pickle . load ( f )
Load a pickle file .
29,089
def read ( handle , id = None ) : from Bio . PDB import PDBParser if not id : id = os . path . basename ( handle ) . split ( '.' ) [ 0 ] p = PDBParser ( ) s = p . get_structure ( id , handle ) return s
Reads a structure via PDBParser . Simplifies life ..
29,090
def write ( structure , name = None ) : from Bio . PDB import PDBIO io = PDBIO ( ) io . set_structure ( structure ) if not name : s_name = structure . id else : s_name = name name = "%s.pdb" % s_name seed = 0 while 1 : if os . path . exists ( name ) : name = "%s_%s.pdb" % ( s_name , seed ) seed += 1 else : break io . s...
Writes a Structure in PDB format through PDBIO . Simplifies life ..
29,091
def download_pisa_multimers_xml ( pdb_ids , save_single_xml_files = True , outdir = None , force_rerun = False ) : if not outdir : outdir = os . getcwd ( ) files = { } pdb_ids = ssbio . utils . force_lower_list ( sorted ( pdb_ids ) ) if save_single_xml_files : if not force_rerun : existing_files = [ op . basename ( x )...
Download the PISA XML file for multimers .
29,092
def copy_modified_gene ( self , modified_gene , ignore_model_attributes = True ) : ignore = [ '_model' , '_reaction' , '_functional' , 'model' , 'reaction' , 'functional' ] for attr in filter ( lambda a : not a . startswith ( '__' ) and not isinstance ( getattr ( type ( self ) , a , None ) , property ) and not callable...
Copy attributes of a Gene object over to this Gene given that the modified gene has the same ID .
29,093
def load_structure_path ( self , structure_path , file_type ) : if not file_type : raise ValueError ( 'File type must be specified' ) self . file_type = file_type self . structure_dir = op . dirname ( structure_path ) self . structure_file = op . basename ( structure_path )
Load a structure file and provide pointers to its location
29,094
def parse_structure ( self , store_in_memory = False ) : if not self . structure_file : log . error ( '{}: no structure file, unable to parse' . format ( self . id ) ) return None else : structure = StructureIO ( self . structure_path , self . file_type ) structure_chains = [ x . id for x in structure . first_model . c...
Read the 3D coordinates of a structure file and return it as a Biopython Structure object . Also create ChainProp objects in the chains attribute for each chain in the first model .
29,095
def clean_structure ( self , out_suffix = '_clean' , outdir = None , force_rerun = False , remove_atom_alt = True , keep_atom_alt_id = 'A' , remove_atom_hydrogen = True , add_atom_occ = True , remove_res_hetero = True , keep_chemicals = None , keep_res_only = None , add_chain_id_if_empty = 'X' , keep_chains = None ) : ...
Clean the structure file associated with this structure and save it as a new file . Returns the file path .
29,096
def add_mapped_chain_ids ( self , mapped_chains ) : mapped_chains = ssbio . utils . force_list ( mapped_chains ) for c in mapped_chains : if c not in self . mapped_chains : self . mapped_chains . append ( c ) log . debug ( '{}: added to list of mapped chains' . format ( c ) ) else : log . debug ( '{}: chain already in ...
Add chains by ID into the mapped_chains attribute
29,097
def add_chain_ids ( self , chains ) : chains = ssbio . utils . force_list ( chains ) for c in chains : if self . chains . has_id ( c ) : log . debug ( '{}: chain already present' . format ( c ) ) else : chain_prop = ChainProp ( ident = c , pdb_parent = self . id ) self . chains . append ( chain_prop ) log . debug ( '{}...
Add chains by ID into the chains attribute
29,098
def get_structure_seqs ( self , model ) : dont_overwrite = [ ] chains = list ( model . get_chains ( ) ) for x in chains : if self . chains . has_id ( x . id ) : if self . chains . get_by_id ( x . id ) . seq_record : dont_overwrite . append ( x . id ) if len ( dont_overwrite ) == len ( chains ) : log . debug ( 'Not writ...
Gather chain sequences and store in their corresponding ChainProp objects in the chains attribute .
29,099
def get_dict_with_chain ( self , chain , only_keys = None , chain_keys = None , exclude_attributes = None , df_format = False ) : if not only_keys : keys = list ( self . __dict__ . keys ( ) ) else : keys = ssbio . utils . force_list ( only_keys ) if exclude_attributes : exclude_attributes = ssbio . utils . force_list (...
get_dict method which incorporates attributes found in a specific chain . Does not overwrite any attributes in the original StructProp .