33 #define ASSERT(f) {assert(f);} 49 if(!omp_get_thread_num())
60 const RangeFile &rangeFile,
float binStep, std::ostream &strm )
62 strm <<
"Per-Species Autocorrelation function:" << endl;
64 for(
unsigned int uj=0;uj<rangeFile.
getNumIons();uj++)
65 strm << rangeFile.
getName(uj) <<
"\t" ;
68 if(!autoCorrelateFunc.size())
73 for(
unsigned int ui=0;ui<autoCorrelateFunc.size();ui++)
75 strm << binStep*ui <<
"\t";
77 for(
unsigned int uj=0;uj<autoCorrelateFunc[ui].size();uj++)
79 strm <<autoCorrelateFunc[ui][uj] <<
"\t";
86 int main(
int argc,
char *argv[])
88 if(!(argc == 6 || argc ==7) )
90 cerr <<
"USAGE : " << argv[0] <<
" POSFILE RANGEFILE Radius binStep Sampling [outputfile]" << endl;
94 std::string posFilename,rangeFilename, outputFile;
95 float sampleFactor,scanRadius,binStep;
98 rangeFilename=argv[2];
104 cerr <<
"unable to understand sampling factor. Aborting." << endl;
109 cerr <<
"unable to understand scan radius. Aborting." << endl;
115 cerr <<
"unable to understand bin step size. Aborting." << endl;
119 if(sampleFactor < 0.0f || sampleFactor > 1.0f)
121 cerr <<
"sampling factor must lie in range [0,1]"<<endl ;
125 if(scanRadius <=0.0f)
127 cerr <<
"Scan radius must be positive" << endl;
133 cerr <<
"Bin step size must be positive" << endl;
138 if(!outputFile.empty())
140 of.open(outputFile.c_str());
143 cerr <<
"Unable to open outputfile :" << outputFile << endl;
149 unsigned int errCode;
151 cerr <<
"Loading pos data from " <<posFilename <<
"..." << endl;
156 cerr <<
"Error loading posfile :" << endl;
161 cerr <<
"\tLoaded :" << ions.size() <<
" ions." << endl;
167 if(!rangeFile.openGuessFormat(rangeFilename.c_str()))
169 cerr <<
"Error loading rangefile :" <<
177 cerr <<
"Ranging...";
178 rangeFile.
range(ions);
179 cerr <<
"Done" << endl;
180 cerr <<
"\tRanged:" << ions.size() <<
" ions." << endl;
184 cerr <<
"No ions after ranging. Aborting." << endl;
192 if(sampleFactor < 1.0f)
195 cerr <<
"Sampling...";
196 vector<IonHit> sampled;
200 cerr <<
"Done" << endl;
201 cerr <<
"\tSampled:" << ions.size() <<
" ions." << endl;
205 cerr <<
"No ions after sampling. Aborting." << endl;
216 cerr <<
"Building search structures....";
219 treeProgressBar->
init();
232 cerr <<
"Data structure not OK. Aborting" << endl;
233 cerr <<
"Does the input data form a volume?" << endl;
239 unsigned int binCount = scanRadius/binStep;
243 cerr <<
"Search radius :" << scanRadius <<
" is too small, needs to be bigger than the bin size:" << binStep << endl;
249 cerr <<
"Computing autocorrelation..." ;
255 unsigned int numCounted =0;
257 vector<vector<unsigned int> > overallCompositionTable;
260 overallCompositionTable.resize(binCount);
261 for(
unsigned int ui=0;ui<overallCompositionTable.size();ui++)
262 overallCompositionTable[ui].resize(rangeFile.
getNumIons(),0);
269 #pragma omp parallel for 270 for(
unsigned int ui=0;ui<ions.size();ui++)
272 vector<size_t> pointIdx;
273 vector<vector<size_t> > compositionTable;
276 compositionTable.resize(binCount);
277 for(
unsigned int uj=0;uj<compositionTable.size();uj++)
278 compositionTable[uj].resize(rangeFile.
getNumIons(),0);
284 if(!omp_get_thread_num())
286 progressBar.
update((
float)numCounted/ions.size()*100.0f);
295 for(
size_t uj=0;uj<pointIdx.size();uj++)
310 if(radius <=sqrt(std::numeric_limits<float>::epsilon()))
314 ionBin = (
unsigned int) (radius/binStep);
315 if(ionBin == binCount && ionBin)
318 compositionTable[ionBin][ionId]++;
323 for(
size_t uj=0;uj<compositionTable.size();uj++)
325 for(
size_t uk=0;uk<compositionTable[uj].size();uk++)
327 overallCompositionTable[uj][uk]+=compositionTable[uj][uk];
340 vector<vector<float> > compPct;
342 compPct.resize(binCount);
343 for(
unsigned int ui=0;ui<binCount;ui++)
351 vector<float> meanComp;
355 for(
unsigned int ui=0;ui<compPct.size();ui++)
360 for(
unsigned int uj=0;uj<compPct[ui].size();uj++)
361 res+=compPct[ui][uj];
363 res/=compPct[ui].size();
369 for(
unsigned int ui=0;ui<compPct.size();ui++)
372 for(
unsigned int uj=0;uj<compPct[ui].size();uj++)
373 compPct[ui][uj]-=meanComp[ui];
376 vector<vector<float> > &deviationComp=compPct;
381 vector<vector<float> > autoCorrelateFunc;
382 vector<float> denominator;
383 autoCorrelateFunc.resize(binCount);
386 denominator.resize(numIons);
387 for(
unsigned int ui=0;ui<numIons;ui++)
391 for(
unsigned int uj=0;uj<deviationComp[ui].size();uj++)
392 normConstant+=deviationComp[ui][uj]*deviationComp[ui][uj];
395 denominator[ui] = normConstant;
401 autoCorrelateFunc.resize(numIons);
402 for(
unsigned int ui=0;ui<numIons;ui++)
404 autoCorrelateFunc[ui].resize(binCount);
406 for(
unsigned int ki=0; ki<binCount; ki++)
410 for(
unsigned int uj=0;uj<binCount-ki; uj++)
412 numValue+=deviationComp[ui][uj]*deviationComp[ui][uj+ki];
415 if(denominator[ui] > std::numeric_limits<float>::epsilon())
416 autoCorrelateFunc[ui][ki] = numValue / denominator[ui];
418 autoCorrelateFunc[ui][ki] = 0;
429 if(outputFile.empty())
433 cerr <<
"Wrote output to:" << outputFile << endl;
435 std::ofstream debugOf;
437 s= outputFile +
"-debugrdf";
438 debugOf.open(s.c_str());
float sqrDist(const Point3D &pt) const
Returns the square of distance to another Point3D.
void range(std::vector< IonHit > &ionHits) const
Clips out ions that are not inside the rangefile's ranges.
void getBoundCube(BoundCube &b)
obtain the bounding rectangular prism volume for all elements in the KD tree
std::string getName(unsigned int ionID, bool shortName=true) const
Get the short name or long name of a specified ionID.
void setProgressPointer(unsigned int *p)
unsigned int getIonID(float mass) const
Get the ion's ID from a specified mass.
const char * getPosFileErrString(unsigned int errMesg)
void computeComposition(const std::vector< unsigned int > &countData, std::vector< float > &compositionData)
void transposeVector(std::vector< std::vector< T > > &v)
Perform an out-of-place tranposition of a given vector.
size_t getOrigIndex(size_t treeIndex) const
void findUntaggedInRadius(const Point3D &queryPt, const BoundCube &b, float radius, std::vector< size_t > &result)
Find untagged points within a given radius.
unsigned int treeProgressValue
void sampleIons(const std::vector< IonHit > &ions, float sampleFactor, std::vector< IonHit > &sampled, bool strongRandom=true)
void setCallback(bool(*cb)(void))
int main(int argc, char *argv[])
void dumpAutocorrelation(const vector< vector< T > > &autoCorrelateFunc, const RangeFile &rangeFile, float binStep, std::ostream &strm)
float getMassToCharge() const
unsigned int loadPosFile(std::vector< IonHit > &posIons, const char *posFile)
Load a pos file directly into a single ion list.
void init()
Draw the initial progress bar.
Helper class to define a bounding cube.
ProgressBar * treeProgressBar
void resetPts(std::vector< Point3D > &pts, bool clear=true)
Supply points to KD tree. Ouput vector will be erased if clear=true.
const unsigned int PROGRESS_BAR_SIZE
bool build()
Build the KD tree using the previously supplied points.
bool isFlat() const
Returns true if any bound is of null thickness.
void setLength(unsigned int l)
Set the number of markers in the progress bar.
This is a data holding class for POS file ions, from.
Data storage and retrieval class for various range files.
bool stream_cast(T1 &result, const T2 &obj)
Template function to cast and object to another by the stringstream.
unsigned int getNumIons() const
Get the number of unique ions.
std::string getErrString() const
Retrieve the translated error associated with the current range file state.
void update(unsigned int newProgress)
Draw the progress bar as needed, using the given progress value [0,100].