// ----------------------------------------------------------------------
// //
// // File:        Samples.c
// //
// // Description:
// //
// // Date:        January 29, 2004
// //
// // Author(s):   Giri Narasimhan, Florida International University
// //
// // ----------------------------------------------------------------------

#include "Samples.h"

static char *usage =
"\nUsage: ./peaks fileName [-t] [-s T] [-a] [-h] [-d] \n"
"Run the peaks analysis software with given file fileName. \n"
"\t-h \t Print this help message. \n"
"\t-s T\t Use threshold value of T. \n"
"\t-t outF\t Compute threshold. Output all trace values to outF. \n"
"\t-d \t Debug Mode. \n"
"\t-a \t Analyze peaks data. Analysis output sent to screen. \n";

int main(int argc, char *argv[])
{
  cout << "========================================================\n";
  cout << "Welcome! \n";

  Samples S = Samples();
  int param = 1;
  while (param < argc)
    {
      if (!strcmp(argv[param],"-t"))  // Homozygous threshold computation
	{
	  ifstream fIn(argv[1], ios::in);
	  cout << "Input File: " << '\"' << argv[1] << '\"' << endl;
	  if (fIn.fail())
	    {
	      cout << "Error opening file " << argv[1] << endl;
	      exit(1);
	    }
	  S.ReadAllHSamples(fIn);
	  ofstream fOutT(argv[++param], ios::out); // file to output all trace values
	  cout << "Output File for Trace Values: " << '\"' 
	       << argv[param] << '\"' << endl;
	  cout << "========================================================\n";
	  S.setThreshold(S.computeThreshold(fOutT));
	  cout << "Computed Threshold = " << S.getThreshold() << endl;
	}

      if (!strcmp(argv[param],"-s"))  // Use given threshold value for analysis. 
	{
	  float thresh = atof(argv[++param]);
	  S.setThreshold(thresh);
	  cout << "Threshold set to " << thresh << endl;
	}

      if (!strcmp(argv[param],"-a"))  // Analyze Homozy-Heterozy Samples.
	{
	  ifstream fIn(argv[1], ios::in);
	  cout << "Input File: " << '\"' << argv[1] << '\"' << endl;
	  if (fIn.fail())
	    {
	      cout << "Error opening file " << argv[1] << endl;
	      exit(1);
	    }
	  S.ReadAllSamples(fIn);
	  S.ProcessAllSamples();
	}

      if ((!strcmp(argv[param],"-h")) || (!strcmp(argv[param],"-H")))  // Usage
        {
	  cerr << usage; 
	  return 0; 
	}

      if ((!strcmp(argv[param],"-d")))  // Usage
        {
	  S.setDEBUG(true); 
	}

      param++;
   }
}
