]> git.donarmstrong.com Git - mothur.git/blob - pintail.cpp
changes for 1.11
[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());
200                                         
201                                         //save 10%
202                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.10)]);
203                                         //save 25%
204                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.25)]);
205                                         //save 50%
206                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.5)]);
207                                         //save 75%
208                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.75)]);
209                                         //save 95%
210                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.95)]);
211                                         //save 99%
212                                         temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.99)]);
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                         //free memory
228                         quantilesMembers.clear();
229                         
230                         m->mothurOut("Done."); m->mothurOutEndLine();
231                 }
232                 
233                 if (reRead) {
234                         for (int i = 0; i < templateSeqs.size(); i++) { delete templateSeqs[i];  }
235                         templateSeqs.clear();
236                         templateSeqs = readSeqs(templateFileName);
237                 }
238
239                 
240                 //free memory
241                 for (int i = 0; i < templateLines.size(); i++) { delete templateLines[i];  }
242                 
243                 return 0;
244                 
245         }
246         catch(exception& e) {
247                 m->errorOut(e, "Pintail", "doPrep");
248                 exit(1);
249         }
250 }
251 //***************************************************************************************************************
252 int Pintail::print(ostream& out, ostream& outAcc) {
253         try {
254                 int index = ceil(deviation);
255                 
256                 //is your DE value higher than the 95%
257                 string chimera;
258                 if (index != 0) {  //if index is 0 then its an exact match to a template seq
259                         if (quantiles[index][4] == 0.0) {
260                                 chimera = "Your template does not include sequences that provide quantile values at distance " + toString(index);
261                         }else {
262                                 if (DE > quantiles[index][4])           {       chimera = "Yes";        }
263                                 else                                                            {       chimera = "No";         }
264                         }
265                 }else{ chimera = "No";          }
266                 
267                 out << querySeq->getName() << '\t' << "div: " << deviation << "\tstDev: " << DE << "\tchimera flag: " << chimera << endl;
268                 if (chimera == "Yes") {
269                         m->mothurOut(querySeq->getName() + "\tdiv: " + toString(deviation) + "\tstDev: " + toString(DE) + "\tchimera flag: " + chimera); m->mothurOutEndLine();
270                         outAcc << querySeq->getName() << endl;
271                 }
272                 out << "Observed\t";
273                 
274                 for (int j = 0; j < obsDistance.size(); j++) {  out << obsDistance[j] << '\t';  }
275                 out << endl;
276                 
277                 out << "Expected\t";
278                 
279                 for (int m = 0; m < expectedDistance.size(); m++) {  out << expectedDistance[m] << '\t';  }
280                 out << endl;
281                 
282                 return 0;
283                 
284         }
285         catch(exception& e) {
286                 m->errorOut(e, "Pintail", "print");
287                 exit(1);
288         }
289 }
290 #ifdef USE_MPI
291 //***************************************************************************************************************
292 int Pintail::print(MPI_File& out, MPI_File& outAcc) {
293         try {
294                 bool results = false;
295                 string outputString = "";
296                 int index = ceil(deviation);
297                 
298                 //is your DE value higher than the 95%
299                 string chimera;
300                 if (index != 0) {  //if index is 0 then its an exact match to a template seq
301                         if (quantiles[index][4] == 0.0) {
302                                 chimera = "Your template does not include sequences that provide quantile values at distance " + toString(index);
303                         }else {
304                                 if (DE > quantiles[index][4])           {       chimera = "Yes";        }
305                                 else                                                            {       chimera = "No";         }
306                         }
307                 }else{ chimera = "No";          }
308
309                 outputString += querySeq->getName() + "\tdiv: " + toString(deviation) + "\tstDev: " + toString(DE) + "\tchimera flag: " + chimera + "\n";
310                 if (chimera == "Yes") {
311                         cout << querySeq->getName() << "\tdiv: " << toString(deviation) << "\tstDev: " << toString(DE) << "\tchimera flag: " << chimera << endl;
312                         string outAccString = querySeq->getName() + "\n";
313                         
314                         MPI_Status statusAcc;
315                         int length = outAccString.length();
316                         char* buf = new char[length];
317                         memcpy(buf, outAccString.c_str(), length);
318                                 
319                         MPI_File_write_shared(outAcc, buf, length, MPI_CHAR, &statusAcc);
320                         delete buf;
321
322                         results = true;
323                 }
324                 outputString += "Observed\t";
325                 
326                 for (int j = 0; j < obsDistance.size(); j++) {  outputString += toString(obsDistance[j]) + "\t";  }
327                 outputString += "\n";
328                 
329                 outputString += "Expected\t";
330                 
331                 for (int m = 0; m < expectedDistance.size(); m++) {  outputString += toString(expectedDistance[m]) + "\t";  }
332                 outputString += "\n";
333                 
334                 MPI_Status status;
335                 int length = outputString.length();
336                 char* buf2 = new char[length];
337                 memcpy(buf2, outputString.c_str(), length);
338                                 
339                 MPI_File_write_shared(out, buf2, length, MPI_CHAR, &status);
340                 delete buf2;
341                 
342                 return results;
343         }
344         catch(exception& e) {
345                 m->errorOut(e, "Pintail", "print");
346                 exit(1);
347         }
348 }
349 #endif
350 //***************************************************************************************************************
351 int Pintail::getChimeras(Sequence* query) {
352         try {
353                 querySeq = query;
354                 trimmed.clear();
355                 windowSizes = window;
356                                                         
357                 //find pairs has to be done before a mask
358                 bestfit = findPairs(query);
359                 
360                 if (m->control_pressed) {  return 0; } 
361                 
362                 //if they mask  
363                 if (seqMask != "") {
364                         decalc->runMask(query);
365                         decalc->runMask(bestfit);
366                 }
367
368                 if (filter) { //must be done after a mask
369                         runFilter(query);
370                         runFilter(bestfit);
371                 }
372                 
373                                 
374                 //trim seq
375                 decalc->trimSeqs(query, bestfit, trimmed);  
376                 
377                 //find windows
378                 it = trimmed.begin();
379                 windowsForeachQuery = decalc->findWindows(query, it->first, it->second, windowSizes, increment);
380
381                 //find observed distance
382                 obsDistance = decalc->calcObserved(query, bestfit, windowsForeachQuery, windowSizes);
383                 
384                 if (m->control_pressed) {  return 0; } 
385                                 
386                 Qav = decalc->findQav(windowsForeachQuery, windowSizes, probabilityProfile);
387                 
388                 if (m->control_pressed) {  return 0; } 
389
390                 //find alpha                    
391                 seqCoef = decalc->getCoef(obsDistance, Qav);
392                 
393                 //calculating expected distance
394                 expectedDistance = decalc->calcExpected(Qav, seqCoef);
395                 
396                 if (m->control_pressed) {  return 0; } 
397                 
398                 //finding de
399                 DE = decalc->calcDE(obsDistance, expectedDistance);
400                 
401                 if (m->control_pressed) {  return 0; } 
402                 
403                 //find distance between query and closest match
404                 it = trimmed.begin();
405                 deviation = decalc->calcDist(query, bestfit, it->first, it->second); 
406                 
407                 delete bestfit;
408                                                                         
409                 return 0;
410         }
411         catch(exception& e) {
412                 m->errorOut(e, "Pintail", "getChimeras");
413                 exit(1);
414         }
415 }
416
417 //***************************************************************************************************************
418
419 vector<float> Pintail::readFreq() {
420         try {
421                 //read in probabilities and store in vector
422                 int pos; float num; 
423
424                 vector<float> prob;
425                 set<int> h = decalc->getPos();  //positions of bases in masking sequence
426                 
427         #ifdef USE_MPI
428                 
429                 MPI_File inMPI;
430                 MPI_Offset size;
431                 MPI_Status status;
432
433                 //char* inFileName = new char[consfile.length()];
434                 //memcpy(inFileName, consfile.c_str(), consfile.length());
435                 
436                 char inFileName[1024];
437                 strcpy(inFileName, consfile.c_str());
438
439                 MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  
440                 MPI_File_get_size(inMPI, &size);
441                 //delete inFileName;
442
443                 char* buffer = new char[size];
444                 MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
445
446                 string tempBuf = buffer;
447                 delete buffer;
448
449                 if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
450                 istringstream iss (tempBuf,istringstream::in);
451                 
452                 while(!iss.eof()) {
453                         iss >> pos >> num;
454         
455                         if (h.count(pos) > 0) {
456                                 float Pi;
457                                 Pi =  (num - 0.25) / 0.75; 
458                         
459                                 //cannot have probability less than 0.
460                                 if (Pi < 0) { Pi = 0.0; }
461
462                                 //do you want this spot
463                                 prob.push_back(Pi);  
464                         }
465                         
466                         gobble(iss);
467                 }
468         
469                 MPI_File_close(&inMPI);
470                 
471         #else   
472
473                 ifstream in;
474                 openInputFile(consfile, in);
475                                 
476                 while(!in.eof()){
477                         
478                         in >> pos >> num;
479                         
480                         if (h.count(pos) > 0) {
481                                 float Pi;
482                                 Pi =  (num - 0.25) / 0.75; 
483                         
484                                 //cannot have probability less than 0.
485                                 if (Pi < 0) { Pi = 0.0; }
486
487                                 //do you want this spot
488                                 prob.push_back(Pi);  
489                         }
490                         
491                         gobble(in);
492                 }
493                 in.close();
494                 
495         #endif
496         
497                 return prob;
498                 
499         }
500         catch(exception& e) {
501                 m->errorOut(e, "Pintail", "readFreq");
502                 exit(1);
503         }
504 }
505
506 //***************************************************************************************************************
507 //calculate the distances from each query sequence to all sequences in the template to find the closest sequence
508 Sequence* Pintail::findPairs(Sequence* q) {
509         try {
510                 
511                 Sequence* seqsMatches;  
512                 
513                 seqsMatches = decalc->findClosest(q, templateSeqs);
514                 return seqsMatches;
515         
516         }
517         catch(exception& e) {
518                 m->errorOut(e, "Pintail", "findPairs");
519                 exit(1);
520         }
521 }
522 //**************************************************************************************************
523 void Pintail::createProcessesQuan() {
524         try {
525 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
526                 int process = 0;
527                 vector<int> processIDS;
528                                 
529                 //loop through and create all the processes you want
530                 while (process != processors) {
531                         int pid = fork();
532                         
533                         if (pid > 0) {
534                                 processIDS.push_back(pid);  
535                                 process++;
536                         }else if (pid == 0){
537                                 
538                                 quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, templateLines[process]->start, templateLines[process]->end);
539                                 
540                                 //write out data to file so parent can read it
541                                 ofstream out;
542                                 string s = toString(getpid()) + ".temp";
543                                 openOutputFile(s, out);
544                                 
545                                                                 
546                                 //output observed distances
547                                 for (int i = 0; i < quantilesMembers.size(); i++) {
548                                         out << quantilesMembers[i].size() << '\t';
549                                         for (int j = 0; j < quantilesMembers[i].size(); j++) {
550                                                 out << quantilesMembers[i][j] << '\t';
551                                         }
552                                         out << endl;
553                                 }
554                                 
555                                 out.close();
556                                 
557                                 exit(0);
558                         }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
559                 }
560                 
561                 //force parent to wait until all the processes are done
562                 for (int i=0;i<processors;i++) { 
563                         int temp = processIDS[i];
564                         wait(&temp);
565                 }
566
567                 //get data created by processes
568                 for (int i=0;i<processors;i++) { 
569                         ifstream in;
570                         string s = toString(processIDS[i]) + ".temp";
571                         openInputFile(s, in);
572                         
573                         vector< vector<float> > quan; 
574                         quan.resize(100);
575                         
576                         //get quantiles
577                         for (int h = 0; h < quan.size(); h++) {
578                                 int num;
579                                 in >> num; 
580                                 
581                                 gobble(in);
582
583                                 vector<float> q;  float w; 
584                                 for (int j = 0; j < num; j++) {
585                                         in >> w;
586                                         q.push_back(w);
587                                 }
588
589                                 quan[h] = q;
590                                 gobble(in);
591                         }
592                         
593         
594                         //save quan in quantiles
595                         for (int j = 0; j < quan.size(); j++) {
596                                 //put all values of q[i] into quan[i]
597                                 for (int l = 0; l < quan[j].size(); l++) {  quantilesMembers[j].push_back(quan[j][l]);   }
598                                 //quantilesMembers[j].insert(quantilesMembers[j].begin(), quan[j].begin(), quan[j].end());
599                         }
600                                         
601                         in.close();
602                         remove(s.c_str());
603                 }
604                 
605 #else
606                 quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, 0, templateSeqs.size());
607 #endif          
608         }
609         catch(exception& e) {
610                 m->errorOut(e, "Pintail", "createProcessesQuan");
611                 exit(1);
612         }
613 }
614 //***************************************************************************************************************
615 vector< vector<float> > Pintail::readQuantiles() {
616         try {
617                 int num; 
618                 float ten, twentyfive, fifty, seventyfive, ninetyfive, ninetynine; 
619                 
620                 vector< vector<float> > quan;
621                 vector <float> temp; temp.resize(6, 0);
622                 
623                 //to fill 0
624                 quan.push_back(temp); 
625
626         #ifdef USE_MPI
627                 
628                 MPI_File inMPI;
629                 MPI_Offset size;
630                 MPI_Status status;
631                 
632                 //char* inFileName = new char[quanfile.length()];
633                 //memcpy(inFileName, quanfile.c_str(), quanfile.length());
634                 
635                 char inFileName[1024];
636                 strcpy(inFileName, quanfile.c_str());
637
638                 MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  
639                 MPI_File_get_size(inMPI, &size);
640                 //delete inFileName;
641
642
643                 char* buffer = new char[size];
644                 MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
645
646                 string tempBuf = buffer;
647                 if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
648                 istringstream iss (tempBuf,istringstream::in);
649                 delete buffer;
650                 
651                 while(!iss.eof()) {
652                         iss >> num >> ten >> twentyfive >> fifty >> seventyfive >> ninetyfive >> ninetynine; 
653                         
654                         temp.clear();
655                         
656                         temp.push_back(ten); 
657                         temp.push_back(twentyfive);
658                         temp.push_back(fifty);
659                         temp.push_back(seventyfive);
660                         temp.push_back(ninetyfive);
661                         temp.push_back(ninetynine);
662                         
663                         quan.push_back(temp);  
664                         
665                         gobble(iss);
666                 }
667         
668                 MPI_File_close(&inMPI);
669                 
670         #else   
671
672                 ifstream in;
673                 openInputFile(quanfile, in);
674                         
675                 while(!in.eof()){
676                         
677                         in >> num >> ten >> twentyfive >> fifty >> seventyfive >> ninetyfive >> ninetynine; 
678                         
679                         temp.clear();
680                         
681                         temp.push_back(ten); 
682                         temp.push_back(twentyfive);
683                         temp.push_back(fifty);
684                         temp.push_back(seventyfive);
685                         temp.push_back(ninetyfive);
686                         temp.push_back(ninetynine);
687                         
688                         quan.push_back(temp);  
689         
690                         gobble(in);
691                 }
692                 in.close();
693         #endif
694         
695                 return quan;
696                 
697         }
698         catch(exception& e) {
699                 m->errorOut(e, "Pintail", "readQuantiles");
700                 exit(1);
701         }
702 }
703 //***************************************************************************************************************/
704
705 void Pintail::printQuanFile(string file, string outputString) {
706         try {
707         
708                 #ifdef USE_MPI
709                 
710                         MPI_File outQuan;
711                         MPI_Status status;
712                         
713                         int pid;
714                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
715
716                         int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
717
718                         //char* FileName = new char[file.length()];
719                         //memcpy(FileName, file.c_str(), file.length());
720                         
721                         char FileName[1024];
722                         strcpy(FileName, file.c_str());
723                         
724                         if (pid == 0) {
725                                 MPI_File_open(MPI_COMM_SELF, FileName, outMode, MPI_INFO_NULL, &outQuan);  //comm, filename, mode, info, filepointer
726                                 
727                                 int length = outputString.length();
728                                 char* buf = new char[length];
729                                 memcpy(buf, outputString.c_str(), length);
730                                         
731                                 MPI_File_write(outQuan, buf, length, MPI_CHAR, &status);
732                                 delete buf;
733
734                                 MPI_File_close(&outQuan);
735                         }
736
737                         //delete FileName;
738                 #else
739                         ofstream outQuan;
740                         openOutputFile(file, outQuan);
741                         
742                         outQuan << outputString;
743                         
744                         outQuan.close();
745                 #endif
746         }
747         catch(exception& e) {
748                 m->errorOut(e, "Pintail", "printQuanFile");
749                 exit(1);
750         }
751 }
752
753 //***************************************************************************************************************/
754
755
756