Note that the equation for the probability of a dictionary (introduced in “Compute the Size of a Spectral Dictionary”1),

$$\mathrm{Pr}(\textit{Dictionary}) = \displaystyle\sum_{\text{each peptide }\textit{Peptide}\text{ in }\textit{Dictionary}} \dfrac{1}{20^{|\textit{Peptide}|}},$$

is similar to an equation for the size of a dictionary,

$$|\textit{Dictionary}|= \displaystyle\sum_{\text{each peptide }\textit{Peptide}\text{ in }\textit{Dictionary}}1.$$

This similarity suggests that we can derive a recurrence for the probability of a dictionary using arguments similar to those used to find the size of a dictionary.

So define Pr(i, t) as the sum of probabilities of all peptides with mass i for which Score(Peptide, Spectrum') is equal to t. The set of peptides contributing to Pr(i, t) can be split into 20 subsets depending on their final amino acid. Each peptide Peptide ending in a specific amino acid a results in a shorter peptide Peptidea if we remove a; Peptidea has mass i − |a| and score tsi. Since the probability of Peptide is 20 times smaller than the probability of Peptidea, the contribution of Peptide to Pr(i, t) is 20 times smaller than contribution of Peptidea to Pr(i − |a|, tsi ). Therefore, Pr(i, t) can be computed as

$$\mathrm{Pr}(i, t) = \displaystyle\sum_{\text{all amino acids }a} \frac{1}{20} \cdot \mathrm{Pr}(i - |a|, t - s_i),$$

which differs from the recurrence for computing Size(i, t) only in the presence of the factor 1/20. We can now compute the probability of a spectral dictionary as

$$\mathrm{Pr}(\textit{Dictionary}_{\textit{threshold}}({\textit{Spectrum'}})) = \displaystyle\sum_{t \geq \textit{threshold}} \mathrm{Pr}(m, t)$$.

Assignment

Given a file with a spectral vector Spectrum', an integer threshold, and an integer max_score.

Return the probability of the dictionary Dictionarythreshold(Spectrum').

Remark

Use the provided max_score for the height of your table. Your answer should be the number of peptides whose score is at least threshold and at most max_score.

Example

>>> spectral_dictionary_probability('data02.txt'2, 19, 39)
0.005125

>>> spectral_dictionary_probability('data03.txt'3, 19, 43)
0.000375

>>> spectral_dictionary_probability('data04.txt'4, 11, 32)
0.0012348468750000001