/*****************************************************************************
#   Copyright (C) 1994-2008 by David Gordon.
#   All rights reserved.                           
#                                                                           
#   This software is part of a beta-test version of the Consed/Autofinish
#   package.  It should not be redistributed or
#   used for any commercial purpose, including commercially funded
#   sequencing, without written permission from the author and the
#   University of Washington.
#   
#   This software is provided ``AS IS'' and any express or implied
#   warranties, including, but not limited to, the implied warranties of
#   merchantability and fitness for a particular purpose, are disclaimed.
#   In no event shall the authors or the University of Washington be
#   liable for any direct, indirect, incidental, special, exemplary, or
#   consequential damages (including, but not limited to, procurement of
#   substitute goods or services; loss of use, data, or profits; or
#   business interruption) however caused and on any theory of liability,
#   whether in contract, strict liability, or tort (including negligence
#   or otherwise) arising in any way out of the use of this software, even
#   if advised of the possibility of such damage.
#
#   Building Consed from source is error prone and not simple which is
#   why I provide executables.  Due to time limitations I cannot
#   provide any assistance in building Consed.  Even if you do not
#   modify the source, you may introduce errors due to using a
#   different version of the compiler, a different version of motif,
#   different versions of other libraries than I used, etc.  For this
#   reason, if you discover Consed bugs, I can only offer help with
#   those bugs if you first reproduce those bugs with an executable
#   provided by me--not an executable you have built.
# 
#   Modifying Consed is also difficult.  Although Consed is modular,
#   some modules are used by many other modules.  Thus making a change
#   in one place can have unforeseen effects on many other features.
#   It may takes months for you to notice these other side-effects
#   which may not seen connected at all.  It is not feasable for me to
#   provide help with modifying Consed sources because of the
#   potentially huge amount of time involved.
#
#*****************************************************************************/
//
// main.cpp
//
// main routine for consEd application
//
//

// main.cpp_part1

// edit the following for new applications: main.cpp_part1, main.cpp_part11
// you can also edit main.cpp_part8 for compatibility between arguments

#include    <new.h>
#include    <setjmp.h>
#include    <signal.h>
#include    <stdlib.h>
#include    <sys/utsname.h>
#include    <time.h>
#include    <unistd.h>

#include    "addAlignedSequence.h"
#include    "addNewReads.h"
#include    "addNewReadsAutomated.h"
#include    "addNewReadsWithExistingAlignments.h"
#include    "assemblyView.h"
#include    "autoEdit.h"
#include    "autoFinish.h"
#include    "autoPCRAmplify.h"
#include    "autoReport.h"
#include    "bIsNumericMaybeWithWhitespace.h"
#include    "checkLicenseKey.h"
#include    "checkVariableLengthLimit.h"
#include    "consed.h"
#include    "consedParameters.h"
#include    "consedResources.h"
#include    "consedResources.h"
#include    "consed_version.h"
#include    "contigwin.h"
#include    "fileDefines.h"
#include    "guiTopWindow.h"
#include    "guiapp.h"
#include    "listOfLibraries.h"
#include    "maybeTerminateIfAnotherReadWriteConsed.h"
#include    "mbt_exception.h"
#include    "perhapsCreateSocketToControlConsed.h"
#include    "printMemory.h"
#include    "printSingleSignal.h"
#include    "printTime.h"
#include    "readAndProcessReadPrefixFile.h"
#include    "rwctokenizer.h"
#include    "saveTagTypes.h"
#include    "setComplementBaseTable.h"
#include    "setErrorRateFromQuality.h"
#include    "setNotACGTTable.h"
#include    "setNumberFromBaseTable.h"
#include    "solexa2PhdBall.h"
#include    "sysdepend.h"
#include    "tagSNPs.h"
#include    "terminateIfNoPhdDir.h"
#include    "whatIsRunning.h"
#include    "phdBall2Fasta.h"
#include    "testReadPhdBall.h"
#include    "removeReads.h"
#include    "removeContigs.h"
#include    "printDefaultResources.h"
#include    "sff2PhdBall.h"
#include    "guiEditResourcesStandalone.h"
#include    "defaultResourcesDefinition.h"
#include    "batchChangeConsensus.h"
#include    "snpGenome.h"
#include    "diffChromosomes.h"
#include    "nextPhredPipeline.h"
#include    "fixContigEnds.h"
#include    "geneClassifications.h"
#include    "phaster2PhdBall.h"
#include    "miscProgram.h"



// definition for soEmptyString.h

RWCString soEmptyString = "";


bool bNoBaseSeg = false;
bool bNoSetSequence = false;
bool bNoFragments = false;
bool bNoListOfFragments = false;
bool bUnsortedBaseSegArray = false;
bool bUsingPhdFiles = true;
bool bReadOnly = false;

int nNumberOfErrorWindowsCurrentlyUp = 0; // global, used by 
// popupInfoOrErrorMessageNoFormat.cpp



jmp_buf jmpBuffer;

const int nErrorReturn = 1;

static void handleSegmentationFault( int nSigNo ) {
   fprintf( stderr, "Error from consed:  segmentation fault.  Attempting to continue\n" );
   longjmp( jmpBuffer, nErrorReturn );
}

static bool bEstablishErrorHandler() {
   if ( setjmp( jmpBuffer ) == nErrorReturn ) {
      // just returned from an error
      if ( setjmp( jmpBuffer ) != 0 ) {
         cerr << "can't establish setjmp for handler of segmentation faults" << endl;
      }
   }
   else if ( setjmp( jmpBuffer ) == 0 ) {
      if ( signal( SIGSEGV, handleSegmentationFault ) == SIG_ERR ) {
         cerr << "can't establish handler for segmentation faults" << endl;
      }
      return( true );
   }
   else {
      cerr << "can't establish setjmp for handler of segmentation faults2" << endl;
   }

   return( false );
}


static void myNewHandler() {
  printMemory( "In new memory handler" );
   cerr<< "Consed: out of memory on heap (datasize)" << endl;
   cerr<< "new threw an exception--you have run out of memory" << endl;
   cerr<< "There is not enough datasize (heap)." << endl;
   cerr<< "There may not be enough physical memory, or else" << endl;  
   cerr<< "there may be a software limit imposed on this process." <<  endl;
   cerr<< "With tcsh, use type: limit to see what you are currently using." << endl;
   cerr<< "Then type: limit datasize unlimited " << endl << ends;
   cerr.flush();

   ostrstream ost;
   ost << "Consed: out of memory on heap (datasize)" << endl;
   ost << "new threw an exception--you have run out of memory" << endl;
   ost << "There is not enough datasize (heap)." << endl;
   ost << "There may not be enough physical memory, or else" << endl;  
   ost << "there may be a software limit imposed on this process." <<  endl;
   ost << "With tcsh, use type: limit to see what you are currently using." << endl;
   ost << "Then type: limit datasize unlimited " << endl << ends;
   SysRequestFailed sys( ost.str() );

   throw( sys );
}




