transitions.png

image from Project Rosalind.

This problem asks:

Given: Two DNA strings s1 and s2 of equal length (at most 1 kbp).

Return: The transition/transversion ratio R(s1,s2).

Required reading

  1. Point mutations
  2. Transitions
  3. Transversions
  4. Transition/transversion ratio

Restate the problem

I need to find everywhere that s1 and s2 are different. For each difference, I need to figure out if it’s a transition or a transversion. I need to return the ratio of transitions to transversions.

Solution steps

First, I set up two counters: transitions and transversions, and started them both at zero.

Then, I compared s1 and s2 character by character.

Every time there was a difference between the two DNA strings, I checked to see if the difference was a transition or a transversion and added 1 to the appropriate counter.

At the end, I printed the ratio of transitions to transversions in the console.