pub struct RecMap {
pub map: GenomeMap<RateMap>,
pub metadata: Option<Vec<String>>,
}
Fields§
§map: GenomeMap<RateMap>
§metadata: Option<Vec<String>>
Implementations§
source§impl RecMap
impl RecMap
sourcepub fn from_hapmap(
filepath: &str,
seqlens: &IndexMap<String, Position>
) -> Result<RecMap, RecMapError>
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
sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &RateMap)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &RateMap)>
Iterate over chromosome name and RateMap
tuples.
sourcepub fn interpolate_map_position(
&self,
name: &str,
position: Position
) -> Result<RateFloat, RecMapError>
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.
sourcepub fn interpolate_map_positions(
&self,
chrom: &str,
positions: &[Position]
) -> Result<Vec<RateFloat>, RecMapError>
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.
sourcepub fn recomb_dist_matrix(
&self,
chrom: &str,
positions_x: &[Position],
positions_y: &[Position],
haldane: bool,
rec_floor: Option<RateFloat>
) -> Result<Array2<RateFloat>, RecMapError>
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 repeatpositions_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.
sourcepub fn write_hapmap(&self, filepath: Option<&str>) -> Result<(), RecMapError>
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:
- Chromosome name
- Position (0-indexed and right-exclusive)
- Rate
- 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. Iffilepath
isNone
, uncompressed output will be written to standard out.
sourcepub fn write_tsv(&self, filepath: Option<&str>) -> Result<(), RecMapError>
pub fn write_tsv(&self, filepath: Option<&str>) -> Result<(), RecMapError>
Write recombination map to a BED-like TSV file.
This file has columns:
- Chromosome name
- Start position (0-indexed)
- End position (0-indexed and right-exclusive)
- Rate
§Arguments
filepath
: The filepath to write the recombination map to. If the filepath has an.gz
extension, the output will be gzip compressed. Iffilepath
isNone
, uncompressed output will be written to standard out.