-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrackviewer.cpp
141 lines (102 loc) · 2.62 KB
/
trackviewer.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "trackviewer.h"
#include "referencetrack.h"
TrackViewer::TrackViewer(QWidget *parent)
:QAbstractScrollArea(parent)
{
mRegion.seqName = "";
mRegion.beginPos = 1;
mRegion.endPos = 100;
}
void TrackViewer::setRegion(const QString &chr, int start, int end)
{
seqan::GenomicRegion region;
region.seqName = chr.toStdString();
region.beginPos = start;
region.endPos = end;
setRegion(region);
}
void TrackViewer::setRegion(const seqan::GenomicRegion ®ion)
{
mRegion = region;
updateScrollBar();
viewport()->update();
emit regionChanged(regionString());
}
void TrackViewer::addTrack(AbstractTrack *track)
{
if (track != mReferenceTrack && mReferenceTrack == nullptr)
{
qWarning()<<"WARNING, cannot add track before setting reference track";
return;
}
track->setViewer(this);
mTracks.append(track);
updateScrollBar();
}
const seqan::GenomicRegion &TrackViewer::region() const
{
return mRegion;
}
QString TrackViewer::regionString() const
{
std::string string;
mRegion.toString<std::string>(string);
return QString::fromStdString(string);
}
int TrackViewer::regionLength() const
{
return mRegion.endPos - mRegion.beginPos;
}
void TrackViewer::setReference(const QString &filename)
{
if (!mReferenceTrack){
mReferenceTrack = new ReferenceTrack(filename);
addTrack(mReferenceTrack);
}
else
mReferenceTrack->setFilename(filename);
}
ReferenceTrack *TrackViewer::referenceTrack() const
{
return mReferenceTrack;
}
AbstractTrack *TrackViewer::track(int index)
{
return mTracks[index];
}
void TrackViewer::paintEvent(QPaintEvent *event)
{
QPainter painter(viewport());
QFont font("Monospace");
font.setStyleHint(QFont::TypeWriter);
painter.setFont(font);
for (AbstractTrack * track : mTracks)
{
track->paint(&painter, mRegion, viewport()->width());
painter.translate(0, mTrackSpacing);
}
}
void TrackViewer::updateScrollBar()
{
// set horizontal
int min = 1 ;
int max = mReferenceTrack->baseCount() - regionLength();
horizontalScrollBar()->setRange(min , max );
horizontalScrollBar()->setPageStep(viewport()->width());
// set vetical
int totalHeight = 0;
for (auto * i : mTracks)
totalHeight+= i->height();
verticalScrollBar()->setRange(1 , totalHeight);
}
void TrackViewer::scrollContentsBy(int dx, int dy)
{
setRegion(seqan::toCString(region().seqName),
mRegion.beginPos - dx ,
mRegion.endPos - dx);
mY -= dy;
}
int TrackViewer::y() const
{
return mY;
}