The following pseudocode bypasses the intermediate step of assigning head and tail nodes in order to transform a single circular chromosome $$C = (c_1, c_2, \ldots, c_m)$$ into a cycle represented as a sequence of integers $$N = (n_1, n_2 , \ldots, n_{2m})$$.

ChromosomeToCycle(C)
    for j ← 1 to |C|
        icj
        if i > 0
            n2j - 1 ← 2i - 1
            n2j ← 2i
        else
            n2j - 1 ← -2i
            n2j ← -2i - 1
    return N

Assignment

Define a class Cycle that represents a cyclic sequence of integers, where the last integer is again followed by the first integer in the sequence. Objects of this class are immutable and the initialisation method takes one or more integer arguments. Make sure the built-in functions repr and str return string representations of objects of the class Cycle that are formatted according to the example given below.

Define another class Chromosome that subclasses SignedPermutation. In other words, a chromosome is represented as a signed permutation where each integer represents a synteny block, with the positive/negative sign of the integer indicating the block's direction. As with signed permutations, objects of this class are also immutable.

Make sure the built-in functions repr and str return string representations of objects of the class Chromosome that are formatted according to the example given below. In particular, the string representation returned by the repr function should mention the class name Chromosome.

The class Chromosome should support an additional method to_cycle that takes no arguments. The method must implement ChromosomeToCycle on chromosomes and return their corresponding cycle (an object of the class Cycle) representation.

Example

>>> cycle = Cycle(1, 2, 4, 3, 6, 5, 7, 8)
>>> cycle
Cycle(1, 2, 4, 3, 6, 5, 7, 8)
>>> print(cycle)
(1 2 4 3 6 5 7 8)

>>> chromosome = Chromosome(+1, -2, -3, +4)
>>> chromosome
Chromosome(1, -2, -3, 4)
>>> print(chromosome)
(+1 -2 -3 +4)
>>> chromosome.to_cycle()
Cycle(1, 2, 4, 3, 6, 5, 7, 8)