|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_POPULATION_PLOTTING_CATHEDRAL_PLOT_H_
2 #define GENESIS_POPULATION_PLOTTING_CATHEDRAL_PLOT_H_
62 namespace population {
196 template<
class Record,
class Accumulator>
200 Accumulator accumulator = Accumulator{}
204 record.window_widths = std::vector<double>( parameters.
height );
207 record.parameters = parameters;
210 double const chr_len =
static_cast<double>( record.chromosome_length );
211 auto const advance = chr_len /
static_cast<double>( parameters.
width );
217 for(
size_t row = 0; row < parameters.
height; ++row ) {
221 assert( std::isfinite( window_width ) && window_width > 0.0 );
222 record.window_widths[row] = window_width;
230 std::deque<typename Record::Entry> queue;
231 size_t entry_idx = 0;
245 double cur_gen_pos = - window_width / 2.0;
248 for(
size_t col = 0; col < parameters.
width; ++col ) {
249 assert( cur_gen_pos + window_width >= 0.0 );
250 assert( cur_gen_pos <=
static_cast<double>( record.chromosome_length ));
255 auto l_gen_pos =
static_cast<size_t>( std::max( cur_gen_pos, 0.0 ));
256 auto r_gen_pos =
static_cast<size_t>( std::min( cur_gen_pos + window_width, chr_len ));
257 if( col == parameters.
width - 1 ) {
258 r_gen_pos = record.chromosome_length;
260 cur_gen_pos += advance;
263 assert( l_gen_pos <= r_gen_pos );
264 assert( r_gen_pos <= record.chromosome_length );
267 while( ! queue.empty() && queue.front().position < l_gen_pos ) {
269 accumulator.dissipate( queue.front() );
278 entry_idx < record.entries.size() &&
279 record.entries[ entry_idx ].position <= r_gen_pos
283 assert( queue.empty() || queue.back().position < record.entries[entry_idx].position );
284 assert( record.entries[entry_idx].position <= record.chromosome_length );
288 accumulator.accumulate( record.entries[entry_idx] );
289 queue.push_back( record.entries[entry_idx] );
295 entry_idx == record.entries.size() ||
296 record.entries[entry_idx].position > r_gen_pos
300 assert( queue.empty() || queue.front().position >= l_gen_pos );
301 assert( queue.empty() || queue.back().position <= r_gen_pos );
304 record.value_matrix( row, col ) = accumulator.aggregate();
310 assert( record.entries.size() == accu_cnt );
311 assert( record.entries.size() == diss_cnt + queue.size() );
326 CathedralPlotParameters
const& parameters
340 CathedralPlotRecord
const& record
353 std::shared_ptr<genesis::utils::BaseOutputTarget> json_target,
354 std::shared_ptr<genesis::utils::BaseOutputTarget> csv_target
372 std::string
const& base_path
389 CathedralPlotRecord
const& record,
390 std::string
const& base_path
400 std::pair<genesis::utils::JsonDocument, genesis::utils::Matrix<double>>
402 std::string
const& base_path
413 std::string
const& base_path
429 CathedralPlotRecord
const& record,
442 CathedralPlotRecord
const& record,
456 CathedralPlotRecord
const& record,
463 #endif // include guard
genesis::utils::JsonDocument cathedral_plot_parameters_to_json_document(CathedralPlotParameters const ¶meters)
Get a user-readable description of a CathedralPlotParameters as a JsonDocument.
CathedralPlotParameters parameters
Store a Json value of any kind.
void compute_cathedral_matrix(CathedralPlotParameters const ¶meters, Record &record, Accumulator accumulator=Accumulator{})
Template function to compute the value matrix for a cathedral plot, given a recored with plot paramet...
CathedralWindowWidthMethod cathedral_window_width_method_from_string(std::string const &method)
Helper function to return a CathedralWindowWidthMethod from its textual representation.
genesis::utils::SvgDocument make_cathedral_plot_svg(CathedralPlotRecord const &record, genesis::utils::HeatmapParameters const &heatmap_parameters, genesis::utils::Matrix< genesis::utils::Color > const &image)
Make a cathedral plot heat map and add it into an SVG document with legend and axes.
virtual ~CathedralPlotRecord()=default
std::pair< genesis::utils::JsonDocument, genesis::utils::Matrix< double > > load_cathedral_plot_record_components_from_files(std::string const &base_path)
Load the parts of a cathedral plot from a set of files.
CathedralWindowWidthMethod window_width_method
Collection of the data used for making for a cathedral plot.
double cathedral_window_width(CathedralPlotRecord const &record, size_t row)
Compute the window width for a row in a cathedral plot.
genesis::utils::Matrix< double > value_matrix
void save_cathedral_plot_record_to_targets(genesis::utils::JsonDocument const &record_document, genesis::utils::Matrix< double > const &record_value_matrix, std::shared_ptr< genesis::utils::BaseOutputTarget > json_target, std::shared_ptr< genesis::utils::BaseOutputTarget > csv_target)
Save the record of a cathedral plot in a set of output targets.
genesis::utils::Matrix< genesis::utils::Color > make_cathedral_plot_heatmap(CathedralPlotRecord const &record, genesis::utils::HeatmapParameters const &heatmap_parameters)
Make a cathedral plot heat map as a color matrix.
std::string chromosome_name
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
CathedralWindowWidthMethod
Interpolation algorithm for window sizes across the rows of a cathedral plot.
void validate_cathedral_plot_record(CathedralPlotRecord const &record)
Check a Cathedral Plot record for internal consistency.
std::string cathedral_window_width_method_to_string(CathedralWindowWidthMethod method)
Helper function to return a textual representation of the method.
void save_cathedral_plot_record_to_files(genesis::utils::JsonDocument const &record_document, genesis::utils::Matrix< double > const &record_value_matrix, std::string const &base_path)
Save the record of a cathedral plot in a set of files.
genesis::utils::JsonDocument cathedral_plot_record_to_json_document(CathedralPlotRecord const &record)
Get a user-readable description of the data of a CathedralPlotRecord as a JsonDocument.
std::vector< double > window_widths
Plot parameters to make a cathedral plot.
CathedralPlotRecord load_cathedral_plot_record_from_files(std::string const &base_path)
Load the record of a cathedral plot from a set of files.