]> git.donarmstrong.com Git - mothur.git/blob - sffinfocommand.cpp
Merge remote-tracking branch 'mothur/master'
[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             filenames[s] = m->getFullPathName(filenames[s]);
310                         m->mothurOut("Extracting info from " + filenames[s] + " ..." ); m->mothurOutEndLine();
311                         
312                         string accnos = "";
313                         if (hasAccnos) { accnos = accnosFileNames[s]; }
314                         
315                         int numReads = extractSffInfo(filenames[s], accnos);
316
317                         m->mothurOut("It took " + toString(time(NULL) - start) + " secs to extract " + toString(numReads) + ".");
318                 }
319                 
320                 if (sfftxtFilename != "") {  parseSffTxt(); }
321                 
322                 if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]);        } return 0; }
323                 
324                 //set fasta file as new current fastafile
325                 string current = "";
326                 itTypes = outputTypes.find("fasta");
327                 if (itTypes != outputTypes.end()) {
328                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
329                 }
330                 
331                 itTypes = outputTypes.find("qfile");
332                 if (itTypes != outputTypes.end()) {
333                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
334                 }
335                 
336                 itTypes = outputTypes.find("flow");
337                 if (itTypes != outputTypes.end()) {
338                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFlowFile(current); }
339                 }
340                 
341                 //report output filenames
342                 m->mothurOutEndLine();
343                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
344                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
345                 m->mothurOutEndLine();
346
347                 return 0;
348         }
349         catch(exception& e) {
350                 m->errorOut(e, "SffInfoCommand", "execute");
351                 exit(1);
352         }
353 }
354 //**********************************************************************************************************************
355 int SffInfoCommand::extractSffInfo(string input, string accnos){
356         try {
357                 
358                 if (outputDir == "") {  outputDir += m->hasPath(input); }
359                 
360                 if (accnos != "")       {  readAccnosFile(accnos);  }
361                 else                            {       seqNames.clear();               }
362
363                 ofstream outSfftxt, outFasta, outQual, outFlow;
364                 string outFastaFileName, outQualFileName;
365         string rootName = outputDir + m->getRootName(m->getSimpleName(input));
366         if(rootName.find_last_of(".") == rootName.npos){ rootName += "."; }
367         
368                 string sfftxtFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "sff.txt";
369                 string outFlowFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "flow";
370                 if (trim) {
371                         outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "fasta";
372                         outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "qual";
373                 }else{
374                         outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.fasta";
375                         outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.qual";
376                 }
377                 
378                 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); }
379                 if (fasta)      { m->openOutputFile(outFastaFileName, outFasta);        outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); }
380                 if (qual)       { m->openOutputFile(outQualFileName, outQual);          outputNames.push_back(outQualFileName); outputTypes["qfile"].push_back(outQualFileName);  }
381                 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);  }
382                 
383                 ifstream in;
384                 in.open(input.c_str(), ios::binary);
385                 
386                 CommonHeader header; 
387                 readCommonHeader(in, header);
388         
389                 int count = 0;
390                 mycount = 0;
391                 
392                 //check magic number and version
393                 if (header.magicNumber != 779314790) { m->mothurOut("Magic Number is not correct, not a valid .sff file"); m->mothurOutEndLine(); return count; }
394                 if (header.version != "0001") { m->mothurOut("Version is not supported, only support version 0001."); m->mothurOutEndLine(); return count; }
395         
396                 //print common header
397                 if (sfftxt) {   printCommonHeader(outSfftxt, header);           }
398                 if (flow)       {       outFlow << header.numFlowsPerRead << endl;      }
399                         
400                 //read through the sff file
401                 while (!in.eof()) {
402                         
403                         bool print = true;
404                         
405                         //read header
406                         Header readheader;
407                         readHeader(in, readheader);
408                         
409                         //read data
410                         seqRead read; 
411                         readSeqData(in, read, header.numFlowsPerRead, readheader.numBases);
412             bool okay = sanityCheck(readheader, read);
413             if (!okay) { break; }
414             
415                         //if you have provided an accosfile and this seq is not in it, then dont print
416                         if (seqNames.size() != 0) {   if (seqNames.count(readheader.name) == 0) { print = false; }  }
417                         
418                         //print 
419                         if (print) {
420                                 if (sfftxt) { printHeader(outSfftxt, readheader); printSffTxtSeqData(outSfftxt, read, readheader); }
421                                 if (fasta)      {       printFastaSeqData(outFasta, read, readheader);  }
422                                 if (qual)       {       printQualSeqData(outQual, read, readheader);    }
423                                 if (flow)       {       printFlowSeqData(outFlow, read, readheader);    }
424                         }
425                         
426                         count++;
427                         mycount++;
428                 
429                         //report progress
430                         if((count+1) % 10000 == 0){     m->mothurOut(toString(count+1)); m->mothurOutEndLine();         }
431                 
432                         if (m->control_pressed) { count = 0; break;   }
433                         
434                         if (count >= header.numReads) { break; }
435                 }
436                 
437                 //report progress
438                 if (!m->control_pressed) {   if((count) % 10000 != 0){  m->mothurOut(toString(count)); m->mothurOutEndLine();           }  }
439                 
440                 in.close();
441                 
442                 if (sfftxt) {  outSfftxt.close();       }
443                 if (fasta)      {  outFasta.close();    }
444                 if (qual)       {  outQual.close();             }
445                 if (flow)       {  outFlow.close();             }
446                 
447                 return count;
448         }
449         catch(exception& e) {
450                 m->errorOut(e, "SffInfoCommand", "extractSffInfo");
451                 exit(1);
452         }
453 }
454 //**********************************************************************************************************************
455 int SffInfoCommand::readCommonHeader(ifstream& in, CommonHeader& header){
456         try {
457
458                 if (!in.eof()) {
459
460                         //read magic number
461                         char buffer[4];
462                         in.read(buffer, 4);
463                         header.magicNumber = be_int4(*(unsigned int *)(&buffer));
464                 
465                         //read version
466                         char buffer9[4];
467                         in.read(buffer9, 4);
468                         header.version = "";
469                         for (int i = 0; i < 4; i++) {  header.version += toString((int)(buffer9[i])); }
470                                 
471                         //read offset
472                         char buffer2 [8];
473                         in.read(buffer2, 8);
474                         header.indexOffset =  be_int8(*(unsigned long long *)(&buffer2));
475                         
476                         //read index length
477                         char buffer3 [4];
478                         in.read(buffer3, 4);
479                         header.indexLength =  be_int4(*(unsigned int *)(&buffer3));
480                         
481                         //read num reads
482                         char buffer4 [4];
483                         in.read(buffer4, 4);
484                         header.numReads =  be_int4(*(unsigned int *)(&buffer4));
485                                 
486                         //read header length
487                         char buffer5 [2];
488                         in.read(buffer5, 2);
489                         header.headerLength =  be_int2(*(unsigned short *)(&buffer5));
490                                         
491                         //read key length
492                         char buffer6 [2];
493                         in.read(buffer6, 2);
494                         header.keyLength = be_int2(*(unsigned short *)(&buffer6));
495                         
496                         //read number of flow reads
497                         char buffer7 [2];
498                         in.read(buffer7, 2);
499                         header.numFlowsPerRead =  be_int2(*(unsigned short *)(&buffer7));
500                                 
501                         //read format code
502                         char buffer8 [1];
503                         in.read(buffer8, 1);
504                         header.flogramFormatCode = (int)(buffer8[0]);
505                         
506                         //read flow chars
507                         char* tempBuffer = new char[header.numFlowsPerRead];
508                         in.read(&(*tempBuffer), header.numFlowsPerRead); 
509                         header.flowChars = tempBuffer;
510                         if (header.flowChars.length() > header.numFlowsPerRead) { header.flowChars = header.flowChars.substr(0, header.numFlowsPerRead);  }
511                         delete[] tempBuffer;
512                         
513                         //read key
514                         char* tempBuffer2 = new char[header.keyLength];
515                         in.read(&(*tempBuffer2), header.keyLength);
516                         header.keySequence = tempBuffer2;
517                         if (header.keySequence.length() > header.keyLength) { header.keySequence = header.keySequence.substr(0, header.keyLength);  }
518                         delete[] tempBuffer2;
519                                 
520                         /* Pad to 8 chars */
521                         unsigned long long spotInFile = in.tellg();
522                         unsigned long long spot = (spotInFile + 7)& ~7;  // ~ inverts
523                         in.seekg(spot);
524                         
525                 }else{
526                         m->mothurOut("Error reading sff common header."); m->mothurOutEndLine();
527                 }
528
529                 return 0;
530         }
531         catch(exception& e) {
532                 m->errorOut(e, "SffInfoCommand", "readCommonHeader");
533                 exit(1);
534         }
535 }
536 //**********************************************************************************************************************
537 int SffInfoCommand::readHeader(ifstream& in, Header& header){
538         try {
539         
540                 if (!in.eof()) {
541                         
542                         //read header length
543                         char buffer [2];
544                         in.read(buffer, 2);
545                         header.headerLength = be_int2(*(unsigned short *)(&buffer));
546                                                 
547                         //read name length
548                         char buffer2 [2];
549                         in.read(buffer2, 2);
550                         header.nameLength = be_int2(*(unsigned short *)(&buffer2));
551
552                         //read num bases
553                         char buffer3 [4];
554                         in.read(buffer3, 4);
555                         header.numBases =  be_int4(*(unsigned int *)(&buffer3));
556                         
557                         //read clip qual left
558                         char buffer4 [2];
559                         in.read(buffer4, 2);
560                         header.clipQualLeft =  be_int2(*(unsigned short *)(&buffer4));
561                         header.clipQualLeft = 5; 
562                         
563                         //read clip qual right
564                         char buffer5 [2];
565                         in.read(buffer5, 2);
566                         header.clipQualRight =  be_int2(*(unsigned short *)(&buffer5));
567                         
568                         //read clipAdapterLeft
569                         char buffer6 [2];
570                         in.read(buffer6, 2);
571                         header.clipAdapterLeft = be_int2(*(unsigned short *)(&buffer6));
572
573                         //read clipAdapterRight
574                         char buffer7 [2];
575                         in.read(buffer7, 2);
576                         header.clipAdapterRight = be_int2(*(unsigned short *)(&buffer7));
577                 
578                         //read name
579                         char* tempBuffer = new char[header.nameLength];
580                         in.read(&(*tempBuffer), header.nameLength);
581                         header.name = tempBuffer;
582                         if (header.name.length() > header.nameLength) { header.name = header.name.substr(0, header.nameLength);  }
583                         delete[] tempBuffer;
584                         
585                         //extract info from name
586                         decodeName(header.timestamp, header.region, header.xy, header.name);
587                         
588                         /* Pad to 8 chars */
589                         unsigned long long spotInFile = in.tellg();
590                         unsigned long long spot = (spotInFile + 7)& ~7;
591                         in.seekg(spot);
592                         
593                 }else{
594                         m->mothurOut("Error reading sff header info."); m->mothurOutEndLine();
595                 }
596
597                 return 0;
598         }
599         catch(exception& e) {
600                 m->errorOut(e, "SffInfoCommand", "readHeader");
601                 exit(1);
602         }
603 }
604 //**********************************************************************************************************************
605 int SffInfoCommand::readSeqData(ifstream& in, seqRead& read, int numFlowReads, int numBases){
606         try {
607         
608                 if (!in.eof()) {
609         
610                         //read flowgram
611                         read.flowgram.resize(numFlowReads);
612                         for (int i = 0; i < numFlowReads; i++) {  
613                                 char buffer [2];
614                                 in.read(buffer, 2);
615                                 read.flowgram[i] = be_int2(*(unsigned short *)(&buffer));
616                         }
617             
618                         //read flowIndex
619                         read.flowIndex.resize(numBases);
620                         for (int i = 0; i < numBases; i++) {  
621                                 char temp[1];
622                                 in.read(temp, 1);
623                                 read.flowIndex[i] = be_int1(*(unsigned char *)(&temp));
624                         }
625         
626                         //read bases
627                         char* tempBuffer = new char[numBases];
628                         in.read(&(*tempBuffer), numBases);
629                         read.bases = tempBuffer;
630                         if (read.bases.length() > numBases) { read.bases = read.bases.substr(0, numBases);  }
631                         delete[] tempBuffer;
632
633                         //read qual scores
634                         read.qualScores.resize(numBases);
635                         for (int i = 0; i < numBases; i++) {  
636                                 char temp[1];
637                                 in.read(temp, 1);
638                                 read.qualScores[i] = be_int1(*(unsigned char *)(&temp));
639                         }
640         
641                         /* Pad to 8 chars */
642                         unsigned long long spotInFile = in.tellg();
643                         unsigned long long spot = (spotInFile + 7)& ~7;
644                         in.seekg(spot);
645                         
646                 }else{
647                         m->mothurOut("Error reading."); m->mothurOutEndLine();
648                 }
649
650                 return 0;
651         }
652         catch(exception& e) {
653                 m->errorOut(e, "SffInfoCommand", "readSeqData");
654                 exit(1);
655         }
656 }
657 //**********************************************************************************************************************
658 int SffInfoCommand::decodeName(string& timestamp, string& region, string& xy, string name) {
659         try {
660                 
661                 if (name.length() >= 6) {
662                         string time = name.substr(0, 6);
663                         unsigned int timeNum = m->fromBase36(time);
664                         
665                         int q1 = timeNum / 60;
666                         int sec = timeNum - 60 * q1;
667                         int q2 = q1 / 60;
668                         int minute = q1 - 60 * q2;
669                         int q3 = q2 / 24;
670                         int hr = q2 - 24 * q3;
671                         int q4 = q3 / 32;
672                         int day = q3 - 32 * q4;
673                         int q5 = q4 / 13;
674                         int mon = q4 - 13 * q5;
675                         int year = 2000 + q5;
676                 
677                         timestamp = toString(year) + "_" + toString(mon) + "_" + toString(day) + "_" + toString(hr) + "_" + toString(minute) + "_" + toString(sec);
678                 }
679                 
680                 if (name.length() >= 9) {
681                         region = name.substr(7, 2);
682                 
683                         string xyNum = name.substr(9);
684                         unsigned int myXy = m->fromBase36(xyNum);
685                         int x = myXy >> 12;
686                         int y = myXy & 4095;
687                 
688                         xy = toString(x) + "_" + toString(y);
689                 }
690                 
691                 return 0;
692         }
693         catch(exception& e) {
694                 m->errorOut(e, "SffInfoCommand", "decodeName");
695                 exit(1);
696         }
697 }
698 //**********************************************************************************************************************
699 int SffInfoCommand::printCommonHeader(ofstream& out, CommonHeader& header) {
700         try {
701         
702                 out << "Common Header:\nMagic Number: " << header.magicNumber << endl;
703                 out << "Version: " << header.version << endl;
704                 out << "Index Offset: " << header.indexOffset << endl;
705                 out << "Index Length: " << header.indexLength << endl;
706                 out << "Number of Reads: " << header.numReads << endl;
707                 out << "Header Length: " << header.headerLength << endl;
708                 out << "Key Length: " << header.keyLength << endl;
709                 out << "Number of Flows: " << header.numFlowsPerRead << endl;
710                 out << "Format Code: " << header.flogramFormatCode << endl;
711                 out << "Flow Chars: " << header.flowChars << endl;
712                 out << "Key Sequence: " << header.keySequence << endl << endl;
713                         
714                 return 0;
715         }
716         catch(exception& e) {
717                 m->errorOut(e, "SffInfoCommand", "printCommonHeader");
718                 exit(1);
719         }
720 }
721 //**********************************************************************************************************************
722 int SffInfoCommand::printHeader(ofstream& out, Header& header) {
723         try {
724                 
725                 out << ">" << header.name << endl;
726                 out << "Run Prefix: " << header.timestamp << endl;
727                 out << "Region #:  " << header.region << endl;
728                 out << "XY Location: " << header.xy << endl << endl;
729                 
730                 out << "Run Name:  " << endl;
731                 out << "Analysis Name:  " << endl;
732                 out << "Full Path: " << endl << endl;
733                 
734                 out << "Read Header Len: " << header.headerLength << endl;
735                 out << "Name Length: " << header.nameLength << endl;
736                 out << "# of Bases: " << header.numBases << endl;
737                 out << "Clip Qual Left: " << header.clipQualLeft << endl;
738                 out << "Clip Qual Right: " << header.clipQualRight << endl;
739                 out << "Clip Adap Left: " << header.clipAdapterLeft << endl;
740                 out << "Clip Adap Right: " << header.clipAdapterRight << endl << endl;
741                 
742                 return 0;
743         }
744         catch(exception& e) {
745                 m->errorOut(e, "SffInfoCommand", "printHeader");
746                 exit(1);
747         }
748 }
749 //**********************************************************************************************************************
750 bool SffInfoCommand::sanityCheck(Header& header, seqRead& read) {
751         try {
752         bool okay = true;
753         string message = "[WARNING]: Your sff file may be corrupted! Sequence: " + header.name + "\n";
754         
755         if (header.clipQualLeft > read.bases.length()) {
756             okay = false; message += "Clip Qual Left = " + toString(header.clipQualLeft) + ", but we only read " + toString(read.bases.length()) + " bases.\n";
757         }
758         if (header.clipQualRight > read.bases.length()) {
759             okay = false; message += "Clip Qual Right = " + toString(header.clipQualRight) + ", but we only read " + toString(read.bases.length()) + " bases.\n";
760         }
761         if (header.clipQualLeft > read.qualScores.size()) {
762             okay = false; message += "Clip Qual Left = " + toString(header.clipQualLeft) + ", but we only read " + toString(read.qualScores.size()) + " quality scores.\n";
763         }
764         if (header.clipQualRight > read.qualScores.size()) {
765             okay = false; message += "Clip Qual Right = " + toString(header.clipQualRight) + ", but we only read " + toString(read.qualScores.size()) + " quality scores.\n";
766         }
767         
768         if (okay == false) {
769             m->mothurOut(message); m->mothurOutEndLine();
770         }
771         
772                 return okay;
773         }
774         catch(exception& e) {
775                 m->errorOut(e, "SffInfoCommand", "sanityCheck");
776                 exit(1);
777         }
778 }
779 //**********************************************************************************************************************
780 int SffInfoCommand::printSffTxtSeqData(ofstream& out, seqRead& read, Header& header) {
781         try {
782                 out << "Flowgram: ";
783                 for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << (read.flowgram[i]/(float)100) << '\t';  }
784                 
785                 out << endl <<  "Flow Indexes: ";
786                 int sum = 0;
787                 for (int i = 0; i < read.flowIndex.size(); i++) {  sum +=  read.flowIndex[i];  out << sum << '\t'; }
788                 
789                 //make the bases you want to clip lowercase and the bases you want to keep upper case
790                 if(header.clipQualRight == 0){  header.clipQualRight = read.bases.length();     }
791                 for (int i = 0; i < (header.clipQualLeft-1); i++) { read.bases[i] = tolower(read.bases[i]); }
792                 for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   read.bases[i] = toupper(read.bases[i]);  }
793                 for (int i = (header.clipQualRight-1); i < read.bases.length(); i++) {   read.bases[i] = tolower(read.bases[i]);  }
794                 
795                 out << endl <<  "Bases: " << read.bases << endl << "Quality Scores: ";
796                 for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
797         
798                 
799                 out << endl << endl;
800                 
801                 return 0;
802         }
803         catch(exception& e) {
804                 m->errorOut(e, "SffInfoCommand", "printSffTxtSeqData");
805                 exit(1);
806         }
807 }
808 //**********************************************************************************************************************
809 int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& header) {
810         try {
811                 string seq = read.bases;
812                 
813         if (trim) {
814                         if(header.clipQualRight < header.clipQualLeft){
815                                 seq = "NNNN";
816                         }
817                         else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
818                                 seq = seq.substr((header.clipQualLeft-1), (header.clipQualRight-header.clipQualLeft));
819                         }
820                         else {
821                                 seq = seq.substr(header.clipQualLeft-1);
822                         }
823                 }else{
824                         //if you wanted the sfftxt then you already converted the bases to the right case
825                         if (!sfftxt) {
826                                 //make the bases you want to clip lowercase and the bases you want to keep upper case
827                                 if(header.clipQualRight == 0){  header.clipQualRight = seq.length();    }
828                                 for (int i = 0; i < (header.clipQualLeft-1); i++) { seq[i] = tolower(seq[i]);  }
829                                 for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++)  {   seq[i] = toupper(seq[i]);  }
830                                 for (int i = (header.clipQualRight-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
831                         }
832                 }
833                 
834                 out << ">" << header.name  << " xy=" << header.xy << endl;
835                 out << seq << endl;
836                 
837                 return 0;
838         }
839         catch(exception& e) {
840                 m->errorOut(e, "SffInfoCommand", "printFastaSeqData");
841                 exit(1);
842         }
843 }
844
845 //**********************************************************************************************************************
846 int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& header) {
847         try {
848                 
849                 if (trim) {
850                         if(header.clipQualRight < header.clipQualLeft){
851                                 out << ">" << header.name << " xy=" << header.xy << endl;
852                                 out << "0\t0\t0\t0";
853                         }
854                         else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
855                                 out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
856                                 for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   out << read.qualScores[i] << '\t'; }
857                         }
858                         else{
859                                 out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
860                                 for (int i = (header.clipQualLeft-1); i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';   }                       
861                         }
862                 }else{
863                         out << ">" << header.name << " xy=" << header.xy << " length=" << read.qualScores.size() << endl;
864                         for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
865                 }
866                 
867                 out << endl;
868                 
869                 return 0;
870         }
871         catch(exception& e) {
872                 m->errorOut(e, "SffInfoCommand", "printQualSeqData");
873                 exit(1);
874         }
875 }
876
877 //**********************************************************************************************************************
878 int SffInfoCommand::printFlowSeqData(ofstream& out, seqRead& read, Header& header) {
879         try {
880                 if(header.clipQualRight > header.clipQualLeft){
881                         
882                         int rightIndex = 0;
883                         for (int i = 0; i < header.clipQualRight; i++) {  rightIndex +=  read.flowIndex[i];     }
884
885                         out << header.name << ' ' << rightIndex;
886                         for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << ' ' << (read.flowgram[i]/(float)100);  }
887                         out << endl;
888                 }
889                 
890                 
891                 return 0;
892         }
893         catch(exception& e) {
894                 m->errorOut(e, "SffInfoCommand", "printFlowSeqData");
895                 exit(1);
896         }
897 }
898 //**********************************************************************************************************************
899 int SffInfoCommand::readAccnosFile(string filename) {
900         try {
901                 //remove old names
902                 seqNames.clear();
903                 
904                 ifstream in;
905                 m->openInputFile(filename, in);
906                 string name;
907                 
908                 while(!in.eof()){
909                         in >> name; m->gobble(in);
910                                                 
911                         seqNames.insert(name);
912                         
913                         if (m->control_pressed) { seqNames.clear(); break; }
914                 }
915                 in.close();             
916                 
917                 return 0;
918         }
919         catch(exception& e) {
920                 m->errorOut(e, "SffInfoCommand", "readAccnosFile");
921                 exit(1);
922         }
923 }
924 //**********************************************************************************************************************
925 int SffInfoCommand::parseSffTxt() {
926         try {
927                 
928                 ifstream inSFF;
929                 m->openInputFile(sfftxtFilename, inSFF);
930                 
931                 if (outputDir == "") {  outputDir += m->hasPath(sfftxtFilename); }
932                 
933                 //output file names
934                 ofstream outFasta, outQual, outFlow;
935                 string outFastaFileName, outQualFileName;
936                 string fileRoot = m->getRootName(m->getSimpleName(sfftxtFilename));
937                 if (fileRoot.length() > 0) {
938                         //rip off last .
939                         fileRoot = fileRoot.substr(0, fileRoot.length()-1);
940                         fileRoot = m->getRootName(fileRoot);
941                 }
942                 
943                 string outFlowFileName = outputDir + fileRoot + "flow";
944                 if (trim) {
945                         outFastaFileName = outputDir + fileRoot + "fasta";
946                         outQualFileName = outputDir + fileRoot + "qual";
947                 }else{
948                         outFastaFileName = outputDir + fileRoot + "raw.fasta";
949                         outQualFileName = outputDir + fileRoot + "raw.qual";
950                 }
951                 
952                 if (fasta)      { m->openOutputFile(outFastaFileName, outFasta);        outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); }
953                 if (qual)       { m->openOutputFile(outQualFileName, outQual);          outputNames.push_back(outQualFileName); outputTypes["qual"].push_back(outQualFileName);  }
954                 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);  }
955                 
956                 //read common header
957                 string commonHeader = m->getline(inSFF);
958                 string magicNumber = m->getline(inSFF); 
959                 string version = m->getline(inSFF);
960                 string indexOffset = m->getline(inSFF);
961                 string indexLength = m->getline(inSFF);
962                 int numReads = parseHeaderLineToInt(inSFF);
963                 string headerLength = m->getline(inSFF);
964                 string keyLength = m->getline(inSFF);
965                 int numFlows = parseHeaderLineToInt(inSFF);
966                 string flowgramCode = m->getline(inSFF);
967                 string flowChars = m->getline(inSFF);
968                 string keySequence = m->getline(inSFF);
969                 m->gobble(inSFF);
970                 
971                 string seqName;
972                 
973                 if (flow)       {       outFlow << numFlows << endl;    }
974                 
975                 for(int i=0;i<numReads;i++){
976                         
977                         //sanity check
978                         if (inSFF.eof()) { m->mothurOut("[ERROR]: Expected " + toString(numReads) + " but reached end of file at " + toString(i+1) + "."); m->mothurOutEndLine(); break; }
979                         
980                         Header header;
981                         
982                         //parse read header
983                         inSFF >> seqName;
984                         seqName = seqName.substr(1);
985                         m->gobble(inSFF);
986                         header.name = seqName;
987                         
988                         string runPrefix = parseHeaderLineToString(inSFF);              header.timestamp = runPrefix;
989                         string regionNumber = parseHeaderLineToString(inSFF);   header.region = regionNumber;
990                         string xyLocation = parseHeaderLineToString(inSFF);             header.xy = xyLocation;
991                         m->gobble(inSFF);
992                                 
993                         string runName = parseHeaderLineToString(inSFF);
994                         string analysisName = parseHeaderLineToString(inSFF);
995                         string fullPath = parseHeaderLineToString(inSFF);
996                         m->gobble(inSFF);
997                         
998                         string readHeaderLen = parseHeaderLineToString(inSFF);  convert(readHeaderLen, header.headerLength);
999                         string nameLength = parseHeaderLineToString(inSFF);             convert(nameLength, header.nameLength);
1000                         int numBases = parseHeaderLineToInt(inSFF);                             header.numBases = numBases;
1001                         string clipQualLeft = parseHeaderLineToString(inSFF);   convert(clipQualLeft, header.clipQualLeft);
1002                         int clipQualRight = parseHeaderLineToInt(inSFF);                header.clipQualRight = clipQualRight;
1003                         string clipAdapLeft = parseHeaderLineToString(inSFF);   convert(clipAdapLeft, header.clipAdapterLeft);
1004                         string clipAdapRight = parseHeaderLineToString(inSFF);  convert(clipAdapRight, header.clipAdapterRight);
1005                         m->gobble(inSFF);
1006                                 
1007                         seqRead read;
1008                         
1009                         //parse read
1010                         vector<unsigned short> flowVector = parseHeaderLineToFloatVector(inSFF, numFlows);      read.flowgram = flowVector;
1011                         vector<unsigned int> flowIndices = parseHeaderLineToIntVector(inSFF, numBases); 
1012                         
1013                         //adjust for print
1014                         vector<unsigned int> flowIndicesAdjusted; flowIndicesAdjusted.push_back(flowIndices[0]);
1015                         for (int j = 1; j < flowIndices.size(); j++) {   flowIndicesAdjusted.push_back(flowIndices[j] - flowIndices[j-1]);   }
1016                         read.flowIndex = flowIndicesAdjusted;
1017                         
1018                         string bases = parseHeaderLineToString(inSFF);                                                                          read.bases = bases;
1019                         vector<unsigned int> qualityScores = parseHeaderLineToIntVector(inSFF, numBases);       read.qualScores = qualityScores;
1020                         m->gobble(inSFF);
1021                                         
1022                         //if you have provided an accosfile and this seq is not in it, then dont print
1023                         bool print = true;
1024                         if (seqNames.size() != 0) {   if (seqNames.count(header.name) == 0) { print = false; }  }
1025                         
1026                         //print 
1027                         if (print) {
1028                                 if (fasta)      {       printFastaSeqData(outFasta, read, header);      }
1029                                 if (qual)       {       printQualSeqData(outQual, read, header);        }
1030                                 if (flow)       {       printFlowSeqData(outFlow, read, header);        }
1031                         }
1032                         
1033                         //report progress
1034                         if((i+1) % 10000 == 0){ m->mothurOut(toString(i+1)); m->mothurOutEndLine();             }
1035                         
1036                         if (m->control_pressed) {  break;  }
1037                 }
1038                 
1039                 //report progress
1040                 if (!m->control_pressed) {   if((numReads) % 10000 != 0){       m->mothurOut(toString(numReads)); m->mothurOutEndLine();                }  }
1041                 
1042                 inSFF.close();
1043                 
1044                 if (fasta)      {  outFasta.close();    }
1045                 if (qual)       {  outQual.close();             }
1046                 if (flow)       {  outFlow.close();             }
1047                 
1048                 return 0;
1049         }
1050         catch(exception& e) {
1051                 m->errorOut(e, "SffInfoCommand", "parseSffTxt");
1052                 exit(1);
1053         }
1054 }
1055 //**********************************************************************************************************************
1056
1057 int SffInfoCommand::parseHeaderLineToInt(ifstream& file){
1058         try {
1059                 int number;
1060                 
1061                 while (!file.eof())     {
1062                         
1063                         char c = file.get(); 
1064                         if (c == ':'){
1065                                 file >> number;
1066                                 break;
1067                         }
1068                         
1069                 }
1070                 m->gobble(file);
1071                 return number;
1072         }
1073         catch(exception& e) {
1074                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToInt");
1075                 exit(1);
1076         }
1077         
1078 }
1079
1080 //**********************************************************************************************************************
1081
1082 string SffInfoCommand::parseHeaderLineToString(ifstream& file){
1083         try {
1084                 string text;
1085                 
1086                 while (!file.eof())     {
1087                         char c = file.get(); 
1088                         
1089                         if (c == ':'){
1090                                 //m->gobble(file);
1091                                 //text = m->getline(file);      
1092                                 file >> text;
1093                                 break;
1094                         }
1095                 }
1096                 m->gobble(file);
1097                 
1098                 return text;
1099         }
1100         catch(exception& e) {
1101                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToString");
1102                 exit(1);
1103         }
1104 }
1105
1106 //**********************************************************************************************************************
1107
1108 vector<unsigned short> SffInfoCommand::parseHeaderLineToFloatVector(ifstream& file, int length){
1109         try {
1110                 vector<unsigned short> floatVector(length);
1111                 
1112                 while (!file.eof())     {
1113                         char c = file.get(); 
1114                         if (c == ':'){
1115                                 float temp;
1116                                 for(int i=0;i<length;i++){
1117                                         file >> temp;
1118                                         floatVector[i] = temp * 100;
1119                                 }
1120                                 break;
1121                         }
1122                 }
1123                 m->gobble(file);        
1124                 return floatVector;
1125         }
1126         catch(exception& e) {
1127                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToFloatVector");
1128                 exit(1);
1129         }
1130 }
1131
1132 //**********************************************************************************************************************
1133
1134 vector<unsigned int> SffInfoCommand::parseHeaderLineToIntVector(ifstream& file, int length){
1135         try {
1136                 vector<unsigned int> intVector(length);
1137                 
1138                 while (!file.eof())     {
1139                         char c = file.get(); 
1140                         if (c == ':'){
1141                                 for(int i=0;i<length;i++){
1142                                         file >> intVector[i];
1143                                 }
1144                                 break;
1145                         }
1146                 }
1147                 m->gobble(file);        
1148                 return intVector;
1149         }
1150         catch(exception& e) {
1151                 m->errorOut(e, "SffInfoCommand", "parseHeaderLineToIntVector");
1152                 exit(1);
1153         }
1154 }
1155
1156 //**********************************************************************************************************************
1157
1158
1159                                 
1160