static void checkIfOperatingSystemIsOK() {
   struct utsname myUtsname;

   int nError = uname( &myUtsname );

   if ( nError != -1 ) {

      RWCString soOperatingSystem;
      soOperatingSystem.getField( myUtsname.sysname, 9 );

      soOperatingSystem.toLower();
      if ( soOperatingSystem == "linux" ) {
         RWCString soRelease;
         soRelease.getField( myUtsname.release, 9 );
         RWCString soVersion;
         soVersion.getField( myUtsname.version, 9 );
      
         // cerr << "release: " << soRelease << " version: " << soVersion << endl;

         // check that this is 2.4 or better
         // current version is 2.4.2-2sm
         // Algorithm:  look for the first character that isn't
         // a [0-9] or "." and just consider that portion.  Separate it
         // by "."  If the first number is greater than 3, accept.  Otherwise
         // it must be a 2 and look at the next number.  If the next
         // number is more than a 4, accept, otherwise it must be a 4 and
         // look at the next number.  The next number must be a 2 or greater
         // in this case.
      
         size_t nFirstBad = strspn( soRelease.data(), "0123456789." );
         soRelease.truncate( nFirstBad );

         RWCTokenizer tok( soRelease );

         RWCString soFirst = tok('.');
         RWCString soSecond = tok('.');
         RWCString soThird = tok('.' );

         int nFirst;
         assert( bIsNumericMaybeWithWhitespace( soFirst, nFirst ) );

         if ( nFirst > 2 )
            return;  // we are fine.

      
         if ( nFirst < 2 ) {
            cerr << "Sorry:  the linux kernel must be version 2.4.2 or better.  Type \"uname -a\" to find your current version. (1)" << endl;
            exit( -1 );
         }

         // if reached here, must be version 2.?.?


         int nSecond;
         assert( bIsNumericMaybeWithWhitespace( soSecond, nSecond ) );

         if ( nSecond > 4 )
            return;  // we are fine

         if ( nSecond < 4 ) {
            cerr << "Sorry:  the linux kernel must be version 2.4.2 or better.  Type \"uname -a\" to find your current version. (2)" << endl;
            exit( -1 );
         }

         int nThird;
         assert( bIsNumericMaybeWithWhitespace( soThird, nThird ) );

         if ( nThird >= 2 ) 
            return;  // we are fine

      
         // if reached here, the user is using an operating system that is 
         // too old.

         cerr << "Sorry:  the linux kernel must be version 2.4.2 or better.  Type \"uname -a\" to find your current version. (3)" << endl;
         exit( -1 );
      
      }
      else if ( soOperatingSystem == "darwin" ) {

         RWCString soRelease;
         soRelease.getField( myUtsname.release, 9 );

	 cerr << "Darwin Version: " << soRelease << endl;

         size_t nFirstBad = strspn( soRelease.data(), "0123456789." );
         soRelease.truncate( nFirstBad );

         RWCTokenizer tok( soRelease );

         RWCString soFirst = tok('.');
         RWCString soSecond = tok('.');
         RWCString soThird = tok('.' );

	 int nVersion;
	 if (!bIsNumericMaybeWithWhitespace( soFirst, nVersion ) ) {
	   return; // don't know if we are ok, but don't know we are not ok
	 }


	 if ( nVersion < 6 ) {
	   cerr << "Sorry: if you are running Macosx, you must be running version 10.2 or better (Darwin kernel 6.0 or better)" << endl;
	   exit( -1 );
	 }
      }
   }

}



// main.cpp_part3






//main.cpp_part3 starts

static RWCString soUsage = 
"\
-ace\n\
   -ace must be followed by a space and then the ace filename\n\
-socket\n\
   -socket must be followed by a space and then a number (the local port number)\n\
-nophd\n\
-autoFinish\n\
-doExperiments\n\
-autoPCRAmplify\n\
   -autoPCRAmplify must be followed by a space and then the name of the file of primer regions\n\
-justCheckAutoFinishReads\n\
-id\n\
   -id must be followed by a space and then the id\n\
-contig\n\
   -contig must be followed by a space and then the contig name\n\
-fileNamesFile\n\
   -filenamesFile must be followed by a space and then the name of the file to contain the filenames\n\
-read_only\n\
-addNewReads\n\
   -addNewReads must be followed by a space and then the name of the file containing the reads to be added\n\
-addReads\n\
   -addReads must be followed by a space and then the name of the file containing a list of the cross_match alignment files\n\
-chem\n\
   -chem must be followed by a space and then the chemistry which can be one of solexa, 454, or Sanger\n\
-autoEdit\n\
-newAceFileName\n\
   -newAceFilename must be followed by a space and then the name of the ace file to be created\n\
-autoReport\n\
-nav\n\
   -nav must be followed by a space and then the name of the custom navigation file\n\
-allowTimestampMismatch\n\
-mainContigPos\n\
   -maincontigpos must be followed by a space and then the unpadded consensus position of the main contig\n\
-solexa2PhdBall\n\
   -solexa2PhdBall must be followed by a space and then the name of a file containing the name of the solexa fastq files.\n\
-phdBallFOF\n\
   -phdBallFOF must be followed by a space and then the name of the phdballfof to be created.  This file contains a list of all of the phdballs created.\n\
-selectRegions\n\
   -selectRegions must be followed by a space and then the name of the regions file\n\
-alignments\n\
   -alignments must be followed by a space and then the name of an fof of alignments files for -selectRegions\n\
-phdBall2Fasta\n\
   -phdBall2Fasta must be followed by a space and then the name of the phd ball\n\
-fasta\n\
   -fasta must be followed by a space and then the name of the output fasta file\n\
-fastq\n\
   -fastq must be followed by a space and then the name of the output fastq file\n\
-testReadPhdBall\n\
   -testReadPhdBall must be followed by a space and then the phdball to be read for testing purposes\n\
-removeReads\n\
   -removeReads must be followed by a space and then the file containing the reads to be removed.  Use consed.removeReadsPutIntoOwnContig: true/false to determine whether the removed reads are just put into their own contigs or completely removed\n\
-removeContigs\n\
   -removeContigs must be followed by a space and then the file containing the contigs to be removed.  Use consed.removeReadsPutIntoOwnContig: true/false to determine whether the removed reads are just put into their own contigs or completely removed\n\
-printDefaultResources\n\
-sff2PhdBall\n\
   -sff2PhdBall must be followed by a space and then full path of the sff file\n\
-phdBall\n\
   -phdBall must be followed by a space and then the full path of the phd ball\n\
-fof\n\
   -fof must be followed by a space and then the name of a file containing read names\n\
-editConsedrc\n\
-changeConsensus\n\
   -changeConsensus must be followed by a space and then the name of the file with lines like this:  Contig21 28-30 x where Contig21 is the contig, 28-30 are the unpadded positions and x is the new base.  To change a pad (let's say at padded position 35, specify this as *35 as in Contig21 *35-*40 c\n\
-snpGenome\n\
   -snpGenome must be followed by a space and then the full path of the snp table in ucsc format\n\
-genome\n\
   -genome is used by -snpGenome.  It must be followed by a space and then a file that has 3 columns for each chromosome:  the name of the chromosome in the snp file, the full path of the corresponding chromosome in fasta format, and the full path of the snp-annotated chromosome to be created.\n\
-valid\n\
   -valid is used by -snpGenome.  It must be followed by a space and then a file that lists, one per line, each validation combination for which *no* snps are to be used.\n\
-diffChromosomes\n\
   -diffChromosomes must be followed by a space and then the full or relative path of the other directory containing the chromosome files\n\
-addFlowcells\n\
   -addFlowcells must be followed by a space and then the full or relative path of file containing flowcell lines\n\
-controlFile\n\
   -controlFile must be followed by a space and then the full or relative path of the control file\n\
-fixContigEnds\n\
-contigEndsFOF\n\
   -contigEndsFOF must be followed by a space and then the full or relative path of a file which each line having (contig name) (left or right)\n\
-geneClassifications\n\
   -geneClassifications must be followed by a space and then the full or relative path of the list of genomic locations in the format chr1 345671\n\
-chromosomesFOF\n\
   -chromosomesFOF must be followed by a space and then the full or relative path of a file containing the full or relative paths of the chromosomes in fasta format\n\
-knownGene\n\
   -knownGene must be followed by a space and then the full or relative path of a file containing the full or relative paths of the knownGene.txt file\n\
-phaster2PhdBall\n\
   -phaster2PhdBall must be followed by a space and then the full or relative path of a file containing a list of phaster output files (assumes cref2 and -report_type:2 )\n\
-phasterLocations\n\
   -phasterLocations must be followed by a space and then the full or relative path of a file containing a list of locations in the form (full phaster genomic location) (chromosome) (1-based chromosome position)\n\
-phyloFOF\n\
   -phyloFOF must be followed by a space and then the full or relative path of a file containing the full or relative path of phyloP conservation score files in wig format such as chr11.phyloP44way.wigFix.gz\n\
-miscProgram\n\
";



// main.cpp_part4



