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