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
|
/* massXpert - the true massist's program.
--------------------------------------
Copyright(C) 2006,2007 Filippo Rusconi
http://www.massxpert.org/massXpert
This file is part of the massXpert project.
The massxpert project is the successor to the "GNU polyxmass"
project that is an official GNU project package(see
www.gnu.org). The massXpert project is not endorsed by the GNU
project, although it is released ---in its entirety--- under the
GNU General Public License. A huge part of the code in massXpert
is actually a C++ rewrite of code in GNU polyxmass. As such
massXpert was started at the Centre National de la Recherche
Scientifique(FRANCE), that granted me the formal authorization to
publish it under this Free Software License.
This software is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 3, as published by the Free Software Foundation.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software; if not, write to the
Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/////////////////////// Local includes
#include "cleaveMotif.hpp"
#include "polymer.hpp"
namespace massXpert
{
//! Constructs a cleavage motif.
/*!
\param polChemDef Polymer chemistry definition. Cannot be 0.
\param name Name. Cannot be empty.
\param str Motif in the form of "Lys/;Arg/;-Lys/Pro".
\param offset Offset of the cleavage.
\param isForCleave Tells if motif is for cleavage.
*/
CleaveMotif::CleaveMotif(const PolChemDef *polChemDef,
QString name, const QString &str,
int offset, bool isForCleave)
: PolChemDefEntity(polChemDef, name),
m_motif(str), m_offset(offset), m_isForCleave(isForCleave)
{
}
//! Constructs a copy of \p other.
/*!
\param other cleavage motif to be used as a mold.
*/
CleaveMotif::CleaveMotif(const CleaveMotif &other)
: PolChemDefEntity(other),
m_motif(other.m_motif), m_codeList(other.m_codeList),
m_offset(other.m_offset), m_isForCleave(other.m_isForCleave)
{
}
//! Destroys the cleavage motif.
CleaveMotif::~CleaveMotif()
{
}
//! Modifies \p other to be identical to \p this.
/*! \param other cleavage motif.
*/
void
CleaveMotif::clone(CleaveMotif *other) const
{
Q_ASSERT(other);
PolChemDefEntity::clone(other);
other->m_motif = m_motif;
other->m_codeList.clear();
other->m_codeList = m_codeList;
other->m_offset = m_offset;
other->m_isForCleave = m_isForCleave;
}
//! Modifies \p this to be identical to \p other.
/*! \param other cleavage motif to be used as a mold.
*/
void
CleaveMotif::mold(const CleaveMotif &other)
{
if (&other == this)
return;
PolChemDefEntity::mold(other);
m_motif = other.m_motif;
m_codeList = other.m_codeList;
m_offset = other.m_offset;
m_isForCleave = other.m_isForCleave;
}
//! Assigns other to \p this cleavage motif.
/*! \param other cleavage motif used as the mold to set values to \p
this instance.
\return a reference to \p this cleavage motif.
*/
CleaveMotif &
CleaveMotif::operator =(const CleaveMotif &other)
{
if (&other != this)
mold(other);
return *this;
}
//! Sets the motif.
/*! \param str new motif.
*/
void
CleaveMotif::setMotif(const QString &str)
{
m_motif = str;
}
//! Returns the motif.
/*!
\return the motif.
*/
const QString &
CleaveMotif::motif()
{
return m_motif;
}
//! Returns the string list of codes in the motif.
/*!
\return the string list of codes in the motif.
*/
const QStringList &
CleaveMotif::codeList() const
{
return m_codeList;
}
//! Sets the offset.
/*! \param value new offset.
*/
void
CleaveMotif::setOffset(int value)
{
m_offset = value;
}
//! Returns the offset.
/*!
\return the offset.
*/
int
CleaveMotif::offset()
{
return m_offset;
}
//! Sets if motif is for cleavage.
/*! \param value if motif is for cleavage.
*/
void
CleaveMotif::setForCleave(bool value)
{
m_isForCleave = value;
}
//! Returns if motif is for cleavage.
/*! \return if motif is for cleavage.
*/
bool
CleaveMotif::isForCleave()
{
return m_isForCleave;
}
//! Parses a cleavage site.
/*! Upon parsing of a cleavage site, this cleavage motif is filled
with data.
\param site Cleavage site in the form "Lys/Pro" or "KKGK/RRGK".
\return the number of monomer codes in the motif, -1 upon error.
*/
int
CleaveMotif::parse(const QString &site)
{
const QList<Monomer *> &refList = mp_polChemDef->monomerList();
QString code;
QString error;
QString local = site;
int index = 0;
int count = 0;
// We get something like "Lys/Pro" or something like "KKGK/RRGK" and
// we have to make three things:
//
// 1. change the site "KKGK/RRGK" to a motif string(KKGKRRGK).
//
// 2. set the offset member to the index of '/' in the initial site
// string.
//
// 3. make an array of codes with the motif.
Sequence sequence(local);
while(1)
{
code.clear();
if(sequence.nextCode(&code, &index, &error,
mp_polChemDef->codeLength()) == -1)
{
if (error == "/")
{
m_offset = count;
// qDebug() << __FILE__ << __LINE__
// << "Found / at code position" << m_offset;
// Increment index so that we iterate in the next code
// at next round.
++index;
continue;
}
// There was an error parsing the site sequence. If the err
// string contains a space, that is not serious, we could
// skip that.
qDebug() << __FILE__ << __LINE__
<< "Failed to parse cleavage site"
<< site.toAscii();
return -1;
}
// There might have been no error, but that does not means that
// we necessarily got a code.
if(code.isEmpty())
{
// We arrived at the end of a code parsing step(either
// because the current 'local' cleavage site(that is
// 'sequence') was finished parsing or because we finished
// parsing one of its monomer codes.
break;
}
// At this point we actually had a code.
// qDebug() << __FILE__ << __LINE__
// << "Got next code:" << code.toAscii();
// At this point, 'code' contains something that looks like a
// valid code, but we still have to make sure that this code
// actually is in our list of monomer codes...
if(Monomer::isCodeInList(code, refList) == -1)
{
qDebug() << __FILE__ << __LINE__
<< "Monomer code" << code
<< " is not in the monomer list.";
return -1;
}
// At the end m_motif will contain KKGKRRGK, while site was
// "KKGK/RRGK" KKGKRRGK
m_motif += code;
// Add the newly parsed code to the code list.
m_codeList << code;
++count;
// Increment index so that we iterate in the next code at next
// round.
++index;
}
// Return the number of successfully parsed monomer codes for the
// 'site' string.
Q_ASSERT(count == m_codeList.size());
return count;
}
bool
CleaveMotif::validate()
{
Q_ASSERT(0);
return true;
}
} // namespace massXpert
|