Is there a way to give weight arguments to each of the residues when using protein_scale in the ProteinAnalysis module of Bio.SeqUtils.ProtParam? I thought this would be done with the window and edge arguments, but from the documentation and the question How to allow "half windows" in biopython? I understand that the weights are symmetric and calculated automatically given a window size.

I'd like to understand what the idea behind this was, just to check that I understand this correctly. For example, if one calculates eg. hydrophobicity of a protein, why should it be a value per residue that depends on a particular window?

I was looking for a functionality like where the value given for each residue in the ParamData dictionary would be multiplied by a specified weight, like so:

```Y = ProteinAnalysis('MSTAEFAQLL')

Of course I can code this myself, but was wondering if that functionality already existed.


There is not a way to control the edge weights as written, but making a modified version is straightforward. Namely make a class that inherits the class Bio.SeqUtils.ProtParam.ProteinAnalysis and overwrites the method relevant methods.

Having a gander at the files one sees the following:

def protein_scale(self, param_dict, window, edge_list: list):
    # generate the weights
    #   _weight_list returns only one tail. If the list should be
    #   [0.4,0.7,1.0,0.7,0.4] what you actually get from _weights_list
    #   is [0.4,0.7]. The correct calculation is done in the loop.
    weights = self._weight_list(window, edge)
    scores = []

So the weights are generated by the 'private' method ._weight_list. Underscore means it is for internal use and for production code it is bad to assume that the name of the private method many not change, but Biopython has not changed in years so you'd be safe. And this is for a quick hack anyway...

class JankyProteinAnalysis(Bio.SeqUtils.ProtParam.ProteinAnalysis):
    overriding_weights = None
    def _weight_list(self, window, edge):
          if self.overriding_weights is not None: # dodgy override!
               print("Weight method hack done!")
               return overriding_weights
          else: # behave normally
               return super()._weight_list(window, edge)

So you'd do:

Y = JankyProteinAnalysis('MSTAEFAQLL')
Y.overriding_weights = [0,0.2,0.3,0.1,0.,0.4,0.5,0.8,0.8,1.]

Note that the edge argument is no longer doing anything.

  • $\begingroup$ Thanks so much! Super helpful. $\endgroup$ – mzzx Aug 5 '20 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.