Minimac4
Loading...
Searching...
No Matches
genetic_map_file Class Reference

A reader and interpolator for genetic map files. More...

#include <recombination.hpp>

Classes

struct  record
 A single line entry from the genetic map file. More...
 

Public Member Functions

 genetic_map_file (const std::string &map_file_path, const std::string &chrom)
 Constructs a genetic_map_file object for reading recombination map data.
 
bool good () const
 Check whether the genetic map file was loaded successfully.
 
 operator bool () const
 Implicit conversion to bool for validity checking.
 
double interpolate_centimorgan (std::size_t variant_pos)
 Interpolate the genetic map position (in centimorgans) for a variant.
 

Detailed Description

A reader and interpolator for genetic map files.

The genetic_map_file class provides an interface to read recombination rate data from a genetic map file and interpolate genetic distances (in centimorgans) for arbitrary variant positions.

The file may be in one of two formats:

  • New format: Three columns — chrom pos cM
  • Legacy format: Four columns — chrom <discard> cM pos

Only entries corresponding to the specified target chromosome are processed.

See also
record, read_record(), interpolate_centimorgan()

Constructor & Destructor Documentation

◆ genetic_map_file()

genetic_map_file::genetic_map_file ( const std::string & map_file_path,
const std::string & chrom )

Constructs a genetic_map_file object for reading recombination map data.

This constructor opens a genetic map file and prepares it for iterating over recombination map records associated with a specific chromosome.

The constructor:

  • Opens the map file stream.
  • Detects whether the file is in "new format" (three-column format with tab separators) or the older PLINK-style format.
  • Skips header lines (those beginning with #).
  • Searches for the first record matching the requested chromosome.
  • Reads and buffers the first two records (prev_rec_ and cur_rec_) for iteration.
Parameters
map_file_pathPath to the genetic map file.
chromChromosome identifier to extract records for.
Note
  • If the file contains invalid header formatting, an error is printed and the object is marked invalid (good_ = false).
  • If no records for the target chromosome are found, or only a single record exists, the object is marked invalid.
  • The validity of the object should be checked with good() before use.

Example:

genetic_map_file gmap("genetic_map_chr1.txt", "1");
if (!gmap.good()) {
throw std::runtime_error("Failed to load map file");
}
genetic_map_file(const std::string &map_file_path, const std::string &chrom)
Constructs a genetic_map_file object for reading recombination map data.
Definition recombination.cpp:119

Member Function Documentation

◆ good()

bool genetic_map_file::good ( ) const
inline

Check whether the genetic map file was loaded successfully.

This function returns the internal state flag that indicates whether the constructor succeeded in opening and preparing the file.

Returns
true if the object is valid and ready for use, false otherwise.

◆ interpolate_centimorgan()

double genetic_map_file::interpolate_centimorgan ( std::size_t variant_pos)

Interpolate the genetic map position (in centimorgans) for a variant.

Given a genomic coordinate (basepair position), this method estimates the corresponding centimorgan (cM) value using linear interpolation between records in the genetic map file. The interpolation relies on two adjacent map records (prev_rec_ and cur_rec_).

  • If the position is before the first record, interpolation assumes a proportional relationship between basepairs and cM using the first record as reference.
  • If the position falls between two known records, interpolation is performed linearly between their map values.
  • If the position extends beyond the current block, additional records are read until the correct interval is found or until the chromosome ends.
Parameters
variant_posThe genomic coordinate (basepair position) of the variant.
Returns
The interpolated centimorgan (cM) value. If the object is invalid (good_ == false), returns NaN.
Note
Assertions ensure that consecutive map records have different positions. These cases should ideally be handled more gracefully.
Warning
Extrapolation beyond the last record assumes constant recombination rate (basepair_cm). Interpret with caution.
See also
good()
Here is the caller graph for this function:

◆ operator bool()

genetic_map_file::operator bool ( ) const
inline

Implicit conversion to bool for validity checking.

Provides a shorthand way to test whether the object is in a usable state. Equivalent to calling good().

Example:

genetic_map_file gmap("map.txt", "1");
if (gmap) {
// safe to use
} else {
// file not valid
}
Returns
true if the object is valid and ready for use, false otherwise.

The documentation for this class was generated from the following files: