int _tcsicmp(LPCTSTR a, LPCTSTR b){ wxChar aa[501] = {0}; wxChar bb[501] = {0}; int ret; strncpy(aa, a, 500); strncpy(bb, b, 500); tolowers(aa); tolowers(bb); ret = strcmp(aa, bb); return ret; }
int CmdPutInto::execute() { int turns = 0; ActorPtr target = SingleNeighbourSelector("Select a container to put into...") .select() .firstActor(); if ( target != nullptr && target->hasFeature<Inventory>()) { OpenablePtr openable = target->getFeature<Openable>(); if ( openable && openable->isClosed() ) { gui::msgBox("Cannot put into " + target->getName() + " - it is closed.", gui::MsgType::Warning); } else { auto afterPutIntoAction = [&](const std::string& item, int amount) { target->notify(Event(EventId::Actor_Put,{{"putter","Player"}, {"container",target->getName()}, {"count", std::to_string(amount)}, {"item", tolowers(item)}})); }; auto containerFullAction = [&target](const std::string& item) { gui::msgBox("Cannot put "+item+" into "+tolowers(target->getName())+":#Not enough space!", gui::MsgType::Error); }; Engine::instance().getWindowManager() .getWindow<gui::PickUpWindow>() .setPicker(target) .setSource( [](){ return Engine::instance().getPlayer()->getFeature<Inventory>()->items(); }) .setRemoveAction([&](ActorPtr a){Engine::instance().getPlayer()->getFeature<Inventory>()->remove(a);}) .setAfterPickupAction( afterPutIntoAction ) .setInventoryFullAction( containerFullAction ) .setWindowTitle("Select item to put") .show(); } ++turns; } else if ( target ) { gui::msgBox("You cannot put anything into "+tolowers(target->getName())+".", gui::MsgType::Error); } return turns; }
void CmdClose::execute() { Target target = SingleNeighbourSelector("Select object to close...") .select(); auto openableIter = std::find_if(target.actors.begin(), target.actors.end(), [](ActorPtr a) { return a->getFeature<Openable>(); }); ActorPtr toClose = openableIter != target.actors.end() ? *openableIter : nullptr; if ( toClose != nullptr) { if ( target.actors.size() == 1 ) { Actor::Player->performAction( std::make_shared<CloseAction>(toClose) ); } else { gui::msgBox("Cannot close " + tolowers(toClose->getName())+":\n" "It is blocked!", gui::MsgType::Warning); } } else { gui::msgBox("Nothing to close there.", gui::MsgType::Warning); } }
void initTitleHelper(struct titleHelper *th, char *track, int startIx, int centerIx, int endIx, int nRecords, struct vcfFile *vcff) /* Set up info including arrays of ref & alt alleles for cluster mouseover. */ { th->track = track; th->startIx = startIx; th->centerIx = centerIx; th->endIx = endIx; th->nRecords = nRecords; int len = endIx - startIx; AllocArray(th->refs, len); AllocArray(th->alts, len); struct vcfRecord *rec; int i; for (rec = vcff->records, i = 0; rec != NULL && i < endIx; rec = rec->next, i++) { if (i < startIx) continue; char refAl[16]; abbrevAndHandleRC(refAl, sizeof(refAl), rec->alleles[0]); th->refs[i-startIx] = vcfFilePooledStr(vcff, refAl); char altAl1[16]; abbrevAndHandleRC(altAl1, sizeof(altAl1), rec->alleles[1]); tolowers(altAl1); th->alts[i-startIx] = vcfFilePooledStr(vcff, altAl1); } }
static void visiGeneMatchDescription(struct visiSearcher *searcher, struct sqlConnection *conn, struct slName *wordList) /* Fold in matches to description - using full text index. */ { struct trix *trix = NULL; struct slName *word; int wordIx; if (!fileExists("visiGeneData/visiGene.ix")) { safef(titleMessage,sizeof(titleMessage), " - visiGene.ix not found, run vgGetText"); fprintf(stderr,"%s\n",titleMessage); return; } trix = trixOpen("visiGeneData/visiGene.ix"); for (word=wordList, wordIx=0; word != NULL; word = word->next, ++wordIx) { char *s = cloneString(word->name); struct trixSearchResult *tsr, *tsrList; tolowers(s); tsrList = trixSearch(trix, 1, &s, FALSE); for (tsr = tsrList; tsr != NULL; tsr = tsr->next) visiSearcherAdd(searcher, sqlUnsigned(tsr->itemId), 1.0, wordIx, 1); trixSearchResultFreeList(&tsrList); freez(&s); } trixClose(&trix); }
static void simpleMultiFillInSequence(boolean preserveCase, char *seqFile, struct agpFrag *agpList, DNA *dna, int dnaSize) /* Fill in DNA array with sequences from one multi-record fasta file. */ { static struct hash *fragHash = NULL; struct agpFrag *agp = NULL; struct dnaSeq *seq = NULL; int illegals = 0; if (fragHash == NULL) { struct lineFile *lf = lineFileOpen(seqFile, TRUE); struct dnaSeq *seqList = faReadAllMixedInLf(lf); fragHash = newHash(17); for (seq = seqList; seq != NULL; seq = seq->next) { if (!preserveCase) tolowers(seq->dna); hashAdd(fragHash, seq->name, seq); } lineFileClose(&lf); } for (agp = agpList; agp != NULL; agp = agp->next) { int size; seq = hashFindVal(fragHash, agp->frag); if (seq == NULL) errAbort("Couldn't find %s in %s", agp->frag, seqFile); size = agp->fragEnd - agp->fragStart; if (agp->strand[0] == '-') reverseComplement(seq->dna + agp->fragStart, size); verbose(3, "dna: %lu, start: %u, size: %d, seqDna: %lu, start: %u, " "size: %d %s %d\n", (unsigned long) dna, agp->chromStart, dnaSize, (unsigned long) seq->dna, agp->fragStart, size, agp->frag, seq->size); if ((agp->chromStart + size) > dnaSize) { warn("frag size %d + dest chromStart %u = %d > %d dest dna size\n", size, agp->chromStart, size+agp->chromStart, dnaSize); errAbort("fragment copy size exceeds destination dna size"); } if ((agp->fragStart + size) > seq->size) { verbose(2, "#\t%s start:%u end:%u seqSize: %d\n", agp->frag, agp->fragStart, agp->fragEnd, seq->size); ++illegals; } else memcpy(dna + agp->chromStart, seq->dna + agp->fragStart, size); } if (illegals > 0) { warn("%d illegal coordinates found in agp files.\n", illegals); warn("sequence file: %s\n", seqFile); errAbort("Fragment copy is more than available fragment sequence."); } }
static void mafLowerCase(struct mafAli *maf) /* Lower case letters in maf. */ { struct mafComp *mc; for (mc = maf->components; mc != NULL; mc = mc->next) if (mc->size != 0) tolowers(mc->text); }
void doMiddle() { char *preIntron, *startIntron, *endIntron, *postIntron; int count = 0; int matchCount = 0; int maxCount; struct nameOff *matchList; boolean invert = cgiVarExists("Invert"); preIntron = cgiString("preIntron"); startIntron = cgiString("startIntron"); endIntron = cgiString("endIntron"); postIntron = cgiString("postIntron"); /* Just for debugging cut search short if matches special magic */ maxCount = atoi(preIntron); if (maxCount <= 0) maxCount = 0x7ffffff; eraseWhiteSpace(preIntron); eraseWhiteSpace(startIntron); eraseWhiteSpace(endIntron); eraseWhiteSpace(postIntron); tolowers(preIntron); tolowers(startIntron); tolowers(endIntron); tolowers(postIntron); matchList = scanIntronFile(preIntron, startIntron, endIntron, postIntron, invert); if (matchList == NULL) errAbort("Sorry, no matches to %s%s %s %s %s", (invert ? "inverted " : ""), preIntron, startIntron, endIntron, postIntron); printf("<P>%d introns matching %s%s(%s %s)%s. ", slCount(matchList), (invert ? "inverted " : ""), preIntron, startIntron, endIntron, postIntron); printf("Shortcut to <A HREF=\"#1\">frequency counts.</A></P>"); htmlHorizontalLine(); showMatches(matchList); htmlHorizontalLine(); printf("<TT><PRE>"); printf("<A NAME=\"1\"></A>"); printAllHistograms(); printf("</TT></PRE>"); }
LPCTSTR StrStrI(LPCTSTR a, LPCTSTR b){ wxChar aa[501] = {0}; wxChar bb[501] = {0}; LPCTSTR ret; strncpy(aa, a, 500); strncpy(bb, b, 500); tolowers(aa); tolowers(bb); ret = strstr(aa, bb); if (ret != NULL) { ret = (LPCTSTR)(ret - aa + a); } return ret; }
boolean wormFixupOrfName(char *name) /* Turn something into a proper cosmid.# style name. Return FALSE if it can't be done. */ { char *dot = strrchr(name, '.'); if (dot == NULL) return FALSE; toUpperN(name, dot-name); /* First part always upper case. */ if (!isdigit(dot[1])) /* Nameless cluster - just leave following digits be. */ return TRUE; else tolowers(dot+1); /* Suffix is lower case. */ return TRUE; }
char *chromFromPath(char *path) /* Extract chromosome name from path */ { static char chromosome[128]; char dir[256], name[128], extension[64]; char *s; splitPath(path, dir, name, extension); s = strchr(name, '.'); if (s != NULL) *s = 0; s = cloneString(name); tolowers(s); return s; }
void CmdPutInto::execute() { ActorPtr target = SingleNeighbourSelector("Select a container to put into...") .select() .firstActor(); if ( target != nullptr && target->hasFeature<Container>()) { auto afterPutIntoAction = [&](const std::string& item, int amount) { Messenger::message()->actorPutInto(Actor::Player->getName(), target->getName(), item, amount); }; auto containerFullAction = [&target](const std::string& item) { gui::msgBox("Cannot put "+item+" into "+tolowers(target->getName())+":\nNot enough space!", gui::MsgType::Error); }; Engine::instance().windowManager() .getWindow<gui::PickUpWindow>() .setPicker(target) .setContainer(Actor::Player->getFeature<Container>()) .setAfterPickupAction( afterPutIntoAction ) .setInventoryFullAction( containerFullAction ) .setWindowTitle("Select item to put") .show(); } else if ( target ) { gui::msgBox("You cannot put anything into "+tolowers(target->getName())+".", gui::MsgType::Error); } }
void ccdsStatusValCheck(struct hash *statusVals, char *stat) /* check if a status value is valid, in a case-insensitive manner */ { char statLower[64]; boolean isValid = (strlen(stat) < sizeof(statLower)); if (isValid) { strcpy(statLower, stat); tolowers(statLower); isValid = (hashLookup(statusVals, statLower) != NULL); } if (!isValid) errAbort("unknown CCDS status: \"%s\"", stat); }
char *oligoMatchSeq(char *s) /* Return sequence for oligo matching. */ { if (s != NULL) { int len; tolowers(s); iupacFilter(s, s); len = strlen(s); if (len < 2) s = NULL; } if (s == NULL) s = cloneString(oligoMatchDefault); return s; }
void cdwValidateTagName(char *tag) /* Make sure that tag is one of the allowed ones. */ { char *geoPrefix = "GEO_"; // If it's not a legal C symbol, don't let it be a tag if (!isSymbolString(tag)) errAbort("Bad tag symbol %s.", tag); // First see if it is in hash of allowed tags. struct hash *allowedHash = cdwAllowedTagsHash(); if (hashLookup(allowedHash, tag) != NULL) return; // Otherwise see if it's one of the prefixes that allows anything afterwords else if (startsWith("lab_", tag) || startsWith("user_", tag) ) { return; } else if (startsWith(geoPrefix, tag) || startsWith("SRA_", tag)) { // Generally just pass GEO_ and SRA_ tags through, but do check that // the case is what we expect to avoid duplicate symbol conflicts between // differently cased versions of GEO_ tags in particular. // We have a couple of built-in geo_ tags for the major GEO database identifiers. int tagLen = strlen(tag); char lowerTag[tagLen+1]; strcpy(lowerTag, tag); tolowers(lowerTag); if (hashLookup(allowedHash, lowerTag)) errAbort("Please change %s tag to %s", tag, lowerTag); // This will detect a misguided attempt to change case on bits after GEO_ that // bit us once. int geoPrefixSize = strlen(geoPrefix); if (!isupper(tag[geoPrefixSize])) errAbort("Looks like %s has been altered, expecting upper case letter after GEO_.", tag); return; } // Otherwise see if it's one of our reserved but unimplemented things else if (sameString("mixin", tag) || sameString("deprecated", tag) || sameString("deprecated_acc", tag) || sameString("children", tag) || sameString("replaces_reason", tag) || sameString("replaces_file", tag)) { errAbort("%s not implemented", tag); } // Otherwise, nope, doesn't validate. errAbort("Unknown tag '%s'", tag); }
static struct slName *expTissuesForProbeInImage(struct sqlConnection *conn, int imageId, int probeId) /* Get list of tissue where we have expression info in gene. * Put + or - depending on expression level. */ { struct dyString *dy = dyStringNew(0); struct slName *tissueList = NULL, *tissue; char query[512], **row; struct sqlResult *sr; safef(query, sizeof(query), "select bodyPart.name,expressionLevel.level,expressionPattern.description " "from expressionLevel join bodyPart join imageProbe " "left join expressionPattern on expressionLevel.expressionPattern = expressionPattern.id " "where imageProbe.image = %d " "and imageProbe.probe = %d " "and imageProbe.id = expressionLevel.imageProbe " "and expressionLevel.bodyPart = bodyPart.id " "order by bodyPart.name" , imageId, probeId); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { double level = atof(row[1]); char *pattern = row[2]; if (pattern) tolowers(pattern); dyStringClear(dy); dyStringAppend(dy, row[0]); if (level == 1.0) dyStringAppend(dy, "(+)"); else if (level == 0.0) dyStringAppend(dy, "(-)"); else dyStringPrintf(dy, "(%.2f)",level); if (pattern && !sameWord(pattern,"Not Applicable") && !sameWord(pattern,"Not Specified")) dyStringPrintf(dy, " %s",pattern); tissue = slNameNew(dy->string); slAddHead(&tissueList, tissue); } sqlFreeResult(&sr); slReverse(&tissueList); dyStringFree(&dy); return tissueList; }
static struct dnaSeq *seqReaderTblGet(struct seqReader *seqReader, char *seqName, int start, int end, int *retFullSeqSize) /* get a sequence from the seqTbl */ { struct dnaSeq *fullSeq = hashFindVal(seqReader->seqTbl, seqName); if (fullSeq == NULL) errAbort("can't find sequence %s in %s", seqName, seqReader->spec); if (end > fullSeq->size) errAbort("range %d-%d longer than sequence %s length %d in %s", start, end, seqName, fullSeq->size, seqReader->spec); if (retFullSeqSize != NULL) *retFullSeqSize = fullSeq->size; int len = (end-start); struct dnaSeq *seq = newDnaSeq(cloneStringZ(fullSeq->dna+start, len), len, seqName); if (!gMasked) tolowers(seq->dna); return seq; }
int unhex(char *s) /* Return hex val of s. */ { int acc = 0; char c; tolowers(s); while ((c = *s++) != 0) { acc <<= 4; if (c >= '0' && c <= '9') acc += c - '0'; else if (c >= 'a' && c <= 'f') acc += c + 10 - 'a'; else errAbort("Expecting hexadecimal character got %s", s); } return acc; }
struct hash *ccdsStatusValLoad(struct sqlConnection *conn) /* load values from the imported ccdsStatusVals table. Table hashes * status name to uid. Names are loaded both as-is and lower-case */ { struct hash *statusVals = hashNew(0); struct sqlResult *sr = sqlGetResult(conn, "NOSQLINJ SELECT ccds_status_val_uid, ccds_status FROM CcdsStatusVals"); char **row; while ((row = sqlNextRow(sr)) != NULL) { int uid = sqlSigned(row[0]); char *stat = row[1]; hashAddInt(statusVals, stat, uid); tolowers(stat); hashAddInt(statusVals, stat, uid); } sqlFreeResult(&sr); return statusVals; }
struct hash *loadGeno(char *genoFile) /* load genome sequences into a hash. This supports the multi-sequence * specs of twoBitLoadAll */ { struct dnaSeq *genos = NULL, *geno; struct hash *genoHash = hashNew(0); if (nibIsFile(genoFile)) genos = nibLoadAllMasked(NIB_MASK_MIXED|NIB_BASE_NAME, genoFile); else if (twoBitIsSpec(genoFile)) genos = twoBitLoadAll(genoFile); else genos = faReadDna(genoFile); while ((geno = slPopHead(&genos)) != NULL) { tolowers(geno->dna); hashAdd(genoHash, geno->name, geno); } return genoHash; }
static struct aHubMatch *searchPublicHubs(struct dbDb *dbDbList, char *term) /* Search for term in public hub trix files -- return a list of matches to assembly hubs * (i.e. hubs that host an assembly with 2bit etc as opposed to only providing tracks.) */ { struct aHubMatch *aHubMatchList = NULL; char *trixFile = cfgOptionEnvDefault("HUBSEARCHTRIXFILE", "hubSearchTrixFile", hReplaceGbdb("/gbdb/hubs/public.ix")); if (fileExists(trixFile)) { struct trix *trix = trixOpen(trixFile); char termCopy[strlen(term)+1]; safecpy(termCopy, sizeof(termCopy), term); tolowers(termCopy); char *words[512]; int wordCount = chopByWhite(termCopy, words, ArraySize(words)); struct trixSearchResult *tsrList = trixSearch(trix, wordCount, words, tsmFirstFive); aHubMatchList = filterTrixSearchMatches(dbDbList, tsrList); trixClose(&trix); } return aHubMatchList; }
struct visiMatch *visiSearch(struct sqlConnection *conn, char *searchString) /* visiSearch - return list of images that match searchString sorted * by how well they match. This will search most fields in the * database. */ { char *dupe = cloneString(searchString); struct trix *trix = trixOpen("visiGeneData/visiGene.ix"); struct trixSearchResult *tsrList, *tsr; struct visiMatch *matchList = NULL, *match; int wordCount = chopByWhite(dupe, NULL, 0); char **words; boolean hasWild; struct hash *privateHash = makePrivateHash(conn); tolowers(dupe); hasWild = (strchr(searchString, '*') != NULL); if (hasWild) stripChar(dupe, '*'); AllocArray(words, wordCount); chopByWhite(dupe, words, wordCount); /* if (wordCount != 1 || (matchList = matchGeneName(conn, words[0],privateHash)) == NULL) */ { tsrList = trixSearch(trix, wordCount, words, hasWild); for (tsr = tsrList; tsr != NULL; tsr = tsr->next) { if (!isPrivate(conn, privateHash, tsr->itemId)) { AllocVar(match); match->imageId = sqlUnsigned(tsr->itemId); slAddHead(&matchList, match); } } trixSearchResultFreeList(&tsrList); trixClose(&trix); slReverse(&matchList); } freeMem(dupe); return matchList; }
static int hexToDecimal(char *hexString) /* return decimal value for hex string (from utils/subChar/subChar.c) */ { int acc = 0; char c; tolowers(hexString); stripChar(hexString, '#'); /* can start with # (as in html) */ while ((c = *hexString++) != 0) { acc <<= 4; if (c >= '0' && c <= '9') acc += c - '0'; else if (c >= 'a' && c <= 'f') acc += c + 10 - 'a'; /* ignoring bad characters else errAbort("Expecting hexadecimal character got %s", hexString); */ } return acc; }
struct slName *wormGeneToOrfNames(char *name) /* Returns list of cosmid.N type ORF names that are known by abc-12 type name. */ { struct slName *synList = NULL; char synFileName[512]; FILE *synFile; char lineBuf[128]; int nameLen = strlen(name); /* genes are supposed to be lower case. */ tolowers(name); /* Open synonym file and loop through each line of it */ sprintf(synFileName, "%ssyn", wormFeaturesDir()); if ((synFile = fopen(synFileName, "r")) == NULL) errAbort("Can't find synonym file '%s'. (errno: %d)\n", synFileName, errno); while (fgets(lineBuf, ArraySize(lineBuf), synFile)) { /* If first part of line matches chop up line. */ if (strncmp(name, lineBuf, nameLen) == 0) { char *syns[32]; int count; count = chopString(lineBuf, whiteSpaceChopper, syns, ArraySize(syns)); /* Looks like we got a synonym. Add all the aliases. */ if (strcmp(name, syns[0]) == 0) { int i; for (i=1; i<count; ++i) slAddTail(&synList, newSlName(syns[i])); break; } } } fclose(synFile); return synList; }
static void setupOutputFiles(char *acc, char *org) /* Get the output files (in globals) for a sequence, opening as needed. */ { if (gByAccPrefixSize > 0) { char accPrefix[32]; strncpy(accPrefix, acc, gByAccPrefixSize); accPrefix[gByAccPrefixSize] = '\0'; tolowers(accPrefix); if (!sameString(accPrefix, gCurAccPrefix)) openByAccPrefix(accPrefix); } else { /* output to a single set of files */ if (raFile == NULL) { raFile = mustOpen(raName, "w"); faFile = gbFaOpen(faName, "w"); if (gbIdxName != NULL) gbIdxFile = mustOpen(gbIdxName, "w"); } } }
struct bed *oligoMatch(struct dnaSeq *target, struct dnaSeq *query) /* Create list of perfect matches to oligo on either strand. */ { char *dna = target->dna; char *fOligo = oligoMatchSeq(query->dna); char *(*finder)(char *needle, char *haystack) = (anyIupac(fOligo) ? iupacIn : stringInWrapper); int oligoSize = strlen(fOligo); char *rOligo = cloneString(fOligo); char *rMatch = NULL, *fMatch = NULL; struct bed *bedList = NULL, *bed; char strand; int count = 0; tolowers(dna); if (oligoSize >= 2) { fMatch = finder(fOligo, dna); iupacReverseComplement(rOligo, oligoSize); if (sameString(rOligo, fOligo)) rOligo = NULL; else rMatch = finder(rOligo, dna); for (;;) { char *oneMatch = NULL; if (rMatch == NULL) { if (fMatch == NULL) break; else { oneMatch = fMatch; fMatch = finder(fOligo, fMatch+1); strand = '+'; } } else if (fMatch == NULL) { oneMatch = rMatch; rMatch = finder(rOligo, rMatch+1); strand = '-'; } else if (rMatch < fMatch) { oneMatch = rMatch; rMatch = finder(rOligo, rMatch+1); strand = '-'; } else { oneMatch = fMatch; fMatch = finder(fOligo, fMatch+1); strand = '+'; } ++count; AllocVar(bed); bed->chrom = cloneString(target->name); bed->chromStart = oneMatch - dna; bed->chromEnd = bed->chromStart + oligoSize; bed->strand[0] = strand; bed->name = oligoMatchName(bed, query->name); slAddHead(&bedList, bed); } slReverse(&bedList); } return bedList; }
void doMiddle() { char *seqName; boolean intronsLowerCase = TRUE; boolean intronsParenthesized = FALSE; boolean hiliteNear = FALSE; int startRange = 0; int endRange = 0; boolean gotRange = FALSE; struct dnaSeq *cdnaSeq; boolean isChromRange = FALSE; DNA *dna; char *translation = NULL; seqName = cgiString("geneName"); seqName = trimSpaces(seqName); if (cgiVarExists("intronsLowerCase")) intronsLowerCase = cgiBoolean("intronsLowerCase"); if (cgiVarExists("intronsParenthesized")) intronsParenthesized = cgiBoolean("intronsParenthesized"); if (cgiVarExists("startRange") && cgiVarExists("endRange" )) { startRange = cgiInt("startRange"); endRange = cgiInt("endRange"); gotRange = TRUE; } if (cgiVarExists("hiliteNear")) { hiliteNear = TRUE; } fprintf(stdout, "<P><TT>\n"); /* The logic here is a little complex to optimize speed. * If we can decide what type of thing the name refers to by * simply looking at the name we do. Otherwise we have to * search the database in various ways until we get a hit. */ if (wormIsNamelessCluster(seqName)) { isChromRange = TRUE; } else if (wormIsChromRange(seqName)) { isChromRange = TRUE; } else if (getWormGeneDna(seqName, &dna, TRUE)) { if (cgiBoolean("litLink")) { char nameBuf[64]; char *geneName = NULL; char *productName = NULL; char *coding; int transSize; struct wormCdnaInfo info; printf("<H3>Information and Links for %s</H3>\n", seqName); if (wormInfoForGene(seqName, &info)) { if (info.description) printf("<P>%s</P>\n", info.description); geneName = info.gene; productName = info.product; } else { if (wormIsGeneName(seqName)) geneName = seqName; else if (wormGeneForOrf(seqName, nameBuf, sizeof(nameBuf))) geneName = nameBuf; } coding = cloneUpperOnly(dna); transSize = 1 + (strlen(coding)+2)/3; translation = needMem(1+strlen(coding)/3); dnaTranslateSome(coding, translation, transSize); freez(&coding); if (geneName) { printf("<A HREF=\"http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query?form=4&db=m" "&term=C+elegans+%s&dispmax=50&relentrezdate=No+Limit\">", geneName); printf("PubMed search on gene: </A>%s<BR>\n", geneName); } if (productName) { char *encoded = cgiEncode(productName); printf("<A HREF=\"http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query?form=4&db=m" "&term=%s&dispmax=50&relentrezdate=No+Limit\">", encoded); printf("PubMed search on product:</A> %s<BR>\n", productName); freeMem(encoded); } /* Process name to get rid of isoform letter for Proteome. */ if (geneName) strcpy(nameBuf, geneName); else { strcpy(nameBuf, seqName); #ifdef NEVER /* Sometimes Proteome requires the letter after the orf name * in alt-spliced cases, sometimes it can't handle it.... */ nameLen = strlen(nameBuf); if (wormIsOrfName(nameBuf) && isalpha(nameBuf[nameLen-1])) { char *dotPos = strrchr(nameBuf, '.'); if (dotPos != NULL && isdigit(dotPos[1])) nameBuf[nameLen-1] = 0; } #endif /* NEVER */ } printf("<A HREF=\"http://www.wormbase.org/db/seq/sequence?name=%s;class=Sequence\">", seqName); printf("WormBase link on:</A> %s<BR>\n", seqName); printf("<A HREF=\"http://www.proteome.com/databases/WormPD/reports/%s.html\">", nameBuf); printf("Proteome link on:</A> %s<BR>\n<BR>\n", nameBuf); printf("<A HREF=#DNA>Genomic DNA Sequence</A><BR>\n"); if (hiliteNear) printf("<A HREF=\"#CLICKED\">Shortcut to where you clicked in gene</A><BR>"); printf("<A HREF=#protein>Translated Protein Sequence</A><BR>\n"); htmlHorizontalLine(); printf("<A NAME=DNA></A>"); printf("<H3>%s Genomic DNA sequence</H3>", seqName); } if (!intronsLowerCase) tolowers(dna); if (hiliteNear) { if (!gotRange) { double nearPos = cgiDouble("hiliteNear"); int rad = 5; int dnaSize = strlen(dna); long mid = (int)(dnaSize * nearPos); startRange = mid - rad; if (startRange < 0) startRange = 0; endRange = mid + rad; if (endRange >= dnaSize) endRange = dnaSize - 1; } } outputSeq(dna, strlen(dna), hiliteNear, startRange, endRange, stdout); freez(&dna); } else if (wormCdnaSeq(seqName, &cdnaSeq, NULL)) { outputSeq(cdnaSeq->dna, cdnaSeq->size, FALSE, 0, 0, stdout); } else { isChromRange = TRUE; } if (isChromRange) { char *chromId; int start, end; char strand = '+'; int size; if (!wormGeneRange(seqName, &chromId, &strand, &start, &end)) errAbort("Can't find %s",seqName); size = end - start; if (intronsLowerCase) dna = wormChromPartExonsUpper(chromId, start, size); else { dna = wormChromPart(chromId, start, size); touppers(dna); } if (cgiVarExists("strand")) strand = cgiString("strand")[0]; if (strand == '-') reverseComplement(dna, size); outputSeq(dna, size, FALSE, 0, 0, stdout); } if (translation != NULL) { htmlHorizontalLine(); printf("<A NAME=protein></A>"); printf("<H3>Translated Protein of %s</H3>\n", seqName); outputSeq(translation, strlen(translation), FALSE, 0, 0, stdout); freez(&translation); } fprintf(stdout, "</TT></P>\n"); }
boolean checkWigDataFilter(char *db, char *table, char **constraint, double *ll, double *ul) /* check if filter exists, return its values, call with db="ct" for * custom tracks */ { char varPrefix[128]; struct hashEl *varList, *var; char *pat = NULL; char *cmp = NULL; if (constraint != NULL) *constraint = NULL; // Make sure return variable gets set to something at least. if (isCustomTrack(table)) db = "ct"; safef(varPrefix, sizeof(varPrefix), "%s%s.%s.", hgtaFilterVarPrefix, db, table); varList = cartFindPrefix(cart, varPrefix); if (varList == NULL) return FALSE; /* check varList, look for dataValue.pat and dataValue.cmp */ for (var = varList; var != NULL; var = var->next) { if (endsWith(var->name, ".pat")) { char *name; name = cloneString(var->name); tolowers(name); /* make sure we are actually looking at datavalue */ if (stringIn("datavalue", name) || stringIn("score", name)) { pat = cloneString(var->val); } freeMem(name); } if (endsWith(var->name, ".cmp")) { char *name; name = cloneString(var->name); tolowers(name); /* make sure we are actually looking at datavalue */ if (stringIn("datavalue", name) || stringIn("score", name)) { cmp = cloneString(var->val); tolowers(cmp); if (stringIn("ignored", cmp)) freez(&cmp); } freeMem(name); } } /* Must get them both for this to work */ if (cmp && pat) { int wordCount = 0; char *words[2]; char *dupe = cloneString(pat); wordCount = chopString(dupe, ", \t\n", words, ArraySize(words)); switch (wordCount) { case 2: if (ul) *ul = sqlDouble(words[1]); case 1: if (ll) *ll = sqlDouble(words[0]); break; default: warn("dataValue filter must be one or two numbers (two for 'in range'). " "Please click the filter edit button and either set the comparison to 'ignored' " "or set the dataValue threshold."); } if (sameWord(cmp,"in range") && (wordCount != 2)) errAbort("'in range' dataValue filter must have two numbers input\n"); if (constraint) *constraint = cmp; return TRUE; } else return FALSE; } /* static boolean checkWigDataFilter() */
void bafWriteLine(struct baf *baf) /* Write out a line of an alignment (which takes up * three lines on the screen. */ { int i; int count = baf->cix; int nStart = baf->nLineStart + 1 + baf->nNumOff; int hStart = baf->hLineStart + 1 + baf->hNumOff; int nEnd = baf->nCurPos + baf->nNumOff; int hEnd = baf->hCurPos + baf->hNumOff; int startDigits = maxDigits(nStart, hStart); int endDigits = maxDigits(nEnd, hEnd); int hStartNum, hEndNum; int nStartNum, nEndNum; static struct axtScoreScheme *ss = 0; /* Scoring scheme. */ struct cfm cfm; extern char blosumText[]; extern struct axtScoreScheme *axtScoreSchemeFromProteinText(char *text, char *fileName); boolean revArrows = (baf->nCountDown ^ baf->hCountDown); char arrowChar = (revArrows ? '<' : '>'); ZeroVar(&cfm); cfm.out = baf->out; if (ss == 0) ss = axtScoreSchemeFromProteinText(blosumText, "fake"); if (baf->nCountDown) { nStartNum = baf->nNumOff - baf->nLineStart; nEndNum = 1+baf->nNumOff - baf->nCurPos; } else { nStartNum = 1+baf->nNumOff + baf->nLineStart; nEndNum = baf->nNumOff + baf->nCurPos; } fprintf(baf->out, "%0*d ", startDigits, nStartNum); for (i=0; i<count; ++i) fputc(baf->nChars[i], baf->out); fprintf(baf->out, " %0*d\n", endDigits, nEndNum); for (i=0; i<startDigits; ++i) fputc(arrowChar, baf->out); fputc(' ', baf->out); for (i=0; i<count; ++i) { char n,h,c = ' '; n = baf->nChars[i]; h = baf->hChars[i]; if (baf->isTrans) { if (n != ' ') { DNA codon[4]; codon[0] = baf->hChars[i-1]; codon[1] = h; codon[2] = baf->hChars[i+1]; codon[3] = 0; tolowers(codon); c = lookupCodon(codon); cfmPushFormat(&cfm); if (toupper(n) == c) cfmOut(&cfm, '|', seqOutColorLookup[0]); else { int color; if (c == 0) c = 'X'; if (ss->matrix[(int)toupper(n)][(int)c] > 0) color = 5; else color = 6; cfmOut(&cfm, c, seqOutColorLookup[color]); } cfmPopFormat(&cfm); } else { fputc(c, baf->out); } } else { if (toupper(n) == toupper(h)) c = '|'; fputc(c, baf->out); } } fputc(' ', baf->out); for (i=0; i<endDigits; ++i) fputc(arrowChar, baf->out); fprintf(baf->out, "\n"); if (baf->hCountDown) { hStartNum = baf->hNumOff - baf->hLineStart; hEndNum = 1+baf->hNumOff - baf->hCurPos; } else { hStartNum = 1+baf->hNumOff + baf->hLineStart; hEndNum = baf->hNumOff + baf->hCurPos; } fprintf(baf->out, "%0*d ", startDigits, hStartNum); for (i=0; i<count; ++i) fputc(baf->hChars[i], baf->out); fprintf(baf->out, " %0*d\n\n", endDigits, hEndNum); }
/* * there are a variety of conditions that affect how FetchData is * going to work. This is an attempt to allow it to do as much * as possible, but not get overloaded. * summaryOnly is done when whole chrom summaries are requested * for statistic purposes. In those cases we do not need to go all * the way to the data to get the averages, the SQL rows are good * enough. Although even on this level there is quite a bit of * work to do on tracks such as Quality that have 180,000 rows on * just chr1. * a wiggleStats wsList is given when doing statistics, if it is * purely a data fetch operation, there is no need to do * wiggleStats and it will be a NULL pointer. * a bedList pointer is given when a returned bed list is desired. * In the case of processing a bedList, we honor the return limit * of number of bed elements via the maxBedElements. * If we are not returning a bedList and we are not doing a stats * summary, then we have an honest data fetch operation, and in * this case we honor the stated line limit of maxBedElements. * When the caller is doing this data fetch operation and states * that maxBedElements is zero, then we do all data that can be found. * This would be the case for a stats operation when only one chrom * is being worked on. */ struct wiggleData *wigFetchData(char *db, char *table, char *chromName, int winStart, int winEnd, boolean summaryOnly, boolean freeData, int tableId, boolean (*wiggleCompare)(int tableId, double value, boolean summaryOnly, struct wiggle *wiggle), char *constraints, struct bed **bedList, unsigned maxBedElements, struct wiggleStats **wsList) /* return linked list of wiggle data between winStart, winEnd */ { struct sqlConnection *conn = hAllocConn(db); struct sqlResult *sr; char **row; int rowOffset; int rowCount = 0; struct wiggle *wiggle; struct hash *spans = NULL; /* List of spans encountered during load */ char spanName[128]; char whereSpan[128]; char query[256]; struct hashEl *el; int leastSpan = BIGNUM; int mostSpan = 0; int spanCount = 0; int span = 0; struct hashCookie cookie; struct wiggleData *wigData = (struct wiggleData *) NULL; struct wiggleData *wdList = (struct wiggleData *) NULL; boolean bewareConstraints = FALSE; boolean createBedList = FALSE; boolean firstSpanDone = FALSE; unsigned dataLimit = 0; unsigned dataDone = 0; boolean reachedDataLimit = FALSE; /* make sure table exists before we try to talk to it * If it does not exist, we return a null result */ if (! sqlTableExists(conn, table)) { hFreeConn(&conn); return((struct wiggleData *)NULL); } if ((struct bed **)NULL != bedList) createBedList = TRUE; /* if we are not doing a summary (== return all data) and * we are not creating a bed list, then obey the limit requested * It will be zero if they really want everything. */ if (!summaryOnly && !createBedList) dataLimit = maxBedElements; spans = newHash(0); /* a listing of all spans found here */ resetStats(&wigStatsAcc); /* zero everything */ /* Are the constraints going to interfere with our span search ? */ if (constraints) { char *c = cloneString(constraints); tolowers(c); if (stringIn("span",c)) bewareConstraints = TRUE; } if (bewareConstraints) snprintf(query, sizeof(query), "SELECT span from %s where chrom = '%s' AND %s group by span", table, chromName, constraints ); else snprintf(query, sizeof(query), "SELECT span from %s where chrom = '%s' group by span", table, chromName ); /* Survey the spans to see what the story is here */ sr = sqlMustGetResult(conn,query); while ((row = sqlNextRow(sr)) != NULL) { unsigned span = sqlUnsigned(row[0]); ++rowCount; snprintf(spanName, sizeof(spanName), "%u", span); el = hashLookup(spans, spanName); if ( el == NULL) { if (span > mostSpan) mostSpan = span; if (span < leastSpan) leastSpan = span; ++spanCount; hashAddInt(spans, spanName, span); } } sqlFreeResult(&sr); /* Now, using that span list, go through each span, fetching data */ cookie = hashFirst(spans); while ((! reachedDataLimit) && (el = hashNext(&cookie)) != NULL) { if ((struct wiggleStats **)NULL != wsList) returnStats(&wigStatsAcc,wsList,chromName,winStart,winEnd,span); resetStats(&wigStatsAcc); if (bewareConstraints) { snprintf(whereSpan, sizeof(whereSpan), "((span = %s) AND %s)", el->name, constraints); } else snprintf(whereSpan, sizeof(whereSpan), "span = %s", el->name); span = atoi(el->name); sr = hOrderedRangeQuery(conn, table, chromName, winStart, winEnd, whereSpan, &rowOffset); rowCount = 0; while ((! reachedDataLimit) && (row = sqlNextRow(sr)) != NULL) { ++rowCount; wiggle = wiggleLoad(row + rowOffset); if (wiggle->count > 0 && (! reachedDataLimit)) { wigData = wigReadDataRow(wiggle, winStart, winEnd, tableId, summaryOnly, wiggleCompare ); if (wigData) { if (firstSpanDone) accumStats(&wigStatsAcc, wigData, (struct bed **)NULL, maxBedElements, table); else accumStats(&wigStatsAcc, wigData, bedList, maxBedElements, table); dataDone += wigData->count; if (freeData) { freeMem(wigData->data); /* and mark it gone */ wigData->data = (struct wiggleDatum *)NULL; } slAddHead(&wdList,wigData); if (!createBedList && dataLimit) if (dataLimit < dataDone) reachedDataLimit = TRUE; if (createBedList && (wigStatsAcc.bedElCount > maxBedElements)) reachedDataLimit = TRUE; } } } /* perhaps last bed line */ if (!firstSpanDone && createBedList && (wigStatsAcc.bedElEnd > wigStatsAcc.bedElStart) && wigData) { struct bed *bedEl; bedEl = bedElement(wigData->chrom, wigStatsAcc.bedElStart, wigStatsAcc.bedElEnd, table, ++wigStatsAcc.bedElCount); slAddHead(bedList, bedEl); } sqlFreeResult(&sr); firstSpanDone = TRUE; } closeWibFile(); if (createBedList) slReverse(bedList); /* last stats calculation */ if ((struct wiggleStats **)NULL != wsList) returnStats(&wigStatsAcc,wsList,chromName,winStart,winEnd,span); hFreeConn(&conn); if (wdList != (struct wiggleData *)NULL) slReverse(&wdList); /* this wdList can be freed by wigFreeData */ return(wdList); } /* struct wiggleData *wigFetchData() */