64
using namespace Internal;
71
using namespace Internal;
66
Spectrum2DCanvas::Spectrum2DCanvas(const Param& preferences, QWidget* parent)
67
: SpectrumCanvas(preferences, parent)
73
Spectrum2DCanvas::Spectrum2DCanvas(const Param & preferences, QWidget * parent) :
74
SpectrumCanvas(preferences, parent)
69
76
//Parameter handling
70
77
defaults_.setValue("background_color", "#ffffff", "Background color.");
71
78
defaults_.setValue("interpolation_steps", 1000, "Number of interploation steps for peak gradient precalculation.");
72
defaults_.setMinInt("interpolation_steps",1);
73
defaults_.setMaxInt("interpolation_steps",1000);
79
defaults_.setMinInt("interpolation_steps", 1);
80
defaults_.setMaxInt("interpolation_steps", 1000);
74
81
defaults_.setValue("dot:gradient", "Linear|0,#eeeeee;1,#ffea00;6,#ff0000;14,#aa00ff;23,#5500ff;100,#000000", "Multi-color gradient for peaks.");
75
82
defaults_.setValue("dot:feature_icon", "circle", "Icon used for features and consensus features.");
76
83
defaults_.setValidStrings("dot:feature_icon", StringList::create("diamond,square,circle,triangle"));
77
84
defaults_.setValue("dot:feature_icon_size", 4, "Icon size used for features and consensus features.");
78
defaults_.setMinInt("dot:feature_icon_size",1);
79
defaults_.setMaxInt("dot:feature_icon_size",999);
80
defaults_.setValue("mapping_of_mz_to","y_axis","Determines which axis is the m/z axis.");
81
defaults_.setValidStrings("mapping_of_mz_to", StringList::create("x_axis,y_axis"));
83
setName("Spectrum2DCanvas");
84
setParameters(preferences);
86
projection_mz_.resize(1);
87
projection_rt_.resize(1);
89
//set preferences and update widgets accordingly
90
if (String(param_.getValue("mapping_of_mz_to")) != "x_axis")
94
//connect preferences change to the right slot
95
connect(this,SIGNAL(preferencesChange()),this,SLOT(currentLayerParametersChanged_()));
98
Spectrum2DCanvas::~Spectrum2DCanvas()
102
void Spectrum2DCanvas::highlightPeak_(QPainter& painter, const PeakIndex& peak)
104
if (!peak.isValid()) return;
106
//determine coordinates;
108
if (getCurrentLayer().type==LayerData::DT_FEATURE)
85
defaults_.setMinInt("dot:feature_icon_size", 1);
86
defaults_.setMaxInt("dot:feature_icon_size", 999);
87
defaults_.setValue("mapping_of_mz_to", "y_axis", "Determines which axis is the m/z axis.");
88
defaults_.setValidStrings("mapping_of_mz_to", StringList::create("x_axis,y_axis"));
90
setName("Spectrum2DCanvas");
91
setParameters(preferences);
93
projection_mz_.resize(1);
94
projection_rt_.resize(1);
96
//set preferences and update widgets accordingly
97
if (String(param_.getValue("mapping_of_mz_to")) != "x_axis")
101
//connect preferences change to the right slot
102
connect(this, SIGNAL(preferencesChange()), this, SLOT(currentLayerParametersChanged_()));
105
Spectrum2DCanvas::~Spectrum2DCanvas()
109
void Spectrum2DCanvas::highlightPeak_(QPainter & painter, const PeakIndex & peak)
114
//determine coordinates;
116
if (getCurrentLayer().type == LayerData::DT_FEATURE)
110
118
dataToWidget_(peak.getFeature(*getCurrentLayer().getFeatureMap()).getMZ(), peak.getFeature(*getCurrentLayer().getFeatureMap()).getRT(), pos);
112
else if (getCurrentLayer().type==LayerData::DT_PEAK)
120
else if (getCurrentLayer().type == LayerData::DT_PEAK)
114
122
dataToWidget_(peak.getPeak(*getCurrentLayer().getPeakData()).getMZ(), peak.getSpectrum(*getCurrentLayer().getPeakData()).getRT(), pos);
116
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS)
124
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS)
118
126
dataToWidget_(peak.getFeature(*getCurrentLayer().getConsensusMap()).getMZ(), peak.getFeature(*getCurrentLayer().getConsensusMap()).getRT(), pos);
120
else if (getCurrentLayer().type==LayerData::DT_CHROMATOGRAM)
122
const LayerData& layer = getCurrentLayer();
128
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM)
130
const LayerData & layer = getCurrentLayer();
123
131
const ExperimentSharedPtrType exp = layer.getPeakData();
125
133
// create iterator on chromatogram spectrum passed by PeakIndex
126
134
vector<MSChromatogram<> >::const_iterator chrom_it = exp->getChromatograms().begin();
127
135
chrom_it += peak.spectrum;
128
136
dataToWidget_(chrom_it->getPrecursor().getMZ(), chrom_it->front().getRT(), pos);
130
else if (getCurrentLayer().type==LayerData::DT_IDENT)
138
else if (getCurrentLayer().type == LayerData::DT_IDENT)
135
//paint highlighed peak
137
painter.setPen(QPen(Qt::red, 2));
143
//paint highlighed peak
145
painter.setPen(QPen(Qt::red, 2));
139
147
if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM) // highlight: chromatogram
141
const LayerData& layer = getCurrentLayer();
149
const LayerData & layer = getCurrentLayer();
142
150
const ExperimentSharedPtrType exp = layer.getPeakData();
144
152
vector<MSChromatogram<> >::const_iterator iter = exp->getChromatograms().begin();
145
153
iter += peak.spectrum;
147
painter.drawRect(pos.x() -5, pos.y() - 5, ( int((iter->back().getRT() - iter->front().getRT()) / visible_area_.height() * width())) + 10, 10);
155
painter.drawRect(pos.x() - 5, pos.y() - 5, (int((iter->back().getRT() - iter->front().getRT()) / visible_area_.height() * width())) + 10, 10);
149
157
else // highlight: peak, feature, consensus feature
151
159
painter.drawEllipse(pos.x() - 5, pos.y() - 5, 10, 10);
158
PeakIndex Spectrum2DCanvas::findNearestPeak_(const QPoint& pos)
160
///no layers => return invalid peak index
161
if (layers_.empty()) return PeakIndex();
163
//Constructing the area corrects swapped mapping of RT and m/z
164
AreaType area (widgetToData_(pos - QPoint(5,5)),widgetToData_(pos + QPoint(5,5)));
166
float max_int = -1 * numeric_limits<float>::max();
168
if (getCurrentLayer().type==LayerData::DT_PEAK)
170
for (ExperimentType::ConstAreaIterator i = getCurrentLayer().getPeakData()->areaBeginConst(area.minPosition()[1],area.maxPosition()[1],
171
area.minPosition()[0],area.maxPosition()[0]);
166
PeakIndex Spectrum2DCanvas::findNearestPeak_(const QPoint & pos)
168
///no layers => return invalid peak index
172
//Constructing the area corrects swapped mapping of RT and m/z
173
AreaType area(widgetToData_(pos - QPoint(5, 5)), widgetToData_(pos + QPoint(5, 5)));
175
float max_int = -1 * numeric_limits<float>::max();
178
if (getCurrentLayer().type == LayerData::DT_PEAK)
180
for (ExperimentType::ConstAreaIterator i = getCurrentLayer().getPeakData()->areaBeginConst(area.minPosition()[1], area.maxPosition()[1],
181
area.minPosition()[0], area.maxPosition()[0]);
172
182
i != getCurrentLayer().getPeakData()->areaEndConst();
175
PeakIndex pi = i.getPeakIndex();
176
if (i->getIntensity() > max_int && getCurrentLayer().filters.passes((*getCurrentLayer().getPeakData())[pi.spectrum],pi.peak))
178
//cout << "new max: " << i.getRT() << " " << i->getMZ() << endl;
179
max_int = i->getIntensity();
180
return i.getPeakIndex();
184
else if (getCurrentLayer().type==LayerData::DT_FEATURE)
185
PeakIndex pi = i.getPeakIndex();
186
if (i->getIntensity() > max_int && getCurrentLayer().filters.passes((*getCurrentLayer().getPeakData())[pi.spectrum], pi.peak))
188
//cout << "new max: " << i.getRT() << " " << i->getMZ() << endl;
189
max_int = i->getIntensity();
194
else if (getCurrentLayer().type == LayerData::DT_FEATURE)
186
196
for (FeatureMapType::ConstIterator i = getCurrentLayer().getFeatureMap()->begin();
187
197
i != getCurrentLayer().getFeatureMap()->end();
190
if ( i->getRT() >= area.minPosition()[1] &&
191
i->getRT() <= area.maxPosition()[1] &&
192
i->getMZ() >= area.minPosition()[0] &&
193
i->getMZ() <= area.maxPosition()[0] &&
194
getCurrentLayer().filters.passes(*i) )
196
if (i->getIntensity() > max_int)
198
max_int = i->getIntensity();
200
return PeakIndex(i-getCurrentLayer().getFeatureMap()->begin());
205
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS)
200
if (i->getRT() >= area.minPosition()[1] &&
201
i->getRT() <= area.maxPosition()[1] &&
202
i->getMZ() >= area.minPosition()[0] &&
203
i->getMZ() <= area.maxPosition()[0] &&
204
getCurrentLayer().filters.passes(*i))
206
if (i->getIntensity() > max_int)
208
max_int = i->getIntensity();
209
max_pi = PeakIndex(i - getCurrentLayer().getFeatureMap()->begin());
214
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS)
207
216
for (ConsensusMapType::ConstIterator i = getCurrentLayer().getConsensusMap()->begin();
208
217
i != getCurrentLayer().getConsensusMap()->end();
211
220
// consensus feature in visible area?
212
if ( i->getRT() >= area.minPosition()[1] &&
213
i->getRT() <= area.maxPosition()[1] &&
214
i->getMZ() >= area.minPosition()[0] &&
215
i->getMZ() <= area.maxPosition()[0] &&
216
getCurrentLayer().filters.passes(*i) )
218
if (i->getIntensity() > max_int)
220
max_int = i->getIntensity();
221
return PeakIndex(i - getCurrentLayer().getConsensusMap()->begin());
226
else if (getCurrentLayer().type==LayerData::DT_CHROMATOGRAM)
228
const LayerData& layer = getCurrentLayer();
221
if (i->getRT() >= area.minPosition()[1] &&
222
i->getRT() <= area.maxPosition()[1] &&
223
i->getMZ() >= area.minPosition()[0] &&
224
i->getMZ() <= area.maxPosition()[0] &&
225
getCurrentLayer().filters.passes(*i))
227
if (i->getIntensity() > max_int)
229
max_int = i->getIntensity();
230
max_pi = PeakIndex(i - getCurrentLayer().getConsensusMap()->begin());
235
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM)
237
const LayerData & layer = getCurrentLayer();
230
239
MSExperiment<Peak1D> exp;
231
240
exp = *layer.getPeakData();
540
570
DoubleReal snap_factor = snap_factors_[layer_index];
542
// calculate pixel width and height in rt/mz coordinates
544
dataToWidget_(1, 1, p1);
545
dataToWidget_(0, 0, p2);
546
DoubleReal pixel_width = abs(p1.x()-p2.x());
547
DoubleReal pixel_height = abs(p1.y()-p2.y());
549
// when data is zoomed in to single peaks these are visualized as circles
554
circle_size = min((Int)(pixel_width * minimum_spacing_mz),(Int)(pixel_height * average_spacing_rt))/2.0;
557
circle_size = min((Int)(pixel_width * average_spacing_rt),(Int)(pixel_height * minimum_spacing_mz))/2.0;
560
572
for (ExperimentType::ConstAreaIterator i = map.areaBeginConst(rt_min, rt_max, mz_min, mz_max);
561
573
i != map.areaEndConst();
564
576
PeakIndex pi = i.getPeakIndex();
565
if (layer.filters.passes(map[pi.spectrum],pi.peak))
577
if (layer.filters.passes(map[pi.spectrum], pi.peak))
568
580
dataToWidget_(i->getMZ(), i.getRT(), pos);
569
if (pos.x()>0 && pos.y()>0 && pos.x()<image_width-1 && pos.y()<image_height-1)
581
if (pos.x() > 0 && pos.y() > 0 && pos.x() < image_width - 1 && pos.y() < image_height - 1)
571
QRgb color = heightColor_(i->getIntensity(), layer.gradient, snap_factor);
573
if (circle_size <= 1)
575
painter.setPen(QColor(color));
576
painter.drawPoint(pos.x(), pos.y());
579
painter.setPen(Qt::NoPen);
580
painter.setBrush(QBrush(color));
583
QRect(pos.x()-(int)circle_size/2, pos.y()-(int)circle_size/2,
584
circle_size, circle_size),
583
// store point in the array of its color
584
Int colorIndex = precalculatedColorIndex_(i->getIntensity(), layer.gradient, snap_factor);
585
coloredPoints[ colorIndex ].push_back( pos );
592
painter.setBrush(QBrush());
589
// draw point arrays from minimum to maximum intensity,
590
// avoiding low-intensity points obscuring the high-intensity ones
593
newPointsPen.setWidthF( pen_width );
594
for ( Int colorIx = 0; colorIx < coloredPoints.size(); colorIx++ ) {
595
const QPolygon& pointsArr = coloredPoints[colorIx];
596
if ( pointsArr.size() ) {
597
newPointsPen.setColor( layer.gradient.precalculatedColorByIndex( colorIx ) );
598
painter.setPen( newPointsPen );
599
painter.drawPoints( pointsArr );
605
void Spectrum2DCanvas::paintMaximumIntensities_(Size layer_index, Size rt_pixel_count, Size mz_pixel_count, QPainter & painter)
607
//set painter to black (we operate directly on the pixels for all colored data)
593
608
painter.setPen(Qt::black);
609
//temporary variables
610
Int image_width = buffer_.width();
611
Int image_height = buffer_.height();
613
const LayerData & layer = getLayer(layer_index);
614
const ExperimentType & map = *layer.getPeakData();
615
const DoubleReal rt_min = visible_area_.minPosition()[1];
616
const DoubleReal rt_max = visible_area_.maxPosition()[1];
617
const DoubleReal mz_min = visible_area_.minPosition()[0];
618
const DoubleReal mz_max = visible_area_.maxPosition()[0];
620
DoubleReal snap_factor = snap_factors_[layer_index];
622
//calculate pixel size in data coordinates
623
DoubleReal rt_step_size = (rt_max - rt_min) / rt_pixel_count;
624
DoubleReal mz_step_size = (mz_max - mz_min) / mz_pixel_count;
626
//iterate over all pixels (RT dimension)
628
for (Size rt = 0; rt < rt_pixel_count; ++rt)
630
DoubleReal rt_start = rt_min + rt_step_size * rt;
631
DoubleReal rt_end = rt_start + rt_step_size;
632
//cout << "rt: " << rt << " (" << rt_start << " - " << rt_end << ")" << endl;
634
//determine the relevant spectra and reserve an array for the peak indices
635
vector<Size> scan_indices, peak_indices;
636
for (Size i = scan_index; i < map.size(); ++i)
638
if (map[i].getRT() >= rt_end)
640
scan_index = i; //store last scan index for next RT pixel
643
if (map[i].getMSLevel() == 1 && map[i].size() > 0)
645
scan_indices.push_back(i);
646
peak_indices.push_back(map[i].MZBegin(mz_min) - map[i].begin());
648
//set the scan index past the end. Otherwise the last scan will be repeated for all following RTs
649
if (i == map.size() - 1)
652
//cout << " scans: " << scan_indices.size() << endl;
654
if (scan_indices.empty())
657
//iterate over all pixels (m/z dimension)
658
for (Size mz = 0; mz < mz_pixel_count; ++mz)
660
DoubleReal mz_start = mz_min + mz_step_size * mz;
661
DoubleReal mz_end = mz_start + mz_step_size;
663
//iterate over all relevant peaks in all relevant scans
665
for (Size i = 0; i < scan_indices.size(); ++i)
667
Size s = scan_indices[i];
668
Size p = peak_indices[i];
669
for (; p < map[s].size(); ++p)
671
if (map[s][p].getMZ() >= mz_end)
673
if (map[s][p].getIntensity() > max && layer.filters.passes(map[s], p))
675
max = map[s][p].getIntensity();
678
peak_indices[i] = p; //store last peak index for next m/z pixel
685
dataToWidget_(mz_start + 0.5 * mz_step_size, rt_start + 0.5 * rt_step_size, pos);
686
if (pos.y() < image_height && pos.x() < image_width)
688
buffer_.setPixel(pos.x(), pos.y(), heightColor_(max, layer.gradient, snap_factor).rgb());
596
void Spectrum2DCanvas::paintMaximumIntensities_(Size layer_index, Size rt_pixel_count, Size mz_pixel_count, QPainter& painter)
598
//set painter to black (we operate directly on the pixels for all colored data)
599
painter.setPen(Qt::black);
600
//temporary variables
601
Int image_width = buffer_.width();
602
Int image_height = buffer_.height();
604
const LayerData& layer = getLayer(layer_index);
605
const ExperimentType& map = *layer.getPeakData();
606
const DoubleReal rt_min = visible_area_.minPosition()[1];
607
const DoubleReal rt_max = visible_area_.maxPosition()[1];
608
const DoubleReal mz_min = visible_area_.minPosition()[0];
609
const DoubleReal mz_max = visible_area_.maxPosition()[0];
611
DoubleReal snap_factor = snap_factors_[layer_index];
613
//calculate pixel size in data coordinates
614
DoubleReal rt_step_size = (rt_max - rt_min) / rt_pixel_count;
615
DoubleReal mz_step_size = (mz_max - mz_min) / mz_pixel_count;
617
//iterate over all pixels (RT dimension)
619
for (Size rt=0; rt<rt_pixel_count; ++rt)
621
DoubleReal rt_start = rt_min + rt_step_size * rt;
622
DoubleReal rt_end = rt_start + rt_step_size;
623
//cout << "rt: " << rt << " (" << rt_start << " - " << rt_end << ")" << endl;
625
//determine the relevant spectra and reserve an array for the peak indices
626
vector<Size> scan_indices, peak_indices;
627
for (Size i=scan_index; i<map.size(); ++i)
629
if (map[i].getRT()>=rt_end)
631
scan_index = i; //store last scan index for next RT pixel
634
if (map[i].getMSLevel()==1 && map[i].size()>0)
636
scan_indices.push_back(i);
637
peak_indices.push_back(map[i].MZBegin(mz_min) - map[i].begin());
639
//set the scan index past the end. Otherwise the last scan will be repeated for all following RTs
640
if (i==map.size()-1) scan_index=i+1;
642
//cout << " scans: " << scan_indices.size() << endl;
644
if (scan_indices.empty()) continue;
646
//iterate over all pixels (m/z dimension)
647
for (Size mz=0; mz<mz_pixel_count; ++mz)
649
DoubleReal mz_start = mz_min + mz_step_size * mz;
650
DoubleReal mz_end = mz_start + mz_step_size;
652
//iterate over all relevant peaks in all relevant scans
654
for (Size i=0; i<scan_indices.size(); ++i)
656
Size s = scan_indices[i];
657
Size p = peak_indices[i];
658
for(; p<map[s].size(); ++p)
660
if (map[s][p].getMZ()>=mz_end) break;
661
if (map[s][p].getIntensity() > max && layer.filters.passes(map[s],p))
663
max = map[s][p].getIntensity();
666
peak_indices[i] = p; //store last peak index for next m/z pixel
673
dataToWidget_(mz_start + 0.5 * mz_step_size, rt_start + 0.5 * rt_step_size, pos);
674
if (pos.y()<image_height && pos.x()<image_width)
676
buffer_.setPixel(pos.x() , pos.y(), heightColor_(max, layer.gradient, snap_factor));
683
695
void Spectrum2DCanvas::paintFeatureData_(Size layer_index, QPainter& painter)
685
697
const LayerData& layer = getLayer(layer_index);
756
void Spectrum2DCanvas::paintIcon_(const QPoint& pos, const QRgb& color, const String& icon, Size s, QPainter& p) const
760
p.setBrush(QBrush(QColor(color),Qt::SolidPattern));
762
int s_half = (int)s/2;
767
pol.putPoints(0,4,pos.x() + s_half, pos.y(),
768
pos.x() , pos.y() + s_half,
769
pos.x() - (int)s_half, pos.y() ,
770
pos.x() , pos.y() - (int)s_half);
771
p.drawConvexPolygon(pol);
773
else if (icon=="square")
776
pol.putPoints(0,4,pos.x() + s_half, pos.y() + s_half,
777
pos.x() - s_half, pos.y() + s_half,
778
pos.x() - s_half, pos.y() - s_half,
779
pos.x() + s_half, pos.y() - s_half);
780
p.drawConvexPolygon(pol);
782
else if (icon=="circle")
784
p.drawEllipse(QRectF(pos.x()-s_half,pos.y()-s_half,s,s));
786
else if (icon=="triangle")
789
pol.putPoints(0,3,pos.x() , pos.y() + s_half,
790
pos.x() + s_half, pos.y() - (int)s_half,
791
pos.x() - (int)s_half, pos.y() - (int)s_half);
792
p.drawConvexPolygon(pol);
797
void Spectrum2DCanvas::paintTraceConvexHulls_(Size layer_index, QPainter& painter)
799
painter.setPen(Qt::black);
801
const LayerData& layer = getLayer(layer_index);
802
for (FeatureMapType::ConstIterator i = layer.getFeatureMap()->begin(); i != layer.getFeatureMap()->end(); ++i)
804
if ( i->getRT() >= visible_area_.minPosition()[1] &&
805
i->getRT() <= visible_area_.maxPosition()[1] &&
806
i->getMZ() >= visible_area_.minPosition()[0] &&
807
i->getMZ() <= visible_area_.maxPosition()[0] &&
808
layer.filters.passes(*i)
811
paintConvexHulls_(i->getConvexHulls(),painter);
816
void Spectrum2DCanvas::paintFeatureConvexHulls_(Size layer_index, QPainter& painter)
818
painter.setPen(Qt::black);
819
const LayerData& layer = getLayer(layer_index);
820
for (FeatureMapType::ConstIterator i = layer.getFeatureMap()->begin(); i != layer.getFeatureMap()->end(); ++i)
822
if ( i->getRT() >= visible_area_.minPosition()[1] &&
823
i->getRT() <= visible_area_.maxPosition()[1] &&
824
i->getMZ() >= visible_area_.minPosition()[0] &&
825
i->getMZ() <= visible_area_.maxPosition()[0] &&
826
layer.filters.passes(*i))
829
ConvexHull2D hull = i->getConvexHull();
830
ConvexHull2D::PointArrayType ch_points = hull.getHullPoints();
832
points.resize((int)ch_points.size());
836
//iterate over hull points
838
for(ConvexHull2D::PointArrayType::const_iterator it=ch_points.begin(); it!=ch_points.end(); ++it, ++index)
840
dataToWidget_(it->getY(), it->getX(),pos);
841
points.setPoint(index, pos);
843
//cout << "Hull: " << hull << " Points: " << points.size()<<endl;
844
painter.drawPolygon(points);
849
void Spectrum2DCanvas::paintIdentifications_(Size layer_index, QPainter& painter)
851
const LayerData& layer = getLayer(layer_index);
852
vector<PeptideIdentification>::const_iterator pep_begin, pep_end;
853
if (layer.type == LayerData::DT_FEATURE)
761
void Spectrum2DCanvas::paintIcon_(const QPoint & pos, const QRgb & color, const String & icon, Size s, QPainter & p) const
765
p.setBrush(QBrush(QColor(color), Qt::SolidPattern));
767
int s_half = (int)s / 2;
769
if (icon == "diamond")
772
pol.putPoints(0, 4, pos.x() + s_half, pos.y(),
773
pos.x(), pos.y() + s_half,
774
pos.x() - (int)s_half, pos.y(),
775
pos.x(), pos.y() - (int)s_half);
776
p.drawConvexPolygon(pol);
778
else if (icon == "square")
781
pol.putPoints(0, 4, pos.x() + s_half, pos.y() + s_half,
782
pos.x() - s_half, pos.y() + s_half,
783
pos.x() - s_half, pos.y() - s_half,
784
pos.x() + s_half, pos.y() - s_half);
785
p.drawConvexPolygon(pol);
787
else if (icon == "circle")
789
p.drawEllipse(QRectF(pos.x() - s_half, pos.y() - s_half, s, s));
791
else if (icon == "triangle")
794
pol.putPoints(0, 3, pos.x(), pos.y() + s_half,
795
pos.x() + s_half, pos.y() - (int)s_half,
796
pos.x() - (int)s_half, pos.y() - (int)s_half);
797
p.drawConvexPolygon(pol);
802
void Spectrum2DCanvas::paintTraceConvexHulls_(Size layer_index, QPainter & painter)
804
painter.setPen(Qt::black);
806
const LayerData & layer = getLayer(layer_index);
807
for (FeatureMapType::ConstIterator i = layer.getFeatureMap()->begin(); i != layer.getFeatureMap()->end(); ++i)
809
if (i->getRT() >= visible_area_.minPosition()[1] &&
810
i->getRT() <= visible_area_.maxPosition()[1] &&
811
i->getMZ() >= visible_area_.minPosition()[0] &&
812
i->getMZ() <= visible_area_.maxPosition()[0] &&
813
layer.filters.passes(*i)
816
bool hasIdentifications = i->getPeptideIdentifications().size()>0
817
&& i->getPeptideIdentifications()[0].getHits().size()>0;
818
paintConvexHulls_(i->getConvexHulls(), hasIdentifications, painter);
823
void Spectrum2DCanvas::paintFeatureConvexHulls_(Size layer_index, QPainter & painter)
825
const LayerData & layer = getLayer(layer_index);
826
for (FeatureMapType::ConstIterator i = layer.getFeatureMap()->begin(); i != layer.getFeatureMap()->end(); ++i)
828
if (i->getRT() >= visible_area_.minPosition()[1] &&
829
i->getRT() <= visible_area_.maxPosition()[1] &&
830
i->getMZ() >= visible_area_.minPosition()[0] &&
831
i->getMZ() <= visible_area_.maxPosition()[0] &&
832
layer.filters.passes(*i))
835
ConvexHull2D hull = i->getConvexHull();
836
ConvexHull2D::PointArrayType ch_points = hull.getHullPoints();
838
points.resize((int)ch_points.size());
842
//iterate over hull points
844
for (ConvexHull2D::PointArrayType::const_iterator it = ch_points.begin(); it != ch_points.end(); ++it, ++index)
846
dataToWidget_(it->getY(), it->getX(), pos);
847
points.setPoint(index, pos);
849
//cout << "Hull: " << hull << " Points: " << points.size()<<endl;
850
bool hasIdentifications = i->getPeptideIdentifications().size()>0
851
&& i->getPeptideIdentifications()[0].getHits().size()>0;
852
painter.setPen( hasIdentifications ? Qt::darkGreen : Qt::darkBlue );
853
painter.drawPolygon(points);
858
void Spectrum2DCanvas::paintIdentifications_(Size layer_index, QPainter & painter)
860
const LayerData & layer = getLayer(layer_index);
861
vector<PeptideIdentification>::const_iterator pep_begin, pep_end;
862
if (layer.type == LayerData::DT_FEATURE)
855
864
pep_begin = layer.getFeatureMap()->getUnassignedPeptideIdentifications().begin();
856
865
pep_end = layer.getFeatureMap()->getUnassignedPeptideIdentifications().end();
858
else if (layer.type == LayerData::DT_IDENT)
860
pep_begin = layer.peptides.begin();
861
pep_end = layer.peptides.end();
865
painter.setPen(Qt::black);
867
for (; pep_begin != pep_end; ++pep_begin)
869
if ( !pep_begin->getHits().empty() )
871
if (!pep_begin->metaValueExists("RT") ||
872
!pep_begin->metaValueExists("MZ"))
874
// TODO: show error message here
877
DoubleReal rt = (DoubleReal) pep_begin->getMetaValue("RT");
878
if (rt < visible_area_.minPosition()[1] || rt > visible_area_.maxPosition()[1]) continue;
879
DoubleReal mz = getIdentificationMZ_(layer_index, *pep_begin);
880
if (mz < visible_area_.minPosition()[0] || mz > visible_area_.maxPosition()[0]) continue;
884
dataToWidget_(mz, rt, pos);
885
painter.drawLine(pos.x(), pos.y() - 1.0, pos.x(), pos.y() + 1.0);
886
painter.drawLine(pos.x() - 1.0, pos.y(), pos.x() + 1.0, pos.y());
889
String sequence = pep_begin->getHits()[0].getSequence().toString();
890
if (pep_begin->getHits().size() > 1) sequence += "...";
891
painter.drawText(pos.x() + 10.0, pos.y() + 10.0, sequence.toQString());
896
void Spectrum2DCanvas::paintConvexHulls_(const vector<ConvexHull2D>& hulls, QPainter& painter)
867
else if (layer.type == LayerData::DT_IDENT)
869
pep_begin = layer.peptides.begin();
870
pep_end = layer.peptides.end();
875
painter.setPen(Qt::darkRed);
877
for (; pep_begin != pep_end; ++pep_begin)
879
if (!pep_begin->getHits().empty())
881
if (!pep_begin->metaValueExists("RT") ||
882
!pep_begin->metaValueExists("MZ"))
884
// TODO: show error message here
887
DoubleReal rt = (DoubleReal) pep_begin->getMetaValue("RT");
888
if (rt < visible_area_.minPosition()[1] || rt > visible_area_.maxPosition()[1])
890
DoubleReal mz = getIdentificationMZ_(layer_index, *pep_begin);
891
if (mz < visible_area_.minPosition()[0] || mz > visible_area_.maxPosition()[0])
896
dataToWidget_(mz, rt, pos);
897
painter.drawLine(pos.x(), pos.y() - 1.0, pos.x(), pos.y() + 1.0);
898
painter.drawLine(pos.x() - 1.0, pos.y(), pos.x() + 1.0, pos.y());
901
String sequence = pep_begin->getHits()[0].getSequence().toString();
902
if (pep_begin->getHits().size() > 1)
904
painter.drawText(pos.x() + 10.0, pos.y() + 10.0, sequence.toQString());
909
void Spectrum2DCanvas::paintConvexHulls_(const vector<ConvexHull2D> & hulls, bool hasIdentifications, QPainter & painter)
900
//iterate over all convex hulls
901
for (Size hull=0; hull<hulls.size(); ++hull)
903
ConvexHull2D::PointArrayType ch_points = hulls[hull].getHullPoints();
904
points.resize((int)ch_points.size());
907
//iterate over hull points
908
for(ConvexHull2D::PointArrayType::const_iterator it=ch_points.begin(); it!=ch_points.end(); ++it, ++index)
910
dataToWidget_(it->getY(), it->getX(),pos);
911
points.setPoint(index, pos);
913
//iterate over all convex hulls
914
for (Size hull = 0; hull < hulls.size(); ++hull)
916
ConvexHull2D::PointArrayType ch_points = hulls[hull].getHullPoints();
917
points.resize((int)ch_points.size());
920
//iterate over hull points
921
for (ConvexHull2D::PointArrayType::const_iterator it = ch_points.begin(); it != ch_points.end(); ++it, ++index)
923
dataToWidget_(it->getY(), it->getX(), pos);
924
points.setPoint(index, pos);
913
926
painter.setPen(QPen(Qt::white, 5, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin));
914
927
painter.drawPolygon(points);
915
painter.setPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
916
painter.drawPolygon(points);
928
painter.setPen(QPen( hasIdentifications ? Qt::green : Qt::blue, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
929
painter.drawPolygon(points);
920
void Spectrum2DCanvas::paintConsensusElements_(Size layer_index, QPainter& p)
922
const LayerData& layer = getLayer(layer_index);
933
void Spectrum2DCanvas::paintConsensusElements_(Size layer_index, QPainter & p)
935
const LayerData & layer = getLayer(layer_index);
924
937
for (ConsensusMapType::ConstIterator i = layer.getConsensusMap()->begin(); i != layer.getConsensusMap()->end(); ++i)
926
paintConsensusElement_(layer_index, *i, p, true);
930
void Spectrum2DCanvas::paintConsensusElement_(Size layer_index, const ConsensusFeature& cf, QPainter& p, bool use_buffer)
932
Int image_width = buffer_.width();
933
Int image_height = buffer_.height();
935
const LayerData& layer = getLayer(layer_index);
937
if ( isConsensusFeatureVisible_(cf, layer_index) && layer.filters.passes(cf))
939
//calculate position of consensus feature (centroid)
940
QPoint consensus_pos;
941
dataToWidget_(cf.getMZ(), cf.getRT(),consensus_pos);
942
//iterate over elements
943
for (ConsensusFeature::HandleSetType::const_iterator element=cf.begin(); element!=cf.end(); ++element)
945
//calculate position of consensus element
947
dataToWidget_(element->getMZ(), element->getRT(),pos);
949
p.drawLine(consensus_pos,pos);
951
if (pos.x()>0 && pos.y()>0 && pos.x()<image_width-1 && pos.y()<image_height-1)
953
// use buffer only when not highlighting
956
buffer_.setPixel(pos.x() ,pos.y() ,Qt::black);
957
buffer_.setPixel(pos.x()-1 ,pos.y() ,Qt::black);
958
buffer_.setPixel(pos.x()+1 ,pos.y() ,Qt::black);
959
buffer_.setPixel(pos.x() ,pos.y()-1 ,Qt::black);
960
buffer_.setPixel(pos.x() ,pos.y()+1 ,Qt::black);
964
p.drawPoint(pos.x() ,pos.y());
965
p.drawPoint(pos.x()-1 ,pos.y());
966
p.drawPoint(pos.x()+1 ,pos.y());
967
p.drawPoint(pos.x() ,pos.y()-1);
968
p.drawPoint(pos.x() ,pos.y()+1);
976
bool Spectrum2DCanvas::isConsensusFeatureVisible_(const ConsensusFeature& ce, Size layer_index)
978
// check the centroid first
979
if (ce.getRT() >= visible_area_.minPosition()[1] &&
980
ce.getRT() <= visible_area_.maxPosition()[1] &&
981
ce.getMZ() >= visible_area_.minPosition()[0] &&
982
ce.getMZ() <= visible_area_.maxPosition()[0])
987
// if element-flag is set, check if any of the consensus elements is visible
988
if (getLayerFlag(layer_index, LayerData::C_ELEMENTS))
990
ConsensusFeature::HandleSetType::const_iterator element=ce.getFeatures().begin();
991
for (; element != ce.getFeatures().end(); ++element)
993
if (element->getRT() >= visible_area_.minPosition()[1] &&
994
element->getRT() <= visible_area_.maxPosition()[1] &&
995
element->getMZ() >= visible_area_.minPosition()[0] &&
996
element->getMZ() <= visible_area_.maxPosition()[0])
1005
void Spectrum2DCanvas::intensityModeChange_()
939
paintConsensusElement_(layer_index, *i, p, true);
943
void Spectrum2DCanvas::paintConsensusElement_(Size layer_index, const ConsensusFeature & cf, QPainter & p, bool use_buffer)
945
Int image_width = buffer_.width();
946
Int image_height = buffer_.height();
948
const LayerData & layer = getLayer(layer_index);
950
if (isConsensusFeatureVisible_(cf, layer_index) && layer.filters.passes(cf))
952
//calculate position of consensus feature (centroid)
953
QPoint consensus_pos;
954
dataToWidget_(cf.getMZ(), cf.getRT(), consensus_pos);
955
//iterate over elements
956
for (ConsensusFeature::HandleSetType::const_iterator element = cf.begin(); element != cf.end(); ++element)
958
//calculate position of consensus element
960
dataToWidget_(element->getMZ(), element->getRT(), pos);
962
p.drawLine(consensus_pos, pos);
964
if (pos.x() > 0 && pos.y() > 0 && pos.x() < image_width - 1 && pos.y() < image_height - 1)
966
// use buffer only when not highlighting
969
buffer_.setPixel(pos.x(), pos.y(), Qt::black);
970
buffer_.setPixel(pos.x() - 1, pos.y(), Qt::black);
971
buffer_.setPixel(pos.x() + 1, pos.y(), Qt::black);
972
buffer_.setPixel(pos.x(), pos.y() - 1, Qt::black);
973
buffer_.setPixel(pos.x(), pos.y() + 1, Qt::black);
977
p.drawPoint(pos.x(), pos.y());
978
p.drawPoint(pos.x() - 1, pos.y());
979
p.drawPoint(pos.x() + 1, pos.y());
980
p.drawPoint(pos.x(), pos.y() - 1);
981
p.drawPoint(pos.x(), pos.y() + 1);
989
bool Spectrum2DCanvas::isConsensusFeatureVisible_(const ConsensusFeature & ce, Size layer_index)
991
// check the centroid first
992
if (ce.getRT() >= visible_area_.minPosition()[1] &&
993
ce.getRT() <= visible_area_.maxPosition()[1] &&
994
ce.getMZ() >= visible_area_.minPosition()[0] &&
995
ce.getMZ() <= visible_area_.maxPosition()[0])
1000
// if element-flag is set, check if any of the consensus elements is visible
1001
if (getLayerFlag(layer_index, LayerData::C_ELEMENTS))
1003
ConsensusFeature::HandleSetType::const_iterator element = ce.getFeatures().begin();
1004
for (; element != ce.getFeatures().end(); ++element)
1006
if (element->getRT() >= visible_area_.minPosition()[1] &&
1007
element->getRT() <= visible_area_.maxPosition()[1] &&
1008
element->getMZ() >= visible_area_.minPosition()[0] &&
1009
element->getMZ() <= visible_area_.maxPosition()[0])
1018
void Spectrum2DCanvas::intensityModeChange_()
1007
1020
for (Size i = 0; i < layers_.size(); ++i)
1009
1022
recalculateDotGradient_(i);
1011
SpectrumCanvas::intensityModeChange_();
1024
SpectrumCanvas::intensityModeChange_();
1014
1027
void Spectrum2DCanvas::recalculateDotGradient_(Size layer)
1016
1029
getLayer_(layer).gradient.fromString(getLayer_(layer).param.getValue("dot:gradient"));
1017
1030
if (intensity_mode_ == IM_LOG)
1019
DoubleReal min_intensity = getMinIntensity(layer);
1032
DoubleReal min_intensity = getMinIntensity(layer);
1020
1033
getLayer_(layer).gradient.activatePrecalculationMode(std::log(min_intensity + 1), std::log(overall_data_range_.maxPosition()[2]) + 1, param_.getValue("interpolation_steps"));
1023
1037
getLayer_(layer).gradient.activatePrecalculationMode(getMinIntensity(layer), overall_data_range_.maxPosition()[2], param_.getValue("interpolation_steps"));
1027
1041
void Spectrum2DCanvas::recalculateCurrentLayerDotGradient()
1029
1043
recalculateDotGradient_(current_layer_);
1032
void Spectrum2DCanvas::updateProjections()
1034
//find the last (visible) peak layers
1035
Size layer_count = 0;
1036
Size last_layer = 0;
1037
Size visible_layer_count = 0;
1038
Size visible_last_layer = 0;
1039
for (Size i=0; i<getLayerCount(); ++i)
1041
if (getLayer(i).type==LayerData::DT_PEAK)
1046
if (getLayer(i).visible)
1048
visible_layer_count++;
1049
visible_last_layer=i;
1046
void Spectrum2DCanvas::updateProjections()
1048
//find the last (visible) peak layers
1049
Size layer_count = 0;
1050
Size last_layer = 0;
1051
Size visible_layer_count = 0;
1052
Size visible_last_layer = 0;
1053
for (Size i = 0; i < getLayerCount(); ++i)
1055
if (getLayer(i).type == LayerData::DT_PEAK)
1060
if (getLayer(i).visible)
1062
visible_layer_count++;
1063
visible_last_layer = i;
1052
1066
if (getLayer(i).type == LayerData::DT_CHROMATOGRAM)
1058
//try to find the right layer to project
1059
const LayerData* layer = 0;
1060
//first choice: current layer
1061
if (layer_count!=0 && getCurrentLayer().type==LayerData::DT_PEAK)
1063
layer = &(getCurrentLayer());
1065
//second choice: the only peak layer
1066
else if (layer_count==1)
1068
layer = &(getLayer(last_layer));
1070
//third choice: the only visible peak layer
1071
else if (visible_layer_count==1)
1073
layer = &(getLayer(visible_last_layer));
1075
//no layer with peaks: disable projections
1078
emit toggleProjections();
1082
//create projection data
1083
map<float, float> rt;
1084
map<int, float> mzint;
1085
map<int,int> mzcount;
1086
map<int,float> mzsum;
1088
UInt peak_count = 0;
1089
DoubleReal intensity_max = 0.0;
1090
DoubleReal intensity_sum = 0.0;
1092
// divide visible range into 100 bins (much faster than using a constant, e.g. 0.05, leading to many peaks for large maps without more information)
1072
//try to find the right layer to project
1073
const LayerData * layer = 0;
1074
//first choice: current layer
1075
if (layer_count != 0 && getCurrentLayer().type == LayerData::DT_PEAK)
1077
layer = &(getCurrentLayer());
1079
//second choice: the only peak layer
1080
else if (layer_count == 1)
1082
layer = &(getLayer(last_layer));
1084
//third choice: the only visible peak layer
1085
else if (visible_layer_count == 1)
1087
layer = &(getLayer(visible_last_layer));
1089
//no layer with peaks: disable projections
1092
emit toggleProjections();
1096
//create projection data
1097
map<float, float> rt;
1098
map<int, float> mzint;
1099
map<int, int> mzcount;
1100
map<int, float> mzsum;
1102
UInt peak_count = 0;
1103
DoubleReal intensity_max = 0.0;
1104
DoubleReal intensity_sum = 0.0;
1106
// divide visible range into 100 bins (much faster than using a constant, e.g. 0.05, leading to many peaks for large maps without more information)
1093
1107
float range = visible_area_.maxPosition()[0] - visible_area_.minPosition()[0];
1094
float mult = 100.0f/(range<=0 ? 1 : range);
1108
float mult = 100.0f / (range <= 0 ? 1 : range);
1096
for (ExperimentType::ConstAreaIterator i = layer->getPeakData()->areaBeginConst(visible_area_.minPosition()[1],visible_area_.maxPosition()[1],visible_area_.minPosition()[0],visible_area_.maxPosition()[0]);
1110
for (ExperimentType::ConstAreaIterator i = layer->getPeakData()->areaBeginConst(visible_area_.minPosition()[1], visible_area_.maxPosition()[1], visible_area_.minPosition()[0], visible_area_.maxPosition()[0]);
1097
1111
i != layer->getPeakData()->areaEndConst();
1100
PeakIndex pi = i.getPeakIndex();
1101
if (layer->filters.passes((*layer->getPeakData())[pi.spectrum],pi.peak))
1105
intensity_sum += i->getIntensity();
1106
mzint[int(i->getMZ()*mult)] += i->getIntensity();
1107
mzcount[int(i->getMZ()*mult)]++;
1108
mzsum[int(i->getMZ()*mult)] += i->getMZ();
1110
rt[i.getRT()] += i->getIntensity();
1112
intensity_max = max(intensity_max,(DoubleReal)(i->getIntensity()));
1117
projection_mz_[0].resize(mzint.size()+2);
1118
projection_mz_[0][0].setMZ(visible_area_.minPosition()[0]);
1119
projection_mz_[0][0].setIntensity(0.0);
1120
projection_mz_[0][1].setMZ(visible_area_.maxPosition()[0]);
1121
projection_mz_[0][1].setIntensity(0.0);
1122
projection_rt_[0].resize(rt.size()+2);
1123
projection_rt_[0][0].setMZ(visible_area_.minPosition()[1]);
1124
projection_rt_[0][0].setIntensity(0.0);
1125
projection_rt_[0][1].setMZ(visible_area_.maxPosition()[1]);
1126
projection_rt_[0][1].setIntensity(0.0);
1129
map<int,float>::iterator intit = mzint.begin();
1130
map<int,int>::iterator cit = mzcount.begin();
1132
for (map<int, float>::iterator it = mzsum.begin(); it != mzsum.end(); ++it)
1134
projection_mz_[0][i].setMZ(it->second/cit->second);
1135
projection_mz_[0][i].setIntensity(intit->second);
1114
PeakIndex pi = i.getPeakIndex();
1115
if (layer->filters.passes((*layer->getPeakData())[pi.spectrum], pi.peak))
1119
intensity_sum += i->getIntensity();
1120
mzint[int(i->getMZ() * mult)] += i->getIntensity();
1121
mzcount[int(i->getMZ() * mult)]++;
1122
mzsum[int(i->getMZ() * mult)] += i->getMZ();
1124
rt[i.getRT()] += i->getIntensity();
1126
intensity_max = max(intensity_max, (DoubleReal)(i->getIntensity()));
1131
projection_mz_[0].resize(mzint.size() + 2);
1132
projection_mz_[0][0].setMZ(visible_area_.minPosition()[0]);
1133
projection_mz_[0][0].setIntensity(0.0);
1134
projection_mz_[0][1].setMZ(visible_area_.maxPosition()[0]);
1135
projection_mz_[0][1].setIntensity(0.0);
1136
projection_rt_[0].resize(rt.size() + 2);
1137
projection_rt_[0][0].setMZ(visible_area_.minPosition()[1]);
1138
projection_rt_[0][0].setIntensity(0.0);
1139
projection_rt_[0][1].setMZ(visible_area_.maxPosition()[1]);
1140
projection_rt_[0][1].setIntensity(0.0);
1143
map<int, float>::iterator intit = mzint.begin();
1144
map<int, int>::iterator cit = mzcount.begin();
1146
for (map<int, float>::iterator it = mzsum.begin(); it != mzsum.end(); ++it)
1148
projection_mz_[0][i].setMZ(it->second / cit->second);
1149
projection_mz_[0][i].setIntensity(intit->second);
1142
for (map<float, float>::iterator it = rt.begin(); it != rt.end(); ++it)
1144
projection_rt_[0][i].setMZ(it->first);
1145
projection_rt_[0][i].setIntensity(it->second);
1156
for (map<float, float>::iterator it = rt.begin(); it != rt.end(); ++it)
1158
projection_rt_[0][i].setMZ(it->first);
1159
projection_rt_[0][i].setIntensity(it->second);
1149
1163
ExperimentSharedPtrType projection_mz_sptr(new ExperimentType(projection_mz_));
1150
1164
ExperimentSharedPtrType projection_rt_sptr(new ExperimentType(projection_rt_));
1154
1168
emit showProjectionHorizontal(projection_mz_sptr, Spectrum1DCanvas::DM_PEAKS);
1155
1169
emit showProjectionVertical(projection_rt_sptr, Spectrum1DCanvas::DM_CONNECTEDLINES);
1159
1173
emit showProjectionHorizontal(projection_rt_sptr, Spectrum1DCanvas::DM_CONNECTEDLINES);
1160
1174
emit showProjectionVertical(projection_mz_sptr, Spectrum1DCanvas::DM_PEAKS);
1162
showProjectionInfo(peak_count, intensity_sum, intensity_max);
1165
bool Spectrum2DCanvas::finishAdding_()
1167
//unselect all peaks
1168
selected_peak_.clear();
1169
measurement_start_.clear();
1171
current_layer_ = getLayerCount()-1;
1173
if (layers_.back().type==LayerData::DT_PEAK) //peak data
1175
update_buffer_ = true;
1176
//Abort if no data points are contained
1177
if (currentPeakData_()->size()==0 || currentPeakData_()->getSize()==0)
1179
layers_.resize(getLayerCount()-1);
1180
if (current_layer_!=0)
1176
showProjectionInfo(peak_count, intensity_sum, intensity_max);
1179
bool Spectrum2DCanvas::finishAdding_()
1181
//unselect all peaks
1182
selected_peak_.clear();
1183
measurement_start_.clear();
1185
current_layer_ = getLayerCount() - 1;
1187
if (layers_.back().type == LayerData::DT_PEAK) //peak data
1189
update_buffer_ = true;
1190
//Abort if no data points are contained
1191
if ((currentPeakData_()->size() == 0 || currentPeakData_()->getSize() == 0) && currentPeakData_()->getDataRange().isEmpty())
1193
layers_.resize(getLayerCount() - 1);
1194
if (current_layer_ != 0)
1182
current_layer_ = current_layer_-1;
1196
current_layer_ = current_layer_ - 1;
1184
QMessageBox::critical(this,"Error","Cannot add a dataset that contains no survey scans. Aborting!");
1188
else if (layers_.back().type==LayerData::DT_FEATURE)//feature data
1198
QMessageBox::critical(this, "Error", "Cannot add a dataset that contains no survey scans. Aborting!");
1201
if ((currentPeakData_()->getSize() == 0) && (!currentPeakData_()->getDataRange().isEmpty()))
1203
setLayerFlag(LayerData::P_PRECURSORS, true); // show precursors if no MS1 data is contained
1206
else if (layers_.back().type == LayerData::DT_FEATURE) //feature data
1190
1208
getCurrentLayer_().getFeatureMap()->updateRanges();
1191
setLayerFlag(LayerData::F_HULL,true);
1209
setLayerFlag(LayerData::F_HULL, true);
1193
//Abort if no data points are contained
1194
if (getCurrentLayer_().getFeatureMap()->size()==0)
1196
layers_.resize(getLayerCount()-1);
1197
if (current_layer_!=0)
1211
//Abort if no data points are contained
1212
if (getCurrentLayer_().getFeatureMap()->size() == 0)
1214
layers_.resize(getLayerCount() - 1);
1215
if (current_layer_ != 0)
1199
current_layer_ = current_layer_-1;
1217
current_layer_ = current_layer_ - 1;
1201
QMessageBox::critical(this,"Error","Cannot add an empty dataset. Aborting!");
1205
else if (layers_.back().type==LayerData::DT_CONSENSUS)//consensus feature data
1219
QMessageBox::critical(this, "Error", "Cannot add an empty dataset. Aborting!");
1223
else if (layers_.back().type == LayerData::DT_CONSENSUS) //consensus feature data
1207
1225
getCurrentLayer_().getConsensusMap()->updateRanges();
1209
//Abort if no data points are contained
1210
if (getCurrentLayer_().getConsensusMap()->size()==0)
1212
layers_.resize(getLayerCount()-1);
1213
if (current_layer_!=0) current_layer_ = current_layer_-1;
1214
QMessageBox::critical(this,"Error","Cannot add an empty dataset. Aborting!");
1218
else if (layers_.back().type==LayerData::DT_CHROMATOGRAM)//chromatogram data
1227
//Abort if no data points are contained
1228
if (getCurrentLayer_().getConsensusMap()->size() == 0)
1230
layers_.resize(getLayerCount() - 1);
1231
if (current_layer_ != 0)
1232
current_layer_ = current_layer_ - 1;
1233
QMessageBox::critical(this, "Error", "Cannot add an empty dataset. Aborting!");
1237
else if (layers_.back().type == LayerData::DT_CHROMATOGRAM) //chromatogram data
1222
1241
currentPeakData_()->sortChromatograms(true);
1223
1242
currentPeakData_()->updateRanges(1);
1225
update_buffer_ = true;
1244
update_buffer_ = true;
1227
//Abort if no data points are contained
1246
//Abort if no data points are contained
1228
1247
if (currentPeakData_()->getChromatograms().empty())
1230
layers_.resize(getLayerCount()-1);
1231
if (current_layer_!=0) current_layer_ = current_layer_-1;
1232
QMessageBox::critical(this,"Error","Cannot add a dataset that contains no chromatograms. Aborting!");
1236
else if (layers_.back().type==LayerData::DT_IDENT) // identification data
1238
//Abort if no data points are contained
1239
if (getCurrentLayer_().peptides.empty())
1241
layers_.resize(getLayerCount()-1);
1242
if (current_layer_!=0) current_layer_ = current_layer_-1;
1243
QMessageBox::critical(this,"Error","Cannot add an empty dataset. Aborting!");
1248
//Warn if negative intensities are contained
1249
if (getMinIntensity(current_layer_)<0.0)
1251
QMessageBox::warning(this,"Warning","This dataset contains negative intensities. Use it at your own risk!");
1254
//overall values update
1255
recalculateRanges_(0,1,2);
1249
layers_.resize(getLayerCount() - 1);
1250
if (current_layer_ != 0)
1251
current_layer_ = current_layer_ - 1;
1252
QMessageBox::critical(this, "Error", "Cannot add a dataset that contains no chromatograms. Aborting!");
1256
else if (layers_.back().type == LayerData::DT_IDENT) // identification data
1258
//Abort if no data points are contained
1259
if (getCurrentLayer_().peptides.empty())
1261
layers_.resize(getLayerCount() - 1);
1262
if (current_layer_ != 0)
1263
current_layer_ = current_layer_ - 1;
1264
QMessageBox::critical(this, "Error", "Cannot add an empty dataset. Aborting!");
1269
//Warn if negative intensities are contained
1270
if (getMinIntensity(current_layer_) < 0.0)
1272
QMessageBox::warning(this, "Warning", "This dataset contains negative intensities. Use it at your own risk!");
1275
//overall values update
1276
recalculateRanges_(0, 1, 2);
1256
1277
if (layers_.size() == 1)
1258
1279
resetZoom(false); //no repaint as this is done in intensityModeChange_() anyway
1261
if (getLayerCount()==2)
1263
setIntensityMode(IM_PERCENTAGE);
1265
intensityModeChange_();
1267
emit layerActivated(this);
1272
void Spectrum2DCanvas::removeLayer(Size layer_index )
1274
if (layer_index >= getLayerCount())
1282
if (getLayerCount() == 2)
1284
setIntensityMode(IM_PERCENTAGE);
1286
intensityModeChange_();
1288
emit layerActivated(this);
1293
void Spectrum2DCanvas::removeLayer(Size layer_index)
1295
if (layer_index >= getLayerCount())
1279
1300
// remove the data
1280
layers_.erase(layers_.begin()+layer_index);
1301
layers_.erase(layers_.begin() + layer_index);
1282
1303
// update visible area and boundaries
1283
1304
DRange<3> old_data_range = overall_data_range_;
1284
recalculateRanges_(0,1,2);
1305
recalculateRanges_(0, 1, 2);
1286
1307
// only reset zoom if data range has been changed
1287
1308
if (old_data_range != overall_data_range_)
1292
1313
// update current layer if it became invalid
1293
1314
if (current_layer_ != 0 && current_layer_ >= getLayerCount())
1295
current_layer_ = getLayerCount()-1;
1316
current_layer_ = getLayerCount() - 1;
1298
if (layers_.empty())
1300
overall_data_range_ = DRange<3>::empty;
1301
update_buffer_ = true;
1302
update_(__PRETTY_FUNCTION__);
1319
if (layers_.empty())
1321
overall_data_range_ = DRange<3>::empty;
1322
update_buffer_ = true;
1323
update_(__PRETTY_FUNCTION__);
1306
1327
// unselect all peaks
1307
1328
selected_peak_.clear();
1308
1329
measurement_start_.clear();
1310
intensityModeChange_();
1312
emit layerActivated(this);
1315
//change the current layer
1316
void Spectrum2DCanvas::activateLayer(Size layer_index)
1331
intensityModeChange_();
1333
emit layerActivated(this);
1336
//change the current layer
1337
void Spectrum2DCanvas::activateLayer(Size layer_index)
1318
1339
if (layer_index >= getLayerCount() || layer_index == current_layer_)
1323
1344
// unselect all peaks
1324
selected_peak_.clear();
1325
measurement_start_.clear();
1327
current_layer_ = layer_index;
1328
emit layerActivated(this);
1330
update_(__PRETTY_FUNCTION__);
1333
void Spectrum2DCanvas::recalculateSnapFactor_()
1335
snap_factors_ = vector<DoubleReal>(getLayerCount(),1.0);
1337
if (intensity_mode_ == IM_SNAP)
1339
for (Size i=0; i<getLayerCount(); i++)
1341
if (getLayer(i).visible)
1343
DoubleReal local_max = -numeric_limits<DoubleReal>::max();
1344
if (getLayer(i).type==LayerData::DT_PEAK)
1346
for (ExperimentType::ConstAreaIterator it = getLayer(i).getPeakData()->areaBeginConst(visible_area_.minPosition()[1],visible_area_.maxPosition()[1],visible_area_.minPosition()[0],visible_area_.maxPosition()[0]);
1347
it != getLayer(i).getPeakData()->areaEndConst();
1350
PeakIndex pi = it.getPeakIndex();
1351
if (it->getIntensity() > local_max && getLayer(i).filters.passes((*getLayer(i).getPeakData())[pi.spectrum],pi.peak))
1353
local_max = it->getIntensity();
1357
else if (getLayer(i).type==LayerData::DT_FEATURE) // features
1345
selected_peak_.clear();
1346
measurement_start_.clear();
1348
current_layer_ = layer_index;
1349
emit layerActivated(this);
1351
update_(__PRETTY_FUNCTION__);
1354
void Spectrum2DCanvas::recalculateSnapFactor_()
1356
snap_factors_ = vector<DoubleReal>(getLayerCount(), 1.0);
1358
if (intensity_mode_ == IM_SNAP)
1360
for (Size i = 0; i < getLayerCount(); i++)
1362
if (getLayer(i).visible)
1364
DoubleReal local_max = -numeric_limits<DoubleReal>::max();
1365
if (getLayer(i).type == LayerData::DT_PEAK)
1367
for (ExperimentType::ConstAreaIterator it = getLayer(i).getPeakData()->areaBeginConst(visible_area_.minPosition()[1], visible_area_.maxPosition()[1], visible_area_.minPosition()[0], visible_area_.maxPosition()[0]);
1368
it != getLayer(i).getPeakData()->areaEndConst();
1371
PeakIndex pi = it.getPeakIndex();
1372
if (it->getIntensity() > local_max && getLayer(i).filters.passes((*getLayer(i).getPeakData())[pi.spectrum], pi.peak))
1374
local_max = it->getIntensity();
1378
else if (getLayer(i).type == LayerData::DT_FEATURE) // features
1359
1380
for (FeatureMapType::ConstIterator it = getLayer(i).getFeatureMap()->begin();
1360
1381
it != getLayer(i).getFeatureMap()->end();
1363
if ( it->getRT() >= visible_area_.minPosition()[1] &&
1364
it->getRT() <= visible_area_.maxPosition()[1] &&
1365
it->getMZ() >= visible_area_.minPosition()[0] &&
1366
it->getMZ() <= visible_area_.maxPosition()[0] &&
1367
getLayer(i).filters.passes(*it) &&
1368
it->getIntensity() > local_max)
1370
local_max = it->getIntensity();
1374
else if (getLayer(i).type==LayerData::DT_CONSENSUS) // consensus
1384
if (it->getRT() >= visible_area_.minPosition()[1] &&
1385
it->getRT() <= visible_area_.maxPosition()[1] &&
1386
it->getMZ() >= visible_area_.minPosition()[0] &&
1387
it->getMZ() <= visible_area_.maxPosition()[0] &&
1388
getLayer(i).filters.passes(*it) &&
1389
it->getIntensity() > local_max)
1391
local_max = it->getIntensity();
1395
else if (getLayer(i).type == LayerData::DT_CONSENSUS) // consensus
1376
1397
for (ConsensusMapType::ConstIterator it = getLayer(i).getConsensusMap()->begin();
1377
1398
it != getLayer(i).getConsensusMap()->end();
1380
if ( it->getRT() >= visible_area_.minPosition()[1] &&
1381
it->getRT() <= visible_area_.maxPosition()[1] &&
1382
it->getMZ() >= visible_area_.minPosition()[0] &&
1383
it->getMZ() <= visible_area_.maxPosition()[0] &&
1384
getLayer(i).filters.passes(*it) &&
1385
it->getIntensity() > local_max)
1387
local_max = it->getIntensity();
1391
else if (getLayer(i).type==LayerData::DT_CHROMATOGRAM) // chromatogr.
1395
else if (getLayer(i).type==LayerData::DT_IDENT) // identifications
1402
snap_factors_[i] = overall_data_range_.maxPosition()[2]/local_max;
1409
void Spectrum2DCanvas::updateScrollbars_()
1413
emit updateHScrollbar(overall_data_range_.minPosition()[0],visible_area_.minPosition()[0],visible_area_.maxPosition()[0],overall_data_range_.maxPosition()[0]);
1414
emit updateVScrollbar(overall_data_range_.minPosition()[1],visible_area_.minPosition()[1],visible_area_.maxPosition()[1],overall_data_range_.maxPosition()[1]);
1418
emit updateVScrollbar(overall_data_range_.minPosition()[0],visible_area_.minPosition()[0],visible_area_.maxPosition()[0],overall_data_range_.maxPosition()[0]);
1419
emit updateHScrollbar(overall_data_range_.minPosition()[1],visible_area_.minPosition()[1],visible_area_.maxPosition()[1],overall_data_range_.maxPosition()[1]);
1423
void Spectrum2DCanvas::horizontalScrollBarChange(int value)
1425
AreaType new_area = visible_area_;
1428
new_area.setMinX(value);
1429
new_area.setMaxX(value + (visible_area_.maxX() - visible_area_.minX()));
1430
//cout << __PRETTY_FUNCTION__ << endl;
1431
changeVisibleArea_(new_area);
1435
new_area.setMinY(value);
1436
new_area.setMaxY(value + (visible_area_.maxY() - visible_area_.minY()));
1437
//cout << __PRETTY_FUNCTION__ << endl;
1438
changeVisibleArea_(new_area);
1442
void Spectrum2DCanvas::verticalScrollBarChange(int value)
1444
AreaType new_area = visible_area_;
1447
new_area.setMinX(value);
1448
new_area.setMaxX(value + (visible_area_.maxX() - visible_area_.minX()));
1449
//cout << __PRETTY_FUNCTION__ << endl;
1450
changeVisibleArea_(new_area);
1454
new_area.setMinY(value);
1455
new_area.setMaxY(value + (visible_area_.maxY() - visible_area_.minY()));
1456
//cout << __PRETTY_FUNCTION__ << endl;
1457
changeVisibleArea_(new_area);
1461
void Spectrum2DCanvas::paintEvent(QPaintEvent* e)
1463
//Only fill background if no layer is present
1464
if (getLayerCount()==0)
1467
painter.begin(this);
1468
painter.fillRect(0,0,this->width(),this->height(),QColor(param_.getValue("background_color").toQString()));
1401
if (it->getRT() >= visible_area_.minPosition()[1] &&
1402
it->getRT() <= visible_area_.maxPosition()[1] &&
1403
it->getMZ() >= visible_area_.minPosition()[0] &&
1404
it->getMZ() <= visible_area_.maxPosition()[0] &&
1405
getLayer(i).filters.passes(*it) &&
1406
it->getIntensity() > local_max)
1408
local_max = it->getIntensity();
1412
else if (getLayer(i).type == LayerData::DT_CHROMATOGRAM) // chromatogr.
1416
else if (getLayer(i).type == LayerData::DT_IDENT) // identifications
1421
if (local_max > 0.0)
1423
snap_factors_[i] = overall_data_range_.maxPosition()[2] / local_max;
1430
void Spectrum2DCanvas::updateScrollbars_()
1434
emit updateHScrollbar(overall_data_range_.minPosition()[0], visible_area_.minPosition()[0], visible_area_.maxPosition()[0], overall_data_range_.maxPosition()[0]);
1435
emit updateVScrollbar(overall_data_range_.minPosition()[1], visible_area_.minPosition()[1], visible_area_.maxPosition()[1], overall_data_range_.maxPosition()[1]);
1439
emit updateVScrollbar(overall_data_range_.minPosition()[0], visible_area_.minPosition()[0], visible_area_.maxPosition()[0], overall_data_range_.maxPosition()[0]);
1440
emit updateHScrollbar(overall_data_range_.minPosition()[1], visible_area_.minPosition()[1], visible_area_.maxPosition()[1], overall_data_range_.maxPosition()[1]);
1444
void Spectrum2DCanvas::horizontalScrollBarChange(int value)
1446
AreaType new_area = visible_area_;
1449
new_area.setMinX(value);
1450
new_area.setMaxX(value + (visible_area_.maxX() - visible_area_.minX()));
1451
//cout << __PRETTY_FUNCTION__ << endl;
1452
changeVisibleArea_(new_area);
1453
emit layerZoomChanged(this);
1457
new_area.setMinY(value);
1458
new_area.setMaxY(value + (visible_area_.maxY() - visible_area_.minY()));
1459
//cout << __PRETTY_FUNCTION__ << endl;
1460
changeVisibleArea_(new_area);
1461
emit layerZoomChanged(this);
1465
void Spectrum2DCanvas::verticalScrollBarChange(int value)
1467
AreaType new_area = visible_area_;
1470
new_area.setMinX(value);
1471
new_area.setMaxX(value + (visible_area_.maxX() - visible_area_.minX()));
1472
//cout << __PRETTY_FUNCTION__ << endl;
1473
changeVisibleArea_(new_area);
1474
emit layerZoomChanged(this);
1478
new_area.setMinY(value);
1479
new_area.setMaxY(value + (visible_area_.maxY() - visible_area_.minY()));
1480
//cout << __PRETTY_FUNCTION__ << endl;
1481
changeVisibleArea_(new_area);
1482
emit layerZoomChanged(this);
1486
void Spectrum2DCanvas::paintEvent(QPaintEvent * e)
1488
//Only fill background if no layer is present
1489
if (getLayerCount() == 0)
1492
painter.begin(this);
1493
painter.fillRect(0, 0, this->width(), this->height(), QColor(param_.getValue("background_color").toQString()));
1474
1499
#ifdef DEBUG_TOPPVIEW
1475
cout << "BEGIN " << __PRETTY_FUNCTION__ << endl;
1476
cout << " Visible area -- m/z: " << visible_area_.minX() << " - " << visible_area_.maxX() << " rt: " << visible_area_.minY() << " - " << visible_area_.maxY() << endl;
1477
cout << " Overall area -- m/z: " << overall_data_range_.minPosition()[0] << " - " << overall_data_range_.maxPosition()[0] << " rt: " << overall_data_range_.minPosition()[1] << " - " << overall_data_range_.maxPosition()[1] << endl;
1500
cout << "BEGIN " << __PRETTY_FUNCTION__ << endl;
1501
cout << " Visible area -- m/z: " << visible_area_.minX() << " - " << visible_area_.maxX() << " rt: " << visible_area_.minY() << " - " << visible_area_.maxY() << endl;
1502
cout << " Overall area -- m/z: " << overall_data_range_.minPosition()[0] << " - " << overall_data_range_.maxPosition()[0] << " rt: " << overall_data_range_.minPosition()[1] << " - " << overall_data_range_.maxPosition()[1] << endl;
1481
QTime overall_timer;
1484
overall_timer.start();
1487
cout << "Updating buffer:" << endl;
1491
cout << "Copying buffer:" << endl;
1498
update_buffer_ = false;
1500
//recalculate snap factor
1501
recalculateSnapFactor_();
1503
buffer_.fill(QColor(param_.getValue("background_color").toQString()).rgb());
1504
painter.begin(&buffer_);
1507
for (Size i=0; i<getLayerCount(); i++)
1512
layer_timer.start();
1515
if (getLayer(i).visible)
1517
if (getLayer(i).type==LayerData::DT_PEAK)
1519
paintDots_(i, painter);
1521
else if (getLayer(i).type==LayerData::DT_FEATURE)
1523
//cout << "dot feature layer: " << i << endl;
1524
if (getLayerFlag(i,LayerData::F_HULLS))
1526
paintTraceConvexHulls_(i, painter);
1528
if (getLayerFlag(i,LayerData::F_HULL))
1530
paintFeatureConvexHulls_(i, painter);
1532
if (getLayerFlag(i,LayerData::F_UNASSIGNED))
1534
paintIdentifications_(i, painter);
1536
paintDots_(i, painter);
1538
else if (getLayer(i).type==LayerData::DT_CONSENSUS)
1540
if (getLayerFlag(i,LayerData::C_ELEMENTS))
1542
paintConsensusElements_(i, painter);
1544
paintDots_(i, painter);
1546
else if (getLayer(i).type==LayerData::DT_CHROMATOGRAM)
1549
paintDots_(i, painter);
1551
else if (getLayer(i).type == LayerData::DT_IDENT)
1553
paintDots_(i, painter);
1559
cout << " -layer " << i << " time: " << layer_timer.elapsed() << " ms" << endl;
1562
paintGridLines_(painter);
1566
painter.begin(this);
1568
//copy peak data from buffer
1569
QVector<QRect> rects = e->region().rects();
1570
for (int i = 0; i < (int)rects.size(); ++i)
1572
painter.drawImage(rects[i].topLeft(), buffer_, rects[i]);
1575
//draw measurement peak
1576
if (action_mode_==AM_MEASURE && measurement_start_.isValid())
1578
painter.setPen(Qt::black);
1580
QPoint line_begin, line_end;
1582
if (selected_peak_.isValid())
1584
if (getCurrentLayer().type==LayerData::DT_FEATURE)
1506
QTime overall_timer;
1509
overall_timer.start();
1512
cout << "Updating buffer:" << endl;
1516
cout << "Copying buffer:" << endl;
1523
update_buffer_ = false;
1525
//recalculate snap factor
1526
recalculateSnapFactor_();
1528
buffer_.fill(QColor(param_.getValue("background_color").toQString()).rgb());
1529
painter.begin(&buffer_);
1532
for (Size i = 0; i < getLayerCount(); i++)
1537
layer_timer.start();
1540
if (getLayer(i).visible)
1542
if (getLayer(i).type == LayerData::DT_PEAK)
1544
paintDots_(i, painter);
1546
else if (getLayer(i).type == LayerData::DT_FEATURE)
1548
//cout << "dot feature layer: " << i << endl;
1549
if (getLayerFlag(i, LayerData::F_HULLS))
1551
paintTraceConvexHulls_(i, painter);
1553
if (getLayerFlag(i, LayerData::F_HULL))
1555
paintFeatureConvexHulls_(i, painter);
1557
if (getLayerFlag(i, LayerData::F_UNASSIGNED))
1559
paintIdentifications_(i, painter);
1561
paintDots_(i, painter);
1563
else if (getLayer(i).type == LayerData::DT_CONSENSUS)
1565
if (getLayerFlag(i, LayerData::C_ELEMENTS))
1567
paintConsensusElements_(i, painter);
1569
paintDots_(i, painter);
1571
else if (getLayer(i).type == LayerData::DT_CHROMATOGRAM)
1574
paintDots_(i, painter);
1576
else if (getLayer(i).type == LayerData::DT_IDENT)
1578
paintDots_(i, painter);
1584
cout << " -layer " << i << " time: " << layer_timer.elapsed() << " ms" << endl;
1587
paintGridLines_(painter);
1591
painter.begin(this);
1593
//copy peak data from buffer
1594
QVector<QRect> rects = e->region().rects();
1595
for (int i = 0; i < (int)rects.size(); ++i)
1597
painter.drawImage(rects[i].topLeft(), buffer_, rects[i]);
1600
//draw measurement peak
1601
if (action_mode_ == AM_MEASURE && measurement_start_.isValid())
1603
painter.setPen(Qt::black);
1605
QPoint line_begin, line_end;
1607
if (selected_peak_.isValid())
1609
if (getCurrentLayer().type == LayerData::DT_FEATURE)
1586
1611
dataToWidget_(selected_peak_.getFeature(*getCurrentLayer().getFeatureMap()).getMZ(), selected_peak_.getFeature(*getCurrentLayer().getFeatureMap()).getRT(), line_begin);
1588
else if (getCurrentLayer().type==LayerData::DT_PEAK)
1613
else if (getCurrentLayer().type == LayerData::DT_PEAK)
1590
1615
dataToWidget_(selected_peak_.getPeak(*getCurrentLayer().getPeakData()).getMZ(), selected_peak_.getSpectrum(*getCurrentLayer().getPeakData()).getRT(), line_begin);
1592
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS)
1617
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS)
1594
1619
dataToWidget_(selected_peak_.getFeature(*getCurrentLayer().getConsensusMap()).getMZ(), selected_peak_.getFeature(*getCurrentLayer().getConsensusMap()).getRT(), line_begin);
1596
else if (getCurrentLayer().type==LayerData::DT_CHROMATOGRAM)
1603
line_begin = last_mouse_pos_;
1606
if (getCurrentLayer().type==LayerData::DT_FEATURE)
1608
dataToWidget_(measurement_start_.getFeature(*getCurrentLayer().getFeatureMap()).getMZ(),measurement_start_.getFeature(*getCurrentLayer().getFeatureMap()).getRT(),line_end);
1610
else if (getCurrentLayer().type==LayerData::DT_PEAK)
1612
dataToWidget_(measurement_start_.getPeak(*getCurrentLayer().getPeakData()).getMZ(),measurement_start_.getSpectrum(*getCurrentLayer().getPeakData()).getRT(),line_end);
1614
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS)
1616
dataToWidget_(measurement_start_.getFeature(*getCurrentLayer().getConsensusMap()).getMZ(),measurement_start_.getFeature(*getCurrentLayer().getConsensusMap()).getRT(),line_end);
1618
else if (getCurrentLayer().type==LayerData::DT_CHROMATOGRAM)
1622
painter.drawLine(line_begin, line_end);
1624
highlightPeak_(painter, measurement_start_);
1627
//draw convex hulls or consensus feature elements
1628
if (selected_peak_.isValid())
1630
if (getCurrentLayer().type==LayerData::DT_FEATURE)
1632
painter.setPen(QPen(Qt::red, 2));
1633
paintConvexHulls_(selected_peak_.getFeature(*getCurrentLayer().getFeatureMap()). getConvexHulls(),painter);
1635
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS && getLayerFlag(current_layer_,LayerData::C_ELEMENTS))
1637
painter.setPen(QPen(Qt::red, 2));
1638
paintConsensusElement_(current_layer_, selected_peak_.getFeature(*getCurrentLayer().getConsensusMap()),painter,false);
1642
if (action_mode_==AM_MEASURE || action_mode_==AM_TRANSLATE)
1621
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM)
1628
line_begin = last_mouse_pos_;
1631
if (getCurrentLayer().type == LayerData::DT_FEATURE)
1633
dataToWidget_(measurement_start_.getFeature(*getCurrentLayer().getFeatureMap()).getMZ(), measurement_start_.getFeature(*getCurrentLayer().getFeatureMap()).getRT(), line_end);
1635
else if (getCurrentLayer().type == LayerData::DT_PEAK)
1637
dataToWidget_(measurement_start_.getPeak(*getCurrentLayer().getPeakData()).getMZ(), measurement_start_.getSpectrum(*getCurrentLayer().getPeakData()).getRT(), line_end);
1639
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS)
1641
dataToWidget_(measurement_start_.getFeature(*getCurrentLayer().getConsensusMap()).getMZ(), measurement_start_.getFeature(*getCurrentLayer().getConsensusMap()).getRT(), line_end);
1643
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM)
1647
painter.drawLine(line_begin, line_end);
1649
highlightPeak_(painter, measurement_start_);
1652
//draw convex hulls or consensus feature elements
1653
if (selected_peak_.isValid())
1655
if (getCurrentLayer().type == LayerData::DT_FEATURE)
1657
painter.setPen(QPen(Qt::red, 2));
1658
const Feature& f = selected_peak_.getFeature(*getCurrentLayer().getFeatureMap());
1659
paintConvexHulls_(f.getConvexHulls(),
1660
f.getPeptideIdentifications().size() && f.getPeptideIdentifications()[0].getHits().size(),
1663
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS && getLayerFlag(current_layer_, LayerData::C_ELEMENTS))
1665
painter.setPen(QPen(Qt::red, 2));
1666
paintConsensusElement_(current_layer_, selected_peak_.getFeature(*getCurrentLayer().getConsensusMap()), painter, false);
1670
if (action_mode_ == AM_MEASURE || action_mode_ == AM_TRANSLATE)
1644
1672
highlightPeak_(painter, selected_peak_);
1647
//draw delta for measuring
1648
if (action_mode_==AM_MEASURE && measurement_start_.isValid())
1650
drawDeltas_(painter, measurement_start_, selected_peak_);
1654
drawCoordinates_(painter, selected_peak_);
1675
//draw delta for measuring
1676
if (action_mode_ == AM_MEASURE && measurement_start_.isValid())
1678
drawDeltas_(painter, measurement_start_, selected_peak_);
1682
drawCoordinates_(painter, selected_peak_);
1658
1686
#ifdef DEBUG_TOPPVIEW
1659
cout << "END " << __PRETTY_FUNCTION__ << endl;
1687
cout << "END " << __PRETTY_FUNCTION__ << endl;
1663
cout << " -overall time: " << overall_timer.elapsed() << " ms" << endl << endl;
1668
void Spectrum2DCanvas::drawCoordinates_(QPainter& painter, const PeakIndex& peak)
1670
if (!peak.isValid()) return;
1672
//determine coordinates;
1673
DoubleReal mz = 0.0;
1674
DoubleReal rt = 0.0;
1677
DoubleReal quality = 0.0;
1691
cout << " -overall time: " << overall_timer.elapsed() << " ms" << endl << endl;
1695
void Spectrum2DCanvas::drawCoordinates_(QPainter & painter, const PeakIndex & peak)
1697
if (!peak.isValid())
1700
//determine coordinates;
1701
DoubleReal mz = 0.0;
1702
DoubleReal rt = 0.0;
1705
DoubleReal quality = 0.0;
1707
const Feature* f = NULL;
1708
const ConsensusFeature* cf = NULL;
1679
1709
ConsensusFeature::HandleSetType sub_features;
1681
switch(getCurrentLayer().type)
1683
case LayerData::DT_FEATURE :
1685
const Feature& f = peak.getFeature(*getCurrentLayer().getFeatureMap());
1688
it = f.getIntensity();
1689
charge = f.getCharge();
1690
quality = f.getOverallQuality();
1693
case LayerData::DT_PEAK :
1695
const Peak1D& p = peak.getPeak(*getCurrentLayer().getPeakData());
1696
const MSSpectrum<>& s = peak.getSpectrum(*getCurrentLayer().getPeakData());
1699
it = p.getIntensity();
1702
case LayerData::DT_CONSENSUS :
1704
const ConsensusFeature& cf = peak.getFeature(*getCurrentLayer().getConsensusMap());
1708
it = cf.getIntensity();
1709
charge = cf.getCharge();
1710
quality = cf.getQuality();
1711
sub_features = cf.getFeatures();
1712
size = sub_features.size();
1716
case LayerData::DT_CHROMATOGRAM :
1718
const LayerData& layer = getCurrentLayer();
1720
MSExperiment<Peak1D> exp;
1721
exp = *layer.getPeakData();
1723
vector<MSChromatogram<> >::const_iterator iter = exp.getChromatograms().begin();
1724
iter += peak.spectrum;
1726
mz = iter->getPrecursor().getMZ();
1727
rt = iter->front().getRT();
1731
case LayerData::DT_IDENT :
1711
switch (getCurrentLayer().type)
1713
case LayerData::DT_FEATURE:
1715
f = &peak.getFeature(*getCurrentLayer().getFeatureMap());
1718
it = f->getIntensity();
1719
charge = f->getCharge();
1720
quality = f->getOverallQuality();
1724
case LayerData::DT_PEAK:
1726
const Peak1D & p = peak.getPeak(*getCurrentLayer().getPeakData());
1727
const MSSpectrum<> & s = peak.getSpectrum(*getCurrentLayer().getPeakData());
1730
it = p.getIntensity();
1734
case LayerData::DT_CONSENSUS:
1736
cf = &peak.getFeature(*getCurrentLayer().getConsensusMap());
1740
it = cf->getIntensity();
1741
charge = cf->getCharge();
1742
quality = cf->getQuality();
1743
sub_features = cf->getFeatures();
1744
size = sub_features.size();
1748
case LayerData::DT_CHROMATOGRAM:
1750
const LayerData & layer = getCurrentLayer();
1752
MSExperiment<Peak1D> exp;
1753
exp = *layer.getPeakData();
1755
vector<MSChromatogram<> >::const_iterator iter = exp.getChromatograms().begin();
1756
iter += peak.spectrum;
1758
mz = iter->getPrecursor().getMZ();
1759
rt = iter->front().getRT();
1763
case LayerData::DT_IDENT:
1732
1764
// TODO implement
1741
lines.push_back("RT: " + QString::number(rt,'f',2));
1742
lines.push_back("m/z: " + QString::number(mz,'f',2));
1743
lines.push_back("Int: " + QString::number(it,'f',2));
1773
lines.push_back("RT: " + QString::number(rt, 'f', 2));
1774
lines.push_back("m/z: " + QString::number(mz, 'f', 2));
1775
lines.push_back("Int: " + QString::number(it, 'f', 2));
1745
if (getCurrentLayer().type == LayerData::DT_FEATURE || getCurrentLayer().type==LayerData::DT_CONSENSUS)
1747
lines.push_back("Charge: " + QString::number(charge));
1748
lines.push_back("Quality: " + QString::number(quality,'f',4));
1777
if (getCurrentLayer().type == LayerData::DT_FEATURE || getCurrentLayer().type == LayerData::DT_CONSENSUS)
1779
lines.push_back("Charge: " + QString::number(charge));
1780
lines.push_back("Quality: " + QString::number(quality, 'f', 4));
1781
// peptide identifications
1782
const PeptideIdentification* pis = NULL;
1783
if ( f && f->getPeptideIdentifications().size() > 0 ) {
1784
pis = &f->getPeptideIdentifications()[0];
1786
else if ( cf && cf->getPeptideIdentifications().size() > 0 ) {
1787
pis = &cf->getPeptideIdentifications()[0];
1789
if ( pis && pis->getHits().size() ) {
1790
Size nHits = pis->getHits().size();
1791
for (Size j = 0; j < nHits; ++j)
1793
lines.push_back( "Peptide" + ( nHits > 1 ? "[" + QString::number(j+1) + "]" : "" ) + ": "
1794
+ pis->getHits()[j].getSequence().toString().toQString() );
1751
1799
if (getCurrentLayer().type == LayerData::DT_CONSENSUS)
1753
1801
lines.push_back("Size: " + QString::number(size));
1754
for ( ConsensusFeature::HandleSetType::const_iterator it = sub_features.begin(); it != sub_features.end(); ++it)
1802
for (ConsensusFeature::HandleSetType::const_iterator it = sub_features.begin(); it != sub_features.end(); ++it)
1756
lines.push_back("Feature m/z:" + QString::number(it->getMZ(),'f',2) +
1757
" rt:" + QString::number(it->getRT(),'f',2) +
1758
" q:" + QString::number(it->getCharge(),'f',2) +
1759
" intensity:" + QString::number(it->getIntensity(),'f',2));
1804
lines.push_back("Feature m/z:" + QString::number(it->getMZ(), 'f', 2) +
1805
" rt:" + QString::number(it->getRT(), 'f', 2) +
1806
" q:" + QString::number(it->getCharge(), 'f', 2) +
1807
" intensity:" + QString::number(it->getIntensity(), 'f', 2));
1763
drawText_(painter, lines);
1766
void Spectrum2DCanvas::drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end)
1768
if (!start.isValid()) return;
1770
//determine coordinates;
1771
DoubleReal mz = 0.0;
1772
DoubleReal rt = 0.0;
1774
if (getCurrentLayer().type==LayerData::DT_FEATURE)
1811
drawText_(painter, lines);
1814
void Spectrum2DCanvas::drawDeltas_(QPainter & painter, const PeakIndex & start, const PeakIndex & end)
1816
if (!start.isValid())
1819
//determine coordinates;
1820
DoubleReal mz = 0.0;
1821
DoubleReal rt = 0.0;
1823
if (getCurrentLayer().type == LayerData::DT_FEATURE)
1778
1827
mz = end.getFeature(*getCurrentLayer().getFeatureMap()).getMZ() - start.getFeature(*getCurrentLayer().getFeatureMap()).getMZ();
1779
1828
rt = end.getFeature(*getCurrentLayer().getFeatureMap()).getRT() - start.getFeature(*getCurrentLayer().getFeatureMap()).getRT();
1780
1829
it = end.getFeature(*getCurrentLayer().getFeatureMap()).getIntensity() / start.getFeature(*getCurrentLayer().getFeatureMap()).getIntensity();
1784
PointType point = widgetToData_(last_mouse_pos_);
1833
PointType point = widgetToData_(last_mouse_pos_);
1785
1834
mz = point[0] - start.getFeature(*getCurrentLayer().getFeatureMap()).getMZ();
1786
1835
rt = point[1] - start.getFeature(*getCurrentLayer().getFeatureMap()).getRT();
1787
it = std::numeric_limits<DoubleReal>::quiet_NaN();
1790
else if (getCurrentLayer().type==LayerData::DT_PEAK)
1836
it = std::numeric_limits<DoubleReal>::quiet_NaN();
1839
else if (getCurrentLayer().type == LayerData::DT_PEAK)
1794
1843
mz = end.getPeak(*getCurrentLayer().getPeakData()).getMZ() - start.getPeak(*getCurrentLayer().getPeakData()).getMZ();
1795
1844
rt = end.getSpectrum(*getCurrentLayer().getPeakData()).getRT() - start.getSpectrum(*getCurrentLayer().getPeakData()).getRT();
1796
1845
it = end.getPeak(*getCurrentLayer().getPeakData()).getIntensity() / start.getPeak(*getCurrentLayer().getPeakData()).getIntensity();
1800
PointType point = widgetToData_(last_mouse_pos_);
1849
PointType point = widgetToData_(last_mouse_pos_);
1801
1850
mz = point[0] - start.getPeak(*getCurrentLayer().getPeakData()).getMZ();
1802
1851
rt = point[1] - start.getSpectrum(*getCurrentLayer().getPeakData()).getRT();
1803
it = std::numeric_limits<DoubleReal>::quiet_NaN();
1806
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS)
1852
it = std::numeric_limits<DoubleReal>::quiet_NaN();
1855
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS)
1810
1859
mz = end.getFeature(*getCurrentLayer().getConsensusMap()).getMZ() - start.getFeature(*getCurrentLayer().getConsensusMap()).getMZ();
1811
1860
rt = end.getFeature(*getCurrentLayer().getConsensusMap()).getRT() - start.getFeature(*getCurrentLayer().getConsensusMap()).getRT();
1812
1861
it = end.getFeature(*getCurrentLayer().getConsensusMap()).getIntensity() / start.getFeature(*getCurrentLayer().getConsensusMap()).getIntensity();
1816
PointType point = widgetToData_(last_mouse_pos_);
1865
PointType point = widgetToData_(last_mouse_pos_);
1817
1866
mz = point[0] - start.getFeature(*getCurrentLayer().getConsensusMap()).getMZ();
1818
1867
rt = point[1] - start.getFeature(*getCurrentLayer().getConsensusMap()).getRT();
1819
it = std::numeric_limits<DoubleReal>::quiet_NaN();
1822
else if (getCurrentLayer().type==LayerData::DT_CHROMATOGRAM)
1826
else if (getCurrentLayer().type == LayerData::DT_IDENT)
1833
lines.push_back("RT delta: " + QString::number(rt,'f',2));
1834
lines.push_back("m/z delta: " + QString::number(mz,'f',6));
1835
if (boost::math::isinf(it) || boost::math::isnan(it))
1837
lines.push_back("Int ratio: n/a");
1841
lines.push_back("Int ratio: " + QString::number(it,'f',2));
1843
drawText_(painter, lines);
1847
void Spectrum2DCanvas::mousePressEvent(QMouseEvent* e)
1849
last_mouse_pos_ = e->pos();
1851
if (e->button() == Qt::LeftButton)
1853
if (action_mode_ == AM_MEASURE)
1855
if (selected_peak_.isValid())
1857
measurement_start_ = selected_peak_;
1861
measurement_start_.clear();
1864
else if (action_mode_ == AM_ZOOM)
1866
//translate (if not moving features)
1867
if (!getCurrentLayer().type==LayerData::DT_FEATURE || !selected_peak_.isValid())
1869
rubber_band_.setGeometry(QRect(e->pos(),QSize()));
1870
rubber_band_.show();
1876
void Spectrum2DCanvas::mouseMoveEvent(QMouseEvent* e)
1878
grabKeyboard(); // (re-)grab keyboard after it has been released by unhandled key
1879
QPoint pos = e->pos();
1880
PointType data_pos = widgetToData_(pos);
1881
emit sendCursorStatus( data_pos[0], data_pos[1]);
1883
PeakIndex near_peak = findNearestPeak_(pos);
1885
//highlight current peak and display peak coordinates
1868
it = std::numeric_limits<DoubleReal>::quiet_NaN();
1871
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM)
1875
else if (getCurrentLayer().type == LayerData::DT_IDENT)
1882
lines.push_back("RT delta: " + QString::number(rt, 'f', 2));
1883
lines.push_back("m/z delta: " + QString::number(mz, 'f', 6));
1884
if (boost::math::isinf(it) || boost::math::isnan(it))
1886
lines.push_back("Int ratio: n/a");
1890
lines.push_back("Int ratio: " + QString::number(it, 'f', 2));
1892
drawText_(painter, lines);
1895
void Spectrum2DCanvas::mousePressEvent(QMouseEvent * e)
1897
last_mouse_pos_ = e->pos();
1899
if (e->button() == Qt::LeftButton)
1901
if (action_mode_ == AM_MEASURE)
1903
if (selected_peak_.isValid())
1905
measurement_start_ = selected_peak_;
1909
measurement_start_.clear();
1912
else if (action_mode_ == AM_ZOOM)
1914
//translate (if not moving features)
1915
if (!getCurrentLayer().type == LayerData::DT_FEATURE || !selected_peak_.isValid())
1917
rubber_band_.setGeometry(QRect(e->pos(), QSize()));
1918
rubber_band_.show();
1924
void Spectrum2DCanvas::mouseMoveEvent(QMouseEvent * e)
1926
grabKeyboard(); // (re-)grab keyboard after it has been released by unhandled key
1927
QPoint pos = e->pos();
1928
PointType data_pos = widgetToData_(pos);
1929
emit sendCursorStatus(data_pos[0], data_pos[1]);
1931
PeakIndex near_peak = findNearestPeak_(pos);
1933
//highlight current peak and display peak coordinates
1886
1934
if (action_mode_ == AM_MEASURE || (action_mode_ == AM_TRANSLATE && !(e->buttons() & Qt::LeftButton)))
1889
selected_peak_ = near_peak;
1890
update_(__PRETTY_FUNCTION__);
1892
//show meta data in status bar (if available)
1893
if (selected_peak_.isValid())
1896
if (getCurrentLayer().type==LayerData::DT_FEATURE)
1899
const FeatureMapType::FeatureType& f = selected_peak_.getFeature(*getCurrentLayer().getFeatureMap());
1900
std::vector<String> keys;
1902
for (Size m=0; m<keys.size(); ++m)
1904
status = status + " " + keys[m] + ": " + (String)(f.getMetaValue(keys[m]));
1907
else if (getCurrentLayer().type==LayerData::DT_PEAK)
1910
const ExperimentType::SpectrumType& s = selected_peak_.getSpectrum(*getCurrentLayer().getPeakData());
1911
for (Size m=0; m<s.getFloatDataArrays().size();++m)
1913
if (selected_peak_.peak < s.getFloatDataArrays()[m].size())
1915
status += s.getFloatDataArrays()[m].getName() + ": " + s.getFloatDataArrays()[m][selected_peak_.peak] + " ";
1918
for (Size m=0; m<s.getIntegerDataArrays().size();++m)
1920
if (selected_peak_.peak < s.getIntegerDataArrays()[m].size())
1922
status += s.getIntegerDataArrays()[m].getName() + ": " + s.getIntegerDataArrays()[m][selected_peak_.peak] + " ";
1925
for (Size m=0; m<s.getStringDataArrays().size();++m)
1927
if (selected_peak_.peak < s.getStringDataArrays()[m].size())
1929
status += s.getStringDataArrays()[m].getName() + ": " + s.getStringDataArrays()[m][selected_peak_.peak] + " ";
1933
else if (getCurrentLayer().type==LayerData::DT_CONSENSUS)// ConsensusFeature
1936
const ConsensusFeature& f = selected_peak_.getFeature(*getCurrentLayer().getConsensusMap());
1937
std::vector<String> keys;
1939
for (Size m=0; m<keys.size(); ++m)
1941
status = status + " " + keys[m] + ": " + (String)(f.getMetaValue(keys[m]));
1944
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM)// chromatogram
1948
if (status!="") emit sendStatusMessage(status, 0);
1951
else if (action_mode_ == AM_ZOOM)
1953
//Zoom mode => no peak should be selected
1954
selected_peak_.clear();
1955
update_(__PRETTY_FUNCTION__);
1958
if (action_mode_==AM_MEASURE)
1960
last_mouse_pos_ = pos;
1962
else if (action_mode_ == AM_ZOOM)
1964
//if mouse button is held down, enlarge the selection
1965
if (e->buttons() & Qt::LeftButton)
1967
rubber_band_.setGeometry(QRect(last_mouse_pos_,pos).normalized());
1968
rubber_band_.show(); //if the mouse button is pressed before the zoom key is pressed
1970
update_(__PRETTY_FUNCTION__);
1973
else if (action_mode_ == AM_TRANSLATE)
1975
if (e->buttons() & Qt::LeftButton)
1977
if (getCurrentLayer().modifiable && getCurrentLayer().type==LayerData::DT_FEATURE && selected_peak_.isValid()) //move feature
1979
PointType new_data = widgetToData_(pos);
1980
DoubleReal mz = new_data[0];
1981
DoubleReal rt = new_data[1];
1983
//restrict the movement to the data range
1984
mz = max(mz,overall_data_range_.minPosition()[0]);
1985
mz = min(mz,overall_data_range_.maxPosition()[0]);
1986
rt = max(rt,overall_data_range_.minPosition()[1]);
1987
rt = min(rt,overall_data_range_.maxPosition()[1]);
1937
selected_peak_ = near_peak;
1938
update_(__PRETTY_FUNCTION__);
1940
//show meta data in status bar (if available)
1941
if (selected_peak_.isValid())
1944
if (getCurrentLayer().type == LayerData::DT_FEATURE)
1947
const FeatureMapType::FeatureType & f = selected_peak_.getFeature(*getCurrentLayer().getFeatureMap());
1948
std::vector<String> keys;
1950
for (Size m = 0; m < keys.size(); ++m)
1952
status = status + " " + keys[m] + ": " + (String)(f.getMetaValue(keys[m]));
1955
else if (getCurrentLayer().type == LayerData::DT_PEAK)
1958
const ExperimentType::SpectrumType & s = selected_peak_.getSpectrum(*getCurrentLayer().getPeakData());
1959
for (Size m = 0; m < s.getFloatDataArrays().size(); ++m)
1961
if (selected_peak_.peak < s.getFloatDataArrays()[m].size())
1963
status += s.getFloatDataArrays()[m].getName() + ": " + s.getFloatDataArrays()[m][selected_peak_.peak] + " ";
1966
for (Size m = 0; m < s.getIntegerDataArrays().size(); ++m)
1968
if (selected_peak_.peak < s.getIntegerDataArrays()[m].size())
1970
status += s.getIntegerDataArrays()[m].getName() + ": " + s.getIntegerDataArrays()[m][selected_peak_.peak] + " ";
1973
for (Size m = 0; m < s.getStringDataArrays().size(); ++m)
1975
if (selected_peak_.peak < s.getStringDataArrays()[m].size())
1977
status += s.getStringDataArrays()[m].getName() + ": " + s.getStringDataArrays()[m][selected_peak_.peak] + " ";
1981
else if (getCurrentLayer().type == LayerData::DT_CONSENSUS) // ConsensusFeature
1984
const ConsensusFeature & f = selected_peak_.getFeature(*getCurrentLayer().getConsensusMap());
1985
std::vector<String> keys;
1987
for (Size m = 0; m < keys.size(); ++m)
1989
status = status + " " + keys[m] + ": " + (String)(f.getMetaValue(keys[m]));
1992
else if (getCurrentLayer().type == LayerData::DT_CHROMATOGRAM) // chromatogram
1997
emit sendStatusMessage(status, 0);
2000
else if (action_mode_ == AM_ZOOM)
2002
//Zoom mode => no peak should be selected
2003
selected_peak_.clear();
2004
update_(__PRETTY_FUNCTION__);
2007
if (action_mode_ == AM_MEASURE)
2009
last_mouse_pos_ = pos;
2011
else if (action_mode_ == AM_ZOOM)
2013
//if mouse button is held down, enlarge the selection
2014
if (e->buttons() & Qt::LeftButton)
2016
rubber_band_.setGeometry(QRect(last_mouse_pos_, pos).normalized());
2017
rubber_band_.show(); //if the mouse button is pressed before the zoom key is pressed
2019
update_(__PRETTY_FUNCTION__);
2022
else if (action_mode_ == AM_TRANSLATE)
2024
if (e->buttons() & Qt::LeftButton)
2026
if (getCurrentLayer().modifiable && getCurrentLayer().type == LayerData::DT_FEATURE && selected_peak_.isValid()) //move feature
2028
PointType new_data = widgetToData_(pos);
2029
DoubleReal mz = new_data[0];
2030
DoubleReal rt = new_data[1];
2032
//restrict the movement to the data range
2033
mz = max(mz, overall_data_range_.minPosition()[0]);
2034
mz = min(mz, overall_data_range_.maxPosition()[0]);
2035
rt = max(rt, overall_data_range_.minPosition()[1]);
2036
rt = min(rt, overall_data_range_.maxPosition()[1]);
1989
2038
(*getCurrentLayer_().getFeatureMap())[selected_peak_.peak].setRT(rt);
1990
2039
(*getCurrentLayer_().getFeatureMap())[selected_peak_.peak].setMZ(mz);
1992
update_buffer_ = true;
1993
update_(__PRETTY_FUNCTION__);
2041
update_buffer_ = true;
2042
update_(__PRETTY_FUNCTION__);
1994
2043
modificationStatus_(activeLayerIndex(), true);
1998
//calculate data coordinates of shift
1999
PointType old_data = widgetToData_(last_mouse_pos_);
2000
PointType new_data = widgetToData_(pos);
2002
DoubleReal shift = old_data.getX() - new_data.getX();
2003
DoubleReal newLoX = visible_area_.minX() + shift;
2004
DoubleReal newHiX = visible_area_.maxX() + shift;
2005
// check if we are falling out of bounds
2006
if (newLoX < overall_data_range_.minX())
2008
newLoX = overall_data_range_.minX();
2009
newHiX = newLoX + visible_area_.width();
2011
if (newHiX > overall_data_range_.maxX())
2013
newHiX = overall_data_range_.maxX();
2014
newLoX = newHiX - visible_area_.width();
2017
shift = old_data.getY() - new_data.getY();
2018
DoubleReal newLoY = visible_area_.minY() + shift;
2019
DoubleReal newHiY = visible_area_.maxY() + shift;
2020
// check if we are falling out of bounds
2021
if (newLoY < overall_data_range_.minY())
2023
newLoY = overall_data_range_.minY();
2024
newHiY = newLoY + visible_area_.height();
2026
if (newHiY > overall_data_range_.maxY())
2028
newHiY = overall_data_range_.maxY();
2029
newLoY = newHiY - visible_area_.height();
2033
//cout << "New area: x " << newLoX <<"-"<< newHiX << " - y "<<newLoY <<"-"<< newHiY << endl;
2034
//cout << __PRETTY_FUNCTION__ << endl;
2035
changeVisibleArea_(AreaType(newLoX,newLoY,newHiX,newHiY));
2036
last_mouse_pos_ = pos;
2042
void Spectrum2DCanvas::mouseReleaseEvent(QMouseEvent* e)
2044
if (e->button() == Qt::LeftButton)
2046
if (action_mode_==AM_MEASURE)
2048
if (!selected_peak_.isValid())
2050
measurement_start_.clear();
2052
measurement_start_.clear();
2053
update_(__PRETTY_FUNCTION__);
2055
else if (action_mode_ == AM_ZOOM)
2057
rubber_band_.hide();
2058
QRect rect = rubber_band_.geometry();
2059
if (rect.width()!=0 && rect.height()!=0)
2061
AreaType area(widgetToData_(rect.topLeft()), widgetToData_(rect.bottomRight()));
2062
//cout << __PRETTY_FUNCTION__ << endl;
2063
changeVisibleArea_(area, true, true);
2069
void Spectrum2DCanvas::contextMenuEvent(QContextMenuEvent* e)
2047
//calculate data coordinates of shift
2048
PointType old_data = widgetToData_(last_mouse_pos_);
2049
PointType new_data = widgetToData_(pos);
2051
DoubleReal shift = old_data.getX() - new_data.getX();
2052
DoubleReal newLoX = visible_area_.minX() + shift;
2053
DoubleReal newHiX = visible_area_.maxX() + shift;
2054
// check if we are falling out of bounds
2055
if (newLoX < overall_data_range_.minX())
2057
newLoX = overall_data_range_.minX();
2058
newHiX = newLoX + visible_area_.width();
2060
if (newHiX > overall_data_range_.maxX())
2062
newHiX = overall_data_range_.maxX();
2063
newLoX = newHiX - visible_area_.width();
2066
shift = old_data.getY() - new_data.getY();
2067
DoubleReal newLoY = visible_area_.minY() + shift;
2068
DoubleReal newHiY = visible_area_.maxY() + shift;
2069
// check if we are falling out of bounds
2070
if (newLoY < overall_data_range_.minY())
2072
newLoY = overall_data_range_.minY();
2073
newHiY = newLoY + visible_area_.height();
2075
if (newHiY > overall_data_range_.maxY())
2077
newHiY = overall_data_range_.maxY();
2078
newLoY = newHiY - visible_area_.height();
2082
//cout << "New area: x " << newLoX <<"-"<< newHiX << " - y "<<newLoY <<"-"<< newHiY << endl;
2083
//cout << __PRETTY_FUNCTION__ << endl;
2084
changeVisibleArea_(AreaType(newLoX, newLoY, newHiX, newHiY));
2085
emit layerZoomChanged(this);
2086
last_mouse_pos_ = pos;
2092
void Spectrum2DCanvas::mouseReleaseEvent(QMouseEvent * e)
2094
if (e->button() == Qt::LeftButton)
2096
if (action_mode_ == AM_MEASURE)
2098
if (!selected_peak_.isValid())
2100
measurement_start_.clear();
2102
measurement_start_.clear();
2103
update_(__PRETTY_FUNCTION__);
2105
else if (action_mode_ == AM_ZOOM)
2107
rubber_band_.hide();
2108
QRect rect = rubber_band_.geometry();
2109
if (rect.width() != 0 && rect.height() != 0)
2111
AreaType area(widgetToData_(rect.topLeft()), widgetToData_(rect.bottomRight()));
2112
//cout << __PRETTY_FUNCTION__ << endl;
2113
changeVisibleArea_(area, true, true);
2114
emit layerZoomChanged(this);
2120
void Spectrum2DCanvas::contextMenuEvent(QContextMenuEvent * e)
2071
2122
//Abort if there are no layers
2072
2123
if (layers_.empty())
2077
2128
DoubleReal mz = widgetToData_(e->pos())[0];
2078
DoubleReal rt = widgetToData_(e->pos())[1];
2080
const LayerData& layer = getCurrentLayer();
2082
QMenu* context_menu = new QMenu(this);
2085
QAction* result = 0;
2087
//Display name and warn if current layer invisible
2088
String layer_name = String("Layer: ") + layer.name;
2091
layer_name += " (invisible)";
2093
context_menu->addAction(layer_name.toQString())->setEnabled(false);
2094
context_menu->addSeparator();
2096
context_menu->addAction("Layer meta data");
2098
QMenu* settings_menu = new QMenu("Settings");
2099
settings_menu->addAction("Show/hide grid lines");
2100
settings_menu->addAction("Show/hide axis legends");
2129
DoubleReal rt = widgetToData_(e->pos())[1];
2131
const LayerData & layer = getCurrentLayer();
2133
QMenu * context_menu = new QMenu(this);
2136
QAction * result = 0;
2138
//Display name and warn if current layer invisible
2139
String layer_name = String("Layer: ") + layer.name;
2142
layer_name += " (invisible)";
2144
context_menu->addAction(layer_name.toQString())->setEnabled(false);
2145
context_menu->addSeparator();
2147
context_menu->addAction("Layer meta data");
2149
QMenu * settings_menu = new QMenu("Settings");
2150
settings_menu->addAction("Show/hide grid lines");
2151
settings_menu->addAction("Show/hide axis legends");
2101
2152
context_menu->addSeparator();
2103
2154
context_menu->addAction("Switch to 3D view");
2105
//-------------------PEAKS----------------------------------
2106
if (layer.type==LayerData::DT_PEAK)
2109
settings_menu->addSeparator();
2110
settings_menu->addAction("Show/hide projections");
2111
settings_menu->addAction("Show/hide MS/MS precursors");
2156
//-------------------PEAKS----------------------------------
2157
if (layer.type == LayerData::DT_PEAK)
2160
settings_menu->addSeparator();
2161
settings_menu->addAction("Show/hide projections");
2162
settings_menu->addAction("Show/hide MS/MS precursors");
2113
//add surrounding survey scans
2114
//find nearest survey scan
2164
//add surrounding survey scans
2165
//find nearest survey scan
2115
2166
SignedSize size = getCurrentLayer().getPeakData()->size();
2116
Int current = getCurrentLayer().getPeakData()->RTBegin(rt)-getCurrentLayer().getPeakData()->begin();
2167
Int current = getCurrentLayer().getPeakData()->RTBegin(rt) - getCurrentLayer().getPeakData()->begin();
2117
2168
if (current == size) // if only one element is present RTBegin points to one after the last element (see RTBegin implementation)
2123
while (current+i<size || current-i>=0)
2125
if(current+i<size && (*getCurrentLayer().getPeakData())[current+i].getMSLevel()==1)
2127
current = current+i;
2130
if(current-i>=0 && (*getCurrentLayer().getPeakData())[current-i].getMSLevel()==1)
2132
current = current-i;
2137
//search for four scans in both directions
2138
vector<Int> indices;
2139
indices.push_back(current);
2141
while (current-i>=0 && indices.size()<5)
2143
if ((*getCurrentLayer().getPeakData())[current-i].getMSLevel()==1)
2145
indices.push_back(current-i);
2150
while (current+i<size && indices.size()<9)
2152
if ((*getCurrentLayer().getPeakData())[current+i].getMSLevel()==1)
2154
indices.push_back(current+i);
2158
sort(indices.rbegin(),indices.rend());
2159
QMenu* ms1_scans = context_menu->addMenu("Survey scan in 1D");
2160
QMenu* ms1_meta = context_menu->addMenu("Survey scan meta data");
2161
context_menu->addSeparator();
2162
for(i=0; i<(Int)indices.size(); ++i)
2164
if (indices[i]==current)
2174
while (current + i < size || current - i >= 0)
2176
if (current + i < size && (*getCurrentLayer().getPeakData())[current + i].getMSLevel() == 1)
2178
current = current + i;
2181
if (current - i >= 0 && (*getCurrentLayer().getPeakData())[current - i].getMSLevel() == 1)
2183
current = current - i;
2188
//search for four scans in both directions
2189
vector<Int> indices;
2190
indices.push_back(current);
2192
while (current - i >= 0 && indices.size() < 5)
2194
if ((*getCurrentLayer().getPeakData())[current - i].getMSLevel() == 1)
2196
indices.push_back(current - i);
2201
while (current + i < size && indices.size() < 9)
2203
if ((*getCurrentLayer().getPeakData())[current + i].getMSLevel() == 1)
2205
indices.push_back(current + i);
2209
sort(indices.rbegin(), indices.rend());
2210
QMenu * ms1_scans = context_menu->addMenu("Survey scan in 1D");
2211
QMenu * ms1_meta = context_menu->addMenu("Survey scan meta data");
2212
context_menu->addSeparator();
2213
for (i = 0; i < (Int)indices.size(); ++i)
2215
if (indices[i] == current)
2166
2217
ms1_scans->addSeparator();
2168
2219
a = ms1_scans->addAction(QString("RT: ") + QString::number((*getCurrentLayer().getPeakData())[indices[i]].getRT()));
2169
a->setData(indices[i]);
2170
if (indices[i]==current)
2220
a->setData(indices[i]);
2221
if (indices[i] == current)
2172
2223
ms1_scans->addSeparator();
2175
if (indices[i]==current)
2226
if (indices[i] == current)
2177
2228
ms1_meta->addSeparator();
2179
2230
a = ms1_meta->addAction(QString("RT: ") + QString::number((*getCurrentLayer().getPeakData())[indices[i]].getRT()));
2180
a->setData(indices[i]);
2181
if (indices[i]==current)
2231
a->setData(indices[i]);
2232
if (indices[i] == current)
2183
2234
ms1_meta->addSeparator();
2187
//add surrounding fragment scans
2188
QMenu* msn_scans = new QMenu("fragment scan in 1D");
2189
QMenu* msn_meta = new QMenu("fragment scan meta data");
2190
DPosition<2> p1 = widgetToData_(e->pos()+ QPoint(10,10));
2191
DPosition<2> p2 = widgetToData_(e->pos()- QPoint(10,10));
2192
DoubleReal rt_min = min(p1[1],p2[1]);
2193
DoubleReal rt_max = max(p1[1],p2[1]);
2194
DoubleReal mz_min = min(p1[0],p2[0]);
2195
DoubleReal mz_max = max(p1[0],p2[0]);
2196
bool item_added = false;
2197
for (ExperimentType::ConstIterator it=getCurrentLayer().getPeakData()->RTBegin(rt_min); it!=getCurrentLayer().getPeakData()->RTEnd(rt_max); ++it)
2199
DoubleReal mz = 0.0;
2200
if (!it->getPrecursors().empty())
2238
//add surrounding fragment scans
2239
QMenu * msn_scans = new QMenu("fragment scan in 1D");
2240
QMenu * msn_meta = new QMenu("fragment scan meta data");
2241
DPosition<2> p1 = widgetToData_(e->pos() + QPoint(10, 10));
2242
DPosition<2> p2 = widgetToData_(e->pos() - QPoint(10, 10));
2243
DoubleReal rt_min = min(p1[1], p2[1]);
2244
DoubleReal rt_max = max(p1[1], p2[1]);
2245
DoubleReal mz_min = min(p1[0], p2[0]);
2246
DoubleReal mz_max = max(p1[0], p2[0]);
2247
bool item_added = false;
2248
for (ExperimentType::ConstIterator it = getCurrentLayer().getPeakData()->RTBegin(rt_min); it != getCurrentLayer().getPeakData()->RTEnd(rt_max); ++it)
2250
DoubleReal mz = 0.0;
2251
if (!it->getPrecursors().empty())
2202
2253
mz = it->getPrecursors()[0].getMZ();
2205
if (it->getMSLevel()>1 && mz >= mz_min && mz <= mz_max)
2207
a = msn_scans->addAction(QString("RT: ") + QString::number(it->getRT()) + " mz: " + QString::number(mz));
2208
a->setData((int)(it-getCurrentLayer().getPeakData()->begin()));
2209
a = msn_meta->addAction(QString("RT: ") + QString::number(it->getRT()) + " mz: " + QString::number(mz));
2210
a->setData((int)(it-getCurrentLayer().getPeakData()->begin()));
2216
context_menu->addMenu(msn_scans);
2217
context_menu->addMenu(msn_meta);
2218
context_menu->addSeparator();
2221
finishContextMenu_(context_menu, settings_menu);
2224
if ((result = context_menu->exec(mapToGlobal(e->pos()))))
2226
if (result->parent()==ms1_scans || result->parent()==msn_scans)
2228
emit showSpectrumAs1D(result->data().toInt());
2230
else if (result->parent()==ms1_meta || result->parent()==msn_meta)
2232
showMetaData(true, result->data().toInt());
2236
//-------------------FEATURES----------------------------------
2237
else if (layer.type==LayerData::DT_FEATURE)
2240
settings_menu->addSeparator();
2241
settings_menu->addAction("Show/hide convex hull");
2242
settings_menu->addAction("Show/hide trace convex hulls");
2243
settings_menu->addAction("Show/hide numbers/labels");
2244
settings_menu->addAction("Show/hide unassigned peptide hits");
2246
//search for nearby features
2247
DPosition<2> p1 = widgetToData_(e->pos()+ QPoint(10,10));
2248
DPosition<2> p2 = widgetToData_(e->pos()- QPoint(10,10));
2249
DoubleReal rt_min = min(p1[1],p2[1]);
2250
DoubleReal rt_max = max(p1[1],p2[1]);
2251
DoubleReal mz_min = min(p1[0],p2[0]);
2252
DoubleReal mz_max = max(p1[0],p2[0]);
2254
QMenu* meta = new QMenu("Feature meta data");
2255
bool present = false;
2256
FeatureMapType& features = *getCurrentLayer_().getFeatureMap();
2257
//featre meta data menu
2258
for (FeatureMapType::Iterator it = features.begin(); it!=features.end(); ++it)
2260
if (it->getMZ() <= mz_max && it->getMZ() >= mz_min && it->getRT() <= rt_max && it->getRT() >= rt_min)
2263
a = meta->addAction(QString("RT: ") + QString::number(it->getRT()) + " m/z:" + QString::number(it->getMZ()) + " charge:" + QString::number(it->getCharge()));
2264
a->setData((int)(it-features.begin()));
2269
context_menu->addMenu(meta);
2270
context_menu->addSeparator();
2273
//add modifiable flag
2274
settings_menu->addSeparator();
2275
settings_menu->addAction("Toggle edit/view mode");
2277
finishContextMenu_(context_menu, settings_menu);
2280
if ((result = context_menu->exec(mapToGlobal(e->pos()))))
2282
if (result->text().left(3)=="RT:")
2284
showMetaData(true,result->data().toInt());
2288
//-------------------CONSENSUS FEATURES----------------------------------
2289
else if (layer.type==LayerData::DT_CONSENSUS)
2292
settings_menu->addSeparator();
2293
settings_menu->addAction("Show/hide elements");
2295
//search for nearby features
2296
DPosition<2> p1 = widgetToData_(e->pos()+ QPoint(10,10));
2297
DPosition<2> p2 = widgetToData_(e->pos()- QPoint(10,10));
2298
DoubleReal rt_min = min(p1[1],p2[1]);
2299
DoubleReal rt_max = max(p1[1],p2[1]);
2300
DoubleReal mz_min = min(p1[0],p2[0]);
2301
DoubleReal mz_max = max(p1[0],p2[0]);
2303
QMenu* consens_meta = new QMenu("Consensus meta data");
2304
bool present = false;
2305
ConsensusMapType& features = *getCurrentLayer_().getConsensusMap();
2306
//consensus feature meta data menu
2307
for (ConsensusMapType::Iterator it = features.begin(); it!=features.end(); ++it)
2309
if (it->getMZ() <= mz_max && it->getMZ() >= mz_min && it->getRT() <= rt_max && it->getRT() >= rt_min)
2313
a = consens_meta->addAction(QString("RT: ") + QString::number(it->getRT()) + " m/z:" + QString::number(it->getMZ()) + " charge:" + QString::number(it->getCharge()));
2314
a->setData((int)(it-features.begin()));
2319
context_menu->addMenu(consens_meta);
2320
context_menu->addSeparator();
2323
finishContextMenu_(context_menu, settings_menu);
2325
if ((result = context_menu->exec(mapToGlobal(e->pos()))))
2327
if (result->text().left(3)=="RT:")
2329
showMetaData(true, result->data().toInt());
2333
//------------------CHROMATOGRAMS----------------------------------
2256
if (it->getMSLevel() > 1 && mz >= mz_min && mz <= mz_max)
2258
a = msn_scans->addAction(QString("RT: ") + QString::number(it->getRT()) + " mz: " + QString::number(mz));
2259
a->setData((int)(it - getCurrentLayer().getPeakData()->begin()));
2260
a = msn_meta->addAction(QString("RT: ") + QString::number(it->getRT()) + " mz: " + QString::number(mz));
2261
a->setData((int)(it - getCurrentLayer().getPeakData()->begin()));
2267
context_menu->addMenu(msn_scans);
2268
context_menu->addMenu(msn_meta);
2269
context_menu->addSeparator();
2272
finishContextMenu_(context_menu, settings_menu);
2275
if ((result = context_menu->exec(mapToGlobal(e->pos()))))
2277
if (result->parent() == ms1_scans || result->parent() == msn_scans)
2279
emit showSpectrumAs1D(result->data().toInt());
2281
else if (result->parent() == ms1_meta || result->parent() == msn_meta)
2283
showMetaData(true, result->data().toInt());
2287
//-------------------FEATURES----------------------------------
2288
else if (layer.type == LayerData::DT_FEATURE)
2291
settings_menu->addSeparator();
2292
settings_menu->addAction("Show/hide convex hull");
2293
settings_menu->addAction("Show/hide trace convex hulls");
2294
settings_menu->addAction("Show/hide numbers/labels");
2295
settings_menu->addAction("Show/hide unassigned peptide hits");
2297
//search for nearby features
2298
DPosition<2> p1 = widgetToData_(e->pos() + QPoint(10, 10));
2299
DPosition<2> p2 = widgetToData_(e->pos() - QPoint(10, 10));
2300
DoubleReal rt_min = min(p1[1], p2[1]);
2301
DoubleReal rt_max = max(p1[1], p2[1]);
2302
DoubleReal mz_min = min(p1[0], p2[0]);
2303
DoubleReal mz_max = max(p1[0], p2[0]);
2305
QMenu * meta = new QMenu("Feature meta data");
2306
bool present = false;
2307
FeatureMapType & features = *getCurrentLayer_().getFeatureMap();
2308
//featre meta data menu
2309
for (FeatureMapType::Iterator it = features.begin(); it != features.end(); ++it)
2311
if (it->getMZ() <= mz_max && it->getMZ() >= mz_min && it->getRT() <= rt_max && it->getRT() >= rt_min)
2314
a = meta->addAction(QString("RT: ") + QString::number(it->getRT()) + " m/z:" + QString::number(it->getMZ()) + " charge:" + QString::number(it->getCharge()));
2315
a->setData((int)(it - features.begin()));
2320
context_menu->addMenu(meta);
2321
context_menu->addSeparator();
2324
//add modifiable flag
2325
settings_menu->addSeparator();
2326
settings_menu->addAction("Toggle edit/view mode");
2328
finishContextMenu_(context_menu, settings_menu);
2331
if ((result = context_menu->exec(mapToGlobal(e->pos()))))
2333
if (result->text().left(3) == "RT:")
2335
showMetaData(true, result->data().toInt());
2339
//-------------------CONSENSUS FEATURES----------------------------------
2340
else if (layer.type == LayerData::DT_CONSENSUS)
2343
settings_menu->addSeparator();
2344
settings_menu->addAction("Show/hide elements");
2346
//search for nearby features
2347
DPosition<2> p1 = widgetToData_(e->pos() + QPoint(10, 10));
2348
DPosition<2> p2 = widgetToData_(e->pos() - QPoint(10, 10));
2349
DoubleReal rt_min = min(p1[1], p2[1]);
2350
DoubleReal rt_max = max(p1[1], p2[1]);
2351
DoubleReal mz_min = min(p1[0], p2[0]);
2352
DoubleReal mz_max = max(p1[0], p2[0]);
2354
QMenu * consens_meta = new QMenu("Consensus meta data");
2355
bool present = false;
2356
ConsensusMapType & features = *getCurrentLayer_().getConsensusMap();
2357
//consensus feature meta data menu
2358
for (ConsensusMapType::Iterator it = features.begin(); it != features.end(); ++it)
2360
if (it->getMZ() <= mz_max && it->getMZ() >= mz_min && it->getRT() <= rt_max && it->getRT() >= rt_min)
2364
a = consens_meta->addAction(QString("RT: ") + QString::number(it->getRT()) + " m/z:" + QString::number(it->getMZ()) + " charge:" + QString::number(it->getCharge()));
2365
a->setData((int)(it - features.begin()));
2370
context_menu->addMenu(consens_meta);
2371
context_menu->addSeparator();
2374
finishContextMenu_(context_menu, settings_menu);
2376
if ((result = context_menu->exec(mapToGlobal(e->pos()))))
2378
if (result->text().left(3) == "RT:")
2380
showMetaData(true, result->data().toInt());
2384
//------------------CHROMATOGRAMS----------------------------------
2334
2385
else if (layer.type == LayerData::DT_CHROMATOGRAM)
2336
2387
settings_menu->addSeparator();
2337
2388
settings_menu->addAction("Show/hide projections");
2338
2389
settings_menu->addAction("Show/hide MS/MS precursors");
2436
2498
showMetaData(true, result->data().toInt());
2441
//common actions of peaks and features
2444
if (result->text() == "Preferences")
2446
showCurrentLayerPreferences();
2448
else if (result->text() == "Show/hide grid lines")
2450
showGridLines(!gridLinesShown());
2452
else if (result->text() == "Show/hide axis legends")
2454
emit changeLegendVisibility();
2456
else if (result->text()=="Layer" || result->text()=="Visible layer data")
2458
saveCurrentLayer(result->text()=="Visible layer data");
2460
else if (result->text()=="As image")
2462
spectrum_widget_->saveAsImage();
2464
else if (result->text()=="Show/hide projections")
2466
emit toggleProjections();
2468
else if (result->text()=="Show/hide MS/MS precursors")
2470
setLayerFlag(LayerData::P_PRECURSORS,!getLayerFlag(LayerData::P_PRECURSORS));
2472
else if (result->text()=="Show/hide convex hull")
2474
setLayerFlag(LayerData::F_HULL,!getLayerFlag(LayerData::F_HULL));
2476
else if (result->text()=="Show/hide trace convex hulls")
2478
setLayerFlag(LayerData::F_HULLS,!getLayerFlag(LayerData::F_HULLS));
2480
else if (result->text()=="Show/hide unassigned peptide hits")
2482
setLayerFlag(LayerData::F_UNASSIGNED,!getLayerFlag(LayerData::F_UNASSIGNED));
2484
else if (result->text()=="Show/hide numbers/labels")
2486
if (layer.label==LayerData::L_NONE)
2488
getCurrentLayer_().label=LayerData::L_META_LABEL;
2492
getCurrentLayer_().label=LayerData::L_NONE;
2495
else if (result->text()=="Toggle edit/view mode")
2503
//common actions of peaks and features
2506
if (result->text() == "Preferences")
2508
showCurrentLayerPreferences();
2510
else if (result->text() == "Show/hide grid lines")
2512
showGridLines(!gridLinesShown());
2514
else if (result->text() == "Show/hide axis legends")
2516
emit changeLegendVisibility();
2518
else if (result->text() == "Layer" || result->text() == "Visible layer data")
2520
saveCurrentLayer(result->text() == "Visible layer data");
2522
else if (result->text() == "As image")
2524
spectrum_widget_->saveAsImage();
2526
else if (result->text() == "Show/hide projections")
2528
emit toggleProjections();
2530
else if (result->text() == "Show/hide MS/MS precursors")
2532
setLayerFlag(LayerData::P_PRECURSORS, !getLayerFlag(LayerData::P_PRECURSORS));
2534
else if (result->text() == "Show/hide convex hull")
2536
setLayerFlag(LayerData::F_HULL, !getLayerFlag(LayerData::F_HULL));
2538
else if (result->text() == "Show/hide trace convex hulls")
2540
setLayerFlag(LayerData::F_HULLS, !getLayerFlag(LayerData::F_HULLS));
2542
else if (result->text() == "Show/hide unassigned peptide hits")
2544
setLayerFlag(LayerData::F_UNASSIGNED, !getLayerFlag(LayerData::F_UNASSIGNED));
2546
else if (result->text() == "Show/hide numbers/labels")
2548
if (layer.label == LayerData::L_NONE)
2550
getCurrentLayer_().label = LayerData::L_META_LABEL;
2554
getCurrentLayer_().label = LayerData::L_NONE;
2557
else if (result->text() == "Toggle edit/view mode")
2497
2559
getCurrentLayer_().modifiable = !getCurrentLayer_().modifiable;
2499
else if (result->text()=="Show/hide elements")
2501
setLayerFlag(LayerData::C_ELEMENTS,!getLayerFlag(LayerData::C_ELEMENTS));
2503
else if (result->text()=="Layer meta data")
2507
else if (result->text()=="Switch to 3D view")
2561
else if (result->text() == "Show/hide elements")
2563
setLayerFlag(LayerData::C_ELEMENTS, !getLayerFlag(LayerData::C_ELEMENTS));
2565
else if (result->text() == "Layer meta data")
2569
else if (result->text() == "Switch to 3D view")
2509
2571
emit showCurrentPeaksAs3D();
2516
void Spectrum2DCanvas::finishContextMenu_(QMenu* context_menu, QMenu* settings_menu)
2518
//finish settings menu
2519
settings_menu->addSeparator();
2520
settings_menu->addAction("Preferences");
2523
QMenu* save_menu = new QMenu("Save");
2524
save_menu->addAction("Layer");
2525
save_menu->addAction("Visible layer data");
2526
save_menu->addAction("As image");
2529
context_menu->addMenu(save_menu);
2530
context_menu->addMenu(settings_menu);
2532
//add external context menu
2535
context_menu->addSeparator();
2536
context_menu->addMenu(context_add_);
2541
void Spectrum2DCanvas::showCurrentLayerPreferences()
2543
Internal::Spectrum2DPrefDialog dlg(this);
2544
LayerData& layer = getCurrentLayer_();
2546
ColorSelector* bg_color = dlg.findChild<ColorSelector*>("bg_color");
2547
QComboBox* mapping = dlg.findChild<QComboBox*>("mapping");
2548
MultiGradientSelector* gradient = dlg.findChild<MultiGradientSelector*>("gradient");
2549
QComboBox* feature_icon = dlg.findChild<QComboBox*>("feature_icon");
2550
QSpinBox* feature_icon_size = dlg.findChild<QSpinBox*>("feature_icon_size");
2552
bg_color->setColor(QColor(param_.getValue("background_color").toQString()));
2555
mapping->setCurrentIndex(0);
2559
mapping->setCurrentIndex(1);
2561
gradient->gradient().fromString(layer.param.getValue("dot:gradient"));
2562
feature_icon->setCurrentIndex(feature_icon->findText(layer.param.getValue("dot:feature_icon").toQString()));
2563
feature_icon_size->setValue((int)layer.param.getValue("dot:feature_icon_size"));
2567
param_.setValue("background_color",bg_color->getColor().name());
2568
layer.param.setValue("dot:feature_icon", feature_icon->currentText());
2569
layer.param.setValue("dot:feature_icon_size", feature_icon_size->value());
2570
if ((mapping->currentIndex()==0 && !isMzToXAxis()) || (mapping->currentIndex()==1 && isMzToXAxis()))
2572
mzToXAxis(!isMzToXAxis());
2574
layer.param.setValue("dot:gradient",gradient->gradient().toString());
2576
emit preferencesChange();
2578
void Spectrum2DCanvas::finishContextMenu_(QMenu * context_menu, QMenu * settings_menu)
2580
//finish settings menu
2581
settings_menu->addSeparator();
2582
settings_menu->addAction("Preferences");
2585
QMenu * save_menu = new QMenu("Save");
2586
save_menu->addAction("Layer");
2587
save_menu->addAction("Visible layer data");
2588
save_menu->addAction("As image");
2591
context_menu->addMenu(save_menu);
2592
context_menu->addMenu(settings_menu);
2594
//add external context menu
2597
context_menu->addSeparator();
2598
context_menu->addMenu(context_add_);
2602
void Spectrum2DCanvas::showCurrentLayerPreferences()
2604
Internal::Spectrum2DPrefDialog dlg(this);
2605
LayerData & layer = getCurrentLayer_();
2607
ColorSelector * bg_color = dlg.findChild<ColorSelector *>("bg_color");
2608
QComboBox * mapping = dlg.findChild<QComboBox *>("mapping");
2609
MultiGradientSelector * gradient = dlg.findChild<MultiGradientSelector *>("gradient");
2610
QComboBox * feature_icon = dlg.findChild<QComboBox *>("feature_icon");
2611
QSpinBox * feature_icon_size = dlg.findChild<QSpinBox *>("feature_icon_size");
2613
bg_color->setColor(QColor(param_.getValue("background_color").toQString()));
2616
mapping->setCurrentIndex(0);
2620
mapping->setCurrentIndex(1);
2622
gradient->gradient().fromString(layer.param.getValue("dot:gradient"));
2623
feature_icon->setCurrentIndex(feature_icon->findText(layer.param.getValue("dot:feature_icon").toQString()));
2624
feature_icon_size->setValue((int)layer.param.getValue("dot:feature_icon_size"));
2628
param_.setValue("background_color", bg_color->getColor().name());
2629
layer.param.setValue("dot:feature_icon", feature_icon->currentText());
2630
layer.param.setValue("dot:feature_icon_size", feature_icon_size->value());
2631
if ((mapping->currentIndex() == 0 && !isMzToXAxis()) || (mapping->currentIndex() == 1 && isMzToXAxis()))
2633
mzToXAxis(!isMzToXAxis());
2635
layer.param.setValue("dot:gradient", gradient->gradient().toString());
2637
emit preferencesChange();
2580
2641
void Spectrum2DCanvas::currentLayerParametersChanged_()
2582
2643
recalculateDotGradient_(activeLayerIndex());
2584
update_buffer_ = true;
2585
update_(__PRETTY_FUNCTION__);
2645
update_buffer_ = true;
2646
update_(__PRETTY_FUNCTION__);
2588
void Spectrum2DCanvas::saveCurrentLayer(bool visible)
2590
const LayerData& layer = getCurrentLayer();
2649
void Spectrum2DCanvas::saveCurrentLayer(bool visible)
2651
const LayerData & layer = getCurrentLayer();
2592
2653
//determine proposed filename
2593
String proposed_name = param_.getValue("default_path");
2594
if (visible==false && layer.filename!="")
2596
proposed_name = layer.filename;
2599
if (layer.type==LayerData::DT_PEAK) //peak data
2601
QString selected_filter = "";
2602
QString file_name = QFileDialog::getSaveFileName(this, "Save file", proposed_name.toQString(),"mzML files (*.mzML);;mzData files (*.mzData);;mzXML files (*.mzXML);;All files (*)", &selected_filter);
2603
if (!file_name.isEmpty())
2605
// check whether a file type suffix has been given
2606
// first check mzData and mzXML then mzML
2607
// if the setting is at "All files"
2608
// mzML will be used
2609
String upper_filename = file_name;
2610
upper_filename.toUpper();
2611
if (selected_filter == "mzData files (*.mzData)")
2613
if (!upper_filename.hasSuffix(".MZDATA"))
2615
file_name += ".mzData";
2618
else if (selected_filter == "mzXML files (*.mzXML)")
2620
if (!upper_filename.hasSuffix(".MZXML"))
2622
file_name += ".mzXML";
2627
if (!upper_filename.hasSuffix(".MZML"))
2629
file_name += ".mzML";
2633
if (visible) //only visible data
2636
getVisiblePeakData(out);
2637
addDataProcessing_(out, DataProcessing::FILTERING);
2638
FileHandler().storeExperiment(file_name,out,ProgressLogger::GUI);
2642
FileHandler().storeExperiment(file_name,*layer.getPeakData(),ProgressLogger::GUI);
2644
modificationStatus_(activeLayerIndex(), false);
2647
else if (layer.type==LayerData::DT_FEATURE) //features
2649
QString file_name = QFileDialog::getSaveFileName(this, "Save file", proposed_name.toQString(),"FeatureXML files (*.featureXML);;All files (*)");
2650
if (!file_name.isEmpty())
2652
// add suffix ".featureXML" if not given
2653
String upper_filename = file_name;
2654
upper_filename.toUpper();
2655
if (!upper_filename.hasSuffix(".FEATUREXML"))
2657
file_name += ".featureXML";
2659
if (visible) //only visible data
2662
getVisibleFeatureData(out);
2663
FeatureXMLFile().store(file_name,out);
2667
FeatureXMLFile().store(file_name,*layer.getFeatureMap());
2669
modificationStatus_(activeLayerIndex(), false);
2672
else if (layer.type==LayerData::DT_CONSENSUS) //consensus feature data
2674
QString file_name = QFileDialog::getSaveFileName(this, "Save file", proposed_name.toQString(),"ConsensusXML files (*.consensusXML);;All files (*)");
2675
if (!file_name.isEmpty())
2677
// add suffix ".consensusXML" if not given
2678
String upper_filename = file_name;
2679
upper_filename.toUpper();
2680
if (!upper_filename.hasSuffix(".CONSENSUSXML"))
2682
file_name += ".consensusXML";
2685
if (visible) //only visible data
2687
ConsensusMapType out;
2688
getVisibleConsensusData(out);
2689
ConsensusXMLFile().store(file_name,out);
2693
ConsensusXMLFile().store(file_name,*layer.getConsensusMap());
2695
modificationStatus_(activeLayerIndex(), false);
2698
else if (layer.type==LayerData::DT_CHROMATOGRAM) //chromatograms
2654
String proposed_name = param_.getValue("default_path");
2655
if (visible == false && layer.filename != "")
2657
proposed_name = layer.filename;
2660
if (layer.type == LayerData::DT_PEAK) //peak data
2662
QString selected_filter = "";
2663
QString file_name = QFileDialog::getSaveFileName(this, "Save file", proposed_name.toQString(), "mzML files (*.mzML);;mzData files (*.mzData);;mzXML files (*.mzXML);;All files (*)", &selected_filter);
2664
if (!file_name.isEmpty())
2666
// check whether a file type suffix has been given
2667
// first check mzData and mzXML then mzML
2668
// if the setting is at "All files"
2669
// mzML will be used
2670
String upper_filename = file_name;
2671
upper_filename.toUpper();
2672
if (selected_filter == "mzData files (*.mzData)")
2674
if (!upper_filename.hasSuffix(".MZDATA"))
2676
file_name += ".mzData";
2679
else if (selected_filter == "mzXML files (*.mzXML)")
2681
if (!upper_filename.hasSuffix(".MZXML"))
2683
file_name += ".mzXML";
2688
if (!upper_filename.hasSuffix(".MZML"))
2690
file_name += ".mzML";
2694
if (visible) //only visible data
2697
getVisiblePeakData(out);
2698
addDataProcessing_(out, DataProcessing::FILTERING);
2699
FileHandler().storeExperiment(file_name, out, ProgressLogger::GUI);
2703
FileHandler().storeExperiment(file_name, *layer.getPeakData(), ProgressLogger::GUI);
2705
modificationStatus_(activeLayerIndex(), false);
2708
else if (layer.type == LayerData::DT_FEATURE) //features
2710
QString file_name = QFileDialog::getSaveFileName(this, "Save file", proposed_name.toQString(), "featureXML files (*.featureXML);;All files (*)");
2711
if (!file_name.isEmpty())
2713
// add suffix ".featureXML" if not given
2714
String upper_filename = file_name;
2715
upper_filename.toUpper();
2716
if (!upper_filename.hasSuffix(".FEATUREXML"))
2718
file_name += ".featureXML";
2720
if (visible) //only visible data
2723
getVisibleFeatureData(out);
2724
FeatureXMLFile().store(file_name, out);
2728
FeatureXMLFile().store(file_name, *layer.getFeatureMap());
2730
modificationStatus_(activeLayerIndex(), false);
2733
else if (layer.type == LayerData::DT_CONSENSUS) //consensus feature data
2735
QString file_name = QFileDialog::getSaveFileName(this, "Save file", proposed_name.toQString(), "consensusXML files (*.consensusXML);;All files (*)");
2736
if (!file_name.isEmpty())
2738
// add suffix ".consensusXML" if not given
2739
String upper_filename = file_name;
2740
upper_filename.toUpper();
2741
if (!upper_filename.hasSuffix(".CONSENSUSXML"))
2743
file_name += ".consensusXML";
2746
if (visible) //only visible data
2748
ConsensusMapType out;
2749
getVisibleConsensusData(out);
2750
ConsensusXMLFile().store(file_name, out);
2754
ConsensusXMLFile().store(file_name, *layer.getConsensusMap());
2756
modificationStatus_(activeLayerIndex(), false);
2759
else if (layer.type == LayerData::DT_CHROMATOGRAM) //chromatograms
2704
2765
void Spectrum2DCanvas::updateLayer(Size i)
2706
2767
//update nearest peak
2707
2768
selected_peak_.clear();
2708
recalculateRanges_(0,1,2);
2709
resetZoom(false); //no repaint as this is done in intensityModeChange_() anyway
2710
intensityModeChange_();
2769
recalculateRanges_(0, 1, 2);
2770
resetZoom(false); //no repaint as this is done in intensityModeChange_() anyway
2771
intensityModeChange_();
2711
2772
modificationStatus_(i, false);
2714
void Spectrum2DCanvas::translateLeft_()
2716
DoubleReal shift = 0.05 * visible_area_.width();
2717
DoubleReal newLo = visible_area_.minX() - shift;
2718
DoubleReal newHi = visible_area_.maxX() - shift;
2719
// check if we are falling out of bounds
2720
if (newLo < overall_data_range_.minX())
2722
newLo = overall_data_range_.minX();
2723
newHi = newLo + visible_area_.width();
2725
//change visible area
2726
changeVisibleArea_(AreaType(newLo,visible_area_.minY(),newHi,visible_area_.maxY()));
2729
void Spectrum2DCanvas::translateRight_()
2731
DoubleReal shift = 0.05 * visible_area_.width();
2732
DoubleReal newLo = visible_area_.minX() + shift;
2733
DoubleReal newHi = visible_area_.maxX() + shift;
2734
// check if we are falling out of bounds
2735
if (newHi > overall_data_range_.maxX())
2737
newHi = overall_data_range_.maxX();
2738
newLo = newHi - visible_area_.width();
2740
//change visible area
2741
changeVisibleArea_(AreaType(newLo,visible_area_.minY(),newHi,visible_area_.maxY()));
2744
void Spectrum2DCanvas::translateForward_()
2746
DoubleReal shift = 0.05 * visible_area_.height();
2747
DoubleReal newLo = visible_area_.minY() + shift;
2748
DoubleReal newHi = visible_area_.maxY() + shift;
2749
// check if we are falling out of bounds
2750
if (newHi > overall_data_range_.maxY())
2752
newHi = overall_data_range_.maxY();
2753
newLo = newHi - visible_area_.height();
2755
//change visible area
2756
changeVisibleArea_(AreaType(visible_area_.minX(),newLo,visible_area_.maxX(),newHi));
2759
void Spectrum2DCanvas::translateBackward_()
2761
DoubleReal shift = 0.05 * visible_area_.height();
2762
DoubleReal newLo = visible_area_.minY() - shift;
2763
DoubleReal newHi = visible_area_.maxY() - shift;
2764
// check if we are falling out of bounds
2765
if (newLo < overall_data_range_.minY())
2767
newLo = overall_data_range_.minY();
2768
newHi = newLo + visible_area_.height();
2770
//change visible area
2771
changeVisibleArea_(AreaType(visible_area_.minX(),newLo,visible_area_.maxX(),newHi));
2775
void Spectrum2DCanvas::keyPressEvent(QKeyEvent* e)
2777
// CTRL+ALT+H => hidden action
2778
if ((e->modifiers() & Qt::ControlModifier) && (e->modifiers() & Qt::AltModifier) && (e->key()==Qt::Key_H))
2781
//Scaling with file size (layers)
2782
for (UInt i=0; i<getLayerCount(); ++i)
2786
for (UInt j=0; j<10; ++j)
2788
QPainter painter(&buffer_);
2789
paintDots_(i, painter);
2791
cout << "peaks: " << getLayer(i).peaks.getSize() << " time: " << timer.elapsed() / 10.0 << endl;
2794
//Scaling with resolution
2795
for (UInt i=250; i<3001; i+=250)
2800
QPainter painter(&buffer_);
2801
paintDots_(0, painter);
2802
cout << "pixels: " << i << " time: " << timer.elapsed() << endl;
2811
LayerData& layer = getCurrentLayer_();
2812
if (getCurrentLayer().modifiable && layer.type==LayerData::DT_FEATURE && selected_peak_.isValid() && e->key()==Qt::Key_Delete)
2814
layer.getFeatureMap()->erase(layer.getFeatureMap()->begin()+selected_peak_.peak);
2815
selected_peak_.clear();
2816
update_buffer_ = true;
2817
update_(__PRETTY_FUNCTION__);
2775
void Spectrum2DCanvas::translateVisibleArea_( DoubleReal mzShiftRel, DoubleReal rtShiftRel )
2777
DoubleReal rtShift = rtShiftRel * visible_area_.height();
2778
DoubleReal mzShift = mzShiftRel * visible_area_.width();
2779
AreaType newArea( visible_area_ );
2780
// shift the visible area avoiding moving out data range bounds
2781
if ( mzShift > 0 ) {
2782
newArea.setMaxX( qMin( overall_data_range_.maxX(), visible_area_.maxX() + mzShift ) );
2783
newArea.setMinX( qMax( overall_data_range_.minX(), newArea.maxX() - visible_area_.width() ) );
2785
newArea.setMinX( qMax( overall_data_range_.minX(), visible_area_.minX() + mzShift ) );
2786
newArea.setMaxX( qMin( overall_data_range_.maxX(), newArea.minX() + visible_area_.width() ) );
2788
if ( rtShift > 0 ) {
2789
newArea.setMaxY( qMin( overall_data_range_.maxY(), visible_area_.maxY() + rtShift ) );
2790
newArea.setMinY( qMax( overall_data_range_.minY(), newArea.maxY() - visible_area_.height() ) );
2792
newArea.setMinY( qMax( overall_data_range_.minY(), visible_area_.minY() + rtShift ) );
2793
newArea.setMaxY( qMin( overall_data_range_.maxY(), newArea.minY() + visible_area_.height() ) );
2795
//change visible area
2796
changeVisibleArea_(newArea);
2797
emit layerZoomChanged(this);
2800
void Spectrum2DCanvas::translateLeft_()
2802
if ( isMzToXAxis() ) translateVisibleArea_( -0.05, 0.0 );
2803
else translateVisibleArea_( 0.0, -0.05 );
2806
void Spectrum2DCanvas::translateRight_()
2808
if ( isMzToXAxis() ) translateVisibleArea_( 0.05, 0.0 );
2809
else translateVisibleArea_( 0.0, 0.05 );
2812
void Spectrum2DCanvas::translateForward_()
2814
if ( isMzToXAxis() ) translateVisibleArea_( 0.0, 0.05 );
2815
else translateVisibleArea_( 0.05, 0.0 );
2818
void Spectrum2DCanvas::translateBackward_()
2820
if ( isMzToXAxis() ) translateVisibleArea_( 0.0, -0.05 );
2821
else translateVisibleArea_( -0.05, 0.0 );
2824
void Spectrum2DCanvas::keyPressEvent(QKeyEvent * e)
2826
// CTRL+ALT+H => hidden action
2827
if ((e->modifiers() & Qt::ControlModifier) && (e->modifiers() & Qt::AltModifier) && (e->key() == Qt::Key_H))
2830
//Scaling with file size (layers)
2831
for (UInt i=0; i<getLayerCount(); ++i)
2835
for (UInt j=0; j<10; ++j)
2837
QPainter painter(&buffer_);
2838
paintDots_(i, painter);
2840
cout << "peaks: " << getLayer(i).peaks.getSize() << " time: " << timer.elapsed() / 10.0 << endl;
2843
//Scaling with resolution
2844
for (UInt i=250; i<3001; i+=250)
2849
QPainter painter(&buffer_);
2850
paintDots_(0, painter);
2851
cout << "pixels: " << i << " time: " << timer.elapsed() << endl;
2860
LayerData & layer = getCurrentLayer_();
2861
if (getCurrentLayer().modifiable && layer.type == LayerData::DT_FEATURE && selected_peak_.isValid() && e->key() == Qt::Key_Delete)
2863
layer.getFeatureMap()->erase(layer.getFeatureMap()->begin() + selected_peak_.peak);
2864
selected_peak_.clear();
2865
update_buffer_ = true;
2866
update_(__PRETTY_FUNCTION__);
2820
2869
modificationStatus_(activeLayerIndex(), true);
2824
SpectrumCanvas::keyPressEvent(e);
2828
void Spectrum2DCanvas::keyReleaseEvent(QKeyEvent* e)
2830
//zoom if in zoom mode and a valid rectangle is selected
2831
if (action_mode_==AM_ZOOM && rubber_band_.isVisible())
2833
rubber_band_.hide();
2834
QRect rect = rubber_band_.geometry();
2835
if (rect.width()!=0 && rect.height()!=0)
2837
AreaType area(widgetToData_(rect.topLeft()), widgetToData_(rect.bottomRight()));
2838
changeVisibleArea_(area, true, true);
2841
else if (action_mode_==AM_MEASURE)
2843
measurement_start_.clear();
2844
update_(__PRETTY_FUNCTION__);
2847
//do the normal stuff
2848
SpectrumCanvas::keyReleaseEvent(e);
2851
void Spectrum2DCanvas::mouseDoubleClickEvent(QMouseEvent* e)
2853
LayerData& current_layer = getCurrentLayer_();
2855
if (current_layer.modifiable && current_layer.type==LayerData::DT_FEATURE)
2858
if (selected_peak_.isValid()) //edit existing feature
2860
FeatureEditDialog dialog(this);
2873
SpectrumCanvas::keyPressEvent(e);
2877
void Spectrum2DCanvas::keyReleaseEvent(QKeyEvent * e)
2879
//zoom if in zoom mode and a valid rectangle is selected
2880
if (action_mode_ == AM_ZOOM && rubber_band_.isVisible())
2882
rubber_band_.hide();
2883
QRect rect = rubber_band_.geometry();
2884
if (rect.width() != 0 && rect.height() != 0)
2886
AreaType area(widgetToData_(rect.topLeft()), widgetToData_(rect.bottomRight()));
2887
changeVisibleArea_(area, true, true);
2888
emit layerZoomChanged(this);
2891
else if (action_mode_ == AM_MEASURE)
2893
measurement_start_.clear();
2894
update_(__PRETTY_FUNCTION__);
2897
//do the normal stuff
2898
SpectrumCanvas::keyReleaseEvent(e);
2901
void Spectrum2DCanvas::mouseDoubleClickEvent(QMouseEvent * e)
2903
LayerData & current_layer = getCurrentLayer_();
2905
if (current_layer.modifiable && current_layer.type == LayerData::DT_FEATURE)
2908
if (selected_peak_.isValid()) //edit existing feature
2910
FeatureEditDialog dialog(this);
2861
2911
dialog.setFeature((*current_layer.getFeatureMap())[selected_peak_.peak]);
2864
tmp = dialog.getFeature();
2914
tmp = dialog.getFeature();
2865
2915
(*current_layer.getFeatureMap())[selected_peak_.peak] = tmp;
2868
else //create new feature
2870
tmp.setRT(widgetToData_(e->pos())[1]);
2871
tmp.setMZ(widgetToData_(e->pos())[0]);
2872
FeatureEditDialog dialog(this);
2873
dialog.setFeature(tmp);
2876
tmp = dialog.getFeature();
2918
else //create new feature
2920
tmp.setRT(widgetToData_(e->pos())[1]);
2921
tmp.setMZ(widgetToData_(e->pos())[0]);
2922
FeatureEditDialog dialog(this);
2923
dialog.setFeature(tmp);
2926
tmp = dialog.getFeature();
2877
2927
current_layer.getFeatureMap()->push_back(tmp);
2881
//update gradient if the min/max intensity changes
2882
if (tmp.getIntensity()<current_layer.getFeatureMap()->getMinInt() || tmp.getIntensity()>current_layer.getFeatureMap()->getMaxInt())
2931
//update gradient if the min/max intensity changes
2932
if (tmp.getIntensity() < current_layer.getFeatureMap()->getMinInt() || tmp.getIntensity() > current_layer.getFeatureMap()->getMaxInt())
2884
2934
current_layer.getFeatureMap()->updateRanges();
2885
recalculateRanges_(0,1,2);
2886
intensityModeChange_();
2888
else //just repaint to show the changes
2890
update_buffer_ = true;
2891
update_(__PRETTY_FUNCTION__);
2935
recalculateRanges_(0, 1, 2);
2936
intensityModeChange_();
2938
else //just repaint to show the changes
2940
update_buffer_ = true;
2941
update_(__PRETTY_FUNCTION__);
2894
2944
modificationStatus_(activeLayerIndex(), true);
2898
2948
void Spectrum2DCanvas::mergeIntoLayer(Size i, FeatureMapSharedPtrType map)
2900
OPENMS_PRECONDITION(i < layers_.size(), "Spectrum2DCanvas::mergeIntoLayer(i, map) index overflow");
2901
OPENMS_PRECONDITION(layers_[i].type==LayerData::DT_FEATURE, "Spectrum2DCanvas::mergeIntoLayer(i, map) non-feature layer selected");
2902
//reserve enough space
2903
layers_[i].getFeatureMap()->reserve(layers_[i].getFeatureMap()->size()+map->size());
2905
for (Size j=0; j<map->size(); ++j)
2950
OPENMS_PRECONDITION(i < layers_.size(), "Spectrum2DCanvas::mergeIntoLayer(i, map) index overflow");
2951
OPENMS_PRECONDITION(layers_[i].type == LayerData::DT_FEATURE, "Spectrum2DCanvas::mergeIntoLayer(i, map) non-feature layer selected");
2952
//reserve enough space
2953
layers_[i].getFeatureMap()->reserve(layers_[i].getFeatureMap()->size() + map->size());
2955
for (Size j = 0; j < map->size(); ++j)
2907
2957
layers_[i].getFeatureMap()->push_back((*map)[j]);
2909
//update the layer and overall ranges (if necessary)
2959
//update the layer and overall ranges (if necessary)
2910
2960
RangeManager<2>::PositionType min_pos_old = layers_[i].getFeatureMap()->getMin();
2911
2961
RangeManager<2>::PositionType max_pos_old = layers_[i].getFeatureMap()->getMax();
2912
2962
DoubleReal min_int_old = layers_[i].getFeatureMap()->getMinInt();
2913
2963
DoubleReal max_int_old = layers_[i].getFeatureMap()->getMaxInt();
2914
2964
layers_[i].getFeatureMap()->updateRanges();
2915
if(min_pos_old>layers_[i].getFeatureMap()->getMin() || max_pos_old<layers_[i].getFeatureMap()->getMax())
2917
recalculateRanges_(0,1,2);
2920
if(min_int_old>layers_[i].getFeatureMap()->getMinInt() || max_int_old<layers_[i].getFeatureMap()->getMaxInt())
2922
intensityModeChange_();
2965
if (min_pos_old > layers_[i].getFeatureMap()->getMin() || max_pos_old < layers_[i].getFeatureMap()->getMax())
2967
recalculateRanges_(0, 1, 2);
2970
if (min_int_old > layers_[i].getFeatureMap()->getMinInt() || max_int_old < layers_[i].getFeatureMap()->getMaxInt())
2972
intensityModeChange_();
2926
2976
void Spectrum2DCanvas::mergeIntoLayer(Size i, ConsensusMapSharedPtrType map)
2928
OPENMS_PRECONDITION(i < layers_.size(), "Spectrum2DCanvas::mergeIntoLayer(i, map) index overflow");
2929
OPENMS_PRECONDITION(layers_[i].type==LayerData::DT_CONSENSUS, "Spectrum2DCanvas::mergeIntoLayer(i, map) non-consensus-feature layer selected");
2930
//reserve enough space
2931
layers_[i].getConsensusMap()->reserve(layers_[i].getFeatureMap()->size()+map->size());
2933
for (Size j=0; j<map->size(); ++j)
2978
OPENMS_PRECONDITION(i < layers_.size(), "Spectrum2DCanvas::mergeIntoLayer(i, map) index overflow");
2979
OPENMS_PRECONDITION(layers_[i].type == LayerData::DT_CONSENSUS, "Spectrum2DCanvas::mergeIntoLayer(i, map) non-consensus-feature layer selected");
2980
//reserve enough space
2981
layers_[i].getConsensusMap()->reserve(layers_[i].getFeatureMap()->size() + map->size());
2983
for (Size j = 0; j < map->size(); ++j)
2935
2985
layers_[i].getConsensusMap()->push_back((*map)[j]);
2937
//update the layer and overall ranges (if necessary)
2987
//update the layer and overall ranges (if necessary)
2938
2988
RangeManager<2>::PositionType min_pos_old = layers_[i].getConsensusMap()->getMin();
2939
2989
RangeManager<2>::PositionType max_pos_old = layers_[i].getConsensusMap()->getMax();
2940
2990
DoubleReal min_int_old = layers_[i].getConsensusMap()->getMinInt();
2941
2991
DoubleReal max_int_old = layers_[i].getConsensusMap()->getMaxInt();
2942
2992
layers_[i].getConsensusMap()->updateRanges();
2943
if(min_pos_old>layers_[i].getConsensusMap()->getMin() || max_pos_old<layers_[i].getConsensusMap()->getMax())
2945
recalculateRanges_(0,1,2);
2948
if(min_int_old>layers_[i].getConsensusMap()->getMinInt() || max_int_old<layers_[i].getConsensusMap()->getMaxInt())
2950
intensityModeChange_();
2993
if (min_pos_old > layers_[i].getConsensusMap()->getMin() || max_pos_old < layers_[i].getConsensusMap()->getMax())
2995
recalculateRanges_(0, 1, 2);
2998
if (min_int_old > layers_[i].getConsensusMap()->getMinInt() || max_int_old < layers_[i].getConsensusMap()->getMaxInt())
3000
intensityModeChange_();
2954
void Spectrum2DCanvas::mergeIntoLayer(Size i, vector<PeptideIdentification>& peptides)
2956
OPENMS_PRECONDITION(i < layers_.size(), "Spectrum2DCanvas::mergeIntoLayer(i, peptides) index overflow");
2957
OPENMS_PRECONDITION(layers_[i].type==LayerData::DT_IDENT, "Spectrum2DCanvas::mergeIntoLayer(i, peptides) non-identification layer selected");
2958
// reserve enough space
2959
layers_[i].peptides.reserve(layers_[i].peptides.size() + peptides.size());
2961
layers_[i].peptides.insert(layers_[i].peptides.end(), peptides.begin(),
2963
// update the layer and overall ranges
2964
recalculateRanges_(0,1,2);
3004
void Spectrum2DCanvas::mergeIntoLayer(Size i, vector<PeptideIdentification> & peptides)
3006
OPENMS_PRECONDITION(i < layers_.size(), "Spectrum2DCanvas::mergeIntoLayer(i, peptides) index overflow");
3007
OPENMS_PRECONDITION(layers_[i].type == LayerData::DT_IDENT, "Spectrum2DCanvas::mergeIntoLayer(i, peptides) non-identification layer selected");
3008
// reserve enough space
3009
layers_[i].peptides.reserve(layers_[i].peptides.size() + peptides.size());
3011
layers_[i].peptides.insert(layers_[i].peptides.end(), peptides.begin(),
3013
// update the layer and overall ranges
3014
recalculateRanges_(0, 1, 2);
2968
3018
} //namespace OpenMS