int main(int nArgc, char* argv[]) {

   bool bAceFileOnCommandLine = false;
   FileName filAceFileToOpen;
   bool bCreateSocketToControlConsed = false;
   RWCString soSocketToControlConsedLocalPortNumber;
   bool bNoPhdFiles = false;
   bool bAutomatedFinishProgram = false;
   bool bDoExperiments = false;
   bool bAutoPCRAmplify = false;
   FileName filFileOfPrimerRegions;
   bool bJustCheckAutoFinishReads = false;
   bool bID = false;
   RWCString soID;
   bool bContigSpecified = false;
   RWCString soContig;
   bool bFileNamesFile = false;
   RWCString soFilenamesFile;
   bool bFileOfPhdFiles = false;
   FileName filFileOfPhdFiles;
   bool bTerminateAfterStartup = false;
   bool bReadOnly = false;
   bool bAddNewReads = false;
   FileName filFileOfReadsOrPhdsToAdd;
   bool bAddReads = false;
   FileName filAddNewReadsAlignmentsFOF;
   bool bChem = false;
   RWCString soChemistry;
   bool bAutoEdit = false;
   bool bNewAceFileName = false;
   FileName filNewAceFile;
   bool bAddAlignedSequence = false;
   FileName filAlignmentFastaFile;
   bool bTagSNPs = false;
   FileName filFileOfReadsOrPhdsToAddForTagSNPs;
   bool bPhdWithWRItem = false;
   FileName filPhdFileWithWRItem;
   bool bAutoReport = false;
   bool bCustomNavigation = false;
   FileName filCustomNavigation;
   bool bAllowTimestampMismatch = false;
   bool bPrintSingleSignal = false;
   RWCString soUnpaddedConsPosForSingleSignal;
   bool bMainContigPos = false;
   RWCString soUnpaddedConsPos;
   bool bSolexa2PhdBall = false;
   FileName filSolexaFOF;
   bool bNewPhdBallFOF = false;
   FileName filNewPhdBallFOF;
   bool bSelectRegions = false;
   FileName filRegionsFile;
   bool bAlignments = false;
   FileName filSelectRegionsAlignmentsFOF;
   bool bPhdBall2Fasta = false;
   FileName filPhdBall;
   bool bFasta = false;
   FileName filFasta;
   bool bFastq = false;
   FileName filFastq;
   bool bTestReadPhdBall = false;
   FileName filPhdBallForTestRead;
   bool bRemoveReads = false;
   FileName filReadsToBeRemoved;
   bool bRemoveContigs = false;
   FileName filContigsToBeRemoved;
   bool bPrintDefaultResources = false;
   bool bSff2PhdBall = false;
   FileName filSffFile;
   bool bPhdBall = false;
   FileName filNewPhdBall;
   bool bFOF = false;
   FileName filFOF;
   bool bEditConsedrc = false;
   bool bChangeConsensus = false;
   FileName filChangeConsensus;
   bool bSnpGenome = false;
   FileName filSnps;
   bool bGenome = false;
   FileName filGenome;
   bool bValid = false;
   FileName filValidation;
   bool bDiffChromosomes = false;
   FileName filOtherDirectory;
   bool bAddFlowcells = false;
   FileName filFlowcellsToAdd;
   bool bControlFile = false;
   FileName filControlFile;
   bool bFixContigEnds = false;
   bool bContigEndsFOF = false;
   FileName filContigEndsFOF;
   bool bGeneClassifications = false;
   FileName filGenomicLocations;
   bool bChromosomesFOF = false;
   FileName filChromosomesFOF;
   bool bKnownGene = false;
   FileName filKnownGene;
   bool bPhaster2PhdBall = false;
   FileName filPhasterFOF;
   bool bPhasterLocations = false;
   FileName filPhasterLocations;
   bool bPhyloFOF = false;
   FileName filPhyloFOF;
   bool bMiscProgram = false;


// main.cpp_part5

   checkIfOperatingSystemIsOK();

   RWCString soCommandLine;
   int n;
   for( n = 0; n < nArgc; ++n ) {
      soCommandLine += argv[n];
      soCommandLine += " ";
   }


   checkLicenseKey();


   set_new_handler( myNewHandler );

   checkVariableLengthLimit();
   setComplementBaseTable();
   setNumberFromBaseTable();
   setNotACGTTable();




// main.cpp_part6 start
   int nWhatIsRunning = nGraphicalConsedIsRunning;

   // nWhatIsRunning might be changed below--
   // nGraphicalConsedIsRunning is just the default

   for( n = 1; n < nArgc; ++n ) {
      RWCString soLowerCaseArg( argv[n] );
      soLowerCaseArg.toLower();
      if ( soLowerCaseArg % aszWhatIsRunning[ 2 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 2;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 3 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 3;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 4 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 4;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 5 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 5;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 6 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 6;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 7 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 7;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 8 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 8;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 9 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 9;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 10 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 10;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 11 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 11;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 12 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 12;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 13 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 13;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 14 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 14;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 15 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 15;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 16 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 16;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 17 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 17;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 18 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 18;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 19 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 19;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 20 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 20;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 21 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 21;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 22 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 22;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 23 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 23;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 24 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 24;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 25 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 25;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 26 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 26;
      }
      if ( soLowerCaseArg % aszWhatIsRunning[ 27 ] ) {
         // check if a group has already been assigned
         if ( nWhatIsRunning != nGraphicalConsedIsRunning ) {
            cerr << "Fatal Error: arguments " << aszWhatIsRunning[ nWhatIsRunning ] << " and " << argv[n] << " are mutually incompatible" << endl;
            exit( -1 );
         }

         nWhatIsRunning = 27;
      }
   }
   // when reached here, we know that the user has not specified running more
   // than one program and we have determined what that program is
   if ( nWhatIsRunning != nGraphicalConsedIsRunning )
      cerr << aszWhatIsRunning[ nWhatIsRunning ] << " will be run." << endl;



// main.cpp_part6b

   for( n = 1; n < nArgc; ++n ) {

      RWCString soLowerCaseArg( argv[n] );
      soLowerCaseArg.toLower();

      if ( strcmp(argv[n], "-noBaseSeg" )==0 ) {
         cout << "bNoBaseSeg" << endl;
         bNoBaseSeg = true;
      }
      else if ( strcmp(argv[n], "-help" ) == 0 ) {
         cout << soUsage << endl;
         cout << "for more help, bring up Consed and click on 'Help' or else see the README.txt file" << endl;
         exit( 0 );
      }
      else if ( strcmp(argv[n], "-unsortedBaseSegArray" )==0 ) {
         cout << "bUnsortedBaseSegArray" << endl;
         bNoBaseSeg = true; 
      }
      else if (strcmp( argv[n], "-noSetSequence" )==0 ) {
         cout << "bNoSetSequence" << endl;
         bNoSetSequence = true;
      }
      else if (strcmp( argv[n], "-noFragments" )==0 ) {
         cout << "bNoFragments" << endl;
         bNoFragments = true;
      }
      else if (strcmp( argv[n], "-noListOfFragments" )==0 ) {
         cout << "bNoListOfFragments" << endl;
         bNoListOfFragments = true;
      }
      else if ( soLowerCaseArg == "-v" ) {
         cout << szConsedVersion << endl;
         exit( 0 );
      }
      else if ( soLowerCaseArg == "-newphdball" ) {
         cerr << "Fatal error:  -newPhdBall is no longer supported.  phdballs go into ../phdball_dir and are labelled phd.ball.1 phd.ball.2 ..." << endl;
         exit( -1 );
      }
      



// main.cpp_part7


      else if ( soLowerCaseArg == "-ace" ) {
         bAceFileOnCommandLine = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -ace must be followed by a space and then the ace filename" << endl;
            exit( -1 );
         }
         filAceFileToOpen = argv[n];
      }
      else if ( soLowerCaseArg == "-socket" ) {
         bCreateSocketToControlConsed = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -socket must be followed by a space and then a number (the local port number)" << endl;
            exit( -1 );
         }
         soSocketToControlConsedLocalPortNumber = argv[n];
      }
      else if ( soLowerCaseArg == "-nophd" ) {
         bNoPhdFiles = true;
      }
      else if ( soLowerCaseArg == "-autofinish" ) {
         bAutomatedFinishProgram = true;
      }
      else if ( soLowerCaseArg == "-doexperiments" ) {
         bDoExperiments = true;
      }
      else if ( soLowerCaseArg == "-autopcramplify" ) {
         bAutoPCRAmplify = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -autoPCRAmplify must be followed by a space and then the name of the file of primer regions" << endl;
            exit( -1 );
         }
         filFileOfPrimerRegions = argv[n];
      }
      else if ( soLowerCaseArg == "-justcheckautofinishreads" ) {
         bJustCheckAutoFinishReads = true;
      }
      else if ( soLowerCaseArg == "-id" ) {
         bID = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -id must be followed by a space and then the id" << endl;
            exit( -1 );
         }
         soID = argv[n];
      }
      else if ( soLowerCaseArg == "-contig" ) {
         bContigSpecified = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -contig must be followed by a space and then the contig name" << endl;
            exit( -1 );
         }
         soContig = argv[n];
      }
      else if ( soLowerCaseArg == "-filenamesfile" ) {
         bFileNamesFile = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -filenamesFile must be followed by a space and then the name of the file to contain the filenames" << endl;
            exit( -1 );
         }
         soFilenamesFile = argv[n];
      }
      else if ( soLowerCaseArg == "-fileofphdfiles" ) {
         bFileOfPhdFiles = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -fileOfPhdFiles must be followed by a space and then the name of the file of phd files" << endl;
            exit( -1 );
         }
         filFileOfPhdFiles = argv[n];
      }
      else if ( soLowerCaseArg == "-terminate" ) {
         bTerminateAfterStartup = true;
      }
      else if ( soLowerCaseArg == "-read_only" ) {
         bReadOnly = true;
      }
      else if ( soLowerCaseArg == "-addnewreads" ) {
         bAddNewReads = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -addNewReads must be followed by a space and then the name of the file containing the reads to be added" << endl;
            exit( -1 );
         }
         filFileOfReadsOrPhdsToAdd = argv[n];
      }
      else if ( soLowerCaseArg == "-addreads" ) {
         bAddReads = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -addReads must be followed by a space and then the name of the file containing a list of the cross_match alignment files" << endl;
            exit( -1 );
         }
         filAddNewReadsAlignmentsFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-chem" ) {
         bChem = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -chem must be followed by a space and then the chemistry which can be one of solexa, 454, or Sanger" << endl;
            exit( -1 );
         }
         soChemistry = argv[n];
      }
      else if ( soLowerCaseArg == "-autoedit" ) {
         bAutoEdit = true;
      }
      else if ( ( soLowerCaseArg == "-newacefilename" )  || ( soLowerCaseArg == "-newacefile" )
 ) {
         bNewAceFileName = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -newAceFilename must be followed by a space and then the name of the ace file to be created" << endl;
            exit( -1 );
         }
         filNewAceFile = argv[n];
      }
      else if ( soLowerCaseArg == "-addalignedsequence" ) {
         bAddAlignedSequence = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -addAlignedSequence must be followed by a space and then the name of the fasta file created by alignment2Ace.perl" << endl;
            exit( -1 );
         }
         filAlignmentFastaFile = argv[n];
      }
      else if ( soLowerCaseArg == "-tagsnps" ) {
         bTagSNPs = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -tagSNPs must be followed by a space and then the name of the fof of SNP reads" << endl;
            exit( -1 );
         }
         filFileOfReadsOrPhdsToAddForTagSNPs = argv[n];
      }
      else if ( soLowerCaseArg == "-phdwithwritem" ) {
         bPhdWithWRItem = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phdWithWRItem must be followed by a space and then the name of the phd file containing the WR Item specifying the genomic region of the assembly" << endl;
            exit( -1 );
         }
         filPhdFileWithWRItem = argv[n];
      }
      else if ( soLowerCaseArg == "-autoreport" ) {
         bAutoReport = true;
      }
      else if ( soLowerCaseArg == "-nav" ) {
         bCustomNavigation = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -nav must be followed by a space and then the name of the custom navigation file" << endl;
            exit( -1 );
         }
         filCustomNavigation = argv[n];
      }
      else if ( soLowerCaseArg == "-allowtimestampmismatch" ) {
         bAllowTimestampMismatch = true;
      }
      else if ( soLowerCaseArg == "-singlesignal" ) {
         bPrintSingleSignal = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -singleSignal must be followed by a space and then the unpadded consensus position" << endl;
            exit( -1 );
         }
         soUnpaddedConsPosForSingleSignal = argv[n];
      }
      else if ( soLowerCaseArg == "-maincontigpos" ) {
         bMainContigPos = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -maincontigpos must be followed by a space and then the unpadded consensus position of the main contig" << endl;
            exit( -1 );
         }
         soUnpaddedConsPos = argv[n];
      }
      else if ( soLowerCaseArg == "-solexa2phdball" ) {
         bSolexa2PhdBall = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -solexa2PhdBall must be followed by a space and then the name of a file containing the name of the solexa fastq files." << endl;
            exit( -1 );
         }
         filSolexaFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-phdballfof" ) {
         bNewPhdBallFOF = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phdBallFOF must be followed by a space and then the name of the phdballfof to be created.  This file contains a list of all of the phdballs created." << endl;
            exit( -1 );
         }
         filNewPhdBallFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-selectregions" ) {
         bSelectRegions = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -selectRegions must be followed by a space and then the name of the regions file" << endl;
            exit( -1 );
         }
         filRegionsFile = argv[n];
      }
      else if ( soLowerCaseArg == "-alignments" ) {
         bAlignments = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -alignments must be followed by a space and then the name of an fof of alignments files for -selectRegions" << endl;
            exit( -1 );
         }
         filSelectRegionsAlignmentsFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-phdball2fasta" ) {
         bPhdBall2Fasta = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phdBall2Fasta must be followed by a space and then the name of the phd ball" << endl;
            exit( -1 );
         }
         filPhdBall = argv[n];
      }
      else if ( soLowerCaseArg == "-fasta" ) {
         bFasta = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -fasta must be followed by a space and then the name of the output fasta file" << endl;
            exit( -1 );
         }
         filFasta = argv[n];
      }
      else if ( soLowerCaseArg == "-fastq" ) {
         bFastq = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -fastq must be followed by a space and then the name of the output fastq file" << endl;
            exit( -1 );
         }
         filFastq = argv[n];
      }
      else if ( soLowerCaseArg == "-testreadphdball" ) {
         bTestReadPhdBall = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -testReadPhdBall must be followed by a space and then the phdball to be read for testing purposes" << endl;
            exit( -1 );
         }
         filPhdBallForTestRead = argv[n];
      }
      else if ( soLowerCaseArg == "-removereads" ) {
         bRemoveReads = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -removeReads must be followed by a space and then the file containing the reads to be removed.  Use consed.removeReadsPutIntoOwnContig: true/false to determine whether the removed reads are just put into their own contigs or completely removed" << endl;
            exit( -1 );
         }
         filReadsToBeRemoved = argv[n];
      }
      else if ( soLowerCaseArg == "-removecontigs" ) {
         bRemoveContigs = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -removeContigs must be followed by a space and then the file containing the contigs to be removed.  Use consed.removeReadsPutIntoOwnContig: true/false to determine whether the removed reads are just put into their own contigs or completely removed" << endl;
            exit( -1 );
         }
         filContigsToBeRemoved = argv[n];
      }
      else if ( soLowerCaseArg == "-printdefaultresources" ) {
         bPrintDefaultResources = true;
      }
      else if ( soLowerCaseArg == "-sff2phdball" ) {
         bSff2PhdBall = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -sff2PhdBall must be followed by a space and then full path of the sff file" << endl;
            exit( -1 );
         }
         filSffFile = argv[n];
      }
      else if ( soLowerCaseArg == "-phdball" ) {
         bPhdBall = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phdBall must be followed by a space and then the full path of the phd ball" << endl;
            exit( -1 );
         }
         filNewPhdBall = argv[n];
      }
      else if ( soLowerCaseArg == "-fof" ) {
         bFOF = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -fof must be followed by a space and then the name of a file containing read names" << endl;
            exit( -1 );
         }
         filFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-editconsedrc" ) {
         bEditConsedrc = true;
      }
      else if ( soLowerCaseArg == "-changeconsensus" ) {
         bChangeConsensus = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -changeConsensus must be followed by a space and then the name of the file with lines like this:  Contig21 28-30 x where Contig21 is the contig, 28-30 are the unpadded positions and x is the new base.  To change a pad (let's say at padded position 35, specify this as *35 as in Contig21 *35-*40 c" << endl;
            exit( -1 );
         }
         filChangeConsensus = argv[n];
      }
      else if ( soLowerCaseArg == "-snpgenome" ) {
         bSnpGenome = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -snpGenome must be followed by a space and then the full path of the snp table in ucsc format" << endl;
            exit( -1 );
         }
         filSnps = argv[n];
      }
      else if ( soLowerCaseArg == "-genome" ) {
         bGenome = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -genome is used by -snpGenome.  It must be followed by a space and then a file that has 3 columns for each chromosome:  the name of the chromosome in the snp file, the full path of the corresponding chromosome in fasta format, and the full path of the snp-annotated chromosome to be created." << endl;
            exit( -1 );
         }
         filGenome = argv[n];
      }
      else if ( soLowerCaseArg == "-valid" ) {
         bValid = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -valid is used by -snpGenome.  It must be followed by a space and then a file that lists, one per line, each validation combination for which *no* snps are to be used." << endl;
            exit( -1 );
         }
         filValidation = argv[n];
      }
      else if ( soLowerCaseArg == "-diffchromosomes" ) {
         bDiffChromosomes = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -diffChromosomes must be followed by a space and then the full or relative path of the other directory containing the chromosome files" << endl;
            exit( -1 );
         }
         filOtherDirectory = argv[n];
      }
      else if ( soLowerCaseArg == "-addflowcells" ) {
         bAddFlowcells = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -addFlowcells must be followed by a space and then the full or relative path of file containing flowcell lines" << endl;
            exit( -1 );
         }
         filFlowcellsToAdd = argv[n];
      }
      else if ( soLowerCaseArg == "-controlfile" ) {
         bControlFile = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -controlFile must be followed by a space and then the full or relative path of the control file" << endl;
            exit( -1 );
         }
         filControlFile = argv[n];
      }
      else if ( soLowerCaseArg == "-fixcontigends" ) {
         bFixContigEnds = true;
      }
      else if ( soLowerCaseArg == "-contigendsfof" ) {
         bContigEndsFOF = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -contigEndsFOF must be followed by a space and then the full or relative path of a file which each line having (contig name) (left or right)" << endl;
            exit( -1 );
         }
         filContigEndsFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-geneclassifications" ) {
         bGeneClassifications = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -geneClassifications must be followed by a space and then the full or relative path of the list of genomic locations in the format chr1 345671" << endl;
            exit( -1 );
         }
         filGenomicLocations = argv[n];
      }
      else if ( soLowerCaseArg == "-chromosomesfof" ) {
         bChromosomesFOF = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -chromosomesFOF must be followed by a space and then the full or relative path of a file containing the full or relative paths of the chromosomes in fasta format" << endl;
            exit( -1 );
         }
         filChromosomesFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-knowngene" ) {
         bKnownGene = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -knownGene must be followed by a space and then the full or relative path of a file containing the full or relative paths of the knownGene.txt file" << endl;
            exit( -1 );
         }
         filKnownGene = argv[n];
      }
      else if ( soLowerCaseArg == "-phaster2phdball" ) {
         bPhaster2PhdBall = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phaster2PhdBall must be followed by a space and then the full or relative path of a file containing a list of phaster output files (assumes cref2 and -report_type:2 )" << endl;
            exit( -1 );
         }
         filPhasterFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-phasterlocations" ) {
         bPhasterLocations = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phasterLocations must be followed by a space and then the full or relative path of a file containing a list of locations in the form (full phaster genomic location) (chromosome) (1-based chromosome position)" << endl;
            exit( -1 );
         }
         filPhasterLocations = argv[n];
      }
      else if ( soLowerCaseArg == "-phylofof" ) {
         bPhyloFOF = true;
         ++n;
         if ( n >= nArgc ) {
            cerr << "Fatal Error: -phyloFOF must be followed by a space and then the full or relative path of a file containing the full or relative path of phyloP conservation score files in wig format such as chr11.phyloP44way.wigFix.gz" << endl;
            exit( -1 );
         }
         filPhyloFOF = argv[n];
      }
      else if ( soLowerCaseArg == "-miscprogram" ) {
         bMiscProgram = true;
      }


