Skip to content

Commit

Permalink
Code Arrangement Changes #7 (#5471)
Browse files Browse the repository at this point in the history
* Code Arrangement Changes #7

* Update ClusterAnalyzer.cpp

Co-authored-by: Arraxx <kumaramanjha2901@gmail.com>
  • Loading branch information
Arraxx and Arraxx committed Aug 3, 2021
1 parent c2555c3 commit b47dbde
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@
#include <OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSAlphabet.h>
#include <OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSAlphabetTextParser.h>

namespace OpenMS
namespace OpenMS::ims
{

namespace ims
{

const IMSAlphabet::name_type & IMSAlphabet::getName(size_type index) const
{
return getElement(index).getName();
Expand Down Expand Up @@ -174,5 +171,4 @@ namespace OpenMS
return os;
}

} // namespace ims
} // namespace OpenMS
} // namespace OpenMS // namespace ims
16 changes: 12 additions & 4 deletions src/openms/source/COMPARISON/SPECTRA/BinnedSpectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ namespace OpenMS
{
OPENMS_PRECONDITION(ps.isSorted(), "Spectrum needs to be sorted by m/z.");

if (ps.empty()) { return; }
if (ps.empty())
{
return;
}

bins_ = EmptySparseVector;

Expand Down Expand Up @@ -120,15 +123,20 @@ namespace OpenMS
}

// efficient look-up of number of non-zero entries, so we use this as-well
if (bins_.nonZeros() != rhs.bins_.nonZeros()) { return false; }
if (bins_.nonZeros() != rhs.bins_.nonZeros())
{
return false;
}

// test non-sparse (non-zero) elements for equality
SparseVectorIteratorType it(bins_);
SparseVectorIteratorType rhs_it(rhs.bins_);
while (it)
{
if (it.index() != rhs_it.index()
|| it.value() != rhs_it.value()) { return false; }
if (it.index() != rhs_it.index() || it.value() != rhs_it.value())
{
return false;
}
++it;
++rhs_it;
}
Expand Down
4 changes: 4 additions & 0 deletions src/openms/source/COMPARISON/SPECTRA/PeakAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ namespace OpenMS
// shortcut similarity calculation by comparing PrecursorPeaks (PrecursorPeaks more than delta away from each other are supposed to be from another peptide)
double pre_mz1 = 0.0;
if (!spec1.getPrecursors().empty())
{
pre_mz1 = spec1.getPrecursors()[0].getMZ();
}
double pre_mz2 = 0.0;
if (!spec2.getPrecursors().empty())
{
pre_mz2 = spec2.getPrecursors()[0].getMZ();
}
if (fabs(pre_mz1 - pre_mz2) > (double)param_.getValue("precursor_mass_tolerance"))
{
return 0;
Expand Down
11 changes: 8 additions & 3 deletions src/openms/source/COMPARISON/SPECTRA/SpectrumAlignmentScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ namespace OpenMS

// calculate sum of squared intensities
double sum1(0);
for (auto const & p : s1) { sum1 += pow(p.getIntensity(), 2); }
for (auto const & p : s1)
{
sum1 += pow(p.getIntensity(), 2);
}

double sum2(0);
for (auto const & p : s2) { sum2 += pow(p.getIntensity(), 2); }

for (auto const & p : s2)
{
sum2 += pow(p.getIntensity(), 2);
}
for (auto const & ap : alignment)
{
const double mz_tolerance = is_relative_tolerance ? tolerance * s1[ap.first].getMZ() * 1e-6 : tolerance;
Expand Down
14 changes: 14 additions & 0 deletions src/openms/source/COMPARISON/SPECTRA/SpectrumCheapDPCorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ namespace OpenMS
lastconsensus_ = PeakSpectrum();
Precursor p1, p2;
if (!x.getPrecursors().empty())
{
p1 = x.getPrecursors()[0];
}
if (!y.getPrecursors().empty())
{
p2 = y.getPrecursors()[0];
}
lastconsensus_.getPrecursors().resize(1);
lastconsensus_.getPrecursors()[0].setMZ((p1.getMZ() + p2.getMZ()) / 2);
lastconsensus_.getPrecursors()[0].setCharge(p1.getCharge());
Expand Down Expand Up @@ -174,9 +178,13 @@ namespace OpenMS
yrun++;
}
if (xit + xrun == x.end())
{
break;
}
if (yit + yrun == y.end())
{
break;
}
}

