The colored edges in the breakpoint graph of $$P$$ and $$Q$$ are given by ColoredEdges($$P$$) together with ColoredEdges($$Q$$). Note that some edges in these two sets may connect the same two nodes, which results in trivial cycles.
We will find it helpful to implement a function converting a genome graph $$g$$ back into a genome.
GraphToGenome(Ggraph) G ← empty genome (no chromosomes) for each cycle N in genome graph Ggraph C ← CycleToChromosome(N) add chromosome C to genome G return genome G
Define a class GenomeGraph that is defined by a collection of undirected edges (the colored edges of the genome). The initialisation method takes zero or more colored edges, represented as tuples $$(x, y)$$. Make sure the built-in functions repr and str return string representations of objects of the class GenomeGraph that are formatted according to the example given below.
The class GenomeGraph must support at least the following methods:
A method cycles that takes no arguments. The method must return an iterator that yields all cycles (objects of the class Cycle) of the genome graph.
A method to_genome that takes no arguments. The method must implement GraphToGenome and return the genome (an object of the class Genome) that corresponds to the genome graph.
>>> graph = GenomeGraph((2, 4), (3, 6), (5, 1), (7, 9), (10, 12), (11, 8)) >>> graph GenomeGraph((1, 5), (10, 12), (2, 4), (3, 6), (7, 9), (8, 11)) >>> print(graph) (1, 5), (10, 12), (2, 4), (3, 6), (7, 9), (8, 11) >>> set(graph.cycles()) {Cycle(4, 3, 6, 5, 1, 2), Cycle(12, 11, 8, 7, 9, 10)} >>> genome = graph.to_genome() >>> genome Genome(Chromosome(-2, -3, 1), Chromosome(-6, -4, 5)) >>> print(genome) (-2 -3 +1)(-6 -4 +5)