Welcome to pylibseq’s documentation!

If you use pylibseq in your research please cite the following papers: [9]

Contents:

Functions and classes

class libsequence.VariantMatrix(*args, **kwargs)

Representation of variation data in matrix format.

see The VariantMatrix for discussion.

Overloaded function.

  1. __init__(self: libsequence._libsequence.VariantMatrix, data: List[int], positions: List[float]) -> None

    Construct with a lists of input data.

    param data:The state data.
    type data:list
    param positions:
     List of mutation positions.
    type positions:list
    >>> import libsequence
    >>> m = libsequence.VariantMatrix([0,1,1,0],[0.1,0.2])
    
  2. __init__(self: libsequence._libsequence.VariantMatrix, data: numpy.ndarray[int8], pos: numpy.ndarray[float64], max_allele_value: int = -1) -> None

    Construct with numpy arrays

    param data:2d ndarray with dtype numpy.int8
    type data:list
    param positions:
     1d array with dtype np.float
    type positions:list
    >>> import libsequence
    >>> import numpy as np
    >>> d = np.array([0,1,1,0],dtype=np.int8).reshape((2,2))
    >>> p = np.array([0.1,0.2])
    >>> m = libsequence.VariantMatrix(d,p)
    
count_alleles(self: libsequence._libsequence.VariantMatrix) → libsequence._libsequence.AlleleCountMatrix
data

Return raw data as numpy array

from_TreeSequence(ts: object) → libsequence._libsequence.VariantMatrix

Create a VariantMatrix from an msprime.TreeSequence

Parameters:ts – A TreeSequence from msprime [5].

A TreeSequence object is the output of msprime.simulate, or, equivalently, certain forward simulations that use that format for storing results.

This function is a convenience function. Internally, the output from msprime are cast from 8-bit unsigned integers to 8-bit signed integers.

nsam

Number of samples

nsites

Number of positions

positions

Return positions as numpy array

sample(self: libsequence._libsequence.VariantMatrix, i: int) → Sequence::internal::col_view_<signed char const*>

Return a view of the i-th sample.

Parameters:i (int) – Index
Return type:libsequence.variantmatrix.ConstColView
site(self: libsequence._libsequence.VariantMatrix, i: int) → Sequence::internal::row_view_<signed char const*>

Return a view of the i-th site.

Parameters:i (int) – Index
Return type:libsequence.variant_matrix.ConstRowView
slice(self: libsequence._libsequence.VariantMatrix, beg: float, end: float, i: int, j: int) → libsequence._libsequence.VariantMatrix
window(self: libsequence._libsequence.VariantMatrix, beg: float, end: float) → libsequence._libsequence.VariantMatrix
class libsequence.AlleleCountMatrix(*args, **kwargs)

A matrix of allele counts. This object supports the buffer protocol.

Overloaded function.

  1. __init__(self: libsequence._libsequence.AlleleCountMatrix, arg0: Sequence::VariantMatrix) -> None

Construct from a libsequence.variant_matrix.VariantMatrix

  1. __init__(self: libsequence._libsequence.AlleleCountMatrix, arg0: List[int], arg1: int, arg2: int, arg3: int) -> None
counts

Flattened view of the raw data.

from_tskit(ts: object, max_allele_value: int = 1) → libsequence._libsequence.AlleleCountMatrix

Construct AlleleCountMatrix from a tree sequence object from tskit

Parameters:
  • ts (tskit.TreeSequence) – A tree sequence
  • max_allele_value (int8) – Maximum numeric value for a mutation
Return type:

libsequence.AlleleCountMatrix

New in version 0.2.3.

>>> import msprime
>>> import libsequence
>>> import numpy as np
>>> ts = msprime.simulate(10, mutation_rate=100)
>>> ac = libsequence.AlleleCountMatrix.from_tskit(ts)
>>> vm = libsequence.VariantMatrix.from_TreeSequence(ts)
>>> vmac = libsequence.AlleleCountMatrix(vm)
>>> assert np.array_equal(np.array(ac), np.array(vmac))
ncol

Number of columns (allelic states) in the matrix.

nrow

Number of rows (sites) in the matrix.

nsam

Sample size of the original VariantMatrix.

row(self: libsequence._libsequence.AlleleCountMatrix, i: int) → iterator

Return an iterator over the i-th site.

class libsequence.ColView

View of a VariantMatrix column.

See The VariantMatrix

as_list(self: libsequence._libsequence.ColView) → list

Return contents as a list.

class libsequence.ConstColView

Immutable view of a VariantMatrix column.

See The VariantMatrix.

as_list(self: libsequence._libsequence.ConstColView) → list

Return contents as a list.

class libsequence.RowView

View of a sample in a VariantMatrix.

See The VariantMatrix.

as_list(self: libsequence._libsequence.RowView) → list
class libsequence.ConstRowView

Immutable view of a sample.

See The VariantMatrix.

as_list(self: libsequence._libsequence.ConstRowView) → list

Return contents as a list.

class libsequence.StateCounts(*args, **kwargs)

Count the states at a site in a VariantMatrix.

See The VariantMatrix

Overloaded function.

  1. __init__(self: libsequence._libsequence.StateCounts) -> None
  2. __init__(self: libsequence._libsequence.StateCounts, refstate: int) -> None
counts

The counts for each possible non-missing allelic state

n

The sample size.

refstate

The reference state.

Deprecated functions and classes

Indices and tables