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
|
// --------------------------------------------------------------------------
// 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: Hannes Roest $
// $Authors: Hannes Roest $
// --------------------------------------------------------------------------
#include <OpenMS/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.h>
#include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/DataAccessHelper.h>
#include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/SimpleOpenMSSpectraAccessFactory.h>
#include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathHelper.h>
#include <OpenMS/APPLICATIONS/TOPPBase.h>
#include <OpenMS/CONCEPT/Exception.h>
#include <OpenMS/CONCEPT/ProgressLogger.h>
#include <fstream>
using namespace OpenMS;
using namespace std;
//
//-------------------------------------------------------------
//Doxygen docu
//-------------------------------------------------------------
/**
@page TOPP_OpenSwathAnalyzer OpenSwathAnalyzer
@brief Executes a peak-picking and scoring algorithm on MRM/SRM data.
<CENTER>
<table>
<tr>
<td ALIGN = "center" BGCOLOR="#EBEBEB"> potential predecessor tools </td>
<td VALIGN="middle" ROWSPAN=3> \f$ \longrightarrow \f$ OpenSwathAnalyzer \f$ \longrightarrow \f$</td>
<td ALIGN = "center" BGCOLOR="#EBEBEB"> potential successor tools </td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_OpenSwathChromatogramExtractor </td>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_OpenSwathFeatureXMLToTSV </td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_MRMMapper </td>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_OpenSwathConfidenceScoring </td>
</tr>
</table>
</CENTER>
The idea of the MRM peak-picker is to analyze a series of chromatograms
together with the associated meta information (stored in TraML format) in
order to determine likely places of elution of a peptide in MRM/SRM.
<B>The command line parameters of this tool are:</B>
@verbinclude TOPP_OpenSwathAnalyzer.cli
<B>The algorithm parameters for the Analyzer filter are:</B>
@htmlinclude TOPP_OpenSwathAnalyzer.html
*/
// We do not want this class to show up in the docu:
/// @cond TOPPCLASSES
class TOPPOpenSwathAnalyzer : public TOPPBase
{
public:
TOPPOpenSwathAnalyzer() :
TOPPBase("OpenSwathAnalyzer",
"Picks peaks and finds features in an SRM experiment.", true)
{
}
protected:
typedef MSExperiment<Peak1D> MapType;
void registerModelOptions_(const String &default_model)
{
registerTOPPSubsection_("model", "Options to control the modeling of retention time transformations from data");
registerStringOption_("model:type", "<name>", default_model, "Type of model", false, true);
StringList model_types;
TransformationDescription::getModelTypes(model_types);
if (!model_types.contains(default_model))
{
model_types.insert(model_types.begin(), default_model);
}
setValidStrings_("model:type", model_types);
registerFlag_("model:symmetric_regression", "Only for 'linear' model: Perform linear regression on 'y - x' vs. 'y + x', instead of on 'y' vs. 'x'.", true);
registerIntOption_("model:num_breakpoints", "<number>", 5,
"Only for 'b_spline' model: Number of breakpoints of the cubic spline in the smoothing step. The breakpoints are spaced uniformly on the retention time interval. More breakpoints mean less smoothing. Reduce this number if the transformation has an unexpected shape.",
false, true);
setMinInt_("model:num_breakpoints", 2);
registerStringOption_("model:interpolation_type", "<name>", "cspline",
"Only for 'interpolated' model: Type of interpolation to apply.", false, true);
}
void registerOptionsAndFlags_()
{
registerInputFile_("in", "<file>", "",
"input file containing the chromatograms." /* , false */);
setValidFormats_("in", StringList::create("mzML"));
registerInputFile_("tr", "<file>", "", "transition file");
setValidFormats_("tr", StringList::create("TraML"));
registerInputFile_("rt_norm", "<file>", "",
"RT normalization file (how to map the RTs of this run to the ones stored in the library)",
false);
setValidFormats_("rt_norm", StringList::create("trafoXML"));
registerOutputFile_("out", "<file>", "", "output file");
setValidFormats_("out", StringList::create("featureXML"));
registerFlag_("no-strict",
"run in non-strict mode and allow some chromatograms to not be mapped.");
addEmptyLine_();
registerInputFileList_("swath_files", "<files>", StringList(),
"[applies only if you have full MS2 spectra maps] "
"Swath files that were used to extract the transitions. "
"If present, SWATH specific scoring will be used.",
false);
setValidFormats_("swath_files", StringList::create("mzML"));
registerDoubleOption_("min_upper_edge_dist", "<double>", 0.0,
"[applies only if you have full MS2 spectra maps] "
"Minimal distance to the edge to still consider a precursor, in Thomson (only in SWATH)",
false);
registerModelOptions_("linear");
registerSubsection_("algorithm", "Algorithm parameters section");
}
Param getSubsectionDefaults_(const String &) const
{
return MRMFeatureFinderScoring().getDefaults();
}
ExitCodes main_(int, const char **)
{
StringList file_list = getStringList_("swath_files");
String in = getStringOption_("in");
String tr_file = getStringOption_("tr");
String out = getStringOption_("out");
DoubleReal min_upper_edge_dist = getDoubleOption_("min_upper_edge_dist");
bool nostrict = getFlag_("no-strict");
// If we have a transformation file, trafo will transform the RT in the
// scoring according to the model. If we dont have one, it will apply the
// null transformation.
String trafo_in = getStringOption_("rt_norm");
TransformationDescription trafo;
if (trafo_in.size() > 0)
{
TransformationXMLFile trafoxml;
String model_type = getStringOption_("model:type");
Param model_params = getParam_().copy("model:", true);
trafoxml.load(trafo_in, trafo);
trafo.fitModel(model_type, model_params);
}
Param feature_finder_param = getParam_().copy("algorithm:", true);
// Create the output map, load the input TraML file and the chromatograms
MapType exp;
FeatureMap<> out_featureFile;
OpenSwath::LightTargetedExperiment transition_exp;
std::cout << "Loading TraML file" << std::endl;
{
TargetedExperiment *transition_exp__ = new TargetedExperiment();
TargetedExperiment &transition_exp_ = *transition_exp__;
{
TraMLFile *t = new TraMLFile;
t->load(tr_file, transition_exp_);
delete t;
}
OpenSwathDataAccessHelper::convertTargetedExp(transition_exp_, transition_exp);
delete transition_exp__;
}
MzMLFile mzmlfile;
mzmlfile.setLogType(log_type_);
mzmlfile.load(in, exp);
// If there are no SWATH files its, just regular SRM/MRM Scoring
if (file_list.size() == 0)
{
MRMFeatureFinderScoring featureFinder;
MapType empty_swath_map;
featureFinder.setParameters(feature_finder_param);
featureFinder.setLogType(log_type_);
featureFinder.setStrictFlag(!nostrict);
OpenMS::MRMFeatureFinderScoring::TransitionGroupMapType transition_group_map;
OpenSwath::SpectrumAccessPtr empty_swath_ptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(empty_swath_map);
OpenSwath::SpectrumAccessPtr chromatogram_ptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(exp);
featureFinder.pickExperiment(chromatogram_ptr, out_featureFile, transition_exp, trafo, empty_swath_ptr, transition_group_map);
out_featureFile.ensureUniqueId();
addDataProcessing_(out_featureFile, getProcessingInfo_(DataProcessing::QUANTITATION));
FeatureXMLFile().store(out, out_featureFile);
return EXECUTION_OK;
}
// Here we deal with SWATH files (can be multiple files)
// Only in OpenMP 3.0 are unsigned loop variables allowed
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (SignedSize i = 0; i < boost::numeric_cast<SignedSize>(file_list.size()); ++i)
{
MRMFeatureFinderScoring featureFinder;
MzMLFile swath_file;
MapType swath_map;
FeatureMap<> featureFile;
cout << "Loading file " << file_list[i] << endl;
////#ifndef _OPENMP
// no progress log on the console in parallel
swath_file.setLogType(log_type_);
featureFinder.setLogType(log_type_);
//#endif
swath_file.load(file_list[i], swath_map);
// Logging and output to the console
#ifdef _OPENMP
#pragma omp critical (featureFinder)
#endif
{
cout << "Doing file " << file_list[i]
#ifdef _OPENMP
<< " (" << i << " out of " << file_list.size() / omp_get_num_threads() << " -- total for all threads: " << file_list.size() << ")" << endl;
#else
<< " (" << i << " out of " << file_list.size() << ")" << endl;
#endif
}
OpenSwath::LightTargetedExperiment transition_exp_used;
bool do_continue = OpenSwathHelper::checkSwathMapAndSelectTransitions(swath_map, transition_exp, transition_exp_used, min_upper_edge_dist);
if (do_continue)
{
featureFinder.setParameters(feature_finder_param);
featureFinder.setStrictFlag(!nostrict);
OpenMS::MRMFeatureFinderScoring::TransitionGroupMapType transition_group_map;
OpenSwath::SpectrumAccessPtr swath_ptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(swath_map);
OpenSwath::SpectrumAccessPtr chromatogram_ptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(exp);
featureFinder.pickExperiment(chromatogram_ptr, featureFile, transition_exp_used, trafo, swath_ptr, transition_group_map);
// write all features and the protein identifications from tmp_featureFile into featureFile
#ifdef _OPENMP
#pragma omp critical (featureFinder)
#endif
{
for (FeatureMap<Feature>::iterator feature_it = featureFile.begin();
feature_it != featureFile.end(); feature_it++)
{
out_featureFile.push_back(*feature_it);
}
for (std::vector<ProteinIdentification>::iterator protid_it =
featureFile.getProteinIdentifications().begin();
protid_it != featureFile.getProteinIdentifications().end();
protid_it++)
{
out_featureFile.getProteinIdentifications().push_back(*protid_it);
}
}
} // end of do_continue
} // end of loop over all files / end of OpenMP
addDataProcessing_(out_featureFile, getProcessingInfo_(DataProcessing::QUANTITATION));
out_featureFile.ensureUniqueId();
FeatureXMLFile().store(out, out_featureFile);
return EXECUTION_OK;
}
};
int main(int argc, const char **argv)
{
TOPPOpenSwathAnalyzer tool;
return tool.main(argc, argv);
}
/// @endcond
|