//dynamic programming necessary to calculate optimal pairing
Expand Down Expand Up @@ -292,7 +300,9 @@ namespace OpenMS
consensuspeak.setMZ(x[xstart + i - 1].getMZ());
consensuspeak.setIntensity((x[xstart + i - 1].getIntensity()) * (1 - factor_));
if (keeppeaks_)
{
lastconsensus_.push_back(consensuspeak);
}
i--;
}
else if (trace[i][j] == -1)
Expand All @@ -301,11 +311,15 @@ namespace OpenMS
consensuspeak.setMZ(y[ystart + j - 1].getMZ());
consensuspeak.setIntensity((y[ystart + j - 1].getIntensity()) * factor_);
if (keeppeaks_)
{
lastconsensus_.push_back(consensuspeak);
}
j--;
}
if (!i || !j)
{
break;
}
}

return dparray[xend - xstart + 1][yend - ystart + 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ namespace OpenMS

double mz1 = 0.0;
if (!x.getPrecursors().empty())
{
mz1 = x.getPrecursors()[0].getMZ();
}
double mz2 = 0.0;
if (!y.getPrecursors().empty())
{
mz2 = y.getPrecursors()[0].getMZ();
}

if (fabs(mz1 - mz2) > window)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ namespace OpenMS
std::cout << std::endl;
std::cout << s2 << std::endl;*/

for (PeakSpectrum::ConstIterator it1 = s1.begin(); it1 != s1.end(); ++it1)
for (const Peak1D& it1 : s1)
{
double temp = it1->getIntensity();
double temp = it1.getIntensity();
sum1 += temp * temp;
sum3 += temp;
}

for (PeakSpectrum::ConstIterator it1 = s2.begin(); it1 != s2.end(); ++it1)
for (const Peak1D& it1 : s2)
{
double temp = it1->getIntensity();
double temp = it1.getIntensity();
sum2 += temp * temp;
sum4 += temp;
}
Expand Down
8 changes: 4 additions & 4 deletions src/openms/source/COMPARISON/SPECTRA/ZhangSimilarityScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ namespace OpenMS
throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
}

