int main(int argc, char *argv[]) /* Process command line. */ { char *command; bzpTime(NULL); dnaUtilOpen(); setMaxAlloc(2LL*1024LL*1024LL*1024LL); optionInit(&argc, argv, options); port = optionInt("port", port); host = optionVal("host", host); netParseSubnet(optionVal("subnet", NULL), subnet); cpuCount = optionInt("cpu", cpuCount); if (argc < 2) usage(); command = argv[1]; if (sameWord(command, "start")) { if (argc < 3) usage(); serverStart(argv+2, argc-2); } else if (sameWord(command, "stop")) { serverStop(); } else if (sameWord(command, "status")) { serverStatus(); } else usage(); return 0; }
void serverStart(char *files[], int fileCount) /* Load DNA. Build up indexes, set up listing port, and fall into * accept loop. */ { struct blatzIndex *indexList = NULL; int i; int acceptor; struct bzp *bzp = bzpDefault(); /* Daemonize self. */ bzpSetOptions(bzp); /* Load up all sequences. */ for (i=0; i<fileCount; ++i) { struct dnaLoad *dl = dnaLoadOpen(files[i]); struct blatzIndex *oneList = blatzIndexDl(dl, bzp->weight, bzp->unmask); indexList = slCat(indexList, oneList); dnaLoadClose(&dl); } bzpTime("Loaded and indexed %d sequences", slCount(indexList)); verbose(1, "Ready for queries\n"); /* Turn self into proper daemon. */ logDaemonize("blatzServer"); acceptor = netAcceptingSocket(port, 100); serviceLoop(acceptor, bzp, indexList); }
static void loadAndAlignAll(struct bzp *bzp, char *target, char *query, char *output) /* blatz - Align genomic dna across species. */ { struct dnaLoad *queryDl = dnaLoadOpen(query); struct dnaLoad *targetDl = dnaLoadOpen(target); struct blatzIndex *indexList = blatzIndexDl(targetDl, bzp->weight, bzp->unmask); bzpTime("loaded and indexed target DNA"); // LX BEG if (bzp->dynaWordCoverage > 0) { dynaNumWords = (pow(4,bzp->weight)); // ?? check with Jim if this is correct AllocArray(dynaWordCount,dynaNumWords); printf("Allocated word count table of size %d\n",dynaNumWords); dynaWordLimit = bzp->dynaWordCoverage; // cheating, should be more like: //dynaWordLimit = bzp->dynaWordCoverage*dynaSequenceSize/dynaNumWords; printf("Set word limit to %d\n",dynaWordLimit); } // LX END verbose(2, "Loaded %d in %s, opened %s\n", slCount(indexList), target, query); alignAll(bzp, indexList, queryDl, output); }
int main(int argc, char *argv[]) /* Process command line. */ { bzpTime(NULL); dnaUtilOpen(); optionInit(&argc, argv, options); port = optionInt("port", port); host = optionVal("host", host); if (argc != 3) usage(); blatzClient(argv[1], argv[2]); return 0; }
int main(int argc, char *argv[]) /* Process command line. */ { struct bzp *bzp = bzpDefault(); /* Do initialization. */ bzpTime(NULL); dnaUtilOpen(); optionInit(&argc, argv, options); if (argc != 4) usage(bzp); /* Fill in parameters from command line options. */ bzpSetOptions(bzp); loadAndAlignAll(bzp, argv[1], argv[2], argv[3]); /* If you were a turtle you'd be home right now. */ return 0; }
void queryResponse(int sd, struct bzp *bzp, struct blatzIndex *indexList) /* Respond to query message - read options and dna from socket, * and do alignment. */ { struct bzp lbzp = *bzp; struct dnaSeq *seq = NULL; char buf[256], *line, *word; char *out = NULL, *mafT = NULL, *mafQ = NULL; /* First get options - overriding what got set at startup. */ for (;;) { if ((line = netGetString(sd, buf)) == NULL) { truncatedQuery(1); return; } word = nextWord(&line); line = skipLeadingSpaces(line); if (sameString(word, "seq")) break; else if (sameString(word, "rna")) lbzp.rna = TRUE; else if (sameString(word, "minScore")) lbzp.minScore = atoi(line); else if (sameString(word, "minGapless")) lbzp.minGapless = atoi(line); else if (sameString(word, "multiHits")) lbzp.multiHits = atoi(line); else if (sameString(word, "minChain")) lbzp.minChain = atoi(line); else if (sameString(word, "maxExtend")) lbzp.maxExtend = atoi(line); else if (sameString(word, "maxBandGap")) lbzp.maxBandGap = atoi(line); else if (sameString(word, "minExpand")) lbzp.minExpand = atoi(line); else if (sameString(word, "expandWindow")) lbzp.expandWindow = atoi(line); else if (sameString(word, "out")) lbzp.out = out = cloneString(line); else if (sameString(word, "mafQ")) lbzp.mafQ = mafQ = cloneString(line); else if (sameString(word, "mafT")) lbzp.mafT = mafT = cloneString(line); } /* Get DNA into seq*/ { char *name = netGetString(sd, buf); char *dna; if (name == NULL) { truncatedQuery(2); return; } dna = netGetHugeString(sd); if (dna == NULL) { truncatedQuery(3); return; } AllocVar(seq); seq->dna = dna; seq->size = strlen(dna); seq->name = cloneString(name); bzpTime("Received %d bases in %s", seq->size, seq->name); if (lbzp.rna) maskTailPolyA(seq->dna, seq->size); } /* Create alignments into chainList and write results. */ { FILE *f = netFileFromSocket(sd); struct chain *chainList = blatzAlign(&lbzp, indexList, seq); blatzWriteChains(&lbzp, &chainList, seq, 0, seq->size, seq->size, indexList, f); bzpTime("sent result - %d chains", slCount(chainList)); carefulClose(&f); } dnaSeqFree(&seq); freez(&out); freez(&mafQ); freez(&mafT); }
void serviceLoop(int acceptor, struct bzp *bzp, struct blatzIndex *indexList) /* Wait for requests on acceptor socket. */ { for (;;) { int sd; char buf[256]; char *command; /* Wait for previous processes */ { int options = 0; int w, status; for (;;) { if (cpusUsed < cpuCount) options = WNOHANG; w = waitpid(-1, &status, options); if (w > 0) { --cpusUsed; if (!WIFEXITED(status)) ++crashCount; else if (WEXITSTATUS(status) != 0) ++badQueryCount; else ++goodQueryCount; } else break; } } sd = netAcceptFrom(acceptor, subnet); bzpTime("Since last query"); command = netGetString(sd, buf); if (command != NULL) { verbose(2, "servicing %s\n", command); if (sameString(command, "stop")) break; else { int pid; ++cpusUsed; pid = mustFork(); if (pid == 0) { if (command != NULL) { if (sameString(command, "status")) statusResponse(sd, bzp, indexList); else if (sameString(command, "query")) queryResponse(sd, bzp, indexList); } exit(0); } } } close(sd); } }