-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotchromosome2.cpp
81 lines (63 loc) · 1.82 KB
/
plotchromosome2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "plotchromosome2.h"
#include "readcontainer.h"
#include "vplot2.h"
#include "utils.h"
#include <iostream>
PlotChromosome::PlotChromosome ( const size_t N, const chr_pos_t L, const std::string name )
: len(L),
name(name)
{
//color = COLORS[L];
}
int PlotChromosome::nExons () const {
return exons.size();
}
void PlotChromosome::addExon ( const p_read_t exon, int layer ) {
auto p1 = exon->fivePrimeEnd;
if (exons.find(p1) == exons.end()) { // already existss
exons.emplace(p1, exon);
}
if (!exon->moreData) {
exon->moreData = new PlotInfo;
((PlotInfo*)exon->moreData)->layer = layer;
}
else {
}
}
// number all displayed fragments in order of position
void PlotChromosome::assignIds() {
uint id(1);
for (auto &exon_it : exons) {
exon_it.second->moreData->id = id++;
}
}
void PlotChromosome::printout() {
std::cout << "chromosome " << name << std::endl;
for (auto& ex : exons) {
std::cout << ex.first << "-" << ex.second << std::endl;
}
}
std::shared_ptr<Rect> PlotChromosome::boundingRect() {
std::shared_ptr<Rect> rect(new Rect);
*rect = {0,0,0,0}; // not used yet
return rect;
}
void PlotChromosome::writeEps ( std::ostream& out, const Rect dim, const int dx, const int dy, const float scale, const float col[3] ) {
assignIds();
int cy = dim.h + .5 * dy;
// Chromosome name
out << dx << " " << cy - 0.25 * dy << " moveto\n";
out << "(" << name << ") show\n";
// Background line
out << len*scale << " " // w
<< 2*dx << " " // x
<< cy << " cL\n"; // y
// Rectangle for exons
for (auto& exon : exons) {
out << col[0] << " " << col[1] << " " << col[2] << " " // r g b
<< (exon.second->threePrimeEnd-exon.first) * scale << " " // w
<< 2*dx + scale * exon.first << " " // x
<< cy - 0.25 * dy << " exon\n";
}
out << std::endl;
}