-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaxmzdatahandler.cpp
168 lines (155 loc) · 4.42 KB
/
saxmzdatahandler.cpp
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
/************************************************************
* SAXMzdataHandler.cpp
*
* Premiere version janvier 2005
* Patrick Lacasse
*
* 3/11/2005 (Brendan MacLean): Use eXpat SAX parser, and create SAXSpectraHandler
*
* November 2005
* Fredrik Levander
* A few changes to handle MzData 1.05.
*
* Updated to handle version 1.04 and 1.05. (Rob Craig)
*
*
* See http://psidev.sourceforge.net/ms/#mzdata for
* mzData schema information.
*
* Inspired by DtaSAX2Handler.cpp
* copyright : (C) 2002 by Pedrioli Patrick, ISB, Proteomics
* email : [email protected]
* Artistic License granted 3/11/2005
*******************************************************/
#include "stdafx.h"
#include "saxmzdatahandler.h"
SAXMzdataHandler::SAXMzdataHandler( vector<mspectrum>& _vS, mspectrumcondition& _sC, mscore& _m)
: SAXSpectraHandler(_vS, _sC, _m)
{
m_bInmzArrayBinary=false;
m_bInintenArrayBinary=false;
m_bInData=false;
m_bInMsLevel2=false;
}
SAXMzdataHandler::~SAXMzdataHandler()
{
}
void SAXMzdataHandler::startElement(const XML_Char *el, const XML_Char **attr)
{
// Let's see what element just started
// We use:
// spectrum for the id number
// acqInstrument for the msLevel
// cvParam for the polarity and the mz of the parent ion
// data for the values of the spectrum
if (isElement("spectrum", el))
{
m_scanNum = atoi(getAttrValue("id", attr));
m_tId = m_scanNum;
while(m_sId.find(m_tId) != m_sId.end()) {
m_tId++;
}
m_sId.insert(m_tId);
}
//mzdata v. 1.04 uses acqInstrument and mzdata v. 1.05 uses spectrumInstrument
else if (isElement("spectrumInstrument", el) || isElement("acqInstrument", el))
{
//first attribute is msLevel
if( (m_cidLevel = atoi(getAttrValue("msLevel", attr))) == 2 )
{
m_bInMsLevel2 = true;
reset(); // Clean up for the next scan
}
}
else if (isElement("cvParam", el))
{
const char* name = getAttrValue("name", attr);
const char* value = getAttrValue("value", attr);
if (!strcmp(name, "polarity")){
if(!strcmp(value, "+"))
m_precursorCharge = 0;
else{
m_precursorCharge = atoi(value);
if(m_precursorCharge == 0)
m_precursorCharge = 2;
}
}
else if (!strcmp(name, "mz") )
m_precursorMz = atof(value);
else if (!strcmp(name, "ChargeState")){
m_precursorCharge = atoi(value);
}
else if (!strcmp(name, "MassToChargeRatio") ){
m_precursorMz = atof(value);
}
else if (!strcmp(name, "Charge State")){
m_precursorCharge = atoi(value);
}
else if (!strcmp(name, "Mass To Charge Ratio") ){
m_precursorMz = atof(value);
}
}
else if (isElement("mzArrayBinary", el)){
m_bInmzArrayBinary = true;
startPeakListBinary(attr);
}
else if (isElement("intenArrayBinary", el)) {
m_bInintenArrayBinary = true;
startPeakListBinary(attr);
}
else if (isElement("data", el)) {
m_bInData = true;
m_peaksCount = atoi(getAttrValue("length", attr));
const char *cE = getAttrValue("endian", attr);
if(strlen(cE) > 0) {
m_bNetworkData = !strcmp("big", cE);
}
const char *cP = getAttrValue("precision", attr);
if(strlen(cP) > 0) {
m_bLowPrecision = !strcmp("64", cP);
}
}
}
void SAXMzdataHandler::startPeakListBinary(const XML_Char **attr)
{
if(strlen(getAttrValue("endian", attr)) > 0) {
m_bNetworkData = (strcmp("little", getAttrValue("endian", attr)) != 0);
}
if(strlen(getAttrValue("precision", attr)) > 0) {
m_bLowPrecision = (strcmp("64", getAttrValue("precision", attr)) != 0);
}
}
void SAXMzdataHandler::endElement(const XML_Char *el)
{
if(isElement("mzArrayBinary", el))
m_bInmzArrayBinary = false;
else if(isElement("intenArrayBinary", el))
m_bInintenArrayBinary = false;
else if(isElement("data", el))
{
processData();
m_bInData = false;
}
else if(isElement("spectrum", el) && m_bInMsLevel2)
{
pushSpectrum();
m_bInMsLevel2 = false;
}
}
void SAXMzdataHandler::characters(const XML_Char *s, int len)
{
if((m_bInmzArrayBinary || m_bInintenArrayBinary) && m_bInMsLevel2 && m_bInData)
{
m_strData.append(s, len);
}
}
void SAXMzdataHandler::processData()
{
if((m_bInmzArrayBinary || m_bInintenArrayBinary) && m_bInMsLevel2 && m_bInData)
{
pushPeaks(m_bInmzArrayBinary, m_bInintenArrayBinary);
}
m_strData.clear();
}