]> git.donarmstrong.com Git - mothur.git/blobdiff - deconvolutecommand.cpp
This is v.1.4.0
[mothur.git] / deconvolutecommand.cpp
index 2fe7a251ca41a5d833ad7f643970a1d9847a8361..fba2d27ebf470c968f50f64c71c54917f0e8f5df 100644 (file)
@@ -19,7 +19,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta"};
+                       string Array[] =  {"fasta", "name"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -33,10 +33,13 @@ DeconvoluteCommand::DeconvoluteCommand(string option) {
                        }
                        
                        //check for required parameters
-                       filename = validParameter.validFile(parameters, "fasta", true);
-                       if (filename == "not open") { abort = true; }
-                       else if (filename == "not found") { filename = ""; cout << "fasta is a required parameter for the unique.seqs command." << endl; abort = true;  }       
+                       inFastaName = validParameter.validFile(parameters, "fasta", true);
+                       if (inFastaName == "not open") { abort = true; }
+                       else if (inFastaName == "not found") { inFastaName = ""; cout << "fasta is a required parameter for the unique.seqs command." << endl; abort = true;  } 
                        
+                       oldNameMapFName = validParameter.validFile(parameters, "name", true);
+                       if (oldNameMapFName == "not open") { abort = true; }
+                       else if (oldNameMapFName == "not found"){       oldNameMapFName = "";   }
                }
 
        }
@@ -75,31 +78,19 @@ int DeconvoluteCommand::execute() {
        try {
                
                if (abort == true) { return 0; }
-       
+
                //prepare filenames and open files
-               outputFileName = (getRootName(filename) + "names");
-               outFastafile = (getRootName(filename) + "unique.fasta");
+               string outNameFile = (getRootName(inFastaName) + "names");
+               string outFastaFile = (getRootName(inFastaName) + "unique" + getExtension(inFastaName));
                
-               openInputFile(filename, in);
-               openOutputFile(outputFileName, out);
-               openOutputFile(outFastafile, outFasta);
-
-               //constructor reads in file and store internally
-               fastamap = new FastaMap();
+               FastaMap fastamap;
        
-               //two columns separated by tabs sequence name and then sequence
-               fastamap->readFastaFile(in);
+               if(oldNameMapFName == "")       {       fastamap.readFastaFile(inFastaName);                                    }
+               else                                            {       fastamap.readFastaFile(inFastaName, oldNameMapFName);   }
                
-               //print out new names file 
-               //file contains 2 columns separated by tabs.  the first column is the groupname(name of first sequence found.
-               //the second column is the list of names of identical sequences separated by ','.
-               fastamap->printNamesFile(out);
-               fastamap->printCondensedFasta(outFasta);
+               fastamap.printCondensedFasta(outFastaFile);
+               fastamap.printNamesFile(outNameFile);
                
-               in.close();
-               out.close();
-               outFasta.close();
-       
                return 0;
        }
        catch(exception& e) {