void ReadParameters(int number, char ** vector) { int c; while ((c = getopt(number, vector, "g:c:n:f:o:s:d:p:")) != EOF) { switch (c) { case 'h': //Print help and exit. PrintHelp(); break; case 'g': //Sets the graph filename. graphFilename = optarg; break; case 'c': //Sets the clustering filename. clusteringFilename = optarg; break; // case 'C': //Sets the complex filename. //complexFilename = optarg; //break; case 'n': //Sets the protein name filename. nameFilename = optarg; break; case 'f': //Sets the function name string. functionMapping = optarg; break; case 'o': //Sets the output filename outputFilename = optarg; break; case 's': //Sets the minimum cluster size sizeCutoff = atoi(optarg); break; case 'd': //Sets the minimum cluster density densityCutoff = atof(optarg); break; case 'p': //Sets the maximum P-value pCutoff = atof(optarg); break; case '?': //invalid command line format printUsageError(); exit(1); return; break; default: //invalid command line format printUsageError(); exit(1); return; break; }//END SWITCH }//END WHILE c (taking command line arguments) if (optind < number) { //More invalid input fprintf(stderr,"Too many arguments.\n"); printUsageError(); exit(1); return; } }
int main(int argc, char **argv) { if(argc==1) PrintHelp(); scaledCost = 0; time_t startTime; srand(time(&startTime)); outputFilename = (char *)"output.txt"; functionMapping = (char *)"UABCDEFGHIJKLMNOPQRSTVWXYZ";//"UEGMPTBFOARDC"; sizeCutoff = 1; densityCutoff=0; pCutoff=1.000001; ReadParameters(argc, argv); printf("Graph filename: %s\n",graphFilename); printf("Number of nodes: %d\n\n",numVerts = ReadClusteringNumber(graphFilename)); if(numVerts== -1){ fprintf(stderr,"Graph input error. File %s is nonexistent, unreadable, or not a valid graph file. QUITTING.\n",graphFilename); printUsageError(); return 0; } printf("Clustering filename: %s\n",clusteringFilename); printf("Number of clusters: %d\n\n",numClust = ReadClusteringNumber(clusteringFilename)); if(numClust == -1){ fprintf(stderr,"Clustering input error. File %s is nonexistent, unreadable, or not a valid clustering file. QUITTING.\n",clusteringFilename); printUsageError(); return 0; } //printf("Number of complexes: %d\n",numberOfComplexes = ReadClusteringNumber(complexFilename)); printf("Protein name filename: %s\n\n",nameFilename); NumFunctions = strlen(functionMapping); printf("%-3dfunctional groups: %s\n\n",NumFunctions, functionMapping); printf("Prediction cutoffs:\n Size >= %d.\n Density >= %-1.3f.\n P-value <= %-.1e.\n\n", sizeCutoff, densityCutoff, pCutoff); /* FIX COMPUTATION OF BEST P-VALUE. * WRITE THE REST OF THE CHAPTER.*/ //initialize the arrays. ComplexList = new SLList[numberOfComplexes]; proteinName = new std::string[numVerts]; Function = new char[numVerts]; FunctionNum = new int[numVerts]; FunctionSize = new int[NumFunctions]; GetProteinNames(nameFilename); whichCluster = new int[numVerts]; AlreadyCounted = new bool[numVerts]; ComplexSize = new int[numberOfComplexes]; numberMatched = new int[numberOfComplexes]; numClust = CountClusters(clusteringFilename); ClusterSize = new int[numClust]; ClusterDensity = new float[numClust]; ComplexDensity = new float[numberOfComplexes]; ClusterP = new double[numClust]; ComplexP = new double[numberOfComplexes]; ComplexPee = new double[numberOfComplexes]; ClusterFunction = new int[numClust]; ComplexFunction = new int[numberOfComplexes]; ClusterMatched = new bool[numClust]; ComplexMatched = new bool[numberOfComplexes]; ClusterSMatched = new bool[numClust]; ComplexSMatched = new bool[numberOfComplexes]; MainInComplex = new int[numberOfComplexes]; MainInCluster = new int[numClust]; UnknownInComplex = new int[numberOfComplexes]; UnknownInCluster = new int[numClust]; ComplexList = new SLList[numberOfComplexes]; MaxMatch = new int[numClust]; MaxMatchPct = new float[numClust]; MaxMatchWith = new int[numClust]; MaxMatchPctWith = new int[numClust]; for(int clust = 1; clust < numClust; clust++){ MaxMatch[clust]=0; MaxMatchPct[clust]=0; MaxMatchWith[clust]=0; MaxMatchPctWith[clust]=0; } ReadClustering(clusteringFilename); graph.SetNumClust(numClust); //printf("%d clusters....\n",(int) graph.NUM_CLUST); graph.MakeGraph(graphFilename); graph.CheckAdjList(); graph.FillAdjList(); graph.InitClustering(whichCluster); //graph.SetInitialNumAndDom(); //Matching criteria //ComplexCutoff=.7; ClusterCutoff=.7; //ComConCutoff=1.1; CluConCutoff=.9; //ReadComplexes(complexFilename); // GenVertexPermutation(graph.Order); //GetComplexP(); GetClusterP(); // Match(); GetStats(); //WriteData(outputFilename); printf("\n"); WriteVerbalData2(outputFilename); //printf("PARAMS: %d %f %f\n", sizeCutoff,densityCutoff, pCutoff); //WriteComposition(outputFilename); /* for(int clust=0; clust<numClust; clust++){ if(!ClusterMatched[clust]){ printf("Cluster %d unmatched. Tops are %d/%d with %d (size %d) and %f with %d (size %d).\n", clust, MaxMatch[clust], (int) graph.ClusterSize[clust], MaxMatchWith[clust], ComplexSize[MaxMatchWith[clust]], MaxMatchPct[clust], MaxMatchPctWith[clust], ComplexSize[MaxMatchPctWith[clust]]); } } */ return 0; }
//**************************************************************************** bool parseArgs (const int argc, const char* const argv[]) { unsigned int argumentIndex = 0; std::string argument; char argCharacter = '\0'; char selectedMode = '\0'; unsigned int key = 0; std::string input; std::string output; std::string inputFile; std::string outputFile; bool hasInput = false; bool hasOutputFile = false; bool hasInputFile = false; bool usageErrorOccured = false; if (argc <= 1) { usageErrorOccured = true; } else { argumentIndex = 1; } while (argumentIndex < static_cast<unsigned int> (argc) && !usageErrorOccured) { argument = argv[argumentIndex]; // Is the argument a flag? (-e, -d, etc.) if (argument.length () > 1 && argument[0] == '-') { argCharacter = argument[1]; switch (argCharacter) { case INPUT_FILENAME_ARG: argumentIndex++; if (argumentIndex < static_cast<unsigned int> (argc) && !hasInput && selectedMode != HELP_ARG) { inputFile = argv[argumentIndex]; hasInputFile = true; hasInput = true; } else { usageErrorOccured = true; } break; case OUTPUT_FILENAME_ARG: argumentIndex++; if (argumentIndex < static_cast<unsigned int> (argc) && !hasOutputFile && selectedMode != HELP_ARG) { outputFile = argv[argumentIndex]; hasOutputFile = true; } else { usageErrorOccured = true; } break; case INPUT_TEXT_ARG: argumentIndex++; if (argumentIndex < static_cast<unsigned int> (argc) && !hasInput && selectedMode != HELP_ARG) { input = argv[argumentIndex]; hasInput = true; } else { usageErrorOccured = true; } break; case ENCIPHER_ARG: case DECIPHER_ARG: // Assume that a mode has not been selected already and check for a valid key. // We do not break so that we roll into the next cases and check if our assumption // on the selected mode was right, if not we exit anyways. argumentIndex++; if (!((argumentIndex < static_cast<unsigned int> (argc)) && parseCStringAsKey (argv[argumentIndex], key))) { usageErrorOccured = true; break; } case CRACK_ARG: case BRUTE_FORCE_ARG: if (selectedMode == '\0') { selectedMode = argCharacter; break; } else { usageErrorOccured = true; } break; case HELP_ARG: if (selectedMode == '\0' && !hasInput && !hasOutputFile && !hasInputFile) { selectedMode = argCharacter; break; } else { usageErrorOccured = true; } break; default: usageErrorOccured = true; break; } } else { // Not enough arguments. usageErrorOccured = true; } argumentIndex++; } if (usageErrorOccured) { printUsageError (); return false; } if (hasInputFile) { if (!loadFileContents (inputFile, input)) { printFileLoadingError (inputFile); return false; } } switch (selectedMode) { case HELP_ARG: printHelp (); break; case ENCIPHER_ARG: output = encipherAndPrint (input, key); break; case DECIPHER_ARG: output = decipherAndPrint (input, key); break; case BRUTE_FORCE_ARG: output = bruteForceAndPrint (input); break; case CRACK_ARG: output = crackAndPrint (input); break; // Shouldn't happen. default: printUsageError (); break; } if (hasOutputFile) { if (!saveFile (outputFile, output)) { printFileSavingError (outputFile); return false; } } return true; }