Ejemplo n.º 1
0
/*
 * Get the file name from the command line arguments.
 * Show the help if required.
 */
bool GetOptions(int argc, char **argv, ConverterOptions &options)
{
	CCmdLine cmdLine;

	// parse argc,argv 
	// no switches were given on the command line, abort
	if (cmdLine.SplitLine(argc, argv) < 1)
	{
		ShowHelp();
		return false;
	}

	// test for the 'help' case
	if (cmdLine.HasSwitch(HELP_ARG))
	{
		ShowHelp();
		return false;
	}

	// get the required argument
	try
	{
		string str;
		str = cmdLine.GetArgument(INPUT_FILE_ARG, 0);
		options.fileName = str;

		str = cmdLine.GetArgument(VERSION_ARG, 0);
		options.version = (CELFileVersionType)(atoi(str.c_str()));
	}
	catch (...)
	{
		// one of the required arguments was missing, abort
		ShowHelp();
		return false;
	}
	return true;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]){
	Fgwas_params p;

    CCmdLine cmdline;
    if (cmdline.SplitLine(argc, argv) < 1){
        printopts();
        exit(1);
    }
    //get the input file
    if (cmdline.HasSwitch("-i")) p.infile = cmdline.GetArgument("-i", 0).c_str();
    else{
    	cerr << "ERROR: missing input file (-i)\n";
        printopts();
        exit(1);
    }
    //get the output file
    if (cmdline.HasSwitch("-o")) p.outstem = cmdline.GetArgument("-o", 0);
    if (cmdline.HasSwitch("-pcond")) printcond = true;
    if (cmdline.HasSwitch("-v")) {
     	p.V.clear();
     	vector<string> strs;
     	string s = cmdline.GetArgument("-v", 0);
     	boost::split(strs, s ,boost::is_any_of(","));
     	for (int i  = 0; i < strs.size(); i++) {
     		p.V.push_back( atof(strs[i].c_str()) );
     	}
     }
    //LD file
    if (cmdline.HasSwitch("-ld")) {
    	p.overlap = true;
    	p.ldfile = cmdline.GetArgument("-ld", 0);
    	if (cmdline.HasSwitch("-nhap")) p.Nhap = atoi(cmdline.GetArgument("-nhap", 0).c_str());
    	else{
    		cerr << "ERROR: inputing LD matrix, -nhap flag\n";
    	   	printopts();
    	   	exit(1);
    	}
    }
    else if (cmdline.HasSwitch("-cor")){
    	//cerr << "WARNING: including correlation, did you mean to include an LD file?\n";
    	//printopts();
    	//exit(1);
    }
    if (cmdline.HasSwitch("-rev")) p.rev = true;
    if (cmdline.HasSwitch("-numbered")) p.numberedseg = true;
    //set K
    if (cmdline.HasSwitch("-k")) p.K = atoi(cmdline.GetArgument("-k", 0).c_str());
    if (cmdline.HasSwitch("-bed")) {
    	p.bedseg = true;
    	p.segment_bedfile = cmdline.GetArgument("-bed", 0);
    }

    if (cmdline.HasSwitch("-noprint")) p.print = false;

    //names of the phenotypes, expecting header like NAME1_Z NAME1_V NAME2_Z NAME2_V
    if (cmdline.HasSwitch("-phenos")){
     	p.pairwise = true;
     	p.pheno1 = cmdline.GetArgument("-phenos", 0);
     	p.pheno2 = cmdline.GetArgument("-phenos", 1);
     }
    else{
    	cerr << "ERROR: missing phenotypes (-pheno)\n";
        printopts();
        exit(1);
    }
    /*
    if (cmdline.HasSwitch("-w")){
    	vector<string> strs;
    	string s = cmdline.GetArgument("-w", 0);
    	boost::split(strs, s ,boost::is_any_of("+"));
    	for (int i  = 0; i < strs.size(); i++) {
    		p.wannot.push_back( strs[i] );
    	}
    }
    if (cmdline.HasSwitch("-dists")){
     	vector<string> strs;
     	string s = cmdline.GetArgument("-dists", 0);
     	boost::split(strs, s ,boost::is_any_of("+"));
     	for (int i  = 0; i < strs.size(); i++) {
     		vector<string> strs2;
     		boost::split(strs2, strs[i], boost::is_any_of(":"));
     		p.dannot.push_back( strs2[0] );
     		p.distmodels.push_back(strs2[1]);
     	}
     }
    if (cmdline.HasSwitch("-drop")){
    	p.dropchr = true;
    	string s = cmdline.GetArgument("-drop", 0);
    	p.chrtodrop = s;
    }


    if (cmdline.HasSwitch("-dens")) {
    	p.segannot.push_back(cmdline.GetArgument("-dens", 0));
    	p.loquant = atof(cmdline.GetArgument("-dens", 1).c_str());
    	p.hiquant = atof(cmdline.GetArgument("-dens", 2).c_str());
    }
    */
    if (cmdline.HasSwitch("-fine")) p.finemap = true;
    if (cmdline.HasSwitch("-mcmc")) p.MCMC = true;
    if (cmdline.HasSwitch("-seed")){
    	p.seed = atoi(cmdline.GetArgument("-seed", 0).c_str());
    }
    else p.seed = unsigned( time(NULL));
    if (cmdline.HasSwitch("-nburn")){
     	p.burnin = atoi(cmdline.GetArgument("-nburn", 0).c_str());
    }
    if (cmdline.HasSwitch("-nsamp")){
      	p.nsamp = atoi(cmdline.GetArgument("-nsamp", 0).c_str());
     }
    if (cmdline.HasSwitch("-jumpsd")){
      	p.MCMC_gauss_SD = atof(cmdline.GetArgument("-jumpsd", 0).c_str());
     }
    if (cmdline.HasSwitch("-cor")){
        	p.cor = atof(cmdline.GetArgument("-cor", 0).c_str());
        	//p.overlap = true;
       }
    if (cmdline.HasSwitch("-prior")){
    	if (cmdline.GetArgumentCount("-prior") != 5) {
    		cerr << "ERROR: -prior needs 5 entries, "<< cmdline.GetArgumentCount("-prior") << " given\n";
    		exit(1);
    	}

       	p.alpha_prior[0] = atof(cmdline.GetArgument("-prior", 0).c_str());
       	p.alpha_prior[1] = atof(cmdline.GetArgument("-prior", 1).c_str());
       	p.alpha_prior[2] = atof(cmdline.GetArgument("-prior", 2).c_str());
       	p.alpha_prior[3] = atof(cmdline.GetArgument("-prior", 3).c_str());
       	p.alpha_prior[4] = atof(cmdline.GetArgument("-prior", 4).c_str());
      }


      //random number generator
    const gsl_rng_type * T;
    gsl_rng * r;
    gsl_rng_env_setup();
    T = gsl_rng_ranlxs2;
    r = gsl_rng_alloc(T);
    int seed = (int) time(0);
    gsl_rng_set(r, p.seed);


    SNPs_PW s(&p);
    if (printcond) s.get_all_condZ();
    s.GSL_optim();
    vector<double> ml;
    for (int i = 0; i < 5; i++)ml.push_back(s.pi[i]);

    vector<pair<pair<int, int>, pair<double, double> > > cis = s.get_cis();
	string outML = p.outstem+".MLE";
	ofstream outr(outML.c_str());
	int sti = 0;
	if (p.finemap) sti = 1;
	for (int i = sti; i < 5; i++){
		outr << "pi_"<< i <<" "<< cis.at(i-sti).second.first << " "<< ml[i]<< " "<< cis.at(i-sti).second.second << "\n";
	}
	outr.close();
    if (p.MCMC) s.MCMC(r);
	if (p.print) s.print(p.outstem+".bfs.gz", p.outstem+".segbfs.gz");
	//if (p.finemap) return 0;


	return 0;
}
Ejemplo n.º 3
0
/*! The main entrance to the program. */
int main(int argc, char * argv[])
{
	try
	{
		// Parse the command line arguments.
		CCmdLine cmdLine;
		if (cmdLine.SplitLine(argc, argv) < 1)
		{
			show_help();
			exit(-1);
		}

		string execId = cmdLine.GetArgument("-execid", 0);
		string celFile = cmdLine.GetSafeArgument("-cel", 0, "");
		string inFile = cmdLine.GetArgument("-in", 0);
		string outFile = cmdLine.GetArgument("-out", 0);
		string arrayType = cmdLine.GetArgument("-arrayType", 0);
		string algName = cmdLine.GetArgument("-algName", 0);
		string algVersion = cmdLine.GetArgument("-algVersion", 0);
		string programName = cmdLine.GetArgument("-programName", 0);
		string programVersion = cmdLine.GetArgument("-programVersion", 0);
		string programCompany = cmdLine.GetArgument("-programCompany", 0);

		vector<string> paramNames;
		int n = cmdLine.GetArgumentCount("-paramNames");
		for (int i=0; i<n; i++)
			paramNames.push_back(cmdLine.GetArgument("-paramNames", i));

		vector<string> paramValues;
		n = cmdLine.GetArgumentCount("-paramValues");
		for (int i=0; i<n; i++)
			paramValues.push_back(cmdLine.GetArgument("-paramValues", i));

		vector<string> sumNames;
		n = cmdLine.GetArgumentCount("-sumNames");
		for (int i=0; i<n; i++)
			sumNames.push_back(cmdLine.GetArgument("-sumNames", i));

		vector<string> sumValues;
		n = cmdLine.GetArgumentCount("-sumValues");
		for (int i=0; i<n; i++)
			sumValues.push_back(cmdLine.GetArgument("-sumValues", i));

		// Read the TSV input file
		list<string> names;
		list<float> quantifications;
		ReadData(inFile, names, quantifications);

		// Create the CHP file.
		CreateFileWithHeader(execId, celFile, outFile, names, algName, algVersion, arrayType,
			programName, programVersion, programCompany, paramNames, paramValues, sumNames, sumValues);
		UpdateQuantifications(outFile, quantifications);
	}
	catch (string s)
	{
		cout << s << endl;
		show_help();
	}
	catch (int e)
	{
		cout << "Invalid argument" << endl;
		show_help();
	}
	catch (...)
	{
		cout << "Unknown error" << endl;
		show_help();
	}
	return 0;
}
Ejemplo n.º 4
0
int main( int argc, char** argv )
{

#ifdef USE_CVCAM
	bool cvcam=true;
#else 
	bool cvcam=false;
#endif

	
	if (cmdLine.SplitLine(argc, argv) < 1)
	{
      // no switches were given on the command line, abort
      //ShowHelp();
      //exit(-1);
	}

	std::string infile="../../../stip_online/video/walk-complex.avi";
	std::string tmp;
	int cam=-1;
	try
	{
		if( cmdLine.HasSwitch("-h") || 
			cmdLine.HasSwitch("-help") ||
			cmdLine.HasSwitch("--help"))
		{
			ShowHelp();
			exit(0);
		}

		if( cmdLine.HasSwitch("-f") && cmdLine.HasSwitch("-cam") )
		{
			std::cout<<"You can't specify both file and camera as input!"<<std::endl;
			ShowHelp();
			exit(-1);
		}

	

		if( !(cmdLine.HasSwitch("-f") || cmdLine.HasSwitch("-cam") ))
		{
			std::cout<<"no input..."<<std::endl;
			ShowHelp();
			exit(-1);
		}

		//*** input/output options
		if(cmdLine.GetArgumentCount("-f")>0) 
			infile = cmdLine.GetArgument("-f", 0);
		if(cmdLine.GetArgumentCount("-o")>0) 
			outfile = cmdLine.GetArgument("-o", 0);
	
		if(cmdLine.HasSwitch("-cam"))
			if(cmdLine.GetArgumentCount("-cam")>0)
				cam =  atoi(cmdLine.GetArgument("-cam", 0).c_str());
			else
				cam = -1;

		if(cmdLine.GetArgumentCount("-res")>0) resid =  atoi(cmdLine.GetArgument( "-res", 0 ).c_str());
		if(resid<0 || resid>4) resid=1;

		if(cmdLine.GetArgumentCount("-vis")>0) show = cmdLine.GetArgument("-vis", 0)=="yes"?true:false;
		
		//*** descriptor options
		if(cmdLine.GetArgumentCount("-dscr")>0) mshb.descriptortype = cmdLine.GetArgument("-dscr", 0);
		if(cmdLine.GetArgumentCount("-szf")>0) mshb.patchsizefactor = atof(cmdLine.GetArgument("-szf", 0).c_str());

		//*** detection options
		if(cmdLine.GetArgumentCount("-nplev")>0) mshb.nxplev=atoi(cmdLine.GetArgument("-nplev", 0).c_str());
		if(cmdLine.GetArgumentCount("-plev0")>0) mshb.initpyrlevel=atoi(cmdLine.GetArgument("-plev0", 0).c_str());
		//if(cmdLine.GetArgumentCount("-sigma")>0) hb.sig2 =  atof(cmdLine.GetArgument( "-sigma", 0 ).c_str());
		//if(cmdLine.GetArgumentCount("-tau")>0) hb.tau2 =  atof(cmdLine.GetArgument( "-tau", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-kparam")>0) mshb.kparam =  atof(cmdLine.GetArgument( "-kparam", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-thresh")>0) mshb.SignificantPointThresh =  atof(cmdLine.GetArgument( "-thresh", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-border")>0) mshb.Border =  atoi(cmdLine.GetArgument( "-border", 0 ).c_str());

		//*** video capture options
		mshb.framemax = 100000000;
		if(cmdLine.GetArgumentCount("-framemax")>0) mshb.framemax =  atoi(cmdLine.GetArgument( "-framemax", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-ff")>0) frame_begin =  atoi(cmdLine.GetArgument( "-ff", 0 ).c_str());
		if(cmdLine.GetArgumentCount("-lf")>0) frame_end =  atoi(cmdLine.GetArgument( "-lf", 0 ).c_str());
		
		
	}
	catch (...)
	{
		ShowHelp();
		exit(-1);
	}


	if(infile=="")  //prb:both can handle cam and file
	{
		if(!InitCVCAM(cam))
			return -2;
		// initialize source name string
        sourcename="CameraStream";
	} else {
		cvcam=false;
		if(!InitCapture(infile.c_str()))
			return -2;	
		// initialize source name string
        sourcename=infile;
		std::cout<<"Options summary: "<<std::endl;
		std::cout<<"  video input:     "<<sourcename<<std::endl;
		std::cout<<"  frame interval:  "<<frame_begin<<"-"<<frame_end<<std::endl;
		std::cout<<"  output file:     "<<outfile<<std::endl;
		std::cout<<"  #pyr.levels:     "<<mshb.nxplev<<std::endl;
		std::cout<<"  init.pyr.level:  "<<mshb.initpyrlevel<<std::endl;
		std::cout<<"  patch size fct.: "<<mshb.patchsizefactor<<std::endl;
		std::cout<<"  descriptor type: "<<mshb.descriptortype<<std::endl;
	}

		
        
	if(show)
	{
		//cvNamedWindow( win1,  CV_WINDOW_AUTOSIZE  );
		cvNamedWindow( win2, 0 );
	}


	//cvNamedWindow("Original");

	if(capture)
	{
    int fn=0;
    for(;;)
    {
        if (fn>=mshb.framemax) break;
        if (fn>=frame_end-frame_begin) break;

        fn++;
		frame = cvQueryFrame( capture );
			
        if( !frame )
            break;

		//CVUtil::DrawCircleFeature(frame,cvPoint(10,10),4.0);
		//CapProperties(capture);		
		//cvShowImage("Original",frame);

		dostuff(frame);
		if(show)
		{
			dovisstuff();
			//cvWaitKey();
			cvWaitKey(10);
			//if(cvWaitKey(10) >= 0 )
			//    break;
		}  
    }
	}
	std::cout<<"-> detected "<<TotalIPs<<" points"<<std::endl;

#ifdef USE_CVCAM
	if(cvcam)
	{
		cvWaitKey(0);
		cvcamExit();
	}
#endif
	
	if(capture)
		cvReleaseCapture( &capture );
	

	if(show)
	{
		cvDestroyWindow(win1);
	}

	if(gray) cvReleaseImage(&gray);
	if(vis)  cvReleaseImage(&vis);
	if(vis2)	cvReleaseImage(&vis2);
	if(vis3)	cvReleaseImage(&vis3);
	if(camimg) cvReleaseImage(&camimg);
    return 0;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[]){
	CCmdLine cmdLine;
	
	cmdLine.SplitLine(argc, argv);

	if ( !(cmdLine.HasSwitch("-i") && cmdLine.HasSwitch("-o") && (cmdLine.HasSwitch("-pos") || cmdLine.HasSwitch("-f") || cmdLine.HasSwitch("-pbOnly"))) ){
		fprintf(stderr, "usage: %s -i <image> -o <output-directory> < -pos <x> <y> | -f <fixation-points-file> > [ -pb <probabilistic-boundary-prefix ] [ -flow <optical-flow-file> ] [ -sobel ]\n",argv[0]);
		fprintf(stderr, "OR \t %s -pbOnly -i <image> -o <output-probabilistic-boundary-prefix>\n",argv[0]);
		exit(1);
	}
	class segLayer frame1;
	char tmp[80];
	strcpy (tmp, cmdLine.GetArgument("-i", 0).c_str());

	int64 tic1,tic2,tic3,tic4;
	double ticFrequency = cvGetTickFrequency()*1000000;
	tic1=cvGetTickCount();

	IplImage *im=cvLoadImage(tmp), *im2;
	#ifdef CUDA_SUPPORT
	int maxWidth=640;
	#else
	int maxWidth=640;
	#endif
	bool resized=false;
	float scale=1;
	if(cvGetSize(im).width>maxWidth){
		scale=maxWidth/(double)(cvGetSize(im).width);
		printf("Image too big, resizing it for the segmentation...\n");
	    	int newHeight=(int)(cvGetSize(im).height*scale);
	    	im2=cvCreateImage( cvSize(maxWidth,newHeight), IPL_DEPTH_8U, 3 );
	    	cvResize(im,im2);
		resized=true;
	}else{
		im2=im;
	}
  	frame1.setImage(im2);

	if (cmdLine.HasSwitch("-pb")){
		strcpy (tmp, cmdLine.GetArgument("-pb", 0).c_str());
		frame1.readPbBoundary(tmp);
	}else{

		// Edge detection!
		if (cmdLine.HasSwitch("-sobel"))
	  		frame1.edgeSobel();
		else{
	#ifdef CUDA_SUPPORT
			if(!get_lock()){
				fprintf(stderr,"Impossible to get the lock...\n");
				exit(1);
			}
			frame1.edgeGPU(false);
			if(!release_lock()){
				fprintf(stderr,"Impossible to release the lock...\n");
				exit(1);
			}
	#else
			frame1.edgeCGTG();
	#endif
		}

		tic2=cvGetTickCount();

		if (cmdLine.HasSwitch("-flow")){
			strcpy (tmp, cmdLine.GetArgument("-flow", 0).c_str());
			IplImage *flow=cvLoadImage(tmp);
			IplImage *flow32 = cvCreateImage(cvGetSize(flow), IPL_DEPTH_32F,3);
			IplImage *flowU = cvCreateImage(cvGetSize(flow), IPL_DEPTH_32F,1);
	  		IplImage *flowV = cvCreateImage(cvGetSize(flow), IPL_DEPTH_32F,1);
			cvConvertScale(flow, flow32, 40/255.,-20);
			cvSplit(flow32,flowU,NULL,NULL,NULL);
			cvSplit(flow32,NULL,flowV,NULL,NULL);
			frame1.setU(flowU);
			frame1.setV(flowV);
			cvReleaseImage(&flow);
			cvReleaseImage(&flow32);
		}


		frame1.generatePbBoundary();
	}
	
	if (cmdLine.HasSwitch("-pbOnly")){
		strcpy (tmp, cmdLine.GetArgument("-o", 0).c_str());
		frame1.savePbBoundary(tmp);
	}else{
		frame1.allocateMemForContours();// Don't forget to allocate memory to store the region contours.
		//select fixation point!
		if(cmdLine.HasSwitch("-pos")){
			float x,y;
			sscanf(cmdLine.GetArgument("-pos", 0).c_str(),"%f",&x);
			sscanf(cmdLine.GetArgument("-pos", 1).c_str(),"%f",&y);
			frame1.assignFixPt((int)(x*scale), (int)(y*scale));
		}else{
			strcpy (tmp, cmdLine.GetArgument("-f", 0).c_str());
			frame1.readFixPts(tmp,scale);
		}
		//segment
		frame1.segmentAllFixs();		
		
		tic3=cvGetTickCount();

		//display!
		//frame1.displayCurrSegs(-1);
		strcpy (tmp, cmdLine.GetArgument("-o", 0).c_str());
		//sprintf(tmp,"%s/",tmp);
		if(resized)
			frame1.saveResizedRegions(tmp,cvGetSize(im).width,cvGetSize(im).height);
		else
			frame1.saveRegions(tmp);
		//release memory!
		frame1.deallocateMemForContours();
	}

	tic4=cvGetTickCount();
	printf("\n\nTotal time = %f\n",(tic4-tic1)/ticFrequency);
	if(!cmdLine.HasSwitch("-pb"))
		printf("\t edges detection = %f\n",(tic2-tic1)/ticFrequency);
	if(!cmdLine.HasSwitch("-pbOnly"))
		printf("\t segmentation = %f\n",(tic3-tic2)/ticFrequency);
  	return 0;
	
}
Ejemplo n.º 6
0
/*! The main entrance to the program. */
int main(int argc, char * argv[])
{
	try
	{
		// Parse the command line arguments.
		CCmdLine cmdLine;
		if (cmdLine.SplitLine(argc, argv) < 1)
		{
			show_help();
			exit(-1);
		}

		string execId = cmdLine.GetArgument("-execid", 0);
		string celFile = cmdLine.GetSafeArgument("-cel", 0, "");
		string inFile = cmdLine.GetArgument("-in", 0);
		string outFile = cmdLine.GetArgument("-out", 0);
		string arrayType = cmdLine.GetArgument("-arrayType", 0);
		string algName = cmdLine.GetArgument("-algName", 0);
		string algVersion = cmdLine.GetArgument("-algVersion", 0);
		string programName = cmdLine.GetArgument("-programName", 0);
		string programVersion = cmdLine.GetArgument("-programVersion", 0);
		string programCompany = cmdLine.GetArgument("-programCompany", 0);

		vector<string> colNames;
		int n = cmdLine.GetArgumentCount("-colNames");
		for (int i=0; i<n; i++)
			colNames.push_back(cmdLine.GetArgument("-colNames", i));

		vector<string> colTypes;
		n = cmdLine.GetArgumentCount("-colTypes");
		for (int i=0; i<n; i++)
			colTypes.push_back(cmdLine.GetArgument("-colTypes", i));

		vector<string> paramNames;
		n = cmdLine.GetArgumentCount("-paramNames");
		for (int i=0; i<n; i++)
			paramNames.push_back(cmdLine.GetArgument("-paramNames", i));

		vector<string> paramValues;
		n = cmdLine.GetArgumentCount("-paramValues");
		for (int i=0; i<n; i++)
			paramValues.push_back(cmdLine.GetArgument("-paramValues", i));

		vector<string> sumNames;
		n = cmdLine.GetArgumentCount("-sumNames");
		for (int i=0; i<n; i++)
			sumNames.push_back(cmdLine.GetArgument("-sumNames", i));

		vector<string> sumValues;
		n = cmdLine.GetArgumentCount("-sumValues");
		for (int i=0; i<n; i++)
			sumValues.push_back(cmdLine.GetArgument("-sumValues", i));

		vector<string> extraNames;
		n = cmdLine.GetArgumentCount("-extraNames");
		for (int i=0; i<n; i++)
			extraNames.push_back(cmdLine.GetArgument("-extraNames", i));

		vector<string> extraValues;
		n = cmdLine.GetArgumentCount("-extraValues");
		for (int i=0; i<n; i++)
			extraValues.push_back(cmdLine.GetArgument("-extraValues", i));

		// Read the TSV input file
		int maxProbeSetNameLength = 0;

		// data collection is no longer used, so we have ReadData return the row count so that we can pass it into
		// CreateFileWithHeader call
		unsigned long rowCount = ReadData(inFile, maxProbeSetNameLength);

		// Create the CHP file.
		// Creates the header
		CreateFileWithHeader(execId, celFile, outFile, colNames, colTypes, rowCount, maxProbeSetNameLength,
			algName, algVersion, arrayType, programName, programVersion, programCompany, paramNames, paramValues,
			sumNames, sumValues, extraNames, extraValues);

		// add the body (data)
		AddFileBody(inFile,outFile, maxProbeSetNameLength, colTypes);
	}
	catch (string s)
	{
		cout << s << endl;
		show_help();
	}
	catch (int e)
	{
		cout << "Invalid argument" << endl;
		show_help();
	}
	catch (...)
	{
		cout << "Unknown error" << endl;
		show_help();
	}
	return 0;
}
Ejemplo n.º 7
0
int main(int argc, char* argv[])
{
        // Read in parameters from command line.
        CCmdLine cmdLine;

        if(cmdLine.SplitLine(argc, argv) < 3)
        {
                cerr << "Usage: ./gittar -m consensus_motif -e log_ratio_file -s promoter_sequence" << endl;
		cerr << "Additional parameters:" << endl;
		cerr << "[-mis] mismatches to consensus motif(Default=1)" << endl;
		cerr << "[-a] annotation file" << endl;
		cerr << "[-o] output(gene_and_other_info PSFM)" << endl;
		cerr << "[-v] verbose mode" << endl;
		cerr << "[-h] hyperprio parameters(hyper_samples=50 mu=2.0 sigma^2=1.0 flanking_length=7" << endl;
		cerr << "[-n] DO NOT use prio information(overide hyperprio parameters)" << endl;
		cerr << "[-g] Gibbs sampler parameters(starting_point=10 burn-in=100 window=100)" << endl;
		cerr << "[-misc] Miscellaneous parameters(stds_of_intial_target=4 skip_core_region=0 random_background=0 threshold_for_target=0.5 stds_enfore=1)" << endl;

                return 1;
        }

        string m, e, s;
        try
        {
                m = cmdLine.GetArgument("-m", 0);
                e = cmdLine.GetArgument("-e", 0);
                s = cmdLine.GetArgument("-s", 0);
        }
        catch(int)
        {
                cerr << "Wrong arguments!" << endl;
                return 1;
        }
	string mis = cmdLine.GetSafeArgument("-mis", 0, "1");	// mismatches.
	unsigned misallow = atoi(mis.data());
	string a = cmdLine.GetSafeArgument("-a", 0, "");	// gene annotation file.
	string o1 = cmdLine.GetSafeArgument("-o", 0, "");	// output gene and other information.
	string o2 = cmdLine.GetSafeArgument("-o", 1, "");	// output PSFM.
	
	// Hyper-prio parameters.
	HypePrio hypePrio;
	string v = cmdLine.GetSafeArgument("-h", 0, "50");
	hypePrio.V = atoi(v.data());
	string mu = cmdLine.GetSafeArgument("-h", 1, "2.0");
	hypePrio.MU = atof(mu.data());
	string sigma2 = cmdLine.GetSafeArgument("-h", 2, "1.0");
	hypePrio.SIGMA_2 = atof(sigma2.data());
	string flanking = cmdLine.GetSafeArgument("-h", 3, "7");
	hypePrio.FLANKING = atoi(flanking.data());

	// DO NOT use prior information? 
	if(cmdLine.HasSwitch("-n"))
		hypePrio.V = 1;

	// Gibbs-sampler parameters.
	string sta_pnt = cmdLine.GetSafeArgument("-g", 0, "10");
	STA_PNT = atoi(sta_pnt.data());
	string burn_in = cmdLine.GetSafeArgument("-g", 1, "100");
	BURN_IN = atoi(burn_in.data());
	string window = cmdLine.GetSafeArgument("-g", 2, "100");
	WINDOW = atoi(window.data());
 
	// Miscellaneous parameters.
	string iniv = cmdLine.GetSafeArgument("-misc", 0, "4");
	INIV = atoi(iniv.data());
	string skipcore	= cmdLine.GetSafeArgument("-misc", 1, "0");
	SKIPCORE = atoi(skipcore.data());
	string randbg = cmdLine.GetSafeArgument("-misc", 2, "0");
	RANDBG = atoi(randbg.data());
	VERBOSE = cmdLine.HasSwitch("-v");	// verbose mode switch.


	// Load data into memory.
	string motifSeq; // string of motif sequence.
	Expr expr; // hash table of expression values.
	Seq seq; // hash table of sequences.
	GeneAnno geneAnno; // hash table of gene annotation info.

	if(VERBOSE)
		cout << "Loading...motif...expression...sequence..." << endl;
	if(load_data(m, e, s, a, motifSeq, expr, seq, geneAnno)) // load data.
	{
		cerr << "Error occurs during data loading!" << endl;
		return 1;
	}
	if(VERBOSE)
		cout << "Data load complete!" << endl;

	// Normalize expression levels.
	double bkm = mean(expr);
	double bkstd = stnd(expr, bkm);
	if(VERBOSE)
		cout << "All gene mean: " << bkm << ", standard deviation: " << bkstd << endl;

	// Find all genes containing the motif with mismatch.
	VGene vGene;
	motifgene(motifSeq, hypePrio.FLANKING, expr, seq, misallow, vGene);
	if(VERBOSE)
		cout << "Total genes identified: " << vGene.size() << endl;
		
	// Calculate pseudo-count for DNA bases among all sequences.
	double dnaPor[4];
	sudocnt(seq, dnaPor);
	if(VERBOSE)
	{
		cout << "DNA bases portion in all sequences." << endl;
		cout << "A: " << dnaPor[0] << endl;
		cout << "C: " << dnaPor[1] << endl;
		cout << "G: " << dnaPor[2] << endl;
		cout << "T: " << dnaPor[3] << endl;
	}
				
	// Gibbs sampler starts from here...
	double tPSFM[4][40], nPSFM[4][40]; // target and non-target PSFM.
	double mTarget, s2Target;
	SST eLen = motifSeq.length() + 2*hypePrio.FLANKING;
	setzero(tPSFM, 4, (unsigned)eLen);
	setzero(nPSFM, 4, (unsigned)eLen);
	mTarget = s2Target = 0.0;
	for(unsigned i = 0; i < STA_PNT; i++)
	{
		// Generate candidate genes' initial labels.
		genlbl(vGene, bkm, bkstd);

		// Use Gibbs Sampler to calculate the estimated labels.
		if(VERBOSE)
			cout << "Gibbs sampler starting..." << endl;
		double mTarget_, s2Target_;
		double tPSFM_[4][40], nPSFM_[4][40];
		/*	
			Here go the parameters information: 
			vGene: Information about all genes that contain motif.
			dnaPor: DNA pseudo-count.
			seq: Promoter sequences for all genes.
			mVal: background expression mean.
			sVal: background expression std.
		*/
		int iter;
		iter = gsamp(vGene, mTarget_, s2Target_, tPSFM_, nPSFM_, misallow, dnaPor, motifSeq, seq, bkm, bkstd, hypePrio);
		if(VERBOSE)
			cout << "Gibbs sampler stops with " << iter << " iterations." << endl;
		mTarget += mTarget_;
		s2Target += s2Target_;
		add2mat(tPSFM, tPSFM, tPSFM_, (unsigned)eLen);
		add2mat(nPSFM, nPSFM, nPSFM_, (unsigned)eLen);
		if(VERBOSE)
		{
			cout << "Target genes in last iteration: " << ntar(vGene) << endl;
			cout << "Non-target genes in last iteration: " << nnon(vGene) << endl;
		}
		sum_iter(i, vGene);
	}
	// Summarize the results from different starting points.
	avg_iter(vGene);
	unsigned nTar = ntar(vGene, true);
	unsigned nNon = nnon(vGene, true);
	mTarget /= STA_PNT;
	s2Target /= STA_PNT;
	normat(tPSFM, (unsigned)eLen, STA_PNT);
	normat(nPSFM, (unsigned)eLen, STA_PNT);
		
	// Write results into files.
	if(VERBOSE)
		cout << "Writing results into files..." << endl;
	time_t time_tag = time(NULL);
	if(o2 == "")
	{
		ostringstream logstream;
		logstream << time_tag << "_" << motifSeq << "_mis" << misallow << ".log";
		o2 = logstream.str();
	}

	// PSFMs and profile ratios.	
	if(write_log(o2, (unsigned)eLen, tPSFM, nPSFM) != 0)
		cerr << "Writing matrices information failed!" << endl;
	else if(VERBOSE)
		cout << "PSFMs and profile ratios write complete!" << endl;

	// Re-calculate binding site according to the averaged PSFM.
	map<string, string> mbindloc;	// A map to store all binding sites of each gene.
	for(unsigned i = 0; i < vGene.size(); i++)
		mbindloc[vGene[i].name] = bindsite(vGene[i], vGene[i].target, seq[vGene[i].name], tPSFM, nPSFM, hypePrio.FLANKING);

	// Write genes information.
	// Sort genes according to their probabilities and expression values.
	sort(vGene.begin(), vGene.end(), cmp);
	if(o1 == "")
	{
		ostringstream infostream;
		infostream << time_tag << "_" << motifSeq << "_mis" << misallow << ".info";
		o1 = infostream.str();
	}
	if(write_info(o1, vGene, geneAnno, mTarget, sqrt(s2Target), bkm, bkstd, 
		(unsigned)seq.size(), nTar, nNon, hypePrio, motifSeq, mbindloc) != 0)
		cerr << "Writing genes information failed!" << endl;
	else if(VERBOSE)
	{
		cout << "Genes information write complete!" << endl;
		cout << "Finished!" << endl;
	}
	
	return 0;

}
Ejemplo n.º 8
0
int
P300ClassifierMain( int argc, char **argv, QApplication& app )
{
  ConfigDialog dialog;

  CCmdLine    cmdLine;
  QString     arg_TrainingDataFiles;
  QString     arg_TestingDataFiles;
  QString     arg_inicfg;
  QStringList arg_TrainingDataFilesList;
  QStringList arg_TestingDataFilesList;
  bool        barg_TrainingDataFiles;
  bool        barg_TestingDataFiles;
  bool        barg_inicfg;

  cmdLine.SplitLine(argc, argv);

  barg_TrainingDataFiles     =cmdLine.HasSwitch("-TrainingDataFiles");
  barg_TestingDataFiles      =cmdLine.HasSwitch("-TestingDataFiles");
  barg_inicfg                =cmdLine.HasSwitch("-inicfg");

  //int co = cmdLine.GetArgumentCount("-TrainingDataFiles");
  if (barg_TrainingDataFiles)
  {
    for (int i=0; i<cmdLine.GetArgumentCount("-TrainingDataFiles"); i++)
    {
        arg_TrainingDataFiles = arg_TrainingDataFiles.fromStdString(cmdLine.GetArgument("-TrainingDataFiles",i));
        arg_TrainingDataFilesList.insert(i, arg_TrainingDataFiles);
    }
  }
  else
  {
      arg_TrainingDataFiles = "";
  }


  if (barg_TestingDataFiles)
  {
   for (int i=0; i<cmdLine.GetArgumentCount("-TestingDataFiles"); i++)
   {
       arg_TestingDataFiles = arg_TestingDataFiles.fromStdString(cmdLine.GetArgument("-TestingDataFiles",i));
       arg_TestingDataFilesList.insert(i, arg_TestingDataFiles);
   }
  }
  else
  {
    arg_TestingDataFiles = "";
  }

  if (barg_inicfg)
  {
    arg_inicfg = arg_inicfg.fromStdString(cmdLine.GetArgument("-inicfg",0));
  }
  else
  {
    arg_inicfg = "";
  }

  QString classifierOutputFile = cmdLine.GetSafeArgument( "-ClassifierOutputFile", 0, "" ).c_str();
  dialog.SetFiles(arg_TrainingDataFilesList, arg_TestingDataFilesList, arg_inicfg, classifierOutputFile);

  return dialog.exec();
}
Ejemplo n.º 9
0
int MainEntry(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
	ULONG_PTR           gdiplusToken;
	GdiplusStartupInput gdiplusStartupInput;
	BOOL bConsoleAttached = FALSE;

	// Set locale
	char *locale = setlocale(LC_ALL, ".936");

	// Startup GDI+
	Status status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	if (status != Ok)
		return FALSE;

	// set options by command line
	CCmdLine cmdline;
	if (cmdline.SplitLine(__argc, __argv) > 0)
	{
		if (cmdline.HasSwitch("-width"))
			g_nScreenWidth = atoi(cmdline.GetArgument("-width", 0).c_str());
		if (cmdline.HasSwitch("-height"))
			g_nScreenHeight = atoi(cmdline.GetArgument("-height", 0).c_str());

		if (cmdline.HasSwitch("-d"))
		{
			if (AttachConsole(ATTACH_PARENT_PROCESS))
			{
				bConsoleAttached = TRUE;
				freopen("CONIN$", "r", stdin);
				freopen("CONOUT$", "w", stdout);
				freopen("CONOUT$", "w", stderr);
			}
		}

		if (cmdline.HasSwitch("-appid"))
		{
			xsStrCpyN(g_szAppId, cmdline.GetArgument("-appid", 0).c_str(), sizeof(g_szAppId));
		}
	}

	xsTcsCpy((xsTChar *)g_szTitle, xsT("XSKit"));
	xsTcsCpy((xsTChar *)g_szWindowClass, xsT("XSKitMainWnd"));

	RegisterWndClass(hInstance);

	if (!InitInstance (hInstance, nCmdShow))
	{
		if (bConsoleAttached)
			FreeConsole();
		return FALSE;
	}

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	xsPalGuiUninit();

	if (bConsoleAttached)
		FreeConsole();
	// Shutdown GDI+
	GdiplusShutdown(gdiplusToken);

	return msg.wParam;
}
int main(int argc, char* argv[])
{
	// Read parameters from console.
	CCmdLine cmdLine;

	if(cmdLine.SplitLine(argc, argv) < 5)
	{
		cerr << "Usage: ./bbnet -s score_file -n node -b bkg -f func_depth -o output" << endl;
		cerr << endl << "Additional parameter:" << endl;
		cerr << "-k\tPenalty parameter(logK, Default = 5.0)" << endl;
		cerr << "-c\tnumber of candidate motifs (Default=50)" << endl;
		cerr << "-d\tpositive negative (for prediction using BN)" << endl;
		cerr << "-l\toutput of all training samples' information." << endl;
		cerr << "-t\ttranslational(transcriptional) start sites.(Default = right end)" << endl;
		cerr << "-rb\tbit-string to determine which rules to include.(Default = 111110)" << endl;
		cerr << "-i\tUse mutual information instead of Bayesian score" << endl;
		cerr << endl << "Contact: \"Li Shen\"<*****@*****.**>" << endl;
		return 1;
	}

	string s, n, b, f, o;
	try
	{
		s = cmdLine.GetArgument("-s", 0);	// score file.
		n = cmdLine.GetArgument("-n", 0);	// node gene list file.
		b = cmdLine.GetArgument("-b", 0);	// bkg gene list file.
		f = cmdLine.GetArgument("-f", 0);	// func depth folder.
		o = cmdLine.GetArgument("-o", 0);	// results output file.
	}
	catch(int)
	{
		cerr << "Wrong arguments!" << endl;
		return 1;
	}

	if(cmdLine.HasSwitch("-i"))
		itag = true;

	//itag = true;
	//string s = "../gbnet/data/Beer/scor_test.list";
	//string n = "../gbnet/data/Beer/node.list";
	//string b = "../gbnet/data/Beer/bkg.list";
	//string f = "../gbnet/data/Beer/func";
	//string k = "0.015";
	//logK = atof(k.data());
	//string o = "../gbnet/data/Beer/bb_res_test2.txt";

	string k;	// Penalty parameter; logK value.
	if(!itag)
		k = cmdLine.GetSafeArgument("-k", 0, "5.0");
	else
		k = cmdLine.GetSafeArgument("-k", 0, "0.015");
	logK = atof(k.data());

	string c = cmdLine.GetSafeArgument("-c", 0, "50");	// number of candidate motifs. default = 50.
	motifcand = atoi(c.data());

	// Use prior counts for some motifs if specified.
	string p = cmdLine.GetSafeArgument("-p", 0, "0");	// prior counts.
	pricnt = atoi(p.data());
	if(pricnt > 0)	// read preferred motifs list from file.
	{
		prior = 1;
		string fPrim = cmdLine.GetSafeArgument("-p", 1, "primot.txt");
		vector<string> primv;
		if(get1stcol(fPrim, primv) < 0)
			return 1;
		for(size_t i = 0; i < primv.size(); i++)
			primo.insert(primv[i]);
	}

	// File names for positive, negative and left-out testing lists.
	string pos = cmdLine.GetSafeArgument("-d", 0, "");	// positive testing cases.
	string neg = cmdLine.GetSafeArgument("-d", 1, "");	// negative testing cases.
	string res = cmdLine.GetSafeArgument("-d", 2, "");	// left-out testing cases.
	vector<string> plst, nlst, rlst;	// positive, negative and left-out lists.
	if(pos != "" && neg != "")
	{
		if(get1stcol(pos, plst) < 0)
			return 1;
		if(get1stcol(neg, nlst) < 0)
			return 1;
	}
	if(res != "")
	{
		if(get1stcol(res, rlst) < 0)
			return 1;
	}

	// File for output of all training samples' information.
	string finfo = cmdLine.GetSafeArgument("-l", 0, "");

	// File to store all genes' translational/transcriptional start sites.
	string ftss = cmdLine.GetSafeArgument("-t", 0, "");
	if(ftss != "")
		loadtss(ftss, mtss);

	// A bit-string to determine which rules to include.
	rb = cmdLine.GetSafeArgument("-rb", 0, "111110");

	string bp = cmdLine.GetSafeArgument("-bp", 0, "");	// Output each gene's probability like in Beer's prediction.
	
	// Load motif Bayesian score file.
	if(loadscor(mscor, s) != 0)
	{
		cerr << "Load motif scores eror!" << endl;
		return 1;
	}
	else
	{
#ifdef VERBOSE
		cout << "Display candidate motifs that are loaded:" << endl;
		dispscor(mscor);
#endif
	}
	vector<MotifScore> oscor = mscor;	// Save an original copy of motif scores.

	// Load gene list.
	vector<Case> tlst, blst, genlst;
	set<string> genset;
	if(loadgene(tlst, blst, n, b) != 0)
	{
		cerr << "Load gene lists error!" << endl;
		return 1;
	}
	else
	{
		genlst.insert(genlst.end(), tlst.begin(), tlst.end());
		genlst.insert(genlst.end(), blst.begin(), blst.end());
#ifdef VERBOSE
		cout << "Load gene list completed!" << endl;
#endif
		// All training and testing gene names are put into genmap.
		for(size_t i = 0; i < genlst.size(); i++)
			genset.insert(genlst[i].name);
		for(size_t i = 0; i < plst.size(); i++)
			genset.insert(plst[i]);
		for(size_t i = 0; i < nlst.size(); i++)
			genset.insert(nlst[i]);
		for(size_t i = 0; i < rlst.size(); i++)
			genset.insert(rlst[i]);
	}

	// Load motif binding information of genes in genmap.
	if(loadbind(allbind, mscor, genset, f) != 0)
	{
		cerr << "Load binding information error!" << endl;
		return 1;
	}
	else
	{
#ifdef VERBOSE
		cout << "Load binding information completed!" << endl;
#endif
	}

	// File for output.
	ofstream hOut(o.data());
	if(!hOut)
	{
		cerr << "Can't open " << o << endl;
		return 1;
	}
	hOut << "Number of genes in category 1: " << tlst.size() << endl;
	hOut << "Number of genes in category 0: " << blst.size() << endl << endl;

#ifdef VERBOSE
	cout << endl << "Running on original data." << endl;
#endif
	vector<Constraint> cons;
	vector<CPTRow> cpt;
	clock_t start = clock();
	double scor = bbnet(cons, cpt, genlst);
	clock_t finish = clock();
	if(outbayes(hOut, scor, cons, cpt, oscor, tlst.size(), blst.size()) != 0)
	{
		cerr << "Output Bayesian network results error!" << endl;
		return 1;
	}
	if(finfo != "")
	{
		if(outgene(finfo, tlst, blst, cons) != 0)
			cerr << "Output training samples' information error!" << endl;
		return 1;
	}
	if(pos != "" && neg != "")
	{
		Pred d = predict(cons, cpt, plst, nlst);
		outpred(hOut, d, n, b, pos, neg);
		if(bp != "")	// output each gene's probability being in this cluster if output file is specified.
		{
			ofstream hbp(bp.data());
			if(!hbp)
			{
				cerr << "Can't open " << bp << endl;
				return 1;
			}
			vector<BPred> trnbp = predict(cons, cpt, genlst, 0);	// probabilities for training genes.
			outpred(hbp, trnbp);
			vector<string> tstlst;	// probabilities for testing genes.
			tstlst.insert(tstlst.end(), plst.begin(), plst.end());	// positive testings.
			tstlst.insert(tstlst.end(), nlst.begin(), nlst.end());	// negative testings.
			vector<BPred> tstbp = predict(cons, cpt, tstlst, 1);
			outpred(hbp, tstbp);
			if(res != "")	// probabilities for left-out genes if the left-out file is specified.
			{
				vector<BPred> lefbp = predict(cons, cpt, rlst, -1);
				outpred(hbp, lefbp);
			}
			hbp.close();
		}
	}
	hOut << endl << "Bayesian network occupied CPU " << (double)(finish-start)/CLOCKS_PER_SEC << " seconds." << endl;
	hOut.close();

	return 0;
}