Exemplo n.º 1
0
void read_words(const string filename) {
	assert(!open_word_list);

	ifstream fin(filename.c_str());
	assert(fin.is_open());

	_all_words.clear();

	word_list.clear();
	word_list.push_back("");
	assert(word_list.at(NO_WORD) == "");
	word_map.clear();
	word_map[""] = NO_WORD;		// FIXME: Don't use [] operator

	unsigned i;
	string word;
	while(!fin.eof()) {
		fin >> i >> ws >> word >> ws;

		word_list.push_back(word);
		assert(word_list.at(i) == word);
		word_map[word] = i;	// FIXME: Don't use [] operator
		_all_words.push_back(i);

//		if (word == "*content*") _Word_CONTENT = i;
	}
	assert(word_list.size() == word_map.size());

	cerr << "Read " << word_list.size()-1 << " words from '" << filename << "'\n";

	fin.close();
	open_word_list = true;
}
Exemplo n.º 2
0
    //добавить переменную в таблицу символов
    static void add_var(const string& name)
    {
        if (table.find(name)!= table.end()) error("duplicate variable");
        else{
            if (table.size() > SIZEVART) error("too many variables");
            else table[name] = 0.0;
        }

    }
Exemplo n.º 3
0
void InitHatLevData(   // init the global HAT data needed for this pyr level
    const Image& img,  // in
    int          ilev) // in
{
    if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs
    {
        hat_g.Init_(img, PatchWidth(ilev));
#if CACHE
        if (TRACE_CACHE) // show results from previous run
            lprintf("[calls %d hitrate %.2f cachesize %d]\n",
                    ncalls_g, double(nhits_g) / ncalls_g, cache_g.size());
        cache_g.clear();
#endif
    }
}
Exemplo n.º 4
0
    void createPermutation(hash_map<int,int> hm,vector<int> cur,vector<vector<int> >& res){
        if(hm.size()){
    		for(hash_map<int,int>::iterator it=hm.begin();it!=hm.end();it++){
				vector<int> tVec(cur);
				hash_map<int,int> tMap(hm);
				tVec.push_back(it->first);
				if(tMap[it->first]==1)
					tMap.erase(it->first);
				else
					tMap[it->first]--;
				createPermutation(tMap,tVec,res);
			}
		}
		else
			res.push_back(cur);
	}
