038c31ecb2bd9e59311bb3009646ddc5374fa9d6
galt
Fri Jul 13 23:06:35 2018 -0700
hgc functions using framesets and a few other odd places that make their own html head were tweaked to include the CSP header. Thisis also helpful with early errors. refs #21729
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 33521b7..481bdec 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -590,30 +590,41 @@
}
void hgcAnchor(char *group, char *item, char *other)
/* Generate an anchor that calls click processing program with item
* and other parameters. */
{
hgcAnchorSomewhere(group, item, other, seqName);
}
void writeFramesetType()
/* Write document type that shows a frame set, rather than regular HTML. */
{
fputs("\n", stdout);
}
+void htmlFramesetStart(char *title)
+/* Write DOCTYPE HTML and HEAD sections for framesets. */
+{
+/* Print start of HTML. */
+writeFramesetType();
+puts("");
+char *meta = getCspMetaHeader();
+printf("
\n%s%s\n\n\n", meta, title);
+freeMem(meta);
+}
+
boolean clipToChrom(int *pStart, int *pEnd)
/* Clip start/end coordinates to fit in chromosome. */
{
static int chromSize = -1;
if (chromSize < 0)
chromSize = hChromSize(database, seqName);
if (*pStart < 0) *pStart = 0;
if (*pEnd > chromSize) *pEnd = chromSize;
return *pStart < *pEnd;
}
struct genbankCds getCds(struct sqlConnection *conn, char *acc)
/* obtain and parse the CDS, errAbort if not found or invalid */
{
@@ -7167,42 +7178,41 @@
if (isNotEmpty(cdsString))
genbankParseCds(cdsString, retCdsStart, retCdsEnd);
}
}
}
void htcBigPslAli(char *acc)
/* Show alignment for accession in bigPsl file. */
{
struct psl *psl;
char *aliTable;
int start;
unsigned int cdsStart = 0, cdsEnd = 0;
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
aliTable = cartString(cart, "aliTable");
if (isCustomTrack(aliTable))
{
struct customTrack *ct = lookupCt(aliTable);
tdb = ct->tdb;
}
else
tdb = hashFindVal(trackHash, aliTable);
-printf("\n%s vs Genomic [%s]\n\n\n", acc, aliTable);
+char title[1024];
+safef(title, sizeof title, "%s vs Genomic [%s]", acc, aliTable);
+htmlFramesetStart(title);
/* Get some environment vars. */
start = cartInt(cart, "l");
int end = cartInt(cart, "r");
char *chrom = cartString(cart, "c");
char *seq, *cdsString = NULL;
struct lm *lm = lmInit(0);
char *fileName = bbiNameFromSettingOrTable(tdb, NULL, tdb->table);
struct bbiFile *bbi = bigBedFileOpen(fileName);
struct bigBedInterval *bb, *bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm);
char *bedRow[32];
char startBuf[16], endBuf[16];
for (bb = bbList; bb != NULL; bb = bb->next)
{
@@ -7231,42 +7241,41 @@
struct dnaSeq *rnaSeq = newDnaSeq(seq, strlen(seq), acc);
enum gfType type = gftRna;
if (pslIsProtein(psl))
type = gftProt;
showSomeAlignment(psl, rnaSeq, type, 0, rnaSeq->size, NULL, cdsStart, cdsEnd);
}
void htcBigPslAliInWindow(char *acc)
/* Show alignment in window for accession in bigPsl file. */
{
struct psl *partPsl, *wholePsl;
char *aliTable;
int start;
unsigned int cdsStart = 0, cdsEnd = 0;
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
aliTable = cartString(cart, "aliTable");
if (isCustomTrack(aliTable))
{
struct customTrack *ct = lookupCt(aliTable);
tdb = ct->tdb;
}
else
tdb = hashFindVal(trackHash, aliTable);
-printf("\n%s vs Genomic [%s]\n\n\n", acc, aliTable);
+char title[1024];
+safef(title, sizeof title, "%s vs Genomic [%s]", acc, aliTable);
+htmlFramesetStart(title);
/* Get some environment vars. */
start = cartInt(cart, "l");
int end = cartInt(cart, "r");
char *chrom = cartString(cart, "c");
char *seq, *cdsString = NULL;
struct lm *lm = lmInit(0);
char *fileName = bbiNameFromSettingOrTable(tdb, NULL, tdb->table);
struct bbiFile *bbi = bigBedFileOpen(fileName);
struct bigBedInterval *bb, *bbList = bigBedIntervalQuery(bbi, chrom, start, end, 0, lm);
char *bedRow[32];
char startBuf[16], endBuf[16];
for (bb = bbList; bb != NULL; bb = bb->next)
{
@@ -7320,35 +7329,34 @@
char table[64];
char accTmp[64];
struct sqlConnection *conn;
struct sqlResult *sr;
char **row;
struct psl *psl;
struct dnaSeq *rnaSeq;
char *aliTable;
int start;
unsigned int cdsStart = 0, cdsEnd = 0;
boolean hasBin;
char accChopped[512] ;
safef(accChopped, sizeof(accChopped), "%s",acc);
chopSuffix(accChopped);
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
aliTable = cartString(cart, "aliTable");
-printf("\n%s vs Genomic [%s]\n\n\n", accChopped, aliTable);
+char title[1024];
+safef(title, sizeof title, "%s vs Genomic [%s]", accChopped, aliTable);
+htmlFramesetStart(title);
/* Get some environment vars. */
start = cartInt(cart, "o");
conn = hAllocConn(database);
getCdsStartAndStop(conn, accChopped, aliTable, &cdsStart, &cdsEnd);
/* Look up alignments in database */
hFindSplitTable(database, seqName, aliTable, table, &hasBin);
sqlSafef(query, sizeof query, "select * from %s where qName like '%s%%' and tName=\"%s\" and tStart=%d",
table, acc, seqName, start);
sr = sqlGetResult(conn, query);
if ((row = sqlNextRow(sr)) == NULL)
errAbort("Couldn't find alignment for %s at %d", acc, start);
psl = pslLoad(row+hasBin);
@@ -7410,35 +7418,33 @@
char **row;
struct psl *wholePsl, *partPsl;
struct dnaSeq *rnaSeq;
char *aliTable;
int start;
unsigned int cdsStart = 0, cdsEnd = 0;
boolean hasBin;
char accChopped[512] ;
safef(accChopped, sizeof(accChopped), "%s",acc);
chopSuffix(accChopped);
/* Get some environment vars. */
aliTable = cartString(cart, "aliTable");
start = cartInt(cart, "o");
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
-printf("\n%s vs Genomic [%s]\n\n\n",
- accChopped, aliTable);
+char title[1024];
+safef(title, sizeof title, "%s vs Genomic [%s]", accChopped, aliTable);
+htmlFramesetStart(title);
conn = hAllocConn(database);
getCdsStartAndStop(conn, accChopped, aliTable, &cdsStart, &cdsEnd);
if (startsWith("user", aliTable))
{
char *pslName, *faName, *qName;
struct lineFile *lf;
bioSeq *oSeqList = NULL, *oSeq = NULL;
struct psl *psl;
int start;
enum gfType tt, qt;
boolean isProt;
char *ss = cartOptionalString(cart, "ss");
@@ -7575,34 +7581,34 @@
chainFree(&chain);
psl = pslTrimToTargetRange(fatPsl, winStart, winEnd);
pslFree(&fatPsl);
if (sameWord(otherDb, "seq"))
{
qSeq = hExtSeqPart(database, psl->qName, psl->qStart, psl->qEnd);
safef(name, sizeof name, "%s", psl->qName);
}
else
{
qSeq = loadGenomePart(otherDb, psl->qName, psl->qStart, psl->qEnd);
safef(name, sizeof name, "%s.%s", otherOrg, psl->qName);
}
-writeFramesetType();
-puts("");
-printf("\n%s %s vs %s %s \n\n\n",
+char title[1024];
+safef(title, sizeof title, "%s %s vs %s %s ",
(otherOrg == NULL ? "" : otherOrg), psl->qName, org, psl->tName );
+htmlFramesetStart(title);
showSomeAlignment(psl, qSeq, gftDnaX, psl->qStart, psl->qEnd, name, 0, 0);
}
void htcChainTransAli(char *item)
/* Draw detailed alignment representation of a chain with translated protein */
{
struct chain *chain;
struct psl *fatPsl, *psl = NULL;
int id = atoi(item);
char *track = cartString(cart, "o");
char *type = trackTypeInfo(track);
char *typeWords[2];
char *otherDb = NULL, *org = NULL, *otherOrg = NULL;
struct dnaSeq *qSeq = NULL;
char name[128];
@@ -7632,53 +7638,52 @@
chainFree(&chain);
psl = pslTrimToTargetRange(fatPsl, winStart, winEnd);
pslFree(&fatPsl);
if (sameWord(otherDb, "seq"))
{
qSeq = hExtSeq(database, psl->qName);
safef(name, sizeof name, "%s", psl->qName);
}
else
{
qSeq = loadGenomePart(otherDb, psl->qName, psl->qStart, psl->qEnd);
safef(name, sizeof name, "%s.%s", otherOrg, psl->qName);
}
-writeFramesetType();
-puts("");
-printf("\n%s %s vs %s %s \n\n\n",
+char title[1024];
+safef(title, sizeof title, "%s %s vs %s %s ",
(otherOrg == NULL ? "" : otherOrg), psl->qName, org, psl->tName );
+htmlFramesetStart(title);
/*showSomeAlignment(psl, qSeq, gftDnaX, psl->qStart, psl->qEnd, name, 0, 0); */
showSomeAlignment(psl, qSeq, gftDnaX, psl->qStart, psl->qEnd, name, cdsStart, cdsEnd);
}
void htcUserAli(char *fileNames)
/* Show alignment for accession. */
{
char *pslName, *faName, *qName;
struct lineFile *lf;
bioSeq *oSeqList = NULL, *oSeq = NULL;
struct psl *psl;
int start;
enum gfType tt, qt;
boolean isProt;
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
-printf("\nUser Sequence vs Genomic\n\n\n");
+char title[1024];
+safef(title, sizeof title, "User Sequence vs Genomic");
+htmlFramesetStart(title);
start = cartInt(cart, "o");
parseSs(fileNames, &pslName, &faName, &qName);
pslxFileOpen(pslName, &qt, &tt, &lf);
isProt = (qt == gftProt);
while ((psl = pslNext(lf)) != NULL)
{
if (sameString(psl->tName, seqName) && psl->tStart == start && sameString(psl->qName, qName))
break;
pslFree(&psl);
}
lineFileClose(&lf);
if (psl == NULL)
errAbort("Couldn't find alignment at %s:%d", seqName, start);
oSeqList = faReadAllSeq(faName, !isProt);
@@ -7695,34 +7700,33 @@
/* Show protein to translated dna alignment for accession. */
{
struct psl *psl;
int start;
enum gfType qt = gftProt;
struct sqlResult *sr;
struct sqlConnection *conn = hAllocConn(database);
struct dnaSeq *seq = NULL;
char query[256], **row;
char fullTable[64];
boolean hasBin;
char buffer[256];
int addp = 0;
char *pred = NULL;
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
-printf("\nProtein Sequence vs Genomic\n\n\n");
+char title[1024];
+safef(title, sizeof title, "Protein Sequence vs Genomic");
+htmlFramesetStart(title);
addp = cartUsualInt(cart, "addp",0);
pred = cartUsualString(cart, "pred",NULL);
start = cartInt(cart, "o");
hFindSplitTable(database, seqName, table, fullTable, &hasBin);
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);
if ((addp == 1) || (pred != NULL))
{
char *ptr;
@@ -7760,34 +7764,33 @@
showSomeAlignment(psl, seq, qt, 0, seq->size, NULL, 0, 0);
}
void htcBlatXeno(char *readName, char *table)
/* Show alignment for accession. */
{
struct psl *psl;
int start;
struct sqlResult *sr;
struct sqlConnection *conn = hAllocConn(database);
struct dnaSeq *seq;
char query[256], **row;
char fullTable[64];
boolean hasBin;
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
-printf("\nSequence %s\n\n\n", readName);
+char title[1024];
+safef(title, sizeof title, "Sequence %s", readName);
+htmlFramesetStart(title);
start = cartInt(cart, "o");
hFindSplitTable(database, seqName, table, fullTable, &hasBin);
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);
seq = hExtSeq(database, readName);
showSomeAlignment(psl, seq, gftDnaX, 0, seq->size, NULL, 0, 0);
}
@@ -8108,34 +8111,34 @@
void htcIlluminaProbesAlign(char *item)
/* If the click came from "show alignment" on the Illumina */
/* probes details page, show the standard alignment page. */
{
struct psl *psl;
struct dnaSeq *seq;
struct sqlResult *sr;
struct sqlConnection *conn = hAllocConn(database);
char query[256], **row;
int start;
char *pslTable = cgiUsualString("pslTable", "illuminaProbesAlign");
char *seqTable = cgiUsualString("seqTable", "illuminaProbesSeq");
char *probeName = item;
char *probeString;
int rowOffset = hOffsetPastBin(database, seqName, pslTable);
-/* Print start of HTML. */
-writeFramesetType();
-puts("");
-printf("\nSequence %s\n\n\n", probeName);
+
+char title[1024];
+safef(title, sizeof title, "Sequence %s", probeName);
+htmlFramesetStart(title);
start = cartInt(cart, "o");
/* get psl */
sqlSafef(query, sizeof(query), "select * from %s where qName = '%s' and tName = '%s' and tStart=%d",
pslTable, probeName, seqName, start);
sr = sqlGetResult(conn, query);
if ((row = sqlNextRow(sr)) == NULL)
errAbort("Couldn't find alignment for %s at %d", probeName, start);
psl = pslLoad(row+rowOffset);
sqlFreeResult(&sr);
sqlSafef(query, sizeof(query), "select seq from %s where id = '%s'", seqTable, probeName);
probeString = sqlNeedQuickString(conn, query);
seq = newDnaSeq(probeString, strlen(probeString), probeName);
hFreeConn(&conn);
showSomeAlignment(psl, seq, gftDna, 0, seq->size, probeName, 0, 0);
pslFree(&psl);
@@ -14223,33 +14226,33 @@
/* In hg10 tables, psl->qName can be org.chrom. Strip it down to just
* the chrom: */
qChrom = psl->qName;
if ((ptr = strchr(qChrom, '.')) != NULL)
qChrom = ptr+1;
/* Make sure that otherOrg's chrom size matches psl's qSize */
if (hChromSize(database, qChrom) != psl->qSize)
errAbort("Alignment's query size for %s is %d, but the size of %s in database %s is %d. Incorrect database in trackDb.type?",
qChrom, psl->qSize, qChrom, otherDb, hChromSize(otherDb, qChrom));
psl = pslTrimToTargetRange(psl, winStart, winEnd);
qSeq = loadGenomePart(otherDb, qChrom, psl->qStart, psl->qEnd);
snprintf(name, sizeof(name), "%s.%s", otherOrg, qChrom);
-writeFramesetType();
-puts("");
-printf("\n%s %dk\n\n\n", name, psl->qStart/1000);
+char title[1024];
+safef(title, sizeof title, "%s %dk", name, psl->qStart/1000);
+htmlFramesetStart(title);
showSomeAlignment(psl, qSeq, gftDnaX, psl->qStart, psl->qEnd, name, 0, 0);
}
void doAlignCompGeno(struct trackDb *tdb, char *itemName, char *otherGenome)
/* Handle click on blat or blastz track in a generic fashion */
/* otherGenome is the text to display for genome name on details page */
{
char query[256];
struct sqlConnection *conn = hAllocConn(database);
struct sqlResult *sr = NULL;
char **row;
int start = cartInt(cart, "o");
int end = cartInt(cart, "t");
char *chrom = cartString(cart, "c");
struct psl *pslList = NULL, *psl;
@@ -20303,31 +20306,31 @@
printPos(gc->chrom, gc->chromStart, gc->chromEnd, NULL, FALSE, NULL);
printf("GC Percentage: %3.1f%% \n", ((float)gc->gcPpt)/10);
gcPercentFree(&gc);
}
printTrackHtml(tdb);
sqlFreeResult(&sr);
hFreeConn(&conn);
}
void chuckHtmlStart(char *title)
/* Prints the header appropriate for the title
* passed in. Links html to chucks stylesheet for
* easier maintaince
*/
{
-printf("\n\n");
+printf("\n\n%s", getCspMetaHeader());
// FIXME blueStyle should not be absolute to genome-test and should be called by:
// webIncludeResourceFile("blueStyle.css");
printf("\n");
printf("%s\n",title);
}
void chuckHtmlContactInfo()
/* Writes out Chuck's email so people bother Chuck instead of Jim */
{
puts("
If you have comments and/or suggestions please email "
"sugnet@cse.ucsc.edu.\n");
}
void abbr(char *s, char *fluff)
@@ -22645,31 +22648,31 @@
char query[100];
struct dnaSeq *winDna;
struct bed *bedList = NULL, *oneBed;
int s, e;
if (!c || !l || !r)
errAbort("Bad Range");
s = atoi(l);
e = atoi(r);
winDna = hDnaFromSeq(database, c, s, e, dnaUpper);
if (sameString(getBed, "all"))
sqlSafef(query, sizeof(query), "select * from cutters");
else
sqlSafef(query, sizeof(query), "select * from cutters where name=\'%s\'", getBed);
cut = cutterLoadByQuery(conn, query);
bedList = matchEnzymes(cut, winDna, s);
-puts("\nEnzyme Output\n