Here is the sequence around this feature: bases %d to %d of %s. " "The bases that contain the feature itself are in upper case.
\n", s, e, seqName); seq = hDnaFromSeq(database, seqName, s, e, dnaLower); toUpperN(seq->dna + (start-s), end - start); printf(""); cfm = cfmNew(10, 50, TRUE, FALSE, stdout, s); for (i=0; i"); } void printBand(char *chrom, int start, int end, boolean tableFormat) /* Print all matching chromosome bands. */ /* Ignore end if it is zero. */ { char sband[HDB_MAX_BAND_STRING], eband[HDB_MAX_BAND_STRING]; boolean gotS = FALSE; boolean gotE = FALSE; if (start < 0) return; gotS = hChromBand(database, chrom, start, sband); /* if the start lookup fails, don't bother with the end lookup */ if (!gotS) return; /* if no end chrom, print start band and exit */ if (end == 0) { if (tableFormat) printf("size; ++i) { cfmOut(cfm, seq->dna[i], 0); } cfmFree(&cfm); printf("
", getNonce(), eUrl, iframeOptions);
}
void printPendingIframe()
/* Write out the iframe queued up by printIframe(), if there is one. Called from
* the position-printing routines so that the iframe lands under the "View DNA"
* line, with the other details, and not at the top of the page. */
{
if (pendingIframe == NULL)
return;
fputs(pendingIframe->string, stdout);
dyStringFree(&pendingIframe);
}
void printCustomUrlWithLabel(struct trackDb *tdb, char *itemName, char *itemLabel,
char *urlSetting, boolean encode, struct slPair *fields)
/* Print custom URL specified in trackDb settings. */
{
char urlLabelSetting[32];
// replace the $$ and other wildchards with the url given in tdb
char *url = getUrlSetting(tdb, urlSetting);
//char* eUrl = constructUrl(tdb, url, itemName, encode);
if (url==NULL || isEmpty(url))
return;
char *eUrl = replaceInUrl(url, itemName, cart, database, seqName, winStart, winEnd, tdb->track,
encode, fields);
if (eUrl==NULL)
return;
/* create the url label setting for trackDb from the url
setting prefix */
safef(urlLabelSetting, sizeof(urlLabelSetting), "%sLabel", urlSetting);
char *linkLabel = trackDbSettingOrDefault(tdb, urlLabelSetting, "Outside Link:");
char *eLinkLabel = replaceInUrl(linkLabel, itemName, cart, database, seqName, winStart, winEnd, tdb->track,
encode, fields);
// if we got no item name from hgTracks or the item name does not appear in the URL
// there is no need to show the item name at all
// the url and its label come from trackDb and the item name from the data file, both of
// which a track hub supplies, so escape them
if (isEmpty(itemName) || !stringIn("$$", url))
{
printf("%s
",hubEncode(tdb, eUrl),
hubEncode(tdb, eLinkLabel));
return;
}
printf("%s ",hubEncode(tdb, eLinkLabel));
printf("", hubEncode(tdb, eUrl));
if (sameWord(tdb->table, "npredGene"))
{
printf("%s (%s)
\n", itemName, "NCBI MapView");
}
else
{
char *label = itemName;
if (isNotEmpty(itemLabel) && differentString(itemName, itemLabel))
label = itemLabel;
printf("%s
The item \"%s\" has been located in other genomes:\n
Currently the item \"%s\" has not been located in another genome.\n",name);
}
void mafPrettyOut(FILE *f, struct mafAli *maf, int lineSize,
boolean onlyDiff, int blockNo, struct hash *hash);
void doAtom( struct trackDb *tdb, char *item)
{
char table[HDB_MAX_TABLE_STRING];
boolean hasBin;
//struct bed *bed;
char query[512];
struct sqlResult *sr;
char **row;
//boolean firstTime = TRUE;
int start = cartInt(cart, "o");
//struct sqlConnection *conn = hAllocConn(database);
char *user = cfgOption("db.user");
char *password = cfgOption("db.password");
struct sqlConnection *sc;
struct atom ret;
genericHeader(tdb, item);
if (!hFindSplitTable(database, seqName, tdb->table, table, sizeof table, &hasBin))
errAbort("mafPrettyOut track %s not found", tdb->table);
#if 0
sqlSafef(query, sizeof query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", table, escapedName, seqName, start);
sr = sqlGetResult(conn, query);
printf("This is the item you clicked on:
\n");
while ((row = sqlNextRow(sr)) != NULL)
{
if (firstTime)
firstTime = FALSE;
else
htmlHorizontalLine();
bed = bedLoadN(row+hasBin, 4);
bedPrintPos(bed, 4, tdb);
}
sqlFreeResult(&sr);
sqlSafef(query, sizeof query, "select * from %s where name = '%s'", table, escapedName);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
bed = bedLoadN(row+hasBin, 4);
if (bed->chromStart != start)
{
htmlHorizontalLine();
firstTime = FALSE;
printf("Another instances on %s:
\n",database);
bedPrintPos(bed, 4, tdb);
}
}
sqlFreeResult(&sr);
#endif
sc = sqlConnectRemote("localhost", user, password, "hgFixed");
sqlSafef(query, sizeof(query),
"select * from %s where name = '%s'", table, item);
sr = sqlGetResult(sc, query);
printf("Atom %s instances ('*' marks item you clicked on)
\n",item);
printf("
\n");
//printf("Ins#\tSpecies\t\tChrom\tStart\tEnd\tStrand\n");
printf( " # %-10s %-5s %12s %12s %10s %s %-10s %-10s\n",
"species","chrom", "start", "end", "length", "strand","fivePrime","threePrime");
while ((row = sqlNextRow(sr)) != NULL)
{
atomStaticLoad(row, &ret);
//atomOutput(&ret, stdout, '\t', '\n');
linkToOtherBrowser(ret.species, ret.chrom, ret.start, ret.end);
if (sameString(ret.chrom, seqName) && (start == ret.start) &&
sameString(ret.species, database))
printf("* ");
else
printf(" ");
printf( "%4d %-10s %-5s %12d %12d %10d %c %-10s %-10s\n",
ret.instance, ret.species,ret.chrom, ret.start + 1, ret.end,
ret.end - ret.start + 1, ret.strand[0],ret.fivePrime,ret.threePrime);
}
printf("");
sqlFreeResult(&sr);
if (!sameString("atom20080226d", table))
return;
printf("| ");
printf("Suh Trees \n"); printf(" ![]() ",item); printf(" | ![]() ",item); printf(" |
|---|---|
| ");
printf("NJ Trees \n"); printf(" ![]() ",item); printf(" | ![]() ",item); printf(" |
| ");
/*
printf("Gap UPGMA Trees \n"); printf(" ![]() ",item); printf(" | ![]() ",item); printf(" |
| "); char table[4096]; safef(table, sizeof(table), "%s", thisTbl->encodedTbl); int swapped = strSwapStrs(table, 4096, ";", " | |
| "); if (swapped == -1) errAbort("Error substituting ';' for ' | |
| "); if (swapped == -1) errAbort("Error substituting '|' for ' | ' in hgc.c:printEmbeddedTable()"); printf("%s |
%s
\n", description); printf("| "); char *toPrint = replaceChars(line, "\t", " | "); printf("%s", toPrint); printf(" |
\n
| \n"); else if (col->isList || col->isArray || col->lowType->stringy || asTypesIsInt(col->lowType->type)) printIdOrLinks(col, fieldToUrl, tdb, fields[ix]); else if (asTypesIsFloating(col->lowType->type)) { double valDouble = strtod(fields[ix],NULL); if (errno == 0 && valDouble != 0) printf(" | %g | \n", valDouble); else printf("%s | \n", hubEncode(tdb, fields[ix])); // decided not to print error } else printf("%s | \n", hubEncode(tdb, fields[ix])); printCount++; } if (skipIds) slFreeList(skipIds); if (sepFields) slFreeList(sepFields); if (embeddedTblFields) { printf("
\n");
printf("#match\tmisMatches\trepMatches\tnCount\tqNumInsert\tqBaseInsert\ttNumInsert\tBaseInsert\tstrand\tqName\tqSize\tqStart\tqEnd\ttName\ttSize\ttStart\ttEnd\tblockCount\tblockSizes\tqStarts\ttStarts\n");
for (psl = pslList; psl != NULL; psl = psl->next)
{
pslTabOut(psl, stdout);
}
printf("\n");
}
struct twoBitFile *getTwoBitFileFromUrlInSettings(struct trackDb *tdb, char *settingName)
/* Assume settingName is a URL to a two bit file and try and return it */
{
struct twoBitFile *tbf = NULL;
char *url = trackDbSetting(tdb, settingName);
if (url != NULL)
tbf = twoBitOpen(url);
return tbf;
}
struct twoBitFile *getOtherTwoBitUrl(struct trackDb *tdb)
/* Return open two bit file if otherTwoBitUrl setting is present */
{
return getTwoBitFileFromUrlInSettings(tdb, "otherTwoBitUrl");
}
struct psl *getPslAndSeq(struct trackDb *tdb, char *chromName, struct bigBedInterval *bb,
unsigned seqTypeField, DNA **retSeq, char **retCdsStr)
/* Read in psl and query sequence out of a bbiInverval on a give chromosome */
{
struct psl *psl= pslFromBigPsl(chromName, bb, seqTypeField, retSeq, retCdsStr);
DNA *dna = *retSeq;
if (dna == NULL)
{
struct twoBitFile *otherTbf = getOtherTwoBitUrl(tdb);
struct dnaSeq *seq = NULL;
if (otherTbf)
{
seq = twoBitReadSeqFrag(otherTbf, psl->qName, 0, 0);
if (seq)
*retSeq = dna = seq->dna;
}
}
return psl;
}
void genericBigPslClick(struct sqlConnection *conn, struct trackDb *tdb,
char *item, int start, int end)
/* Handle click in big psl track. */
{
struct psl* pslList = NULL;
char *fileName = bbiNameFromSettingOrTable(tdb, conn, tdb->table);
struct bbiFile *bbi = bigBedFileOpenAlias(fileName, chromAliasFindAliases);
struct lm *lm = lmInit(0);
int ivStart = start, ivEnd = end;
if (start == end)
{
// item is an insertion; expand the search range from 0 bases to 2 so we catch it:
ivStart = max(0, start-1);
ivEnd++;
}
if (cfgOptionBooleanDefault("drawDot", FALSE))
bigPslDotPlot(tdb, bbi, seqName, winStart, winEnd);
boolean showEvery = sameString(item, "PrintAllSequences");
boolean showAll = trackDbSettingOn(tdb, "showAll");
unsigned seqTypeField = bbExtraFieldIndex(bbi, "seqType");
struct bigBedInterval *bb, *bbList = NULL;
struct hash *chainHash = NULL;
struct hash *mapPsls = NULL; // mapping alignments quickLift reuses across items
char *quickLiftFile = trackDbSetting(tdb, "quickLiftUrl");
// A quickLifted track can only show what the chains around this window reach, so it takes
// the windowed query even when the track asks for every alignment of the item. The file
// holds the other assembly's alignments, so the window has to be turned into that
// assembly's coordinates before the query. quickLiftGetIntervals also hands back the
// chains needed to bring the alignments the other way.
// If showAll is on, show all alignments with this qName, not just the
// selected one.
if (quickLiftFile != NULL)
bbList = quickLiftGetIntervals(quickLiftFile, bbi, seqName, ivStart, ivEnd, &chainHash);
else if (showEvery)
{
struct bbiChromInfo *chrom, *chromList = bbiChromList(bbi);
for (chrom = chromList; chrom != NULL; chrom = chrom->next)
{
char *chromName = chrom->name;
int start = 0, end = chrom->size;
int itemsLeft = 0; // Zero actually means no limit....
struct bigBedInterval *intervalList = bigBedIntervalQuery(bbi, chromName,
start, end, itemsLeft, lm);
slCat(&bbList, intervalList);
}
}
else if (showAll)
{
int fieldIx;
struct bptFile *bpt = bigBedOpenExtraIndex(bbi, "name", &fieldIx);
bbList = bigBedNameQuery(bbi, bpt, fieldIx, item, lm);
}
else
bbList = bigBedIntervalQuery(bbi, seqName, ivStart, ivEnd, 0, lm);
/* print out extra fields */
for (bb = bbList; bb != NULL; bb = bb->next)
{
char *restFields[256];
int restCount = chopTabs(cloneString(bb->rest), restFields);
if (sameString(restFields[0], item))
{
/* print standard position information */
char *strand = restFields[2];
int bedSize = 25;
int restBedFields = bedSize - 3;
struct slPair *extraFieldPairs = NULL;
if (restCount > restBedFields)
{
char **extraFields = (restFields + restBedFields);
int extraFieldCount = restCount - restBedFields;
extraFieldPairs = getExtraFields(tdb, extraFields, extraFieldCount);
char *itemForUrl = getIdInUrl(tdb, item);
printCustomUrlWithFields(tdb, item, item, item == itemForUrl, extraFieldPairs);
if (itemForUrl)
printIframe(tdb, itemForUrl);
printPos(seqName, ivStart, ivEnd, strand, FALSE, item);
int printCount = extraFieldsPrint(tdb,NULL,extraFields, extraFieldCount);
printCount += 0;
}
}
}
char *bedRow[32];
char startBuf[16], endBuf[16];
int lastChromId = -1;
char chromName[bbi->chromBpt->keySize+1];
boolean firstTime = TRUE;
struct hash *seqHash = hashNew(0);
struct dyString *sequencesText = dyStringNew(256);
int sequencesFound = 0;
for (bb = bbList; bb != NULL; bb = bb->next)
{
bbiCachedChromLookup(bbi, bb->chromId, lastChromId, chromName, sizeof(chromName));
lastChromId=bb->chromId;
bigBedIntervalToRow(bb, chromName, startBuf, endBuf, bedRow, 4);
if (showEvery || sameString(bedRow[3], item))
{
char *cdsStr, *seq;
struct psl *psl= getPslAndSeq(tdb, chromName, bb, seqTypeField, &seq, &cdsStr);
if (chainHash != NULL)
{
struct psl *lifted = quickLiftPsl(chainHash, &mapPsls, psl);
pslFree(&psl);
if (lifted == NULL)
continue; // nothing in the chains places this alignment
psl = lifted;
}
slAddHead(&pslList, psl);
// we're assuming that if there are multiple psl's with the same id that
// they are the same query sequence so we only put out one set of sequences
if (!hashLookup(seqHash, bedRow[3]) && !isEmpty(seq)) // if there is a query sequence
{
if (firstTime)
{
firstTime = FALSE;
printf("| Q1 | %f |
| median | %f |
| Q3 | %f |
| average | %f |
| min | %f |
| max | %f |
| count | %d |
| total | %f |
| standard deviation | %f |
| %s Position | %s Position | Bases | Alignment |
| %s | %s | ", ourPos, otherPos); printf("%.*s | ", hr->otherBaseCount, hr->otherBases); hgcAnchorSomewhereExt("htcChainAli", item, tdb->track, chain->tName, hr->chromStart - 10, hr->chromEnd + 10, tdb->track); printf("alignment |
| %s Position | %s Position | Bases | Alignment |
| %s | %s | ", ourPos, otherPos); printf("%.*s | ", hr->baseCount, hr->bases); hgcAnchorSomewhereExt("htcChainAli", item, tdb->track, chain->tName, hr->chromStart - 10, hr->chromEnd + 10, tdb->track); printf("alignment |
| %s Position | %s Position | # Bases in %s | #Bases in %s | Alignment |
| %s | %s | ", ourPos, otherPos); printf("%d | %d | ", hr->baseCount, hr->otherBaseCount); hgcAnchorSomewhereExt("htcChainAli", item, tdb->track, chain->tName, hr->chromStart - 10, hr->chromEnd + 10, tdb->track); printf("alignment |
| %s Position | %s Position | Change | Alignment |
| %s | %s | ", ourPos, otherPos); printf("%.*s -> %.*s | ", hr->otherBaseCount, hr->otherBases, hr->baseCount, hr->bases); hgcAnchorSomewhereExt("htcChainAli", item, tdb->track, chain->tName, hr->chromStart - 10, hr->chromEnd + 10, tdb->track); printf("alignment |
"); if (dbIsFound) puts("Note: The \"Mask repeats\" option applies only to \"Get DNA\", not to \"Extended case/color options\".
"); } boolean dnaIgnoreTrack(char *track) /* Return TRUE if this is one of the tracks too boring * to put DNA on. */ { return (sameString("cytoBand", track) || sameString("gcPercent", track) || sameString("gold", track) || sameString("gap", track) || startsWith("mouseSyn", track)); } struct customTrack *getCtList() /* initialize theCtList if necessary and return it */ { if (theCtList == NULL) theCtList = customTracksParseCart(database, cart, NULL, NULL); return(theCtList); } struct trackDb *tdbForCustomTracks() /* Load custom tracks (if any) and translate to list of trackDbs */ { struct customTrack *ctList = getCtList(); struct customTrack *ct; struct trackDb *tdbList = NULL, *tdb; for (ct=ctList; ct != NULL; ct=ct->next) { AllocVar(tdb); tdb->track = ct->tdb->track; tdb->table = ct->tdb->table; tdb->shortLabel = ct->tdb->shortLabel; tdb->type = ct->tdb->type; tdb->longLabel = ct->tdb->longLabel; tdb->visibility = ct->tdb->visibility; tdb->priority = ct->tdb->priority; tdb->colorR = ct->tdb->colorR; tdb->colorG = ct->tdb->colorG; tdb->colorB = ct->tdb->colorB; tdb->altColorR = ct->tdb->altColorR; tdb->altColorG = ct->tdb->altColorG; tdb->altColorB = ct->tdb->altColorB; tdb->useScore = ct->tdb->useScore; tdb->private = ct->tdb->private; tdb->url = ct->tdb->url; tdb->grp = ct->tdb->grp; tdb->canPack = ct->tdb->canPack; trackDbPolish(tdb); slAddHead(&tdbList, tdb); } slReverse(&tdbList); return(tdbList); } static struct trackDb *getCustomTrackTdb(char *table) /* Find the trackDb structure for a custom track table. */ { struct customTrack *ctList = getCtList(); struct customTrack *ct = NULL; for (ct = ctList; ct != NULL; ct = ct->next) if (sameString(table, ct->tdb->track)) return ct->tdb; return NULL; } struct trackDb *getTdbForTrackName(char *trackName) /* Given a track name (which may have ct_ or hub_ prepended), tdb */ { assert(trackHash != NULL); if (isCustomTrack(trackName)) return getCustomTrackTdb(trackName); else if (isHubTrack(trackName)) return hubConnectAddHubForTrackAndFindTdb( database, trackName, NULL, trackHash); else return hashMustFindVal(trackHash, trackName); } struct customTrack *lookupCt(char *name) /* Return custom track for name, or NULL. */ { struct customTrack *ct; for (ct=getCtList(); ct != NULL; ct=ct->next) if (sameString(name, ct->tdb->track)) return(ct); return(NULL); } void parseSs(char *ss, char **retPslName, char **retFaName, char **retQName) /* Parse space separated 'ss' item. */ { static char buf[512*2]; int wordCount; char *words[4]; /* SECURITY (refs #38054): ss comes from the cart variable of the same name, or from * the item name, and a visitor controls both. A legitimate value is a short triple * of trash file paths, so anything that does not fit is a bug or an attack. safecpy * aborts instead of writing past the end of the buffer, which matches the errAborts * below on the other malformed cases. */ safecpy(buf, sizeof buf, ss); wordCount = chopLine(buf, words); if (wordCount < 1) errAbort("Empty user cart variable ss."); *retPslName = words[0]; if (retFaName != NULL) { if (wordCount < 2) errAbort("Expecting psl filename and fa filename in cart variable ss, but only got one word: %s", ss); *retFaName = words[1]; } if (retQName != NULL) { if (wordCount < 3) errAbort("Expecting psl filename, fa filename and query name in cart variable ss, but got this: %s", ss); *retQName = words[2]; } } boolean ssFilesExist(char *ss) /* Return TRUE if both files in ss exist. -- Copied from hgTracks! */ { char *faFileName, *pslFileName; parseSs(ss, &pslFileName, &faFileName, NULL); return fileExists(pslFileName) && fileExists(faFileName); } struct trackDb *tdbForUserPsl() /* Load up user's BLAT results into trackDb. */ { char *ss = cartOptionalString(cart, "ss"); if ((ss != NULL) && !ssFilesExist(ss)) { ss = NULL; cartRemove(cart, "ss"); } if (ss == NULL) return(NULL); else { struct trackDb *tdb; AllocVar(tdb); tdb->track = cloneString(USER_PSL_TRACK_NAME); tdb->table = cloneString(USER_PSL_TRACK_NAME); tdb->shortLabel = cloneString(USER_PSL_TRACK_LABEL); tdb->type = cloneString("psl"); tdb->longLabel = cloneString(USER_PSL_TRACK_LONGLABEL); tdb->visibility = tvFull; tdb->priority = 11.0; trackDbPolish(tdb); return(tdb); } } struct trackDb *rFindUnderstandableTrack(char *db, struct trackDb *tdb) // If any leaf is usable in getting DNA then that leaf's tdb is returned. { if (tdb->subtracks != NULL) return rFindUnderstandableTrack(db,tdb->subtracks); if (fbUnderstandTrack(db, tdb) && !dnaIgnoreTrack(tdb->table)) return tdb; else return NULL; } boolean forestHasUnderstandableTrack(char *db, struct trackDb *tdb) // TRUE if any leaf is usable in getting DNA. { return (rFindUnderstandableTrack(db, tdb) != NULL); } struct trackDb* loadTracks() /* load native tracks, cts, userPsl and track Hubs and return tdbList */ { struct trackDb *tdbList = hTrackDb(database); struct trackDb *ctdbList = tdbForCustomTracks(); struct trackDb *utdbList = tdbForUserPsl(); struct grp *pGrpList = NULL; struct trackDb *hubList = hubCollectTracks(database, &pGrpList); ctdbList = slCat(ctdbList, tdbList); ctdbList = slCat(ctdbList, hubList); tdbList = slCat(utdbList, ctdbList); return tdbList; } static boolean parseDnaPos(char *db, char *pos, char **retChrom, int *retStart, int *retEnd) /* Parse a position string that may be chrom:start-end or just chrom:pos (single base). */ { if (hgParseChromRange(db, pos, retChrom, retStart, retEnd)) return TRUE; /* check for single position like chrX:67774500 (colon but no dash) */ char *colon = strchr(pos, ':'); if (colon != NULL && strchr(colon, '-') == NULL) { struct dyString *dy = dyStringCreate("%s-%s", pos, colon + 1); boolean result = hgParseChromRange(db, dy->string, retChrom, retStart, retEnd); dyStringFree(&dy); return result; } return FALSE; } void doGetDnaExtended1() /* Do extended case/color get DNA options. */ { boolean revComp = cartUsualBoolean(cart, "hgSeq.revComp", FALSE); boolean maskRep = cartUsualBoolean(cart, "hgSeq.maskRepeats", FALSE); int padding5 = cartUsualInt(cart, "hgSeq.padding5", 0); int padding3 = cartUsualInt(cart, "hgSeq.padding3", 0); int lineWidth = cartUsualInt(cart, "lineWidth", 60); char *casing = cartUsualString(cart, "hgSeq.casing", ""); char *repMasking = cartUsualString(cart, "hgSeq.repMasking", ""); boolean caseUpper= FALSE; char *pos = NULL; struct trackDb *tdbList = loadTracks(); cartWebStart(cart, database, "Extended DNA Case/Color"); if (NULL != (pos = stripCommas(cartOptionalString(cart, "getDnaPos")))) parseDnaPos(database, pos, &seqName, &winStart, &winEnd); if (winEnd - winStart > 5000000) { printf("Please zoom in to 5 million bases or less to color the DNA"); return; } printf("
"); if (cgiBooleanDefined("hgSeq.maskRepeats")) cartSetBoolean(cart, "hgSeq.maskRepeats", maskRep); if (*repMasking != 0) cartSetString(cart, "hgSeq.repMasking", repMasking); if (maskRep) { struct trackDb *rtdb; char *visString = cartOptionalString(cart, "rmsk"); for (rtdb = tdbList; rtdb != NULL; rtdb=rtdb->next) { if (startsWith(rtdb->table, "rmsk")) break; } printf("
Note: repeat masking style from previous page will not apply to this page.\n"); if ((rtdb != NULL) && ((visString == NULL) || !sameString(visString, "hide"))) printf("Use the case/color options for the RepeatMasker track below.
\n"); else printf("Unhide the RepeatMasker track in the genome browser, then return to this page and use the case/color options for the RepeatMasker track below.
\n"); } cartSetInt(cart, "padding5", padding5); cartSetInt(cart, "padding3", padding3); if (sameString(casing, "upper")) caseUpper = TRUE; if (*casing != 0) cartSetString(cart, "hgSeq.casing", casing); printf("
\n"); printf("Copying and pasting the web page output to a text editor such as Word " "will retain upper case but lose colors and other formatting. That is still " "useful because other web tools such as " "NCBI Blast " "can be set to ignore lower case. To fully capture formatting such as color " "and underlining, view the output as \"source\" in your web browser, or download " "it, or copy the output page into an html editor.
"); puts("The default line width of 60 characters is standard, but if you have " "a reasonable sized monitor it's useful to set this higher - to 125 characters " "or more. You can see more DNA at once this way, and fewer line breaks help " "in finding DNA strings using the web browser search function.
"); puts("Be careful about requesting complex formatting for a very large " "chromosomal region. After all the html tags are added to the output page, " "the file size may exceed size limits that your browser, clipboard, and " "other software can safely display. The tool will format 10 Mb and more, however.
"); trackDbFreeList(&tdbList); } void doGetBlastPep(char *readName, char *table) /* get predicted protein */ { int qStart; struct psl *psl; int start, end; struct sqlResult *sr; struct sqlConnection *conn = hAllocConn(database); struct dnaSeq *tSeq; char query[256], **row; char fullTable[HDB_MAX_TABLE_STRING]; boolean hasBin; char *buffer, *str; int i, j; char *ptr; start = cartInt(cart, "o"); if (!hFindSplitTable(database, seqName, table, fullTable, sizeof fullTable, &hasBin)) errAbort("doGetBlastPep track %s not found", table); sqlSafef(query, sizeof query, "select * from %s where qName = '%s' and tName = '%s' and tStart=%d", fullTable, readName, seqName, start); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) == NULL) errAbort("Couldn't find alignment for %s at %d", readName, start); psl = pslLoad(row+hasBin); sqlFreeResult(&sr); hFreeConn(&conn); printf("");
end = psl->tEnd;
if (psl->strand[1] == '+')
end = psl->tStarts[psl->blockCount - 1] + psl->blockSizes[psl->blockCount - 1] *3;
if ((ptr = strchr(readName, '.')) != NULL)
*ptr++ = 0;
printf(">%s-%s\n", readName,database);
tSeq = hDnaFromSeq(database, psl->tName, start, end, dnaLower);
if (psl->strand[1] == '-')
{
start = psl->tSize - end;
reverseComplement(tSeq->dna, tSeq->size);
}
str = buffer = needMem(psl->qSize + 1);
qStart = 0;
for (i=0; iblockCount; ++i)
{
int ts = psl->tStarts[i] - start;
int sz = psl->blockSizes[i];
for (;qStart < psl->qStarts[i]; qStart++)
*str++ = 'X';
for (j=0; jdna[codonStart];
if ((*str = lookupCodon(codon)) == 0)
*str = '*';
str++;
qStart++;
}
}
*str = 0;
printLines(stdout, buffer, 50);
printf(" ");
}
void doGetDna2()
/* Do second DNA dialog (or just fetch DNA) */
{
char *tbl = cgiUsualString("table", "");
char *action = cgiUsualString("submit", "");
int itemCount;
char *pos = NULL;
char *chrom = NULL;
int start = 0;
int end = 0;
if (sameString(action, EXTENDED_DNA_BUTTON))
{
doGetDnaExtended1();
return;
}
// This output probably should be just text/plain but
// trying to support the fancy warn handler box requires html.
// But we want to keep it very simple and close to a plain text dump.
cartHtmlStart("DNA");
puts("");
if (tbl[0] == 0)
{
itemCount = 1;
if ( NULL != (pos = stripCommas(cartOptionalString(cart, "getDnaPos"))) &&
parseDnaPos((dbIsFound ? database : NULL), pos, &chrom, &start, &end))
{
hgSeqRange(database, chrom, start, end, '?', "dna");
}
else
{
hgSeqRange(database, seqName, cartInt(cart, "l"), cartInt(cart, "r"),
'?', "dna");
}
}
else
{
struct hTableInfo *hti = NULL;
char rootName[HDB_MAX_TABLE_STRING];
char parsedChrom[HDB_MAX_CHROM_STRING];
/* use the values from the dnaPos dialog box */
if (!( NULL != (pos = stripCommas(cartOptionalString(cart, "getDnaPos"))) &&
parseDnaPos(database, pos, &chrom, &start, &end)))
{
/* if can't get DnaPos from dialog box, use "o" and "t" */
start = cartInt(cart, "o");
end = cartInt(cart, "t");
}
else
{
seqName = chrom;
}
/* Table might be a custom track if it's not in the database,
* or bigBed if it is in the database but has only one column called 'fileName';
* in which case, just get DNA as if no table were given. */
hParseTableName(database, tbl, rootName, parsedChrom);
if (!trackHubDatabase(database))
hti = hFindTableInfo(database, seqName, rootName);
if (hti == NULL || hti->startField[0] == 0)
{
itemCount = 1;
hgSeqRange(database, seqName, start, end, '?', tbl);
}
else
{
char *where = NULL;
char *item = cgiUsualString("i", "");
char buf[256];
if ((hti->nameField[0] != 0) && (item[0] != 0))
{
sqlSafef(buf, sizeof(buf), "%s = '%s'", hti->nameField, item);
where = buf;
}
itemCount = hgSeqItemsInRange(database, tbl, seqName, start, end, where);
}
}
if (itemCount == 0)
printf("\n# No results returned from query.\n\n");
puts("");
}
struct hTableInfo *ctToHti(struct customTrack *ct)
/* Create an hTableInfo from a customTrack. */
{
struct hTableInfo *hti;
AllocVar(hti);
hti->rootName = cloneString(ct->tdb->table);
hti->isPos = TRUE;
hti->isSplit = FALSE;
hti->hasBin = FALSE;
hti->type = cloneString(ct->tdb->type);
int fieldCount = 3;
if (sameWord(ct->dbTrackType, "bedDetail"))
fieldCount = ct->fieldCount - 2;
else if (sameWord(ct->dbTrackType, "pgSnp"))
fieldCount = 4;
else
fieldCount = ct->fieldCount;
if (fieldCount >= 3)
{
strncpy(hti->chromField, "chrom", 32);
strncpy(hti->startField, "chromStart", 32);
strncpy(hti->endField, "chromEnd", 32);
}
if (fieldCount >= 4)
{
strncpy(hti->nameField, "name", 32);
}
if (fieldCount >= 5)
{
strncpy(hti->scoreField, "score", 32);
}
if (fieldCount >= 6)
{
strncpy(hti->strandField, "strand", 32);
}
if (fieldCount >= 8)
{
strncpy(hti->cdsStartField, "thickStart", 32);
strncpy(hti->cdsEndField, "thickEnd", 32);
hti->hasCDS = TRUE;
}
if (fieldCount >= 12)
{
strncpy(hti->countField, "blockCount", 32);
strncpy(hti->startsField, "chromStarts", 32);
strncpy(hti->endsSizesField, "blockSizes", 32);
hti->hasBlocks = TRUE;
}
return(hti);
}
struct hTableInfo *htiForUserPsl()
/* Create an hTableInfo for user's BLAT results. */
{
struct hTableInfo *hti;
AllocVar(hti);
hti->rootName = cloneString(USER_PSL_TRACK_NAME);
hti->isPos = TRUE;
hti->isSplit = FALSE;
hti->hasBin = FALSE;
hti->type = cloneString("psl");
strncpy(hti->chromField, "tName", 32);
strncpy(hti->startField, "tStart", 32);
strncpy(hti->endField, "tEnd", 32);
strncpy(hti->nameField, "qName", 32);
/* psl can be scored... but strictly speaking, does not have a score field! */
strncpy(hti->strandField, "strand", 32);
hti->hasCDS = FALSE;
strncpy(hti->countField, "blockCount", 32);
strncpy(hti->startsField, "tStarts", 32);
strncpy(hti->endsSizesField, "tSizes", 32);
hti->hasBlocks = TRUE;
return(hti);
}
struct bed *bedFromUserPsl()
/* Load up user's BLAT results into bedList. */
{
struct bed *bedList = NULL;
char *ss = cartOptionalString(cart, "ss");
if ((ss != NULL) && ! ssFilesExist(ss))
{
ss = NULL;
cartRemove(cart, "ss");
}
if (ss == NULL)
return(NULL);
else
{
struct lineFile *f;
struct psl *psl;
enum gfType qt, tt;
char *faFileName, *pslFileName;
int i;
parseSs(ss, &pslFileName, &faFileName, NULL);
pslxFileOpen(pslFileName, &qt, &tt, &f);
while ((psl = pslNext(f)) != NULL)
{
struct bed *bed;
AllocVar(bed);
bed->chrom = cloneString(seqName);
bed->chromStart = psl->tStart;
bed->chromEnd = psl->tEnd;
bed->name = cloneString(psl->qName);
bed->score = pslScore(psl);
if ((psl->strand[0] == '-' && psl->strand[1] == '+') ||
(psl->strand[0] == '+' && psl->strand[1] == '-'))
strncpy(bed->strand, "-", 2);
else
strncpy(bed->strand, "+", 2);
bed->thickStart = bed->chromStart;
bed->thickEnd = bed->chromEnd;
bed->blockCount = psl->blockCount;
bed->chromStarts = needMem(bed->blockCount * sizeof(int));
bed->blockSizes = needMem(bed->blockCount * sizeof(int));
for (i=0; i < bed->blockCount; i++)
{
bed->chromStarts[i] = psl->tStarts[i];
bed->blockSizes[i] = psl->blockSizes[i];
}
if (qt == gftProt)
for (i=0; i < bed->blockCount; i++)
{
/* If query is protein, blockSizes are in aa units; fix 'em. */
bed->blockSizes[i] *= 3;
}
if (psl->strand[1] == '-')
{
/* psl: if target strand is '-', flip the coords.
* (this is the target part of pslRc from src/lib/psl.c) */
for (i=0; i < bed->blockCount; ++i)
{
bed->chromStarts[i] =
psl->tSize - (bed->chromStarts[i] +
bed->blockSizes[i]);
}
reverseInts(bed->chromStarts, bed->blockCount);
reverseInts(bed->blockSizes, bed->blockCount);
assert(bed->chromStart == bed->chromStarts[0]);
}
/* translate absolute starts to relative starts (after handling
* target-strand coord-flipping) */
for (i=0; i < bed->blockCount; i++)
{
bed->chromStarts[i] -= bed->chromStart;
}
slAddHead(&bedList, bed);
pslFree(&psl);
}
lineFileClose(&f);
slReverse(&bedList);
return(bedList);
}
}
void addColorToRange(int r, int g, int b, struct rgbColor *colors, int start, int end)
/* Add rgb values to colors array from start to end. Don't let values
* exceed 255 */
{
struct rgbColor *c;
int rr, gg, bb;
int i;
for (i=start; i");
printf(">%s:%d-%d %s\n", seqName, winStart+1, winEnd,
(isRc ? "(reverse complement)" : ""));
seq = hDnaFromSeq(database, seqName, winStart, winEnd, dnaLower);
if (isRc)
reverseComplement(seq->dna, seq->size);
if (defaultUpper)
touppers(seq->dna);
AllocArray(colors, winSize);
struct trackDb* tdb;
for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
{
char *track = tdb->track;
char *table = tdb->table;
struct featureBits *fbList = NULL, *fb;
struct customTrack *ct = lookupCt(track);
if (sameString(USER_PSL_TRACK_NAME, table)
|| ct != NULL
|| ( tdbVisLimitedByAncestors(cart,tdb,TRUE,TRUE) != tvHide
&& forestHasUnderstandableTrack(database, tdb) ) )
{
char buf[256];
int r,g,b;
/* to save a LOT of time, don't fetch track features unless some
* coloring/formatting has been specified for them. */
boolean hasSettings = FALSE;
safef(buf, sizeof(buf), "%s_u", track);
hasSettings |= cgiBoolean(buf);
safef(buf, sizeof(buf), "%s_b", track);
hasSettings |= cgiBoolean(buf);
safef(buf, sizeof(buf), "%s_i", track);
hasSettings |= cgiBoolean(buf);
safef(buf, sizeof(buf), "%s_case", track);
hasSettings |= cgiBoolean(buf);
safef(buf, sizeof(buf), "%s_red", track);
hasSettings |= (cgiOptionalInt(buf, 0) != 0);
safef(buf, sizeof(buf), "%s_green", track);
hasSettings |= (cgiOptionalInt(buf, 0) != 0);
safef(buf, sizeof(buf), "%s_blue", track);
hasSettings |= (cgiOptionalInt(buf, 0) != 0);
if (! hasSettings)
continue;
if (sameString(USER_PSL_TRACK_NAME, track))
{
struct hTableInfo *hti = htiForUserPsl();
struct bedFilter *bf;
struct bed *bedList, *bedList2;
AllocVar(bf);
bedList = bedFromUserPsl();
bedList2 = bedFilterListInRange(bedList, bf, seqName, winStart,
winEnd);
fbList = fbFromBed(database, track, hti, bedList2, winStart, winEnd,
TRUE, FALSE);
bedFreeList(&bedList);
bedFreeList(&bedList2);
}
else if (ct != NULL)
{
struct hTableInfo *hti = ctToHti(ct);
struct bedFilter *bf;
struct bed *bedList2, *ctBedList = NULL;
AllocVar(bf);
if (ct->dbTrack && (!sameString(tdb->type, "vcf")))
{
struct bed *bed;
int fieldCount = ct->fieldCount;
if ((ct->dbTrackType != NULL) && sameString(ct->dbTrackType, "pgSnp"))
fieldCount = 4;
char query[512];
int rowOffset;
char **row;
struct sqlConnection *conn = hAllocConn(CUSTOM_TRASH);
struct sqlResult *sr = NULL;
sqlSafef(query, sizeof(query), "select * from %s", ct->dbTableName);
sr = hRangeQuery(conn, ct->dbTableName, seqName,
winStart, winEnd, NULL, &rowOffset);
while ((row = sqlNextRow(sr)) != NULL)
{
bed = bedLoadN(row+rowOffset, fieldCount);
if (bf == NULL || bedFilterOne(bf, bed))
{
struct bed *copy = cloneBed(bed);
slAddHead(&ctBedList, copy);
}
}
sqlFreeResult(&sr);
hFreeConn(&conn);
}
else if (sameString(ct->dbTrackType, "bigBed"))
{
struct lm *lm = lmInit(0);
struct bigBedInterval *bb, *bbList = bigBedIntervalQuery(ct->bbiFile, seqName, winStart, winEnd, 0, lm);
char *bedRow[32];
char startBuf[16], endBuf[16];
for (bb = bbList; bb != NULL; bb = bb->next)
{
bigBedIntervalToRow(bb, seqName, startBuf, endBuf, bedRow, ArraySize(bedRow));
struct bed *bed = bedLoadN(bedRow, ct->bbiFile->definedFieldCount);
slAddHead(&ctBedList, bed);
}
}
else
{
ctBedList = ct->bedList;
}
if (startsWith("vcf", tdb->type))
{
fbList = vcfLoadInterval(ct->tdb, winStart, winEnd);
}
else
{
bedList2 = bedFilterListInRange(ctBedList, bf, seqName, winStart,
winEnd);
fbList = fbFromBed(database, track, hti, bedList2, winStart, winEnd,
TRUE, FALSE);
bedFreeList(&bedList2);
}
if (!ct->bedList)
bedFreeList(&ctBedList);
}
else
{
if (tdb->subtracks)
{
struct slRef *refLeaves = trackDbListGetRefsToDescendantLeaves(tdb->subtracks);
struct slRef *refLeaf = NULL;
while ((refLeaf = slPopHead(&refLeaves)) != NULL)
{
struct trackDb *tdbLeaf = refLeaf->val;
if (tdbVisLimitedByAncestors(cart,tdbLeaf,TRUE,TRUE) != tvHide
&& fbUnderstandTrack(database, tdbLeaf)
&& !dnaIgnoreTrack(tdbLeaf->table))
{
struct featureBits *fbLeafList;
if (startsWith("vcf", tdbLeaf->type))
fbLeafList = vcfLoadInterval(tdbLeaf, winStart, winEnd);
else if (startsWith("big", tdbLeaf->type))
fbLeafList = getBigBedFbList(tdbLeaf, seqName, winStart, winEnd);
else
fbLeafList = fbGetRange(database, tdbLeaf->table, seqName, winStart, winEnd);
if (fbLeafList != NULL)
fbList = slCat(fbList,fbLeafList);
}
freeMem(refLeaf);
}
}
else
{
if (startsWith("vcf", tdb->type))
fbList = vcfLoadInterval(tdb, winStart, winEnd);
else if (startsWith("big", tdb->type))
fbList = getBigBedFbList(tdb, seqName, winStart, winEnd);
else
fbList = fbGetRange(database, tdb->table, seqName, winStart, winEnd);
}
}
/* Flip underline/italic/bold bits. */
getDnaHandleBits(track, "u", uBits, winStart, winEnd, isRc, fbList);
getDnaHandleBits(track, "b", bBits, winStart, winEnd, isRc, fbList);
getDnaHandleBits(track, "i", iBits, winStart, winEnd, isRc, fbList);
/* Toggle case if necessary. */
safef(buf, sizeof buf, "%s_case", track);
if (cgiBoolean(buf))
{
for (fb = fbList; fb != NULL; fb = fb->next)
{
DNA *dna;
int start = fb->start - winStart;
int end = fb->end - winStart;
int size = fb->end - fb->start;
if (isRc)
reverseIntRange(&start, &end, seq->size);
dna = seq->dna + start;
if (defaultUpper)
toLowerN(dna, size);
else
toUpperN(dna, size);
}
}
/* Add in RGB values if necessary. */
safef(buf, sizeof buf, "%s_red", track);
r = cartInt(cart, buf);
safef(buf, sizeof buf, "%s_green", track);
g = cartInt(cart, buf);
safef(buf, sizeof buf, "%s_blue", track);
b = cartInt(cart, buf);
if (r != 0 || g != 0 || b != 0)
{
for (fb = fbList; fb != NULL; fb = fb->next)
{
int s = fb->start - winStart;
int e = fb->end - winStart;
if (isRc)
reverseIntRange(&s, &e, winEnd - winStart);
addColorToRange(r, g, b, colors, s, e);
}
}
}
}
cfm = cfmNew(0, lineWidth, FALSE, FALSE, stdout, 0);
for (i=0; isize; ++i)
{
struct rgbColor *color = colors+i;
int c = (color->r<<16) + (color->g<<8) + color->b;
cfmOutExt(cfm, seq->dna[i], c,
bitReadOne(uBits, i), bitReadOne(bBits, i), bitReadOne(iBits, i));
}
cfmFree(&cfm);
freeDnaSeq(&seq);
bitFree(&uBits);
bitFree(&iBits);
bitFree(&bBits);
}
void medlineLinkedTermLine(char *title, char *text, char *search, char *keyword)
/* Produce something that shows up on the browser as
* TITLE: value
* with the value hyperlinked to medline using a specified search term. */
{
char *encoded = cgiEncode(search);
char *encodedKeyword = cgiEncode(keyword);
printf("%s: ", title);
if (sameWord(text, "n/a") || sameWord(text, "none"))
printf("n/a
\n");
else
{
printf("%s
\n", text);
}
freeMem(encoded);
}
void medlineLinkedLine(char *title, char *text, char *search)
/* Produce something that shows up on the browser as
* TITLE: value
* with the value hyperlinked to medline. */
{
char *encoded = cgiEncode(search);
printf("%s: ", title);
if (sameWord(text, "n/a"))
printf("n/a
\n");
else
{
printf("%s
\n", text);
}
freeMem(encoded);
}
void medlineProductLinkedLine(char *title, char *text)
/* Produce something that shows up on the browser as
* TITLE: value
* with the value hyperlinked to medline.
* Replaces commas in the product name with spaces, as commas sometimes
* interfere with PubMed search */
{
subChar(text, ',', ' ');
medlineLinkedLine(title, text, text);
}
void appendAuthor(struct dyString *dy, char *gbAuthor, int len)
/* Convert from Kent,W.J. to Kent WJ and append to dy.
* gbAuthor gets eaten in the process.
* Also strip web URLs since Entrez doesn't like those. */
{
char buf[MAXURLSIZE];
char *ptr;
if (len >= sizeof(buf))
warn("author %s too long to process", gbAuthor);
else
{
memcpy(buf, gbAuthor, len);
buf[len] = 0;
stripChar(buf, '.');
subChar(buf, ',' , ' ');
if ((ptr = strstr(buf, " http://")) != NULL)
*ptr = 0;
if ((ptr = strstr(buf, " https://")) != NULL)
*ptr = 0;
dyStringAppend(dy, buf);
dyStringAppend(dy, " ");
}
}
void gbToEntrezAuthor(char *authors, struct dyString *dy)
/* Convert from Genbank author format:
* Kent,W.J., Haussler,D. and Zahler,A.M.
* to Entrez search format:
* Kent WJ,Haussler D,Zahler AM
*/
{
char *s = authors, *e;
/* Parse first authors, which will be terminated by '.,' */
while ((e = strstr(s, ".,i ")) != NULL)
{
int len = e - s + 1;
appendAuthor(dy, s, len);
s += len+2;
}
if ((e = strstr(s, " and")) != NULL)
{
int len = e - s;
appendAuthor(dy, s, len);
s += len+4;
}
if ((s = skipLeadingSpaces(s)) != NULL && s[0] != 0)
{
int len = strlen(s);
appendAuthor(dy, s, len);
}
}
/* --- !!! Riken code is under development Fan. 4/16/02 */
void printRikenInfo(char *acc, struct sqlConnection *conn )
/* Print Riken annotation info */
{
struct sqlResult *sr;
char **row;
char query[512];
char *seqid, *accession, *comment;
// char *qualifier, *anntext, *datasrc, *srckey, *href, *evidence;
accession = acc;
sqlSafef(query, sizeof(query),
"select seqid from rikenaltid where altid='%s';", accession);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
if (row != NULL)
{
seqid=cloneString(row[0]);
sqlSafef(query, sizeof(query),
"select Qualifier, Anntext, Datasrc, Srckey, Href, Evidence "
"from rikenann where seqid='%s';", seqid);
sqlFreeResult(&sr);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
while (row !=NULL)
{
// qualifier = row[0]; unused variable
// anntext = row[1]; unused variable
// datasrc = row[2]; unused variable
// srckey = row[3]; unused variable
// href = row[4]; unused variable
// evidence = row[5]; unused variable
row = sqlNextRow(sr);
}
sqlSafef(query, sizeof(query),
"select comment from rikenseq where id='%s';", seqid);
sqlFreeResult(&sr);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
if (row != NULL)
{
comment = row[0];
printf("Riken/comment: %s
\n",comment);
}
}
}
void printGeneCards(char *db, char *geneName)
/* Print out a link to GeneCards (Human only).
* Caller passes the assembly db so quickLifted callers can pass the source
* (quickLiftDb) rather than the destination hub_NNN_. */
{
if (startsWith("hg", db) && isNotEmpty(geneName))
{
printf("GeneCards: "
"%s
\n",
geneName, geneName);
}
}
int getImageId(struct sqlConnection *conn, char *acc)
/* get the image id for a clone, or 0 if none */
{
int imageId = 0;
if (sqlTableExists(conn, imageCloneTable))
{
struct sqlResult *sr;
char **row;
char query[128];
sqlSafef(query, sizeof(query),
"select imageId from %s where acc = '%s'",imageCloneTable, acc);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
if (row != NULL)
imageId = sqlUnsigned(row[0]);
sqlFreeResult(&sr);
}
return imageId;
}
void htcDisplayMrna(char *acc)
/* Display mRNA available from genback or seq table.. */
{
struct dnaSeq *seq = hGenBankGetMrna(database, acc, NULL);
if (seq == NULL)
errAbort("mRNA sequence %s not found", acc);
cartHtmlStart("mRNA sequence");
printf("");
faWriteNext(stdout, seq->name, seq->dna, seq->size);
printf("");
dnaSeqFree(&seq);
}
static int getEstTranscriptionDir(struct sqlConnection *conn, struct psl *psl)
/* get the direction of transcription for an EST; return splice support count */
{
char query[256], estOrient[64];
sqlSafef(query, sizeof(query),
"select intronOrientation from %s.estOrientInfo where chrom = '%s' and chromStart = %d and name = '%s'",
database, psl->tName, psl->tStart, psl->qName);
if (sqlQuickQuery(conn, query, estOrient, sizeof(estOrient)) != NULL)
return sqlSigned(estOrient) * ((psl->strand[0] == '+') ? 1 : -1);
else
return 0;
}
static struct gbWarn *checkGbWarn(struct sqlConnection *conn, char *acc)
/* check if there is a gbWarn entry for this accession, return NULL if none */
{
struct gbWarn *gbWarn = NULL;
if (sqlTableExists(conn, gbWarnTable))
gbWarn = sqlQueryObjs(conn, (sqlLoadFunc)gbWarnLoad, sqlQuerySingle,
"SELECT * FROM %s WHERE acc = \"%s\"", gbWarnTable, acc);
return gbWarn;
}
static void printGbWarn(char *acc, struct gbWarn *gbWarn)
/* print descriptive information about an accession in the gbWarn table */
{
char *msg = NULL;
switch (gbWarn->reason) {
case gbWarnInvitroNorm:
msg = "is from the InVitroGen/Genoscope full-length library. Some of the entries "
"associated with this dataset appear to have been aligned to the reference "
"genome and the sequences subsequently modified to match the genome. This "
"process may have resulted in apparent high-quality alignments to pseudogenes.";
break;
case gbWarnAthRage:
msg = "is from the Athersys RAGE library. These sequences were created by inducing expression and may not "
"be an indication of in vivo expression.";
break;
case gbWarnOrestes:
msg = "is from an ORESTES library. This protocol includes a PCR step subject to genomic contamination.";
break;
}
assert(msg != NULL);
char *msg2= "Care should be taken in using alignments of this sequence as evidence of transcription.";
printf("Warning: %s %s %s
\n", acc, msg, msg2);
}
static void printRnaSpecs(struct trackDb *tdb, char *acc, struct psl *psl)
/* Print auxiliarry info on RNA. */
{
struct dyString *dy = dyStringNew(1024);
struct sqlConnection *conn = hAllocConn(database);
struct sqlConnection *conn2= hAllocConn(database);
struct sqlResult *sr;
char **row;
char rgdEstId[512];
char query[256];
char *type,*direction,*orgFullName,*library,*clone,*sex,*tissue,
*development,*cell,*cds,*description, *author,*geneName,
*date,*productName;
// char *source; unused variable
// int seqSize,fileSize; unused variables
// long fileOffset; unused variable
// char *extFile; unused variable
boolean hasVersion = hHasField(database, gbCdnaInfoTable, "version");
boolean haveGbSeq = sqlTableExists(conn, gbSeqTable);
char *seqTbl = haveGbSeq ? gbSeqTable : "seq";
char *version = NULL;
struct trackDb *tdbRgdEst;
char *chrom = cartString(cart, "c");
int start = cartInt(cart, "o");
int end = cartUsualInt(cart, "t",0);
struct gbWarn *gbWarn = checkGbWarn(conn, acc);
/* This sort of query and having to keep things in sync between
* the first clause of the select, the from clause, the where
* clause, and the results in the row ... is really tedious.
* One of my main motivations for going to a more object
* based rather than pure relational approach in general,
* and writing 'autoSql' to help support this. However
* the pure relational approach wins for pure search speed,
* and these RNA fields are searched. So it looks like
* the code below stays. Be really careful when you modify
* it.
*
* Uses the gbSeq table if available, otherwise use seq for older databases.
*/
sqlDyStringPrintf(dy,
"select g.type,g.direction,"
"so.name,o.name,l.name,m.name,"
"se.name,t.name,dev.name,ce.name,cd.name,"
"des.name,a.name,gene.name,p.name,"
"gbS.size,g.moddate,gbS.gbExtFile,gbS.file_offset,gbS.file_size ");
/* If the gbCdnaInfoTAble table has a "version" column then will show it */
if (hasVersion)
{
sqlDyStringPrintf(dy,
", g.version ");
}
sqlDyStringPrintf(dy,
" from %s g,%s gbS,%s so,%s o,%s l,%s m,%s se,%s t,"
"%s dev,%s ce,%s cd,%s des,%s a,%s gene,%s p"
" where g.acc = '%s' and g.id = gbS.id ",
gbCdnaInfoTable,seqTbl, sourceTable, organismTable, libraryTable, mrnaCloneTable, sexTable, tissueTable, developmentTable, cellTable, cdsTable, descriptionTable, authorTable, geneNameTable, productNameTable, acc);
sqlDyStringPrintf(dy,
"and g.source = so.id and g.organism = o.id "
"and g.library = l.id and g.mrnaClone = m.id "
"and g.sex = se.id and g.tissue = t.id "
"and g.development = dev.id and g.cell = ce.id "
"and g.cds = cd.id and g.description = des.id "
"and g.author = a.id and g.geneName = gene.id "
"and g.productName = p.id");
sr = sqlMustGetResult(conn, dy->string);
row = sqlNextRow(sr);
if (row != NULL)
{
type=row[0];direction=row[1];
// source=row[2]; unused variable
orgFullName=row[3];library=row[4];clone=row[5];
sex=row[6];tissue=row[7];development=row[8];cell=row[9];cds=row[10];description=row[11];
author=row[12];geneName=row[13];productName=row[14];
// seqSize = sqlUnsigned(row[15]); unused variable
date = row[16];
// ext_file = row[17]; unused variable
// fileOffset=sqlUnsigned(row[18]); unused variable
// fileSize=sqlUnsigned(row[19]); unused variable
boolean isEst = sameWord(type, "est");
if (hasVersion)
{
version = row[20];
}
/* Now we have all the info out of the database and into nicely named
* local variables. There's still a few hoops to jump through to
* format this prettily on the web with hyperlinks to NCBI. */
printf("Information on %s %s
\n", acc);
printf("Description: %s
\n", description);
if (gbWarn != NULL)
printGbWarn(acc, gbWarn);
medlineLinkedLine("Gene", geneName, geneName);
medlineProductLinkedLine("Product", productName);
dyStringClear(dy);
gbToEntrezAuthor(author, dy);
medlineLinkedLine("Author", author, dy->string);
printf("Organism: ");
printf("",
cgiEncode(orgFullName));
printf("%s
\n", orgFullName);
printf("Tissue: %s
\n", tissue);
printf("Development stage: %s
\n", development);
printf("Cell line: %s
\n", cell);
printf("Sex: %s
\n", sex);
printf("Library: %s
\n", library);
printf("Clone: %s
\n", clone);
if (isEst)
{
printf("Read direction: ");
if (direction[0] != '0')
printf("%s' (guessed from GenBank description)
\n", direction);
else
printf("unknown (can't guess from GenBank description)
");
}
else
printf("CDS: %s
\n", cds);
printf("Date: %s
\n", date);
if (hasVersion)
{
printf("Version: %s
\n", version);
}
/* print RGD EST Report link if it is Rat genome and it has a link to RGD */
if (sameWord(organism, "Rat"))
{
if (hTableExists(database, "rgdEstLink"))
{
sqlSafef(query, sizeof(query),
"select id from %s.rgdEstLink where name = '%s';", database, acc);
if (sqlQuickQuery(conn2, query, rgdEstId, sizeof(rgdEstId)) != NULL)
{
tdbRgdEst = hashFindVal(trackHash, "rgdEst");
printf("RGD EST Report: ");
printf("", tdbRgdEst->url, rgdEstId);
printf("RGD:%s
\n", rgdEstId);
}
}
}
if (isEst && hTableExists(database, "estOrientInfo") && (psl != NULL))
{
int estOrient = getEstTranscriptionDir(conn2, psl);
if (estOrient != 0)
printf("EST transcribed from %c strand (supported by %d splice sites).
\n",
(estOrient > 0 ? '+' : '-' ), abs(estOrient));
}
if (hGenBankHaveSeq(database, acc, NULL))
{
printf("%s sequence: ", type);
hgcAnchorSomewhere("htcDisplayMrna", acc, tdb->track, seqName);
printf("%s
\n", acc);
}
}
else
{
warn("Couldn't find %s in %s table", gbCdnaInfoTable, acc);
}
if (end != 0 && differentString(chrom,"0") && isNotEmpty(chrom))
{
printf("Position: "
"",
hgTracksPathAndSettings(), database, chrom, start+1, end);
printf("%s:%d-%d
\n", chrom, start+1, end);
}
gbWarnFree(&gbWarn);
sqlFreeResult(&sr);
dyStringFree(&dy);
hFreeConn(&conn);
hFreeConn(&conn2);
}
static char *aliTrackParam()
/* "&aliTrack=