Exemplo n.º 5
0
void
Dictionary::loadDictionary(const string & f)
{
	wifstream fin(f.c_str());
    fin.imbue(std::locale(""));

    wstring word;
    float freq = 0;

    wcout << L"loading dictionary..." << endl;
	
    fin >> word >> freq;
    while (fin)
    {
        _dict[word] = freq;    
		fin >> word >> freq;
    }
    
    fin.close();
    wcout << L"finished, " 
          << "Totally " << _dict.size() << " words." << endl;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    

   outfile.open("./tree.txt");

    printf("THR = %f\n", THR);
    for (int ini = 0; ini < 9; ini++)
    {
        char temp = '1'+ini;
        AsciiToInt[temp] = ini;
        IntToAscii[ini] = temp;
    }
    for (int ini = 0; ini < 26; ini++)
    {
        char temp = 'a'+ini;
        AsciiToInt[temp] = 9 + ini;
        IntToAscii[9+ini] = temp;
    }
    for (int ini = 0; ini < 26; ini++)
    {
        char temp = 'A'+ini;
        AsciiToInt[temp] = 35 + ini;
        IntToAscii[35+ini] = temp;
    }
    //cout<<AsciiToInt.find('a')->first<<endl;
    //cout<<AsciiToInt.find('a')->second<<endl;
    double total_random_time = 0;
    double random_time , main_time;
    clock_t start_random_time, end_random_time;
    timeval tv, tv1, tvPartition;
    timeval treeover, DSeqover, Camover;
    register int i, j;
    long long subgraphCounterMain;
    generator gen;
      int next_option;
  const char *const short_options = "hi:d:o:r:s:f:";
  const struct option long_options[] = {
        {"help",   0, NULL, 'h'},
        {"input",  1, NULL, 'i'},
        {"Dnodes input",  1, NULL, 'd'},
        {"output", 1, NULL, 'o'},
        {"random", 1, NULL, 'r'},
        {"size",   1, NULL, 's'},
        {"treeflag",   1, NULL, 'f'},       
        {NULL,     0, NULL,  0 }        
    };
    
    char *program_name;
    char input_filename[256], output_directory[256], Dpath[256];

    int verbose = 0;
    strcpy(output_directory, "result");

    program_name = argv[0];
    do {
        next_option = getopt_long (argc, argv, short_options, long_options, NULL);
    
        switch (next_option) {
            case 'h':
                print_usage (stdout, 0);

            case 'i':
                strcpy(input_filename, optarg);
                break;

            case 'd':
                strcpy(Dpath, optarg);
                break;
                
            case 'o':
                strcpy(output_directory, optarg);
                break;
            
            case 'r':
                 num_random_graphs = atoi(optarg);
                break;

            case 's':
                subgraphSize = atoi(optarg);
                break;

            case 'f':
                treeflag = atoi(optarg);
                break;
            
            case '?':
                print_usage (stdout, 1);
                
            case -1:        /* Done with options. */
                break;
            
            default:        /* Something else: unexpected. */
                print_usage (stderr, -1);
        }
    } while (next_option != -1);

 
    if (input_filename == NULL) {
        fprintf(stderr, "Input Argument Error: Please specify an input filename using \"-i <FILE NAME>\".\n");
        print_usage (stderr, -1);
    }
    
    if (subgraphSize == -1) {
        fprintf(stderr, "Input Argument Error: Please specify a motif size using \"-s <MOTIF SIZE>\".\n");
        print_usage (stderr, -1);
    }
    
    num_random_graphs = 0;
   
    subgraph = new int*[subgraphSize];
    for (int i = 0; i < subgraphSize; i++)
        subgraph[i] = new int[subgraphSize+3];   //add two cells on subgraph save the number of nodes, edges

    num = 0;
    printf("Graphlets Size: %d\n", subgraphSize);
    printf("Input Graph: %s\n", input_filename);

    if (!ReadData(input_filename, Dpath))
        return 0;

    g->setPath(output_directory);

    double realStart_t = realtime();

    clock_t startTime = clock();
    gettimeofday(&tv, 0);
    //for main graph
    isRand = false;
    subgraphCounter = 0;
    Enumerate();
    

    gettimeofday(&tvPartition, 0);

    cout<<"partitionTime"<<(tvPartition.tv_sec - tv.tv_sec + (double)(tvPartition.tv_usec - tv.tv_usec) / CLOCKS_PER_SEC)<<endl;
    exit(1);

    int deleted=0;
    vector<std::string> frequentG;
    
    vector< pair<std::string, long long int> > finalTree;
    hash_map<std::string, vector< const std::string* > > degreeSeq;
    hash_map<std::string, long long int> degreeSeqCount;
    /*******************Tree isomorphic*****************************/

    /*
    int treeSize = treeInt.size();
 
    int flag=0;
    
    int countTree =0;
  
    for (hash_map<std::string, long long int>::iterator it = treeInt.begin(); it != treeInt.end(); it++)
    {
        std::string tree1 = it->first;
        cout<<"Tree1 = "<<tree1<<endl;
        long long int tempCount = it->second;

        flag = 0;
    
        countTree++;
        
        for (int vi = 0; vi < finalTree.size(); vi++)
        {

            std::string tree2 = finalTree[vi].first;


            if(treeIso(tree1,tree2))
            {
                finalTree[vi].second = tempCount + finalTree[vi].second;
                flag = 1;
                break;
            }
        }
        if(flag == 0)
        {
            pair<string, long long int> tempPair = make_pair(tree1, tempCount);
            finalTree.push_back(tempPair);
        }
        
    }
    */


 
    /******************write non-isomorphic trees into file***********/
    int frequentTree = 0;
    ofstream fileTree;

    fileTree.open(("resultTree_"+intToString(subgraphSize)+".txt").c_str());

    for (hash_map<std::string, long long int>::iterator it = treeInt.begin(); it != treeInt.end(); it++)
    {
        if(it->second > (THR*subgraphCounter))
        {
            frequentTree++;
            //fileTree<< it->first<<" "<<it->second<<"\n";
        }
    }
    
    fileTree.close();

    printf("OutTree: %d\n", frequentTree);

    treeInt.clear();
    finalTree.clear();
    gettimeofday(&treeover, 0);

    cout<<"Time of dealing with tree after Partition before graph: "<<(treeover.tv_sec - tvPartition.tv_sec + (double)(treeover.tv_usec - tvPartition.tv_usec) / CLOCKS_PER_SEC)<<endl;
    
    /****************************************************************/
    /*****************graph isomorphic********************************/
    int graphSize = graphInt.size();
    //cout<<"graphSize:"<<graphSize<<endl;
    vector<bool> CountedGraph(graphSize, true);

    int flag = 0;
    int flag2 = 0;
    //degree sequence
    /*1210 2013**/
    for (hash_map<std::string, long long int>::iterator it = graphInt.begin(); it != graphInt.end(); it++)
    {
        const std::string *graph1 = &(it->first);

        //cout<<"Graph1 = " << *graph1 <<endl;

        std::string gds1 = graphDegreeSequence(*graph1,subgraphSize,AsciiToInt);
        long long int tempCount = it->second;
        //vector<const std::string*> tempGraphs;
        //tempGraphs.push_back(graph1);

        if(degreeSeqCount.find(gds1)==degreeSeqCount.end())
        {
            degreeSeqCount[gds1] = tempCount;
            vector<const std::string*> tempGraphsTemp;
            tempGraphsTemp.push_back(graph1);
            degreeSeq[gds1] = tempGraphsTemp;
        }
        else
        {
            degreeSeqCount.find(gds1)->second = degreeSeqCount.find(gds1)->second + tempCount;
            degreeSeq.find(gds1)->second.push_back(graph1);
        }

    }

    gettimeofday(&DSeqover, 0);

    cout<<"Time of dealing with Degree sequence: "<<(DSeqover.tv_sec - treeover.tv_sec  + (double)(DSeqover.tv_usec - treeover.tv_usec ) / CLOCKS_PER_SEC)<<endl;

    hash_map<std::string, long long int> finalGraph;
    int countCam = 0;
    for (hash_map<std::string, vector<const std::string*> >::iterator it = degreeSeq.begin(); it != degreeSeq.end(); it++)
    {
        vector<const std::string*> tempV = it->second;//graph strings' address with the same degreeSeq 

        if (degreeSeqCount.find(it->first)->second <= (seqTHR*subgraphCounter))
        {
            continue;
        }

        for (int iv = 0; iv < tempV.size(); iv++)
        {
            string tempCam = *(tempV[iv]);
            //cout<<"tempCam = "<<tempCam<<endl;
            countCam++;
            string cam =  calculateCam(tempCam,subgraphSize,AsciiToInt);
            //cout<<"cam = "<< cam<<endl;

            hash_map<std::string, long long int>::iterator it2 =  finalGraph.find(cam);
            if (it2 == finalGraph.end())
            {

                finalGraph[cam] = graphInt.find(tempCam)->second;
            }
            else
            {
                (it2->second) =  (it2->second) + graphInt.find(tempCam)->second;
            }
        }
        tempV.clear();
    }


    gettimeofday(&Camover, 0);

    cout<<"Time of dealing with Cam: "<<(Camover.tv_sec - DSeqover.tv_sec   + (double)(Camover.tv_usec - DSeqover.tv_usec) / CLOCKS_PER_SEC)<<endl;

    // cout<<"here 3333"<<endl;
    ofstream fileGraph;
    fileGraph.open(("resultGraph_"+intToString(subgraphSize)+".txt").c_str());
    //cout<<"Number of finalGraph : "<<finalGraph.size()<<endl;
    int frequentGraph = 0;
    for (hash_map<std::string, long long int> ::iterator it = finalGraph.begin(); it != finalGraph.end(); it++)
    {
        if (it->second > THR*subgraphCounter)
        {
            frequentGraph ++;
            //fileGraph<< it->first<<" "<<it->second<<"\n";
        }
    }
    printf("OutGraph: %d\n", frequentGraph);
    fileGraph.close();

    /****************************************************************/
    //g->AllocateCounter();
    //std::cout<<"countCam"<<countCam<<std::endl;
    //std::cout<<"degreeSeq:"<<degreeSeq.size()<<std::endl;
    //std::cout<<"finalGraph:"<<finalGraph.size()<<std::endl;
    //std::cout<<"deleted:"<<deleted<<std::endl;
    //std::cout<<"frequentGCount:"<<frequentG.size()<<std::endl;
    
    //g->Extract();

    clock_t end_main_time = clock();
    main_time = difftime(end_main_time, startTime)/(double)CLOCKS_PER_SEC;
    //printf("Time Used for main graph: %f\n", main_time);

    subgraphCounterMain = subgraphCounter;
    //for random graphs
    srand(time(NULL));
    isRand = true;
    long long boz = 0;
    //printf("Number of Random Graphs: %d\n", num_random_graphs);
    for (i = 1; i <= num_random_graphs; i++)
    {
        
        gen.genRandGraph_Edge(g);
        subgraphCounter = 0;
        Enumerate();
        g->Extract();
    }

    if (0 < num_random_graphs)
        g->calculateZSCORE(num_random_graphs, subgraphCounterMain, output_directory);

    for(i = 0; i < subgraphSize; i++)
    {
        delete [] Index[i];
        delete [] childSet[i];
    }

    for (int i = 0; i < subgraphSize; i++)
        delete [] subgraph[i];

    delete [] subgraph;
    delete [] Index;
    delete [] childSet;
    delete [] Visited;
    delete g;
    gettimeofday(&tv1, 0);
    clock_t endTime = clock();
    double total_time = difftime(endTime, startTime)/(double)CLOCKS_PER_SEC;
    printf("Time Used: %f\n", total_time);
    cout<<(tv1.tv_sec - tv.tv_sec + (double)(tv1.tv_usec - tv.tv_usec) / CLOCKS_PER_SEC)<<endl;

    double realEnd_t = realtime();
    cout<<"Total real Time: "<<realEnd_t - realStart_t <<endl;
    printf("=============================\n");
    //printf("graphInt: %d\n", graphInt.size());

    //printf("finalGraph: %d\n", finalGraph.size());
    printf("Tree Cam Count: %d\n", frequentTree);
    printf("Graph Cam Count: %d\n", finalGraph.size());
    printf("Total Cam Count: %d\n", finalGraph.size() + frequentTree);
    printf("Total Number of Subgraphs: %lld\n", subgraphCounter);


    return 0;
}
Exemplo n.º 7
0
Arquivo: g2i.cpp Projeto: dkj/simtools
int main(int argc, char *argv[])
{
	char c;
	int nBadFiles = 0;
	vector<string> infiles;

	while ((c = getopt (argc, argv, "neckmsvbw?hgo:i:x:p:d:r:t:")) != -1) {
		switch (c) {
				case 'v':	verbose=true; break;
				case 'b':	binary=true; break;
				case 'c':	excludeCnv=true; break;
				case 'k':	includeCnv=true; break;
				case 'e':	excludeExo=true; break;
				case 'g':	genoSNP=true; break;
				case 's':	genoCalling=true; break;
				case 'm':	simOutput=true; break;
				case 'n':	normalise=false; break;
				case 'h':
				case '?':	displayUsage(); break;
				case 'o':	outputFile = optarg;	break;
				case 't':	tmpFile = optarg;	break;
				case 'p':	project = optarg; break;
                case 'd':   manifestDir = optarg; break;
                case 'x':   exclusionFile = optarg; break;
				case 'r':	chrSelect = optarg; break;
				case 'i':	ifstream f; string s;
							f.open(optarg);
							if (strcmp(optarg,".json")) {
								bool parsingSuccessful = reader.parse( f, root );
								if ( !parsingSuccessful ) {
									std::cout  << "Failed to parse json file\n" << reader.getFormatedErrorMessages() << endl;
									return 0;
								}
								for ( unsigned int index = 0; index < root.size(); ++index ) { // Iterates over the sequence elements.
									sampleNames.push_back(root[index]["uri"].asString());
									infiles.push_back(root[index]["result"].asString());
								}
							} else {
								while (f >> s) infiles.push_back(s);
							}
							f.close();
							break;
		}
	}

	if (outputFile.size() == 0) {
		cout << "No output file specified" << endl;
		displayUsage();
	}

	if (tmpFile.size() == 0) {
		tmpFile = outputFile;
	}

	if (project.size()) {
		getAutocallInfo(infiles,project);
	}

	if (exclusionFile.size() != 0) {
		loadExclusionFile(exclusionFile);
	}

	// read the rest of the command line
	for (int n = optind; n < argc; n++) {
		infiles.push_back(argv[n]);
	}

	if (infiles.size() == 0) {
		cout << "No input files specified" << endl;
		displayUsage();
	}

	if (excludeCnv && includeCnv) {
		cout << "You can't specify -c AND -k options together! That doesn't make sense!" << endl;
		displayUsage();
	}

	if (!excludeCnv && !includeCnv) excludeCnv=true;	// default to 'exclude' if nothing specified

	// sanity check the GTC files
	if (verbose) cout << timestamp() << "Sanity checking";

	for (vector<string>::iterator f = infiles.begin(); f != infiles.end(); f++) {
		bool badFile = false;
		if (verbose) cout << '.';
		try {
			gtc.open(*f,0);
			if (gtc.errorMsg.length()) throw gtc.errorMsg;
		}
		catch (string s) {
			cout << s << endl;
			badFile = true;
			nBadFiles++;
		}
		if (excludeExo && ( (gtc.sampleName.find("Exo") == 0) || 
		                    (gtc.sampleName.find("EXO") == 0))) {
			badFile=true;
			if (verbose) cout << "X";
		}
		if (exclusionList[gtc.sampleName]) {
			badFile = true;
			if (verbose) cout << "X";
		}
		if (!badFile) {
			gtcHash[gtc.sampleName] = *f;
			sampleArray.push_back(gtc.sampleName);
		}
	}
	if (verbose) cout << endl;

	// a little validation...
	if (gtcHash.size() == 0) {
		cout << "No gtc files specified\n";
		exit(1);
	}

	string manifestName = "";
	for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
		gtc.open(i->second,0);
		if (manifestName != "" && gtc.manifest != manifestName) {
			cout << "GTC files do not all have the same manifest" << endl;
			exit(1);
		}
		manifestName = gtc.manifest;
	}

	if (verbose) {
		cout << timestamp() << "About to process " << gtcHash.size() << " GTC files" << endl;
		if (nBadFiles) cout << "Cannot process " << nBadFiles << " GTC files" << endl;
	}

	if (!simOutput) {
	if (verbose) cout << "Loading manifest " << manifestName << endl;
    
    if (manifestDir.size()) {
      loadManifest(manifestDir, manifestName);
    } else {
      loadManifest(relativeManifestPath(infiles[0]), manifestName);
    }
	}

	try {
	if (genoSNP)          { createGenoSNP(tmpFile); }
	else if (genoCalling) { createGenoCalling(tmpFile);   }
	else if (simOutput)   { createSimFile(tmpFile);   }
	else                  { goForIt(tmpFile);       }
	}
	catch (char *s) {
		cerr << timestamp() << "Caught fatal error: " << s << endl;
		return 1;
	}

	// Copy temporary files to final output files
	if (tmpFile.compare(outputFile)) {
		for (vector<string>::iterator i = filenameArray.begin(); i != filenameArray.end(); i++) {
			string command = "cp " + tmpFile + *i + " " + outputFile + *i;
			if (verbose) cout << timestamp() << "Sending command: '" << command << "'" << endl;
			int ret = system(command.c_str());
			if (ret) {
				cerr << "system(" << command << ") returned value " << ret;
				exit(1);
			}
                        if (remove((tmpFile + *i).c_str()) != 0)
				cerr << "error cleaning up temporary file" << endl;
		}
	}

	return 0;
}
Exemplo n.º 8
0
Arquivo: g2i.cpp Projeto: dkj/simtools
void createGenoCalling(string fname)
{
	int recordLength = gtcHash.size() * 18;
	char *buffer = new char[recordLength];
	memset(buffer,' ',recordLength);
	buffer[recordLength-1] = '\n';

	// Sort the SNPs into position order
	sort(manifest->snps.begin(), manifest->snps.end(), SortByPosition);

	// Create lockfile
	string lockFileName = fname + ".lock";
	FILE *lockfile = fopen(lockFileName.c_str(), "w");
	if (!lockfile) throw (strerror(errno));
	fclose(lockfile);

	//
	// Create all of the output files - one for each chromosome
	//
	for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
		if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
		if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
		fstream *f = outFile[snp->chromosome];
		if (!f) {
			f = new fstream();
			string fullFname = fname + "_gtu_" + snp->chromosome + ".txt";
			filenameArray.push_back("_gtu_" + snp->chromosome + ".txt");
			
			if (verbose) cout << timestamp() << "creating file " << fullFname << endl;
			f->open(fullFname.c_str(), ios::in | ios::out | ios::trunc);

			// write sample names from all the gtc files
			for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
				*f << "\t" << i->first;
			}
			*f << endl;
			// associate the file handle with the chromosome
			outFile[snp->chromosome] = f;
		}
		f = outFile[snp->chromosome];
		*f << snp->name;
		filePos[snp->name] = f->tellp();	// store next position to write
		f->write(buffer,recordLength);	// fill with nulls (or spaces)

		gcCache[snp->name] = "";
	}

	//
	// Process each GTC file in turn
	//
	int n=1;
	int cacheIndex = 0;
	for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
		if (verbose) cout << timestamp() << "Processing GTC file " << n++ << " of " << gtcHash.size() << endl;
		gtc.open(i->second,Gtc::GENOTYPES | Gtc::BASECALLS | Gtc::SCORES);	// reload GTC file to read required arrays

		for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
			if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
			if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
			int idx = snp->index - 1;	// index is zero based in arrays, but starts from 1 in the map file
			char buffer[128];
                        if (gtc.genotypes[idx] > 3)
			   cout << "Unknown genotype value: " << gtc.genotypes[idx] << endl;
                        if (gtc.genotypes[idx] == 0)
			    sprintf(buffer,"\tNN;%f", gtc.scores[idx]);
                        else
			    sprintf(buffer,"\t%c%c;%f", gtc.baseCalls[idx].a, gtc.baseCalls[idx].b, gtc.scores[idx]);
			gcCache[snp->name] += buffer;
		}
		cacheIndex++;
		if (cacheIndex == GCCACHESIZE) { flushgcCache(cacheIndex); cacheIndex=0; }
	}

	flushgcCache(cacheIndex);

	// close all of the files
	for (pos = outFile.begin(); pos != outFile.end(); pos++) {
		pos->second->close();
	}

	// delete lockfile and create donefile
	string doneFileName = lockFileName;
	string::size_type dot = doneFileName.find(".lock");
	doneFileName.replace(dot, 5, ".g2i");
	rename(lockFileName.c_str(), doneFileName.c_str());
	if (verbose) cout << timestamp() << "Renamed " << lockFileName << " to " << doneFileName << endl;
}
Exemplo n.º 9
0
Arquivo: g2i.cpp Projeto: dkj/simtools
void createGenoSNP(string fname)
{
	// Sort the SNPs into position order
	sort(manifest->snps.begin(), manifest->snps.end(), SortByPosition);

	// Create lockfile
	string lockFileName = fname + ".lock";
	FILE *lockfile = fopen(lockFileName.c_str(), "w");
	fclose(lockfile);

	//
	// Create all of the output files
	//
	string rawFname = fname + ".raw.txt";
	string snpFname = fname + ".snp.txt";
	string norFname = fname + ".nor.txt";
	filenameArray.push_back(".raw.txt");
	filenameArray.push_back(".snp.txt");
	filenameArray.push_back(".nor.txt");
	
	fstream fn;
	fstream fs;
	fstream fr;
	fr.open(rawFname.c_str(), ios::in | ios::out | ios::trunc);
	fn.open(norFname.c_str(), ios::in | ios::out | ios::trunc);
	fs.open(snpFname.c_str(), ios::in | ios::out | ios::trunc);
	if (verbose) cout << timestamp() << "creating file " << rawFname << ", " << norFname << " and " << snpFname << endl;

        // Write SNP list to .snp
	for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
		if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
		if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
		fs << snp->name << '\t'
		   << (snp->normId % 100) + 1 << '\t'
		   << snp->snp[0] << " " << snp->snp[1] << endl;
	}
        fs.close();
        if (fs.bad())
            cout << "Error closing snp file" << endl;

	//
	// Process each GTC file in turn
	//
	int n=1;
	for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
		if (verbose) cout << timestamp() << "Processing GTC file " << n++ << " of " << gtcHash.size() << endl;
		//
		// add sample name to each output file
		// no family info as yet (todo?) - write sample ID twice
		fn << i->first << "\t" << i->first;
		fr << i->first << "\t" << i->first;

		gtc.open(i->second,Gtc::XFORM | Gtc::INTENSITY);	// reload GTC file to read XForm and Intensity arrays

		for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
			if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
			if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
			int idx = snp->index - 1;	// index is zero based in arrays, but starts from 1 in the map file
			unsigned int norm = manifest->normIdMap[snp->normId];
			XFormClass *XF = &gtc.XForm[norm];

			// first do the normalisation calculation
			double tempx = gtc.xRawIntensity[idx] - XF->xOffset;
			double tempy = gtc.yRawIntensity[idx] - XF->yOffset;

			double cos_theta = cos(XF->theta);
			double sin_theta = sin(XF->theta);
			double tempx2 = cos_theta * tempx + sin_theta * tempy;
			double tempy2 = -sin_theta * tempx + cos_theta * tempy;

			double tempx3 = tempx2 - XF->shear * tempy2;
			double tempy3 = tempy2;

			double xn = tempx3 / XF->xScale;
			double yn = tempy3 / XF->yScale;

			// add raw/norm x/y to .raw and .nor files
			fr << "\t" << std::fixed << setprecision(3) << gtc.xRawIntensity[idx] << " " << gtc.yRawIntensity[idx];
			fn << "\t" << std::fixed << setprecision(3) << xn << " " << yn;
		}
		fn << endl;
		fr << endl;
	}

	fn.close();
	if (fn.bad()) cout << "Error closing nor file" << endl;
	fr.close();
	if (fr.bad()) cout << "Error closing raw file" << endl;

	// delete lockfile and create donefile
	string doneFileName = lockFileName;
	string::size_type dot = doneFileName.find(".lock");
	doneFileName.replace(dot, 5, ".g2i");
	rename(lockFileName.c_str(), doneFileName.c_str());
	if (verbose) cout << timestamp() << "Renamed " << lockFileName << " to " << doneFileName << endl;
}
Exemplo n.º 10
0
Arquivo: g2i.cpp Projeto: dkj/simtools
void createSimFile(string fname)
{
	Sim *sim = new Sim();

	hash_map<string,string>::iterator i = gtcHash.begin();
	gtc.open(i->second, Gtc::INTENSITY);
	sim->createFile(fname);
	sim->writeHeader(gtcHash.size(), gtc.xRawIntensity.size());

	//
	//
	// Process each GTC file in turn
	//
	unsigned int n=1;
	for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
		char *buffer;
		if (verbose) cout << timestamp() << "Processing GTC file " << n << " of " << gtcHash.size() << endl;
		//
		// add sample name to each output file
		// no family info as yet (todo?) - write sample ID twice
//		fn << i->first << endl;

		gtc.open(i->second,Gtc::XFORM | Gtc::INTENSITY);	// reload GTC file to read XForm and Intensity arrays
		buffer = new char[sim->sampleNameSize];
		memset(buffer,0,sim->sampleNameSize);
		// if we have a sample name from the json file, use it
		if (sampleNames.size() > (n-1)) { strcpy(buffer, sampleNames[n-1].c_str()); }
		else                            { strcpy(buffer,gtc.sampleName.c_str()); }
		sim->write(buffer, sim->sampleNameSize);

		for (unsigned int idx = 0; idx < gtc.xRawIntensity.size(); idx++) {
			uint16_t v;
			v = gtc.xRawIntensity[idx];
			sim->write(&v,sizeof(v));
			v = gtc.yRawIntensity[idx];
			sim->write(&v,sizeof(v));
		}
		n++;

#if 0
		for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
			if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
			if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
			int idx = snp->index - 1;	// index is zero based in arrays, but starts from 1 in the map file
			unsigned int norm = manifest->normIdMap[snp->normId];
			XFormClass *XF = &gtc.XForm[norm];

			// first do the normalisation calculation
			double tempx = gtc.xRawIntensity[idx] - XF->xOffset;
			double tempy = gtc.yRawIntensity[idx] - XF->yOffset;

			double cos_theta = cos(XF->theta);
			double sin_theta = sin(XF->theta);
			double tempx2 = cos_theta * tempx + sin_theta * tempy;
			double tempy2 = -sin_theta * tempx + cos_theta * tempy;

			double tempx3 = tempx2 - XF->shear * tempy2;
			double tempy3 = tempy2;

			double xn = tempx3 / XF->xScale;
			double yn = tempy3 / XF->yScale;

			// add raw/norm x/y to .raw and .nor files
//			fn << "\t" << std::fixed << setprecision(3) << xn << " " << yn;
		}