// main.cpp_part8
     else if ( soLowerCaseArg == "-dumpdefaultresources" ) {
        bPrintDefaultResources = true;
     }
     else if ( soLowerCaseArg == "-printconsedresources" ) {
        bPrintDefaultResources = true;
     }
     else if ( soLowerCaseArg == "-printconsedrcresources" ) {
        bPrintDefaultResources = true;
     }
     else if ( soLowerCaseArg == "-printconsedparameters" ) {
        bPrintDefaultResources = true;
     }
     else if ( soLowerCaseArg == "-printconsedrcparameters" ) {
        bPrintDefaultResources = true;
     }
     else {
        cerr << "Error:  do not recognize argument " << argv[n] << " lowercase: " << soLowerCaseArg << endl;
        cout << soUsage << endl;
        _exit( -1 );
     }
        
   } // for(  n = 0; n < nArgc; ++n ) {


   if ( bAddReads && !bChem ) {
      cerr << "Fatal Error:  if you specify -addReads, you must also specify -chem to give the type of chemistry of reads being added.  At this time, each chemistry of reads must be added one at a time." << endl;
      _exit( -1 );
   }

   if ( bSolexa2PhdBall && !bNewPhdBallFOF ) {
      cerr << "Fatal Error: if you specify -solexa2PhdBall, you must also specify -phdBallFOF (file for this program to write the phdball filenames)" << endl;
      _exit( -1 );
   }

   if ( bSelectRegions && !bAlignments ) {
      cerr << "Fatal Error: if you specify -selectRegions, you must also specify -alignments (alignments file)" << endl;
      _exit( -1 );
   }

   if ( bPhdBall2Fasta && !bFasta && !bFastq ) {
      cerr << "Fatal Error:  if you specify -phdBall2Fasta, you must also specify -fasta (fasta file) or -fastq (fastq file)" << endl;
      _exit( -1 );
   }

   if ( bSff2PhdBall && !bPhdBall ) {
      cerr << "Fatal Error:  if you specify -sff2PhdBall, must also specify -phdBall (phdball full path)" << endl;
      _exit( -1 );
   }

   if ( bSnpGenome && !bGenome ) {
      cerr << "Fatal Error:  if you specify -snpGenome, you must also specify -genome" << endl;
      _exit( -1 );
   }

   if ( bSnpGenome && !bValid ) {
      cerr << "Fatal Error:  if you specify -snpGenome, you must also specify -valid" << endl;
      _exit( -1 );
   }

   if ( bGeneClassifications && ! bChromosomesFOF ) {
      cerr << "Fatal Error:  if you specify -geneClassifications, you must also specify -chromosomesFOF" << endl;
      _exit( -1 );
   }
   
   if ( bGeneClassifications && !bKnownGene ) {
      cerr << "Fatal Error:  if you specify -geneClassifications, you must also specify -knownGene" << endl;
      _exit( -1 );
   }

   if ( bPhaster2PhdBall && !bPhasterLocations ) {
      cerr << "Fatal Error: if you specify -phaster2PhdBall, you must also specify -phasterLocations" << endl;
      _exit( -1 );
   }

   if ( bPhaster2PhdBall && !bNewPhdBallFOF ) {
      cerr << "Fatal Error:  if you specify -phaster2PhdBall, you must also specify -phdBallFOF (file for this program to write the phdball filenames)" << endl;
      _exit( -1 );
   }
      

   

   if ( bNoPhdFiles ) {
      cout << "Not using phd files" << endl;
   }


   if ( bAddFlowcells && !bControlFile ) {
      cerr << "Fatal Error:  if you specify -addFlowCell, you must also specify -controlFile" << endl;
      _exit( -1 );
   }





