From a584f7478d0eb8bbfb0a2bb1b36bb47042094923 Mon Sep 17 00:00:00 2001 From: luponzo86 Date: Sun, 8 Dec 2019 15:34:42 -0800 Subject: [PATCH] add '.importFeatMatrix()' and 'ignore_PolyPhen2_errors' option to core --- rhapsody/features/PolyPhen2.py | 5 ++++- rhapsody/predict/core.py | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/rhapsody/features/PolyPhen2.py b/rhapsody/features/PolyPhen2.py index 709461c..b5ebf69 100644 --- a/rhapsody/features/PolyPhen2.py +++ b/rhapsody/features/PolyPhen2.py @@ -104,7 +104,8 @@ def _replace_strings_in_file(fname, new_fname, dict_substitutions): def queryPolyPhen2(filename, dump=True, prefix='pph2', - fasta_file=None, fix_isoforms=False, **kwargs): + fasta_file=None, fix_isoforms=False, + ignore_errors=False, **kwargs): # original PolyPhen-2 curl command (see: # http://genetics.bwh.harvard.edu/pph2/dokuwiki/faq ): # @@ -196,6 +197,8 @@ def queryPolyPhen2(filename, dump=True, prefix='pph2', if dump: outfile = f'pph2-{k}.txt' _replace_strings_in_file(outfile, outfile, orig_accs) + elif not ignore_errors: + LOGGER.warn('Please check PolyPhen-2 log file') else: LOGGER.error('Please check PolyPhen-2 log file') diff --git a/rhapsody/predict/core.py b/rhapsody/predict/core.py index b3f03bf..c05999b 100644 --- a/rhapsody/predict/core.py +++ b/rhapsody/predict/core.py @@ -60,7 +60,8 @@ def __init__(self, query=None, query_type='SAVs', queryPolyPhen2=True, 'status_file_Pfam', 'status_prefix_Uniprot', 'status_prefix_PDB', - 'status_prefix_Pfam'] + 'status_prefix_Pfam', + 'ignore_PolyPhen2_errors'] assert all([k in valid_kwargs for k in kwargs]) # masked NumPy array that will contain all info abut SAVs @@ -218,7 +219,8 @@ def queryPolyPhen2(self, query, filename='rhapsody-SAVs.txt'): # submit query to PolyPhen-2 try: PolyPhen2_output = PolyPhen2.queryPolyPhen2( - SAV_file, fix_isoforms=fix_isoforms) + SAV_file, fix_isoforms=fix_isoforms, + ignore_errors=self.options.get('ignore_PolyPhen2_errors')) except Exception as e: err = (f'Unable to get a response from PolyPhen-2: {e} \n' 'Please click "Check Status" on the server homepage \n' @@ -398,6 +400,14 @@ def _buildFeatMatrix(self, featset, all_features): feat_matrix[:, j] = array[featname] return feat_matrix + def importFeatMatrix(self, struct_array): + assert self.featMatrix is None, 'Feature matrix already set.' + assert self.featSet is not None, 'Feature set not set.' + assert self.data is not None, 'SAVs not set.' + assert len(struct_array) == self.numSAVs, 'Wrong length.' + featm = self._buildFeatMatrix(self.featSet, [struct_array]) + self.featMatrix = featm + def _calcFeatMatrix(self, refresh=False): assert self.data is not None, 'SAVs not set.' assert self.featSet is not None, 'Feature set not set.' @@ -460,7 +470,7 @@ def exportTrainingData(self, refresh=False): trainData[f] = self.featMatrix[:, i] return trainData - def importPrecomputedFeatures(self, features_dict): + def importPrecomputedExtraFeatures(self, features_dict): assert isinstance(features_dict, dict) # import additional precomputed features default_feats = RHAPSODY_FEATS['all']