<p>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 <code>Bio.SeqUtils.ProtParam.ProteinAnalysis</code> and overwrites the method relevant methods.</p>
<p>Having a gander at the files one sees the following:</p>
<pre><code>def protein_scale(self, param_dict, window, edge_list: list):
    &quot;&quot;&quot;[...]
    &quot;&quot;&quot;
    # 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 = []
    ...
</code></pre>
<p>So the weights are generated by the 'private' method <code>._weight_list</code>. 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...</p>
<pre><code>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(&quot;Weight method hack done!&quot;)
               return overriding_weights
          else: # behave normally
               return super()._weight_list(window, edge)
</code></pre>
<p>So you'd do:</p>
<pre><code>Y = JankyProteinAnalysis('MSTAEFAQLL')
Y.overriding_weights = [0,0.2,0.3,0.1,0.,0.4,0.5,0.8,0.8,1.]
Y.protein_scale(Bio.SeqUtils.ProtParamData.kd,10,float('nan'))
</code></pre>
<p>Note that the <code>edge</code> argument is no longer doing anything.</p>

CC BY-SA 4.0
2020-08-05T19:45:27.860Z
Thanks so much! Super helpful.
mzzx
CC BY-SA 4.0
2020-08-02T11:39:50.360Z
2020-08-02T11:39:50.360Z
Matteo Ferla
<p>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 <a href="https://bioinformatics.stackexchange.com/questions/7396/how-to-allow-half-windows-in-biopython">How to allow &quot;half windows&quot; in biopython?</a> I understand that the weights are symmetric and calculated automatically given a window size.</p>
<p>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?</p>
<p>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:</p>
<pre><code>```Y = ProteinAnalysis('MSTAEFAQLL')
Y.protein_scale(Bio.SeqUtils.ProtParamData.kd,10)
Y.protein_scale(Bio.SeqUtils.ProtParamData.kd,10,edge[0,0.2,0.3,0.1,0.,0.4,0.5,0.8,0.8,1.])```
</code></pre>
<p>Of course I can code this myself, but was wondering if that functionality already existed.</p>

<proteins><python>
Modifying protein_scale in ProteinAnalysis in SeqUtil in Biopython?
# Modifying protein_scale in ProteinAnalysis in SeqUtil in Biopython?

(Asked by: username_0 on 2020-07-31)

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')
Y.protein_scale(Bio.SeqUtils.ProtParamData.kd,10)
Y.protein_scale(Bio.SeqUtils.ProtParamData.kd,10,edge[0,0.2,0.3,0.1,0.,0.4,0.5,0.8,0.8,1.])```

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

**Tags:** proteins, python

---

## 1 answers

### Answer by username_1 on 2020-08-02. Score: 3 | Accepted answer

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.]
Y.protein_scale(Bio.SeqUtils.ProtParamData.kd,10,float('nan'))

Note that the edge argument is no longer doing anything.

> **Comments:**
> **username_0**: Thanks so much! Super helpful.  

---

