Transition and Transversion Ratio

Intermediate Bioinformatics Mutations Molecular Evolution Ratios Formatting
Significance:

Not all point mutations are equally likely. Transitions — swaps within the purines
(A and G) or within the pyrimidines (C and T) — occur far more often than transversions, which
cross between the two chemical classes. The observed ratio is typically around 2 for genomic DNA and
higher still in coding regions, and it is a standard sanity check on variant-calling output: a ratio
far from the expected value usually means false positives have crept in.

Statement

You are given two DNA sequences of equal length. At each position where they differ,
classify the substitution as either a transition (A<->G or C<->T) or a transversion (any
other change).

Print the ratio of transitions to transversions, rounded to four decimal places.

If there are no transversions, print INF instead.

Input — read from standard input
Variable Type Description
s1
line 1
str The first DNA sequence
1 <= len(s1) <= 5000, uppercase A, C, G, T only
s2
line 2
str The second DNA sequence, same length as s1
len(s2) == len(s1)

These variables are already read for you in the starter code on the right.

Output

str transition-to-transversion ratio to four decimal places, or the literal string INF

Sample Cases
Sample 1
Input
GCAACGCACAACGAAAACCCTTAGGGACTGGATTATTTCGTGATCGTTGTAGTTATTGGAAGTACGGGCATCAACCCAGTT
TTATCTGACAAAGAAAGCCGTCAACGGCTGGATAATTTCGCGATCGTGCTGGTTACTGGCGGTACGAGTGTTCCTTTGGGT
Expected Output
1.2143
A realistic pair of homologous sequences giving a ratio close to the expected genomic value.
Sample 2
Input
AG
GA
Expected Output
INF
Both positions are purine-to-purine transitions and there are no transversions.

Submit also runs your code against 5 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.

Constraints
  • 1 <= length(s1) = length(s2) <= 5000
  • Both sequences contain only uppercase A, C, G, T
  • Positions where the two sequences agree are ignored entirely
  • Output exactly four decimal places, or the literal INF when the transversion count is zero
Further Reading
  • Purines are {A, G} and pyrimidines are {C, T}; a transition keeps you within one set.
  • A single set membership check is cleaner than enumerating all four transition pairs.
  • Handle the zero-transversion case before dividing, not with a try/except afterwards.

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: s1 (str), s2 (str)
Next Problem
Pairwise p-Distance Matrix