Skip to content

Commit e5fe561

Browse files
committed
Noticed instability in FI search results (entries with different xcorrs in consecutive runs); these went away with memset initialization of uiBinnedIonMasses instead of the sparse initialization previously performed. Also defined iArraySizeGlobal as that value was calculated many times previously.
1 parent 8ca5ca7 commit e5fe561

File tree

6 files changed

+52
-199
lines changed

6 files changed

+52
-199
lines changed

CometSearch/CometDataInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ struct StaticParams
702702
EnzymeInfo enzymeInformation;
703703
MassUtil massUtility;
704704
double dInverseBinWidth; // this is used in BIN() many times so use inverse binWidth to do multiply vs. divide
705+
int iArraySizeGlobal; // (int)((g_staticParams.options.dPeptideMassHigh + g_staticParams.tolerances.dInputTolerancePlus + 2.0) * g_staticParams.dInverseBinWidth)
705706
double dOneMinusBinOffset; // this is used in BIN() many times so calculate once
706707
IonInfo ionInformation;
707708
int iXcorrProcessingOffset;
@@ -744,6 +745,7 @@ struct StaticParams
744745
enzymeInformation = a.enzymeInformation;
745746
massUtility = a.massUtility;
746747
dInverseBinWidth = a.dInverseBinWidth;
748+
iArraySizeGlobal = a.iArraySizeGlobal;
747749
dOneMinusBinOffset = a.dOneMinusBinOffset;
748750
iXcorrProcessingOffset = a.iXcorrProcessingOffset;
749751
ionInformation = a.ionInformation;

CometSearch/CometPostAnalysis.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void CometPostAnalysis::CalculateDeltaCn(int iWhichQuery)
132132

133133
int iLastEntry = 0;
134134
for (int iWhichResult = 0; iWhichResult < iNumPrintLines; ++iWhichResult)
135-
if (pOutput[iWhichResult].fXcorr > 0.0000001)
135+
if (pOutput[iWhichResult].fXcorr > FLOAT_ZERO)
136136
iLastEntry = iWhichResult;
137137

138138
for (int iWhichResult = 0; iWhichResult < iNumPrintLines; ++iWhichResult)
@@ -169,7 +169,7 @@ void CometPostAnalysis::CalculateDeltaCn(int iWhichQuery)
169169
// calculate deltaCn only if sequences are less than 0.75 similar
170170
if (g_staticParams.options.bExplicitDeltaCn || ((double)(iMinLength - iDiffCt) / iMinLength) < 0.75)
171171
{
172-
if (pOutput[iWhichResult].fXcorr > 0.0000001 && pOutput[j].fXcorr > 0.0000001)
172+
if (pOutput[iWhichResult].fXcorr > FLOAT_ZERO && pOutput[j].fXcorr > FLOAT_ZERO)
173173
dDeltaCn = 1.0 - (pOutput[j].fXcorr / pOutput[iWhichResult].fXcorr);
174174
else if (pOutput[iWhichResult].fXcorr > 0.0 && pOutput[j].fXcorr < 0.0)
175175
dDeltaCn = 0.0;
@@ -193,7 +193,7 @@ void CometPostAnalysis::CalculateDeltaCn(int iWhichQuery)
193193

194194
if (g_staticParams.options.bExportAdditionalScoresPepXML)
195195
{
196-
if (pOutput[iWhichResult].fXcorr > 0.0000001 && pOutput[iLastEntry].fXcorr > 0.0000001)
196+
if (pOutput[iWhichResult].fXcorr > FLOAT_ZERO && pOutput[iLastEntry].fXcorr > FLOAT_ZERO)
197197
dLastDeltaCn = 1.0 - (pOutput[iLastEntry].fXcorr / pOutput[iWhichResult].fXcorr);
198198
else if (pOutput[iWhichResult].fXcorr > 0.0 && pOutput[iLastEntry].fXcorr < 0.0)
199199
dLastDeltaCn = 0.0;
@@ -337,10 +337,7 @@ void CometPostAnalysis::CalculateSP(Results *pOutput,
337337
{
338338
sort(pOutput[i].pWhichProtein.begin(), pOutput[i].pWhichProtein.end(), ProteinEntryCmp);
339339

340-
// Sadly this erase(unique()) code doesn't work; it leaves only first entry in vector
341-
// pOutput[i].pWhichProtein.erase(unique(pOutput[i].pWhichProtein.begin(), pOutput[i].pWhichProtein.end(), ProteinEntryCmp),
342-
// pOutput[i].pWhichProtein.end());
343-
340+
// erase duplicate proteins in the list
344341
comet_fileoffset_t lPrev = 0;
345342
for (std::vector<ProteinEntryStruct>::iterator it = pOutput[i].pWhichProtein.begin(); it != pOutput[i].pWhichProtein.end(); )
346343
{
@@ -372,7 +369,7 @@ void CometPostAnalysis::CalculateSP(Results *pOutput,
372369
}
373370
}
374371

375-
if (pOutput[i].iLenPeptide>0) // take care of possible edge case
372+
if (pOutput[i].iLenPeptide > 0 && pOutput[i].fXcorr > XCORR_CUTOFF) // take care of possible edge case
376373
{
377374
int ii;
378375
int ctCharge;
@@ -496,7 +493,7 @@ void CometPostAnalysis::CalculateSP(Results *pOutput,
496493
// Gets fragment ion mass.
497494
dFragmentIonMass = CometMassSpecUtils::GetFragmentIonMass(iWhichIonSeries, iii, ctCharge, pdAAforward, pdAAreverse);
498495

499-
if ( dFragmentIonMass > FLOAT_ZERO)
496+
if (dFragmentIonMass > FLOAT_ZERO)
500497
{
501498
int iFragmentIonMass = BIN(dFragmentIonMass);
502499
float fSpScore;

CometSearch/CometPreprocess.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,9 @@ bool CometPreprocess::Preprocess(struct Query *pScoring,
769769
}
770770

771771
// initialize these temporary arrays before re-using
772-
size_t iTmp= (size_t)((g_staticParams.options.dPeptideMassHigh + dCushion + 2.0) * g_staticParams.dInverseBinWidth)*sizeof(double);
773-
memset(pdTmpRawData, 0, iTmp);
774-
memset(pdTmpFastXcorrData, 0, iTmp);
775-
memset(pdTmpCorrelationData, 0, iTmp);
772+
memset(pdTmpRawData, 0, g_staticParams.iArraySizeGlobal * sizeof(double));
773+
memset(pdTmpFastXcorrData, 0, g_staticParams.iArraySizeGlobal * sizeof(double));
774+
memset(pdTmpCorrelationData, 0, g_staticParams.iArraySizeGlobal * sizeof(double));
776775

777776
// pdTmpRawData is a binned array holding raw data
778777
if (!LoadIons(pScoring, pdTmpRawData, mstSpectrum, &pPre))
@@ -1871,9 +1870,6 @@ bool CometPreprocess::AllocateMemory(int maxNumThreads)
18711870
dCushion = g_staticParams.tolerances.dInputTolerancePlus * g_staticParams.options.dPeptideMassHigh / 1E6;
18721871
}
18731872

1874-
//MH: Must be equal to largest possible array
1875-
int iArraySize = (int)((g_staticParams.options.dPeptideMassHigh + dCushion + 2.0) * g_staticParams.dInverseBinWidth);
1876-
18771873
//MH: Initally mark all arrays as available (i.e. false=not inuse).
18781874
pbMemoryPool = new bool[maxNumThreads];
18791875
for (i=0; i<maxNumThreads; ++i)
@@ -1887,12 +1883,12 @@ bool CometPreprocess::AllocateMemory(int maxNumThreads)
18871883
{
18881884
try
18891885
{
1890-
ppdTmpRawDataArr[i] = new double[iArraySize]();
1886+
ppdTmpRawDataArr[i] = new double[g_staticParams.iArraySizeGlobal]();
18911887
}
18921888
catch (std::bad_alloc& ba)
18931889
{
18941890
char szErrorMsg[256];
1895-
sprintf(szErrorMsg, " Error - new(pdTmpRawData[%d]). bad_alloc: %s.\n", iArraySize, ba.what());
1891+
sprintf(szErrorMsg, " Error - new(pdTmpRawData[%d]). bad_alloc: %s.\n", g_staticParams.iArraySizeGlobal, ba.what());
18961892
sprintf(szErrorMsg+strlen(szErrorMsg), "Comet ran out of memory. Look into \"spectrum_batch_size\"\n");
18971893
sprintf(szErrorMsg+strlen(szErrorMsg), "parameters to address mitigate memory use.\n");
18981894
string strErrorMsg(szErrorMsg);
@@ -1908,12 +1904,12 @@ bool CometPreprocess::AllocateMemory(int maxNumThreads)
19081904
{
19091905
try
19101906
{
1911-
ppdTmpFastXcorrDataArr[i] = new double[iArraySize]();
1907+
ppdTmpFastXcorrDataArr[i] = new double[g_staticParams.iArraySizeGlobal]();
19121908
}
19131909
catch (std::bad_alloc& ba)
19141910
{
19151911
char szErrorMsg[256];
1916-
sprintf(szErrorMsg, " Error - new(pdTmpFastXcorrData[%d]). bad_alloc: %s.\n", iArraySize, ba.what());
1912+
sprintf(szErrorMsg, " Error - new(pdTmpFastXcorrData[%d]). bad_alloc: %s.\n", g_staticParams.iArraySizeGlobal, ba.what());
19171913
sprintf(szErrorMsg+strlen(szErrorMsg), "Comet ran out of memory. Look into \"spectrum_batch_size\"\n");
19181914
sprintf(szErrorMsg+strlen(szErrorMsg), "parameters to address mitigate memory use.\n");
19191915
string strErrorMsg(szErrorMsg);
@@ -1929,12 +1925,12 @@ bool CometPreprocess::AllocateMemory(int maxNumThreads)
19291925
{
19301926
try
19311927
{
1932-
ppdTmpCorrelationDataArr[i] = new double[iArraySize]();
1928+
ppdTmpCorrelationDataArr[i] = new double[g_staticParams.iArraySizeGlobal]();
19331929
}
19341930
catch (std::bad_alloc& ba)
19351931
{
19361932
char szErrorMsg[256];
1937-
sprintf(szErrorMsg, " Error - new(pdTmpCorrelationData[%d]). bad_alloc: %s.\n", iArraySize, ba.what());
1933+
sprintf(szErrorMsg, " Error - new(pdTmpCorrelationData[%d]). bad_alloc: %s.\n", g_staticParams.iArraySizeGlobal, ba.what());
19381934
sprintf(szErrorMsg+strlen(szErrorMsg), "Comet ran out of memory. Look into \"spectrum_batch_size\"\n");
19391935
sprintf(szErrorMsg+strlen(szErrorMsg), "parameters to address mitigate memory use.\n");
19401936
string strErrorMsg(szErrorMsg);
@@ -2061,8 +2057,7 @@ bool CometPreprocess::PreprocessSingleSpectrum(int iPrecursorCharge,
20612057
double dIon=0,
20622058
dIntensity=0;
20632059

2064-
int iTmpArraySize = (int)((g_staticParams.options.dPeptideMassHigh + g_staticParams.tolerances.dInputTolerancePlus + 2.0) * g_staticParams.dInverseBinWidth);
2065-
memset(pdTmpSpectrum, 0, iTmpArraySize*sizeof(double));
2060+
memset(pdTmpSpectrum, 0, g_staticParams.iArraySizeGlobal * sizeof(double));
20662061

20672062
// set dIntensityCutoff based on either minimum intensity or % of base peak
20682063
double dIntensityCutoff = g_staticParams.options.dMinIntensity;
@@ -2103,7 +2098,7 @@ bool CometPreprocess::PreprocessSingleSpectrum(int iPrecursorCharge,
21032098

21042099
dIntensity = sqrt(dIntensity);
21052100

2106-
if (iBinIon < iTmpArraySize && pdTmpSpectrum[iBinIon] < dIntensity) // used in DoSingleSpectrumSearch to return matched ions
2101+
if (iBinIon < g_staticParams.iArraySizeGlobal && pdTmpSpectrum[iBinIon] < dIntensity) // used in DoSingleSpectrumSearch to return matched ions
21072102
pdTmpSpectrum[iBinIon] = dIntensity;
21082103

21092104
if (iBinIon > pPre.iHighestIon)

0 commit comments

Comments
 (0)