Skip to content

Commit

Permalink
add '.importFeatMatrix()' and 'ignore_PolyPhen2_errors' option to core
Browse files Browse the repository at this point in the history
  • Loading branch information
luponzo86 committed Dec 8, 2019
1 parent c43117b commit a584f74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion rhapsody/features/PolyPhen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ):
#
Expand Down Expand Up @@ -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')

Expand Down
16 changes: 13 additions & 3 deletions rhapsody/predict/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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.'
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit a584f74

Please sign in to comment.