// main.cpp_part9


   if ( bCreateSocketToControlConsed ) {
       if ( ( nWhatIsRunning != nGraphicalConsedIsRunning )
           ) {
          cerr << "-socket cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-socket must only be used with: " << endl;
          cerr << "   graphical_consed" << endl;
          exit( -1 );
       }
   }
   if ( bDoExperiments ) {
       if ( ( nWhatIsRunning != nAutoFinishIsRunning )
           ) {
          cerr << "-doExperiments cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-doExperiments must only be used with: " << endl;
          cerr << "   -autoFinish" << endl;
          exit( -1 );
       }
   }
   if ( bJustCheckAutoFinishReads ) {
       if ( ( nWhatIsRunning != nAutoFinishIsRunning )
           ) {
          cerr << "-justCheckAutoFinishReads cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-justCheckAutoFinishReads must only be used with: " << endl;
          cerr << "   -autoFinish" << endl;
          exit( -1 );
       }
   }
   if ( bID ) {
       if ( ( nWhatIsRunning != nAutoFinishIsRunning )
           ) {
          cerr << "-id cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-id must only be used with: " << endl;
          cerr << "   -autoFinish" << endl;
          exit( -1 );
       }
   }
   if ( bContigSpecified ) {
       if ( ( nWhatIsRunning != nAutoFinishIsRunning )
           ) {
          cerr << "-contig cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-contig must only be used with: " << endl;
          cerr << "   -autoFinish" << endl;
          exit( -1 );
       }
   }
   if ( bFileNamesFile ) {
       if ( ( nWhatIsRunning != nAutoFinishIsRunning )
           ) {
          cerr << "-fileNamesFile cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-fileNamesFile must only be used with: " << endl;
          cerr << "   -autoFinish" << endl;
          exit( -1 );
       }
   }
   if ( bChem ) {
       if ( ( nWhatIsRunning != nAddReadsIsRunning )
           ) {
          cerr << "-chem cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-chem must only be used with: " << endl;
          cerr << "   -addReads" << endl;
          exit( -1 );
       }
   }
   if ( bNewAceFileName ) {
       if ( ( nWhatIsRunning != nAutoEditIsRunning )
       && ( nWhatIsRunning != nAddAlignedSequenceIsRunning )
       && ( nWhatIsRunning != nTagSNPsIsRunning )
       && ( nWhatIsRunning != nAddReadsIsRunning )
       && ( nWhatIsRunning != nAddNewReadsIsRunning )
       && ( nWhatIsRunning != nRemoveReadsIsRunning )
       && ( nWhatIsRunning != nRemoveContigsIsRunning )
       && ( nWhatIsRunning != nChangeConsensusIsRunning )
           ) {
          cerr << "-newAceFileName cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-newAceFileName must only be used with: " << endl;
          cerr << "   -autoEdit" << endl;
          cerr << "   -addAlignedSequence" << endl;
          cerr << "   -tagSNPs" << endl;
          cerr << "   -addReads" << endl;
          cerr << "   -addNewReads" << endl;
          cerr << "   -removeReads" << endl;
          cerr << "   -removeContigs" << endl;
          cerr << "   -changeConsensus" << endl;
          exit( -1 );
       }
   }
   if ( bPhdWithWRItem ) {
       if ( ( nWhatIsRunning != nAddAlignedSequenceIsRunning )
           ) {
          cerr << "-phdWithWRItem cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-phdWithWRItem must only be used with: " << endl;
          cerr << "   -addAlignedSequence" << endl;
          exit( -1 );
       }
   }
   if ( bCustomNavigation ) {
       if ( ( nWhatIsRunning != nGraphicalConsedIsRunning )
           ) {
          cerr << "-nav cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-nav must only be used with: " << endl;
          cerr << "   graphical_consed" << endl;
          exit( -1 );
       }
   }
   if ( bMainContigPos ) {
       if ( ( nWhatIsRunning != nGraphicalConsedIsRunning )
           ) {
          cerr << "-mainContigPos cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-mainContigPos must only be used with: " << endl;
          cerr << "   graphical_consed" << endl;
          exit( -1 );
       }
   }
   if ( bNewPhdBallFOF ) {
       if ( ( nWhatIsRunning != nSolexa2PhdBallIsRunning )
       && ( nWhatIsRunning != nSff2PhdBallIsRunning )
       && ( nWhatIsRunning != nPhaster2PhdBallIsRunning )
           ) {
          cerr << "-phdBallFOF cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-phdBallFOF must only be used with: " << endl;
          cerr << "   -solexa2PhdBall" << endl;
          cerr << "   -sff2PhdBall" << endl;
          cerr << "   -phaster2PhdBall" << endl;
          exit( -1 );
       }
   }
   if ( bAlignments ) {
       if ( ( nWhatIsRunning != nSelectRegionsIsRunning )
           ) {
          cerr << "-alignments cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-alignments must only be used with: " << endl;
          cerr << "   -selectRegions" << endl;
          exit( -1 );
       }
   }
   if ( bFasta ) {
       if ( ( nWhatIsRunning != nPhdBall2FastaIsRunning )
           ) {
          cerr << "-fasta cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-fasta must only be used with: " << endl;
          cerr << "   -phdBall2Fasta" << endl;
          exit( -1 );
       }
   }
   if ( bFastq ) {
       if ( ( nWhatIsRunning != nPhdBall2FastaIsRunning )
           ) {
          cerr << "-fastq cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-fastq must only be used with: " << endl;
          cerr << "   -phdBall2Fasta" << endl;
          exit( -1 );
       }
   }
   if ( bPhdBall ) {
       if ( ( nWhatIsRunning != nSff2PhdBallIsRunning )
           ) {
          cerr << "-phdBall cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-phdBall must only be used with: " << endl;
          cerr << "   -sff2PhdBall" << endl;
          exit( -1 );
       }
   }
   if ( bFOF ) {
       if ( ( nWhatIsRunning != nSff2PhdBallIsRunning )
           ) {
          cerr << "-fof cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-fof must only be used with: " << endl;
          cerr << "   -sff2PhdBall" << endl;
          exit( -1 );
       }
   }
   if ( bGenome ) {
       if ( ( nWhatIsRunning != nSnpGenomeIsRunning )
           ) {
          cerr << "-genome cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-genome must only be used with: " << endl;
          cerr << "   -snpGenome" << endl;
          exit( -1 );
       }
   }
   if ( bValid ) {
       if ( ( nWhatIsRunning != nSnpGenomeIsRunning )
           ) {
          cerr << "-valid cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-valid must only be used with: " << endl;
          cerr << "   -snpGenome" << endl;
          exit( -1 );
       }
   }
   if ( bControlFile ) {
       if ( ( nWhatIsRunning != nAddFlowcellsIsRunning )
           ) {
          cerr << "-controlFile cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-controlFile must only be used with: " << endl;
          cerr << "   -addFlowcells" << endl;
          exit( -1 );
       }
   }
   if ( bContigEndsFOF ) {
       if ( ( nWhatIsRunning != nFixContigEndsIsRunning )
           ) {
          cerr << "-contigEndsFOF cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-contigEndsFOF must only be used with: " << endl;
          cerr << "   -fixContigEnds" << endl;
          exit( -1 );
       }
   }
   if ( bChromosomesFOF ) {
       if ( ( nWhatIsRunning != nGeneClassificationsIsRunning )
           ) {
          cerr << "-chromosomesFOF cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-chromosomesFOF must only be used with: " << endl;
          cerr << "   -geneClassifications" << endl;
          exit( -1 );
       }
   }
   if ( bKnownGene ) {
       if ( ( nWhatIsRunning != nGeneClassificationsIsRunning )
           ) {
          cerr << "-knownGene cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-knownGene must only be used with: " << endl;
          cerr << "   -geneClassifications" << endl;
          exit( -1 );
       }
   }
   if ( bPhasterLocations ) {
       if ( ( nWhatIsRunning != nPhaster2PhdBallIsRunning )
           ) {
          cerr << "-phasterLocations cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-phasterLocations must only be used with: " << endl;
          cerr << "   -phaster2PhdBall" << endl;
          exit( -1 );
       }
   }
   if ( bPhyloFOF ) {
       if ( ( nWhatIsRunning != nGeneClassificationsIsRunning )
           ) {
          cerr << "-phyloFOF cannot be used with " << aszWhatIsRunning[ nWhatIsRunning ] << endl;
          cerr << "-phyloFOF must only be used with: " << endl;
          cerr << "   -geneClassifications" << endl;
          exit( -1 );
       }
   }



