OpenMS
Loading...
Searching...
No Matches
UniProtXMLHandler.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13
14#include <functional>
15#include <string>
16
17namespace OpenMS::Internal
18{
31 class OPENMS_DLLAPI UniProtXMLHandler :
32 public XMLHandler
33 {
34 public:
38 using EntryCallback = std::function<void(UniProtEntry&&)>;
39
42 enum class CaptureTarget
43 {
44 None,
45 Accession,
46 EntryName,
47 FullName,
48 PrimaryGene,
49 TaxName,
50 Sequence,
51 FeatureOriginal,
52 FeatureVariation
53 };
54
56 UniProtXMLHandler(const std::string& filename, EntryCallback callback);
57
60
61 void onStartElement(const char16_t* qname, const XMLAttributes& attrs) override;
62 void onEndElement(const char16_t* qname) override;
63 void onCharacters(const char16_t* chars, Size length) override;
64
65 private:
68
70 int depth_{0};
71
75 int entry_depth_{0};
76 int recommended_name_depth_{0};
77 int gene_depth_{0};
78 int organism_depth_{0};
79 int alt_products_depth_{0};
80 int feature_depth_{0};
81 int sequence_depth_{0};
82
85 bool full_name_captured_{false};
86
88 std::string char_buf_;
89
91 CaptureTarget capture_{CaptureTarget::None};
92
95
97 bool gene_name_is_primary_{false};
99 bool organism_name_is_scientific_{false};
100
105
108 static int parsePosition_(const std::string& attr);
109 };
110
111} // namespace OpenMS::Internal
SAX handler for UniProtKB XML <entry> documents.
Definition UniProtXMLHandler.h:33
void onStartElement(const char16_t *qname, const XMLAttributes &attrs) override
Parsing method for opening tags.
std::string char_buf_
Buffer for character data; appended-to in characters(), consumed in endElement().
Definition UniProtXMLHandler.h:88
~UniProtXMLHandler() override
Destructor.
UniProtXMLHandler(const std::string &filename, EntryCallback callback)
Build a handler that delivers each parsed UniProtEntry to callback.
void resetFeature_()
Clear all per-feature state so the next <feature> starts fresh.
std::function< void(UniProtEntry &&)> EntryCallback
Definition UniProtXMLHandler.h:38
static int parsePosition_(const std::string &attr)
CaptureTarget
Definition UniProtXMLHandler.h:43
EntryCallback callback_
Definition UniProtXMLHandler.h:66
void resetEntry_()
Clear all per-entry state so the next <entry> starts fresh.
UniProtEntry current_entry_
Definition UniProtXMLHandler.h:67
UniProtFeature current_feature_
Per-feature working state (used between startElement("feature") and endElement("feature")).
Definition UniProtXMLHandler.h:94
void onEndElement(const char16_t *qname) override
Parsing method for closing tags.
void onCharacters(const char16_t *chars, Size length) override
Parsing method for character data.
Xerces-free, lightweight view over the attribute list of an XML element.
Definition XMLAttributes.h:32
Base class for XML handlers.
Definition XMLHandler.h:42
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Namespace used to hide implementation details from users.
Definition BayesianProteinInferenceAlgorithm.h:26
A single <entry> from a UniProtKB XML file, in a parser-neutral form.
Definition UniProtXMLFile.h:48
A single <feature> element from a UniProtKB XML entry.
Definition UniProtXMLFile.h:28