]> git.donarmstrong.com Git - mothur.git/blob - pintail.cpp
added MPI code, broke up chimera.seqs into 5 separated commands, added parse.sff...
[mothur.git] / pintail.cpp
1 /*
2  *  pintail.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 7/9/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "pintail.h"
11 #include "ignoregaps.h"
12 #include "eachgapdist.h"
13
14 //********************************************************************************************************************
15 //sorts lowest to highest
16 inline bool compareQuanMembers(quanMember left, quanMember right){
17         return (left.score < right.score);      
18
19 //***************************************************************************************************************
20
21 Pintail::Pintail(string filename, string temp, bool f, int p, string mask, string cons, string q, int win, int inc, string o) : Chimera() { 
22         try {
23         
24                 fastafile = filename; 
25                 templateFileName = temp; templateSeqs = readSeqs(temp);
26                 filter = f;
27                 processors = p;
28                 setMask(mask);
29                 consfile = cons;
30                 quanfile = q;
31                 window = win;
32                 increment = inc; 
33                 outputDir = o; 
34                 
35                 distcalculator = new eachGapDist();
36                 decalc = new DeCalculator();
37                 
38                 doPrep();
39         }
40         catch(exception& e) {
41                 m->errorOut(e, "Pintail", "Pintail");
42                 exit(1);
43         }
44
45 }
46 //***************************************************************************************************************
47
48 Pintail::~Pintail() {
49         try {
50                 
51                 delete distcalculator;
52                 delete decalc; 
53         }
54         catch(exception& e) {
55                 m->errorOut(e, "Pintail", "~Pintail");
56                 exit(1);
57         }
58 }
59 //***************************************************************************************************************
60 int Pintail::doPrep() {
61         try {
62                 
63                 mergedFilterString = "";
64                 windowSizesTemplate.resize(templateSeqs.size(), window);
65                 quantiles.resize(100);  //one for every percent mismatch
66                 quantilesMembers.resize(100);  //one for every percent mismatch
67                 
68                 //if the user does not enter a mask then you want to keep all the spots in the alignment
69                 if (seqMask.length() == 0)      {       decalc->setAlignmentLength(templateSeqs[0]->getAligned().length());     }
70                 else                                            {       decalc->setAlignmentLength(seqMask.length());                                           }
71                 
72                 decalc->setMask(seqMask);
73                 
74         #ifdef USE_MPI
75                 //do nothing
76         #else
77                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
78                         //find breakup of templatefile for quantiles
79                         if (processors == 1) {   templateLines.push_back(new linePair(0, templateSeqs.size()));  }
80                         else { 
81                                 for (int i = 0; i < processors; i++) {
82                                         templateLines.push_back(new linePair());
83                                         templateLines[i]->start = int (sqrt(float(i)/float(processors)) * templateSeqs.size());
84                                         templateLines[i]->end = int (sqrt(float(i+1)/float(processors)) * templateSeqs.size());
85                                 }
86                         }
87                 #else
88                         templateLines.push_back(new linePair(0, templateSeqs.size()));
89                 #endif
90         #endif
91                 
92                 m->mothurOut("Getting conservation... "); cout.flush();
93                 if (consfile == "") { 
94                         m->mothurOut("Calculating probability of conservation for your template sequences.  This can take a while...  I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command.  Providing the .freq file will improve speed.    "); cout.flush();
95                         probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFileName)); 
96                         if (m->control_pressed) {  return 0;  }
97                         m->mothurOut("Done."); m->mothurOutEndLine();
98                 }else                           {   probabilityProfile = readFreq();    m->mothurOut("Done.");            }
99                 m->mothurOutEndLine();
100                 
101                 //make P into Q
102                 for (int i = 0; i < probabilityProfile.size(); i++)  { probabilityProfile[i] = 1 - probabilityProfile[i];  }  //
103                 
104                 bool reRead = false;
105                 //create filter if needed for later
106                 if (filter) {
107                                                 
108                         //read in all query seqs
109                         vector<Sequence*> tempQuerySeqs = readSeqs(fastafile);
110                                 
111                         vector<Sequence*> temp;
112                         //merge query seqs and template seqs
113                         temp = templateSeqs;
114                         for (int i = 0; i < tempQuerySeqs.size(); i++) {  temp.push_back(tempQuerySeqs[i]);  }
115         
116                         if (seqMask != "") {
117                             reRead = true;
118                                 //mask templates
119                                 for (int i = 0; i < temp.size(); i++) {
120                                         if (m->control_pressed) {  
121                                                 for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
122                                                 return 0; 
123                                         }
124                                         decalc->runMask(temp[i]);
125                                 }
126                         }
127
128                         mergedFilterString = createFilter(temp, 0.5);
129                         
130                         if (m->control_pressed) {  
131                                 for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
132                                 return 0; 
133                         }
134                         
135                         //reread template seqs
136                         for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
137                 }
138                 
139                 
140                 //quantiles are used to determine whether the de values found indicate a chimera
141                 //if you have to calculate them, its time intensive because you are finding the de and deviation values for each 
142                 //combination of sequences in the template
143                 if (quanfile != "") {  
144                         quantiles = readQuantiles(); 
145                 }else {
146                         if ((!filter) && (seqMask != "")) { //if you didn't filter but you want to mask. if you filtered then you did mask first above.
147                                 reRead = true;
148                                 //mask templates
149                                 for (int i = 0; i < templateSeqs.size(); i++) {
150                                         if (m->control_pressed) {  return 0;  }
151                                         decalc->runMask(templateSeqs[i]);
152                                 }
153                         }
154                         
155                         if (filter) { 
156                                 reRead = true;
157                                 for (int i = 0; i < templateSeqs.size(); i++) {
158                                         if (m->control_pressed) {  return 0;  }
159                                         runFilter(templateSeqs[i]);
160                                 }
161                         }
162                         
163                         m->mothurOut("Calculating quantiles for your template.  This can take a while...  I will output the quantiles to a .quan file that you can input them using the quantiles parameter next time you run this command.  Providing the .quan file will dramatically improve speed.    "); cout.flush();
164                         if (processors == 1) { 
165                                 quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, 0, templateSeqs.size());
166                         }else {         createProcessesQuan();          }
167                 
168                         if (m->control_pressed) {  return 0;  }
169                         
170                         string noOutliers, outliers;
171                         
172                         if ((!filter) && (seqMask == "")) {
173                                 noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.quan";
174                         }else if ((!filter) && (seqMask != "")) { 
175                                 noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.masked.quan";
176                         }else if ((filter) && (seqMask != "")) { 
177                                 noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "masked.quan";
178                         }else if ((filter) && (seqMask == "")) { 
179                                 noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "quan";
180                         }
181
182                         decalc->removeObviousOutliers(quantilesMembers, templateSeqs.size());
183                         
184                         if (m->control_pressed) {  return 0;  }
185                 
186                         string outputString = "";
187                         
188                         //adjust quantiles
189                         for (int i = 0; i < quantilesMembers.size(); i++) {
190                                 vector<float> temp;
191                                 
192                                 if (quantilesMembers[i].size() == 0) {
193                                         //in case this is not a distance found in your template files
194                                         for (int g = 0; g < 6; g++) {
195                                                 temp.push_back(0.0);
196                                         }
197                                 }else{
198                                         
199                                         sort(quantilesMembers[i].begin(), quantilesMembers[i].end(), compareQuanMembers);
200                                         
201                                         //save 10%
202                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.10)].score);
203                                         //save 25%
204                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.25)].score);
205                                         //save 50%
206                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.5)].score);
207                                         //save 75%
208                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.75)].score);
209                                         //save 95%
210                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.95)].score);
211                                         //save 99%
212                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.99)].score);
213                                         
214                                 }
215                                 
216                                 //output quan value
217                                 outputString += toString(i+1) + "\t";                           
218                                 for (int u = 0; u < temp.size(); u++) {   outputString += toString(temp[u]) + "\t"; }
219                                 outputString += "\n";
220                                 
221                                 quantiles[i] = temp;
222                                 
223                         }
224                         
225                         printQuanFile(noOutliers, outputString);
226                         
227                         m->mothurOut("Done."); m->mothurOutEndLine();
228                 }
229                 
230                 if (reRead) {
231                         for (int i = 0; i < templateSeqs.size(); i++) { delete templateSeqs[i];  }
232                         templateSeqs.clear();
233                         templateSeqs = readSeqs(templateFileName);
234                 }
235
236                 
237                 //free memory
238                 for (int i = 0; i < templateLines.size(); i++) { delete templateLines[i];  }
239                 
240                 return 0;
241                 
242         }
243         catch(exception& e) {
244                 m->errorOut(e, "Pintail", "doPrep");
245                 exit(1);
246         }
247 }
248 //***************************************************************************************************************
249 int Pintail::print(ostream& out, ostream& outAcc) {
250         try {
251                 int index = ceil(deviation);
252                 
253                 //is your DE value higher than the 95%
254                 string chimera;
255                 if (index != 0) {  //if index is 0 then its an exact match to a template seq
256                         if (quantiles[index][4] == 0.0) {
257                                 chimera = "Your template does not include sequences that provide quantile values at distance " + toString(index);
258                         }else {
259                                 if (DE > quantiles[index][4])           {       chimera = "Yes";        }
260                                 else                                                            {       chimera = "No";         }
261                         }
262                 }else{ chimera = "No";          }
263                 
264                 out << querySeq->getName() << '\t' << "div: " << deviation << "\tstDev: " << DE << "\tchimera flag: " << chimera << endl;
265                 if (chimera == "Yes") {
266                         m->mothurOut(querySeq->getName() + "\tdiv: " + toString(deviation) + "\tstDev: " + toString(DE) + "\tchimera flag: " + chimera); m->mothurOutEndLine();
267                         outAcc << querySeq->getName() << endl;
268                 }
269                 out << "Observed\t";
270                 
271                 for (int j = 0; j < obsDistance.size(); j++) {  out << obsDistance[j] << '\t';  }
272                 out << endl;
273                 
274                 out << "Expected\t";
275                 
276                 for (int m = 0; m < expectedDistance.size(); m++) {  out << expectedDistance[m] << '\t';  }
277                 out << endl;
278                 
279                 return 0;
280                 
281         }
282         catch(exception& e) {
283                 m->errorOut(e, "Pintail", "print");
284                 exit(1);
285         }
286 }
287 #ifdef USE_MPI
288 //***************************************************************************************************************
289 int Pintail::print(MPI_File& out, MPI_File& outAcc) {
290         try {
291                 bool results = false;
292                 string outputString = "";
293                 int index = ceil(deviation);
294                 
295                 //is your DE value higher than the 95%
296                 string chimera;
297                 if (index != 0) {  //if index is 0 then its an exact match to a template seq
298                         if (quantiles[index][4] == 0.0) {
299                                 chimera = "Your template does not include sequences that provide quantile values at distance " + toString(index);
300                         }else {
301                                 if (DE > quantiles[index][4])           {       chimera = "Yes";        }
302                                 else                                                            {       chimera = "No";         }
303                         }
304                 }else{ chimera = "No";          }
305
306                 outputString += querySeq->getName() + "\tdiv: " + toString(deviation) + "\tstDev: " + toString(DE) + "\tchimera flag: " + chimera + "\n";
307                 if (chimera == "Yes") {
308                         cout << querySeq->getName() << "\tdiv: " << toString(deviation) << "\tstDev: " << toString(DE) << "\tchimera flag: " << chimera << endl;
309                         string outAccString = querySeq->getName() + "\n";
310                         
311                         MPI_Status statusAcc;
312                         int length = outAccString.length();
313                         char buf[length];
314                         strcpy(buf, outAccString.c_str()); 
315                                 
316                         MPI_File_write_shared(outAcc, buf, length, MPI_CHAR, &statusAcc);
317                         
318                         results = true;
319                 }
320                 outputString += "Observed\t";
321                 
322                 for (int j = 0; j < obsDistance.size(); j++) {  outputString += toString(obsDistance[j]) + "\t";  }
323                 outputString += "\n";
324                 
325                 outputString += "Expected\t";
326                 
327                 for (int m = 0; m < expectedDistance.size(); m++) {  outputString += toString(expectedDistance[m]) + "\t";  }
328                 outputString += "\n";
329                 
330                 MPI_Status status;
331                 int length = outputString.length();
332                 char buf2[length];
333                 strcpy(buf2, outputString.c_str()); 
334                                 
335                 MPI_File_write_shared(out, buf2, length, MPI_CHAR, &status);
336                 
337                 return results;
338         }
339         catch(exception& e) {
340                 m->errorOut(e, "Pintail", "print");
341                 exit(1);
342         }
343 }
344 #endif
345 //***************************************************************************************************************
346 int Pintail::getChimeras(Sequence* query) {
347         try {
348                 querySeq = query;
349                 trimmed.clear();
350                 windowSizes = window;
351                                                         
352                 //find pairs has to be done before a mask
353                 bestfit = findPairs(query);
354                 
355                 if (m->control_pressed) {  return 0; } 
356                 
357                 //if they mask  
358                 if (seqMask != "") {
359                         decalc->runMask(query);
360                         decalc->runMask(bestfit);
361                 }
362
363                 if (filter) { //must be done after a mask
364                         runFilter(query);
365                         runFilter(bestfit);
366                 }
367                 
368                                 
369                 //trim seq
370                 decalc->trimSeqs(query, bestfit, trimmed);  
371                 
372                 //find windows
373                 it = trimmed.begin();
374                 windowsForeachQuery = decalc->findWindows(query, it->first, it->second, windowSizes, increment);
375
376                 //find observed distance
377                 obsDistance = decalc->calcObserved(query, bestfit, windowsForeachQuery, windowSizes);
378                 
379                 if (m->control_pressed) {  return 0; } 
380                                 
381                 Qav = decalc->findQav(windowsForeachQuery, windowSizes, probabilityProfile);
382                 
383                 if (m->control_pressed) {  return 0; } 
384
385                 //find alpha                    
386                 seqCoef = decalc->getCoef(obsDistance, Qav);
387                 
388                 //calculating expected distance
389                 expectedDistance = decalc->calcExpected(Qav, seqCoef);
390                 
391                 if (m->control_pressed) {  return 0; } 
392                 
393                 //finding de
394                 DE = decalc->calcDE(obsDistance, expectedDistance);
395                 
396                 if (m->control_pressed) {  return 0; } 
397                 
398                 //find distance between query and closest match
399                 it = trimmed.begin();
400                 deviation = decalc->calcDist(query, bestfit, it->first, it->second); 
401                 
402                 delete bestfit;
403                                                                         
404                 return 0;
405         }
406         catch(exception& e) {
407                 m->errorOut(e, "Pintail", "getChimeras");
408                 exit(1);
409         }
410 }
411
412 //***************************************************************************************************************
413
414 vector<float> Pintail::readFreq() {
415         try {
416                 //read in probabilities and store in vector
417                 int pos; float num; 
418
419                 vector<float> prob;
420                 set<int> h = decalc->getPos();  //positions of bases in masking sequence
421                 
422         #ifdef USE_MPI
423                 
424                 MPI_File inMPI;
425                 MPI_Offset size;
426                 MPI_Status status;
427                 
428                 char inFileName[consfile.length()];
429                 strcpy(inFileName, consfile.c_str());
430
431                 MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  
432                 MPI_File_get_size(inMPI, &size);
433
434                 char buffer[size];
435                 MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
436
437                 string tempBuf = buffer;
438
439                 if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
440                 istringstream iss (tempBuf,istringstream::in);
441                 
442                 while(!iss.eof()) {
443                         iss >> pos >> num;
444         
445                         if (h.count(pos) > 0) {
446                                 float Pi;
447                                 Pi =  (num - 0.25) / 0.75; 
448                         
449                                 //cannot have probability less than 0.
450                                 if (Pi < 0) { Pi = 0.0; }
451
452                                 //do you want this spot
453                                 prob.push_back(Pi);  
454                         }
455                         
456                         gobble(iss);
457                 }
458         
459                 MPI_File_close(&inMPI);
460                 
461         #else   
462
463                 ifstream in;
464                 openInputFile(consfile, in);
465                                 
466                 while(!in.eof()){
467                         
468                         in >> pos >> num;
469                         
470                         if (h.count(pos) > 0) {
471                                 float Pi;
472                                 Pi =  (num - 0.25) / 0.75; 
473                         
474                                 //cannot have probability less than 0.
475                                 if (Pi < 0) { Pi = 0.0; }
476
477                                 //do you want this spot
478                                 prob.push_back(Pi);  
479                         }
480                         
481                         gobble(in);
482                 }
483                 in.close();
484                 
485         #endif
486         
487                 return prob;
488                 
489         }
490         catch(exception& e) {
491                 m->errorOut(e, "Pintail", "readFreq");
492                 exit(1);
493         }
494 }
495
496 //***************************************************************************************************************
497 //calculate the distances from each query sequence to all sequences in the template to find the closest sequence
498 Sequence* Pintail::findPairs(Sequence* q) {
499         try {
500                 
501                 Sequence* seqsMatches;  
502                 
503                 seqsMatches = decalc->findClosest(q, templateSeqs);
504                 return seqsMatches;
505         
506         }
507         catch(exception& e) {
508                 m->errorOut(e, "Pintail", "findPairs");
509                 exit(1);
510         }
511 }
512 //**************************************************************************************************
513 void Pintail::createProcessesQuan() {
514         try {
515 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
516                 int process = 0;
517                 vector<int> processIDS;
518                                 
519                 //loop through and create all the processes you want
520                 while (process != processors) {
521                         int pid = fork();
522                         
523                         if (pid > 0) {
524                                 processIDS.push_back(pid);  
525                                 process++;
526                         }else if (pid == 0){
527                                 
528                                 quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, templateLines[process]->start, templateLines[process]->end);
529                                 
530                                 //write out data to file so parent can read it
531                                 ofstream out;
532                                 string s = toString(getpid()) + ".temp";
533                                 openOutputFile(s, out);
534                                 
535                                                                 
536                                 //output observed distances
537                                 for (int i = 0; i < quantilesMembers.size(); i++) {
538                                         out << quantilesMembers[i].size() << '\t';
539                                         for (int j = 0; j < quantilesMembers[i].size(); j++) {
540                                                 out << quantilesMembers[i][j].score << '\t' << quantilesMembers[i][j].member1 << '\t' << quantilesMembers[i][j].member2 << '\t';
541                                         }
542                                         out << endl;
543                                 }
544                                 
545                                 out.close();
546                                 
547                                 exit(0);
548                         }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
549                 }
550                 
551                 //force parent to wait until all the processes are done
552                 for (int i=0;i<processors;i++) { 
553                         int temp = processIDS[i];
554                         wait(&temp);
555                 }
556
557                 //get data created by processes
558                 for (int i=0;i<processors;i++) { 
559                         ifstream in;
560                         string s = toString(processIDS[i]) + ".temp";
561                         openInputFile(s, in);
562                         
563                         vector< vector<quanMember> > quan; 
564                         quan.resize(100);
565                         
566                         //get quantiles
567                         for (int m = 0; m < quan.size(); m++) {
568                                 int num;
569                                 in >> num; 
570                                 
571                                 gobble(in);
572
573                                 vector<quanMember> q;  float w; int b, n;
574                                 for (int j = 0; j < num; j++) {
575                                         in >> w >> b >> n;
576         
577                                         quanMember newMember(w, b, n);
578                                         q.push_back(newMember);
579                                 }
580
581                                 quan[m] = q;
582                                 gobble(in);
583                         }
584                         
585         
586                         //save quan in quantiles
587                         for (int j = 0; j < quan.size(); j++) {
588                                 //put all values of q[i] into quan[i]
589                                 for (int l = 0; l < quan[j].size(); l++) {  quantilesMembers[j].push_back(quan[j][l]);   }
590                                 //quantilesMembers[j].insert(quantilesMembers[j].begin(), quan[j].begin(), quan[j].end());
591                         }
592                                         
593                         in.close();
594                         remove(s.c_str());
595                 }
596                 
597 #else
598                 quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, 0, templateSeqs.size());
599 #endif          
600         }
601         catch(exception& e) {
602                 m->errorOut(e, "Pintail", "createProcessesQuan");
603                 exit(1);
604         }
605 }
606 //***************************************************************************************************************
607 vector< vector<float> > Pintail::readQuantiles() {
608         try {
609                 int num; 
610                 float ten, twentyfive, fifty, seventyfive, ninetyfive, ninetynine; 
611                 
612                 vector< vector<float> > quan;
613                 vector <float> temp; temp.resize(6, 0);
614                 
615                 //to fill 0
616                 quan.push_back(temp); 
617
618         #ifdef USE_MPI
619                 
620                 MPI_File inMPI;
621                 MPI_Offset size;
622                 MPI_Status status;
623                 
624                 char inFileName[quanfile.length()];
625                 strcpy(inFileName, quanfile.c_str());
626
627                 MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  
628                 MPI_File_get_size(inMPI, &size);
629
630                 char buffer[size];
631                 MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
632
633                 string tempBuf = buffer;
634                 if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
635                 istringstream iss (tempBuf,istringstream::in);
636                 
637                 while(!iss.eof()) {
638                         iss >> num >> ten >> twentyfive >> fifty >> seventyfive >> ninetyfive >> ninetynine; 
639                         
640                         temp.clear();
641                         
642                         temp.push_back(ten); 
643                         temp.push_back(twentyfive);
644                         temp.push_back(fifty);
645                         temp.push_back(seventyfive);
646                         temp.push_back(ninetyfive);
647                         temp.push_back(ninetynine);
648                         
649                         quan.push_back(temp);  
650                         
651                         gobble(iss);
652                 }
653         
654                 MPI_File_close(&inMPI);
655                 
656         #else   
657
658                 ifstream in;
659                 openInputFile(quanfile, in);
660                         
661                 while(!in.eof()){
662                         
663                         in >> num >> ten >> twentyfive >> fifty >> seventyfive >> ninetyfive >> ninetynine; 
664                         
665                         temp.clear();
666                         
667                         temp.push_back(ten); 
668                         temp.push_back(twentyfive);
669                         temp.push_back(fifty);
670                         temp.push_back(seventyfive);
671                         temp.push_back(ninetyfive);
672                         temp.push_back(ninetynine);
673                         
674                         quan.push_back(temp);  
675         
676                         gobble(in);
677                 }
678                 in.close();
679         #endif
680         
681                 return quan;
682                 
683         }
684         catch(exception& e) {
685                 m->errorOut(e, "Pintail", "readQuantiles");
686                 exit(1);
687         }
688 }
689 //***************************************************************************************************************/
690
691 void Pintail::printQuanFile(string file, string outputString) {
692         try {
693         
694                 #ifdef USE_MPI
695                 
696                         MPI_File outQuan;
697                         MPI_Status status;
698                         
699                         int pid;
700                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
701
702                         int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
703                         
704                         char FileName[file.length()];
705                         strcpy(FileName, file.c_str());
706                         
707                         if (pid == 0) {
708                                 MPI_File_open(MPI_COMM_SELF, FileName, outMode, MPI_INFO_NULL, &outQuan);  //comm, filename, mode, info, filepointer
709                                 
710                                 int length = outputString.length();
711                                 char buf[length];
712                                 strcpy(buf, outputString.c_str()); 
713                                         
714                                 MPI_File_write(outQuan, buf, length, MPI_CHAR, &status);
715                         
716                                 MPI_File_close(&outQuan);
717                         }
718                 #else
719                         ofstream outQuan;
720                         openOutputFile(file, outQuan);
721                         
722                         outQuan << outputString;
723                         
724                         outQuan.close();
725                 #endif
726         }
727         catch(exception& e) {
728                 m->errorOut(e, "Pintail", "printQuanFile");
729                 exit(1);
730         }
731 }
732
733 //***************************************************************************************************************/
734
735
736