#endif

	}
	sim->close();
}
Exemplo n.º 11
0
Arquivo: g2i.cpp Projeto: dkj/simtools
//
// We've read the Manifest and all the GTC files
// Now it's time to create the output files
//
void goForIt(string fname)
{
	int recordLength = gtcHash.size() * 10 * 2;
	if (binary) recordLength = gtcHash.size() * sizeof(float) * 2;
	char *buffer = new char[recordLength];
	if (binary) {
		memset(buffer,0,recordLength);
	} else {
		memset(buffer,' ',recordLength);
		buffer[recordLength-1] = '\n';
	}

	// Sort the SNPs into position order
	sort(manifest->snps.begin(), manifest->snps.end(), SortByPosition);

	// Create lockfile
	string lockFileName = fname + ".lock";
	FILE *lockfile = fopen(lockFileName.c_str(), "w");
	if (!lockfile) {
		cerr << "Can't create lock file " << lockFileName << endl;
		cerr << strerror(errno) << endl;
		exit(1);
	}
	fclose(lockfile);

	//
	// Create all of the output files - one for each chromosome
	//
	for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
		if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
		if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
		fstream *f = outFile[snp->chromosome];
		if (!f) {
			f = new fstream();
			string fullFname = fname + "_intu_" + snp->chromosome + ".txt";
			filenameArray.push_back("_intu_" + snp->chromosome + ".txt");
			if (verbose) cout << timestamp() << "creating file " << fullFname << endl;
			if (binary) f->open(fullFname.c_str(), ios::in | ios::out | ios::trunc | ios::binary);
			else        f->open(fullFname.c_str(), ios::in | ios::out | ios::trunc);

			*f << "SNP\tCoor\tAlleles";
			// write sample names from all the gtc files
			for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
				*f << "\t" << i->first << "A\t" << i->first << "B";
			}
			*f << endl;
			// associate the file handle with the chromosome
			outFile[snp->chromosome] = f;
		}
		f = outFile[snp->chromosome];
		*f << snp->name << "\t" << snp->position << "\t" << snp->snp[0] << snp->snp[1];
		filePos[snp->name] = f->tellp();	// store next position to write
		f->write(buffer,recordLength);	// fill with nulls (or spaces)

		cache[snp->name] = new float[CACHESIZE];
	}

	//
	// Process each GTC file in turn
	//
	int n=1;
	int cacheIndex = 0;
	for (hash_map<string,string>::iterator i = gtcHash.begin(); i != gtcHash.end(); i++) {
		if (verbose) cout << timestamp() << "Processing GTC file " << n++ << " of " << gtcHash.size() << endl;
		gtc.open(i->second,Gtc::XFORM | Gtc::INTENSITY);	// reload GTC file to read XForm and Intensity arrays

		for (vector<snpClass>::iterator snp = manifest->snps.begin(); snp != manifest->snps.end(); snp++) {
			if (excludeCnv && snp->name.find("cnv") != string::npos) continue;
			if (chrSelect.size() && chrSelect.compare(snp->chromosome)) continue;
			int idx = snp->index - 1;	// index is zero based in arrays, but starts from 1 in the map file
			unsigned int norm = manifest->normIdMap[snp->normId];
			XFormClass *XF = &gtc.XForm[norm];

			double xn, yn;
			if (normalise) {
				// first do the normalisation calculation
				double tempx = gtc.xRawIntensity[idx] - XF->xOffset;
				double tempy = gtc.yRawIntensity[idx] - XF->yOffset;

				double cos_theta = cos(XF->theta);
				double sin_theta = sin(XF->theta);
				double tempx2 = cos_theta * tempx + sin_theta * tempy;
				double tempy2 = -sin_theta * tempx + cos_theta * tempy;

				double tempx3 = tempx2 - XF->shear * tempy2;
				double tempy3 = tempy2;

				xn = tempx3 / XF->xScale;
				yn = tempy3 / XF->yScale;
			} else {
				xn = gtc.xRawIntensity[idx];
				yn = gtc.yRawIntensity[idx];
			}

			cache[snp->name][cacheIndex] = xn;
			cache[snp->name][cacheIndex+1] = yn;
		}
		cacheIndex += 2;
		if (cacheIndex == CACHESIZE) { flushCache(cacheIndex); cacheIndex=0; }
	}

	flushCache(cacheIndex);

	// close all of the files
	for (pos = outFile.begin(); pos != outFile.end(); pos++) {
		pos->second->close();
	}

	// delete lockfile and create donefile
	string doneFileName = lockFileName;
	string::size_type dot = doneFileName.find(".lock");
	doneFileName.replace(dot, 5, ".g2i");
	rename(lockFileName.c_str(), doneFileName.c_str());
	if (verbose) cout << timestamp() << "Renamed " << lockFileName << " to " << doneFileName << endl;
}
Exemplo n.º 12
0
void Callback(string dir,WCHAR* X,vector<data*>& Y,hash_map<string,indx>& Z,int label)
{
	std::wstring wstr(X);
	char buf[MAX_SIZE];
	string file(wstr.begin(),wstr.end());
	file=dir+file;
	std::ifstream ifs(file,ifstream::in);
	string temp;
	int pos=0;
	int tos=0;
	int sum=0;
	hash_map<string,indx>::iterator ter;
	hash_map<string,int>::iterator iter;
	while(ifs.good())
	{
		if(label==1)
			positivecnt++;
		else if(label==-1)
			negativecnt++;
		else
			predictcnt++;
		sum=0;
		data* _dt=new data();
		set<attribute,attribute>example;	
		hash_map<string,int>tempo;
		ifs.getline(buf,MAX_SIZE);
		temp.assign(buf);
		if(temp.length()<=1)
			continue;
		while((pos=temp.find_first_of(',',tos+1))!=string::npos)
		{
			if((iter=tempo.find(temp.substr(tos,pos-tos)))!=tempo.end())
			{
				iter->second++;
				sum++;
			}
			else 
			{
				if(temp.substr(tos,pos-tos)!="")
				{
				tempo.insert(pair<string,int>(temp.substr(tos,pos-tos),1));
				sum++;
				}
			}
			tos=pos+1;
			
		}
	
		if((iter=tempo.find(temp.substr(tos)))!=tempo.end())
		{
			iter->second++;
			sum++;
		}
			else
			{
				if(temp.substr(tos,pos-tos)!="")
				{
				tempo.insert(pair<string,int>(temp.substr(tos),1));
				sum++;
				}
		}

		int i;
		for(i=0,iter=tempo.begin();iter!=tempo.end();iter++,i++)
		{
			if(label!=0)
			{
			if((ter=Z.find(iter->first))!=Z.end())
				ter->second.DF++;
			else
			{
			
				indx i;
				i.DF=1;
				i.index=Z.size()+1;
				Z.insert(pair<string,indx>(iter->first,i));
			}
			}
			attribute a;
			a.feature=iter->first;
			a.TF=((double)iter->second)/(double)sum;
			a.index=((ter=Z.find(iter->first))!=Z.end())?ter->second.index:0;
			example.insert(a);		
		}	
		_dt->features=example;
		if(label==1)
		_dt->label=1;
		else if(label==-1)
		_dt->label=-1;
		else
		_dt->label=0;
		Y.push_back(_dt);
		pos=0;
		tos=0;
	}
}
Exemplo n.º 13
0
void mapLoadDefaultColour()
{
    if(g_dayColourUnits.size()&&g_nightColourUnits.size())
    {
        return;
    }
    g_dayColourUnits.clear();
    g_nightColourUnits.clear();

    size_t maxTableSize = sizeof(g_roadColourTable) / sizeof(TMapColourEntry);
    for(size_t i = 0; i < maxTableSize; i++){                            //load road
        ColourUnit cUnit;
        cUnit.type = ROAD_ARC_MISC;
        RGBCOLOUR colour = g_navDisplay->getColour(g_roadColourTable[i].colourIndex);
        cUnit.colour.red = colour.red;
        cUnit.colour.green = colour.green;
        cUnit.colour.blue = colour.blue;
        cUnit.colour.alpha = colour.alpha;
        cUnit.typeIndex = i;
        if(g_dayColourUnits.find(g_roadColourTable[i].legend) == g_dayColourUnits.end())
        {
            g_dayColourUnits.insert(ColourPair(g_roadColourTable[i].legend, cUnit));
            g_nightColourUnits.insert(ColourPair(g_roadColourTable[i].legend, cUnit));
        }

    }
    TElevationPalette *pElevationPalette = g_navDisplay->getElevationPalette();
    for(size_t i = 0; i < numberOfGradients; i++){                       //load gradient
        ColourUnit cUnit;
        if(i < pElevationPalette->elevationThresholdsCount){
            cUnit.type = GRADIENT_ENABLE;
            TElevationPaletteEntry entry = pElevationPalette->elevationPalette[i];
            cUnit.colour.red = entry.r;
            cUnit.colour.green = entry.g;
            cUnit.colour.blue = entry.b;
            cUnit.colour.alpha = entry.elevation;
        }else{
            cUnit.type = GRADIENT_DISABLE;
        }
        if(g_dayColourUnits.find(STR_GRADIENT[i]) == g_dayColourUnits.end())
        {
            g_dayColourUnits.insert(ColourPair(STR_GRADIENT[i], cUnit));
            g_nightColourUnits.insert(ColourPair(STR_GRADIENT[i], cUnit));
        }

    }
    maxTableSize = sizeof(g_polyColourTable) /
            sizeof(TPolyMapColourEntry) - 1;                                   //last one is elevation, so skip
    for(size_t i = 0; i < maxTableSize; i++) {                           //load poly
        ColourUnit cUnit;
        cUnit.type = POLY_CITY;
        RGBCOLOUR colour = g_navDisplay->getPolygonFillColour(g_polyColourTable[i].polyClass);
        cUnit.colour.red = colour.red;
        cUnit.colour.green = colour.green;
        cUnit.colour.blue = colour.blue;
        cUnit.colour.alpha = colour.alpha;
        cUnit.typeIndex = i;
        if(g_dayColourUnits.find(g_polyColourTable[i].polyName) == g_dayColourUnits.end())
        {
            g_dayColourUnits.insert(ColourPair(g_polyColourTable[i].polyName, cUnit));
            g_nightColourUnits.insert(ColourPair(g_polyColourTable[i].polyName, cUnit));
        }

    }
    g_currentColourType = DAY;
}
Exemplo n.º 14
0
unsigned int select_map_size(){
	return select_sockets_hash_map.size();
}
Exemplo n.º 15
0
/// \todo Make some assertion about # of constit. labels, and/or that
/// they are the lowest numbered ones?
void read_labels(const string filename) {
	assert(!open_label_list);

	ifstream fin(filename.c_str());
	assert(fin.is_open());

	_all_labels.clear();
	_all_constituent_labels.clear();
	_all_terminal_labels.clear();
	_max_label = 0;

	label_list.clear();
	label_map.clear();
	terminal_set.clear();
	constituent_set.clear();

	unsigned i, is_terminal, cnt;
	string label;
	while(!fin.eof()) {
		fin >> i >> ws >> is_terminal >> ws >> cnt >> label >> ws;

		if (i == NO_LABEL)
			label = "";

		label_list.push_back(label);
		assert(label_list.at(i) == label);
		label_map[label] = i;	// FIXME: Don't use [] operator

		if (i != NO_LABEL) {
			_all_labels.push_back(i);
			if (is_terminal) {
				terminal_set.insert(i, true);
				_all_terminal_labels.push_back(i);
			} else {
				constituent_set.insert(i, true);
				_all_constituent_labels.push_back(i);
			}
			if (i > _max_label) _max_label = i+1;
		}
	}
	assert(label_list.at(NO_LABEL) == "");
	assert(label_map[""] == NO_LABEL);	// FIXME: Don't use [] operator
	assert(label_list.size() == label_map.size());
//	assert(label_map.size() == terminal_set.size() + constituent_set.size() + 1);
	terminal_set.lock();
	constituent_set.lock();

/*
	Debug::log(1) << "Read " << constituent_set.size() << " constituents, " << \
			terminal_set.size() << " terminals from '" << filename << "'\n";
*/

	fin.close();
	open_label_list = true;

	if (is_label_string("ADJP")) _Label_ADJP = string_to_label("ADJP");
	if (is_label_string("ADVP")) _Label_ADVP = string_to_label("ADVP");
	if (is_label_string("AUX")) _Label_AUX = string_to_label("AUX");
	if (is_label_string("AUXG")) _Label_AUXG = string_to_label("AUXG");
	if (is_label_string("CC")) _Label_CC = string_to_label("CC");
	if (is_label_string("CD")) _Label_CD = string_to_label("CD");
	if (is_label_string("COLON")) _Label_COLON = string_to_label(":");
	if (is_label_string("COMMA")) _Label_COMMA = string_to_label(",");
	if (is_label_string("CONJP")) _Label_CONJP = string_to_label("CONJP");
	if (is_label_string("DOLLAR")) _Label_DOLLAR = string_to_label("$");
	if (is_label_string("DT")) _Label_DT = string_to_label("DT");
	if (is_label_string("EX")) _Label_EX = string_to_label("EX");
	if (is_label_string("FRAG")) _Label_FRAG = string_to_label("FRAG");
	if (is_label_string("FW")) _Label_FW = string_to_label("FW");
	if (is_label_string("HASH")) _Label_HASH = string_to_label("#");
	if (is_label_string("IN")) _Label_IN = string_to_label("IN");
	if (is_label_string("INTJ")) _Label_INTJ = string_to_label("INTJ");
	if (is_label_string("JJ")) _Label_JJ = string_to_label("JJ");
	if (is_label_string("JJR")) _Label_JJR = string_to_label("JJR");
	if (is_label_string("JJS")) _Label_JJS = string_to_label("JJS");
	if (is_label_string("LS")) _Label_LS = string_to_label("LS");
	if (is_label_string("LST")) _Label_LST = string_to_label("LST");
	if (is_label_string("MD")) _Label_MD = string_to_label("MD");
	if (is_label_string("NAC")) _Label_NAC = string_to_label("NAC");
	if (is_label_string("NN")) _Label_NN = string_to_label("NN");
	if (is_label_string("NNP")) _Label_NNP = string_to_label("NNP");
	if (is_label_string("NNPS")) _Label_NNPS = string_to_label("NNPS");
	if (is_label_string("NNS")) _Label_NNS = string_to_label("NNS");
	if (is_label_string("NP")) _Label_NP = string_to_label("NP");
	if (is_label_string("NPB")) _Label_NPB = string_to_label("NPB");
	if (is_label_string("NX")) _Label_NX = string_to_label("NX");
	if (is_label_string("POS")) _Label_POS = string_to_label("POS");
	if (is_label_string("PP")) _Label_PP = string_to_label("PP");
	if (is_label_string("PRN")) _Label_PRN = string_to_label("PRN");
	if (is_label_string("PRP")) _Label_PRP = string_to_label("PRP");
	if (is_label_string("PRPP")) _Label_PRPP = string_to_label("PRP$");
	if (is_label_string("PRT")) _Label_PRT = string_to_label("PRT");
	if (is_label_string("QP")) _Label_QP = string_to_label("QP");
	if (is_label_string("RB")) _Label_RB = string_to_label("RB");
	if (is_label_string("RBR")) _Label_RBR = string_to_label("RBR");
	if (is_label_string("RBS")) _Label_RBS = string_to_label("RBS");
	if (is_label_string("RP")) _Label_RP = string_to_label("RP");
	if (is_label_string("RRC")) _Label_RRC = string_to_label("RRC");
	if (is_label_string("S")) _Label_S = string_to_label("S");
	if (is_label_string("SBAR")) _Label_SBAR = string_to_label("SBAR");
	if (is_label_string("SBARQ")) _Label_SBARQ = string_to_label("SBARQ");
	if (is_label_string("SINV")) _Label_SINV = string_to_label("SINV");
	if (is_label_string("SQ")) _Label_SQ = string_to_label("SQ");
	if (is_label_string("SYM")) _Label_SYM = string_to_label("SYM");
	if (is_label_string("TO")) _Label_TO = string_to_label("TO");
	if (is_label_string("TOP")) _Label_TOP = string_to_label("TOP");
	if (is_label_string("UCP")) _Label_UCP = string_to_label("UCP");
	if (is_label_string("UH")) _Label_UH = string_to_label("UH");
	if (is_label_string("VB")) _Label_VB = string_to_label("VB");
	if (is_label_string("VBD")) _Label_VBD = string_to_label("VBD");
	if (is_label_string("VBG")) _Label_VBG = string_to_label("VBG");
	if (is_label_string("VBN")) _Label_VBN = string_to_label("VBN");
	if (is_label_string("VBP")) _Label_VBP = string_to_label("VBP");
	if (is_label_string("VBZ")) _Label_VBZ = string_to_label("VBZ");
	if (is_label_string("VP")) _Label_VP = string_to_label("VP");
	if (is_label_string("WDT")) _Label_WDT = string_to_label("WDT");
	if (is_label_string("WHADJP")) _Label_WHADJP = string_to_label("WHADJP");
	if (is_label_string("WHADVP")) _Label_WHADVP = string_to_label("WHADVP");
	if (is_label_string("WHNP")) _Label_WHNP = string_to_label("WHNP");
	if (is_label_string("WHPP")) _Label_WHPP = string_to_label("WHPP");
	if (is_label_string("WP")) _Label_WP = string_to_label("WP");
	if (is_label_string("X")) _Label_X = string_to_label("X");
}
Exemplo n.º 16
0
int main(int argc, char *argv[]) {

	// for (int ini = 0; ini < 9; ini++)
 //    {
 //        char temp = '1'+ini;
 //        AsciiToInt[temp] = ini;
 //        IntToAscii[ini] = temp;
 //    }
 //    for (int ini = 0; ini < 26; ini++)
 //    {
 //        char temp = 'a'+ini;
 //        AsciiToInt[temp] = 9 + ini;
 //        IntToAscii[9+ini] = temp;
 //    }
 //    for (int ini = 0; ini < 26; ini++)
 //    {
 //        char temp = 'A'+ini;
 //        AsciiToInt[temp] = 35 + ini;
 //        IntToAscii[35+ini] = temp;
 //    }
	for(int ini = 0; ini < 94; ini++)
	{
		char temp = '!' + ini;
		AsciiToInt[temp] = ini;
		IntToAscii[ini] = temp;
	}


	double total_random_time = 0 , main_time;
	clock_t start_random_time, end_random_time;
	directed = true;
	register int i, j;
	long long unsigned subgraphCounterMain;

	int next_option;
	const char *const short_options = "h:i:o:r:s:d:f:l:u";
	const struct option long_options[] = {
		{"help",   0, NULL, 'h'},
		{"input",  1, NULL, 'i'},
		{"output", 1, NULL, 'o'},
		{"random", 1, NULL, 'r'},
		{"size",   1, NULL, 's'},
		{"density", 1, NULL, 'd'},
		{"frequency", 1, NULL, 'f'},
		{"limit", 1, NULL, 'l'},
		{"undirected",   0, NULL, 'u'},
		{NULL,     0, NULL,  0 }
	};
	
	char *program_name;
    char input_filename[256], output_directory[256];

    int verbose = 0;
    strcpy(output_directory, "result");

    program_name = argv[0];
    do {
		next_option = getopt_long (argc, argv, short_options, long_options, NULL);
	
		switch (next_option) {
			case 'h':
	    		print_usage (stdout, 0);

			case 'i':
				strcpy(input_filename, optarg);
	    		break;
	    	
			case 'o':
				strcpy(output_directory, optarg);
	    		break;
			
			case 'r':
				 num_random_graphs = atoi(optarg);
	    		break;

			case 's':
				subgraphSize = atoi(optarg);
	    		break;
	    	case 'd':
	    		subgraphDensity = atof(optarg);
	    		break;
	    	case 'f':
	    		frequency_thr = atof(optarg);
	    		break;
	    	case 'l':
	    		subgraph_THR = atof(optarg);
	    		break;
			case 'u':
				directed = false;
	    		break;
			
			case '?':
	    		print_usage (stdout, 1);
				
			case -1:		/* Done with options. */
			    break;
			
			default:		/* Something else: unexpected. */
                print_usage (stderr, -1);
		}
    } while (next_option != -1);
    cout<<"subgraph_THR = " << subgraph_THR<<endl;
    directed = false;//Tao 2016 Jun 25, only work on undirected graph now.

	if (input_filename == NULL) {
		fprintf(stderr, "Input Argument Error: Please specify an input filename using \"-i <FILE NAME>\".\n");
        print_usage (stderr, -1);
	}
	
	if (subgraphSize == -1) {
		fprintf(stderr, "Input Argument Error: Please specify a motif size using \"-s <MOTIF SIZE>\".\n");
        print_usage (stderr, -1);
	}
	
	printf("Motif Size: %d\n", subgraphSize);
	printf("Input Graph: %s\n", input_filename);
	
	if (!ReadData(input_filename))
		return 0;

	printf("ReadData Finished!!!\n");
	cout<<"Nodes:"<<g->nV<<endl;
	cout<<"Edges:"<<g->Edges()<<endl;
	g->setPath(output_directory);

	clock_t startTime = clock();
	//for main graph
	isRand = false;
	g->subgraphCounter = 0;
	g->notClassSubCounter = 0;
	clock_t mainStartTime = clock();
	//printf("before enumerate, everything is OK!\n");
	Enumerate();

	//printf("after enumerate, everything is OK!!\n");
	clock_t mainEndTime = clock();

	//hash_map<std::string, long long int> degreeSeqCount;
	hash_map<string, pair< vector<const string*>, long long int> > degreeSeqPair;
	hash_map<string, pair< vector<const string*>, long long int> >::iterator itor;
	cout<<"graphIntSize = "<<graphInt.size()<<endl;
	for(hash_map<std::string, long long int>::iterator it = graphInt.begin(); it!= graphInt.end(); it++)
	{
		const std::string *graphAdjMatStr = &(it->first);
		//cout<< *graphAdjMatStr<<endl;
		std::string graphDegSeq = graphDegreeSequence(*graphAdjMatStr, subgraphSize);
		//cout<<"No problem"<<endl;
		long long int tempCount = it->second;
		
		itor = degreeSeqPair.find(graphDegSeq);

		if( itor == degreeSeqPair.end())
		{
			vector<const string*> tmpstringvec;
			tmpstringvec.push_back(graphAdjMatStr);
			pair< vector<const string*>, long long int > tmpPair = make_pair(tmpstringvec, tempCount);

			degreeSeqPair[graphDegSeq] = tmpPair;
		}
		else
		{
			(itor->second).first.push_back(graphAdjMatStr);
			(itor->second).second += tempCount;
		}

	}

	//cout<<"still alive!"<<endl;

	hash_map<string, long long int> finalGraph;
	for(itor = degreeSeqPair.begin(); itor != degreeSeqPair.end(); itor++)
	{
		if((itor->second).second <= frequency_thr )
		{
			continue;
		}
		for(int iv = 0; iv < (itor->second).first.size(); iv++ )
		{
			string tempCam = *(((itor->second).first)[iv]);
			string cam = calculateCam(tempCam, subgraphSize);
			callNautyCount += 1;

			hash_map<std::string, long long int>::iterator it2 =  finalGraph.find(cam);
            if (it2 == finalGraph.end())
            {

                finalGraph[cam] = graphInt.find(tempCam)->second;
            }
            else
            {
                (it2->second) += graphInt.find(tempCam)->second;
            }
		}
	}

	//count graph part
	int graph_class = 0, tree_class = 0;
	for(hash_map<std::string, long long int>::iterator it = finalGraph.begin(); it!= finalGraph.end(); it++)
	{
		if (it->second >= frequency_thr)
		{
			graph_class += 1;
		}
	}	

	//count tree part
	hash_map<string, long long int> finalTree;
	for(hash_map<std::string, long long int>::iterator it = treeInt.begin(); it!= treeInt.end(); it++)
	{
		if (it->second >= frequency_thr)
		{
			tree_class += 1;
			//cout<< it->first<<endl;
		}
	}


	subgraphCounterMain = g->subgraphCounter;
	enumerated_class = graph_class + tree_class;

	
	delete g;
	//delete IsD;
	delete subgraphDegree;

	clock_t endTime = clock();
	main_time = difftime(mainEndTime, mainStartTime)/(double)CLOCKS_PER_SEC;
	double total_time = difftime(endTime, startTime)/(double)CLOCKS_PER_SEC;

	printf("\n===========RESULTS===========\n");
	
	printf("\nMotif Size: %d\n", subgraphSize);
	printf("\nTotal number of subgraphs in original network: %llu\n", subgraphCounterMain);
	printf("Number of frequent non-isomorphic classes: %lu\n", enumerated_class);
	printf("Number of frequent non-isomorphic graph classes: %lu\n", graph_class);
	printf("Number of frequent non-isomorphic tree classes: %lu\n", tree_class);
	printf("\nTime Used for Enumerate:      %f\n", main_time); 
	
	printf("\nTotal Time Used: %f\n", total_time); 
	printf("\n=============================\n");
	printf("Call Nauty %lld\n", callNautyCount );
	
	return 0;
}