Miscellanea

allel.plot_variant_locator(pos, step=None, ax=None, start=None, stop=None, flip=False, line_kwargs=None)[source]

Plot lines indicating the physical genome location of variants from a single chromosome/contig. By default the top x axis is in variant index space, and the bottom x axis is in genome position space.

Parameters:

pos : array_like

A sorted 1-dimensional array of genomic positions from a single chromosome/contig.

step : int, optional

Plot a line for every step variants.

ax : axes, optional

The axes on which to draw. If not provided, a new figure will be created.

start : int, optional

The start position for the region to draw.

stop : int, optional

The stop position for the region to draw.

flip : bool, optional

Flip the plot upside down.

line_kwargs : dict-like

Additional keyword arguments passed through to plt.Line2D.

Returns:

ax : axes

The axes on which the plot was drawn

allel.tabulate_state_transitions(x, states, pos=None)[source]

Construct a dataframe where each row provides information about a state transition.

Parameters:

x : array_like, int

1-dimensional array of state values.

states : set

Set of states of interest. Any state value not in this set will be ignored.

pos : array_like, int, optional

Array of positions corresponding to values in x.

Returns:

df : DataFrame

Notes

The resulting dataframe includes one row at the start representing the first state observation and one row at the end representing the last state observation.

Examples

>>> import allel
>>> x = [1, 1, 0, 1, 1, 2, 2, 0, 2, 1, 1]
>>> df = allel.tabulate_state_transitions(x, states={1, 2})
>>> df
   lstate  rstate  lidx  ridx
0      -1       1    -1     0
1       1       2     4     5
2       2       1     8     9
3       1      -1    10    -1
>>> pos = [2, 4, 7, 8, 10, 14, 19, 23, 28, 30, 31]
>>> df = allel.tabulate_state_transitions(x, states={1, 2}, pos=pos)
>>> df
   lstate  rstate  lidx  ridx  lpos  rpos
0      -1       1    -1     0    -1     2
1       1       2     4     5    10    14
2       2       1     8     9    28    30
3       1      -1    10    -1    31    -1
allel.tabulate_state_blocks(x, states, pos=None)[source]

Construct a dataframe where each row provides information about continuous state blocks.

Parameters:

x : array_like, int

1-dimensional array of state values.

states : set

Set of states of interest. Any state value not in this set will be ignored.

pos : array_like, int, optional

Array of positions corresponding to values in x.

Returns:

df : DataFrame

Examples

>>> import allel
>>> x = [1, 1, 0, 1, 1, 2, 2, 0, 2, 1, 1]
>>> df = allel.tabulate_state_blocks(x, states={1, 2})
>>> df
   state  support  start_lidx  start_ridx  stop_lidx  stop_ridx  size_min  \
0      1        4          -1           0          4          5         5
1      2        3           4           5          8          9         4
2      1        2           8           9         10         -1         2
   size_max is_marginal
0        -1        True
1         4       False
2        -1        True
>>> pos = [2, 4, 7, 8, 10, 14, 19, 23, 28, 30, 31]
>>> df = allel.tabulate_state_blocks(x, states={1, 2}, pos=pos)
>>> df
   state  support  start_lidx  start_ridx  stop_lidx  stop_ridx  size_min  \
0      1        4          -1           0          4          5         5
1      2        3           4           5          8          9         4
2      1        2           8           9         10         -1         2
   size_max is_marginal  start_lpos  start_rpos  stop_lpos  stop_rpos  \
0        -1        True          -1           2         10         14
1         4       False          10          14         28         30
2        -1        True          28          30         31         -1
   length_min  length_max
0           9          -1
1          15          19
2           2          -1