// main.cpp_part10


   if ( bAutomatedFinishProgram && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -autoFinish, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAutoPCRAmplify && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -autoPCRAmplify, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAddNewReads && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -addNewReads, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAddReads && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -addReads, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAutoEdit && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -autoEdit, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bNewAceFileName && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -newAceFileName, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAddAlignedSequence && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -addAlignedSequence, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bTagSNPs && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -tagSNPs, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAutoReport && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -autoReport, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bCustomNavigation && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -nav, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bPrintSingleSignal && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -singleSignal, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bMainContigPos && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -mainContigPos, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bSolexa2PhdBall && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -solexa2PhdBall, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bSelectRegions && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -selectRegions, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAlignments && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -alignments, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bPhdBall2Fasta && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -phdBall2Fasta, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bFasta && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -fasta, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bFastq && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -fastq, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bTestReadPhdBall && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -testReadPhdBall, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bRemoveReads && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -removeReads, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bRemoveContigs && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -removeContigs, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bPrintDefaultResources && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -printDefaultResources, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bSff2PhdBall && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -sff2PhdBall, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bEditConsedrc && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -editConsedrc, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bChangeConsensus && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -changeConsensus, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bSnpGenome && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -snpGenome, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bGenome && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -genome, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bValid && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -valid, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bDiffChromosomes && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -diffChromosomes, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bAddFlowcells && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -addFlowcells, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bControlFile && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -controlFile, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bFixContigEnds && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -fixContigEnds, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bContigEndsFOF && !bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -contigEndsFOF, you must also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bGeneClassifications && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -geneClassifications, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bChromosomesFOF && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -chromosomesFOF, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bKnownGene && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -knownGene, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bPhaster2PhdBall && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -phaster2PhdBall, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bPhasterLocations && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -phasterLocations, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bPhyloFOF && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -phyloFOF, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }
   if ( bMiscProgram && bAceFileOnCommandLine ) {
      cerr << "Error:  If you specify -miscProgram, you must not also specify -ace (ace file)" << endl;
      exit( -1 );
   }


