1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Timo Sachsenberg $
// $Authors: Timo Sachsenberg $
// --------------------------------------------------------------------------
#include <OpenMS/VISUAL/APPLICATIONS/TOPPViewBase.h>
#include <OpenMS/VISUAL/Spectrum1DWidget.h>
#include <OpenMS/VISUAL/TOPPViewSpectraViewBehavior.h>
#include <OpenMS/KERNEL/ChromatogramTools.h>
#include <OpenMS/VISUAL/AxisWidget.h>
#include <QtGui/QMessageBox>
#include <QtCore/QString>
using namespace OpenMS;
using namespace std;
namespace OpenMS
{
TOPPViewSpectraViewBehavior::TOPPViewSpectraViewBehavior(TOPPViewBase * parent) :
tv_(parent)
{
}
String caption;
void TOPPViewSpectraViewBehavior::showSpectrumAs1D(int index)
{
// basic behavior 1
const LayerData & layer = tv_->getActiveCanvas()->getCurrentLayer();
ExperimentSharedPtrType exp_sptr = layer.getPeakData();
// open new 1D widget
Spectrum1DWidget * w = new Spectrum1DWidget(tv_->getSpectrumParameters(1), (QWidget *)tv_->getWorkspace());
if (layer.type == LayerData::DT_CHROMATOGRAM)
{
// fix legend if its a chromatogram
w->xAxis()->setLegend("Time [sec]");
// create a managed pointer fill it with a spectrum containing the chromatographic data
ExperimentSharedPtrType chrom_exp_sptr(new ExperimentType());
chrom_exp_sptr->setMetaValue("is_chromatogram", "true"); //this is a hack to store that we have chromatogram data
SpectrumType spectrum;
const MSChromatogram<ChromatogramPeak> & current_chrom = exp_sptr->getChromatograms()[index];
for (Size i = 0; i != current_chrom.size(); ++i)
{
const ChromatogramPeak & cpeak = current_chrom[i];
Peak1D peak1d;
peak1d.setMZ(cpeak.getRT());
peak1d.setIntensity(cpeak.getIntensity());
spectrum.push_back(peak1d);
}
chrom_exp_sptr->addSpectrum(spectrum);
caption = layer.name + "[" + index + "]";
//add chromatogram data as peak spectrum
if (!w->canvas()->addLayer(chrom_exp_sptr, layer.filename))
{
return;
}
w->canvas()->setDrawMode(Spectrum1DCanvas::DM_CONNECTEDLINES);
}
else if (layer.type == LayerData::DT_PEAK)
{
caption = layer.name;
//add data
if (!w->canvas()->addLayer(exp_sptr, layer.filename) || (Size)index >= w->canvas()->getCurrentLayer().getPeakData()->size())
{
return;
}
}
w->canvas()->activateSpectrum(index);
// set relative (%) view of visible area
w->canvas()->setIntensityMode(SpectrumCanvas::IM_SNAP);
if (layer.type == LayerData::DT_PEAK)
{
//for MS1 spectra set visible area to visible area in 2D view.
UInt ms_level = w->canvas()->getCurrentLayer().getCurrentSpectrum().getMSLevel();
if (ms_level == 1)
{
// set visible aree to visible area in 2D view
w->canvas()->setVisibleArea(tv_->getActiveCanvas()->getVisibleArea());
}
}
else if (layer.type == LayerData::DT_CHROMATOGRAM)
{
// set visible area to visible area in 2D view
// switch X/Y because now we want to have RT on the x-axis and not m/z
DRange<2> visible_area = tv_->getActiveCanvas()->getVisibleArea();
int tmp_x1 = visible_area.minX();
int tmp_x2 = visible_area.maxX();
visible_area.setMinX(visible_area.minY());
visible_area.setMaxX(visible_area.maxY());
visible_area.setMinY(tmp_x1);
visible_area.setMaxY(tmp_x2);
w->canvas()->setVisibleArea(visible_area);
w->canvas()->getCurrentLayer().getChromatogramData() = exp_sptr; // save the original chromatogram data so that we can access it later
}
// basic behavior 2
String caption = layer.name;
w->canvas()->setLayerName(w->canvas()->activeLayerIndex(), caption);
tv_->showSpectrumWidgetInWindow(w, caption);
tv_->updateLayerBar();
tv_->updateViewBar();
tv_->updateFilterBar();
tv_->updateMenu();
}
void TOPPViewSpectraViewBehavior::showSpectrumAs1D(std::vector<int, std::allocator<int> > indices)
{
// basic behavior 1
// show multiple spectra together is only used for chromatograms directly
// where multiple (SRM) traces are shown together
const LayerData & layer = tv_->getActiveCanvas()->getCurrentLayer();
ExperimentSharedPtrType exp_sptr = layer.getPeakData();
// string for naming the different chromatogram layers with their index
String chromatogram_caption;
// string for naming the tab title with the indices of the chromatograms
caption = layer.name;
//open new 1D widget
Spectrum1DWidget * w = new Spectrum1DWidget(tv_->getSpectrumParameters(1), (QWidget *)tv_->getWorkspace());
// fix legend if its a chromatogram
w->xAxis()->setLegend("Time [sec]");
for (Size index = 0; index != indices.size(); ++index)
{
// create a managed pointer fill it with a spectrum containing the chromatographic data
ExperimentSharedPtrType chrom_exp_sptr(new ExperimentType());
chrom_exp_sptr->setMetaValue("is_chromatogram", "true"); //this is a hack to store that we have chromatogram data
SpectrumType spectrum;
if (layer.type == LayerData::DT_CHROMATOGRAM)
{
const MSChromatogram<ChromatogramPeak> & current_chrom = exp_sptr->getChromatograms()[indices[index]];
for (Size i = 0; i != current_chrom.size(); ++i)
{
const ChromatogramPeak & cpeak = current_chrom[i];
Peak1D peak1d;
peak1d.setMZ(cpeak.getRT());
peak1d.setIntensity(cpeak.getIntensity());
spectrum.push_back(peak1d);
}
chrom_exp_sptr->addSpectrum(spectrum);
caption = caption + " [" + indices[index] + "];";
chromatogram_caption = layer.name + "[" + indices[index] + "]";
//add chromatogram data as peak spectrum
if (!w->canvas()->addLayer(chrom_exp_sptr, layer.filename))
{
return;
}
w->canvas()->activateSpectrum(*indices.begin());
w->canvas()->setLayerName(w->canvas()->activeLayerIndex(), chromatogram_caption);
w->canvas()->setDrawMode(Spectrum1DCanvas::DM_CONNECTEDLINES);
w->canvas()->getCurrentLayer().getChromatogramData() = exp_sptr; // save the original chromatogram data so that we can access it later
// set visible area to visible area in 2D view
// switch X/Y because now we want to have RT on the x-axis and not m/z
DRange<2> visible_area = tv_->getActiveCanvas()->getVisibleArea();
int tmp_x1 = visible_area.minX();
int tmp_x2 = visible_area.maxX();
visible_area.setMinX(visible_area.minY());
visible_area.setMaxX(visible_area.maxY());
visible_area.setMinY(tmp_x1);
visible_area.setMaxY(tmp_x2);
w->canvas()->setVisibleArea(visible_area);
}
}
// set relative (%) view of visible area
w->canvas()->setIntensityMode(SpectrumCanvas::IM_SNAP);
// basic behavior 2
tv_->showSpectrumWidgetInWindow(w, caption);
tv_->updateLayerBar();
tv_->updateViewBar();
tv_->updateFilterBar();
tv_->updateMenu();
}
void TOPPViewSpectraViewBehavior::activate1DSpectrum(int index)
{
Spectrum1DWidget * widget_1d = tv_->getActive1DWidget();
widget_1d->canvas()->activateSpectrum(index);
const LayerData & layer = tv_->getActiveCanvas()->getCurrentLayer();
// If we have a chromatogram, we cannot just simply activate this spectrum.
// we have to do much more work, e.g. creating a new experiment with the
// new spectrum.
if (layer.chromatogram_flag_set())
{
// first get chromatogram data
ExperimentSharedPtrType exp_sptr = widget_1d->canvas()->getCurrentLayer().getChromatogramData();
const LayerData & layer = widget_1d->canvas()->getCurrentLayer();
String fname = layer.filename;
String lname = layer.name;
Size layercount = widget_1d->canvas()->getLayerCount();
for (Size i = 0; i != layercount; ++i)
{
widget_1d->canvas()->removeLayer(0); // remove layer 0 until there are no more layers
}
// create a managed pointer fill it with a spectrum containing the chromatographic data
ExperimentSharedPtrType chrom_exp_sptr(new ExperimentType());
SpectrumType spectrum;
const MSChromatogram<ChromatogramPeak> & current_chrom = exp_sptr->getChromatograms()[index];
for (Size i = 0; i != current_chrom.size(); ++i)
{
const ChromatogramPeak & cpeak = current_chrom[i];
Peak1D peak1d;
peak1d.setMZ(cpeak.getRT());
peak1d.setIntensity(cpeak.getIntensity());
spectrum.push_back(peak1d);
}
chrom_exp_sptr->addSpectrum(spectrum);
caption = lname + "[" + index + "]";
//add chromatogram data as peak spectrum
if (!widget_1d->canvas()->addLayer(chrom_exp_sptr, fname))
{
return;
}
widget_1d->canvas()->setDrawMode(Spectrum1DCanvas::DM_CONNECTEDLINES);
widget_1d->canvas()->activateSpectrum(index);
widget_1d->canvas()->getCurrentLayer().name = caption;
widget_1d->canvas()->getCurrentLayer().filename = fname;
widget_1d->canvas()->getCurrentLayer().getChromatogramData() = exp_sptr; // save the original chromatogram data so that we can access it later
//this is a hack to store that we have chromatogram data, that we selected multiple ones and which one we selected
widget_1d->canvas()->getCurrentLayer().getPeakData()->setMetaValue("is_chromatogram", "true");
widget_1d->canvas()->getCurrentLayer().getPeakData()->setMetaValue("multiple_select", "false");
widget_1d->canvas()->getCurrentLayer().getPeakData()->setMetaValue("selected_chromatogram", index);
tv_->updateLayerBar();
tv_->updateViewBar();
tv_->updateFilterBar();
tv_->updateMenu();
}
}
void TOPPViewSpectraViewBehavior::activate1DSpectrum(std::vector<int, std::allocator<int> > indices)
{
Spectrum1DWidget * widget_1d = tv_->getActive1DWidget();
// If we have a chromatogram, we cannot just simply activate this spectrum.
// we have to do much more work, e.g. creating a new experiment with the
// new spectrum.
const LayerData & layer = widget_1d->canvas()->getCurrentLayer();
String fname = layer.filename;
if (layer.chromatogram_flag_set())
{
// first get chromatogram data
ExperimentSharedPtrType exp_sptr = widget_1d->canvas()->getCurrentLayer().getChromatogramData();
Size layercount = widget_1d->canvas()->getLayerCount();
for (Size i = 0; i != layercount; ++i)
{
widget_1d->canvas()->removeLayer(0); // remove layer 0 until there are no more layers
}
for (Size index = 0; index != indices.size(); ++index)
{
// create a managed pointer fill it with a spectrum containing the chromatographic data
ExperimentSharedPtrType chrom_exp_sptr(new ExperimentType());
SpectrumType spectrum;
const MSChromatogram<ChromatogramPeak> & current_chrom = exp_sptr->getChromatograms()[indices[index]];
for (Size i = 0; i != current_chrom.size(); ++i)
{
const ChromatogramPeak & cpeak = current_chrom[i];
Peak1D peak1d;
peak1d.setMZ(cpeak.getRT());
peak1d.setIntensity(cpeak.getIntensity());
spectrum.push_back(peak1d);
}
chrom_exp_sptr->addSpectrum(spectrum);
caption = fname + "[" + indices[index] + "]";
if (current_chrom.getPrecursor().metaValueExists("peptide_sequence"))
{
caption = String(current_chrom.getPrecursor().getMetaValue("peptide_sequence")) + "[" + indices[index] + "]";
}
//add chromatogram data as peak spectrum
if (!widget_1d->canvas()->addLayer(chrom_exp_sptr, fname))
{
return;
}
widget_1d->canvas()->setDrawMode(Spectrum1DCanvas::DM_CONNECTEDLINES);
widget_1d->canvas()->setIntensityMode(Spectrum1DCanvas::IM_NONE);
widget_1d->canvas()->activateSpectrum(indices[index]);
//widget_1d->canvas()->activateSpectrum(0);
widget_1d->canvas()->getCurrentLayer().name = caption;
widget_1d->canvas()->getCurrentLayer().filename = fname;
widget_1d->canvas()->getCurrentLayer().getChromatogramData() = exp_sptr; // save the original chromatogram data so that we can access it later
//this is a hack to store that we have chromatogram data, that we selected multiple ones and which one we selected
widget_1d->canvas()->getCurrentLayer().getPeakData()->setMetaValue("is_chromatogram", "true");
widget_1d->canvas()->getCurrentLayer().getPeakData()->setMetaValue("multiple_select", "true");
widget_1d->canvas()->getCurrentLayer().getPeakData()->setMetaValue("selected_chromatogram", indices[index]);
}
tv_->updateLayerBar();
tv_->updateViewBar();
tv_->updateFilterBar();
tv_->updateMenu();
}
}
void TOPPViewSpectraViewBehavior::deactivate1DSpectrum(int /* spectrum_index */)
{
// no special handling of spectrum deactivation needed
}
void TOPPViewSpectraViewBehavior::activateBehavior()
{
// no special handling of activation
}
void TOPPViewSpectraViewBehavior::deactivateBehavior()
{
// no special handling of deactivation
}
} // OpenMS
|