]> git.donarmstrong.com Git - mothur.git/blob - sffinfocommand.cpp
Revert to previous commit
[mothur.git] / sffinfocommand.cpp
1 /*
2  *  sffinfocommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 7/7/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "sffinfocommand.h"
11 #include "endiannessmacros.h"
12
13 //**********************************************************************************************************************
14 vector<string> SffInfoCommand::setParameters(){ 
15         try {           
16                 CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff);
17                 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
18                 CommandParameter psfftxt("sfftxt", "String", "", "", "", "", "",false,false); parameters.push_back(psfftxt);
19                 CommandParameter pflow("flow", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pflow);
20                 CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(ptrim);
21                 CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pfasta);
22                 CommandParameter pqfile("name", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pqfile);
23                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
24                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
25                 
26                 vector<string> myArray;
27                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
28                 return myArray;
29         }
30         catch(exception& e) {
31                 m->errorOut(e, "SffInfoCommand", "setParameters");
32                 exit(1);
33         }
34 }
35 //**********************************************************************************************************************
36 string SffInfoCommand::getHelpString(){ 
37         try {
38                 string helpString = "";
39                 helpString += "The sffinfo command reads a sff file and extracts the sequence data, or you can use it to parse a sfftxt file.\n";
40                 helpString += "The sffinfo command parameters are sff, fasta, qfile, accnos, flow, sfftxt, and trim. sff is required. \n";
41                 helpString += "The sff parameter allows you to enter the sff file you would like to extract data from.  You may enter multiple files by separating them by -'s.\n";
42                 helpString += "The fasta parameter allows you to indicate if you would like a fasta formatted file generated.  Default=True. \n";
43                 helpString += "The qfile parameter allows you to indicate if you would like a quality file generated.  Default=True. \n";
44                 helpString += "The flow parameter allows you to indicate if you would like a flowgram file generated.  Default=True. \n";
45                 helpString += "The sfftxt parameter allows you to indicate if you would like a sff.txt file generated.  Default=False. \n";
46                 helpString += "If you want to parse an existing sfftxt file into flow, fasta and quality file, enter the file name using the sfftxt parameter. \n";
47                 helpString += "The trim parameter allows you to indicate if you would like a sequences and quality scores trimmed to the clipQualLeft and clipQualRight values.  Default=True. \n";
48                 helpString += "The accnos parameter allows you to provide a accnos file containing the names of the sequences you would like extracted. You may enter multiple files by separating them by -'s. \n";
49                 helpString += "Example sffinfo(sff=mySffFile.sff, trim=F).\n";
50                 helpString += "Note: No spaces between parameter labels (i.e. sff), '=' and parameters (i.e.yourSffFileName).\n";
51                 return helpString;
52         }
53         catch(exception& e) {
54                 m->errorOut(e, "SffInfoCommand", "getHelpString");
55                 exit(1);
56         }
57 }
58
59
60 //**********************************************************************************************************************
61 SffInfoCommand::SffInfoCommand(){       
62         try {
63                 abort = true; calledHelp = true; 
64                 setParameters();
65                 vector<string> tempOutNames;
66                 outputTypes["fasta"] = tempOutNames;
67                 outputTypes["flow"] = tempOutNames;
68                 outputTypes["sfftxt"] = tempOutNames;
69                 outputTypes["qfile"] = tempOutNames;
70         }
71         catch(exception& e) {
72                 m->errorOut(e, "SffInfoCommand", "SffInfoCommand");
73                 exit(1);
74         }
75 }
76 //**********************************************************************************************************************
77
78 SffInfoCommand::SffInfoCommand(string option)  {
79         try {
80                 abort = false; calledHelp = false;   
81                 hasAccnos = false;
82                 
83                 //allow user to run help
84                 if(option == "help") { help(); abort = true; calledHelp = true; }
85                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
86                 
87                 else {
88                         //valid paramters for this command
89                         vector<string> myArray = setParameters();
90                         
91                         OptionParser parser(option);
92                         map<string, string> parameters = parser.getParameters();
93                         
94                         ValidParameters validParameter;
95                         //check to make sure all parameters are valid for command
96                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
97                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
98                         }
99                         
100                         //initialize outputTypes
101                         vector<string> tempOutNames;
102                         outputTypes["fasta"] = tempOutNames;
103                         outputTypes["flow"] = tempOutNames;
104                         outputTypes["sfftxt"] = tempOutNames;
105                         outputTypes["qfile"] = tempOutNames;
106                         
107                         //if the user changes the output directory command factory will send this info to us in the output parameter 
108                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
109                         
110                         //if the user changes the input directory command factory will send this info to us in the output parameter 
111                         string inputDir = validParameter.validFile(parameters, "inputdir", false);        if (inputDir == "not found"){ inputDir = "";          }
112
113                         sffFilename = validParameter.validFile(parameters, "sff", false);
114                         if (sffFilename == "not found") { sffFilename = "";  }
115                         else { 
116                                 m->splitAtDash(sffFilename, filenames);
117                                 
118                                 //go through files and make sure they are good, if not, then disregard them
119                                 for (int i = 0; i < filenames.size(); i++) {
120                                         bool ignore = false;
121                                         if (filenames[i] == "current") { 
122                                                 filenames[i] = m->getSFFFile(); 
123                                                 if (filenames[i] != "") {  m->mothurOut("Using " + filenames[i] + " as input file for the sff parameter where you had given current."); m->mothurOutEndLine(); }
124                                                 else {  
125                                                         m->mothurOut("You have no current sfffile, ignoring current."); m->mothurOutEndLine(); ignore=true; 
126                                                         //erase from file list
127                                                         filenames.erase(filenames.begin()+i);
128                                                         i--;
129                                                 }
130                                         }
131                                         
132                                         if (!ignore) {
133                                                 if (inputDir != "") {
134                                                         string path = m->hasPath(filenames[i]);
135                                                         //if the user has not given a path then, add inputdir. else leave path alone.
136                                                         if (path == "") {       filenames[i] = inputDir + filenames[i];         }
137                                                 }
138                 
139                                                 ifstream in;
140                                                 int ableToOpen = m->openInputFile(filenames[i], in, "noerror");
141                                         
142                                                 //if you can't open it, try default location
143                                                 if (ableToOpen == 1) {
144                                                         if (m->getDefaultPath() != "") { //default path is set
145                                                                 string tryPath = m->getDefaultPath() + m->getSimpleName(filenames[i]);
146                                                                 m->mothurOut("Unable to open " + filenames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
147                                                                 ifstream in2;
148                                                                 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
149                                                                 in2.close();
150                                                                 filenames[i] = tryPath;
151                                                         }
152                                                 }
153                                                 
154                                                 //if you can't open it, try default location
155                                                 if (ableToOpen == 1) {
156                                                         if (m->getOutputDir() != "") { //default path is set
157                                                                 string tryPath = m->getOutputDir() + m->getSimpleName(filenames[i]);
158                                                                 m->mothurOut("Unable to open " + filenames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
159                                                                 ifstream in2;
160                                                                 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
161                                                                 in2.close();
162                                                                 filenames[i] = tryPath;
163                                                         }
164                                                 }
165                                                 
166                                                 in.close();
167                                                 
168                                                 if (ableToOpen == 1) { 
169                                                         m->mothurOut("Unable to open " + filenames[i] + ". It will be disregarded."); m->mothurOutEndLine();
170                                                         //erase from file list
171                                                         filenames.erase(filenames.begin()+i);
172                                                         i--;
173                                                 }else { m->setSFFFile(filenames[i]); }
174                                         }
175                                 }
176                                 
177                                 //make sure there is at least one valid file left
178                                 if (filenames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
179                         }
180                         
181                         accnosName = validParameter.validFile(parameters, "accnos", false);
182                         if (accnosName == "not found") { accnosName = "";  }
183                         else { 
184                                 hasAccnos = true;
185                                 m->splitAtDash(accnosName, accnosFileNames);
186                                 
187                                 //go through files and make sure they are good, if not, then disregard them
188                                 for (int i = 0; i < accnosFileNames.size(); i++) {
189                                         bool ignore = false;
190                                         if (accnosFileNames[i] == "current") { 
191                                                 accnosFileNames[i] = m->getAccnosFile(); 
192                                                 if (accnosFileNames[i] != "") {  m->mothurOut("Using " + accnosFileNames[i] + " as input file for the accnos parameter where you had given current."); m->mothurOutEndLine(); }
193                                                 else {  
194                                                         m->mothurOut("You have no current accnosfile, ignoring current."); m->mothurOutEndLine(); ignore=true; 
195                                                         //erase from file list
196                                                         accnosFileNames.erase(accnosFileNames.begin()+i);
197                                                         i--;
198                                                 }
199                                         }
200                                         
201                                         if (!ignore) {
202                                         
203                                                 if (inputDir != "") {
204                                                         string path = m->hasPath(accnosFileNames[i]);
205                                                         //if the user has not given a path then, add inputdir. else leave path alone.
206                                                         if (path == "") {       accnosFileNames[i] = inputDir + accnosFileNames[i];             }
207                                                 }
208                 
209                                                 ifstream in;
210                                                 int ableToOpen = m->openInputFile(accnosFileNames[i], in, "noerror");
211                                         
212                                                 //if you can't open it, try default location
213                                                 if (ableToOpen == 1) {
214                                                         if (m->getDefaultPath() != "") { //default path is set
215                                                                 string tryPath = m->getDefaultPath() + m->getSimpleName(accnosFileNames[i]);
216                                                                 m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
217                                                                 ifstream in2;
218                                                                 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
219                                                                 in2.close();
220                                                                 accnosFileNames[i] = tryPath;
221                                                         }
222                                                 }
223                                                 //if you can't open it, try default location
224                                                 if (ableToOpen == 1) {
225                                                         if (m->getOutputDir() != "") { //default path is set
226                                                                 string tryPath = m->getOutputDir() + m->getSimpleName(accnosFileNames[i]);
227                                                                 m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
228                                                                 ifstream in2;
229                                                                 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
230                                                                 in2.close();
231                                                                 accnosFileNames[i] = tryPath;
232                                                         }
233                                                 }
234                                                 in.close();
235                                                 
236                                                 if (ableToOpen == 1) { 
237                                                         m->mothurOut("Unable to open " + accnosFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
238                                                         //erase from file list
239                                                         accnosFileNames.erase(accnosFileNames.begin()+i);
240                                                         i--;
241                                                 }
242                                         }
243                                 }
244                                 
245                                 //make sure there is at least one valid file left
246                                 if (accnosFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
247                         }
248                         
249                         if (hasAccnos) {
250                                 if (accnosFileNames.size() != filenames.size()) { abort = true; m->mothurOut("If you provide a accnos file, you must have one for each sff file."); m->mothurOutEndLine(); }
251                         }
252                         
253                         string temp = validParameter.validFile(parameters, "qfile", false);                     if (temp == "not found"){       temp = "T";                             }
254                         qual = m->isTrue(temp); 
255                         
256                         temp = validParameter.validFile(parameters, "fasta", false);                            if (temp == "not found"){       temp = "T";                             }
257                         fasta = m->isTrue(temp); 
258                         
259                         temp = validParameter.validFile(parameters, "flow", false);                                     if (temp == "not found"){       temp = "T";                             }
260                         flow = m->isTrue(temp); 
261                         
262                         temp = validParameter.validFile(parameters, "trim", false);                                     if (temp == "not found"){       temp = "T";                             }
263                         trim = m->isTrue(temp); 
264                         
265                         temp = validParameter.validFile(parameters, "sfftxt", false);                           
266                         if (temp == "not found")        {       temp = "F";      sfftxt = false; sfftxtFilename = "";           }
267                         else if (m->isTrue(temp))       {       sfftxt = true;          sfftxtFilename = "";                            }
268                         else {
269                                 //you are a filename
270                                 if (inputDir != "") {
271                                         map<string,string>::iterator it = parameters.find("sfftxt");
272                                         //user has given a template file
273                                         if(it != parameters.end()){ 
274                                                 string path = m->hasPath(it->second);
275                                                 //if the user has not given a path then, add inputdir. else leave path alone.
276                                                 if (path == "") {       parameters["sfftxt"] = inputDir + it->second;           }
277                                         }
278                                 }
279                                 
280                                 sfftxtFilename = validParameter.validFile(parameters, "sfftxt", true);
281                                 if (sfftxtFilename == "not found") { sfftxtFilename = "";  }
282                                 else if (sfftxtFilename == "not open") { sfftxtFilename = "";  }
283                         }
284                         
285                         if ((sfftxtFilename == "") && (filenames.size() == 0)) {  
286                                 //if there is a current sff file, use it
287                                 string filename = m->getSFFFile(); 
288                                 if (filename != "") { filenames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the sff parameter."); m->mothurOutEndLine(); }
289                                 else {  m->mothurOut("[ERROR]: you must provide a valid sff or sfftxt file."); m->mothurOutEndLine(); abort=true;  }
290                         }
291                 }
292         }
293         catch(exception& e) {
294                 m->errorOut(e, "SffInfoCommand", "SffInfoCommand");
295                 exit(1);
296         }
297 }
298 //**********************************************************************************************************************
299 int SffInfoCommand::execute(){
300         try {
301                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
302                 
303                 for (int s = 0; s < filenames.size(); s++) {
304                         
305                         if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]);        } return 0; }
306                         
307                         int start = time(NULL);
308                         
309                         m->mothurOut("Extracting info from " + filenames[s] + " ..." ); m->mothurOutEndLine();
310                         
311                         string accnos = "";
312                         if (hasAccnos) { accnos = accnosFileNames[s]; }
313                         
314                         int numReads = extractSffInfo(filenames[s], accnos);
315
316                         m->mothurOut("It took " + toString(time(NULL) - start) + " secs to extract " + toString(numReads) + ".");
317                 }
318                 
319                 if (sfftxtFilename != "") {  parseSffTxt(); }
320                 
321                 if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]);        } return 0; }
322                 
323                 //set fasta file as new current fastafile
324                 string current = "";
325                 itTypes = outputTypes.find("fasta");
326                 if (itTypes != outputTypes.end()) {
327                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
328                 }
329                 
330                 itTypes = outputTypes.find("qfile");
331                 if (itTypes != outputTypes.end()) {
332                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
333                 }
334                 
335                 itTypes = outputTypes.find("flow");
336                 if (itTypes != outputTypes.end()) {
337                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFlowFile(current); }
338                 }
339                 
340                 //report output filenames
341                 m->mothurOutEndLine();
342                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
343                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
344                 m->mothurOutEndLine();
345
346                 return 0;
347         }
348         catch(exception& e) {
349                 m->errorOut(e, "SffInfoCommand", "execute");
350                 exit(1);
351         }
352 }
353 //**********************************************************************************************************************
354 int SffInfoCommand::extractSffInfo(string input, string accnos){
355         try {
356                 
357                 if (outputDir == "") {  outputDir += m->hasPath(input); }
358                 
359                 if (accnos != "")       {  readAccnosFile(accnos);  }
360                 else                            {       seqNames.clear();               }
361
362                 ofstream outSfftxt, outFasta, outQual, outFlow;
363                 string outFastaFileName, outQualFileName;
364         string rootName = outputDir + m->getRootName(m->getSimpleName(input));
365         if(rootName.find_last_of(".") == rootName.npos){ rootName += "."; }
366         
367                 string sfftxtFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "sff.txt";
368                 string outFlowFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "flow";
369                 if (trim) {
370                         outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "fasta";
371                         outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "qual";
372                 }else{
373                         outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.fasta";
374                         outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.qual";
375                 }
376                 
377                 if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint);  outputNames.push_back(sfftxtFileName);  outputTypes["sfftxt"].push_back(sfftxtFileName); }
378                 if (fasta)      { m->openOutputFile(outFastaFileName, outFasta);        outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); }
379                 if (qual)       { m->openOutputFile(outQualFileName, outQual);          outputNames.push_back(outQualFileName); outputTypes["qfile"].push_back(outQualFileName);  }
380                 if (flow)       { m->openOutputFile(outFlowFileName, outFlow);          outputNames.push_back(outFlowFileName);  outFlow.setf(ios::fixed, ios::floatfield); outFlow.setf(ios::showpoint); outputTypes["flow"].push_back(outFlowFileName);  }
381                 
382                 ifstream in;
383                 in.open(input.c_str(), ios::binary);
384                 
385                 CommonHeader header; 
386                 readCommonHeader(in, header);
387         
388                 int count = 0;
389                 mycount = 0;
390                 
391                 //check magic number and version
392                 if (header.magicNumber != 779314790) { m->mothurOut("Magic Number is not correct, not a valid .sff file"); m->mothurOutEndLine(); return count; }
393                 if (header.version != "0001") { m->mothurOut("Version is not supported, only support version 0001."); m->mothurOutEndLine(); return count; }
394         
395                 //print common header
396                 if (sfftxt) {   printCommonHeader(outSfftxt, header);           }
397                 if (flow)       {       outFlow << header.numFlowsPerRead << endl;      }
398                         
399                 //read through the sff file
400                 while (!in.eof()) {
401                         
402                         bool print = true;
403                         
404                         //read header
405                         Header readheader;
406                         readHeader(in, readheader);
407                         
408                         //read data
409                         seqRead read; 
410                         readSeqData(in, read, header.numFlowsPerRead, readheader.numBases);
411             bool okay = sanityCheck(readheader, read);
412             if (!okay) { break; }
413             
414                         //if you have provided an accosfile and this seq is not in it, then dont print
415                         if (seqNames.size() != 0) {   if (seqNames.count(readheader.name) == 0) { print = false; }  }
416                         
417                         //print 
418                         if (print) {
419                                 if (sfftxt) { printHeader(outSfftxt, readheader); printSffTxtSeqData(outSfftxt, read, readheader); }
420                                 if (fasta)      {       printFastaSeqData(outFasta, read, readheader);  }
421                                 if (qual)       {       printQualSeqData(outQual, read, readheader);    }
422                                 if (flow)       {       printFlowSeqData(outFlow, read, readheader);    }
423                         }
424                         
425                         count++;
426                         mycount++;
427                 
428                         //report progress
429                         if((count+1) % 10000 == 0){     m->mothurOut(toString(count+1)); m->mothurOutEndLine();         }
430                 
431                         if (m->control_pressed) { count = 0; break;   }
432                         
433                         if (count >= header.numReads) { break; }
434                 }
435                 
436                 //report progress
437                 if (!m->control_pressed) {   if((count) % 10000 != 0){  m->mothurOut(toString(count)); m->mothurOutEndLine();           }  }
438                 
439                 in.close();
440                 
441                 if (sfftxt) {  outSfftxt.close();       }
442                 if (fasta)      {  outFasta.close();    }
443                 if (qual)       {  outQual.close();             }
444                 if (flow)       {  outFlow.close();             }
445                 
446                 return count;
447         }
448         catch(exception& e) {
449                 m->errorOut(e, "SffInfoCommand", "extractSffInfo");
450                 exit(1);
451         }
452 }
453 //**********************************************************************************************************************
454 int SffInfoCommand::readCommonHeader(ifstream& in, CommonHeader& header){
455         try {
456
457                 if (!in.eof()) {
458
459                         //read magic number
460                         char buffer[4];
461                         in.read(buffer, 4);
462                         header.magicNumber = be_int4(*(unsigned int *)(&buffer));
463                 
464                         //read version
465                         char buffer9[4];
466                         in.read(buffer9, 4);
467                         header.version = "";
468                         for (int i = 0; i < 4; i++) {  header.version += toString((int)(buffer9[i])); }
469                                 
470                         //read offset
471                         char buffer2 [8];
472                         in.read(buffer2, 8);
473                         header.indexOffset =  be_int8(*(unsigned long long *)(&buffer2));
474                         
475                         //read index length
476                         char buffer3 [4];
477                         in.read(buffer3, 4);
478                         header.indexLength =  be_int4(*(unsigned int *)(&buffer3));
479                         
480                         //read num reads
481                         char buffer4 [4];
482                         in.read(buffer4, 4);
483                         header.numReads =  be_int4(*(unsigned int *)(&buffer4));
484                                 
485                         //read header length
486                         char buffer5 [2];
487                         in.read(buffer5, 2);
488                         header.headerLength =  be_int2(*(unsigned short *)(&buffer5));
489                                         
490                         //read key length
491                         char buffer6 [2];
492                         in.read(buffer6, 2);
493                         header.keyLength = be_int2(*(unsigned short *)(&buffer6));
494                         
495                         //read number of flow reads
496                         char buffer7 [2];
497                         in.read(buffer7, 2);
498                         header.numFlowsPerRead =  be_int2(*(unsigned short *)(&buffer7));
499                                 
500                         //read format code
501                         char buffer8 [1];
502                         in.read(buffer8, 1);
503                         header.flogramFormatCode = (int)(buffer8[0]);
504                         
505                         //read flow chars
506                         char* tempBuffer = new char[header.numFlowsPerRead];
507                         in.read(&(*tempBuffer), header.numFlowsPerRead); 
508                         header.flowChars = tempBuffer;
509                         if (header.flowChars.length() > header.numFlowsPerRead) { header.flowChars = header.flowChars.substr(0, header.numFlowsPerRead);  }
510                         delete[] tempBuffer;
511                         
512                         //read key
513                         char* tempBuffer2 = new char[header.keyLength];
514                         in.read(&(*tempBuffer2), header.keyLength);
515                         header.keySequence = tempBuffer2;
516                         if (header.keySequence.length() > header.keyLength) { header.keySequence = header.keySequence.substr(0, header.keyLength);  }
517                         delete[] tempBuffer2;
518                                 
519                         /* Pad to 8 chars */
520                         unsigned long long spotInFile = in.tellg();
521                         unsigned long long spot = (spotInFile + 7)& ~7;  // ~ inverts
522                         in.seekg(spot);
523                         
524                 }else{
525                         m->mothurOut("Error reading sff common header."); m->mothurOutEndLine();
526                 }
527
528                 return 0;
529         }
530         catch(exception& e) {
531                 m->errorOut(e, "SffInfoCommand", "readCommonHeader");
532                 exit(1);
533         }
534 }
535 //**********************************************************************************************************************
536 int SffInfoCommand::readHeader(ifstream& in, Header& header){
537         try {
538         
539                 if (!in.eof()) {
540                         
541                         //read header length
542                         char buffer [2];
543                         in.read(buffer, 2);
544                         header.headerLength = be_int2(*(unsigned short *)(&buffer));
545                                                 
546                         //read name length
547                         char buffer2 [2];
548                         in.read(buffer2, 2);
549                         header.nameLength = be_int2(*(unsigned short *)(&buffer2));
550
551                         //read num bases
552                         char buffer3 [4];
553                         in.read(buffer3, 4);
554                         header.numBases =  be_int4(*(unsigned int *)(&buffer3));
555                         
556                         //read clip qual left
557                         char buffer4 [2];
558                         in.read(buffer4, 2);
559                         header.clipQualLeft =  be_int2(*(unsigned short *)(&buffer4));
560                         header.clipQualLeft = 5; 
561                         
562                         //read clip qual right
563                         char buffer5 [2];
564                         in.read(buffer5, 2);
565                         header.clipQualRight =  be_int2(*(unsigned short *)(&buffer5));
566                         
567                         //read clipAdapterLeft
568                         char buffer6 [2];
569                         in.read(buffer6, 2);
570                         header.clipAdapterLeft = be_int2(*(unsigned short *)(&buffer6));
571
572                         //read clipAdapterRight
573                         char buffer7 [2];
574                         in.read(buffer7, 2);
575                         header.clipAdapterRight = be_int2(*(unsigned short *)(&buffer7));
576                 
577                         //read name
578                         char* tempBuffer = new char[header.nameLength];
579                         in.read(&(*tempBuffer), header.nameLength);
580                         header.name = tempBuffer;
581                         if (header.name.length() > header.nameLength) { header.name = header.name.substr(0, header.nameLength);  }
582                         delete[] tempBuffer;
583                         
584                         //extract info from name
585                         decodeName(header.timestamp, header.region, header.xy, header.name);
586                         
587                         /* Pad to 8 chars */
588                         unsigned long long spotInFile = in.tellg();
589                         unsigned long long spot = (spotInFile + 7)& ~7;
590                         in.seekg(spot);
591                         
592                 }else{
593                         m->mothurOut("Error reading sff header info."); m->mothurOutEndLine();
594                 }
595
596                 return 0;
597         }
598         catch(exception& e) {
599                 m->errorOut(e, "SffInfoCommand", "readHeader");
600                 exit(1);
601         }
602 }
603 //**********************************************************************************************************************
604 int SffInfoCommand::readSeqData(ifstream& in, seqRead& read, int numFlowReads, int numBases){
605         try {
606         
607                 if (!in.eof()) {
608         
609                         //read flowgram
610                         read.flowgram.resize(numFlowReads);
611                         for (int i = 0; i < numFlowReads; i++) {  
612                                 char buffer [2];
613                                 in.read(buffer, 2);
614                                 read.flowgram[i] = be_int2(*(unsigned short *)(&buffer));
615                         }
616             
617                         //read flowIndex
618                         read.flowIndex.resize(numBases);
619                         for (int i = 0; i < numBases; i++) {  
620                                 char temp[1];
621                                 in.read(temp, 1);
622                                 read.flowIndex[i] = be_int1(*(unsigned char *)(&temp));
623                         }
624         
625                         //read bases
626                         char* tempBuffer = new char[numBases];
627                         in.read(&(*tempBuffer), numBases);
628                         read.bases = tempBuffer;
629                         if (read.bases.length() > numBases) { read.bases = read.bases.substr(0, numBases);  }
630                         delete[] tempBuffer;
631
632                         //read qual scores
633                         read.qualScores.resize(numBases);
634                         for (int i = 0; i < numBases; i++) {  
635                                 char temp[1];
636                                 in.read(temp, 1);
637                                 read.qualScores[i] = be_int1(*(unsigned char *)(&temp));
638                         }
639         
640                         /* Pad to 8 chars */
641                         unsigned long long spotInFile = in.tellg();
642                         unsigned long long spot = (spotInFile + 7)& ~7;
643                         in.seekg(spot);
644                         
645                 }else{
646                         m->mothurOut("Error reading."); m->mothurOutEndLine();
647                 }
648
649                 return 0;
650         }
651         catch(exception& e) {
652                 m->errorOut(e, "SffInfoCommand", "readSeqData");
653                 exit(1);
654         }
655 }
656 //**********************************************************************************************************************
657 int SffInfoCommand::decodeName(string& timestamp, string& region, string& xy, string name) {
658         try {
659                 
660                 if (name.length() >= 6) {
661                         string time = name.substr(0, 6);
662                         unsigned int timeNum = m->fromBase36(time);
663                         
664                         int q1 = timeNum / 60;
665                         int sec = timeNum - 60 * q1;
666                         int q2 = q1 / 60;
667                         int minute = q1 - 60 * q2;
668                         int q3 = q2 / 24;
669                         int hr = q2 - 24 * q3;
670                         int q4 = q3 / 32;
671                         int day = q3 - 32 * q4;
672                         int q5 = q4 / 13;
673                         int mon = q4 - 13 * q5;
674                         int year = 2000 + q5;
675                 
676                         timestamp = toString(year) + "_" + toString(mon) + "_" + toString(day) + "_" + toString(hr) + "_" + toString(minute) + "_" + toString(sec);
677                 }
678                 
679                 if (name.length() >= 9) {
680                         region = name.substr(7, 2);
681                 
682                         string xyNum = name.substr(9);
683                         unsigned int myXy = m->fromBase36(xyNum);
684                         int x = myXy >> 12;
685                         int y = myXy & 4095;
686                 
687                         xy = toString(x) + "_" + toString(y);
688                 }
689                 
690                 return 0;
691         }
692         catch(exception& e) {
693                 m->errorOut(e, "SffInfoCommand", "decodeName");
694                 exit(1);
695         }
696 }
697 //**********************************************************************************************************************
698 int SffInfoCommand::printCommonHeader(ofstream& out, CommonHeader& header) {
699         try {
700         
701                 out << "Common Header:\nMagic Number: " << header.magicNumber << endl;
702                 out << "Version: " << header.version << endl;
703                 out << "Index Offset: " << header.indexOffset << endl;
704                 out << "Index Length: " << header.indexLength << endl;
705                 out << "Number of Reads: " << header.numReads << endl;
706                 out << "Header Length: " << header.headerLength << endl;
707                 out << "Key Length: " << header.keyLength << endl;
708                 out << "Number of Flows: " << header.numFlowsPerRead << endl;
709                 out << "Format Code: " << header.flogramFormatCode << endl;
710                 out << "Flow Chars: " << header.flowChars << endl;
711                 out << "Key Sequence: " << header.keySequence << endl << endl;
712                         
713                 return 0;
714         }
715         catch(exception& e) {
716                 m->errorOut(e, "SffInfoCommand", "printCommonHeader");
717                 exit(1);
718         }
719 }
720 //**********************************************************************************************************************
721 int SffInfoCommand::printHeader(ofstream& out, Header& header) {
722         try {
723                 
724                 out << ">" << header.name << endl;
725                 out << "Run Prefix: " << header.timestamp << endl;
726                 out << "Region #:  " << header.region << endl;
727                 out << "XY Location: " << header.xy << endl << endl;
728                 
729                 out << "Run Name:  " << endl;
730                 out << "Analysis Name:  " << endl;
731                 out << "Full Path: " << endl << endl;
732                 
733                 out << "Read Header Len: " << header.headerLength << endl;
734                 out << "Name Length: " << header.nameLength << endl;
735                 out << "# of Bases: " << header.numBases << endl;
736                 out << "Clip Qual Left: " << header.clipQualLeft << endl;
737                 out << "Clip Qual Right: " << header.clipQualRight << endl;
738                 out << "Clip Adap Left: " << header.clipAdapterLeft << endl;
739                 out << "Clip Adap Right: " << header.clipAdapterRight << endl << endl;
740                 
741                 return 0;
742         }
743         catch(exception& e) {
744                 m->errorOut(e, "SffInfoCommand", "printHeader");
745                 exit(1);
746         }
747 }
748 //**********************************************************************************************************************
749 bool SffInfoCommand::sanityCheck(Header& header, seqRead& read) {
750         try {
751         bool okay = true;
752         string message = "[WARNING]: Your sff file may be corrupted! Sequence: " + header.name + "\n";
753         
754         if (header.clipQualLeft > read.bases.length()) {
755             okay = false; message += "Clip Qual Left = " + toString(header.clipQualLeft) + ", but we only read " + toString(read.bases.length()) + " bases.\n";
756         }
757         if (header.clipQualRight > read.bases.length()) {
758             okay = false; message += "Clip Qual Right = " + toString(header.clipQualRight) + ", but we only read " + toString(read.bases.length()) + " bases.\n";
759         }
760         if (header.clipQualLeft > read.qualScores.size()) {
761             okay = false; message += "Clip Qual Left = " + toString(header.clipQualLeft) + ", but we only read " + toString(read.qualScores.size()) + " quality scores.\n";
762         }
763         if (header.clipQualRight > read.qualScores.size()) {
764             okay = false; message += "Clip Qual Right = " + toString(header.clipQualRight) + ", but we only read " + toString(read.qualScores.size()) + " quality scores.\n";
765         }
766         
767         if (okay == false) {
768             m->mothurOut(message); m->mothurOutEndLine();
769         }
770         
771                 return okay;
772         }
773         catch(exception& e) {
774                 m->errorOut(e, "SffInfoCommand", "sanityCheck");
775                 exit(1);
776         }
777 }
778 //**********************************************************************************************************************
779 int SffInfoCommand::printSffTxtSeqData(ofstream& out, seqRead& read, Header& header) {
780         try {
781                 out << "Flowgram: ";
782                 for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << (read.flowgram[i]/(float)100) << '\t';  }
783                 
784                 out << endl <<  "Flow Indexes: ";
785                 int sum = 0;
786                 for (int i = 0; i < read.flowIndex.size(); i++) {  sum +=  read.flowIndex[i];  out << sum << '\t'; }
787                 
788                 //make the bases you want to clip lowercase and the bases you want to keep upper case
789                 if(header.clipQualRight == 0){  header.clipQualRight = read.bases.length();     }
790                 for (int i = 0; i < (header.clipQualLeft-1); i++) { read.bases[i] = tolower(read.bases[i]); }
791                 for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   read.bases[i] = toupper(read.bases[i]);  }
792                 for (int i = (header.clipQualRight-1); i < read.bases.length(); i++) {   read.bases[i] = tolower(read.bases[i]);  }
793                 
794                 out << endl <<  "Bases: " << read.bases << endl << "Quality Scores: ";
795                 for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
796         
797                 
798                 out << endl << endl;
799                 
800                 return 0;
801         }
802         catch(exception& e) {
803                 m->errorOut(e, "SffInfoCommand", "printSffTxtSeqData");
804                 exit(1);
805         }
806 }
807 //**********************************************************************************************************************
808 int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& header) {
809         try {
810                 string seq = read.bases;
811                 
812         if (trim) {
813                         if(header.clipQualRight < header.clipQualLeft){
814                                 seq = "NNNN";
815                         }
816                         else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
817                                 seq = seq.substr((header.clipQualLeft-1), (header.clipQualRight-header.clipQualLeft));
818                         }
819                         else {
820                                 seq = seq.substr(header.clipQualLeft-1);
821                         }
822                 }else{
823                         //if you wanted the sfftxt then you already converted the bases to the right case
824                         if (!sfftxt) {
825                                 //make the bases you want to clip lowercase and the bases you want to keep upper case
826                                 if(header.clipQualRight == 0){  header.clipQualRight = seq.length();    }
827                                 for (int i = 0; i < (header.clipQualLeft-1); i++) { seq[i] = tolower(seq[i]);  }
828                                 for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++)  {   seq[i] = toupper(seq[i]);  }
829                                 for (int i = (header.clipQualRight-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
830                         }
831                 }
832                 
833                 out << ">" << header.name  << " xy=" << header.xy << endl;
834                 out << seq << endl;
835                 
836                 return 0;
837         }
838         catch(exception& e) {
839                 m->errorOut(e, "SffInfoCommand", "printFastaSeqData");
840                 exit(1);
841         }
842 }
843
844 //**********************************************************************************************************************
845 int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& header) {
846         try {
847                 
848                 if (trim) {
849                         if(header.clipQualRight < header.clipQualLeft){
850                                 out << ">" << header.name << " xy=" << header.xy << endl;
851                                 out << "0\t0\t0\t0";
852                         }
853                         else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
854                                 out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
855                                 for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   out << read.qualScores[i] << '\t'; }
856                         }
857                         else{
858                                 out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
859                                 for (int i = (header.clipQualLeft-1); i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';   }                       
860                         }
861                 }else{
862                         out << ">" << header.name << " xy=" << header.xy << " length=" << read.qualScores.size() << endl;
863                         for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
864                 }
865                 
866                 out << endl;
867                 
868                 return 0;
869         }
870         catch(exception& e) {
871                 m->errorOut(e, "SffInfoCommand", "printQualSeqData");
872                 exit(1);
873         }
874 }
875
876 //**********************************************************************************************************************
877 int SffInfoCommand::printFlowSeqData(ofstream& out, seqRead& read, Header& header) {
878         try {
879                 if(header.clipQualRight > header.clipQualLeft){
880                         
881                         int rightIndex = 0;
882                         for (int i = 0; i < header.clipQualRight; i++) {  rightIndex +=  read.flowIndex[i];     }
883
884                         out << header.name << ' ' << rightIndex;
885                         for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << ' ' << (read.flowgram[i]/(float)100);  }
886                         out << endl;
887                 }
888                 
889                 
890                 return 0;
891         }
892         catch(exception& e) {
893                 m->errorOut(e, "SffInfoCommand", "printFlowSeqData");
894                 exit(1);
895         }
896 }
897 //**********************************************************************************************************************
898 int SffInfoCommand::readAccnosFile(string filename) {
899         try {
900                 //remove old names
901                 seqNames.clear();
902                 
903                 ifstream in;
904                 m->openInputFile(filename, in);
905                 string name;
906                 
907                 while(!in.eof()){
908                         in >> name; m->gobble(in);
909                                                 
910                         seqNames.insert(name);
911                         
912                         if (m->control_pressed) { seqNames.clear(); break; }
913                 }
914                 in.close();             
915                 
916                 return 0;
917         }
918         catch(exception& e) {
919                 m->errorOut(e, "SffInfoCommand", "readAccnosFile");
920                 exit(1);
921         }
922 }
923 //**********************************************************************************************************************
924 int SffInfoCommand::parseSffTxt() {
925         try {
926                 
927                 ifstream inSFF;
928                 m->openInputFile(sfftxtFilename, inSFF);
929                 
930                 if (outputDir == "") {  outputDir += m->hasPath(sfftxtFilename); }
931                 
932                 //output file names
933                 ofstream outFasta, outQual, outFlow;
934                 string outFastaFileName, outQualFileName;
935                 string fileRoot = m->getRootName(m->getSimpleName(sfftxtFilename));
936                 if (fileRoot.length() > 0) {
937                         //rip off last .
938                         fileRoot = fileRoot.substr(0, fileRoot.length()-1);
939                         fileRoot = m->getRootName(fileRoot);
940                 }
941                 
942                 string outFlowFileName = outputDir + fileRoot + "flow";
943                 if (trim) {
944                         outFastaFileName = outputDir + fileRoot + "fasta";
945                         outQualFileName = outputDir + fileRoot + "qual";
946                 }else{
947                         outFastaFileName = outputDir + fileRoot + "raw.fasta";
948                         outQualFileName = outputDir + fileRoot + "raw.qual";
949                 }
950                 
951                 if (fasta)      { m->openOutputFile(outFastaFileName, outFasta);        outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); }
952                 if (qual)       { m->openOutputFile(outQualFileName, outQual);          outputNames.push_back(outQualFileName); outputTypes["qual"].push_back(outQualFileName);  }
953                 if (flow)       { m->openOutputFile(outFlowFileName, outFlow);          outputNames.push_back(outFlowFileName);  outFlow.setf(ios::fixed, ios::floatfield); outFlow.setf(ios::showpoint); outputTypes["flow"].push_back(outFlowFileName);  }
954                 
955                 //read common header
956                 string commonHeader = m->getline(inSFF);
957                 string magicNumber = m->getline(inSFF); 
958                 string version = m->getline(inSFF);
959                 string indexOffset = m->getline(inSFF);
960                 string indexLength = m->getline(inSFF);
961                 int numReads = parseHeaderLineToInt(inSFF);
962                 string headerLength = m->getline(inSFF);
963                 string keyLength = m->getline(inSFF);
964                 int numFlows = parseHeaderLineToInt(inSFF);
965                 string flowgramCode = m->getline(inSFF);
966                 string flowChars = m->getline(inSFF);
967                 string keySequence = m->getline(inSFF);
968                 m->gobble(inSFF);
969                 
970                 string seqName;
971                 
972                 if (flow)       {       outFlow << numFlows << endl;    }
973                 
974                 for(int i=0;i<numReads;i++){
975                         
976                         //sanity check
977                         if (inSFF.eof()) { m->mothurOut("[ERROR]: Expected " + toString(numReads) + " but reached end of file at " + toString(i+1) + "."); m->mothurOutEndLine(); break; }
978                         
979                         Header header;
980                         
981                         //parse read header
982                         inSFF >> seqName;
983                         seqName = seqName.substr(1);
984                         m->gobble(inSFF);
985                         header.name = seqName;
986                         
987                         string runPrefix = parseHeaderLineToString(inSFF);              header.timestamp = runPrefix;
988                         string regionNumber = parseHeaderLineToString(inSFF);   header.region = regionNumber;
989                         string xyLocation = parseHeaderLineToString(inSFF);             header.xy = xyLocation;
990                         m->gobble(inSFF);
991                                 
992                         string runName = parseHeaderLineToString(inSFF);
993                         string analysisName = parseHeaderLineToString(inSFF);
994                         string fullPath = parseHeaderLineToString(inSFF);
995                         m->gobble(inSFF);
996                         
997                         string readHeaderLen = parseHeaderLineToString(inSFF);  convert(readHeaderLen, header.headerLength);
998                         string nameLength = parseHeaderLineToString(inSFF);             convert(nameLength, header.nameLength);
999                         int numBases = parseHeaderLineToInt(inSFF);                             header.numBases = numBases;
1000                         string clipQualLeft = parseHeaderLineToString(inSFF);   convert(clipQualLeft, header.clipQualLeft);
1001                         int clipQualRight = parseHeaderLineToInt(inSFF);                header.clipQualRight = clipQualRight;
1002                         string clipAdapLeft = parseHeaderLineToString(inSFF);   convert(clipAdapLeft, header.clipAdapterLeft);
1003                         string clipAdapRight = parseHeaderLineToString(inSFF);  convert(clipAdapRight, header.clipAdapterRight);
1004                         m->gobble(inSFF);
1005                                 
1006                         seqRead read;
1007                         
1008                         //parse read
1009                         vector<unsigned short> flowVector = parseHeaderLineToFloatVector(inSFF, numFlows);      read.flowgram = flowVector;
1010                         vector<unsigned int> flowIndices = parseHeaderLineToIntVector(inSFF, numBases); 
1011                         
1012                         //adjust for print
1013                         vector<unsigned int> flowIndicesAdjusted; flowIndicesAdjusted.push_back(flowIndices[0]);
1014                         for (int j = 1; j < flowIndices.size(); j++) {   flowIndicesAdjusted.push_back(flowIndices[j] - flowIndices[j-1]);   }
1015                         read.flowIndex = flowIndicesAdjusted;
1016                         
1017                         string bases = parseHeaderLineToString(inSFF);                                                                          read.bases = bases;
1018                         vector<unsigned int> qualityScores = parseHeaderLineToIntVector(inSFF, numBases);       read.qualScores = qualityScores;
1019                         m->gobble(inSFF);
1020                                         
1021                         //if you have provided an accosfile and this seq is not in it, then dont print
1022                         bool print = true;
1023                         if (seqNames.size() != 0) {   if (seqNames.count(header.name) == 0) { print = false; }  }
1024                         
1025                         //print 
1026                         if (print) {
1027                                 if (fasta)      {       printFastaSeqData(outFasta, read, header);      }
1028                                 if (qual)       {       printQualSeqData(outQual, read, header);        }
1029                                 if (flow)       {       printFlowSeqData(outFlow, read, header);        }
1030                         }
1031                         
1032                         //report progress
1033                         if((i+1) % 10000 == 0){ m->mothurOut(toString(i+1)); m->mothurOutEndLine();             }
1034                         
1035                         if (m->control_pressed) {  break;  }
1036                 }
1037                 
1038                 //report progress
1039                 if (!m->control_pressed) {   if((numReads) % 10000 != 0){       m->mothurOut(toString(numReads)); m->mothurOutEndLine();                }  }
1040                 
1041                 inSFF.close();
1042                 
1043                 if (fasta)      {  outFasta.close();    }
1044                 if (qual)       {  outQual.close();             }
1045                 if (flow)       {  outFlow.close();             }
1046                 
1047                 return 0;
1048         }
1049         catch(exception& e) {
1050                 m->errorOut(e, "SffInfoCommand", "parseSffTxt");
1051                 exit(1);
1052         }
1053 }
1054 //**********************************************************************************************************************
1055
1056 int SffInfoCommand::parseHeaderLineToInt(ifstream& file){
1057         try {
1058                 int number;
1059                 
1060                 while (!file.eof())     {
1061                         
1062                         char c = file.get(); 
1063                         if (c == ':'){
1064                                 file >> number;
1065                                 break;
1066                         }
1067                         
1068                 }
1069                 m->gobble(file);
1070                 return number;
1071         }
1072         catch(exception& e) {
1073                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToInt");
1074                 exit(1);
1075         }
1076         
1077 }
1078
1079 //**********************************************************************************************************************
1080
1081 string SffInfoCommand::parseHeaderLineToString(ifstream& file){
1082         try {
1083                 string text;
1084                 
1085                 while (!file.eof())     {
1086                         char c = file.get(); 
1087                         
1088                         if (c == ':'){
1089                                 //m->gobble(file);
1090                                 //text = m->getline(file);      
1091                                 file >> text;
1092                                 break;
1093                         }
1094                 }
1095                 m->gobble(file);
1096                 
1097                 return text;
1098         }
1099         catch(exception& e) {
1100                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToString");
1101                 exit(1);
1102         }
1103 }
1104
1105 //**********************************************************************************************************************
1106
1107 vector<unsigned short> SffInfoCommand::parseHeaderLineToFloatVector(ifstream& file, int length){
1108         try {
1109                 vector<unsigned short> floatVector(length);
1110                 
1111                 while (!file.eof())     {
1112                         char c = file.get(); 
1113                         if (c == ':'){
1114                                 float temp;
1115                                 for(int i=0;i<length;i++){
1116                                         file >> temp;
1117                                         floatVector[i] = temp * 100;
1118                                 }
1119                                 break;
1120                         }
1121                 }
1122                 m->gobble(file);        
1123                 return floatVector;
1124         }
1125         catch(exception& e) {
1126                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToFloatVector");
1127                 exit(1);
1128         }
1129 }
1130
1131 //**********************************************************************************************************************
1132
1133 vector<unsigned int> SffInfoCommand::parseHeaderLineToIntVector(ifstream& file, int length){
1134         try {
1135                 vector<unsigned int> intVector(length);
1136                 
1137                 while (!file.eof())     {
1138                         char c = file.get(); 
1139                         if (c == ':'){
1140                                 for(int i=0;i<length;i++){
1141                                         file >> intVector[i];
1142                                 }
1143                                 break;
1144                         }
1145                 }
1146                 m->gobble(file);        
1147                 return intVector;
1148         }
1149         catch(exception& e) {
1150                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToIntVector");
1151                 exit(1);
1152         }
1153 }
1154
1155 //**********************************************************************************************************************
1156
1157
1158                                 
1159