tracts.chromosome

Classes

Chrom([ls, label, tracts])

A chromosome wraps a list of tracts, which form a partition on it.

Chropair([chroms, chropair_len, auto, label])

A pair of chromosomes.

class tracts.chromosome.Chrom(ls=None, label='POP', tracts=None)

Bases: object

A chromosome wraps a list of tracts, which form a partition on it. The chromosome has a finite, immutable length.

__init__(ls=None, label='POP', tracts=None)

Constructor.

Parameters:
  • ls (int, default: None) – The length of this chromosome, in Morgans.

  • label (string, default: "POP") – An identifier categorizing this chromosome.

  • tracts (list of tract objects, default: None) – The list of tracts that span this chromosome. If None is given, then a single, unlabeled tract is created to span the whole chromosome, according to the length len.

extract(start, end)

Extracts a segment from the chromosome.

Parameters:
  • start (int) – The starting point of the desired segment to extract.

  • end (int) – The ending point of the desired segment to extract.

Returns:

A list of tract objects that span the desired interval.

Notes

Uses the goto method of this class to identify the starting and ending points of the segment, so if those positions are invalid, goto will raise a ValueError.

goto(pos)

Finds the first tract containing a given position, in Morgans, and return its index in the underlying list.

is_equal(chrom)

Check if two chromosomes are equal, in terms of their tracts.

len()

The length of this chromosome, in Morgans.

merge_ancestries(ancestries, newlabel)

Merges segments that are contiguous and either have the same ancestry or are labeled as belonging to a specified list.

The label of each tract in the chromosome’s inner list is checked against the labels listed in ancestries. If a match is found, the tract is relabeled to newlabel. This batch relabeling allows several technically different ancestries to be treated as equivalent by assigning them the same label. The resulting list is then smoothed to combine adjacent tracts with identical labels. This new list replaces the original tracts list.

Parameters:
  • ancestries (list of strings) – The ancestries to merge.

  • newlabel (string) – The identifier for the new ancestry to assign to the matching tracts.

Returns:

Nothing.

plot(canvas, colordict, height=0, chrwidth=0.1)
smooth_unknown()

Removes segments of unknown ancestry. Unknown segments at begining and end of chromosomes are removed. Internal unknwon segments are removed, extending the neighboring segments to occupy the space previously assigned to the unknown segments.

tractlengths()

Gets the list of tract lengths. Make sure that proper smoothing is implemented. Returns a tuple with ancestry, length of block, and length of chromosome.

class tracts.chromosome.Chropair(chroms=None, chropair_len=1, auto=True, label='POP')

Bases: object

A pair of chromosomes. Using chromosome pairs allows modeling of diploid individuals.

__init__(chroms=None, chropair_len=1, auto=True, label='POP')

Can be instantiated either by explicitly providing two chromosomes as a tuple, or by specifying an ancestry label, length, and autosome status.

applychrom(func)

Apply func to chromosomes.

plot(canvas, colordict, height=0)
recombine()