To generalize the cyclopeptide sequencing problem from "Find a cyclic peptide with a given ideal spectrum1" to handle noisy spectra, we need to relax the requirement that a candidate peptide's theoretical spectrum must match the experimental spectrum exactly, and instead incorporate a scoring function that will select the peptide whose theoretical spectrum matches the given experimental spectrum the most closely. Given a cyclic peptide $$p$$ and a spectrum $$s$$, we define ScoreC($$p$$, $$s$$) as the number of masses shared between Cyclospectrum($$p$$) and $$s$$. As an example, if

$$s$$ = {0, 99, 113, 114, 128, 227, 257, 299, 355, 356, 370, 371, 484}

then

ScoreC(NQEL, $$s$$) = 11

The scoring function should take into account the multiplicities of shared masses, i.e., how many times they occur in each spectrum. For example, suppose that $$s$$ is the theoretical spectrum of the cyclic peptide NQEL. For this spectrum, mass 242 has multiplicity 2. If 242 has multiplicity 1 in the theoretical spectrum of cyclic peptide $$p$$, then 242 contributes 1 to ScoreC($$p$$, $$s$$). If 242 has larger multiplicity in the theoretical spectrum of $$p$$, then 242 contributes 2 to ScoreC($$p$$, $$s$$).

Assignment

Write a function score that takes a cyclic peptide $$p$$ and a spectrum $$s$$. The function must return the score of cyclic peptide $$p$$ against spectrum $$s$$: ScoreC($$p$$, $$s$$).

Example

>>> score('NQEL', (0, 99, 113, 114, 128, 227, 257, 299, 355, 356, 370, 371, 484))
11
>>> score('VYYEVDWTMGRQIDPDEYPIAQCTRHRATILTLPDWQM', (0, 71, 71, 87, 87, 97, 97, ..., 4622, 4622, 4693))
521
>>> score('PCWHYNGEDTLRHWAPFQPWWDAWWDIYLEIHCWRM', (0, 57, 71, 71, 97, 97, 97, ..., 4542, 4556, 4613))
311