| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <new> |
| 4 | #include "searchGENOME.H" |
| 5 | |
| 6 | configuration config; |
| 7 | |
| 8 | |
| 9 | void *loaderThread(void *U); |
| 10 | void searchThread(void *U, void *T, void *Q); |
| 11 | void writerThread(void *U, void *Q); |
| 12 | |
| 13 | |
| 14 | |
| 15 | int |
| 16 | main(int argc, char **argv) { |
| 17 | |
| 18 | // Read the configuration from the command line |
| 19 | // |
| 20 | config.read(argc, argv); |
| 21 | |
| 22 | // Open and init the query sequence |
| 23 | // |
| 24 | if (config._beVerbose) |
| 25 | fprintf(stderr, "Opening the cDNA sequences.\n"); |
| 26 | |
| 27 | config._qsFASTA = new seqCache(config._qsFileName); |
| 28 | config._dbSTREAM = new seqStream(config._dbFileName); |
| 29 | |
| 30 | // Complete the configuration |
| 31 | // |
| 32 | config._initTime = getTime(); |
| 33 | |
| 34 | |
| 35 | // |
| 36 | // Build the positions |
| 37 | // |
| 38 | |
| 39 | // Read in the positionDB if it's already built, or build a new one. |
| 40 | // |
| 41 | if ((config._tableFileName) && (fileExists(config._tableFileName))) { |
| 42 | if (config._tableBuildOnly) { |
| 43 | fprintf(stderr, "All done. Table '%s' already built.\n", config._tableFileName); |
| 44 | exit(1); |
| 45 | } else { |
| 46 | fprintf(stderr, "Loading positionDB state from '%s'\n", config._tableFileName); |
| 47 | config._positions = new positionDB(config._tableFileName, config._merSize, config._merSkip, 0); |
| 48 | } |
| 49 | } else { |
| 50 | merStream *MS = new merStream(new kMerBuilder(config._merSize), |
| 51 | config._dbSTREAM, |
| 52 | true, false); |
| 53 | config._positions = new positionDB(MS, config._merSize, config._merSkip, 0L, 0L, 0L, 0, 0, 0, 0, config._beVerbose); |
| 54 | delete MS; |
| 55 | |
| 56 | if (config._tableFileName) { |
| 57 | if (config._beVerbose) |
| 58 | fprintf(stderr, "Dumping positions table to '%s'\n", config._tableFileName); |
| 59 | |
| 60 | config._positions->saveState(config._tableFileName); |
| 61 | |
| 62 | if (config._tableBuildOnly) |
| 63 | exit(0); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Build the masking database. |
| 68 | // |
| 69 | // Previous versions build the existDB takeing the posDB as a |
| 70 | // parameter. The existDB would then be exclude mers not in the |
| 71 | // posDB. A neat and nice feature, but with only 45,000 to 70,000 |
| 72 | // mers in the masks, hardly worth the effort. |
| 73 | // |
| 74 | if (config._maskFileName) { |
| 75 | if (config._beVerbose) |
| 76 | fprintf(stderr, "Building maskDB from '%s'\n", config._maskFileName); |
| 77 | config._maskDB = new existDB(config._maskFileName, config._merSize, existDBnoFlags, 0, ~uint32ZERO); |
| 78 | } |
| 79 | |
| 80 | if (config._onlyFileName) { |
| 81 | if (config._beVerbose) |
| 82 | fprintf(stderr, "Building onlyDB from '%s'\n", config._onlyFileName); |
| 83 | config._onlyDB = new existDB(config._onlyFileName, config._merSize, existDBnoFlags, 0, ~uint32ZERO); |
| 84 | } |
| 85 | |
| 86 | config._buildTime = getTime(); |
| 87 | |
| 88 | #if 0 |
| 89 | // Maybe we don't need this anymore! |
| 90 | #ifdef __alpha |
| 91 | // Start the deadlock detection threads |
| 92 | // |
| 93 | fprintf(stderr, "Deadlock detection enabled!\n"); |
| 94 | pthread_create(&threadID, &threadAttr, deadlockDetector, 0L); |
| 95 | pthread_create(&threadID, &threadAttr, deadlockChecker, 0L); |
| 96 | #endif |
| 97 | #endif |
| 98 | |
| 99 | sweatShop *ss = new sweatShop(loaderThread, |
| 100 | searchThread, |
| 101 | writerThread); |
| 102 | |
| 103 | ss->setNumberOfWorkers(config._numSearchThreads); |
| 104 | |
| 105 | for (uint32 i=0; i<config._numSearchThreads; i++) |
| 106 | ss->setThreadData(i, new searcherState); |
| 107 | |
| 108 | ss->setLoaderQueueSize(config._loaderQueue); |
| 109 | ss->setWriterQueueSize(config._writerQueue); |
| 110 | |
| 111 | ss->run(0L, config._beVerbose); |
| 112 | |
| 113 | config._searchTime = getTime(); |
| 114 | |
| 115 | // the configuration does most cleanup, and it's on the stack. |
| 116 | |
| 117 | return(0); |
| 118 | } |
| 119 |