9f6d2ecec7b6362e055b19017c34ce823ed0a993 max Mon Dec 5 18:33:18 2011 -0800 patches to t2g to make it work even if no article/sequence table exist diff --git src/hg/hgc/t2g.c src/hg/hgc/t2g.c index f1b334d..2d7e8ed 100644 --- src/hg/hgc/t2g.c +++ src/hg/hgc/t2g.c @@ -34,34 +34,39 @@ { abstract = "(No abstract found for this article. Please use the link to the fulltext above.)"; } docId = cloneString(row[0]); printf("<P>%s</P>\n", row[3]); printf("<A HREF=\"%s\"><B>%s</B></A>\n", row[1], row[2]); printf("<P style=\"width:800px; font-size:80%%\">%s</P>\n", row[4]); printf("<P style=\"width:800px; font-size:100%%\">%s</P>\n", abstract); } sqlFreeResult(&sr); return docId; } struct hash* getSeqIdHash(struct sqlConnection* conn, char* trackTable, char* docId, char *item, char* seqName, int start) { - /* get sequence-Ids for feature that was clicked (item&startPos are unique) and return as hash */ - // there must be an easier way to do this... - // couldn't find a function that splits a string and converts it to a list char query[512]; + /* check first if the column exists (some debugging tables on hgwdev don't have seqIds) */ + safef(query, sizeof(query), "SHOW COLUMNS FROM %s LIKE 'seqIds';", trackTable); + char* seqIdPresent = sqlQuickString(conn, query); + if (!seqIdPresent) { + return NULL; + } + + /* get sequence-Ids for feature that was clicked (item&startPos are unique) and return as hash */ safef(query, sizeof(query), "SELECT seqIds,'' FROM %s WHERE name='%s' " "and chrom='%s' and chromStart=%d", trackTable, item, seqName, start); if (t2gDebug) puts(query); char* seqIdCoordString = sqlQuickString(conn, query); char* seqIdCoords[1024]; int partCount = chopString(seqIdCoordString, ",", seqIdCoords, ArraySize(seqIdCoords)); int i; struct hash *seqIdHash = NULL; seqIdHash = newHash(0); for (i=0; i<partCount; i++) { char* seqId[1024]; chopString(seqIdCoords[i], ":", seqId, ArraySize(seqId)); if (t2gDebug) @@ -116,31 +121,31 @@ { char* fileDesc = row[0]; char* snippet = row[1]; char* locList = row[2]; char* artId = row[3]; char* fileId = row[4]; char* seqId = row[5]; char* seq = row[6]; // annotation (=sequence) ID is a 64 bit int with 10 digits for // article, 3 digits for file, 5 for annotation char annotId[100]; safef(annotId, 100, "%010d%03d%05d", atoi(artId), atoi(fileId), atoi(seqId)); // only display this sequence if we're in the right section - if ((hashLookup(filterIdHash, annotId)==0) ^ !isClickedSection) { + if (filterIdHash!=NULL && ((hashLookup(filterIdHash, annotId)==0) ^ !isClickedSection)) { foundSkippedRows = FALSE; continue; } if (fasta) { printf("<TT>>%s<BR>%s<BR></TT>", annotId, seq); } else { printf("<TR style=\"background-color: #%s\">\n", HG_COL_LOCAL_TABLE); if (showDesc) printf("<TD style=\"word-break: normal\">%s\n", fileDesc); //printf("<TD><I>%s</I></TD>\n", snippet); printf("<TD style=\"word-break: normal\"><I>%s</I></TD>\n", snippet); @@ -177,31 +182,35 @@ } printf("</TR>\n"); webEndSectionTables(); sqlFreeResult(&sr); return foundSkippedRows; } void printSeqInfo(struct sqlConnection* conn, char* trackTable, char* docId, char* item, char* seqName, int start, bool fileDesc, bool fasta) /* print sequences, split into two sections * two sections: one for sequences that were clicked, one for all others*/ { struct hash* clickedSeqs = getSeqIdHash(conn, trackTable, docId, item, seqName, start); bool skippedRows; + if (clickedSeqs) skippedRows = printSeqSection(docId, "Sequences used to construct this feature", fileDesc, conn, clickedSeqs, 1, fasta); + else + skippedRows=1; + if (skippedRows) printSeqSection(docId, "Other Sequences in this article", fileDesc, conn, clickedSeqs, 0, fasta); //else //printf("<P>No more sequences<P>"); if (endsWith(trackTable, "Elsevier")) printf("<P><SMALL>Article information and excerpts are Copyright 2011 Elsevier B.V. All rights reserved.</SMALL><P>"); freeHash(&clickedSeqs); } void printTrackVersion(struct trackDb *tdb, struct sqlConnection* conn, char* item) { char versionString[256]; char dateReference[256]; char headerTitle[512];