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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
|
// --------------------------------------------------------------------------
// 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: Alexandra Zerck $
// $Authors: Alexandra Zerck, Chris Bielow$
// --------------------------------------------------------------------------
//#include <OpenMS/FORMAT/TraMLFile.h>
#include <OpenMS/FORMAT/IdXMLFile.h>
#include <OpenMS/FORMAT/FileHandler.h>
#include <OpenMS/ANALYSIS/TARGETED/InclusionExclusionList.h>
#include <OpenMS/ANALYSIS/TARGETED/OfflinePrecursorIonSelection.h>
#include <OpenMS/APPLICATIONS/TOPPBase.h>
using namespace OpenMS;
using namespace std;
//-------------------------------------------------------------
//Doxygen docu
//-------------------------------------------------------------
/**
@page TOPP_InclusionExclusionListCreator InclusionExclusionListCreator
@brief A tool for creating inclusion and/or exclusion lists for LC-MS/MS.
<CENTER>
<table>
<tr>
<td ALIGN = "center" BGCOLOR="#EBEBEB"> potential predecessor tools </td>
<td VALIGN="middle" ROWSPAN=3> \f$ \longrightarrow \f$ InclusionExclusionListCreator \f$ \longrightarrow \f$</td>
<td ALIGN = "center" BGCOLOR="#EBEBEB"> potential successor tools </td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_MascotAdapter (or other ID engines) </td>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=2> - </td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_FeatureFinderCentroided </td>
</tr>
</table>
</CENTER>
Currently this tool can create tab-delimited inclusion or exclusion lists (m/z, RT start, RT stop).
The input can either be peptide identifications from previous runs, a feature map or a FASTA-file with proteins.
Inclusion and exclusion charges can be specified for FASTA and idXML input. If no charges are specified in the case of peptide id input, only
the charge state of the peptide id is in/excluded, otherwise all given charge states are entered to the list.
The RT window size can be specified in the RT section of the INI file, either as relative window
with [rt-rel_rt_window_size*rt,rt+rel_rt_window_size*rt] or absolute window.
The default is RT in minutes, but seconds can also be used (see INI file).
<B>The command line parameters of this tool are:</B>
@verbinclude TOPP_InclusionExclusionListCreator.cli
<B>INI file documentation of this tool:</B>
@htmlinclude TOPP_InclusionExclusionListCreator.html
*/
// We do not want this class to show up in the docu:
/// @cond TOPPCLASSES
class TOPPInclusionExclusionListCreator :
public TOPPBase
{
public:
TOPPInclusionExclusionListCreator() :
TOPPBase("InclusionExclusionListCreator", "Creates inclusion and/or exclusion lists.")
{
}
protected:
void registerOptionsAndFlags_()
{
registerInputFile_("include", "<file>", "", "Inclusion list input file in FASTA or featureXML format.", false);
setValidFormats_("include", StringList::create("featureXML,fasta"));
registerInputFile_("exclude", "<file>", "", "Exclusion list input file in featureXML, idXML or FASTA format.", false);
setValidFormats_("exclude", StringList::create("featureXML,idXML,fasta"));
registerOutputFile_("out", "<file>", "", "Output file (tab delimited csv file).");
setValidFormats_("out", StringList::create("csv"));
registerInputFile_("rt_model", "<file>", "", "RTModel file used for the rt prediction of peptides in FASTA files.", false);
setValidFormats_("rt_model", StringList::create("txt"));
registerInputFile_("pt_model", "<file>", "", "PTModel file used for the pt prediction of peptides in FASTA files (only needed for inclusion_strategy PreotinBased_LP).", false);
setValidFormats_("pt_model", StringList::create("txt"));
//in FASTA or featureXML
registerIntList_("inclusion_charges", "<charge>", IntList(), "List containing the charge states to be considered for the inclusion list compounds, space separated.", false);
setMinInt_("inclusion_charges", 1);
registerStringOption_("inclusion_strategy", "<name>", "ALL", "strategy to be used for selection", false);
setValidStrings_("inclusion_strategy", StringList::create("FeatureBased_LP,ProteinBased_LP,ALL"));
registerIntList_("exclusion_charges", "<charge>", IntList(), "List containing the charge states to be considered for the exclusion list compounds (for idXML and FASTA input), space separated.", false);
setMinInt_("exclusion_charges", 1);
registerInputFile_("raw_data", "<mzMLFile>", "", "File containing the raw data (only needed for FeatureBased_LP).", false);
setValidFormats_("raw_data", StringList::create("mzML"));
// setValidFormats_("out", StringList::create("traML"));
registerSubsection_("algorithm", "Inclusion/Exclusion algorithm section");
}
Param getSubsectionDefaults_(const String & /*section*/) const
{
// there is only one subsection: 'algorithm' (s.a) .. and in it belongs the InclusionExclusionList param
InclusionExclusionList fdc;
OfflinePrecursorIonSelection ops;
Param tmp;
tmp.insert("InclusionExclusionList:", fdc.getParameters());
tmp.insert("PrecursorSelection:", ops.getParameters());
return tmp;
}
ExitCodes main_(int, const char **)
{
//-------------------------------------------------------------
// parameter handling
//-------------------------------------------------------------
//input/output files
String include(getStringOption_("include"));
String exclude(getStringOption_("exclude"));
String out(getStringOption_("out"));
String strategy = getStringOption_("inclusion_strategy");
std::cout << "strategy " << strategy << std::endl;
String pt_model_file(getStringOption_("pt_model"));
if (include == "" && exclude == "")
{
writeLog_("Error: No input file given.");
return MISSING_PARAMETERS;
}
// currently we can handle only inclusion OR exclusion, will be possible with the traML output
if (include != "" && exclude != "")
{
writeLog_("Error: Currently only inclusion OR exclusion, both will be possible with the traML output coming soon");
return ILLEGAL_PARAMETERS;
}
IntList incl_charges(getIntList_("inclusion_charges"));
IntList excl_charges(getIntList_("exclusion_charges"));
String rt_model_file(getStringOption_("rt_model"));
//-------------------------------------------------------------
// loading input: inclusion list part
//-------------------------------------------------------------
FileHandler fh;
TargetedExperiment exp;
Param const & iel_param = getParam_().copy("algorithm:InclusionExclusionList:", true);
writeDebug_("Parameters passed to InclusionExclusionList", iel_param, 3);
InclusionExclusionList list;
list.setParameters(iel_param);
// std::cout << "\n\n\n\n" << iel_param.getValue("RT:unit") << "\n\n";
if (include != "")
{
FileTypes::Type in_type = fh.getType(include);
if (in_type == FileTypes::FEATUREXML)
{
// load feature map
FeatureMap<> map;
FeatureXMLFile().load(include, map);
if (!incl_charges.empty())
{
writeLog_("Warning: 'inclusion_charges' parameter is not honored for featureXML input.");
return ILLEGAL_PARAMETERS;
}
if (strategy == "ALL")
{
// convert to targeted experiment
// for traML output
// list.loadTargets(map,incl_targets,exp);
// for tab-delimited output
try
{
list.writeTargets(map, out);
}
catch (Exception::UnableToCreateFile)
{
writeLog_("Error: Unable to create output file.");
return CANNOT_WRITE_OUTPUT_FILE;
}
}
else if (strategy == "FeatureBased_LP")
{
String raw_data_path = getStringOption_("raw_data");
MSExperiment<> exp, ms2;
FeatureMap<> out_map;
MzMLFile().load(raw_data_path, exp);
IntList levels;
levels << 1;
exp.getSpectra().erase(remove_if(exp.begin(), exp.end(),
InMSLevelRange<MSSpectrum<> >(levels, true)), exp.end());
exp.sortSpectra(true);
OfflinePrecursorIonSelection opis;
Param param = getParam_().copy("algorithm:PrecursorSelection:", true);
UInt spot_cap = param.getValue("ms2_spectra_per_rt_bin");
std::cout << "spot_cap " << spot_cap << std::endl;
opis.setParameters(param);
std::set<Int> charges_set;
charges_set.insert(0);
// create ILP
PSLPFormulation ilp_wrapper;
// get the mass ranges for each features for each scan it occurs in
std::vector<std::vector<std::pair<Size, Size> > > indices;
opis.getMassRanges(map, exp, indices);
std::vector<PSLPFormulation::IndexTriple> variable_indices;
std::vector<int> solution_indices;
ilp_wrapper.createAndSolveILPForKnownLCMSMapFeatureBased(map, exp, variable_indices, indices, charges_set, spot_cap, solution_indices);
sort(variable_indices.begin(), variable_indices.end(), PSLPFormulation::IndexLess());
#ifdef DEBUG_OPS
std::cout << "best_solution " << std::endl;
#endif
std::vector<Int> rt_sizes(exp.size(), 0);
// print best solution
// create inclusion list
for (Size i = 0; i < solution_indices.size(); ++i)
{
Size feature_index = variable_indices[solution_indices[i]].feature;
Size scan = variable_indices[solution_indices[i]].scan;
out_map.push_back(map[feature_index]);
std::cout << map[feature_index].getMetaValue("msms_score") << std::endl;
++rt_sizes[scan];
}
for (Size r = 0; r < rt_sizes.size(); ++r)
{
std::cout << r << "\t" << rt_sizes[r] << "\n";
}
try
{
if (out.hasSuffix("featureXML"))
{
FeatureXMLFile().store(out, out_map);
}
else list.writeTargets(out_map, out);
}
catch (Exception::UnableToCreateFile)
{
writeLog_("Error: Unable to create output file.");
return CANNOT_WRITE_OUTPUT_FILE;
}
} //else if(strategy == "ILP") // ILP
else
{
writeLog_("Warning: 'ProteinBased_LP' inclusion strategy is not valid for featureXML input.");
return ILLEGAL_PARAMETERS;
}
}
else // FASTA format
{
if (!File::exists(rt_model_file))
{
writeLog_("Error: RT model file required for FASTA input to predict RT elution time.");
return MISSING_PARAMETERS;
}
if (incl_charges.empty())
{
writeLog_("Error: Protein sequences for inclusion given, but no charge states specified.");
return MISSING_PARAMETERS;
}
if (strategy == "ProteinBased_LP")
{
OfflinePrecursorIonSelection opis;
Param param = getParam_().copy("algorithm:PrecursorSelection:", true);
opis.setParameters(param);
FeatureMap<> precursors;
opis.createProteinSequenceBasedLPInclusionList(include, rt_model_file, pt_model_file, precursors);
if (out.hasSuffix("featureXML"))
{
FeatureXMLFile().store(out, precursors);
}
else list.writeTargets(precursors, out);
}
else
{
std::vector<FASTAFile::FASTAEntry> entries;
// load fasta-file
FASTAFile().load(include, entries);
// convert to targeted experiment
// if traML output
//list.loadTargets(entries,incl_targets,exp,missed_cleavages);
// if tab-delimited output
try
{
list.writeTargets(entries, out, incl_charges, rt_model_file);
}
catch (Exception::UnableToCreateFile)
{
writeLog_("Error: Unable to create output file.");
return CANNOT_WRITE_OUTPUT_FILE;
}
}
}
// exp.setIncludeTargets(incl_targets);
}
//-------------------------------------------------------------
// loading input: exclusion list part
//-------------------------------------------------------------
if (exclude != "")
{
FileTypes::Type ex_type = fh.getType(exclude);
// std::vector<IncludeExcludeTarget> excl_targets;
if (ex_type == FileTypes::FEATUREXML)
{
if (!excl_charges.empty())
{
writeLog_("Warning: 'exclusion_charges' parameter is not honored for featureXML input.");
return ILLEGAL_PARAMETERS;
}
// load feature map
FeatureMap<> map;
FeatureXMLFile().load(exclude, map);
// convert to targeted experiment if traML output is selected
// list.loadTargets(map,excl_targets,exp);
// else write tab-delimited file directly
try
{
list.writeTargets(map, out);
}
catch (Exception::UnableToCreateFile)
{
writeLog_("Error: Unable to create output file.");
return CANNOT_WRITE_OUTPUT_FILE;
}
}
else if (ex_type == FileTypes::IDXML)
{
std::vector<PeptideIdentification> pep_ids;
std::vector<ProteinIdentification> prot_ids;
IdXMLFile().load(exclude, prot_ids, pep_ids);
try
{
list.writeTargets(pep_ids, out, excl_charges);
}
catch (Exception::UnableToCreateFile)
{
writeLog_("Error: Unable to create output file.");
return CANNOT_WRITE_OUTPUT_FILE;
}
catch (Exception::InvalidSize)
{
writeLog_("Error: Peptide identification contains several hits. Use IDFilter to filter for significant peptide hits.");
return ILLEGAL_PARAMETERS;
}
catch (Exception::MissingInformation)
{
writeLog_("Error: Peptide identification contains no RT information.");
return ILLEGAL_PARAMETERS;
}
}
else // FASTA format ...
{
if (!File::exists(rt_model_file))
{
writeLog_("Error: RT model file required for FASTA input to predict RT elution time.");
return MISSING_PARAMETERS;
}
if (excl_charges.empty())
{
writeLog_("Error: Protein sequences for exclusion given, but no charge states specified.");
return MISSING_PARAMETERS;
}
std::vector<FASTAFile::FASTAEntry> entries;
// load fasta-file
FASTAFile().load(exclude, entries);
// convert to targeted experiment for traML output
// list.loadTargets(entries,excl_targets,exp,missed_cleavages);
// else for tab-delimited output
try
{
list.writeTargets(entries, out, excl_charges, rt_model_file);
}
catch (Exception::UnableToCreateFile)
{
writeLog_("Error: Unable to create output file.");
return CANNOT_WRITE_OUTPUT_FILE;
}
}
// exp.setExcludeTargets(excl_targets);
}
//-------------------------------------------------------------
// writing output
//-------------------------------------------------------------
//TraMLFile().store(out, exp);
return EXECUTION_OK;
}
};
int main(int argc, const char ** argv)
{
TOPPInclusionExclusionListCreator tool;
return tool.main(argc, argv);
}
/// @endcond
|