Commit d2270c93 authored by Damien Leroux's avatar Damien Leroux
Browse files

Have a nice chromosome display now.

parent 2f3fbfde
......@@ -758,8 +758,8 @@ struct braille_histogram : public braille_plot {
height = ret.back();
}
}
MSG_DEBUG("bins " << ret);
MSG_DEBUG("labels " << bin_labels);
/*MSG_DEBUG("bins " << ret);*/
/*MSG_DEBUG("labels " << bin_labels);*/
return ret;
}
......
......@@ -2,6 +2,7 @@
#define _SPEL_CHROMOSOME_H_
#include <vector>
#include "braille_plot.h"
struct marker_name_and_position {
......@@ -106,6 +107,12 @@ struct chromosome {
return *this;
}
size_t
operator - (const haplotype_iterator& hi) const
{
return hs_i - hi.hs_i;
}
bool operator == (const haplotype_iterator& hi) const
{
return hs_i == hi.hs_i;
......@@ -119,6 +126,98 @@ struct chromosome {
haplotype_iterator begin() const { return {*this, false}; }
haplotype_iterator end() const { return {*this, true}; }
braille_grid
pretty_print(size_t width, const std::map<double, std::string>& POI) const
{
std::map<double, std::string> marker_labels;
double length = raw.marker_locus.back();
for (const auto& haplo: *this) {
std::stringstream label;
double pos = raw.marker_locus[haplo.first];
label << raw.marker_name[haplo.first];
for (size_t m = haplo.first + 1; m < haplo.second; ++m) {
label << ',' << raw.marker_name[m];
}
marker_labels[pos] = label.str();
}
MSG_DEBUG("marker_labels begin");
for (const auto& ml: marker_labels) { MSG_DEBUG(ml.first << ": " << ml.second); }
MSG_DEBUG("marker_labels end");
size_t llsz = marker_labels.begin()->second.size();
if (POI.size()) {
llsz = std::max(llsz, POI.begin()->second.size());
}
int padding_left = 2 * (llsz + 1);
double x_factor = (2 * (width - 1) - padding_left) / length;
auto compute_xya
= [&] (const std::map<double, std::string>& poi, std::vector<int>& X, std::vector<int>& Y, std::vector<int>& anchor, size_t& ymax)
{
std::vector<int> xend;
for (const auto& pl: poi) {
anchor.push_back(round(padding_left + pl.first * x_factor));
int x = anchor.back() - 2 * (1 + pl.second.size());
int y;
auto yi = std::find_if(xend.begin(), xend.end(), [&] (int xend) { return xend < x; });
if (yi == xend.end()) {
xend.push_back(anchor.back() + 2);
y = xend.size() + 1;
yi = xend.end();
} else {
*yi = anchor.back() + 2;
y = 2 + (yi - xend.begin());
}
for (auto xe = xend.begin(); xe < yi; ++xe) { *xe = anchor.back() + 2; }
X.push_back(x);
Y.push_back(y);
}
ymax = xend.size();
};
std::vector<int> label_x, label_y, label_anchor;
std::vector<int> poi_x, poi_y, poi_anchor;
size_t label_ymax, poi_ymax;
compute_xya(marker_labels, label_x, label_y, label_anchor, label_ymax);
compute_xya(POI, poi_x, poi_y, poi_anchor, poi_ymax);
braille_grid grid(2 * width, 12 + 4 * (label_ymax + poi_ymax));
grid.set_background(40, 40, 40);
int y0 = 4 * (2 + poi_ymax);
grid.line(label_anchor.front(), y0, 2 * label_anchor.back(), y0, 1, 0);
grid.line(label_anchor.front(), y0 + 1, 2 * label_anchor.back(), y0 + 1, 1, 0);
auto ai = label_anchor.begin();
auto xi = label_x.begin();
auto yi = label_y.begin();
for (const auto& pl: marker_labels) {
grid.line(*ai, y0 - 1, *ai, y0 + 4 * (*yi - 1), 1, 0);
grid.line(*ai, y0 + 4 * (*yi - 1), *ai - 3, y0 + 4 * (*yi) - 1, 1, 0);
grid.add_label(*xi, y0 + 4 * (*yi - 1), pl.second);
++ai;
++xi;
++yi;
}
ai = poi_anchor.begin();
xi = poi_x.begin();
yi = poi_y.begin();
for (const auto& pl: POI) {
grid.line(*ai, y0 +2, *ai, y0 - 4 * (*yi - 1), 1, 0, 0, 255, 0);
grid.line(*ai, y0 - 4 * (*yi - 1), *ai - 3, y0 - 4 * (*yi) + 1, 1, 0, 0, 255, 0);
grid.add_label(*xi, y0 - 4 * (*yi), pl.second, 0, 255, 0);
++ai;
++xi;
++yi;
}
grid.add_label(0, 0, MESSAGE("Chromosome " << name), 0, 255, 255);
return grid;
}
};
static inline
......
......@@ -36,7 +36,7 @@ struct key_already_exists : public std::exception {
struct model_block_key {
typedef std::map<const chromosome*, locus_key> selection_type;
typedef selection_type::value_type selection_value_type;
std::map<const chromosome*, locus_key> selection;
selection_type selection;
model_block_key() : selection() {}
model_block_key(std::initializer_list<selection_value_type> il)
......
......@@ -181,3 +181,6 @@ study_pedigree.o: Makefile
study_pedigree: study_pedigree.o Makefile
$C $< -o $@
test_map_print: test_map_print.cc input/read_map.o ../include/data/chromosome.h ../include/braille_plot.h
$C $< input/read_map.o -o $@
/*#include "all.h"*/
#include "malloc.h"
#include "geno_matrix.h"
#include "computations.h"
#include "chrono.h"
......@@ -98,6 +99,8 @@ int main(int argc, const char** argv)
}
}
std::map<std::string, std::map<double, std::string>> poi;
for (const auto& trait_pops: pops_by_trait) {
model_manager mm(trait_pops.second,
trait_matrix(trait_pops.first, trait_pops.second),
......@@ -172,6 +175,26 @@ int main(int argc, const char** argv)
MSG_DEBUG("RSS " << mm.Mcurrent.rss());
/*MSG_DEBUG("Model " << std::endl << mm.Mcurrent);*/
MSG_QUEUE_FLUSH();
for (const auto& mbk: mm.Mcurrent.m_blocks) {
for (const auto& chr_lk: mbk.first.selection) {
for (double l: chr_lk.second) {
if (poi[chr_lk.first->name][l].size()) {
poi[chr_lk.first->name][l] = MESSAGE(poi[chr_lk.first->name][l] << ',' << trait_pops.first);
} else {
poi[chr_lk.first->name][l] = trait_pops.first;
}
}
}
}
}
size_t width = msg_handler_t::termcols();
if (width > 80) {
width = width * .8;
}
for (const auto& chr: active_settings->map) {
MSG_DEBUG(chr.pretty_print(width, poi[chr.name]));
}
return 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment