#include #include "Peaks_R.h" void __cdecl cPeaksMZ(long double* data, int* startMZ, int* endMZ, int* firstMZ, int* lastMZ, int* length, long double* span, int* ret) { long double MZStep = (*lastMZ - *firstMZ) / ((long double)(*length) - 1); int leftEdge, rightEdge, curSpan; long double curValue; for (int curPos = (int)( (long double)(*startMZ - *firstMZ) / MZStep ); curPos < (int)( (long double)(*endMZ - *firstMZ) / MZStep ); curPos++) { curValue = data[curPos]; curSpan = (int)( ( (long double)curPos + ((long double)*firstMZ / MZStep) ) * *span ); // Calculate the edges leftEdge = curPos - curSpan; if (leftEdge < 0) { leftEdge = 0; } rightEdge = curPos + curSpan; if (rightEdge >= *length) { rightEdge = *length - 1; } // Check if this position has a higher value than anything within the span ret[curPos] = 1; for (int compPos = leftEdge; compPos <= rightEdge; compPos++) { if (data[compPos] >= curValue) { if (compPos != curPos) {ret[curPos] = 0; compPos = *length;} } } } } void __cdecl cPeakAreaMZ(long double* data, int* startMZ, int* endMZ, int* firstMZ, int* lastMZ, int* length, long double* span, long double* ret) { long double MZStep = (*lastMZ - *firstMZ) / ((long double)(*length) - 1); long double negFactor, posFactor, sum, localSum; int left, right, sumPos; int curSpan, negSpan; for (int curPos = (int)( (long double)(*startMZ - *firstMZ) / MZStep ); curPos < (int)( (long double)(*endMZ - *firstMZ) / MZStep ); curPos++) { curSpan = (int)( ( (long double)curPos + ((long double)*firstMZ / MZStep) ) * *span ); negSpan = (int)((long double)curSpan * (long double)0.2); if (negSpan < 1) { negSpan = 1; } negFactor = -(long double)0.5 / (long double)negSpan; posFactor = 1 / (long double)(2 * curSpan + 1 - 2 * negSpan); left = curPos - curSpan; right = curPos + curSpan; sum = 0; // Only continue if the span does not fall of an edge if ( (left >= 0) && (right < *length) ) { // Sum the left negative lobe localSum = 0; for (sumPos = left; sumPos < left + negSpan; sumPos++) { localSum += data[sumPos]; } sum += (localSum * negFactor); // Sum the positive region localSum = 0; for (sumPos = left + negSpan; sumPos <= right - negSpan; sumPos++) { localSum += data[sumPos]; } sum += (localSum * posFactor); // Sum the right negative lobe localSum = 0; for (sumPos = right - negSpan + 1; sumPos <= right; sumPos++) { localSum += data[sumPos]; } sum += (localSum * negFactor); } ret[curPos] = sum; } }