/* hgVarAnnogrator - User interface for variant annotation integrator tool. */ #include "common.h" #include "asParse.h" #include "linefile.h" #include "hash.h" #include "memalloc.h" #include "options.h" #include "jksql.h" #include "htmshell.h" #include "web.h" #include "hPrint.h" #include "hdb.h" #include "cheapcgi.h" #include "cart.h" #include "hui.h" #include "jsHelper.h" #include "pipeline.h" #include "textOut.h" #include "hgFind.h" #include "trackHub.h" #include "hubConnect.h" #include "hgColors.h" #include "hgConfig.h" #include "udc.h" #include "customTrack.h" #include "grp.h" #include "hCommon.h" #include "trackDb.h" #include "wikiTrack.h" #include "hgMaf.h" #if ((defined USE_BAM || defined USE_TABIX) && defined KNETFILE_HOOKS) #include "knetUdc.h" #endif//def (USE_BAM || USE_TABIX) && KNETFILE_HOOKS #include "annoGratorQuery.h" #include "annoStreamDb.h" #include "annoStreamVcf.h" #include "annoStreamWig.h" #include "annoGrateWigDb.h" #include "annoGratorGpVar.h" #include "annoFormatTab.h" /* Global Variables */ struct cart *cart; /* CGI and other variables */ struct hash *oldVars; /* The cart before new cgi stuff added. */ char *genome; /* Name of genome - mouse, human, etc. */ char *database; /* Current genome database - hg17, mm5, etc. */ char *regionType; /* genome, ENCODE pilot regions, or specific position range. */ char *position; /* position range (if applicable) */ static struct pipeline *compressPipeline = (struct pipeline *)NULL; struct grp *fullGroupList; /* List of all groups. */ struct trackDb *fullTrackList; /* List of all tracks in database. */ struct customTrack *theCtList = NULL; /* List of custom tracks. */ struct slName *browserLines = NULL; /* Browser lines in custom tracks. */ int maxOutRows = 10000; //#*** make sensible, configurable limit #define hgvaRange "position" #define hgvaRegionType "hgva_regionType" #define hgvaRegionTypeEncode "encode" #define hgvaRegionTypeGenome "genome" #define hgvaRegionTypeRange "range" #define hgvaPositionContainer "positionContainer" void addSomeCss() /* This should go in a .css file of course. */ { hPrintf("\n"); } // #*** -------------------------- libify to jsHelper ? ------------------------ void expectJsonType(struct jsonElement *el, jsonElementType type, char *desc) /* Die if el is NULL or its type is not as expected. */ { if (el == NULL) errAbort("expected %s (type %d) but got NULL", desc, type); if (el->type != type) errAbort("expected %s to have type %d but got type %d", desc, type, el->type); } char *stringFromJHash(struct hash *jHash, char *elName, boolean nullOk) /* Look up the jsonElement with elName in hash, make sure the element's type is jsonString, * and return its actual string. If nullOK, return NULL when elName is not found. */ { struct hashEl *hel = hashLookup(jHash, elName); if (hel == NULL && nullOk) return NULL; struct jsonElement *el = hel ? hel->val : NULL; expectJsonType(el, jsonString, elName); return el->val.jeString; } struct slRef *listFromJHash(struct hash *jHash, char *elName, boolean nullOk) /* Look up the jsonElement with elName in hash, make sure the element's type is jsonList, * and return its actual list. If nullOK, return NULL when elName is not found. */ { struct hashEl *hel = hashLookup(jHash, elName); if (hel == NULL && nullOk) return NULL; struct jsonElement *el = hel ? hel->val : NULL; expectJsonType(el, jsonList, elName); return el->val.jeList; } struct hash *hashFromJEl(struct jsonElement *jel, char *desc, boolean nullOk) /* Make sure jel's type is jsonObject and return its actual hash. If nullOK, return * NULL when elName is not found. */ { expectJsonType(jel, jsonObject, desc); return jel->val.jeHash; } struct hash *hashFromJHash(struct hash *jHash, char *elName, boolean nullOk) /* Look up the jsonElement with elName in jHash, make sure the element's type is jsonObject, * and return its actual hash. If nullOK, return NULL when elName is not found. */ { struct hashEl *hel = hashLookup(jHash, elName); if (hel == NULL && nullOk) return NULL; struct jsonElement *el = hel ? hel->val : NULL; return hashFromJEl(el, elName, nullOk); } struct slPair *stringsWithPrefixFromJHash(struct hash *jHash, char *prefix) /* Search jHash elements for string variables whose names start with prefix. */ { struct slPair *varList = NULL; struct hashCookie cookie = hashFirst(jHash); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) { if (startsWith(prefix, hel->name)) { struct jsonElement *el = hel->val; if (el->type == jsonString) slAddHead(&varList, slPairNew(hel->name, el->val.jeString)); } } return varList; } // #*** -------------------------- end maybe libify to jsHelper ------------------------ //#*** --------------- begin verbatim from hgTables.c -- libify ------------------------ char *getScriptName() /* returns script name from environment or hardcoded for command line */ //#*** This should be libified and used for all the places where one CGI needs another //#*** to return to it. { char *script = cgiScriptName(); if (script != NULL) return script; else return hgVarAnnogratorName(); } boolean searchPosition(char *range) /* Try and fill in region via call to hgFind. Return FALSE * if it can't find a single position. */ { struct hgPositions *hgp = NULL; char retAddr[512]; char position[512]; char *chrom = NULL; int start=0, end=0; safef(retAddr, sizeof(retAddr), "%s", getScriptName()); hgp = findGenomePosWeb(database, range, &chrom, &start, &end, cart, TRUE, retAddr); if (hgp != NULL && hgp->singlePos != NULL) { safef(position, sizeof(position), "%s:%d-%d", chrom, start+1, end); cartSetString(cart, hgvaRange, position); return TRUE; } else if (start == 0) /* Confusing way findGenomePosWeb says pos not found. */ { cartSetString(cart, hgvaRange, hDefaultPos(database)); return FALSE; } else return FALSE; } boolean lookupPosition() /* Look up position (aka range) if need be. Return FALSE if it puts * up multiple positions. */ { char *range = cartUsualString(cart, hgvaRange, ""); boolean isSingle = TRUE; range = trimSpaces(range); if (range[0] != 0) isSingle = searchPosition(range); else cartSetString(cart, hgvaRange, hDefaultPos(database)); return isSingle; } //#*** ------------------ end verbatim --------------- //#*** ------------------ begin verbatim from hgTables/mainPage.c --------------- int trackDbCmpShortLabel(const void *va, const void *vb) /* Sort track by shortLabel. */ { const struct trackDb *a = *((struct trackDb **)va); const struct trackDb *b = *((struct trackDb **)vb); return strcmp(a->shortLabel, b->shortLabel); } void nbSpaces(int count) /* Print some non-breaking spaces. */ { int i; for (i=0; inext) if (cartBoolean(cart, hubVar->name)) cgiMakeHiddenVar(hubVar->name, hubVar->val); char *trackHubs = cartOptionalString(cart, hubConnectTrackHubsVarName); if (isNotEmpty(trackHubs)) cgiMakeHiddenVar(hubConnectTrackHubsVarName, trackHubs); } static boolean gotCustomTracks() /* Return TRUE if fullTrackList has at least one custom track */ { struct trackDb *t; for (t = fullTrackList; t != NULL; t = t->next) { if (isCustomTrack(t->table)) return TRUE; } return FALSE; } //#*** perhaps this fancy onChange stuff should be done in hgVarAnnogrator.js? //#*** and do we really need a hidden form? static struct dyString *onChangeStart() /* Start up a javascript onChange command */ { struct dyString *dy = jsOnChangeStart(); jsTextCarryOver(dy, hgvaRegionType); jsTextCarryOver(dy, hgvaRange); return dy; } static char *onChangeClade() /* Return javascript executed when they change clade. */ { struct dyString *dy = onChangeStart(); jsDropDownCarryOver(dy, "clade"); dyStringAppend(dy, " document.hiddenForm.org.value=0;"); dyStringAppend(dy, " document.hiddenForm.db.value=0;"); dyStringAppend(dy, " document.hiddenForm." hgvaRange ".value='';"); return jsOnChangeEnd(&dy); } static char *onChangeOrg() /* Return javascript executed when they change organism. */ { struct dyString *dy = onChangeStart(); jsDropDownCarryOver(dy, "clade"); jsDropDownCarryOver(dy, "org"); dyStringAppend(dy, " document.hiddenForm.db.value=0;"); dyStringAppend(dy, " document.hiddenForm." hgvaRange ".value='';"); return jsOnChangeEnd(&dy); } static char *onChangeDb() /* Return javascript executed when they change database. */ { struct dyString *dy = onChangeStart(); jsDropDownCarryOver(dy, "clade"); jsDropDownCarryOver(dy, "db"); dyStringAppend(dy, " document.hiddenForm." hgvaRange ".value='';"); return jsOnChangeEnd(&dy); } INLINE void printOption(char *val, char *selectedVal, char *label) /* For rolling our own select without having to build conditional arrays/lists. */ { printf("