//  main.cpp_part11 ok to edit since not computer-generated


   // get consed resources here
   
   consedResources::getConsedResources( );

   setErrorRateFromQuality();

   // put consed resources into consedParameters here

   new consedParameters( consedResources::pCurrentResources_ );

   pAO = stderr;
   //   printMemory( "memory at startup" );


   pCP->filFileOfPhdFiles_ = filFileOfPhdFiles;
   pCP->bTerminateAfterStartup_ = bTerminateAfterStartup;
   pCP->bReadOnly_ = bReadOnly;
   pCP->soCommandLine_ = soCommandLine;
   pCP->bAllowTimestampMismatch_ = bAllowTimestampMismatch;
   pCP->myTime_ = time( NULL );
   pCP->nWhatIsRunning_ = nWhatIsRunning;
   pCP->filUserWantsToSaveToThisAceFile_ = filNewAceFile;


   // put consed resources into tagTypes here

   saveTagTypes( consedResources::pCurrentResources_ );

   pCP->postProcessingAfterTagTypes();

   // put consed resources into colorDefaults in ctor for GuiApp (below)

   // (remove GuiApp completely from autoFinish )


   try {

      if ( bAutomatedFinishProgram ) {

         autoFinish( filAceFileToOpen, nArgc, argv, bContigSpecified, soContig,
                     soID, bDoExperiments, bJustCheckAutoFinishReads,
                     soFilenamesFile );
         _exit( 0 );
      }
      else if ( bAddNewReads ) {

         addNewReadsAutomated add( filAceFileToOpen, filFileOfReadsOrPhdsToAdd, 
                                   filNewAceFile );

         add.doIt();
         _exit( 0 );
      }
      else if ( bAutoPCRAmplify ) {
      
         autoPCRAmplify* pAutoPCRAmplify = 
            new autoPCRAmplify( filAceFileToOpen, filFileOfPrimerRegions );
         pAutoPCRAmplify->doIt();
         _exit( 0 );
      }
      else if ( bAutoEdit ) {

         autoEdit* pAutoEdit = new autoEdit( filAceFileToOpen,
                                             filNewAceFile );
         pAutoEdit->doIt();
         _exit( 0 );
      }
      else if ( bAddAlignedSequence ) {
         assert( !filAlignmentFastaFile.isNull() );
         if ( filPhdFileWithWRItem.isNull() ) {
            cerr << "Error:  if -addAlignedSequence is specified, -phdWithWRItem must also be specified" << endl;
            _exit( -1 );
         }
      
         addAlignedSequence* pAddAlignedSequence = 
            new addAlignedSequence( filAceFileToOpen,
                                    filNewAceFile,
                                    filAlignmentFastaFile,
                                    filPhdFileWithWRItem );

         pAddAlignedSequence->doIt();
         _exit( 0 );

      }
      else if ( bTagSNPs ) {
      
         tagSNPs* pTagSNPs = new tagSNPs( filAceFileToOpen,
                                          filNewAceFile,
                                          filFileOfReadsOrPhdsToAddForTagSNPs );

         pTagSNPs->doIt();
         _exit( 0 );
      }
      else if ( bAutoReport ) {

         autoReport* pAutoReport = new autoReport( filAceFileToOpen );
         pAutoReport->doIt();
         _exit( 0 );
      }
      else if ( bPrintSingleSignal ) {
      
         printSingleSignal* pPrintSingleSignal = 
            new printSingleSignal( filAceFileToOpen,
                                   soUnpaddedConsPosForSingleSignal );

         pPrintSingleSignal->doIt();

         _exit( 0 );
      }
      else if ( bAddReads ) {

         addNewReadsWithExistingAlignments add( filAceFileToOpen, 
                                                filNewAceFile,
                                                filAddNewReadsAlignmentsFOF,
                                                soChemistry );

         add.doIt();
         _exit( 0 );
      }
      else if ( bRemoveContigs ) {
         removeContigs myRemoveContigs( filAceFileToOpen,
                                        filNewAceFile,
                                        filContigsToBeRemoved );
         myRemoveContigs.doIt();
         _exit( 0 );
      }
      else if ( bRemoveReads ) {
         removeReads myRemoveReads( filAceFileToOpen,
                                    filNewAceFile,
                                    filReadsToBeRemoved );
         myRemoveReads.doIt();
         _exit( 0 );
      }
      else if ( bPrintDefaultResources ) {
         printDefaultResources();
         _exit( 0 );
      }
      else if ( bSolexa2PhdBall ) {
      
         solexa2PhdBall mySolexa2PhdBall( filSolexaFOF, filNewPhdBallFOF );

         mySolexa2PhdBall.doIt();
         _exit( 0 );
      }
      else if ( bSelectRegions ) {
         addNewReads myAddNewReads( filAceFileToOpen,
                                    filRegionsFile,
                                    filSelectRegionsAlignmentsFOF );

         myAddNewReads.doItSelectRegions();
         _exit( 0 );
      }
      else if ( bPhdBall2Fasta ) {
         phdBall2Fasta myPhdBall2Fasta( filPhdBall,
                                        filFasta,
                                        filFastq );

         myPhdBall2Fasta.doIt();
         _exit( 0 );
      }
      else if ( bTestReadPhdBall ) {
         testReadPhdBall testReadPhdBall( filPhdBallForTestRead );
         testReadPhdBall.doIt();
         _exit( 0 );
      } 
      else if ( bSff2PhdBall ) {
         sff2PhdBall mySff2PhdBall( filSffFile, filNewPhdBall, bFOF, filFOF );
         mySff2PhdBall.doIt();
         _exit( 0 );
      }
      else if ( bEditConsedrc ) {
         guiEditResourcesStandalone myGuiEditResourcesStandalone;
         myGuiEditResourcesStandalone.doIt();
         _exit( 0 );
      }
      else if ( bChangeConsensus ) {
         batchChangeConsensus myBatchChangeConsensus(
            filAceFileToOpen,
            filNewAceFile,
            filChangeConsensus );
          
          myBatchChangeConsensus.doIt();
          _exit( 0 );
      }
      else if ( bSnpGenome ) {
         snpGenome mySnpGenome( filSnps, filGenome, filValidation );

         mySnpGenome.doIt();
         _exit( 0 );
      }
      else if ( bDiffChromosomes ) {
         diffChromosomes myDiffChromosome( filOtherDirectory );

         myDiffChromosome.doIt();
         _exit( 0 );
      }
      else if ( bAddFlowcells ) {
         
         nextPhredPipeline myNextPhredPipeline( filControlFile );

         myNextPhredPipeline.addFlowcells( filFlowcellsToAdd );

         _exit( 0 );
      }
      else if ( bFixContigEnds ) {
         fixContigEnds myFixContigEnds( filAceFileToOpen,
                                        filNewAceFile,
                                        filContigEndsFOF );
         myFixContigEnds.doIt();
         _exit( 0 );
      }
      else if ( bGeneClassifications ) {
         geneClassifications myGeneClassifications(
                 filGenomicLocations,
                 filChromosomesFOF,
                 filKnownGene,
                 filPhyloFOF );

         myGeneClassifications.doIt();
         _exit( 0 );
      }
      else if ( bPhaster2PhdBall ) {
         phaster2PhdBall myPhaster2PhdBall( 
                 filPhasterFOF,
                 filPhasterLocations,
                 filNewPhdBallFOF );
         
         myPhaster2PhdBall.doIt();
         _exit( 0 );
      }
      else if ( bMiscProgram ) {
         miscProgram();
         _exit( 0 );
      }
   } // try
   catch (ExceptionBase eb) {
      cerr << "Fatal consed error: " << eb.szGetDesc() << endl;
      cerr.flush();
      _exit( EXIT_FAILURE );
   } 
   
      


   assert( pCP->nWhatIsRunning_ = nGraphicalConsedIsRunning );


   pFILE = stdout;


   // create the GuiApp object which contains and manages
   // the toplevel widget, display and resource info, etc.
   // there is now a global pointer to this sole instance,
   // set in the ctor, accessible as GuiApp::pGetGuiApp()
   GuiApp guiAppGlobalInstance("consed", nArgc, argv);

   // create the ConsEd object, which owns and manages the
   // Assembly data structure(s) as well as the lists of
   // currently existing ContigWin and Teditor objects.
   // there is now a global pointer to this sole instance,
   // set in the ctor, accessible as ConsEd::global()
   ConsEd* pConsed = new ConsEd();


   // I want this after the ConsEd object is created because it uses
   // that object.
   GuiApp::pGetGuiApp()->startBlinking();


   ConsEd::pGetConsEd()->bUsingPhdFiles_ = !bNoPhdFiles;
   //   ConsEd::pGetConsEd()->bSettingQualityValues_ = false;


   // tell the toplevel widget to manage itself
   GuiApp::pGetGuiApp()->makeVisible();

   if ( pCP->bMakeLightBackgroundInAlignedReadsWindowAndTracesWindow_ )
      GuiApp::pGetGuiApp()->changeDefaultToLightBackground();

   consedParameters::pGetConsedParameters()->bCreateSocketToControlConsed_ =
      bCreateSocketToControlConsed;


   if ( bCreateSocketToControlConsed ) {

      int nSocketToControlConsedLocalPortNumber;

      if ( ! bIsNumericMaybeWithWhitespace( 
                                           soSocketToControlConsedLocalPortNumber,
                                           nSocketToControlConsedLocalPortNumber
                                           ) ) {
         cerr << "Fatal Error:  -socket must be followed by a number (the local port number) but instead is followed by " <<  soSocketToControlConsedLocalPortNumber << endl;
         _exit( -1 );
      }


      pCP->nCreateSocketToControlConsedOnThisLocalPort_ =
         nSocketToControlConsedLocalPortNumber;

   }






   if (ConsEd::pGetConsEd()->bUsingPhdFiles_ )
      terminateIfNoPhdDir();



   // I want to read the list of libraries before reading the ace file
   // to make debugging by the user easier
   pCP->pListOfLibraries_ = new listOfLibraries();

   pCP->pListOfLibraries_->aLibraries_.soName_ = 
      "pCP->pListOfLibraries_->aLibraries_ in main.cpp";

   pCP->pListOfLibraries_->parseLibraryFile();

   maybeTerminateIfAnotherReadWriteConsed();

   // consed now takes a command line arg of file to open
   if ( bAceFileOnCommandLine ) {

      ConsEd::pGetConsEd()->openAssemblyFile( filAceFileToOpen );

      // used to pick up basename
      ConsEd::pGetConsEd()->pGetGuiTopWindow()->setAssemblyName( filAceFileToOpen.soGetBasename() );




   
      if ( ! consedParameters::pGetConsedParameters()->bErrorMessageDisplayedAtStartup_ )
         XRaiseWindow( 
                   XtDisplay( GuiApp::pGetGuiApp()->widGetTopLevel() ),
                   XtWindow(  GuiApp::pGetGuiApp()->widGetTopLevel() ) 
                   );

      ConsEd::pGetConsEd()->setAssemblyNameOnAllContigwins( 
                                 filAceFileToOpen.soGetBasename() 
                                                          );
      ConsEd::pGetConsEd()->perhapsApplyEditHistoryFile( filAceFileToOpen );

      perhapsCreateSocketToControlConsed();


      ConsEd::pGetConsEd()->updateContigListOnMainConsedWindow();


      if ( bCustomNavigation ) {
         ConsEd::pGetConsEd()->startUpConsedWithCustomNavigationFile( 
              filCustomNavigation );
      }
      else if ( bMainContigPos ) {
         ConsEd::pGetConsEd()->startUpConsedAtMainContigPos( soUnpaddedConsPos );
      }
   }
   else {
      // popup the file menu for the user to load an
      // assembly into this first contigwin
      ConsEd::pGetConsEd()->askUserForFileToOpen();
   }

   readAndProcessReadPrefixFile();

   // comment out error handler for making core dumps   
//    if ( !bEstablishErrorHandler() )
//       // try once more
//       bEstablishErrorHandler();


   if ( bTerminateAfterStartup )
      _exit( 0 );


   if ( pCP->bAssemblyViewAutomaticallyStartWithConsed_ && 
        ConsEd::pGetAssembly() ) {

      ConsEd::pGetConsEd()->pAssemblyView_ =
         new assemblyView();

      ConsEd::pGetConsEd()->pAssemblyView_->createWindow( 
         ConsEd::pGetAssembly() );
   }


   printTime( "time for consed to start: " );


   // enter the main X application loop, intercepting
   // exceptions and retrying
   while (true) {
      try {
         GuiApp::pGetGuiApp()->mainLoop();
      }
      catch (RWInternalError rwErr) {
         GuiApp::popupErrorMessage(
            "Gordon C++ class toolkit has thrown an exception: %s",
            rwErr.szGetDesc() );
      }
      catch (ExceptionBase eb) {
         if (! eb.bUserNotified()) {
            GuiApp::popupErrorMessage("Error (Consed exception): %s",
                                      eb.szGetDesc());
         }
      }
      catch (...) {
         GuiApp::popupErrorMessage(
            "Error (exception of unknown type)");
      }
   }
}