static void printTabularHeaderRow(const struct vcfInfoDef *def) /* Parse the column header parts out of def->description and print as table header row; * call this only when looksTabular returns TRUE. */ { regmatch_t substrArr[PATH_LEN]; if (regexMatchSubstr(def->description, COL_DESC_REGEX, substrArr, ArraySize(substrArr))) { puts("<TR>"); // Make a copy of the part of def->description that matches the regex, // then chop by '|' and print out header column tags: int matchSize = substrArr[0].rm_eo - substrArr[0].rm_so; char copy[matchSize+1]; safencpy(copy, sizeof(copy), def->description + substrArr[0].rm_so, matchSize); // Turn '_' into ' ' so description words can wrap inside headers, saving some space subChar(copy, '_', ' '); char *words[PATH_LEN]; int descColCount = chopByChar(copy, '|', words, ArraySize(words)); int i; for (i = 0; i < descColCount; i++) printf("<TH class='withThinBorder'>%s</TH>", words[i]); puts("</TR>"); } else errAbort("printTabularHeaderRow: code bug, if looksTabular returns true then " "regex should work here"); }
static void checkTerm(char *term, char *target, enum dbDbMatchType type, struct dbDb *dbDb, struct hash *matchHash, struct dbDbMatch **pMatchList) /* If target starts with term (case-insensitive), and target is not already in matchHash, * add target to matchHash and add a new match to pMatchList. */ { // Make uppercase version of target for case-insensitive matching. int targetLen = strlen(target); char targetUpcase[targetLen + 1]; safencpy(targetUpcase, sizeof(targetUpcase), target, targetLen); touppers(targetUpcase); int offset = wordMatchOffset(term, targetUpcase); if (offset >= 0) { addIfFirstMatch(dbDb, type, offset, targetUpcase, term, matchHash, pMatchList); } else if (offset < 0 && type == ddmtSciName && term[0] == targetUpcase[0]) { // For scientific names ("Genus species"), see if the user entered the term as 'G. species' // e.g. term 'P. trog' for target 'Pan troglodytes' regmatch_t substrArr[3]; if (regexMatchSubstrNoCase(term, "^[a-z](\\.| ) *([a-z]+)", substrArr, ArraySize(substrArr))) { char *termSpecies = term + substrArr[2].rm_so; char *targetSpecies = skipLeadingSpaces(skipToSpaces(targetUpcase)); if (targetSpecies && startsWithNoCase(termSpecies, targetSpecies)) { // Keep the negative offset since we can't just bold one chunk of target... addIfFirstMatch(dbDb, type, offset, targetUpcase, term, matchHash, pMatchList); } } } }
INLINE void safeAddN(char **pDest, int *pSize, char *src, int len) /* Copy len bytes of src into dest. Subtract len from *pSize and add len to *pDest, * for building up a string bit by bit. */ { safencpy(*pDest, *pSize, src, len); *pSize -= len; *pDest += len; }
static char *parsePrefix(char *varName) /* parse prefix before first dot. WARNING: static return */ { static char prefix[65]; char *dot = strchr(varName, '.'); if (dot == NULL) prefix[0] = '\0'; // empty string if no dot else safencpy(prefix, sizeof(prefix), varName, (dot-varName)); return prefix; }
INLINE void abbrevAndHandleRC(char *abbrevAl, size_t abbrevAlSize, const char *fullAl) /* Limit the size of displayed allele to abbrevAlSize-1 and handle reverse-complemented display. */ { boolean fullLen = strlen(fullAl); boolean truncating = (fullLen > abbrevAlSize-1); if (truncating) { int truncLen = abbrevAlSize - 4; if (revCmplDisp) { safencpy(abbrevAl, abbrevAlSize, (fullAl + fullLen - truncLen), truncLen); reverseComplement(abbrevAl, truncLen); } else safencpy(abbrevAl, abbrevAlSize, fullAl, truncLen); safecat(abbrevAl, abbrevAlSize, "..."); } else { safecpy(abbrevAl, abbrevAlSize, fullAl); if (revCmplDisp) reverseComplement(abbrevAl, fullLen); } }
void annoAssemblyGetSeq(struct annoAssembly *aa, char *seqName, uint start, uint end, char *buf, size_t bufSize) /* Copy sequence to buf; bufSize must be at least end-start+1 chars in length. */ { if (aa->curSeq == NULL || differentString(aa->curSeq->name, seqName)) { dnaSeqFree(&aa->curSeq); aa->curSeq = twoBitReadSeqFragLower(aa->tbf, seqName, 0, 0); } uint chromSize = aa->curSeq->size; if (end > chromSize || start > chromSize || start > end) errAbort("annoAssemblyGetSeq: bad coords [%u,%u) (sequence %s size %u)", start, end, seqName, chromSize); safencpy(buf, bufSize, aa->curSeq->dna+start, end-start); }
struct variant *variantFromVcfAnnoRow(struct annoRow *row, char *refAllele, struct lm *lm, struct dyString *dyScratch) /* Translate vcf array of words into variant (allocated by lm, overwriting dyScratch * as temporary scratch string). */ { char **words = row->data; char *alStr = vcfGetSlashSepAllelesFromWords(words, dyScratch); // The reference allele is the first allele in alStr -- and it may be trimmed on both ends with // respect to the raw VCF ref allele in words[3], so copy vcfRefAllele back out of alStr. // That ensures that variantNew will get the reference allele that matches the slash-separated // allele string. int refLen = strlen(alStr); char *p = strchr(alStr, '/'); if (p) refLen = p - alStr; char vcfRefAllele[refLen + 1]; safencpy(vcfRefAllele, sizeof(vcfRefAllele), alStr, refLen); unsigned alCount = countChars(alStr, '/') + 1; return variantNew(row->chrom, row->start, row->end, alCount, alStr, vcfRefAllele, lm); }
static void printTabularData(struct vcfInfoElement *el) /* Print a row for each value in el, separating columns by '|'. */ { int j; for (j = 0; j < el->count; j++) { puts("<TR>"); char *val = el->values[j].datString; if (!isEmpty(val)) { int len = strlen(val); char copy[len+1]; safencpy(copy, sizeof(copy), val, len); char *words[PATH_LEN]; int colCount = chopByChar(copy, '|', words, ArraySize(words)); int k; for (k = 0; k < colCount; k++) printf("<TD class='withThinBorder'>%s</TD>", words[k]); } puts("</TR>"); } }
static enum vcfInfoType vcfInfoTypeFromSubstr(struct vcfFile *vcff, char *line, regmatch_t substr) /* Translate substring of line into vcfInfoType or complain. */ { char typeWord[16]; int substrLen = substr.rm_eo - substr.rm_so; if (substrLen > sizeof(typeWord) - 1) { vcfFileErr(vcff, "substring passed to vcfInfoTypeFromSubstr is too long."); return vcfInfoNoType; } safencpy(typeWord, sizeof(typeWord), line + substr.rm_so, substrLen); if (sameString("Integer", typeWord)) return vcfInfoInteger; if (sameString("Float", typeWord)) return vcfInfoFloat; if (sameString("Flag", typeWord)) return vcfInfoFlag; if (sameString("Character", typeWord)) return vcfInfoCharacter; if (sameString("String", typeWord)) return vcfInfoString; vcfFileErr(vcff, "Unrecognized type word \"%s\" in metadata line \"%s\"", typeWord, line); return vcfInfoNoType; }
static void tabBlastOut(struct axtBundle *abList, int queryIx, boolean isProt, FILE *f, char *databaseName, int databaseSeqCount, double databaseLetterCount, char *ourId, boolean withComment) /* Do NCBI tabular blast output. */ { char *queryName = abList->axtList->qName; int querySize = abList->qSize; struct targetHits *targetList = NULL, *target; if (withComment) { // use date from CVS, unless checked out with -kk, then ignore. char * rcsDate = "$Date: 2009/02/26 00:05:49 $"; char dateStamp[11]; if (strlen(rcsDate) > 17) safencpy(dateStamp, sizeof(dateStamp), rcsDate+7, 10); else safecpy(dateStamp, sizeof(dateStamp), ""); dateStamp[10] = 0; fprintf(f, "# BLAT %s [%s]\n", gfVersion, dateStamp); fprintf(f, "# Query: %s\n", queryName); fprintf(f, "# Database: %s\n", databaseName); fprintf(f, "%s\n", "# Fields: Query id, Subject id, % identity, alignment length, " "mismatches, gap openings, q. start, q. end, s. start, s. end, " "e-value, bit score"); } /* Print out details on each target. */ targetList = bundleIntoTargets(abList); for (target = targetList; target != NULL; target = target->next) { struct axtRef *ref; for (ref = target->axtList; ref != NULL; ref = ref->next) { struct axt *axt = ref->axt; int matches = countMatches(axt->qSym, axt->tSym, axt->symCount); int gaps = countGaps(axt->qSym, axt->tSym, axt->symCount); int gapOpens = countGapOpens(axt->qSym, axt->tSym, axt->symCount); fprintf(f, "%s\t", axt->qName); fprintf(f, "%s\t", axt->tName); fprintf(f, "%.2f\t", 100.0 * matches/axt->symCount); fprintf(f, "%d\t", axt->symCount); fprintf(f, "%d\t", axt->symCount - matches - gaps); fprintf(f, "%d\t", gapOpens); if (axt->qStrand == '-') { int s = axt->qStart, e = axt->qEnd; reverseIntRange(&s, &e, querySize); fprintf(f, "%d\t", s+1); fprintf(f, "%d\t", e); printAxtTargetBlastTab(f, axt, target->size); } else { fprintf(f, "%d\t", axt->qStart + 1); fprintf(f, "%d\t", axt->qEnd); printAxtTargetBlastTab(f, axt, target->size); } fprintf(f, "%3.1e\t", blastzScoreToNcbiExpectation(axt->score)); fprintf(f, "%d.0\n", blastzScoreToNcbiBits(axt->score)); } } /* Cleanup time. */ targetHitsFreeList(&targetList); }