コード例 #1
0
ファイル: dbwebserver.cpp プロジェクト: phildarnowsky/mongo
        void handleRESTQuery( string ns , string action , map<string,string> & params , int & responseCode , stringstream & out ) {
            Timer t;

            int skip = _getOption( params["skip"] , 0 );
            int num = _getOption( params["limit"] , _getOption( params["count" ] , 1000 ) ); // count is old, limit is new

            int one = 0;
            if ( params["one"].size() > 0 && tolower( params["one"][0] ) == 't' ) {
                num = 1;
                one = 1;
            }

            BSONObjBuilder queryBuilder;

            for ( map<string,string>::iterator i = params.begin(); i != params.end(); i++ ) {
                if ( ! i->first.find( "filter_" ) == 0 )
                    continue;

                const char * field = i->first.substr( 7 ).c_str();
                const char * val = i->second.c_str();

                char * temp;

                // TODO: this is how i guess if something is a number.  pretty lame right now
                double number = strtod( val , &temp );
                if ( temp != val )
                    queryBuilder.append( field , number );
                else
                    queryBuilder.append( field , val );
            }

            BSONObj query = queryBuilder.obj();

            auto_ptr<DBClientCursor> cursor = db.query( ns.c_str() , query, num , skip );

            if ( one ) {
                if ( cursor->more() ) {
                    BSONObj obj = cursor->next();
                    out << obj.jsonString() << "\n";
                }
                else {
                    responseCode = 404;
                }
                return;
            }

            out << "{\n";
            out << "  \"offset\" : " << skip << ",\n";
            out << "  \"rows\": [\n";

            int howMany = 0;
            while ( cursor->more() ) {
                if ( howMany++ )
                    out << " ,\n";
                BSONObj obj = cursor->next();
                out << "    " << obj.jsonString();

            }
            out << "\n  ],\n\n";

            out << "  \"total_rows\" : " << howMany << " ,\n";
            out << "  \"query\" : " << query.jsonString() << " ,\n";
            out << "  \"millis\" : " << t.millis() << "\n";
            out << "}\n";
        }
コード例 #2
0
ファイル: Config.cpp プロジェクト: KlugerLab/Ritornello
/**
 * Parses the command line setting the global parameters of the program
 *
 * @param begin address of the first command line argument
 * @param end address of the last command line argument
 */
int Config::parseCmdLine(int argc, char* argv[]){
	if(_optionExists(argv, argv + argc, "--version")){
		printVersion();
		exit(0);
	}
	if(_optionExists(argv, argv + argc, "--help")){
		printHelp();
		exit(0);
	}

	bamFileName = _getOption(argv, argv + argc, "-f");
	if(bamFileName==NULL){
		 fprintf(stderr, "-f<ChIP.bam> is required.  in.bam is a sorted bam file\n");
		 exit(EXIT_FAILURE);
	}
	outputPrefix = _getOption(argv, argv + argc, "-o");
	if(outputPrefix ==NULL){
		outputPrefix = bamFileName;
	} else {
		fprintf(stderr, "Output prefix set to [%s]\n", outputPrefix);
	}
	/** deprecated
	char * MAX_FRAGMENT_LENGTH_STR = _getOption(argv, argv + argc, "-m");
	if(MAX_FRAGMENT_LENGTH_STR){
		setMaxFragmentLength(atoi(MAX_FRAGMENT_LENGTH_STR));
	}
	*/
	debugFolder = _getOption(argv, argv + argc, "--debug-folder");
	if(debugFolder!=NULL){
		fprintf(stderr, "Debug folder set to [%s]\n", debugFolder);
	}
	filterFile = _getOption(argv, argv + argc, "--filter-file");
	if(filterFile!=NULL){
		fprintf(stderr, "Reading filter from file [%s]\n", filterFile);
	}
	FLDFile = _getOption(argv, argv + argc, "--FLD-file");
	if(FLDFile!=NULL){
		fprintf(stderr, "Reading FLD from file [%s]\n", FLDFile);
	}
	TRAINFile = _getOption(argv, argv + argc, "--TRAIN-file");
	if(TRAINFile!=NULL){
		fprintf(stderr, "Reading training peaks from from file [%s]\n", TRAINFile);
	}
	char* NUM_THREADS_STR = _getOption(argv, argv + argc, "-p");
	if(NUM_THREADS_STR){
		numThreads = atoi(NUM_THREADS_STR);
		fprintf(stderr, "Set number to threads to [%d]\n", numThreads);
	}
	char* LQVAL_SIGNIF_STR = _getOption(argv, argv + argc, "-q");
	if(LQVAL_SIGNIF_STR){
		logQValSignifThreshold = atof(LQVAL_SIGNIF_STR);
		fprintf(stderr, "Setting the log q-Value significance threshold to [%f]\n", logQValSignifThreshold);
	}
	char* SIG_VAL_STR = _getOption(argv, argv + argc, "-s");
	if(SIG_VAL_STR){
		signalValueThreshold = atof(SIG_VAL_STR);
		fprintf(stderr, "Setting the signal value threshold to [%f]\n", signalValueThreshold);
	}
	char* MIN_READ_STR = _getOption(argv, argv + argc, "-n");
	if(MIN_READ_STR){
		minReadThreshold = atof(MIN_READ_STR);
		fprintf(stderr, "Setting the minimum read and matched filter threshold to [%f]\n", minReadThreshold);
	}
	if(_optionExists(argv, argv + argc, "--OCE")){
		modelOpenChromatinEffect=true;
		fprintf(stderr, "Adding open chromatin effect to the model\n");
	}
	if(_optionExists(argv, argv + argc, "--Correct-PCR")){
		correctPCR=true;
		fprintf(stderr, "PCR correction preprocessing on\n");
	}
	if(_optionExists(argv, argv + argc, "--no-artifact-handling")){
		handleArtifacts=false;
		fprintf(stderr, "Turning off artifact handling\n");
	}
	return 0;
}