API¶
- class tspop.PopAncestry(left, right, population, ancestor, child, sample_nodes, sequence_length)¶
Bases:
objectIn most cases, this should be created with the
tspop.get_pop_ancestry()method. An object holding local ancestry information, and various summaries of that information.- Parameters:
- ancestry_table¶
A pandas.DataFrame object with column labels
sample,left,right,ancestor,population. Each row (sample,left,right,ancestor,population) indicates that over the genomic interval with coordinates [left,right), the sample node with IDsamplehas inherited from the ancestral node with IDancestorin the population with IDpopulation. Ancestral nodes and population labels are taken from the specified census time.
- ancestry_table_write_csv(outfile, **kwargs)¶
Writes the ancestry table to a csv file.
param outfile: The name of the output file. type: str param kwargs: other keyword arguments for pandas.to_csv
- calculate_ancestry_fraction(population, sample=None)¶
Returns the total fraction of genomic material inherited from a given population.
- coverage¶
The proportion of the total genome length with an ancestor in the
tspop.PopAncestry.squashed_tableandtspop.PopAncestry.ancestry_table.
- num_ancestors¶
The number of ancestral haplotypes. Strictly less than or equal to the number of inputted ancestral nodes.
- num_samples¶
The number of provided samples.
- plot_karyotypes(sample_pair, colors=None, pop_labels=None, title=None, length_in_Mb=True, outfile=None, height=12, width=20)¶
Note
Diploid only for now.
Creates a plot of the ancestry tracts in a sample pair of chromosomes using
matplotlib.- Parameters:
sample_pair (list(int)) – a pair of sample node IDs in the PopAncestry object.
colors (list(str)) – A list of pyplot-compatible colours to use for the ancestral populations, given in order of their appearance in the
tspop.PopAncestry.squashed_table. If None, uses the default matplotlib colour cycle.pop_labels (list(str)) – Ancestral population labels for the plot legend. If None, defaults to Pop0, Pop1 etc.
title (str) – The title of the plot. If None, defaults to ‘Ancestry in admixed individual’.
length_in_Mb (bool) – Whether or not to label the horizontal axis in megabases. Defaults to True.
outfile (str) – The name of the output file. If None, the plot opens with the system viewer.
height (float) – The height of the figure in inches.
width (float) – The width of the figure in inches.
- Returns:
a matplotlib figure.
- squashed_table¶
A pandas.DataFrame object with column labels
sample,left,right,population. Each row (sample,left,right,population) indicates that over the genomic interval with coordinates [left,right), the sample node with IDsamplehas inherited from an ancestral node in the population with IDpopulation. Population labels are taken from the specified census time.
- squashed_table_write_csv(outfile, **kwargs)¶
Writes the squashed table to a csv file.
param outfile: The name of the output file. type: str param kwargs: other keyword arguments for pandas.to_csv
- subset_tables(subset_samples, inplace=False)¶
Subsets the ancestry table and squashed table by sample. Note: by default this returns a copy of the original tables. To overwrite the original tables, set inplace=True. (In this case, the function returns nothing).
- total_genome_length¶
Sequence length times the number of samples.
- tspop.get_pop_ancestry(ts, census_time)¶
Creates a
tspop.PopAncestryobject from a simulated tree sequence containing ancestral census nodes. These are the ancestors that population-based ancestry will be calculated with respect to.- Parameters:
- Returns:
a
tspop.PopAncestryobject