OpenMS  3.0.0
MsInspectFile.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2022.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/KERNEL/Feature.h>
40 #include <OpenMS/FORMAT/TextFile.h>
41 
42 #include <fstream>
43 #include <vector>
44 
45 namespace OpenMS
46 {
59  class OPENMS_DLLAPI MsInspectFile
60  {
61 public:
63  MsInspectFile();
65  virtual ~MsInspectFile();
66 
75  template <typename FeatureMapType>
76  void load(const String& filename, FeatureMapType& feature_map)
77  {
78  // load input
79  TextFile input(filename);
80 
81  // reset map
82  FeatureMapType fmap;
83  feature_map = fmap;
84 
85  bool first_line = true;
86  for (TextFile::ConstIterator it = input.begin(); it != input.end(); ++it)
87  {
88  String line = *it;
89 
90  //ignore comment lines
91  if (line.empty() || line[0] == '#') continue;
92 
93  //skip leader line
94  if (first_line)
95  {
96  first_line = false;
97  continue;
98  }
99 
100  //split lines: scan\ttime\tmz\taccurateMZ\tmass\tintensity\tcharge\tchargeStates\tkl\tbackground\tmedian\tpeaks\tscanFirst\tscanLast\tscanCount\ttotalIntensity\tsumSquaresDist\tdescription
101  std::vector<String> parts;
102  line.split('\t', parts);
103 
104  if (parts.size() < 18)
105  {
106  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", String("Failed to convert line ") + String((it - input.begin()) + 1) + ". Not enough columns (expected 18 or more, got " + String(parts.size()) + ")");
107  }
108 
109  //create feature
110  Feature f;
111  Size column_to_convert = 0;
112  try
113  {
114  column_to_convert = 1;
115  f.setRT(parts[1].toDouble());
116  column_to_convert = 2;
117  f.setMZ(parts[2].toDouble());
118  column_to_convert = 5;
119  f.setIntensity(parts[5].toDouble());
120  column_to_convert = 6;
121  f.setCharge(parts[6].toInt());
122  column_to_convert = 8;
123  f.setOverallQuality(parts[8].toDouble());
124 
125  column_to_convert = 3;
126  f.setMetaValue("accurateMZ", parts[3]);
127  column_to_convert = 4;
128  f.setMetaValue("mass", parts[4].toDouble());
129  column_to_convert = 7;
130  f.setMetaValue("chargeStates", parts[7].toInt());
131  column_to_convert = 9;
132  f.setMetaValue("background", parts[9].toDouble());
133  column_to_convert = 10;
134  f.setMetaValue("median", parts[10].toDouble());
135  column_to_convert = 11;
136  f.setMetaValue("peaks", parts[11].toInt());
137  column_to_convert = 12;
138  f.setMetaValue("scanFirst", parts[12].toInt());
139  column_to_convert = 13;
140  f.setMetaValue("scanLast", parts[13].toInt());
141  column_to_convert = 14;
142  f.setMetaValue("scanCount", parts[14].toInt());
143  column_to_convert = 15;
144  f.setMetaValue("totalIntensity", parts[15].toDouble());
145  column_to_convert = 16;
146  f.setMetaValue("sumSquaresDist", parts[16].toDouble());
147  }
148  catch ( Exception::BaseException& )
149  {
150  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", String("Failed to convert value in column ") + String(column_to_convert + 1) + " into a number (line '" + String((it - input.begin()) + 1) + ")");
151  }
152  f.setMetaValue("description", parts[17]);
153  feature_map.push_back(f);
154  }
155 
156  }
157 
165  template <typename SpectrumType>
166  void store(const String& filename, const SpectrumType& spectrum) const
167  {
168  std::cerr << "Store() for MsInspectFile not implemented. Filename was: " << filename << ", spec of size " << spectrum.size() << "\n";
169  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
170  }
171 
172  };
173 } // namespace OpenMS
174 
OpenMS::MsInspectFile
File adapter for MsInspect files.
Definition: MsInspectFile.h:59
DefaultParamHandler.h
OpenMS::File::rename
static bool rename(const String &from, const String &to, bool overwrite_existing=true, bool verbose=true)
Rename a file.
OpenMS::ProteinIdentification::SearchParameters::digestion_enzyme
Protease digestion_enzyme
The cleavage site information in details (from ProteaseDB)
Definition: ProteinIdentification.h:273
OpenMS::PeptideHit::getCharge
Int getCharge() const
returns the charge of the peptide
OpenMS::StringUtils::toInt
static Int toInt(const String &this_s)
Definition: StringUtils.h:206
OpenMS::TextFile::end
ConstIterator end() const
Gives access to the underlying text buffer.
FileHandler.h
TextFile.h
Size
OpenMS::IdXMLFile::store
void store(const String &filename, const std::vector< ProteinIdentification > &protein_ids, const std::vector< PeptideIdentification > &peptide_ids, const String &document_id="")
Stores the data in an idXML file.
OpenMS::ResidueModification
Representation of a modification on an amino acid residue.
Definition: ResidueModification.h:78
OpenMS::PeptideHit::getSequence
const AASequence & getSequence() const
returns the peptide sequence without trailing or following spaces
OpenMS::PeptideIdentification::insertHit
void insertHit(const PeptideHit &hit)
Appends a peptide hit.
OpenMS::DigestionEnzymeDB::getInstance
static InstanceType * getInstance()
this member function serves as a replacement of the constructor
Definition: DigestionEnzymeDB.h:69
OpenMS::PeptideIdentification::setIdentifier
void setIdentifier(const String &id)
sets the identifier which links this PI to its corresponding ProteinIdentification
OpenMS::StringUtils::toQString
static QString toQString(const String &this_s)
Definition: StringUtils.h:201
OpenMS::FileTypes::PEPXML
TPP pepXML file (.pepXML)
Definition: FileTypes.h:73
OpenMS::MetaInfoInterface::getMetaValue
const DataValue & getMetaValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
OpenMS::ProteinIdentification::setSearchEngineVersion
void setSearchEngineVersion(const String &search_engine_version)
Sets the search engine version.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:57
OpenMS::String
A more convenient string class.
Definition: String.h:58
JavaInfo.h
OpenMS::PeptideEvidence::setProteinAccession
void setProteinAccession(const String &s)
set the protein accession the peptide matches to. If not available set to empty string.
MzMLFile.h
OpenMS::ResidueModification::getId
const String & getId() const
returns the identifier of the modification
Int
Feature.h
OpenMS::PeptideIdentification::setRT
void setRT(double rt)
sets the RT of the MS2 spectrum where the identification occurred
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
SearchEngineBase.h
OpenMS::TextFile
This class provides some basic file handling methods for text files.
Definition: TextFile.h:46
OpenMS::PeakFileOptions::addMSLevel
void addMSLevel(int level)
adds a desired MS level for peaks to load
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
IdXMLFile.h
OpenMS::ProteinHit
Representation of a protein hit.
Definition: ProteinHit.h:58
OpenMS::ResidueModification::N_TERM
The modification can only be N-terminal on the peptide.
Definition: ResidueModification.h:101
OpenMS::ProteinIdentification::MONOISOTOPIC
Definition: ProteinIdentification.h:249
OpenMS::PeptideEvidence::setAABefore
void setAABefore(const char acid)
sets the amino acid single letter code before the sequence (preceding amino acid in the protein)....
OpenMS::AASequence::toString
String toString() const
returns the peptide as string with modifications embedded in brackets
OpenMS::File::remove
static bool remove(const String &file)
Removes a file (if it exists).
SpectrumMetaDataLookup.h
OpenMS::ResidueModification::PROTEIN_C_TERM
The modification can only be protein C-terminal (on a C-terminal peptide)
Definition: ResidueModification.h:102
OpenMS::ProteinIdentification
Representation of a protein identification run.
Definition: ProteinIdentification.h:70
OpenMS::Peak2D::setIntensity
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition: Peak2D.h:172
OpenMS::PeptideIdentification::getHits
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
OpenMS::DateTime::now
static DateTime now()
Returns the current date and time.
OPENMS_LOG_FATAL_ERROR
#define OPENMS_LOG_FATAL_ERROR
Macro to be used if fatal error are reported (processing stops)
Definition: LogStream.h:450
OpenMS::ModificationsDB::getInstance
static ModificationsDB * getInstance()
Returns a pointer to the modifications DB (singleton)
OpenMS::ProteinIdentification::SearchParameters::charges
String charges
The allowed charges for the search.
Definition: ProteinIdentification.h:264
OpenMS::ProteinHit::setAccession
void setAccession(const String &accession)
sets the accession of the protein
OpenMS::MsInspectFile::load
void load(const String &filename, FeatureMapType &feature_map)
Loads a MsInspect file into a featureXML.
Definition: MsInspectFile.h:76
OpenMS::MzIdentMLFile
File adapter for MzIdentML files.
Definition: MzIdentMLFile.h:67
OpenMS::File::exists
static bool exists(const String &file)
Method used to test if a file exists.
OpenMS::Peak2D::setRT
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:214
OpenMS::PeptideEvidence::N_TERMINAL_AA
static const char N_TERMINAL_AA
Definition: PeptideEvidence.h:60
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::PeptideHit::addPeptideEvidence
void addPeptideEvidence(const PeptideEvidence &peptide_evidence)
adds information on a peptide that is (potentially) identified by this PSM
Exception.h
OpenMS::ProteinIdentification::SearchParameters::variable_modifications
std::vector< String > variable_modifications
Allowed variable modifications.
Definition: ProteinIdentification.h:267
OpenMS::ProteinIdentification::SearchParameters::mass_type
PeakMassType mass_type
Mass type of the peaks.
Definition: ProteinIdentification.h:265
OpenMS::ResidueModification::getOrigin
char getOrigin() const
Returns the origin (i.e. modified amino acid)
ProteaseDB.h
OpenMS::PeptideIdentification::sort
void sort()
Sorts the hits by score.
OpenMS::ProteinIdentification::setPrimaryMSRunPath
void setPrimaryMSRunPath(const StringList &s, bool raw=false)
OpenMS::MetaInfoInterface::setMetaValue
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
OpenMS::ResidueModification::C_TERM
The modification can only be C-terminal on the peptide.
Definition: ResidueModification.h:100
OpenMS::ProteinIdentification::setScoreType
void setScoreType(const String &type)
Sets the protein score type.
OpenMS::ProteinIdentification::SearchParameters::db
String db
The used database.
Definition: ProteinIdentification.h:261
OpenMS::PeptideEvidence::UNKNOWN_AA
static const char UNKNOWN_AA
Definition: PeptideEvidence.h:57
QProcess
OpenMS::ResidueModification::PROTEIN_N_TERM
The modification can only be protein N-terminal (on a N-terminal peptide)
Definition: ResidueModification.h:103
ProteinIdentification.h
OpenMS::ResidueModification::getDiffMonoMass
double getDiffMonoMass() const
returns the diff monoisotopic mass, or 0.0 if not set
OpenMS::PeptideEvidence
Representation of a peptide evidence.
Definition: PeptideEvidence.h:50
OpenMS::PeptideIdentification::setHigherScoreBetter
void setHigherScoreBetter(bool value)
sets the peptide score orientation
OpenMS::Exception::BaseException
Exception base class.
Definition: Exception.h:89
OpenMS::String::split
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
OpenMS::Peak2D::setMZ
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:202
PepXMLFile.h
OpenMS::Feature::setOverallQuality
void setOverallQuality(QualityType q)
Set the overall quality.
ms
Definition: MSNumpress.h:78
OpenMS::String::toQString
QString toQString() const
Conversion to Qt QString.
CsvFile.h
OpenMS::Exception::NotImplemented
Not implemented exception.
Definition: Exception.h:428
OpenMS::ProteinIdentification::setSearchParameters
void setSearchParameters(const SearchParameters &search_parameters)
Sets the search parameters.
OpenMS::PeakFileOptions::setFillData
void setFillData(bool only)
sets whether to fill the actual data into the container (spectrum/chromatogram)
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::SearchEngineBase
Base class for Search Engine Adapters.
Definition: SearchEngineBase.h:54
OpenMS::ProteinIdentification::SearchParameters::fixed_modifications
std::vector< String > fixed_modifications
Used fixed modifications.
Definition: ProteinIdentification.h:266
OpenMS::MzIdentMLFile::load
void load(const String &filename, std::vector< ProteinIdentification > &poid, std::vector< PeptideIdentification > &peid)
Loads the identifications from a MzIdentML file.
ModificationsDB.h
OpenMS::CsvFile
This class handles csv files. Currently only loading is implemented.
Definition: CsvFile.h:49
OpenMS::JavaInfo::canRun
static bool canRun(const String &java_executable, bool verbose_on_error=true)
Determine if Java is installed and reachable.
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::ProteinIdentification::setSearchEngine
void setSearchEngine(const String &search_engine)
Sets the search engine type.
OpenMS::ProteinIdentification::SearchParameters::precursor_mass_tolerance
double precursor_mass_tolerance
Mass tolerance of precursor ions (Dalton or ppm)
Definition: ProteinIdentification.h:271
OpenMS::Constants::UserParam::ISOTOPE_ERROR
const std::string ISOTOPE_ERROR
Definition: Constants.h:327
OpenMS::TextFile::begin
ConstIterator begin() const
Gives access to the underlying text buffer.
OpenMS::StringUtils::toDouble
static double toDouble(const String &this_s)
Definition: StringUtils.h:216
OPENMS_LOG_ERROR
#define OPENMS_LOG_ERROR
Macro to be used if non-fatal error are reported (processing continues)
Definition: LogStream.h:455
OpenMS::File::TempDir
Class representing a temporary directory.
Definition: File.h:64
OpenMS::PeptideIdentification
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:63
OpenMS::Exception::ParseError
Parse Error exception.
Definition: Exception.h:622
OpenMS::ListUtils
Collection of utility functions for management of vectors.
Definition: ListUtils.h:77
OpenMS::String::substr
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::MetaInfoInterface::metaValueExists
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
OpenMS::PeptideHit::getScore
double getScore() const
returns the PSM score
OpenMS::PepXMLFile::load
void load(const String &filename, std::vector< ProteinIdentification > &proteins, std::vector< PeptideIdentification > &peptides, const String &experiment_name, const SpectrumMetaDataLookup &lookup)
Loads peptide sequences with modifications out of a PepXML file.
OpenMS::Exception::FileNotWritable
File not writable exception.
Definition: Exception.h:537
OpenMS::PeptideIndexing
Refreshes the protein references for all peptide hits in a vector of PeptideIdentifications and adds ...
Definition: PeptideIndexing.h:113
OpenMS::MSExperiment::getPrimaryMSRunPath
void getPrimaryMSRunPath(StringList &toFill) const
get the file path to the first MS run
OpenMS::PeptideEvidence::C_TERMINAL_AA
static const char C_TERMINAL_AA
Definition: PeptideEvidence.h:61
OpenMS::ModifiedPeptideGenerator::MapToResidueType::val
boost::container::flat_map< const ResidueModification *, const Residue * > val
Definition: ModifiedPeptideGenerator.h:58
OpenMS::StringUtils::number
static String number(double d, UInt n)
Definition: StringUtils.h:196
OpenMS::TOPPBase::ExitCodes
ExitCodes
Exit codes.
Definition: TOPPBase.h:152
PeptideIndexing.h
String.h
OpenMS::ModificationsDB::getAllSearchModifications
void getAllSearchModifications(std::vector< String > &modifications) const
Collects all modifications that can be used for identification searches.
OpenMS::ProteinIdentification::setDateTime
void setDateTime(const DateTime &date)
Sets the date of the protein identification run.
OpenMS::ModifiedPeptideGenerator::MapToResidueType
Definition: ModifiedPeptideGenerator.h:58
OpenMS::ProteinIdentification::SearchParameters::precursor_mass_tolerance_ppm
bool precursor_mass_tolerance_ppm
Mass tolerance unit of precursor ions (true: ppm, false: Dalton)
Definition: ProteinIdentification.h:272
OpenMS::AASequence
Representation of a peptide/protein sequence.
Definition: AASequence.h:111
ModifiedPeptideGenerator.h
OpenMS::PepXMLFile
Used to load and store PepXML files.
Definition: PepXMLFile.h:63
OpenMS::AASequence::fromString
static AASequence fromString(const String &s, bool permissive=true)
create AASequence object by parsing an OpenMS string
OpenMS::Exception::MissingInformation
Not all required information provided.
Definition: Exception.h:186
OpenMS::ResidueModification::getTermSpecificityName
String getTermSpecificityName(TermSpecificity term_spec=NUMBER_OF_TERM_SPECIFICITY) const
Returns the name of the terminal specificity.
OpenMS::StringUtils::substr
static String substr(const String &this_s, size_t pos, size_t n)
Definition: StringUtilsSimple.h:213
OpenMS::ModifiedPeptideGenerator::getModifications
static MapToResidueType getModifications(const StringList &modNames)
Retrieve modifications from strings.
OpenMS::ProteinIdentification::setIdentifier
void setIdentifier(const String &id)
Sets the identifier.
OpenMS::ProteinIdentification::setHits
void setHits(const std::vector< ProteinHit > &hits)
Sets the protein hits.
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
OpenMS::ProteinIdentification::SearchParameters
Search parameters of the DB search.
Definition: ProteinIdentification.h:258
OpenMS::PeptideIdentification::setMZ
void setMZ(double mz)
sets the MZ of the MS2 spectrum
OpenMS::TextFile::ConstIterator
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: TextFile.h:56
OpenMS::ProteinIdentification::SearchParameters::enzyme_term_specificity
EnzymaticDigestion::Specificity enzyme_term_specificity
The number of required cutting-rule matching termini during search (none=0, semi=1,...
Definition: ProteinIdentification.h:274
OpenMS::DefaultParamHandler::writeParametersToMetaValues
static void writeParametersToMetaValues(const Param &write_this, MetaInfoInterface &write_here, const String &key_prefix="")
Writes all parameters to meta values.
OpenMS::ModificationsDB::getModification
const ResidueModification * getModification(Size index) const
Returns the modification with the given index. note: out-of-bounds check is only performed in debug m...
OpenMS::DateTime
DateTime Class.
Definition: DateTime.h:58
File.h
OpenMS::PeptideEvidence::setAAAfter
void setAAAfter(const char acid)
sets the amino acid single letter code after the sequence (subsequent amino acid in the protein)....
MzIdentMLFile.h
OpenMS::BaseFeature::setCharge
void setCharge(const ChargeType &ch)
Set charge state.
OpenMS::MzMLFile::getOptions
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
OpenMS::MsInspectFile::store
void store(const String &filename, const SpectrumType &spectrum) const
Stores a featureXML as a MsInspect file.
Definition: MsInspectFile.h:166
TOPPBase.h
OpenMS::PeptideIdentification::setScoreType
void setScoreType(const String &type)
sets the peptide score type
OpenMS::IdXMLFile
Used to load and store idXML files.
Definition: IdXMLFile.h:68
OpenMS::SpectrumMetaDataLookup::addMissingRTsToPeptideIDs
static bool addMissingRTsToPeptideIDs(std::vector< PeptideIdentification > &peptides, const String &filename, bool stop_on_error=false)
Add missing retention time values to peptide identifications based on raw data.
OpenMS::PeptideHit::setScore
void setScore(double score)
sets the PSM score
OpenMS::FileHandler::swapExtension
static String swapExtension(const String &filename, const FileTypes::Type new_type)
Tries to find and remove a known file extension, and append the new one.
OpenMS::DateTime::getDate
void getDate(UInt &month, UInt &day, UInt &year) const
Fills the arguments with the date.
OpenMS::PeptideHit
Representation of a peptide hit.
Definition: PeptideHit.h:55