Struct recmap::recmap::RecMap

source ·
pub struct RecMap {
    pub map: GenomeMap<RateMap>,
    pub metadata: Option<Vec<String>>,
}

Fields§

§map: GenomeMap<RateMap>§metadata: Option<Vec<String>>

Implementations§

source§

impl RecMap

source

pub fn from_hapmap( filepath: &str, seqlens: &IndexMap<String, Position> ) -> Result<RecMap, RecMapError>

Create a new RecMap from a (possibly gzip-compressed) HapMap-formatted recombination map file.

The HapMap recombination map format is (rather unfortunately) very poorly specified. This parser is quite permissive, and skips through comment lines that begin with # and a possible header line that beings with Chr. Note that this parser does not read the cumulative map positions. Instead, the cumulative map positions can be calculated directly from the rates and the distances between markers.

The HapMap recombination format looks like:

Chromosome      Position(bp)    Rate(cM/Mb)     Map(cM)
chr1    55550   2.981822        0.000000
chr1    82571   2.082414        0.080572
chr1    88169   2.081358        0.092229
chr1    254996  3.354927        0.439456
chr1    564598  2.887498        1.478148
chr1    564621  2.885864        1.478214
chr1    565433  2.883892        1.480558
chr1    568322  2.887570        1.488889
chr1    568527  2.895420        1.489481

The HapMap format is well-described in the tskit documentation.

§Warnings

Given that the HapMap recombination map format is poorly specified, and users often implement their own versions, it is highly recommended that you always validate the parsed recombination map. Ideally check that:

  • The total map length (i.e. in Morgans or centiMorgans) makes sense. Off-by-one errors due to the format not following the 0-indexed end-exclusive format assumed by [RecMap.from_hapmap] will often lead to obviously erroneous total map lengths.
  • Visually plot the recombination map, looking for outlier rates.
  • If the recombination map includes a fourth
source

pub fn len(&self) -> usize

Return the number of chromosomes in the recombination map.

source

pub fn is_empty(&self) -> bool

Return if the recombination map is empty.

source

pub fn iter(&self) -> impl Iterator<Item = (&String, &RateMap)>

Iterate over chromosome name and RateMap tuples.

source

pub fn interpolate_map_position( &self, name: &str, position: Position ) -> Result<RateFloat, RecMapError>

Interpolate the recombination map position at the specified physical position. This uses linear interpolation.

§Arguments
  • name: the chromosome name.
  • position: the physical position to estimate the recombination map position at.
source

pub fn interpolate_map_positions( &self, chrom: &str, positions: &[Position] ) -> Result<Vec<RateFloat>, RecMapError>

Interpolate the recombination map position at the specified physical positions. This uses linear interpolation.

§Arguments
  • name: the chromosome name.
  • position: the physical position to estimate the recombination map position at.
source

pub fn recomb_dist_matrix( &self, chrom: &str, positions_x: &[Position], positions_y: &[Position], haldane: bool, rec_floor: Option<RateFloat> ) -> Result<Array2<RateFloat>, RecMapError>

Build the pairwise recombination distance matrix for the specified chromosome.

Creates a positions_x.len() x positions_y.len() matrix of recombination distances (in Morgans), for the supplied set of positions on the physical map.

§Arguments
  • positions_x: the first set of marker positions.
  • positions_y: the second set of marker positions (just repeat positions_x for a symmetric distance matrix).
  • haldane: whether to convert the recombination distances in Morgans to a unit-less recombination fraction.
  • rec_floor: an optional floor value; all elements in the matrix less than this value will be set to this value. This is sometimes useful in downstream processing when zero values create problems.
source

pub fn write_hapmap(&self, filepath: Option<&str>) -> Result<(), RecMapError>

Write recombination map to HapMap-formatted file.

This file has the usual HapMap recombination map header, and columns:

  1. Chromosome name
  2. Position (0-indexed and right-exclusive)
  3. Rate
  4. Map position
§Arguments
  • filepath: The filepath to write the recombination map to. If the filepath has an .gz extension, the output will be gzip compressed. If filepath is None, uncompressed output will be written to standard out.
source

pub fn write_tsv(&self, filepath: Option<&str>) -> Result<(), RecMapError>

Write recombination map to a BED-like TSV file.

This file has columns:

  1. Chromosome name
  2. Start position (0-indexed)
  3. End position (0-indexed and right-exclusive)
  4. Rate
§Arguments
  • filepath: The filepath to write the recombination map to. If the filepath has an .gz extension, the output will be gzip compressed. If filepath is None, uncompressed output will be written to standard out.

Trait Implementations§

source§

impl Clone for RecMap

source§

fn clone(&self) -> RecMap

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RecMap

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for RecMap

source§

fn default() -> RecMap

Returns the “default value” for a type. Read more
source§

impl PartialEq for RecMap

source§

fn eq(&self, other: &RecMap) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for RecMap

Auto Trait Implementations§

§

impl Freeze for RecMap

§

impl RefUnwindSafe for RecMap

§

impl Send for RecMap

§

impl Sync for RecMap

§

impl Unpin for RecMap

§

impl UnwindSafe for RecMap

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.