cgt package

cgt.distances module

Implements a number of distance measures for genomes under the position paradigm.

cgt.distances.MFPT(framework, model, scale_by=1)

Return the mean time elapsed rearranging ref->genome where the target is an absorbing state

cgt.distances.likelihood_function(framework, model, genome, attempt_exact=False, use_projections=True)

Return the likelihood function for a given genome

cgt.distances.maximise(framework, L, max_time=100)

Return the time that maximises likelihood function L, using additional information from the framework

cgt.distances.min_distance(framework, model, weighted=False)

Return dictionary of minimum distances ref->genome, using inverse of model probabilities as weights (or not)

cgt.distances.mle(framework, model, genome_instance)

Return maximum likelihood estimates for a genome instance under the given model and framework

cgt.distances.mles(framework, model, genome_instances)

Return maximum likelihood estimates for a set of genome instances under the given model and framework

cgt.enums module

class cgt.enums.ALGEBRA(value)

Bases: enum.Enum

An enumeration.

genome = 2
genome_class = 3
group = 1
class cgt.enums.CLASSES(value)

Bases: enum.Enum

An enumeration.

conjugacy_classes = 1
cosets = 2
double_cosets = 3
class cgt.enums.DISPLAY(value)

Bases: enum.Enum

An enumeration.

arrows = 1
cycles = 3
one_row = 2
class cgt.enums.FORMAT(value)

Bases: enum.Enum

An enumeration.

dictionary = 3
equiv_classes = 2
formal_sum = 1
only_reps = 4
class cgt.enums.MODEL(value)

Bases: enum.Enum

An enumeration.

all_inversions = 'all inversions'
one_region_inversions = 'inversions of a single region'
one_region_swaps = 'adjacent transpositions'
two_region_adjacent_transpositions = 'transpositions of two adjacent regions'
two_region_inversions = 'inversions of two adjacent regions'
class cgt.enums.SET(value)

Bases: enum.Enum

An enumeration.

one_row = 3
signed_cycles = 1
unsigned_cycles = 2
wreath = 4
wreath_s2 = 5
class cgt.enums.SYMMETRY(value)

Bases: enum.Enum

An enumeration.

C_2 = 2
D_n = 1
S_2 = 2
circular = 1
dihedral = 1
flip = 2
linear = 2
reflection = 2
class cgt.enums.TYPE(value)

Bases: enum.Enum

An enumeration.

pos_to_signed_reg = 2
reg_to_signed_pos = 1
signed_pos_to_reg = 4
signed_reg_to_pos = 3

cgt.examples module


cgt.genome module

class cgt.genome.Genome(framework, genome)

Bases: object

Optional wrapper for genomes, so that they can be printed/operated on in a more pythonic way.

cgt.models module

class cgt.models.Model(framework, generating_dictionary)

Bases: object

Defines a model. A model consists of some collection of permutations and a map from these permutations to probabilities [0,1]

classmethod named_model_with_relative_probs(framework, named_model_dictionary)

Return the regular representation of zs as comptued by PositionParadigmFramework.reg_rep_zs, but store the sparse result

s_element(in_algebra=<ALGEBRA.genome: 2>)

cgt.position_paradigm module

position_paradigm is the most important module in cgt. PositionParadigmFramework keeps track of important objects, can convert group elements and genomes between different forms, and instances can be passed to functions from other modules so that they can acces information without it needing to be recreated.

class cgt.position_paradigm.PositionParadigmFramework(num_regions, oriented=True, symmetry=None, genome_type=<TYPE.reg_to_signed_pos: 1>)

Bases: object

Everything you need for working with genomes under the position paradigm


Return the ‘canonical’ instance of the genome represented by the permutation if there is one.


sage: import cgt; ppf = cgt.PositionParadigmFramework(3, symmetry=cgt.SYMMETRY.circular) sage: ppf.canonical_instance(‘(1,-2)(-1,2)’) [1, 2, -3]

coefficient_in(more_terms, fewer_terms)

For example, the coefficient of (a/2 + b/2) in x=(a/3 + b/3 + c/3) is 2/3, since x=2/3*(a/2 + b/2) + c/3

collect_genome_terms(formal_sum, display=<DISPLAY.one_row: 2>)

Return a weighted sum of genomes, represented as [canonical representation]z

draw_instance(instance, shortened=False)

Return a one-line drawing of a genome using arrows indicating orientation and elipsis indicating rotational symmetry

genome(instance, format=None)
genome_equivalence_classes(combine_inverse_classes=False, sort_classes=True)

Return double cosets of instances—genomes in the same class will have the same likelihood functions


Return the permutation group containing genome instances.

genomes(format=<FORMAT.dictionary: 3>, sort_genomes=True)

Return the group alegbra, where the group is the group containing genome instances.


Return a complete list of pairwise irreducible representations of the genome group.


element – return the image of element for each irreducible representation.


a complete list of pairwise irreducible representations of the genome group, or a list of matrices if element is not None. Output is cached so that irreps are computed only once per session. Matrix entries sit inside the UniversalCyclotomicField and are exact expressions.


Return the defining representation matrix. Note that matrix(x)matrix(y) = matrix(yx)


Return the number of distinct genomes up to symmetries.

one_row(element, as_list=False)

Return a given genome instance in one-row notation.

  • element – the genome instance to represent in one-row notation. Multiple formats accepted.

  • as_list – if true, return as a list of images, otherwise return a sage permutation.


sage: import cgt sage: ppf = cgt.PositionParadigmFramework(3) sage: ppf.cycles(ppf.one_row(‘(1,-2)(-1,2)’)) == ppf.cycles(‘(1,-2)(-1,2)’) True

random_genome(format=<FORMAT.formal_sum: 1>)

Return a random genome


Return a random permutation corresponding to a given genome, or a random genome if none is given.

reg_rep_of_zs(model, to_adjacency_matrix=False, sparse=True)

Return the regular representation of a single element


Return a permutation which reflects a genome instance about the center region (n odd), or the center two regions (n even).


Return a permutation which rotates positions clockwise by one position.


Return the symmetry element: a convex sum of elements from symmetry_group().


Return the symmetry group of the genomes.

cgt.rearrangements module

cgt.rearrangements.all_adjacent_transpositions_representatives(framework, num_regions=None)
cgt.rearrangements.all_inversions_representatives(framework, num_regions=None)
cgt.rearrangements.conjugacy_class(framework, perm)
cgt.rearrangements.cuts(framework, sigma)
cgt.rearrangements.double_coset(framework, perm)
cgt.rearrangements.single_coset(framework, perm)

cgt.structures module

A place for functions which return important but general algebraic structures requiring only a few parameters


Return the hyperoctahedral group of order (2^n)n! as a subgroup of SymmetricGroup(2n) with two generators.


cgt.visualisation module

cgt.visualisation.draw_genome_instance(framework, instance, show=False)

Produce a drawing of a circular genome with n regions