for (PeakSpectrum::ConstIterator it1 = s1.begin(); it1 != s1.end(); ++it1)
for (const Peak1D& it1 : s1)
{
sum1 += it1->getIntensity();
sum1 += it1.getIntensity();
/*
for (PeakSpectrum::ConstIterator it2 = s1.begin(); it2 != s1.end(); ++it2)
{
Expand Down Expand Up @@ -158,9 +158,9 @@ for (PeakSpectrum::ConstIterator it2 = s1.begin(); it2 != s1.end(); ++it2)
}
}*/

for (PeakSpectrum::ConstIterator it1 = s2.begin(); it1 != s2.end(); ++it1)
for (const Peak1D& it1 : s2)
{
sum2 += it1->getIntensity();
sum2 += it1.getIntensity();
/*
for (PeakSpectrum::ConstIterator it2 = s2.begin(); it2 != s2.end(); ++it2)
{
Expand Down
20 changes: 4 additions & 16 deletions src/openms/source/CONCEPT/ClassTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@

#include <QFileInfo>

namespace OpenMS
namespace OpenMS::Internal::ClassTest
{
namespace Internal
{
namespace ClassTest
{

bool all_tests = true;
bool equal_files;
bool newline = false;
Expand Down Expand Up @@ -91,10 +88,6 @@ namespace OpenMS
std::vector<std::string> tmp_file_list;
std::vector<UInt> failed_lines_list;
StringList whitelist;
}

namespace ClassTest
{

void mainInit(const char* version, const char* class_name, int argc, const char* argv0)
{
Expand Down Expand Up @@ -443,8 +436,7 @@ namespace OpenMS
}
}

bool
isRealSimilar(long double number_1, long double number_2)
bool isRealSimilar(long double number_1, long double number_2)
{
// Note: The original version of the stuff below was copied from
// FuzzyStringComparator and then heavily modified for ClassTest.
Expand Down Expand Up @@ -571,8 +563,7 @@ namespace OpenMS
}
}

void
testStringEqual(const char* /*file*/, int line,
void testStringEqual(const char* /*file*/, int line,
const std::string& string_1,
const char* string_1_stringified,
const std::string& string_2,
Expand Down Expand Up @@ -684,7 +675,4 @@ namespace OpenMS

return result;
}

}
}
}
14 changes: 10 additions & 4 deletions src/openms/source/CONCEPT/FuzzyStringComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ namespace OpenMS
bool FuzzyStringComparator::compareLines_(std::string const& line_str_1, std::string const& line_str_2)
{
// in most cases, results will be identical. If not, do the expensive fuzzy compare
if (line_str_1 == line_str_2) return true;

if (line_str_1 == line_str_2)
{
return true;
}
for (StringList::const_iterator slit = whitelist_.begin();
slit != whitelist_.end(); ++slit)
{
Expand Down Expand Up @@ -350,8 +352,10 @@ namespace OpenMS
#ifdef DEBUG_FUZZY
std::cout << "cmp number: " << String(element_1_.number) << " : " << String(element_2_.number) << std::endl;
#endif
if (element_1_.number == element_2_.number) continue;

if (element_1_.number == element_2_.number)
{
continue;
}
// check if absolute difference is small
double absdiff = element_1_.number - element_2_.number;
if (absdiff < 0)
Expand Down Expand Up @@ -666,7 +670,9 @@ namespace OpenMS
wlcit != whitelist_cases_.end(); ++wlcit)
{
if (wlcit->first.size() > length)
{
length = wlcit->first.size();
}
}
for (std::map<String, UInt>::const_iterator wlcit = whitelist_cases_.begin();
wlcit != whitelist_cases_.end(); ++wlcit)
Expand Down
8 changes: 2 additions & 6 deletions src/openms/source/CONCEPT/GlobalExceptionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@

#define OPENMS_CORE_DUMP_ENVNAME "OPENMS_DUMP_CORE"

namespace OpenMS
namespace OpenMS::Exception
{

namespace Exception
{

GlobalExceptionHandler::GlobalExceptionHandler() throw()
{
std::set_terminate(terminate);
Expand Down Expand Up @@ -143,6 +140,5 @@ namespace OpenMS
GlobalExceptionHandler::line_() = line;
}

} // namespace Exception

} // namespace OpenMS
} // namespace OpenMS // namespace Exception
33 changes: 15 additions & 18 deletions src/openms/source/CONCEPT/Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,25 @@

#include <xercesc/util/PlatformUtils.hpp>

namespace OpenMS
namespace OpenMS::Internal
{
namespace Internal
{

// Initialize xerces
// see ticket #352 for more details
struct xerces_init
// Initialize xerces
// see ticket #352 for more details
struct xerces_init
{
xerces_init()
{
xerces_init()
{
xercesc::XMLPlatformUtils::Initialize();
}
xercesc::XMLPlatformUtils::Initialize();
}

~xerces_init()
{
xercesc::XMLPlatformUtils::Terminate();
}
~xerces_init()
{
xercesc::XMLPlatformUtils::Terminate();
}

};
const xerces_init xinit;
};
const xerces_init xinit;

}
}
} //OpenMS //Internal

0 comments on commit b47dbde

Please sign in to comment.