OpenMS  3.0.0
TextFile.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: Marc Sturm, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
39 namespace OpenMS
40 {
46  class OPENMS_DLLAPI TextFile
47  {
48 
49 public:
53  typedef std::vector<String>::iterator Iterator;
56  typedef std::vector<String>::const_iterator ConstIterator;
58  typedef std::vector<String>::reverse_iterator ReverseIterator;
60  typedef std::vector<String>::const_reverse_iterator ConstReverseIterator;
62 
63 
65  TextFile();
66 
68  virtual ~TextFile();
69 
80  TextFile(const String& filename, bool trim_lines = false, Int first_n = -1, bool skip_empty_lines = false);
81 
92  void load(const String& filename, bool trim_lines = false, Int first_n = -1, bool skip_empty_lines = false);
93 
101  void store(const String& filename);
102 
104  template <typename StringType>
105  TextFile& operator<<(const StringType& string)
106  {
107  buffer_.push_back(static_cast<String>(string));
108  return *this;
109  }
110 
111  template <typename StringType>
112  void addLine(const StringType& line)
113  {
114  buffer_.push_back(static_cast<String>(line));
115  }
116 
123  static std::istream& getLine(std::istream& is, std::string& t);
124 
128  ConstIterator begin() const;
129 
130  Iterator begin();
134  ConstIterator end() const;
135 
136  Iterator end();
137 
138 protected:
140  std::vector<String> buffer_;
141  };
142 
143 } // namespace OpenMS
144 
OpenMS::ProteinIdentification::SearchParameters::digestion_enzyme
Protease digestion_enzyme
The cleavage site information in details (from ProteaseDB)
Definition: ProteinIdentification.h:273
OpenMS::FileTypes::IDXML
OpenMS identification format (.idXML)
Definition: FileTypes.h:64
OpenMS::PeptideHit::getCharge
Int getCharge() const
returns the charge of the peptide
ConsensusXMLFile.h
OpenMS::MetaInfoInterfaceUtils::findCommonMetaKeys
static T_Out findCommonMetaKeys(const typename T_In::const_iterator &it_start, const typename T_In::const_iterator &it_end, float min_frequency, typename Detail::MetaKeyGetter< typename T_In::value_type > getter=Detail::MetaKeyGetter< typename T_In::value_type >())
Find keys in a collection of MetaInfoInterface objects which reach a certain frequency threshold.
Definition: MetaInfoInterfaceUtils.h:92
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
FileHandler.h
OpenMS::TextFile::addLine
void addLine(const StringType &line)
Definition: TextFile.h:112
FileTypes.h
OpenMS::String::QuotingMethod
QuotingMethod
How to handle embedded quotes when quoting strings.
Definition: String.h:81
Size
OpenMS::PeptideIdentification::hasRT
bool hasRT() const
shortcut for isnan(getRT())
double
OpenMS::DateTime::toString
String toString(std::string format="yyyy-MM-ddThh:mm:ss") const
OpenMS::BaseFeature::getWidth
WidthType getWidth() const
Non-mutable access to the features width (full width at half max, FWHM)
OpenMS::PeptideHit::getSequence
const AASequence & getSequence() const
returns the peptide sequence without trailing or following spaces
OpenMS::SVOutStream::modifyStrings
bool modifyStrings(bool modify)
Switch modification of strings (quoting/replacing of separators) on/off.
OpenMS::TextFile::ConstReverseIterator
std::vector< String >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: TextFile.h:60
OpenMS::StringUtils::suffix
static String suffix(const String &this_s, size_t length)
Definition: StringUtilsSimple.h:156
OpenMS::FileHandler::getTypeByFileName
static FileTypes::Type getTypeByFileName(const String &filename)
Determines the file type from a file name.
OpenMS::FileTypes::MZML
MzML file (.mzML)
Definition: FileTypes.h:70
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::SearchParameters::missed_cleavages
UInt missed_cleavages
The number of allowed missed cleavages.
Definition: ProteinIdentification.h:268
OpenMS::String::NONE
Definition: String.h:81
OpenMS::FeatureHandle::getWidth
WidthType getWidth() const
Returns the width (FWHM)
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::ProteinIdentification::ProteinGroup::accessions
std::vector< String > accessions
Accessions of (indistinguishable) proteins that belong to the same group.
Definition: ProteinIdentification.h:134
OpenMS::BaseFeature
A basic LC-MS feature.
Definition: BaseFeature.h:58
Int
ConsensusMap.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::FileTypes::CONSENSUSXML
OpenMS consensus map format (.consensusXML)
Definition: FileTypes.h:65
OpenMS::TextFile
This class provides some basic file handling methods for text files.
Definition: TextFile.h:46
IdXMLFile.h
FeatureXMLFile.h
OpenMS::ProteinHit
Representation of a protein hit.
Definition: ProteinHit.h:58
OpenMS::ProteinHit::getCoverage
double getCoverage() const
returns the coverage (in percent) of the protein hit based upon matched peptides
OpenMS::ProteinIdentification::MONOISOTOPIC
Definition: ProteinIdentification.h:249
OpenMS::Peak2D::getIntensity
IntensityType getIntensity() const
Definition: Peak2D.h:166
OpenMS::String::DOUBLE
Definition: String.h:81
OpenMS::MSExperiment::const_iterator
Base::const_iterator const_iterator
Definition: MSExperiment.h:118
OpenMS::FileTypes::UNKNOWN
Unknown file extension.
Definition: FileTypes.h:58
OpenMS::TextFile::operator<<
TextFile & operator<<(const StringType &string)
Operator for appending entries with less code.
Definition: TextFile.h:105
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::Peak2D::CoordinateType
double CoordinateType
Coordinate type (of the position)
Definition: Peak2D.h:64
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::FeatureHandle::setCharge
void setCharge(ChargeType charge)
Sets the charge.
OpenMS::IdXMLFile::load
void load(const String &filename, std::vector< ProteinIdentification > &protein_ids, std::vector< PeptideIdentification > &peptide_ids)
Loads the identifications of an idXML file without identifier.
OpenMS::Exception::InvalidParameter
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:339
OpenMS::ListUtils::concatenate
static String concatenate(const std::vector< T > &container, const String &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition: ListUtils.h:209
OpenMS::ProteinIdentification::getIdentifier
const String & getIdentifier() const
Returns the identifier.
OpenMS::ProteinIdentification::SearchParameters::charges
String charges
The allowed charges for the search.
Definition: ProteinIdentification.h:264
OpenMS::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS::Peak2D::setRT
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:214
OpenMS::ProteinHit::getAccession
const String & getAccession() const
returns the accession of the protein
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::DateTime::get
void get(UInt &month, UInt &day, UInt &year, UInt &hour, UInt &minute, UInt &second) const
Fills the arguments with the date and the time.
OpenMS::SVOutStream::write
SVOutStream & write(const String &str)
Unformatted output (no quoting: useful for comments, but use only on a line of its own!...
OpenMS::StringUtils::remove
static String & remove(String &this_s, char what)
Definition: StringUtilsSimple.h:595
OpenMS::PeptideEvidence::UNKNOWN_POSITION
static const int UNKNOWN_POSITION
Definition: PeptideEvidence.h:53
OpenMS::ProteinIdentification::SearchParameters::variable_modifications
std::vector< String > variable_modifications
Allowed variable modifications.
Definition: ProteinIdentification.h:267
OpenMS::FileTypes::FEATUREXML
OpenMS feature file (.featureXML)
Definition: FileTypes.h:63
OpenMS::ProteinIdentification::SearchParameters::mass_type
PeakMassType mass_type
Mass type of the peaks.
Definition: ProteinIdentification.h:265
OpenMS::MSExperiment::getChromatograms
const std::vector< MSChromatogram > & getChromatograms() const
returns the chromatogram list
OpenMS::MetaInfoInterface::metaRegistry
static MetaInfoRegistry & metaRegistry()
Returns a reference to the MetaInfoRegistry.
OpenMS::SVOutStream
Stream class for writing to comma/tab/...-separated values files.
Definition: SVOutStream.h:56
OpenMS::ProteinIdentification::getSearchEngineVersion
const String & getSearchEngineVersion() const
Returns the search engine version.
OpenMS::ProteinIdentification::SearchParameters::db
String db
The used database.
Definition: ProteinIdentification.h:261
OpenMS::ProteinIdentification::getHits
const std::vector< ProteinHit > & getHits() const
Returns the protein hits.
OpenMS::FileHandler
Facilitates file handling by file type recognition.
Definition: FileHandler.h:66
OpenMS::PeptideEvidence::UNKNOWN_AA
static const char UNKNOWN_AA
Definition: PeptideEvidence.h:57
OpenMS::PeptideHit::getRank
UInt getRank() const
returns the PSM rank
OpenMS::FileHandler::loadExperiment
bool loadExperiment(const String &filename, MSExperiment &exp, FileTypes::Type force_type=FileTypes::UNKNOWN, ProgressLogger::LogType log=ProgressLogger::NONE, const bool rewrite_source_file=true, const bool compute_hash=true)
Loads a file into an MSExperiment.
OpenMS::FeatureXMLFile::load
void load(const String &filename, FeatureMap &feature_map)
loads the file with name filename into map and calls updateRanges().
FeatureMap.h
OpenMS::FileTypes::CSV
general comma separated files format (might also be tab or space separated!!!), data should be regula...
Definition: FileTypes.h:93
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:56
OpenMS::Exception::UnableToCreateFile
Unable to create file exception.
Definition: Exception.h:636
MathFunctions.h
OpenMS::BaseFeature::getCharge
const ChargeType & getCharge() const
Non-mutable access to charge state.
OpenMS::ProteinHit::getSequence
const String & getSequence() const
returns the protein sequence
OpenMS::ConsensusFeature
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:69
OpenMS::FileHandler::getType
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
OpenMS::PeptideIdentification::hasMZ
bool hasMZ() const
shortcut for isnan(getRT())
OpenMS::FeatureHandle::setWidth
void setWidth(WidthType width)
Sets the width (FWHM)
OpenMS::ProteinIdentification::SearchParameters::db_version
String db_version
The database version.
Definition: ProteinIdentification.h:262
OpenMS::Peak2D::setMZ
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:202
OpenMS::ConsensusFeature::const_iterator
HandleSetType::const_iterator const_iterator
Definition: ConsensusFeature.h:76
OpenMS::nl
Definition: SVOutStream.h:47
OpenMS::TextFile::Iterator
std::vector< String >::iterator Iterator
Mutable iterator.
Definition: TextFile.h:54
OpenMS::ChromatogramSettings::SELECTED_REACTION_MONITORING_CHROMATOGRAM
Definition: ChromatogramSettings.h:74
OpenMS::TextFile::ReverseIterator
std::vector< String >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: TextFile.h:58
OpenMS::PeptideIdentification::getScoreType
const String & getScoreType() const
returns the peptide score type
OpenMS::ProteinIdentification::SearchParameters::fragment_mass_tolerance
double fragment_mass_tolerance
Mass tolerance of fragment ions (Dalton or ppm)
Definition: ProteinIdentification.h:269
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:82
OpenMS::FeatureMap::getUnassignedPeptideIdentifications
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::Peak2D::getRT
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:208
OpenMS::ConsensusXMLFile::load
void load(const String &filename, ConsensusMap &map)
Loads a consensus map from file and calls updateRanges.
MetaInfoInterfaceUtils.h
Iterator
OpenMS::ProteinIdentification::getSearchParameters
const SearchParameters & getSearchParameters() const
Returns the search parameters.
OpenMS::ProteinIdentification::SearchParameters::fixed_modifications
std::vector< String > fixed_modifications
Used fixed modifications.
Definition: ProteinIdentification.h:266
OpenMS::String::ESCAPE
Definition: String.h:81
SVOutStream.h
OpenMS::SVOutStream::writeValueOrNan
SVOutStream & writeValueOrNan(NumericT thing)
Write a numeric value or "nan"/"inf"/"-inf", if applicable (would not be needed for Linux)
Definition: SVOutStream.h:173
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::ProteinIdentification::SearchParameters::precursor_mass_tolerance
double precursor_mass_tolerance
Mass tolerance of precursor ions (Dalton or ppm)
Definition: ProteinIdentification.h:271
OpenMS::PeptideHit::getPeptideEvidences
const std::vector< PeptideEvidence > & getPeptideEvidences() const
returns information on peptides (potentially) identified by this PSM
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::PeptideIdentification
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:63
OpenMS::PeptideIdentification::getMZ
double getMZ() const
returns the MZ of the MS2 spectrum
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::FeatureHandle
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:57
OpenMS::MetaInfoInterface::metaValueExists
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
OpenMS::MSExperiment::getSpectra
const std::vector< MSSpectrum > & getSpectra() const
returns the spectrum list
OpenMS::PeptideHit::getScore
double getScore() const
returns the PSM score
OpenMS::ProteinHit::getDescription
String getDescription() const
returns the description of the protein
OpenMS::FeatureXMLFile
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:62
float
OpenMS::FileTypes::nameToType
static Type nameToType(const String &name)
OpenMS::ProteinIdentification::getScoreType
const String & getScoreType() const
Returns the protein score type.
OpenMS::ProgressLogger::NONE
No progress logging.
Definition: ProgressLogger.h:72
OpenMS::PeptideIdentification::getIdentifier
const String & getIdentifier() const
Returns the identifier which links this PI to its corresponding ProteinIdentification.
OpenMS::Peak2D::getMZ
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:196
OpenMS::ProteinIdentification::isHigherScoreBetter
bool isHigherScoreBetter() const
Returns true if a higher score represents a better score.
OpenMS::ProteinHit::getScore
double getScore() const
returns the score of the protein hit
OpenMS::ProteinIdentification::ProteinGroup::probability
double probability
Probability of this group.
Definition: ProteinIdentification.h:131
OpenMS::MSChromatogram::ConstIterator
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSChromatogram.h:93
OpenMS::TextFile::buffer_
std::vector< String > buffer_
Internal buffer storing the lines before writing them to the file.
Definition: TextFile.h:140
OpenMS::ProteinIdentification::SearchParameters
Search parameters of the DB search.
Definition: ProteinIdentification.h:258
OpenMS::TextFile::ConstIterator
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: TextFile.h:56
OpenMS::ProteinIdentification::SearchParameters::taxonomy
String taxonomy
The taxonomy restriction.
Definition: ProteinIdentification.h:263
OpenMS::FeatureHandle::getCharge
ChargeType getCharge() const
Returns the charge.
OpenMS::ProteinHit::getRank
UInt getRank() const
returns the rank of the protein hit
OpenMS::ProteinIdentification::getDateTime
const DateTime & getDateTime() const
Returns the date of the protein identification run.
OpenMS::Internal::ClassTest::infile
std::ifstream infile
Questionable file tested by TEST_FILE_EQUAL.
OpenMS::BaseFeature::getQuality
QualityType getQuality() const
TOPPBase.h
OpenMS::DigestionEnzyme::getName
const String & getName() const
returns the name of the enzyme
OpenMS::ConsensusXMLFile
This class provides Input functionality for ConsensusMaps and Output functionality for alignments and...
Definition: ConsensusXMLFile.h:58
OpenMS::IdXMLFile
Used to load and store idXML files.
Definition: IdXMLFile.h:68
OpenMS::FileTypes::typeToName
static String typeToName(Type type)
Returns the name/extension of the type.
OpenMS::PeptideIdentification::getRT
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred
OpenMS::ProteinIdentification::ProteinGroup
Bundles multiple (e.g. indistinguishable) proteins in a group.
Definition: ProteinIdentification.h:117
OpenMS::PeptideHit
Representation of a peptide hit.
Definition: PeptideHit.h:55
StringListUtils.h