]> git.donarmstrong.com Git - mothur.git/blob - aligncommand.cpp
working on chimeras
[mothur.git] / aligncommand.cpp
1 /*
2  *  aligncommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 5/15/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  *      This version of nast does everything I think that the greengenes nast server does and then some.  I have added the 
9  *      feature of allowing users to define their database, kmer size for searching, alignment penalty values and alignment 
10  *      method.  This latter feature is perhaps most significant.  nastPlus enables a user to use either a Needleman-Wunsch 
11  *      (non-affine gap penalty) or Gotoh (affine gap penalty) pairwise alignment algorithm.  This is significant because it
12  *      allows for a global alignment and not the local alignment provided by bLAst.  Furthermore, it has the potential to
13  *      provide a better alignment because of the banding method employed by blast (I'm not sure about this).
14  *
15  */
16
17 #include "aligncommand.h"
18 #include "sequence.hpp"
19
20 #include "gotohoverlap.hpp"
21 #include "needlemanoverlap.hpp"
22 #include "blastalign.hpp"
23 #include "noalign.hpp"
24
25 #include "nast.hpp"
26 #include "nastreport.hpp"
27
28
29 //**********************************************************************************************************************
30
31 AlignCommand::AlignCommand(string option){
32         try {
33                 //              globaldata = GlobalData::getInstance();
34                 abort = false;
35                 
36                 //allow user to run help
37                 if(option == "help") { help(); abort = true; }
38                 
39                 else {
40                         
41                         //valid paramters for this command
42                         string AlignArray[] =  {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"};
43                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
44                         
45                         OptionParser parser(option);
46                         map<string, string> parameters = parser.getParameters(); 
47                         
48                         ValidParameters validParameter;
49                         map<string, string>::iterator it;
50                         
51                         //check to make sure all parameters are valid for command
52                         for (it = parameters.begin(); it != parameters.end(); it++) { 
53                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
54                         }
55
56                         //if the user changes the output directory command factory will send this info to us in the output parameter 
57                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
58                         
59
60                         //if the user changes the input directory command factory will send this info to us in the output parameter 
61                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
62                         
63                         if (inputDir == "not found"){   inputDir = "";          }
64                         else {
65                                 string path;
66
67                                 it = parameters.find("template");
68
69                                 //user has given a template file
70                                 if(it != parameters.end()){ 
71                                         path = hasPath(it->second);
72                                         //if the user has not given a path then, add inputdir. else leave path alone.
73                                         if (path == "") {       parameters["template"] = inputDir + it->second;         }
74                                 }
75                         }
76
77                         //check for required parameters
78                         templateFileName = validParameter.validFile(parameters, "template", true);
79                         
80                         if (templateFileName == "not found") { 
81                                 mothurOut("template is a required parameter for the align.seqs command."); 
82                                 mothurOutEndLine();
83                                 abort = true; 
84                         }else if (templateFileName == "not open") { abort = true; }     
85                         
86                         candidateFileName = validParameter.validFile(parameters, "candidate", false);
87                         if (candidateFileName == "not found") { mothurOut("candidate is a required parameter for the align.seqs command."); mothurOutEndLine(); abort = true;  }
88                         else { 
89                                 splitAtDash(candidateFileName, candidateFileNames);
90                                 
91                                 //go through files and make sure they are good, if not, then disregard them
92                                 for (int i = 0; i < candidateFileNames.size(); i++) {
93                                         if (inputDir != "") {
94                                                 string path = hasPath(candidateFileNames[i]);
95                                                 //if the user has not given a path then, add inputdir. else leave path alone.
96                                                 if (path == "") {       candidateFileNames[i] = inputDir + candidateFileNames[i];               }
97                                         }
98
99                                         int ableToOpen;
100                                         ifstream in;
101                                         ableToOpen = openInputFile(candidateFileNames[i], in);
102                                         if (ableToOpen == 1) { 
103                                                 mothurOut(candidateFileNames[i] + " will be disregarded."); mothurOutEndLine(); 
104                                                 //erase from file list
105                                                 candidateFileNames.erase(candidateFileNames.begin()+i);
106                                                 i--;
107                                         }
108                                         in.close();
109                                 }
110                                 
111                                 //make sure there is at least one valid file left
112                                 if (candidateFileNames.size() == 0) { mothurOut("no valid files."); mothurOutEndLine(); abort = true; }
113                         }
114                         
115                         //check for optional parameter and set defaults
116                         // ...at some point should added some additional type checking...
117                         string temp;
118                         temp = validParameter.validFile(parameters, "ksize", false);            if (temp == "not found"){       temp = "8";                             }
119                         convert(temp, kmerSize); 
120                         
121                         temp = validParameter.validFile(parameters, "match", false);            if (temp == "not found"){       temp = "1.0";                   }
122                         convert(temp, match);  
123                         
124                         temp = validParameter.validFile(parameters, "mismatch", false);         if (temp == "not found"){       temp = "-1.0";                  }
125                         convert(temp, misMatch);  
126                         
127                         temp = validParameter.validFile(parameters, "gapopen", false);          if (temp == "not found"){       temp = "-2.0";                  }
128                         convert(temp, gapOpen);  
129                         
130                         temp = validParameter.validFile(parameters, "gapextend", false);        if (temp == "not found"){       temp = "-1.0";                  }
131                         convert(temp, gapExtend); 
132                         
133                         temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = "1";                             }
134                         convert(temp, processors); 
135                         
136                         temp = validParameter.validFile(parameters, "flip", false);                     if (temp == "not found"){       temp = "f";                             }
137                         flip = isTrue(temp); 
138                         
139                         temp = validParameter.validFile(parameters, "threshold", false);        if (temp == "not found"){       temp = "0.50";                  }
140                         convert(temp, threshold); 
141                         
142                         search = validParameter.validFile(parameters, "search", false);         if (search == "not found"){     search = "kmer";                }
143                         
144                         align = validParameter.validFile(parameters, "align", false);           if (align == "not found"){      align = "needleman";    }
145                 }
146                 
147         }
148         catch(exception& e) {
149                 errorOut(e, "AlignCommand", "AlignCommand");
150                 exit(1);
151         }
152 }
153
154 //**********************************************************************************************************************
155
156 AlignCommand::~AlignCommand(){  
157
158         if (abort == false) {
159                 for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
160                 delete templateDB;
161                 delete alignment;
162         }
163 }
164
165 //**********************************************************************************************************************
166
167 void AlignCommand::help(){
168         try {
169                 mothurOut("The align.seqs command reads a file containing sequences and creates an alignment file and a report file.\n");
170                 mothurOut("The align.seqs command parameters are template, candidate, search, ksize, align, match, mismatch, gapopen and gapextend.\n");
171                 mothurOut("The template and candidate parameters are required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n");
172                 mothurOut("The search parameter allows you to specify the method to find most similar template.  Your options are: suffix, kmer and blast. The default is kmer.\n");
173                 mothurOut("The align parameter allows you to specify the alignment method to use.  Your options are: gotoh, needleman, blast and noalign. The default is needleman.\n");
174                 mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate.  The default is 8.\n");
175                 mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n");
176                 mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases.  The default is -1.0.\n");
177                 mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n");
178                 mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment.  The default is -1.0.\n");
179                 mothurOut("The flip parameter is used to specify whether or not you want mothur to try the reverse complement if a sequence falls below the threshold.  The default is false.\n");
180                 mothurOut("The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. The default threshold is 0.50, meaning 50% of the bases are removed in the alignment.\n");
181                 mothurOut("If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n");
182                 mothurOut("The default for the threshold parameter is 0.50, meaning at least 50% of the bases must remain or the sequence is reported as potentially reversed.\n");
183                 mothurOut("The align.seqs command should be in the following format: \n");
184                 mothurOut("align.seqs(template=yourTemplateFile, candidate=yourCandidateFile, align=yourAlignmentMethod, search=yourSearchmethod, ksize=yourKmerSize, match=yourMatchBonus, mismatch=yourMismatchpenalty, gapopen=yourGapopenPenalty, gapextend=yourGapExtendPenalty) \n");
185                 mothurOut("Example align.seqs(candidate=candidate.fasta, template=core.filtered, align=kmer, search=gotoh, ksize=8, match=2.0, mismatch=3.0, gapopen=-2.0, gapextend=-1.0)\n");
186                 mothurOut("Note: No spaces between parameter labels (i.e. candidate), '=' and parameters (i.e.yourFastaFile).\n\n");
187         }
188         catch(exception& e) {
189                 errorOut(e, "AlignCommand", "help");
190                 exit(1);
191         }
192 }
193
194
195 //**********************************************************************************************************************
196
197 int AlignCommand::execute(){
198         try {
199                 if (abort == true) {    return 0;       }
200                 
201                 templateDB = new AlignmentDB(templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch);
202                 int longestBase = templateDB->getLongestBase();
203         
204                 if(align == "gotoh")                    {       alignment = new GotohOverlap(gapOpen, gapExtend, match, misMatch, longestBase);                 }
205                 else if(align == "needleman")   {       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);                                }
206                 else if(align == "blast")               {       alignment = new BlastAlignment(gapOpen, gapExtend, match, misMatch);            }
207                 else if(align == "noalign")             {       alignment = new NoAlign();                                                                                                      }
208                 else {
209                         mothurOut(align + " is not a valid alignment option. I will run the command using needleman.");
210                         mothurOutEndLine();
211                         alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase);
212                 }
213                 
214                 for (int s = 0; s < candidateFileNames.size(); s++) {
215                         mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); mothurOutEndLine();
216                         
217                         if (outputDir == "") {  outputDir += hasPath(candidateFileNames[s]); }
218                         string alignFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align";
219                         string reportFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align.report";
220                         string accnosFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "flip.accnos";
221                         bool hasAccnos = true;
222                         
223                         int numFastaSeqs = 0;
224                         for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
225                         int start = time(NULL);
226                         
227 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
228                         if(processors == 1){
229                                 ifstream inFASTA;
230                                 openInputFile(candidateFileNames[s], inFASTA);
231                                 numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
232                                 inFASTA.close();
233                                 
234                                 lines.push_back(new linePair(0, numFastaSeqs));
235                                 
236                                 driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
237                                 
238                                 //delete accnos file if its blank else report to user
239                                 if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  }
240                                 else { 
241                                         mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + ".");
242                                         if (!flip) {
243                                                 mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); 
244                                         }else{  mothurOut(" If the reverse compliment proved to be better it was reported.");  }
245                                         mothurOutEndLine();
246                                 }
247                         }
248                         else{
249                                 vector<int> positions;
250                                 processIDS.resize(0);
251                                 
252                                 ifstream inFASTA;
253                                 openInputFile(candidateFileNames[s], inFASTA);
254                                 
255                                 string input;
256                                 while(!inFASTA.eof()){
257                                         input = getline(inFASTA);
258                                         if (input.length() != 0) {
259                                                 if(input[0] == '>'){    long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1);  }
260                                         }
261                                 }
262                                 inFASTA.close();
263                                 
264                                 numFastaSeqs = positions.size();
265                                 
266                                 int numSeqsPerProcessor = numFastaSeqs / processors;
267                                 
268                                 for (int i = 0; i < processors; i++) {
269                                         long int startPos = positions[ i * numSeqsPerProcessor ];
270                                         if(i == processors - 1){
271                                                 numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
272                                         }
273                                         lines.push_back(new linePair(startPos, numSeqsPerProcessor));
274                                 }
275                                 
276                                 createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
277                                 
278                                 rename((alignFileName + toString(processIDS[0]) + ".temp").c_str(), alignFileName.c_str());
279                                 rename((reportFileName + toString(processIDS[0]) + ".temp").c_str(), reportFileName.c_str());
280                                 
281                                 //append alignment and report files
282                                 for(int i=1;i<processors;i++){
283                                         appendAlignFiles((alignFileName + toString(processIDS[i]) + ".temp"), alignFileName);
284                                         remove((alignFileName + toString(processIDS[i]) + ".temp").c_str());
285                                         
286                                         appendReportFiles((reportFileName + toString(processIDS[i]) + ".temp"), reportFileName);
287                                         remove((reportFileName + toString(processIDS[i]) + ".temp").c_str());
288                                 }
289                                 
290                                 vector<string> nonBlankAccnosFiles;
291                                 //delete blank accnos files generated with multiple processes
292                                 for(int i=0;i<processors;i++){  
293                                         if (!(isBlank(accnosFileName + toString(processIDS[i]) + ".temp"))) {
294                                                 nonBlankAccnosFiles.push_back(accnosFileName + toString(processIDS[i]) + ".temp");
295                                         }else { remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str());  }
296                                 }
297                                 
298                                 //append accnos files
299                                 if (nonBlankAccnosFiles.size() != 0) { 
300                                         rename(nonBlankAccnosFiles[0].c_str(), accnosFileName.c_str());
301                                         
302                                         for (int h=1; h < nonBlankAccnosFiles.size(); h++) {
303                                                 appendAlignFiles(nonBlankAccnosFiles[h], accnosFileName);
304                                                 remove(nonBlankAccnosFiles[h].c_str());
305                                         }
306                                         mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + ".");
307                                         if (!flip) {
308                                                 mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); 
309                                         }else{  mothurOut(" If the reverse compliment proved to be better it was reported.");  }
310                                         mothurOutEndLine();
311                                 }else{ hasAccnos = false;  }
312                         }
313 #else
314                         ifstream inFASTA;
315                         openInputFile(candidateFileNames[s], inFASTA);
316                         numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
317                         inFASTA.close();
318                         
319                         lines.push_back(new linePair(0, numFastaSeqs));
320                         
321                         driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
322                         
323                         //delete accnos file if its blank else report to user
324                         if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
325                         else { 
326                                 mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + ".");
327                                 if (!flip) {
328                                         mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); 
329                                 }else{  mothurOut(" If the reverse compliment proved to be better it was reported.");  }
330                                 mothurOutEndLine();
331                         }
332                         
333 #endif
334                         
335                         mothurOut("Output File Names: " + alignFileName + ", " + reportFileName);
336                         if (hasAccnos)  {       mothurOut(", " + accnosFileName + ".");         }
337                         else                    {       mothurOut(".");                                                         }
338                         mothurOutEndLine();
339                         
340                         mothurOut("It took " + toString(time(NULL) - start) + " secs to align " + toString(numFastaSeqs) + " sequences.");
341                         mothurOutEndLine();
342                         mothurOutEndLine();
343                 }
344                 
345                 return 0;
346         }
347         catch(exception& e) {
348                 errorOut(e, "AlignCommand", "execute");
349                 exit(1);
350         }
351 }
352
353 //**********************************************************************************************************************
354
355 int AlignCommand::driver(linePair* line, string alignFName, string reportFName, string accnosFName, string filename){
356         try {
357                 ofstream alignmentFile;
358                 openOutputFile(alignFName, alignmentFile);
359                 
360                 ofstream accnosFile;
361                 openOutputFile(accnosFName, accnosFile);
362                 
363                 NastReport report(reportFName);
364                 
365                 ifstream inFASTA;
366                 openInputFile(filename, inFASTA);
367
368                 inFASTA.seekg(line->start);
369                 
370                 for(int i=0;i<line->numSeqs;i++){
371                 
372                         Sequence* candidateSeq = new Sequence(inFASTA);  gobble(inFASTA);
373                         int origNumBases = candidateSeq->getNumBases();
374                         string originalUnaligned = candidateSeq->getUnaligned();
375                         int numBasesNeeded = origNumBases * threshold;
376         
377                         if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
378                                 if (candidateSeq->getUnaligned().length() > alignment->getnRows()) {
379                                         alignment->resize(candidateSeq->getUnaligned().length()+1);
380                                 }
381                                                                 
382                                 Sequence temp = templateDB->findClosestSequence(candidateSeq);
383                                 Sequence* templateSeq = &temp;
384                                 
385                                 float searchScore = templateDB->getSearchScore();
386                                                                 
387                                 Nast* nast = new Nast(alignment, candidateSeq, templateSeq);
388                                 Sequence* copy;
389                                 
390                                 Nast* nast2;
391                                 bool needToDeleteCopy = false;  //this is needed in case you have you enter the ifs below
392                                                                                                 //since nast does not make a copy of hte sequence passed, and it is used by the reporter below
393                                                                                                 //you can't delete the copy sequence til after you report, but you may choose not to create it in the first place
394                                                                                                 //so this bool tells you if you need to delete it
395                                                                                                 
396                                 //if there is a possibility that this sequence should be reversed
397                                 if (candidateSeq->getNumBases() < numBasesNeeded) {
398                                         
399                                         string wasBetter = "";
400                                         //if the user wants you to try the reverse
401                                         if (flip) {
402                                                 //get reverse compliment
403                                                 copy = new Sequence(candidateSeq->getName(), originalUnaligned);
404                                                 copy->reverseComplement();
405                                                 
406                                                 //rerun alignment
407                                                 Sequence temp2 = templateDB->findClosestSequence(copy);
408                                                 Sequence* templateSeq2 = &temp2;
409                                                 
410                                                 searchScore = templateDB->getSearchScore();
411                                                 
412                                                 nast2 = new Nast(alignment, copy, templateSeq2);
413                         
414                                                 //check if any better
415                                                 if (copy->getNumBases() > candidateSeq->getNumBases()) {
416                                                         candidateSeq->setAligned(copy->getAligned());  //use reverse compliments alignment since its better
417                                                         templateSeq = templateSeq2; 
418                                                         delete nast;
419                                                         nast = nast2;
420                                                         needToDeleteCopy = true;
421                                                 }else{  
422                                                         wasBetter = "\treverse complement did NOT produce a better alignment, please check sequence.";
423                                                         delete nast2;
424                                                         delete copy;    
425                                                 }
426                                         }
427                                         
428                                         //create accnos file with names
429                                         accnosFile << candidateSeq->getName() << wasBetter << endl;
430                                 }
431                                 
432                                 report.setCandidate(candidateSeq);
433                                 report.setTemplate(templateSeq);
434                                 report.setSearchParameters(search, searchScore);
435                                 report.setAlignmentParameters(align, alignment);
436                                 report.setNastParameters(*nast);
437         
438                                 alignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
439                                 
440                                 report.print();
441                                 delete nast;
442                                 if (needToDeleteCopy) {   delete copy;   }
443                         }
444                         delete candidateSeq;
445                         
446                         //report progress
447                         if((i+1) % 100 == 0){   mothurOut(toString(i+1)); mothurOutEndLine();           }
448                 }
449                 //report progress
450                 if((line->numSeqs) % 100 != 0){ mothurOut(toString(line->numSeqs)); mothurOutEndLine();         }
451                 
452                 alignmentFile.close();
453                 inFASTA.close();
454                 accnosFile.close();
455                 
456                 return 1;
457         }
458         catch(exception& e) {
459                 errorOut(e, "AlignCommand", "driver");
460                 exit(1);
461         }
462 }
463
464 /**************************************************************************************************/
465
466 void AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
467         try {
468 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
469                 int process = 0;
470                 //              processIDS.resize(0);
471                 
472                 //loop through and create all the processes you want
473                 while (process != processors) {
474                         int pid = fork();
475                         
476                         if (pid > 0) {
477                                 processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
478                                 process++;
479                         }else if (pid == 0){
480                                 driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
481                                 exit(0);
482                         }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); }
483                 }
484                 
485                 //force parent to wait until all the processes are done
486                 for (int i=0;i<processors;i++) { 
487                         int temp = processIDS[i];
488                         wait(&temp);
489                 }
490 #endif          
491         }
492         catch(exception& e) {
493                 errorOut(e, "AlignCommand", "createProcesses");
494                 exit(1);
495         }
496 }
497
498 /**************************************************************************************************/
499
500 void AlignCommand::appendAlignFiles(string temp, string filename) {
501         try{
502                 
503                 ofstream output;
504                 ifstream input;
505                 openOutputFileAppend(filename, output);
506                 openInputFile(temp, input);
507                 
508                 while(char c = input.get()){
509                         if(input.eof())         {       break;                  }
510                         else                            {       output << c;    }
511                 }
512                 
513                 input.close();
514                 output.close();
515         }
516         catch(exception& e) {
517                 errorOut(e, "AlignCommand", "appendAlignFiles");
518                 exit(1);
519         }
520 }
521 //**********************************************************************************************************************
522
523 void AlignCommand::appendReportFiles(string temp, string filename) {
524         try{
525                 
526                 ofstream output;
527                 ifstream input;
528                 openOutputFileAppend(filename, output);
529                 openInputFile(temp, input);
530
531                 while (!input.eof())    {       char c = input.get(); if (c == 10 || c == 13){  break;  }       } // get header line
532                                 
533                 while(char c = input.get()){
534                         if(input.eof())         {       break;                  }
535                         else                            {       output << c;    }
536                 }
537                 
538                 input.close();
539                 output.close();
540         }
541         catch(exception& e) {
542                 errorOut(e, "AlignCommand", "appendReportFiles");
543                 exit(1);
544         }
545 }
546
547 //**********************************************************************************************************************