main.cpp 3.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
// C++ std libs
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <sys/time.h>
#include <sys/types.h>

// C++ Boost
#include <boost/program_options.hpp>

// utils
#include "utils.h"

// Classes
#include "Galacs.h"


using namespace std;
namespace po = boost::program_options;

int main(int argc, char* argv[])
{
    cerr << "Starting Main" << endl;

	int currentThread = 0;
	int nbThread = 1;
	int loggingLevel;
    int window; 
    int step; 

	double ratioThreshold;
	double pvalueThreshold;
    double zscore;
	
	string bamFile;
	string outputFile;
    string outputFilePairs;
    string outputFileSplits;
	string logFile;
    string referenceFile;


	po::options_description desc("Allowed options");
	desc.add_options()
	("help,h", "produce help message")
	("input,i",  po::value<string>(&bamFile), "Input BAM file containing aligned read from sample.")
	("output,o",  po::value<string>(&outputFile), "output result file variants.")
    ("outputPairs,p",  po::value<string>(&outputFilePairs), "output result file containing discordant pairs.")
    ("outputSplits,S",  po::value<string>(&outputFileSplits), "output result file containing split read.")
	("logFile,l",  po::value<string>(&logFile), "Log file output.")
	("reference,r" ,  po::value<string>(&referenceFile) , "Reference Fasta file." )
	("window,w", po::value<int>(&window)->default_value(50), "Depth treshold to call a variant. (optional)")
	("step,s" , po::value<int>(&step)->default_value(0.1) , "Minimum ratio of alt reads to consider a mutation. (optional)" )
	("zscore,z" , po::value<double>(&zscore)->default_value(0.05) , "pvalue threshold from FET to consider a mutation. (optional)" )
	("thread,t", po::value<int>(&nbThread)->default_value(50), "Number of thread to use. (NYI)")
	("loglevel,L", po::value<int>(&loggingLevel)->default_value(1), "Logging level.");


	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);

	// Verif que le nb de thread n'est pas négatif ...
	if( nbThread < 1 )
	{
		nbThread = 1;
		cerr << "You entered a null or negative value for thread number, positionning it to 1. " << endl;
	}


	if( argc <= 1 )
	{
		cerr << "Error while checking program arguments" << endl;
		cerr << desc << "\n";
		return 1;
	}


	// check provided files
	if( bamFile.length( ) > 0 )
	{
		if( !IsFileReadable( bamFile ) )
		{
			cerr << "File provided as input BAM : " << bamFile << " is not accessible : stopping" << endl;
			return -1;
		}
	}
	else
	{
		cerr << "No file provided as input BAM file : stopping" << endl;
		return -1;
	}


	if( referenceFile.length( ) > 0 )
	{
		if( !IsFileReadable( referenceFile ) )
		{
			cerr << "File provided as reference : " << referenceFile << " is not accessible : stopping" << endl;
			return -1;
		}
	}
	else
	{
		cerr << "No file provided as reference file : stopping" << endl;
		return -1;
	}


	Galacs * App = new Galacs(bamFile, referenceFile, outputFile, outputFilePairs, outputFileSplits, window, step, zscore, nbThread, loggingLevel);
  App->mainLoop();


	delete App;
	cerr << "end of main" << endl;
  return 0;
}