/* 7.7.3 <SUFFIX PROGRAM DATA> */ int scpiLex_SuffixProgramData(lex_state_t * state, scpi_token_t * token) { token->ptr = state->pos; skipChr(state, '/'); // TODO: strict parsing : SLASH? (ALPHA+ (MINUS? DIGIT)?) ((SLASH | DOT) (ALPHA+ (MINUS? DIGIT)?))* if (skipAlpha(state)) { skipChr(state, '-'); skipDigit(state); while (skipSlashDot(state)) { skipAlpha(state); skipChr(state, '-'); skipDigit(state); } } token->len = state->pos - token->ptr; if ((token->len > 0)) { token->type = SCPI_TOKEN_SUFFIX_PROGRAM_DATA; } else { token->type = SCPI_TOKEN_UNKNOWN; state->pos = token->ptr; token->len = 0; } return token->len; }
/** * Detect token nondecimal number * @param state * @param token * @return */ int scpiLex_NondecimalNumericData(lex_state_t * state, scpi_token_t * token) { int someNumbers = 0; token->ptr = state->pos; if (skipChr(state, '#')) { if (!iseos(state)) { if (isH(state->pos[0])) { state->pos++; someNumbers = skipHexNum(state); token->type = SCPI_TOKEN_HEXNUM; } else if (isQ(state->pos[0])) { state->pos++; someNumbers = skipOctNum(state); token->type = SCPI_TOKEN_OCTNUM; } else if (isB(state->pos[0])) { state->pos++; someNumbers = skipBinNum(state); token->type = SCPI_TOKEN_BINNUM; } } } if (someNumbers) { token->ptr += 2; // ignore number prefix token->len = state->pos - token->ptr; } else { token->type = SCPI_TOKEN_UNKNOWN; state->pos = token->ptr; token->len = 0; } return token->len > 0 ? token->len + 2 : 0; }
char *hCytoBandName(struct cytoBand *band, boolean isDmel) /* Return name of band. Returns a static buffer, so don't free result. */ { static char buf[32]; sprintf(buf, "%s%s", (isDmel ? "" : skipChr(band->chrom)), band->name); return buf; }
static char *abbreviatedBandName(struct cytoBand *band, MgFont *font, int width, boolean isDmel) /* Return a string abbreviated enough to fit into space. */ { int textWidth; static char string[32]; /* If have enough space, return original chromosome/band. */ sprintf(string, "%s%s", (isDmel ? "" : skipChr(band->chrom)), band->name); textWidth = mgFontStringWidth(font, string); if (textWidth <= width) return string; /* Try leaving off chromosome */ sprintf(string, "%s", band->name); textWidth = mgFontStringWidth(font, string); if (textWidth <= width) return string; /* Try leaving off initial letter */ sprintf(string, "%s", band->name+1); textWidth = mgFontStringWidth(font, string); if (textWidth <= width) return string; return NULL; }
/** * Detect token New line * @param state * @param token * @return */ int scpiLex_NewLine(lex_state_t * state, scpi_token_t * token) { token->ptr = state->pos; skipChr(state, '\r'); skipChr(state, '\n'); token->len = state->pos - token->ptr; if ((token->len > 0)) { token->type = SCPI_TOKEN_NL; } else { token->type = SCPI_TOKEN_UNKNOWN; state->pos = token->ptr; token->len = 0; } return token->len; }
/** * Detect token Block Data * @param state * @param token * @return */ int scpiLex_ArbitraryBlockProgramData(lex_state_t * state, scpi_token_t * token) { int i; int arbitraryBlockLength = 0; const char * ptr = state->pos; int validData = -1; token->ptr = state->pos; if (skipChr(state, '#')) { if (!iseos(state) && isNonzeroDigit(state->pos[0])) { /* Get number of digits */ i = state->pos[0] - '0'; state->pos++; for (; i > 0; i--) { if (!iseos(state) && isdigit((uint8_t)(state->pos[0]))) { arbitraryBlockLength *= 10; arbitraryBlockLength += (state->pos[0] - '0'); state->pos++; } else { break; } } if (i == 0) { state->pos += arbitraryBlockLength; if ((state->buffer + state->len) >= (state->pos)) { token->ptr = state->pos - arbitraryBlockLength; token->len = arbitraryBlockLength; validData = 1; } else { validData = 0; } } else if (iseos(state)) { validData = 0; } } else if (iseos(state)) { validData = 0; } } if (validData == 1) { /* valid */ token->type = SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA; } else if (validData == 0) { /* incomplete */ token->type = SCPI_TOKEN_UNKNOWN; token->len = 0; state->pos = state->buffer + state->len; } else { /* invalid */ token->type = SCPI_TOKEN_UNKNOWN; state->pos = token->ptr; token->len = 0; } return token->len + (token->ptr - ptr); }
/** * Detect specified character * @param state * @param token * @return */ int scpiLex_SpecificCharacter(lex_state_t * state, scpi_token_t * token, char chr) { token->ptr = state->pos; if (skipChr(state, chr)) { token->len = 1; token->type = SCPI_TOKEN_SPECIFIC_CHARACTER; } else { token->len = 0; token->type = SCPI_TOKEN_UNKNOWN; } return token->len; }
/** * Detect token colon * @param state * @param token * @return */ int scpiLex_Colon(lex_state_t * state, scpi_token_t * token) { token->ptr = state->pos; if (skipChr(state, ':')) { token->len = 1; token->type = SCPI_TOKEN_COLON; } else { token->len = 0; token->type = SCPI_TOKEN_UNKNOWN; } return token->len; }
/* 7.7.2 <DECIMAL NUMERIC PROGRAM DATA> */ static int skipMantisa(lex_state_t * state) { int someNumbers = 0; skipPlusmn(state); someNumbers += skipNumbers(state); if (skipChr(state, '.')) { someNumbers += skipNumbers(state); } return someNumbers; }
/** * Detect token command or compound program header * @param state * @param token * @return */ int scpiLex_ProgramHeader(lex_state_t * state, scpi_token_t * token) { int res; token->ptr = state->pos; token->type = SCPI_TOKEN_UNKNOWN; res = skipCommonProgramHeader(state); if (res >= SKIP_OK) { if (skipChr(state, '?') >= SKIP_OK) { token->type = SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER; } else { token->type = SCPI_TOKEN_COMMON_PROGRAM_HEADER; } } else if (res <= SKIP_INCOMPLETE) { token->type = SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER; } else if (res == SKIP_NONE) { res = skipCompoundProgramHeader(state); if (res >= SKIP_OK) { if (skipChr(state, '?') >= SKIP_OK) { token->type = SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER; } else { token->type = SCPI_TOKEN_COMPOUND_PROGRAM_HEADER; } } else if (res <= SKIP_INCOMPLETE) { token->type = SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER; } } if (token->type != SCPI_TOKEN_UNKNOWN) { token->len = state->pos - token->ptr; } else { token->len = 0; state->pos = token->ptr; } return token->len; }
char *encodeRnaName(struct track *tg, void *item) /* Return RNA gene name. */ { struct encodeRna *el = item; char *full = el->name; static char abbrev[SMALLBUF]; char *e; strcpy(abbrev, skipChr(full)); subChar(abbrev, '_', ' '); abbr(abbrev, " pseudogene"); if ((e = strstr(abbrev, "-related")) != NULL) strcpy(e, "-like"); return abbrev; }
struct dyString *ensContigViewUrl( char *database, char *ensOrg, char *chrom, int chromSize, int winStart, int winEnd, char *archive) /* Return a URL that will take you to ensembl's contig view. */ /* Not using chromSize. archive is possibly a date reference */ { struct dyString *dy = dyStringNew(0); char *chrName; char *ensemblName = ucscToEnsembl(database, chrom); int ensemblLift = 0; int start = winStart; int end = winEnd; if (isNotEmpty(ensemblName)) { chrName = ensemblName; ensemblLift = liftToEnsembl(database, ensemblName); start += ensemblLift; end += ensemblLift; } else if (startsWith("scaffold", chrom)) chrName = chrom; else chrName = skipChr(chrom); if (archive) if (sameWord(archive,"ncbi36")) { dyStringPrintf(dy, "http://%s.ensembl.org/%s/contigview?chr=%s&start=%d&end=%d", archive, ensOrg, chrName, start, end); } else { dyStringPrintf(dy, "http://%s.archive.ensembl.org/%s/contigview?chr=%s&start=%d&end=%d", archive, ensOrg, chrName, start, end); } else dyStringPrintf(dy, "http://www.ensembl.org/%s/contigview?chr=%s&start=%d&end=%d", ensOrg, chrName, start, end); return dy; }
void showAliPlaces(char *pslName, char *faName, char *database, enum gfType qType, enum gfType tType, char *organism, boolean feelingLucky) /* Show all the places that align. */ { struct lineFile *lf = pslFileOpen(pslName); struct psl *pslList = NULL, *psl; char *browserUrl = hgTracksName(); char *hgcUrl = hgcName(); char uiState[64]; char *vis; char unhideTrack[64]; char *sort = cartUsualString(cart, "sort", sortList[0]); char *output = cartUsualString(cart, "output", outputList[0]); boolean pslOut = startsWith("psl", output); boolean isStraightNuc = (qType == gftRna || qType == gftDna); int minThreshold = (isStraightNuc ? minMatchShown : 0); sprintf(uiState, "%s=%s", cartSessionVarName(), cartSessionId(cart)); /* If user has hidden BLAT track, add a setting that will unhide the track if user clicks on a browser link. */ vis = cartOptionalString(cart, "hgUserPsl"); if (vis != NULL && sameString(vis, "hide")) snprintf(unhideTrack, sizeof(unhideTrack), "&hgUserPsl=dense"); else unhideTrack[0] = 0; while ((psl = pslNext(lf)) != NULL) { if (psl->match >= minThreshold) slAddHead(&pslList, psl); } lineFileClose(&lf); if (pslList == NULL) { puts("<table><tr><td><hr>Sorry, no matches found<hr><td></tr></table>"); return; } if (sameString(sort, "query,start")) { slSort(&pslList, pslCmpQuery); } else if (sameString(sort, "query,score")) { slSort(&pslList, pslCmpQueryScore); } else if (sameString(sort, "score")) { slSort(&pslList, pslCmpScore); } else if (sameString(sort, "chrom,start")) { slSort(&pslList, pslCmpTargetStart); } else if (sameString(sort, "chrom,score")) { slSort(&pslList, pslCmpTargetScore); } else { slSort(&pslList, pslCmpQueryScore); } if(feelingLucky) { /* If we found something jump browser to there. */ if(slCount(pslList) > 0) printLuckyRedirect(browserUrl, pslList, database, pslName, faName, uiState, unhideTrack); /* Otherwise call ourselves again not feeling lucky to print empty results. */ else { cartWebStart(cart, database, "%s BLAT Results", trackHubSkipHubName(organism)); showAliPlaces(pslName, faName, database, qType, tType, organism, FALSE); cartWebEnd(); } } else if (pslOut) { printf("<TT><PRE>"); if (!sameString(output, "psl no header")) pslxWriteHead(stdout, qType, tType); for (psl = pslList; psl != NULL; psl = psl->next) pslTabOut(psl, stdout); printf("</PRE></TT>"); } else { printf("<H2>BLAT Search Results</H2>"); printf("<TT><PRE>"); printf(" ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND START END SPAN\n"); printf("---------------------------------------------------------------------------------------------------\n"); for (psl = pslList; psl != NULL; psl = psl->next) { printf("<A HREF=\"%s?position=%s:%d-%d&db=%s&ss=%s+%s&%s%s\">", browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, pslName, faName, uiState, unhideTrack); printf("browser</A> "); printf("<A HREF=\"%s?o=%d&g=htcUserAli&i=%s+%s+%s&c=%s&l=%d&r=%d&db=%s&%s\">", hgcUrl, psl->tStart, pslName, cgiEncode(faName), psl->qName, psl->tName, psl->tStart, psl->tEnd, database, uiState); printf("details</A> "); printf("%-14s %5d %5d %5d %5d %5.1f%% %4s %2s %9d %9d %6d\n", psl->qName, pslScore(psl), psl->qStart+1, psl->qEnd, psl->qSize, 100.0 - pslCalcMilliBad(psl, TRUE) * 0.1, skipChr(psl->tName), psl->strand, psl->tStart+1, psl->tEnd, psl->tEnd - psl->tStart); } printf("</PRE></TT>"); } pslFreeList(&pslList); }
void fakeFinContigs(char *agpName, char *faName, char *finDir, char *rootName, char *finFaDir, char *ooVer) /* fakeFinContigs - Fake up contigs for a finished chromosome. */ { struct contig *contigList = NULL, *contig = NULL; struct agpFrag *agp; struct lineFile *lf = lineFileOpen(agpName, TRUE); char *line, *words[16]; int lineSize, wordCount; int contigIx = 0; char liftDir[512], contigDir[512], path[512]; char chrom[128]; FILE *f; struct dnaSeq *seq; int fragIx; /* Build up contig list by scanning agp file. */ printf("Reading %s\n", lf->fileName); while (lineFileNext(lf, &line, &lineSize)) { if (line[0] == '#' || line[0] == 0) continue; wordCount = chopLine(line, words); if (wordCount < 5) errAbort("Expecting at least 5 words line %d of %s", lf->lineIx, lf->fileName); if (words[4][0] == 'N' || words[4][0] == 'U') { contig = NULL; continue; } lineFileExpectWords(lf, 9, wordCount); agp = agpFragLoad(words); // file is 1-based but agpFragLoad() now assumes 0-based: agp->chromStart -= 1; agp->fragStart -= 1; if (contig == NULL) { AllocVar(contig); sprintf(contig->name, "%s%d", rootName, ++contigIx); contig->startOffset = agp->chromStart; slAddHead(&contigList, contig); } else { if (contig->agpList != NULL && contig->agpList->chromEnd != agp->chromStart) errAbort("Start doesn't match previous end line %d of %s", lf->lineIx, lf->fileName); } if (agp->chromEnd - agp->chromStart != agp->fragEnd - agp->fragStart) errAbort("Chrom and frag size mismatch line %d of %s", lf->lineIx, lf->fileName); slAddHead(&contig->agpList, agp); contig->endOffset = agp->chromEnd; } slReverse(&contigList); for (contig = contigList; contig != NULL; contig = contig->next) slReverse(&contig->agpList); lineFileClose(&lf); /* Load up chromosome sequence and make sure it is in one piece. */ printf("Reading %s\n", faName); seq = faReadAllDna(faName); if (slCount(seq) != 1) errAbort("Got %d sequences in %s, can only handle one.", slCount(seq), faName); /* Fix up agp coordinates. Make a directory for each contig. Fill it with * .fa .agp barge.NN files for that contig. */ printf("Writing contig dirs\n"); for (contig = contigList; contig != NULL; contig = contig->next) { /* Make Contig dir. */ sprintf(contigDir, "%s/%s", finDir, contig->name); makeDir(contigDir); /* Make contig.agp file. */ sprintf(path, "%s/%s.agp", contigDir, contig->name); f = mustOpen(path, "w"); fragIx = 0; for (agp = contig->agpList; agp != NULL; agp = agp->next) { char buf[128]; sprintf(buf, "%s/%s", skipChr(agp->chrom), contig->name); freez(&agp->chrom); agp->chrom = cloneString(buf); agp->chromStart -= contig->startOffset; agp->chromEnd -= contig->startOffset; agp->ix = ++fragIx; agpFragTabOut(agp, f); } carefulClose(&f); /* Make ooGreedy.NN.gl file */ sprintf(path, "%s/%s.%s.gl", contigDir, "ooGreedy", ooVer); f = mustOpen(path, "w"); for (agp = contig->agpList; agp != NULL; agp = agp->next) { if (agp->type[0] != 'N' && agp->type[0] != 'U') { fprintf(f, "%s_1\t%d\t%d\t%s\n", agp->frag, agp->chromStart, agp->chromEnd, agp->strand); } } carefulClose(&f); /* Make contig.fa file. */ sprintf(path, "%s/%s.fa", contigDir, contig->name); faWrite(path, contig->name, seq->dna + contig->startOffset, contig->endOffset - contig->startOffset); /* Make contig/barge file. */ sprintf(path, "%s/barge.%s", contigDir, ooVer); f = mustOpen(path, "w"); fprintf(f, "Barge (Connected Clone) File ooGreedy Version %s\n", ooVer); fprintf(f, "\n"); fprintf(f, "start accession size overlap maxClone maxOverlap\n"); fprintf(f, "------------------------------------------------------------\n"); for (agp = contig->agpList; agp != NULL; agp = agp->next) { char clone[128]; strcpy(clone, agp->frag); chopSuffix(clone); fprintf(f, "%d\t%s\t%d\t100\tn/a\t0\n", agp->chromStart, clone, agp->chromEnd); } carefulClose(&f); /* Make contig/gold file. */ sprintf(path, "%s/gold.%s", contigDir, ooVer); f = mustOpen(path, "w"); fragIx = 0; for (agp = contig->agpList; agp != NULL; agp = agp->next) { char fragName[128]; struct agpFrag frag = *agp; sprintf(fragName, "%s_1", agp->frag); frag.frag = fragName; frag.type[0] = '0'; agpFragTabOut(&frag, f); } carefulClose(&f); } /* Create lift subdirectory. */ printf("Creating lift files\n"); sprintf(liftDir, "%s/lift", finDir); makeDir(liftDir); /* Create lift/oOut.lst file (just a list of contigs). */ sprintf(path, "%s/oOut.lst", liftDir); f = mustOpen(path, "w"); for (contig = contigList; contig != NULL; contig = contig->next) fprintf(f, "%s/%s.fa.out\n", contig->name, contig->name); carefulClose(&f); /* Create lift/ordered.lst file (just a list of contigs). */ sprintf(path, "%s/ordered.lst", liftDir); f = mustOpen(path, "w"); for (contig = contigList; contig != NULL; contig = contig->next) fprintf(f, "%s\n", contig->name); carefulClose(&f); /* Create lift/ordered.lft file. */ sprintf(path, "%s/ordered.lft", liftDir); f = mustOpen(path, "w"); splitPath(faName, NULL, chrom, NULL); for (contig = contigList; contig != NULL; contig = contig->next) fprintf(f, "%d\t%s/%s\t%d\t%s\t%d\n", contig->startOffset, skipChr(chrom), contig->name, contig->endOffset - contig->startOffset, chrom, seq->size); carefulClose(&f); }