]> git.donarmstrong.com Git - mothur.git/blob - sffinfocommand.cpp
added compile time default path
[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
15 SffInfoCommand::SffInfoCommand(string option)  {
16         try {
17                 abort = false;
18                 hasAccnos = false;
19                 
20                 //allow user to run help
21                 if(option == "help") { help(); abort = true; }
22                 
23                 else {
24                         //valid paramters for this command
25                         string Array[] =  {"sff","qfile","fasta","flow","trim","accnos","sfftxt","outputdir","inputdir", "outputdir"};
26                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
27                         
28                         OptionParser parser(option);
29                         map<string, string> parameters = parser.getParameters();
30                         
31                         ValidParameters validParameter;
32                         //check to make sure all parameters are valid for command
33                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
34                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
35                         }
36                         
37                         //if the user changes the output directory command factory will send this info to us in the output parameter 
38                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
39                         
40                         //if the user changes the input directory command factory will send this info to us in the output parameter 
41                         string inputDir = validParameter.validFile(parameters, "inputdir", false);        if (inputDir == "not found"){ inputDir = "";          }
42
43                         sffFilename = validParameter.validFile(parameters, "sff", false);
44                         if (sffFilename == "not found") { m->mothurOut("sff is a required parameter for the sffinfo command."); m->mothurOutEndLine(); abort = true;  }
45                         else { 
46                                 splitAtDash(sffFilename, filenames);
47                                 
48                                 //go through files and make sure they are good, if not, then disregard them
49                                 for (int i = 0; i < filenames.size(); i++) {
50                                         if (inputDir != "") {
51                                                 string path = hasPath(filenames[i]);
52                                                 //if the user has not given a path then, add inputdir. else leave path alone.
53                                                 if (path == "") {       filenames[i] = inputDir + filenames[i];         }
54                                         }
55         
56                                         ifstream in;
57                                         int ableToOpen = openInputFile(filenames[i], in, "noerror");
58                                 
59                                         //if you can't open it, try default location
60                                         if (ableToOpen == 1) {
61                                                 if (m->getDefaultPath() != "") { //default path is set
62                                                         string tryPath = m->getDefaultPath() + getSimpleName(filenames[i]);
63                                                         m->mothurOut("Unable to open " + filenames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
64                                                         ableToOpen = openInputFile(tryPath, in, "noerror");
65                                                         filenames[i] = tryPath;
66                                                 }
67                                         }
68                                         in.close();
69                                         
70                                         if (ableToOpen == 1) { 
71                                                 m->mothurOut("Unable to open " + filenames[i] + ". It will be disregarded."); m->mothurOutEndLine();
72                                                 //erase from file list
73                                                 filenames.erase(filenames.begin()+i);
74                                                 i--;
75                                         }
76                                 }
77                                 
78                                 //make sure there is at least one valid file left
79                                 if (filenames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
80                         }
81                         
82                         accnosName = validParameter.validFile(parameters, "accnos", false);
83                         if (accnosName == "not found") { accnosName = "";  }
84                         else { 
85                                 hasAccnos = true;
86                                 splitAtDash(accnosName, accnosFileNames);
87                                 
88                                 //go through files and make sure they are good, if not, then disregard them
89                                 for (int i = 0; i < accnosFileNames.size(); i++) {
90                                         if (inputDir != "") {
91                                                 string path = hasPath(accnosFileNames[i]);
92                                                 //if the user has not given a path then, add inputdir. else leave path alone.
93                                                 if (path == "") {       accnosFileNames[i] = inputDir + accnosFileNames[i];             }
94                                         }
95         
96                                         ifstream in;
97                                         int ableToOpen = openInputFile(accnosFileNames[i], in, "noerror");
98                                 
99                                         //if you can't open it, try default location
100                                         if (ableToOpen == 1) {
101                                                 if (m->getDefaultPath() != "") { //default path is set
102                                                         string tryPath = m->getDefaultPath() + getSimpleName(accnosFileNames[i]);
103                                                         m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
104                                                         ableToOpen = openInputFile(tryPath, in, "noerror");
105                                                         accnosFileNames[i] = tryPath;
106                                                 }
107                                         }
108                                         in.close();
109                                         
110                                         if (ableToOpen == 1) { 
111                                                 m->mothurOut("Unable to open " + accnosFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
112                                                 //erase from file list
113                                                 accnosFileNames.erase(accnosFileNames.begin()+i);
114                                                 i--;
115                                         }
116                                 }
117                                 
118                                 //make sure there is at least one valid file left
119                                 if (accnosFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
120                         }
121                         
122                         if (hasAccnos) {
123                                 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(); }
124                         }
125                         
126                         string temp = validParameter.validFile(parameters, "qfile", false);                     if (temp == "not found"){       temp = "T";                             }
127                         qual = isTrue(temp); 
128                         
129                         temp = validParameter.validFile(parameters, "fasta", false);                            if (temp == "not found"){       temp = "T";                             }
130                         fasta = isTrue(temp); 
131                         
132                         temp = validParameter.validFile(parameters, "flow", false);                                     if (temp == "not found"){       temp = "F";                             }
133                         flow = isTrue(temp); 
134                         
135                         temp = validParameter.validFile(parameters, "trim", false);                                     if (temp == "not found"){       temp = "T";                             }
136                         trim = isTrue(temp); 
137                         
138                         temp = validParameter.validFile(parameters, "sfftxt", false);                           if (temp == "not found"){       temp = "F";                             }
139                         sfftxt = isTrue(temp); 
140                 }
141         }
142         catch(exception& e) {
143                 m->errorOut(e, "SffInfoCommand", "SffInfoCommand");
144                 exit(1);
145         }
146 }
147 //**********************************************************************************************************************
148
149 void SffInfoCommand::help(){
150         try {
151                 m->mothurOut("The sffinfo command reads a sff file and outputs a .sff.txt file.\n");
152                 
153                 m->mothurOut("Example sffinfo(sff=...).\n");
154                 m->mothurOut("Note: No spaces between parameter labels (i.e. sff), '=' and parameters (i.e.yourSffFileName).\n\n");
155         }
156         catch(exception& e) {
157                 m->errorOut(e, "SffInfoCommand", "help");
158                 exit(1);
159         }
160 }
161 //**********************************************************************************************************************
162
163 SffInfoCommand::~SffInfoCommand(){}
164
165 //**********************************************************************************************************************
166 int SffInfoCommand::execute(){
167         try {
168                 
169                 if (abort == true) { return 0; }
170                 
171                 for (int s = 0; s < filenames.size(); s++) {
172                         
173                         if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());         } return 0; }
174                         
175                         int start = time(NULL);
176                         
177                         m->mothurOut("Extracting info from " + filenames[s] + " ..." ); m->mothurOutEndLine();
178                         
179                         string accnos = "";
180                         if (hasAccnos) { accnos = accnosFileNames[s]; }
181                         
182                         int numReads = extractSffInfo(filenames[s], accnos);
183
184                         m->mothurOut("It took " + toString(time(NULL) - start) + " secs to extract " + toString(numReads) + ".");
185                 }
186                 
187                 if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());         } return 0; }
188                 
189                 //report output filenames
190                 m->mothurOutEndLine();
191                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
192                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
193                 m->mothurOutEndLine();
194
195                 return 0;
196         }
197         catch(exception& e) {
198                 m->errorOut(e, "SffInfoCommand", "execute");
199                 exit(1);
200         }
201 }
202 //**********************************************************************************************************************
203 int SffInfoCommand::extractSffInfo(string input, string accnos){
204         try {
205                 
206                 if (outputDir == "") {  outputDir += hasPath(input); }
207                 
208                 if (accnos != "")       {  readAccnosFile(accnos);  }
209                 else                            {       seqNames.clear();               }
210
211                 ofstream outSfftxt, outFasta, outQual, outFlow;
212                 string outFastaFileName, outQualFileName;
213                 string sfftxtFileName = outputDir + getRootName(getSimpleName(input)) + "sff.txt";
214                 string outFlowFileName = outputDir + getRootName(getSimpleName(input)) + "flow";
215                 if (trim) {
216                         outFastaFileName = outputDir + getRootName(getSimpleName(input)) + "fasta";
217                         outQualFileName = outputDir + getRootName(getSimpleName(input)) + "qual";
218                 }else{
219                         outFastaFileName = outputDir + getRootName(getSimpleName(input)) + "raw.fasta";
220                         outQualFileName = outputDir + getRootName(getSimpleName(input)) + "raw.qual";
221                 }
222                 
223                 if (sfftxt) { openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint);  outputNames.push_back(sfftxtFileName); }
224                 if (fasta)      { openOutputFile(outFastaFileName, outFasta);   outputNames.push_back(outFastaFileName); }
225                 if (qual)       { openOutputFile(outQualFileName, outQual);             outputNames.push_back(outQualFileName);  }
226                 if (flow)       { openOutputFile(outFlowFileName, outFlow);             outputNames.push_back(outFlowFileName);  }
227                 
228                 ifstream in;
229                 in.open(input.c_str(), ios::binary);
230                 
231                 CommonHeader header; 
232                 readCommonHeader(in, header);
233                 
234                 int count = 0;
235                 
236                 //check magic number and version
237                 if (header.magicNumber != 779314790) { m->mothurOut("Magic Number is not correct, not a valid .sff file"); m->mothurOutEndLine(); return count; }
238                 if (header.version != "0001") { m->mothurOut("Version is not supported, only support version 0001."); m->mothurOutEndLine(); return count; }
239         
240                 //print common header
241                 if (sfftxt) { printCommonHeader(outSfftxt, header); }
242                 
243                 //read through the sff file
244                 while (!in.eof()) {
245                         
246                         bool print = true;
247                         
248                         //read header
249                         Header readheader;
250                         readHeader(in, readheader);
251                         
252                         //read data
253                         seqRead read; 
254                         readSeqData(in, read, header.numFlowsPerRead, readheader.numBases);
255                         
256                         //if you have provided an accosfile and this seq is not in it, then dont print
257                         if (seqNames.size() != 0) {   if (seqNames.count(readheader.name) == 0) { print = false; }  }
258                         
259                         //print 
260                         if (print) {
261                                 if (sfftxt) { printHeader(outSfftxt, readheader); printSffTxtSeqData(outSfftxt, read); }
262                                 if (fasta)      {       printFastaSeqData(outFasta, read, readheader);  }
263                                 if (qual)       {       printQualSeqData(outQual, read, readheader);    }
264                                 if (flow)       {       printFlowSeqData(outFlow, read, readheader);    }
265                         }
266                         
267                         count++;
268                         
269                         //report progress
270                         if((count+1) % 500 == 0){       m->mothurOut(toString(count+1)); m->mothurOutEndLine();         }
271                 
272                         if (m->control_pressed) { count = 0; break;   }
273                         
274                         if (count >= header.numReads) { break; }
275                 }
276                 
277                 //report progress
278                 if (!m->control_pressed) {   if((count) % 500 != 0){    m->mothurOut(toString(count)); m->mothurOutEndLine();           }  }
279                 
280                 in.close();
281                 
282                 if (sfftxt) {  outSfftxt.close();       }
283                 if (fasta)      {  outFasta.close();    }
284                 if (qual)       {  outQual.close();             }
285                 if (flow)       {  outFlow.close();             }
286                 
287                 return count;
288         }
289         catch(exception& e) {
290                 m->errorOut(e, "SffInfoCommand", "extractSffInfo");
291                 exit(1);
292         }
293 }
294 //**********************************************************************************************************************
295 int SffInfoCommand::readCommonHeader(ifstream& in, CommonHeader& header){
296         try {
297
298                 if (!in.eof()) {
299                 
300                         //read magic number
301                         char buffer[sizeof(header.magicNumber)];
302                         in.read(buffer, sizeof(header.magicNumber));
303                         header.magicNumber = be_int4(*(unsigned int *)(&buffer));
304                         
305                         //read version
306                         char buffer9[4];
307                         in.read(buffer9, 4);
308                         header.version = "";
309                         for (int i = 0; i < 4; i++) {  header.version += toString((int)(buffer9[i])); }
310                                 
311                         //read offset
312                         char buffer2 [sizeof(header.indexOffset)];
313                         in.read(buffer2, sizeof(header.indexOffset));
314                         header.indexOffset =  be_int8(*(unsigned long int *)(&buffer2));
315                         
316                         //read index length
317                         char buffer3 [sizeof(header.indexLength)];
318                         in.read(buffer3, sizeof(header.indexLength));
319                         header.indexLength =  be_int4(*(unsigned int *)(&buffer3));
320                         
321                         //read num reads
322                         char buffer4 [sizeof(header.numReads)];
323                         in.read(buffer4, sizeof(header.numReads));
324                         header.numReads =  be_int4(*(unsigned int *)(&buffer4));
325                                 
326                         //read header length
327                         char buffer5 [sizeof(header.headerLength)];
328                         in.read(buffer5, sizeof(header.headerLength));
329                         header.headerLength =  be_int2(*(unsigned short *)(&buffer5));
330                                         
331                         //read key length
332                         char buffer6 [sizeof(header.keyLength)];
333                         in.read(buffer6, sizeof(header.keyLength));
334                         header.keyLength = be_int2(*(unsigned short *)(&buffer6));
335                         
336                         //read number of flow reads
337                         char buffer7 [sizeof(header.numFlowsPerRead)];
338                         in.read(buffer7, sizeof(header.numFlowsPerRead));
339                         header.numFlowsPerRead =  be_int2(*(unsigned short *)(&buffer7));
340                                 
341                         //read format code
342                         char buffer8 [1];
343                         in.read(buffer8, 1);
344                         header.flogramFormatCode = (int)(buffer8[0]);
345                         
346                         //read flow chars
347                         char tempBuffer [header.numFlowsPerRead];
348                         in.read(tempBuffer, header.numFlowsPerRead); 
349                         header.flowChars = tempBuffer;
350                         if (header.flowChars.length() > header.numFlowsPerRead) { header.flowChars = header.flowChars.substr(0, header.numFlowsPerRead);  }
351                         
352                         //read key
353                         char tempBuffer2 [header.keyLength];
354                         in.read(tempBuffer2, header.keyLength);
355                         header.keySequence = tempBuffer2;
356                         if (header.keySequence.length() > header.keyLength) { header.keySequence = header.keySequence.substr(0, header.keyLength);  }
357                                 
358                         /* Pad to 8 chars */
359                         int spotInFile = in.tellg();
360                         int spot = (spotInFile + 7)& ~7;  // ~ inverts
361                         in.seekg(spot);
362                         
363                 }else{
364                         m->mothurOut("Error reading sff common header."); m->mothurOutEndLine();
365                 }
366
367                 return 0;
368         }
369         catch(exception& e) {
370                 m->errorOut(e, "SffInfoCommand", "readCommonHeader");
371                 exit(1);
372         }
373 }
374 //**********************************************************************************************************************
375 int SffInfoCommand::readHeader(ifstream& in, Header& header){
376         try {
377         
378                 if (!in.eof()) {
379                         
380                         //read header length
381                         char buffer [sizeof(header.headerLength)];
382                         in.read(buffer, sizeof(header.headerLength));
383                         header.headerLength = be_int2(*(unsigned short *)(&buffer));
384                                                 
385                         //read name length
386                         char buffer2 [sizeof(header.nameLength)];
387                         in.read(buffer2, sizeof(header.nameLength));
388                         header.nameLength = be_int2(*(unsigned short *)(&buffer2));
389
390                         //read num bases
391                         char buffer3 [sizeof(header.numBases)];
392                         in.read(buffer3, sizeof(header.numBases));
393                         header.numBases =  be_int4(*(unsigned int *)(&buffer3));
394                         
395                         //read clip qual left
396                         char buffer4 [sizeof(header.clipQualLeft)];
397                         in.read(buffer4, sizeof(header.clipQualLeft));
398                         header.clipQualLeft =  be_int2(*(unsigned short *)(&buffer4));
399                         
400                         //read clip qual right
401                         char buffer5 [sizeof(header.clipQualRight)];
402                         in.read(buffer5, sizeof(header.clipQualRight));
403                         header.clipQualRight =  be_int2(*(unsigned short *)(&buffer5));
404                         
405                         //read clipAdapterLeft
406                         char buffer6 [sizeof(header.clipAdapterLeft)];
407                         in.read(buffer6, sizeof(header.clipAdapterLeft));
408                         header.clipAdapterLeft = be_int2(*(unsigned short *)(&buffer6));
409
410                         //read clipAdapterRight
411                         char buffer7 [sizeof(header.clipAdapterRight)];
412                         in.read(buffer7, sizeof(header.clipAdapterRight));
413                         header.clipAdapterRight = be_int2(*(unsigned short *)(&buffer7));
414                 
415                         //read name
416                         char tempBuffer [header.nameLength];
417                         in.read(tempBuffer, header.nameLength);
418                         header.name = tempBuffer;
419                         if (header.name.length() > header.nameLength) { header.name = header.name.substr(0, header.nameLength);  }
420                         
421                         /* Pad to 8 chars */
422                         int spotInFile = in.tellg();
423                         int spot = (spotInFile + 7)& ~7;
424                         in.seekg(spot);
425                         
426                 }else{
427                         m->mothurOut("Error reading sff header info."); m->mothurOutEndLine();
428                 }
429
430                 return 0;
431         }
432         catch(exception& e) {
433                 m->errorOut(e, "SffInfoCommand", "readHeader");
434                 exit(1);
435         }
436 }
437 //**********************************************************************************************************************
438 int SffInfoCommand::readSeqData(ifstream& in, seqRead& read, int numFlowReads, int numBases){
439         try {
440         
441                 if (!in.eof()) {
442         
443                         //read flowgram
444                         read.flowgram.resize(numFlowReads);
445                         for (int i = 0; i < numFlowReads; i++) {  
446                                 char buffer [sizeof(unsigned short)];
447                                 in.read(buffer, (sizeof(unsigned short)));
448                                 read.flowgram[i] = be_int2(*(unsigned short *)(&buffer));
449                         }
450         
451                         //read flowIndex
452                         read.flowIndex.resize(numBases);
453                         for (int i = 0; i < numBases; i++) {  
454                                 char temp[1];
455                                 in.read(temp, 1);
456                                 read.flowIndex[i] = be_int1(*(unsigned char *)(&temp));
457                         }
458                 
459                         //read bases
460                         char tempBuffer[numBases];
461                         in.read(tempBuffer, numBases);
462                         read.bases = tempBuffer;
463                         if (read.bases.length() > numBases) { read.bases = read.bases.substr(0, numBases);  }
464
465                         //read flowgram
466                         read.qualScores.resize(numBases);
467                         for (int i = 0; i < numBases; i++) {  
468                                 char temp[1];
469                                 in.read(temp, 1);
470                                 read.qualScores[i] = be_int1(*(unsigned char *)(&temp));
471                         }
472                 
473                         /* Pad to 8 chars */
474                         int spotInFile = in.tellg();
475                         int spot = (spotInFile + 7)& ~7;
476                         in.seekg(spot);
477                         
478                 }else{
479                         m->mothurOut("Error reading."); m->mothurOutEndLine();
480                 }
481
482                 return 0;
483         }
484         catch(exception& e) {
485                 m->errorOut(e, "SffInfoCommand", "readSeqData");
486                 exit(1);
487         }
488 }
489 //**********************************************************************************************************************
490 int SffInfoCommand::printCommonHeader(ofstream& out, CommonHeader& header) {
491         try {
492         
493                 out << "Common Header:\nMagic Number: " << header.magicNumber << endl;
494                 out << "Version: " << header.version << endl;
495                 out << "Index Offset: " << header.indexOffset << endl;
496                 out << "Index Length: " << header.indexLength << endl;
497                 out << "Number of Reads: " << header.numReads << endl;
498                 out << "Header Length: " << header.headerLength << endl;
499                 out << "Key Length: " << header.keyLength << endl;
500                 out << "Number of Flows: " << header.numFlowsPerRead << endl;
501                 out << "Format Code: " << header.flogramFormatCode << endl;
502                 out << "Flow Chars: " << header.flowChars << endl;
503                 out << "Key Sequence: " << header.keySequence << endl << endl;
504                         
505                 return 0;
506         }
507         catch(exception& e) {
508                 m->errorOut(e, "SffInfoCommand", "printCommonHeader");
509                 exit(1);
510         }
511 }
512 //**********************************************************************************************************************
513 int SffInfoCommand::printHeader(ofstream& out, Header& header) {
514         try {
515                 
516                 out << ">" << header.name << endl;
517                 out << "Run Prefix: " << endl;
518                 out << "Region #:  " << endl;
519                 out << "XY Location: " << endl << endl;
520                 
521                 out << "Run Name:  " << endl;
522                 out << "Analysis Name:  " << endl;
523                 out << "Full Path: " << endl << endl;
524                 
525                 out << "Read Header Len: " << header.headerLength << endl;
526                 out << "Name Length: " << header.nameLength << endl;
527                 out << "# of Bases: " << header.numBases << endl;
528                 out << "Clip Qual Left: " << header.clipQualLeft << endl;
529                 out << "Clip Qual Right: " << header.clipQualRight << endl;
530                 out << "Clip Adap Left: " << header.clipAdapterLeft << endl;
531                 out << "Clip Adap Right: " << header.clipAdapterRight << endl << endl;
532                 
533                 return 0;
534         }
535         catch(exception& e) {
536                 m->errorOut(e, "SffInfoCommand", "printHeader");
537                 exit(1);
538         }
539 }
540
541 //**********************************************************************************************************************
542 int SffInfoCommand::printSffTxtSeqData(ofstream& out, seqRead& read) {
543         try {
544                 
545                 out << "FlowGram: ";
546                 for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << (read.flowgram[i]/(float)100) << '\t';  }
547                 
548                 out << endl <<  "Flow Indexes: ";
549                 int sum = 0;
550                 for (int i = 0; i < read.flowIndex.size(); i++) {  sum +=  read.flowIndex[i];  out << sum << '\t'; }
551                 
552                 out << endl <<  "Bases: " << read.bases << endl << "Quality Scores: ";
553                 for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
554                 out << endl << endl;
555                 
556                 return 0;
557         }
558         catch(exception& e) {
559                 m->errorOut(e, "SffInfoCommand", "printSffTxtSeqData");
560                 exit(1);
561         }
562 }
563 //**********************************************************************************************************************
564 int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& header) {
565         try {
566                 
567                 string seq = read.bases;
568                 
569                 
570                 if (trim) {
571                         seq = seq.substr(header.clipQualLeft, (header.clipQualRight-header.clipQualLeft));
572                 }
573                 
574                 out << ">" << header.name << endl;
575                 out << seq << endl;
576                 
577                 return 0;
578         }
579         catch(exception& e) {
580                 m->errorOut(e, "SffInfoCommand", "printFastaSeqData");
581                 exit(1);
582         }
583 }
584
585 //**********************************************************************************************************************
586 int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& header) {
587         try {
588                 
589                 if (trim) {
590                         out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
591                         for (int i = header.clipQualLeft; i < (header.clipQualRight-header.clipQualLeft); i++) {   out << read.qualScores[i] << '\t';  }
592                 }else{
593                         out << ">" << header.name << " length=" << read.qualScores.size() << endl;
594                         for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
595                 }
596                 
597                 out << endl;
598                 
599                 return 0;
600         }
601         catch(exception& e) {
602                 m->errorOut(e, "SffInfoCommand", "printQualSeqData");
603                 exit(1);
604         }
605 }
606
607 //**********************************************************************************************************************
608 int SffInfoCommand::printFlowSeqData(ofstream& out, seqRead& read, Header& header) {
609         try {
610                 
611                 out << ">" << header.name << endl;
612                 for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << (read.flowgram[i]/(float)100) << '\t';  }
613                 out << endl;
614                 
615                 return 0;
616         }
617         catch(exception& e) {
618                 m->errorOut(e, "SffInfoCommand", "printFlowSeqData");
619                 exit(1);
620         }
621 }
622 //**********************************************************************************************************************
623 int SffInfoCommand::readAccnosFile(string filename) {
624         try {
625                 //remove old names
626                 seqNames.clear();
627                 
628                 ifstream in;
629                 openInputFile(filename, in);
630                 string name;
631                 
632                 while(!in.eof()){
633                         in >> name; gobble(in);
634                                                 
635                         seqNames.insert(name);
636                         
637                         if (m->control_pressed) { seqNames.clear(); break; }
638                 }
639                 in.close();             
640                 
641                 return 0;
642         }
643         catch(exception& e) {
644                 m->errorOut(e, "SffInfoCommand", "readAccnosFile");
645                 exit(1);
646         }
647 }
648 //**********************************************************************************************************************/