void writePcrResultTrack(struct gfPcrOutput *gpoList, char *db, char *target) /* Write trash files and store their name in a cart variable. */ { char *cartVar = pcrResultCartVar(db); struct tempName bedTn, primerTn; char buf[2048]; trashDirFile(&bedTn, "hgPcr", "hgPcr", ".psl"); trashDirFile(&primerTn, "hgPcr", "hgPcr", ".txt"); gfPcrOutputWriteAll(gpoList, "psl", NULL, bedTn.forCgi); writePrimers(gpoList, primerTn.forCgi); if (isNotEmpty(target)) safef(buf, sizeof(buf), "%s %s %s", bedTn.forCgi, primerTn.forCgi, target); else safef(buf, sizeof(buf), "%s %s", bedTn.forCgi, primerTn.forCgi); cartSetString(cart, cartVar, buf); }
static void h1n1DownloadPdb(char *item, char *pdbUrl, struct tempName *tmpPdb) /* uncompress PDB to trash */ { int inFd = netOpenHttpExt(pdbUrl, "GET", NULL); int inFdRedir = 0; char *pdbUrlRedir = NULL; if (!netSkipHttpHeaderLinesHandlingRedirect(inFd, pdbUrl, &inFdRedir, &pdbUrlRedir)) errAbort("Unable to access predicted 3D structure file: %s", pdbUrl); if (pdbUrlRedir != NULL) { close(inFd); inFd = inFdRedir; freez(&pdbUrlRedir); } trashDirFile(tmpPdb, "hgct", item, ".pdb"); FILE *outFh = mustOpen(tmpPdb->forCgi, "w"); struct lineFile *inLf = lineFileDecompressFd(pdbUrl, TRUE, inFd); char *line; while (lineFileNext(inLf, &line, NULL)) { fputs(line, outFh); fputc('\n', outFh); } lineFileClose(&inLf); carefulClose(&outFh); }
void doGetGreatOutput(void (*dispatch)()) { struct tempName tn; int saveStdout; FILE *f; trashDirFile(&tn, "great", cartSessionId(cart), ".bed"); f = fopen(tn.forCgi, "w"); /* We want to capture hgTables stdout output to a trash file * which will later be fetched by Great via URL. */ /* Workaround because stdout stream is not assignable on some operating systems */ fflush(stdout); saveStdout = dup(STDOUT_FILENO); dup2(fileno(f),STDOUT_FILENO); /* closes STDOUT before setting it again */ fclose(f); dispatch(); /* this writes to stdout */ /* restore stdout */ fflush(stdout); dup2(saveStdout ,STDOUT_FILENO); /* closes STDOUT before setting it back to saved descriptor */ close(saveStdout); cartRemove(cart, hgtaDoGreatOutput); htmlOpen("Table Browser integration with GREAT"); doSubmitToGreat(tn.forCgi); htmlClose(); }
char *userRegionsParse(char *db, char *regionsText, int maxRegions, int maxErrs, int *retRegionCount, char **retWarnText) /* Parse user regions entered as BED3, BED4 or chr:start-end optionally followed by name. * Return name of trash file containing BED for parsed regions if regionsText contains * valid regions; otherwise NULL. * If maxRegions <= 0, it is ignored; likewise for maxErrs. * If retRegionCount is non-NULL, it will be set to the number of valid parsed regions * in the trash file. * If retWarnText is non-NULL, it will be set to a string containing warning and error * messages encountered while parsing input. */ { char *trashFileName = NULL; if (isNotEmpty(regionsText)) { char *copy = cloneString(regionsText); struct dyString *dyWarn = dyStringNew(0); struct bed4 *bedList = parseRegionInput(db, copy, maxRegions, maxErrs, dyWarn); if (retWarnText != NULL) { if (dyWarn->stringSize > 0) *retWarnText = dyStringCannibalize(&dyWarn); else { *retWarnText = NULL; dyStringFree(&dyWarn); } } int regionCount = slCount(bedList); if (retRegionCount != NULL) *retRegionCount = regionCount; if (regionCount > 0) { struct tempName tn; trashDirFile(&tn, "hgtData", "user", ".region"); trashFileName = cloneString(tn.forCgi); FILE *f = mustOpen(trashFileName, "w"); struct bed4 *bed; for (bed = bedList; bed; bed = bed->next ) { char *name = bed->name ? bed->name : ""; fprintf(f, "%s\t%d\t%d\t%s\n", bed->chrom, bed->chromStart, bed->chromEnd, name); } carefulClose(&f); } freeMem(copy); } else { if (retRegionCount != NULL) *retRegionCount = 0; if (retWarnText != NULL) *retWarnText = NULL; } return trashFileName; }
static boolean drawGtexRBoxplot(char *geneName, struct tissueSampleVals *tsvList, boolean doLogTransform, char *version, struct tempName *pngTn) /* Draw a box-and-whiskers plot from GTEx sample data, using R boxplot */ { /* Create R data frame. This is a tab-sep file, one row per sample, * with columns for sample, tissue, rpkm */ struct tempName dfTn; trashDirFile(&dfTn, "hgc", "gtexGene", ".df.txt"); FILE *f = fopen(dfTn.forCgi, "w"); if (f == NULL) errAbort("can't create temp file %s", dfTn.forCgi); fprintf(f, "sample\ttissue\trpkm\n"); struct tissueSampleVals *tsv; int sampleId=1; int i; for (tsv = tsvList; tsv != NULL; tsv = tsv->next) { int count = tsv->count; // remove trailing parenthesized phrases as not worth label length chopSuffixAt(tsv->description, '('); for (i=0; i<count; i++) fprintf(f, "%d\t%s\t%0.3f\n", sampleId++, tsv->description, tsv->vals[i]); } fclose(f); // Plot to PNG file if (!pngTn) return FALSE; trashDirFile(pngTn, "hgc", "gtexGene", ".png"); char cmd[256]; /* Exec R in quiet mode, without reading/saving environment or workspace */ safef(cmd, sizeof(cmd), "Rscript --vanilla --slave hgcData/gtexBoxplot.R %s %s %s %s %s %s", geneName, dfTn.forCgi, pngTn->forHtml, doLogTransform ? "log=TRUE" : "log=FALSE", "order=alpha", version); //NOTE: use "order=score" to order bargraph by median RPKM, descending int ret = system(cmd); if (ret == 0) return TRUE; return FALSE; }
static void getOutFile(char *pdbId, char *other, struct tempName *outName) /* generate output file names, other can be NULL*/ { char baseName[PATH_LEN]; if (other != NULL) safef(baseName, sizeof(baseName), "%s.%s", pdbId, other); else safecpy(baseName, sizeof(baseName), pdbId); trashDirFile(outName, "lssnp", baseName, ".chimerax"); }
void handlePostscript() /* Deal with Postscript output. */ { struct tempName psTn; struct tempName psTn2; char *pdfFile = NULL; trashDirFile(&psTn, "pbt", "pbt", ".eps"); trashDirFile(&psTn2, "pbt", "pbt2", ".eps"); printf("<H1>PostScript/PDF Output</H1>\n"); printf("PostScript images can be printed at high resolution " "and edited by many drawing programs such as Adobe Illustrator."); printf(" PDF can be viewed with Adobe Acrobat Reader.<BR><BR>\n"); doTrackForm(psTn.forCgi, psTn2.forCgi); printf("<A HREF=\"%s\">Click here to download</A> " "the current protein tracks graphic in PostScript. ", psTn.forCgi); pdfFile = convertEpsToPdf(psTn.forCgi); if (pdfFile != NULL) { printf("<BR><A HREF=\"%s\">Click here to download</A> " "the current protein tracks graphic in PDF", pdfFile); } else printf("<BR><BR>PDF format not available"); printf("<BR><BR><A HREF=\"%s\">Click here to download</A> " "the current protein histograms graphic in PostScript. ", psTn2.forCgi); pdfFile = convertEpsToPdf(psTn2.forCgi); if (pdfFile != NULL) { printf("<BR><A HREF=\"%s\">Click here to download</A> " "the current protein histograms graphic in PDF", pdfFile); } else printf("<BR><BR>PDF format not available"); freez(&pdfFile); }
static void getTrashFileNames(char *rsId, char epsFile[PATH_LEN], char pdfFile[PATH_LEN], char pngFile[PATH_LEN]) /* Get stable trash file names (always in trash/hgc, based on geo->name so we can reuse). */ { struct tempName tn; trashDirFile(&tn, "hgc", "", ""); char trashDir[FILENAME_LEN]; splitPath(tn.forCgi, trashDir, NULL, NULL); safef(epsFile, PATH_LEN, "%shgdpGeo_%s.eps", trashDir, rsId); safef(pdfFile, PATH_LEN, "%shgdpGeo_%s.pdf", trashDir, rsId); safef(pngFile, PATH_LEN, "%shgdpGeo_%s.png", trashDir, rsId); }
static struct customTrack *beginCustomTrack(char *table, int fields, boolean doCt, boolean doWigHdr, boolean doDataPoints) /* If doCt, return a new custom track object from TB cart settings and params; * if !doCt, return NULL but print out a header line. */ { char *ctName = cgiUsualString(hgtaCtName, table); char *ctDesc = cgiUsualString(hgtaCtDesc, table); char *ctUrl = cgiUsualString(hgtaCtUrl, ""); char *ctVis = cgiUsualString(hgtaCtVis, "dense"); int visNum = (int) hTvFromStringNoAbort(ctVis); struct customTrack *ctNew = NULL; if (visNum < 0) visNum = 0; if (doCt) { ctNew = newCt(ctName, ctDesc, visNum, ctUrl, fields); if (doDataPoints) { struct dyString *wigSettings = newDyString(0); struct tempName tn; trashDirFile(&tn, "ct", hgtaCtTempNamePrefix, ".wib"); ctNew->wibFile = cloneString(tn.forCgi); char *wiggleFile = cloneString(ctNew->wibFile); chopSuffix(wiggleFile); strcat(wiggleFile, ".wia"); ctNew->wigAscii = cloneString(wiggleFile); chopSuffix(wiggleFile); /* .wig file will be created upon encoding in customFactory */ /*strcat(wiggleFile, ".wig"); ctNew->wigFile = cloneString(wiggleFile); */ ctNew->wiggle = TRUE; dyStringPrintf(wigSettings, "type wiggle_0\nwibFile %s\n", ctNew->wibFile); ctNew->tdb->settings = dyStringCannibalize(&wigSettings); freeMem(wiggleFile); } } else { if (doWigHdr) hPrintf("track type=wiggle_0 name=\"%s\" description=\"%s\" " "visibility=%d url=%s \n", ctName, ctDesc, visNum, ctUrl); else hPrintf("track name=\"%s\" description=\"%s\" visibility=%d url=%s \n", ctName, ctDesc, visNum, ctUrl); } return ctNew; }
void doDocIdMeta(struct cart *theCart) { char *docId = cartString(theCart, "docId"); cartWebStart(cart, database, "ENCODE DCC: Metadata for docId %s",docId); struct sqlConnection *conn = sqlConnect(database); char query[10 * 1024]; struct sqlResult *sr; char **row; struct tempName tn; trashDirFile(&tn, "docId", "meta", ".txt"); char *tempFile = tn.forCgi; boolean beenHere = FALSE; printf("<a href=docIdView?db=%s> Return </a><BR>", database); safef(query, sizeof query, "select * from %s where ix=%s", docIdTable,docId); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (beenHere) errAbort("found more than one record with ix value %s in table %s", docId, docIdTable); beenHere = TRUE; struct docIdSub *docIdSub = docIdSubLoad(row); cgiDecode(docIdSub->metaData, docIdSub->metaData, strlen(docIdSub->metaData)); //printf("tempFile is %s\n<BR>", tempFile); FILE *f = mustOpen(tempFile, "w"); fwrite(docIdSub->metaData, strlen(docIdSub->metaData), 1, f); fclose(f); boolean validated; struct mdbObj *mdbObj = mdbObjsLoadFromFormattedFile(tempFile, &validated); unlink(tempFile); if (mdbObj->next) errAbort("got more than one metaObj from metaData"); for(; mdbObj; mdbObj = mdbObj->next) { printf("<BR>object: %s\n", mdbObj->obj); struct mdbVar *vars = mdbObj->vars; for(; vars; vars = vars->next) { printf("<BR>%s %s\n", vars->var, vars->val); } } } cartWebEnd(); }
void lsSnpPdbChimeraGenericLink(char *pdbSpec, char *script, char *trashDirName, char *trashBaseName, struct tempName *chimerax) /* Generate a chimerax file for the given pdbSpec, which can be a PDB id or a * URL. Copies in the lsSnpPdbChimera.py file and then adds optional script python code. * Fills in chimerax structure. * FIXME: This is an experiment for H1N1 flu browser, this function has * nothing to do with LS/SNP. If we decide to keep this, this should be * split into a generic chimera module. */ { trashDirFile(chimerax, trashDirName, trashBaseName, ".chimerax"); FILE *xfh = chimeraxBegin(chimerax->forCgi); fprintf(xfh, "\ndisplayPdb(\"%s\", ())\n", pdbSpec); if (script != NULL) fputs(script, xfh); chimeraxEnd(&xfh); }
static void mkH1n1StructData(char *gene, char *idPairFile, char *highlightId, struct tempName *imageFile, struct tempName *chimeraScript) /* generate 3D structure files; difference highlighting is generate only idPairFile or * idPairFile, if specified, but not both. */ { struct tempName prefix; trashDirFile(&prefix, "hgct", gene, "tmp"); char idFile[PATH_LEN], idArg[PATH_LEN], logFile[PATH_LEN], cmd[2*PATH_LEN]; idArg[0] = '\0'; if ((idPairFile != NULL) || (highlightId != NULL)) { safef(idFile, sizeof(idFile), "%s.ids", prefix.forCgi); if (idPairFile != NULL) { // extract first column safef(cmd, sizeof(cmd), "cut -f 1 %s >%s", idPairFile, idFile); if (system(cmd) != 0) errAbort("extracting protein ids failed: %s", cmd); } else { FILE *fh = mustOpen(idFile, "w"); fprintf(fh, "%s\n", highlightId); carefulClose(&fh); } safef(idArg, sizeof(idArg), "--ids %s", idFile); } // dynamic_highlight.pl knows locations of model files safef(logFile, sizeof(logFile), "%s.log", prefix.forCgi); safef(cmd, sizeof(cmd), "%s/dynamic_highlight.pl --rasmol --chimera --protein %s --consensus 0602 %s --base %s >%s 2>&1", getH1n1StructDir(), gene, idArg, prefix.forCgi, logFile); if (system(cmd) != 0) errAbort("creation of 3D structure highlight files failed: %s", cmd); // output names are all predefined by script relative to prefix tempNameFromPrefix(imageFile, &prefix, "_highlight.jpg"); tempNameFromPrefix(chimeraScript, &prefix, "_highlight.cmd"); }
void doPastedIdentifiers(struct sqlConnection *conn) /* Process submit in paste identifiers page. */ { char *idText = trimSpaces(cartString(cart, hgtaPastedIdentifiers)); htmlOpen("Table Browser (Input Identifiers)"); if (isNotEmpty(idText)) { /* Write terms to temp file, checking whether they have matches, and * save temp file name. */ boolean saveIdText = (strlen(idText) < MAX_IDTEXT); char *idTextForLf = saveIdText ? cloneString(idText) : idText; struct lineFile *lf = lineFileOnString("idText", TRUE, idTextForLf); char *line, *word; struct tempName tn; FILE *f; int totalTerms = 0, foundTerms = 0; struct slName* missingTerms = NULL; struct dyString *exampleMissingIds = dyStringNew(256); char *actualDb = database; if (sameWord(curTable, WIKI_TRACK_TABLE)) actualDb = wikiDbName(); struct hTableInfo *hti = maybeGetHti(actualDb, curTable, conn); char *idField = getIdField(actualDb, curTrack, curTable, hti); if (idField == NULL) { warn("Sorry, I can't tell which field of table %s to treat as the " "identifier field.", curTable); webNewSection("Table Browser"); cartRemove(cart, hgtaIdentifierDb); cartRemove(cart, hgtaIdentifierTable); cartRemove(cart, hgtaIdentifierFile); mainPageAfterOpen(conn); htmlClose(); return; } struct slName *allTerms = NULL, *term; while (lineFileNext(lf, &line, NULL)) { while ((word = nextWord(&line)) != NULL) { term = slNameNew(word); slAddHead(&allTerms, term); totalTerms++; } } slReverse(&allTerms); lineFileClose(&lf); char *extraWhere = NULL; int maxIdsInWhere = cartUsualInt(cart, "hgt_maxIdsInWhere", DEFAULT_MAX_IDS_IN_WHERE); if (totalTerms > 0 && totalTerms <= maxIdsInWhere) extraWhere = slNameToInExpression(idField, allTerms); struct lm *lm = lmInit(0); struct hash *matchHash = getAllPossibleIds(conn, lm, idField, extraWhere); trashDirFile(&tn, "hgtData", "identifiers", ".key"); f = mustOpen(tn.forCgi, "w"); for (term = allTerms; term != NULL; term = term->next) { struct slName *matchList = NULL, *match; if (matchHash == NULL) { matchList = slNameNew(term->name); } else { /* Support multiple alias->id mappings: */ char upcased[1024]; safecpy(upcased, sizeof(upcased), term->name); touppers(upcased); struct hashEl *hel = hashLookup(matchHash, upcased); if (hel != NULL) { matchList = slNameNew((char *)hel->val); while ((hel = hashLookupNext(hel)) != NULL) { match = slNameNew((char *)hel->val); slAddHead(&matchList, match); } } } if (matchList != NULL) { foundTerms++; for (match = matchList; match != NULL; match = match->next) { mustWrite(f, match->name, strlen(match->name)); mustWrite(f, "\n", 1); } } else { slAddHead(&missingTerms, slNameNew(term->name)); } } slReverse(&missingTerms); carefulClose(&f); cartSetString(cart, hgtaIdentifierDb, database); cartSetString(cart, hgtaIdentifierTable, curTable); cartSetString(cart, hgtaIdentifierFile, tn.forCgi); if (saveIdText) freez(&idTextForLf); else cartRemove(cart, hgtaPastedIdentifiers); int missingCount = totalTerms - foundTerms; if (missingCount > 0) { char *xrefTable, *aliasField; getXrefInfo(conn, &xrefTable, NULL, &aliasField); boolean xrefIsSame = xrefTable && sameString(curTable, xrefTable); struct tempName tn; trashDirFile(&tn, "hgt/missingIds", cartSessionId(cart), ".tmp"); FILE *f = mustOpen(tn.forCgi, "w"); int exampleCount = 0; for (term = missingTerms; term != NULL; term = term->next) { if (exampleCount < 10) { ++exampleCount; dyStringPrintf(exampleMissingIds, "%s\n", term->name); } fprintf(f, "%s\n", term->name); } carefulClose(&f); dyStringPrintf(exampleMissingIds, "\n<a href=%s>Complete list of missing identifiers<a>\n", tn.forHtml); warn("Note: %d of the %d given identifiers have no match in " "table %s, field %s%s%s%s%s. " "Try the \"describe table schema\" button for more " "information about the table and field.\n" "%d %smissing identifier(s):\n" "%s\n", (totalTerms - foundTerms), totalTerms, curTable, idField, (xrefTable ? (xrefIsSame ? "" : " or in alias table ") : ""), (xrefTable ? (xrefIsSame ? "" : xrefTable) : ""), (xrefTable ? (xrefIsSame ? " or in field " : ", field ") : ""), (xrefTable ? aliasField : ""), exampleCount, exampleCount < missingCount ? "example " : "", exampleMissingIds->string ); webNewSection("Table Browser"); } lmCleanup(&lm); hashFree(&matchHash); } else { cartRemove(cart, hgtaIdentifierFile); } mainPageAfterOpen(conn); htmlClose(); }
static struct labeledFile *parseToLabeledFiles(struct customPp *cpp, int colCount, char *formatType, char *markerType, boolean firstLineLabels, struct sqlConnection *conn, boolean report) /* Parse out cpp until next track, creating a list of labeled * binary files. */ { /* Allocate a labeledFile for each column of real data. */ struct labeledFile *fileList = NULL, *fileEl; int posColCount = markerCols(markerType); int i; for (i=posColCount; i<colCount; ++i) { struct tempName tempName; char buf[16]; safef(buf, sizeof(buf), "hggUp%d", i); trashDirFile(&tempName, "hgg", buf, ".cgb"); safef(buf, sizeof(buf), "%d", i+1-posColCount); fileEl = labeledFileNew(tempName.forCgi, buf); slAddHead(&fileList, fileEl); } slReverse(&fileList); boolean ok = FALSE; if (sameString(markerType, cgfMarkerGenomic)) ok = mayProcessGenomic(conn, cpp, colCount, formatType, firstLineLabels, fileList, report); else if (sameString(markerType, cgfMarkerSts)) ok = mayProcessDb(conn, cpp, colCount, formatType, firstLineLabels, fileList, "stsMap", "select chrom,round((chromStart+chromEnd)*0.5),name from %s", "stsAlias", "select alias,trueName from %s", report, FALSE); else if (sameString(markerType, cgfMarkerSnp)) { char *snpTable = hFindLatestSnpTableConn(conn, NULL); if (snpTable == NULL) errAbort("No SNP table in %s", sqlGetDatabase(conn)); char *query = "select chrom,chromStart,name from %s"; ok = mayProcessDb(conn, cpp, colCount, formatType, firstLineLabels, fileList, snpTable, query, NULL, NULL, report, TRUE); } else if (sameString(markerType, cgfMarkerAffy100)) { warn("Support for Affy 100k chip coming soon."); } else if (sameString(markerType, cgfMarkerAffy500) || sameString(markerType, cgfMarkerAffy6) || sameString(markerType, cgfMarkerAffy6SV) || sameString(markerType, cgfMarkerHumanHap300) || sameString(markerType, cgfMarkerHumanHap550) || sameString(markerType, cgfMarkerHumanHap650) || sameString(markerType, cgfMarkerHumanHap1M) || sameString(markerType, cgfMarkerAgilentCgh244A) ) { char *table = ""; if (sameString(markerType, cgfMarkerAffy500)) table = affy500Table; if (sameString(markerType, cgfMarkerAffy6)) table = affy6Table; if (sameString(markerType, cgfMarkerAffy6SV)) table = affy6SVTable; if (sameString(markerType, cgfMarkerHumanHap300)) table = illumina300Table; if (sameString(markerType, cgfMarkerHumanHap550)) table = illumina550Table; if (sameString(markerType, cgfMarkerHumanHap650)) table = illumina650Table; if (sameString(markerType, cgfMarkerHumanHap1M)) table = illumina1MTable; if (sameString(markerType, cgfMarkerAgilentCgh244A)) table = agilentCgh244ATable; if (!sqlTableExists(conn, table)) errAbort("Sorry, no data for %s on this assembly.", markerType); ok = mayProcessDb(conn, cpp, colCount, formatType, firstLineLabels, fileList, table, "select chrom,chromStart,name from %s", NULL, NULL, report, FALSE); } else { errAbort("Unknown identifier format. markerType=%s", markerType); } if (ok) return fileList; else { noWarnAbort(); return NULL; } }
void doStandard(struct cart *theCart) { cart = theCart; cartWebStart(cart, database, "ENCODE DCC Submissions"); struct sqlConnection *conn = sqlConnect(database); struct docIdSub *docIdSub; char query[10 * 1024]; struct sqlResult *sr; char **row; struct tempName tn; trashDirFile(&tn, "docId", "meta", ".txt"); char *tempFile = tn.forCgi; //printf("tempFile is %s\n<BR>", tempFile); // <Data type> <Cell Type> <Key Metadata> <View> printf("<table border=1><tr>"); printf("<th>dataType</th>"); printf("<th>cell type</th>"); printf("<th>metadata</th>"); printf("<th>view</th>"); printf("<th>fileType</th>"); printf("<th>file</th>"); printf("<th>lab</th>"); printf("<th>assembly</th>"); printf("<th>subId</th>"); printf("<th>val-report</th>"); printf("</tr>\n"); safef(query, sizeof query, "select * from %s", docIdTable); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { docIdSub = docIdSubLoad(row); verbose(2, "ix %d\n", docIdSub->ix); verbose(2, "submitDate %s\n", docIdSub->submitDate); verbose(2, "md5sum %s\n", docIdSub->md5sum); verbose(2, "valReport %s\n", docIdSub->valReport); verbose(2, "metaData %s\n", docIdSub->metaData); verbose(2, "submitPath %s\n", docIdSub->submitPath); verbose(2, "submitter %s\n", docIdSub->submitter); cgiDecode(docIdSub->metaData, docIdSub->metaData, strlen(docIdSub->metaData)); //printf("tempFile %s\n", tempFile); FILE *f = mustOpen(tempFile, "w"); fwrite(docIdSub->metaData, strlen(docIdSub->metaData), 1, f); fclose(f); boolean validated; struct mdbObj *mdbObj = mdbObjsLoadFromFormattedFile(tempFile, &validated); unlink(tempFile); // <Data type> <Cell Type> <Key Metadata> <View> char *docIdType = mdbObjFindValue(mdbObj, "type"); char *docIdComposite = mdbObjFindValue(mdbObj, "composite"); char buffer[10 * 1024]; safef(buffer, sizeof buffer, "%d", docIdSub->ix); if (sameString(database, "encpipeline_beta")) docIdDir = docIdDirBeta; printf("<tr>"); printf("<td>%s</td> ", mdbObjFindValue(mdbObj, "dataType")); printf("<td>%s</td> ", mdbObjFindValue(mdbObj, "cell")); struct dyString *str = newDyString(100); addValue(str, mdbObjFindValue(mdbObj, "antibody")); addValue(str, mdbObjFindValue(mdbObj, "treatment")); addValue(str, mdbObjFindValue(mdbObj, "rnaExtract")); addValue(str, mdbObjFindValue(mdbObj, "localization")); printf("<td>%s<a href=docIdView?docId=%s&db=%s&meta=\"\"> ...</a></td>", str->string,buffer, database); freeDyString(&str); printf("<td>%s</td> ", mdbObjFindValue(mdbObj, "view")); printf("<td>%s</td> ", mdbObjFindValue(mdbObj, "type")); printf("<td><a href=%s> %s</a></td>", docIdGetPath(buffer, docIdDir, docIdType, NULL) , docIdDecorate(docIdComposite,docIdSub->ix)); char *lab = mdbObjFindValue(mdbObj, "lab"); char *subId = mdbObjFindValue(mdbObj, "subId"); printf("<td><a href=docIdView?docId=%s&db=%s&lab=\"%s\"> %s</a></td>",buffer, database, subId, lab); printf("<td>%s</td> ", mdbObjFindValue(mdbObj, "assembly")); printf("<td>%s</td> ", subId); printf("<td><a href=docIdView?docId=%s&db=%s&report=\"\"> report</a></td>", buffer, database); printf("</tr>\n"); } printf("</table>"); sqlFreeResult(&sr); sqlDisconnect(&conn); cartWebEnd(); }
void saveSubjList(struct subjInfo *subjListIn) /* save the filtered list of subject gisaids to a file for other applications to use */ { struct subjInfo *subjList; char *outName = cartOptionalString(cart, gisaidSubjList); char *outName2= cartOptionalString(cart, gisaidSeqList); char *outName3= cartOptionalString(cart, gisaidAaSeqList); char *outNameTemp; struct tempName tn; struct tempName tn2; struct tempName tn3; struct tempName tnTemp; struct sqlResult *sr; char **row; char query[255]; int cnt; char cmd[512]; if (!outName) { trashDirFile(&tn, "ct", "gisaidSubj", ".list"); outName = tn.forCgi; } if (!outName2) { trashDirFile(&tn2, "ct", "gisaidSeq", ".list"); outName2 = tn2.forCgi; } if (!outName3) { trashDirFile(&tn3, "ct", "gisaidAaSeq", ".list"); outName3 = tn3.forCgi; } trashDirFile(&tnTemp, "ct", "gisaidListTemp", ".list"); outNameTemp = tnTemp.forCgi; FILE *outF = mustOpen(outName,"w"); FILE *outF2= mustOpen(outName2,"w"); FILE *outF3= mustOpen(outName3,"w"); cnt = 0; subjList = subjListIn; while (subjList) { fprintf(outF, "%s\n", subjList->fields[1]); sqlSafef(query, sizeof(query), "select distinct seqId from h1n1SeqXref where islId='%s'", subjList->fields[0]); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { /* Remove "ss." from the front of the DNA sequence ID, so that they could be used both for DNA and protein MSA maf display */ fprintf(outF2, "%s\t%s\n", row[0], subjList->fields[1]); cnt++; } sqlFreeResult(&sr); subjList=subjList->next; } subjList = subjListIn; while (subjList) { fprintf(outF, "%s\n", subjList->fields[0]); sqlSafef(query, sizeof(query), "select distinct seqId, geneSymbol from h1n1SeqXref where islId='%s'", subjList->fields[0]); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { /* Remove "ss." from the front of the DNA sequence ID, so that they could be used both for DNA and protein MSA maf display */ fprintf(outF3, "%s_%s\t%s\n", row[0], row[1], subjList->fields[1]); cnt++; } sqlFreeResult(&sr); subjList=subjList->next; } carefulClose(&outF); carefulClose(&outF2); carefulClose(&outF3); /* sort -u to make the selection lists unique */ sprintf(cmd, "cat %s |sort -u >%s", outName, outNameTemp); system(cmd); sprintf(cmd, "mv %s %s", outNameTemp, outName); system(cmd); sprintf(cmd, "cat %s |sort -u >%s", outName2, outNameTemp); system(cmd); sprintf(cmd, "mv %s %s", outNameTemp, outName2); system(cmd); sprintf(cmd, "cat %s |sort -u >%s", outName3, outNameTemp); system(cmd); sprintf(cmd, "mv %s %s", outNameTemp, outName3); system(cmd); cartSetString(cart, gisaidSubjList, outName); cartSetString(cart, gisaidSeqList, outName2); cartSetString(cart, gisaidAaSeqList, outName3); }
void doSubmitUserRegions(struct sqlConnection *conn) /* Process submit in set regions page. */ { char *idText = trimSpaces(cartString(cart, hgtaEnteredUserRegions)); char *userRegionFile = trimSpaces(cartString(cart, hgtaEnteredUserRegionFile)); boolean hasData = (idText != NULL && idText[0] != 0) || (userRegionFile != NULL && userRegionFile[0] != 0); /* beware, the string pointers from cartString() point to strings in the * cart hash. If they are manipulated and changed, they will get saved * back to the cart in their changed form. You don't want to be * altering them like that. Thus, the idText is duplicated below with * the cloneString(idText) */ htmlOpen("Table Browser (Region definitions)"); /* presence of fileName text overrides previously existing text area * contents */ if (userRegionFile != NULL && userRegionFile[0] != 0) { idText = cloneString(userRegionFile); cartRemove(cart, hgtaEnteredUserRegions); cartRemove(cart, hgtaUserRegionsFile); cartSetString(cart, hgtaEnteredUserRegions, idText); } else idText = cloneString(idText); char *lineLimitText = limitText(idText); if ( (strlen(lineLimitText) > 0) && (strlen(lineLimitText) != strlen(idText)) ) { freeMem(idText); idText = lineLimitText; cartSetString(cart, hgtaEnteredUserRegions, lineLimitText); } else freeMem(lineLimitText); if (hasData) { struct tempName tn; FILE *f; struct bed *bedEl; struct bed *bedList = parseRegionInput(idText); if (NULL == bedList) errAbort("no valid data points found in input"); trashDirFile(&tn, "hgtData", "user", ".region"); f = mustOpen(tn.forCgi, "w"); for (bedEl = bedList; bedEl; bedEl = bedEl->next ) { if (bedEl->name) fprintf(f, "%s\t%d\t%d\t%s\n", bedEl->chrom, bedEl->chromStart, bedEl->chromEnd, bedEl->name); else fprintf(f, "%s\t%d\t%d\n", bedEl->chrom, bedEl->chromStart, bedEl->chromEnd); } carefulClose(&f); cartSetString(cart, hgtaUserRegionsDb, database); cartSetString(cart, hgtaUserRegionsTable, curTable); cartSetString(cart, hgtaUserRegionsFile, tn.forCgi); cartSetString(cart, hgtaRegionType, hgtaRegionTypeUserRegions); if (strlen(idText) > 64 * 1024) cartRemove(cart, hgtaEnteredUserRegions); } else { cartRemove(cart, hgtaUserRegionsFile); cartRemove(cart, hgtaEnteredUserRegionFile); cartRemove(cart, hgtaRegionType); } mainPageAfterOpen(conn); htmlClose(); }
void doFrame(struct sqlConnection *conn, boolean forceImageToList) /* Make a html frame page. Fill frame with thumbnail, control bar, * and image panes. */ { int imageId = cartUsualInt(cart, hgpId, 0); char *sidUrl = cartSidUrlString(cart); char *listSpec = cartUsualString(cart, hgpListSpec, ""); struct tempName matchTempName; char *matchFile = NULL; struct visiMatch *matchList = visiSearch(conn, listSpec); #ifdef SOON if (!cartUsualBoolean(cart, hgpIncludeMutants, FALSE)) matchList = removeMutants(conn, matchList); #endif /* SOON */ matchList = onePerImageFile(conn, matchList); weighMatches(conn, matchList); slSort(&matchList, visiMatchCmpWeight); if (forceImageToList) { if (matchList != NULL) imageId = matchList->imageId; else imageId = 0; } trashDirFile(&matchTempName, "vg", "visiMatch", ".tab"); matchFile = matchTempName.forCgi; saveMatchFile(matchFile, matchList); cartSetString(cart, hgpMatchFile, matchFile); cartSetInt(cart, hgpId, imageId); //puts("\n"); puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">"); printf("<HTML>\n"); printf("<HEAD>\n"); printf("<TITLE>\n"); printf("%s ", hgVisiGeneShortName()); printf("%s",titleMessage); printf("</TITLE>\n"); printf("</HEAD>\n"); printf(" <frameset rows=\"27,*\">\n"); printf(" <frame name=\"controls\" src=\"%s?%s=go&%s&%s=%d\" noresize marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\">\n", hgVisiGeneCgiName(), hgpDoControls, sidUrl, hgpId, imageId); printf(" <frameset cols=\"230,*\"> \n"); printf(" <frame src=\"%s?%s=go&%s&%s=%d\" noresize frameborder=\"0\" name=\"list\">\n", hgVisiGeneCgiName(), hgpDoThumbnails, sidUrl, hgpId, imageId); printf(" <frame src=\"%s?%s=go&%s&%s=%d\" name=\"image\" noresize frameborder=\"0\">\n", hgVisiGeneCgiName(), hgpDoImage, sidUrl, hgpId, imageId); printf(" </frameset>\n"); printf(" <noframes>\n"); printf(" <body>\n"); printf(" <p>This web page uses frames, but your browser doesn't support them.</p>\n"); printf(" </body>\n"); printf(" </noframes>\n"); printf("</frameset>\n"); printf("</HTML>\n"); }
void saveSubjList(struct subjInfo *subjList) /* save the filtered list of subject gsids to a file for other applications to use */ { char *outName = cartOptionalString(cart, gsidSubjList); char *outName2= cartOptionalString(cart, gsidSeqList); struct tempName tn; struct tempName tn2; struct sqlResult *sr; char **row; char query[255]; char *chp; int cnt; if (!outName) { trashDirFile(&tn, "ct", "gsidSubj", ".list"); outName = tn.forCgi; } if (!outName2) { trashDirFile(&tn2, "ct", "gsidSeq", ".list"); outName2 = tn2.forCgi; } FILE *outF = mustOpen(outName,"w"); FILE *outF2= mustOpen(outName2,"w"); cnt = 0; while (subjList) { fprintf(outF, "%s\n", subjList->fields[0]); sqlSafef(query, sizeof(query), "select dnaSeqId from gsIdXref where subjId='%s'", subjList->fields[0]); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { /* Remove "ss." from the front of the DNA sequence ID, so that they could be used both for DNA and protein MSA maf display */ chp = strstr(row[0], "ss."); if (chp != NULL) { fprintf(outF2, "%s\t%s\n", chp+3L, subjList->fields[0]); } else { fprintf(outF2, "%s\t%s\n", row[0], subjList->fields[0]); } cnt++; } sqlFreeResult(&sr); subjList=subjList->next; } carefulClose(&outF); carefulClose(&outF2); cartSetString(cart, gsidSubjList, outName); cartSetString(cart, gsidSeqList, outName2); }
void doTracks(char *proteinID, char *mrnaID, char *aa, int *yOffp, char *psOutput) /* draw various protein tracks */ { int l; char aaOrigOffsetStr[20]; int hasResFreq; char uniProtDbName[50]; char *protDbDate; char *chrom; char strand; char *kgId, *kgPep, *protPep; char cond_str[255]; char *answer; //int i, ll; //char *chp1, *chp2; g_font = mgSmallFont(); safef(pbScaleStr, sizeof(pbScaleStr), "%d", pbScale); if (psOutput != NULL) { pbScale = atoi(cartOptionalString(cart, "pbt.pbScaleStr")); } if (cgiOptionalString("trackOffset") != NULL) { trackOrigOffset = atoi(cgiOptionalString("trackOffset")); } if (cgiOptionalString("pbScaleStr") != NULL) { pbScale = atoi(cgiOptionalString("pbScaleStr")); } if (cgiOptionalString("pbScale") != NULL) { scaleButtonPushed = TRUE; if (strcmp(cgiOptionalString("pbScale"), "1/6") == 0) pbScale = 1; if (strcmp(cgiOptionalString("pbScale"), "1/2") == 0) pbScale = 3; if (strcmp(cgiOptionalString("pbScale"), "FULL") == 0) pbScale = 6; if (strcmp(cgiOptionalString("pbScale"), "DNA") == 0) pbScale =22; safef(pbScaleStr, sizeof(pbScaleStr), "%d", pbScale); cgiMakeHiddenVar("pbScaleStr", pbScaleStr); } else { scaleButtonPushed = FALSE; } if (psOutput == NULL) { if (cgiVarExists("pbt.left3")) { relativeScroll(-0.95); initialWindow = FALSE; } else if (cgiVarExists("pbt.left2")) { relativeScroll(-0.475); initialWindow = FALSE; } else if (cgiVarExists("pbt.left1")) { relativeScroll(-0.02); initialWindow = FALSE; } else if (cgiVarExists("pbt.right1")) { relativeScroll(0.02); initialWindow = FALSE; } else if (cgiVarExists("pbt.right2")) { relativeScroll(0.475); initialWindow = FALSE; } else if (cgiVarExists("pbt.right3")) { relativeScroll(0.95); initialWindow = FALSE; } } dnaUtilOpen(); l=strlen(aa); /* initialize AA properties */ aaPropertyInit(&hasResFreq); sfCount = getSuperfamilies2(proteinID); if (sfCount == 0) { sfCount = getSuperfamilies(proteinID); } if (mrnaID != NULL) { if (kgVersion == KG_III) { doExonTrack = FALSE; sqlSafefFrag(cond_str, sizeof(cond_str), "spId='%s'", proteinID); kgId = sqlGetField(database, "kgXref", "kgId", cond_str); if (kgId != NULL) { sqlSafefFrag(cond_str, sizeof(cond_str), "name='%s'", kgId); kgPep = sqlGetField(database, "knownGenePep", "seq", cond_str); //printf("<pre><br>%s", kgPep);fflush(stdout); if (kgPep != NULL) { if (strstr(protDbName, "proteins") != NULL) { protDbDate = strstr(protDbName, "proteins") + strlen("proteins"); safef(uniProtDbName, sizeof(uniProtDbName),"sp%s", protDbDate); sqlSafefFrag(cond_str, sizeof(cond_str), "acc='%s'", proteinID); protPep = sqlGetField(uniProtDbName, "protein", "val", cond_str); //printf("<br>%s\n", protPep);fflush(stdout); if (protPep != NULL) { if (sameWord(kgPep, protPep)) { //printf("<br>MATCH!\n");fflush(stdout); sqlSafefFrag(cond_str, sizeof(cond_str), "qName='%s'", kgId); answer = sqlGetField(database, kgProtMapTableName, "qName", cond_str); if (answer != NULL) { /* NOTE: passing in kgId instead of proteinID because kgProtMap2's qName uses kgId instead of protein display ID */ getExonInfo(kgId, &exCount, &chrom, &strand); assert(exCount > 0); doExonTrack = TRUE; } } /* else { chp1 = kgPep; printf("<br>"); chp2 = protPep; ll = strlen(kgPep); if (strlen(protPep) < ll) ll= strlen(protPep); for (i=0; i<ll; i++) { if (*chp1 != *chp2) { printf("%c", *chp1); } else { printf("."); } chp1++; chp2++; } } //printf("</pre>");fflush(stdout); */ } } } } } else { doExonTrack = TRUE; getExonInfo(proteinID, &exCount, &chrom, &strand); assert(exCount > 0); } /* do the following only if pbTracks called doTracks() */ if (initialWindow && IAmPbTracks) { prevGBOffsetSav = calPrevGB(exCount, chrom, strand, l, yOffp, proteinID, mrnaID); trackOrigOffset = prevGBOffsetSav; if (trackOrigOffset > (protSeqLen*pbScale - 600)) trackOrigOffset = protSeqLen*pbScale - 600; /* prevent negative value */ if (trackOrigOffset < 0) trackOrigOffset = 0; } /* if this if for PDF/Postscript, the trackOrigOffset is already calculated previously, use the saved value */ if (psOutput != NULL) { trackOrigOffset = atoi(cartOptionalString(cart, "pbt.trackOffset")); } } /*printf("<br>%d %d<br>%d %d\n", prevGBStartPos, prevGBEndPos, blockGenomeStartPositive[exCount-1], blockGenomeStartPositive[0]); fflush(stdout); */ if (strand == '-') { if ((prevGBStartPos <= blockGenomeStartPositive[exCount-1]) && (prevGBEndPos >= blockGenomeStartPositive[0])) { showPrevGBPos = FALSE; } } else { if ((prevGBStartPos <= blockGenomeStartPositive[0]) && (prevGBEndPos >= blockGenomeStartPositive[exCount-1])) { showPrevGBPos = FALSE; } } if ((cgiOptionalString("aaOrigOffset") != NULL) && scaleButtonPushed) { trackOrigOffset = atoi(cgiOptionalString("aaOrigOffset"))*pbScale; } pixWidth = 160+ protSeqLen*pbScale; if (pixWidth > MAX_PB_PIXWIDTH) { pixWidth = MAX_PB_PIXWIDTH; } if ((protSeqLen*pbScale - trackOrigOffset) < MAX_PB_PIXWIDTH) { pixWidth = protSeqLen*pbScale - trackOrigOffset + 160; } if (pixWidth < 550) pixWidth = 550; insideWidth = pixWidth-gfxBorder; if (proteinInSupportedGenome) { pixHeight = 250; } else { pixHeight = 215; } if (sfCount > 0) pixHeight = pixHeight + 20; /* make room for individual residues display */ if (pbScale >=6) pixHeight = pixHeight + 20; if (pbScale >=18) pixHeight = pixHeight + 30; if (psOutput) { vg = vgOpenPostScript(pixWidth, pixHeight, psOutput); suppressHtml = TRUE; hideControls = TRUE; } else { trashDirFile(&gifTn, "pbt", "pbt", ".png"); vg = vgOpenPng(pixWidth, pixHeight, gifTn.forCgi, FALSE); } /* Put up horizontal scroll controls. */ hWrites("Move "); hButton("pbt.left3", "<<<"); hButton("pbt.left2", " <<"); hButton("pbt.left1", " < "); hButton("pbt.right1", " > "); hButton("pbt.right2", ">> "); hButton("pbt.right3", ">>>"); hPrintf("     "); /* Put up scaling controls. */ hPrintf("Current scale: "); if (pbScale == 1) hPrintf("1/6 "); if (pbScale == 3) hPrintf("1/2 "); if (pbScale == 6) hPrintf("FULL "); if (pbScale == 22) hPrintf("DNA "); hPrintf("    Rescale to "); hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"1/6\">\n"); hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"1/2\">\n"); hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"FULL\">\n"); if (kgVersion == KG_III) { /* for KG III, the protein has to exist in the kgProtMap2 table (which will turn on doExonTrack flag) to provide the genomic position data needed for DNA sequence display */ if ((proteinInSupportedGenome) && (doExonTrack)) hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"DNA\">\n"); } else { if (proteinInSupportedGenome) hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"DNA\">\n"); } hPrintf("<FONT SIZE=1><BR><BR></FONT>\n"); g_vg = vg; pbRed = vgFindColorIx(g_vg, 0xf9, 0x51, 0x59); pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0); bkgColor = vgFindColorIx(vg, 255, 254, 232); vgBox(vg, 0, 0, insideWidth, pixHeight, bkgColor); /* Start up client side map. */ hPrintf("<MAP Name=%s>\n", mapName); vgSetClip(vg, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder); /* start drawing indivisual tracks */ doAAScale(l, yOffp, 1); if (pbScale >= 6) doResidues(aa, l, yOffp); if (pbScale >= 18) doDnaTrack(chrom, strand, exCount, l, yOffp); if ((mrnaID != NULL) && showPrevGBPos) { doPrevGB(exCount, chrom, strand, l, yOffp, proteinID, mrnaID); } if (mrnaID != NULL) { if (doExonTrack) doExon(exCount, chrom, l, yOffp, proteinID, mrnaID); } doCharge(aa, l, yOffp); doHydrophobicity(aa, l, yOffp); doCysteines(aa, l, yOffp); if (sfCount > 0) doSuperfamily(ensPepName, sfCount, yOffp); if (hasResFreq) doAnomalies(aa, l, yOffp); doAAScale(l, yOffp, -1); vgClose(&vg); /* Finish map and save out picture and tell html file about it. */ hPrintf("</MAP>\n"); /* put tracks image here */ hPrintf( "\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>", gifTn.forCgi, pixWidth, pixHeight, mapName); if (proteinInSupportedGenome) { hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#tracks\" TARGET=_blank>"); } else { if (hIsGsidServer()) { hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbGsid/pbTracksHelp.shtml#tracks\" TARGET=_blank>"); } else { hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#tracks\" TARGET=_blank>"); } } hPrintf("Explanation of Protein Tracks</A><br>"); safef(trackOffset, sizeof(trackOffset), "%d", trackOrigOffset); cgiMakeHiddenVar("trackOffset", trackOffset); /* remember where the AA base origin is so that it can be passed to next PB page */ aaOrigOffset = trackOrigOffset/pbScale; safef(aaOrigOffsetStr, sizeof(aaOrigOffsetStr), "%d", aaOrigOffset); cgiMakeHiddenVar("aaOrigOffset", aaOrigOffsetStr); /* save the following state variables, to be used by PDF/Postcript processing */ cartSetString(cart,"pbt.pbScaleStr", pbScaleStr); cartSetString(cart,"pbt.trackOffset", trackOffset); cartSaveSession(cart); fflush(stdout); }
// TODO move this to a generic re-usable location void startBackgroundWork(char *exec, char **pWorkUrl) /* deal with forking off child for background work * and setting up the trash file for communicating * from the child to the browser */ { char *workUrl = NULL; char hgsid[64]; struct tempName tn; safef(hgsid, sizeof(hgsid), "%s", cartSessionId(cart)); trashDirFile(&tn, "backGround", hgsid, ".tmp"); workUrl = cloneString(tn.forCgi); fflush(stdout); fflush(stderr); // seems that we need to use the double-fork trick // to create enough separation between the non-waiting parent // and the grand-child process. otherwise the OS and Apache are waiting on the child. int pid = fork(); if (pid == -1) { errAbort("can't fork, error %d", errno); } if (pid == 0) // child { int pid2 = fork(); if (pid2 == -1) { errAbort("can't fork, error %d", errno); } if (pid2 == 0) // grand child { // we need to close or redup to open stdout, stderr, stdin // in order for apache to break ties with it. // Will the grandchild cgi still be able to function? // redirect stdout of child to the trash file for easier use of // library functions that output html to stdout. int out = mustOpenFd(tn.forCgi, O_WRONLY | O_CREAT); fflush(stdout); dup2(out,STDOUT_FILENO); /* closes STDOUT before setting it back to saved descriptor */ close(out); // Unfortunately we must create our own stderr log file char errName[1024]; safef(errName, sizeof errName, "%s.err", tn.forCgi); int err = mustOpenFd(errName, O_CREAT | O_WRONLY | O_APPEND); dup2(err, STDERR_FILENO); close(err); // stdin input is just empty int in = mustOpenFd("/dev/null", O_RDONLY); dup2(in, STDIN_FILENO); close(in); // execute so that we will be able to use database and other operations normally. char execPath[4096]; safef(execPath, sizeof execPath, "%s hgsid=%s", exec, hgsid); char *args[10]; int numArgs = chopString(execPath, " ", args, 10); args[numArgs] = NULL; // by creating a minimal environment and not inheriting from the parent, // it cause cgiSpoof to run, picking up command-line params as cgi vars. char *newenviron[] = { "HGDB_CONF=hg.conf", NULL }; int sleepSeconds = 1; // was 5 sleep(sleepSeconds); // Give the foreground process time to write the cart. execve(args[0], args+1, newenviron); // SHOULD NOT GET HERE UNLESS EXEC FAILED. verbose(1,"execve failed for %s\n", exec); _exit(0); // exit without the usual cleanup which messes up parent's db connections etc. } else // child { _exit(0); // exit without the usual cleanup which messes up parent's db connections etc. } } else // parent { *pWorkUrl = workUrl; // wait for the exiting child (not grandchild) int w, status; do { w = waitpid(pid, &status, WUNTRACED | WCONTINUED); if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); } if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) verbose(1, "exited, status=%d\n", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { verbose(1, "killed by signal %d\n", WTERMSIG(status)); } else if (WIFSTOPPED(status)) { verbose(1, "stopped by signal %d\n", WSTOPSIG(status)); } else if (WIFCONTINUED(status)) { verbose(1, "continued\n"); } } while (!WIFEXITED(status) && !WIFSIGNALED(status)); // done waiting for child. } }
void blatSeq(char *userSeq, char *organism) /* Blat sequence user pasted in. */ { FILE *f; struct dnaSeq *seqList = NULL, *seq; struct tempName pslTn, faTn; int maxSingleSize, maxTotalSize, maxSeqCount; int minSingleSize = minMatchShown; char *genome, *db; char *type = cgiString("type"); char *seqLetters = cloneString(userSeq); struct serverTable *serve; int conn; int oneSize, totalSize = 0, seqCount = 0; boolean isTx = FALSE; boolean isTxTx = FALSE; boolean txTxBoth = FALSE; struct gfOutput *gvo; boolean qIsProt = FALSE; enum gfType qType, tType; struct hash *tFileCache = gfFileCacheNew(); boolean feelingLucky = cgiBoolean("Lucky"); getDbAndGenome(cart, &db, &genome, oldVars); if(!feelingLucky) cartWebStart(cart, db, "%s BLAT Results", trackHubSkipHubName(organism)); /* Load user sequence and figure out if it is DNA or protein. */ if (sameWord(type, "DNA")) { seqList = faSeqListFromMemText(seqLetters, TRUE); uToT(seqList); isTx = FALSE; } else if (sameWord(type, "translated RNA") || sameWord(type, "translated DNA")) { seqList = faSeqListFromMemText(seqLetters, TRUE); uToT(seqList); isTx = TRUE; isTxTx = TRUE; txTxBoth = sameWord(type, "translated DNA"); } else if (sameWord(type, "protein")) { seqList = faSeqListFromMemText(seqLetters, FALSE); isTx = TRUE; qIsProt = TRUE; } else { seqList = faSeqListFromMemTextRaw(seqLetters); isTx = !seqIsDna(seqList); if (!isTx) { for (seq = seqList; seq != NULL; seq = seq->next) { seq->size = dnaFilteredSize(seq->dna); dnaFilter(seq->dna, seq->dna); toLowerN(seq->dna, seq->size); subChar(seq->dna, 'u', 't'); } } else { for (seq = seqList; seq != NULL; seq = seq->next) { seq->size = aaFilteredSize(seq->dna); aaFilter(seq->dna, seq->dna); toUpperN(seq->dna, seq->size); } qIsProt = TRUE; } } if (seqList != NULL && seqList->name[0] == 0) { freeMem(seqList->name); seqList->name = cloneString("YourSeq"); } trimUniq(seqList); /* If feeling lucky only do the first on. */ if(feelingLucky && seqList != NULL) { seqList->next = NULL; } /* Figure out size allowed. */ maxSingleSize = (isTx ? 10000 : 75000); maxTotalSize = maxSingleSize * 2.5; #ifdef LOWELAB maxSeqCount = 200; #else maxSeqCount = 25; #endif /* Create temporary file to store sequence. */ trashDirFile(&faTn, "hgSs", "hgSs", ".fa"); faWriteAll(faTn.forCgi, seqList); /* Create a temporary .psl file with the alignments against genome. */ trashDirFile(&pslTn, "hgSs", "hgSs", ".pslx"); f = mustOpen(pslTn.forCgi, "w"); gvo = gfOutputPsl(0, qIsProt, FALSE, f, FALSE, TRUE); serve = findServer(db, isTx); /* Write header for extended (possibly protein) psl file. */ if (isTx) { if (isTxTx) { qType = gftDnaX; tType = gftDnaX; } else { qType = gftProt; tType = gftDnaX; } } else { qType = gftDna; tType = gftDna; } pslxWriteHead(f, qType, tType); if (qType == gftProt) { minSingleSize = 14; } else if (qType == gftDnaX) { minSingleSize = 36; } /* Loop through each sequence. */ for (seq = seqList; seq != NULL; seq = seq->next) { printf(" "); fflush(stdout); /* prevent apache cgi timeout by outputting something */ oneSize = realSeqSize(seq, !isTx); if ((seqCount&1) == 0) // Call bot delay every 2nd time starting with first time hgBotDelay(); if (++seqCount > maxSeqCount) { warn("More than 25 input sequences, stopping at %s.", seq->name); break; } if (oneSize > maxSingleSize) { warn("Sequence %s is %d letters long (max is %d), skipping", seq->name, oneSize, maxSingleSize); continue; } if (oneSize < minSingleSize) { warn("Warning: Sequence %s is only %d letters long (%d is the recommended minimum)", seq->name, oneSize, minSingleSize); // we could use "continue;" here to actually enforce skipping, // but let's give the short sequence a chance, it might work. // minimum possible length = tileSize+stepSize, so mpl=16 for dna stepSize=5, mpl=10 for protein. if (qIsProt && oneSize < 1) // protein does not tolerate oneSize==0 continue; } totalSize += oneSize; if (totalSize > maxTotalSize) { warn("Sequence %s would take us over the %d letter limit, stopping here.", seq->name, maxTotalSize); break; } conn = gfConnect(serve->host, serve->port); if (isTx) { gvo->reportTargetStrand = TRUE; if (isTxTx) { gfAlignTransTrans(&conn, serve->nibDir, seq, FALSE, 5, tFileCache, gvo, !txTxBoth); if (txTxBoth) { reverseComplement(seq->dna, seq->size); conn = gfConnect(serve->host, serve->port); gfAlignTransTrans(&conn, serve->nibDir, seq, TRUE, 5, tFileCache, gvo, FALSE); } } else { gfAlignTrans(&conn, serve->nibDir, seq, 5, tFileCache, gvo); } } else { gfAlignStrand(&conn, serve->nibDir, seq, FALSE, minMatchShown, tFileCache, gvo); reverseComplement(seq->dna, seq->size); conn = gfConnect(serve->host, serve->port); gfAlignStrand(&conn, serve->nibDir, seq, TRUE, minMatchShown, tFileCache, gvo); } gfOutputQuery(gvo, f); } carefulClose(&f); showAliPlaces(pslTn.forCgi, faTn.forCgi, serve->db, qType, tType, organism, feelingLucky); if(!feelingLucky) cartWebEnd(); gfFileCacheFree(&tFileCache); }
void docIdTidy(char *database, char *docIdDir) /* docIdTidy - tidy up the docId library by compressing and md5suming where appropriate. */ { char query[10 * 1024]; struct sqlResult *sr; char **row; struct sqlConnection *conn = sqlConnect(database); struct tempName tn; trashDirFile(&tn, "docId", "meta", ".txt"); char *tempFile = tn.forCgi; struct toDoList *toDoList = NULL; safef(query, sizeof query, "select * from %s", docIdTable); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { struct docIdSub *docIdSub = docIdSubLoad(row); cgiDecode(docIdSub->metaData, docIdSub->metaData, strlen(docIdSub->metaData)); FILE *f = mustOpen(tempFile, "w"); fwrite(docIdSub->metaData, strlen(docIdSub->metaData), 1, f); fclose(f); boolean validated; //printf("metadata is %s\n", docIdSub->metaData); struct mdbObj *mdbObj = mdbObjsLoadFromFormattedFile(tempFile, &validated); unlink(tempFile); char *docIdType = mdbObjFindValue(mdbObj, "type"); char buffer[10 * 1024]; safef(buffer, sizeof buffer, "%d", docIdSub->ix); char *path = docIdGetPath(buffer, docIdDir, docIdType, NULL); //docIdDecorate(docIdSub->ix)); printf("path %s\n", path); struct toDoList *toDoItem = NULL; if (!fileIsCompressed(path)) { if (toDoItem == NULL) AllocVar(toDoItem); printf("foo\n"); toDoItem->needs |= NEEDS_COMPRESSION; toDoItem->path = path; toDoItem->docId = docIdSub->ix; } printf("docId %d md5sum %s valReport %s\n",docIdSub->ix, docIdSub->md5sum, docIdSub->valReport); //if (docIdSub->md5sum == NULL) if (sameString(docIdSub->md5sum, "")) { printf("mdsum\n"); if (toDoItem == NULL) AllocVar(toDoItem); toDoItem->needs |= NEEDS_MD5SUM; toDoItem->path = path; toDoItem->docId = docIdSub->ix; } //if (docIdSub->valReport == NULL) if (sameString(docIdSub->valReport,"")) { printf("report\n"); if (toDoItem == NULL) AllocVar(toDoItem); toDoItem->needs |= NEEDS_REPORT; toDoItem->path = path; toDoItem->docId = docIdSub->ix; } if (toDoItem) slAddHead(&toDoList, toDoItem); } sqlFreeResult(&sr); doCompression(toDoList); doReports(toDoList); doMd5Summing(toDoList); }
void makeActiveImagePB(char *psOutput, char *psOutput2) /* Make image and image map. */ { char *mapName = "map"; int pixWidth, pixHeight; char *answer; char cond_str[255]; struct sqlConnection *conn; struct sqlConnection *connCentral; char query[256]; struct sqlResult *sr; char **row; int iypos; char *blatGbDb; char *sciName, *commonName; char *spDisplayId; char *oldDisplayId; conn = sqlConnect(UNIPROT_DB_NAME); hPrintf("<br><font size=4>Protein "); hPrintf("<A HREF=\"http://www.uniprot.org/uniprot/%s\" TARGET=_blank><B>%s</B></A>\n", proteinID, proteinID); spDisplayId = spAccToId(conn, spFindAcc(conn, proteinID)); if (strstr(spDisplayId, spFindAcc(conn, proteinID)) == NULL) { hPrintf(" (aka %s", spDisplayId); /* show once if the new and old displayId are the same */ oldDisplayId = oldSpDisplayId(spDisplayId); if (oldDisplayId != NULL) { if (!sameWord(spDisplayId, oldDisplayId)) { hPrintf(" or %s", oldSpDisplayId(spDisplayId)); } } hPrintf(")\n"); } hPrintf(" %s\n", description); hPrintf("</font><br>"); hPrintf("Organism: "); /* get scientific and Genbank common name of this organism */ sciName = NULL; commonName = NULL; sqlSafefFrag(cond_str, sizeof(cond_str),"accession='%s'", proteinID); answer = sqlGetField(PROTEOME_DB_NAME, "spXref3", "division", cond_str); if (answer != NULL) { sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='scientific name'", answer); sciName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='genbank common name'", answer); commonName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); } if (sciName != NULL) { hPrintf("%s", sciName); } if (commonName != NULL) { hPrintf(" (%s)", commonName); } hPrintf("<br>"); protSeq = getAA(proteinID); if (protSeq == NULL) { hUserAbort("%s is not a current valid entry in UniProtKB\n", proteinID); } protSeqLen = strlen(protSeq); fflush(stdout); iypos = 15; doTracks(proteinID, mrnaID, protSeq, &iypos, psOutput); if (!hTableExists(database, "pbStamp")) goto histDone; pbScale = 3; pixWidth = 765; insideWidth = pixWidth-gfxBorder; pixHeight = 350; if (psOutput2) { vg2 = vgOpenPostScript(pixWidth, pixHeight, psOutput2); } else { trashDirFile(&gifTn2, "pbt", "pbt", ".png"); vg2 = vgOpenPng(pixWidth, pixHeight, gifTn2.forCgi, FALSE); } g_vg = vg2; pbRed = vgFindColorIx(vg2, 0xf9, 0x51, 0x59); pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0); normalColor = pbBlue; abnormalColor = pbRed; bkgColor = vgFindColorIx(vg2, 255, 254, 232); vgBox(vg2, 0, 0, insideWidth, pixHeight, bkgColor); /* Start up client side map. */ mapName=cloneString("pbStamps"); hPrintf("\n<MAP Name=%s>\n", mapName); vgSetClip(vg2, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder); iypos = 15; /* Draw stamps. */ doStamps(proteinID, mrnaID, protSeq, vg2, &iypos); /* Finish map. */ hPrintf("</MAP>\n"); /* Save out picture and tell html file about it. */ vgClose(&vg2); hPrintf("<P>"); hPrintf("\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>", gifTn2.forCgi, pixWidth, pixHeight, mapName); if (proteinInSupportedGenome) { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } else { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } hPrintf("Explanation of Protein Property Histograms</A><BR>"); hPrintf("<P>"); histDone: hPrintf("<P>"); fflush(stdout); /* See if a UCSC Genome Browser exist for this organism. If so, display BLAT link. */ connCentral = hConnectCentral(); sqlSafef(query, sizeof(query), "select defaultDb.name from dbDb, defaultDb where dbDb.scientificName='%s' and dbDb.name=defaultDb.name", sciName); sr = sqlGetResult(connCentral, query); row = sqlNextRow(sr); if (row != NULL) { blatGbDb = strdup(row[0]); } else { blatGbDb = NULL; } sqlFreeResult(&sr); hDisconnectCentral(&connCentral); if (proteinInSupportedGenome || (blatGbDb != NULL)) { hPrintf("\n<B>UCSC Links:</B><BR>\n "); hPrintf("<UL>\n"); /* Show GB links only if the protein belongs to a supported genome */ if (proteinInSupportedGenome) { doGenomeBrowserLink(proteinID, mrnaID, hgsidStr); doGeneDetailsLink(proteinID, mrnaID, hgsidStr); } /* Show Gene Sorter link only if it is valid for this genome */ if (hgNearOk(database)) { doGeneSorterLink(protDisplayID, mrnaID, hgsidStr); } /* Show BLAT link if we have UCSC Genome Browser for it */ if (blatGbDb != NULL) { doBlatLink(blatGbDb, sciName, commonName, protSeq); } hPrintf("</UL><P>"); } /* This section shows various types of domains */ conn = sqlConnect(UNIPROT_DB_NAME); domainsPrint(conn, proteinID); hPrintf("<P>"); /* Do Pathway section only if the protein belongs to a supported genome */ if (proteinInSupportedGenome); { doPathwayLinks(proteinID, mrnaID); } printFASTA(proteinID, protSeq); }
void makeActiveImagePB(char *psOutput, char *psOutput2) /* Make image and image map. */ { char *mapName = "map"; int pixWidth, pixHeight; struct sqlConnection *conn; char query[256]; struct sqlResult *sr; char **row; int iypos; char *spDisplayId; char *oldDisplayId; conn = sqlConnect(UNIPROT_DB_NAME); printf("<BR>"); hPrintf("<BR><font size=4><B>Protein: "); hPrintf("%s</B>", proteinID); /* Please note the hiv database name is hard wired here.*/ safef(query, sizeof(query), "select subjId from hivVax003Vax004.gsIdXref where aaSeqId = '%s'", proteinID); sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); if (row != NULL) { printf("<BR>"); hPrintf("<font size=4><B>Subject: "); hPrintf("<A HREF=\"../cgi-bin/gsidSubj?hgs_subj=%s&submit=Go!\">", row[0]); hPrintf("%s</A></B><BR>", row[0]); } sqlFreeResult(&sr); spDisplayId = spAccToId(conn, spFindAcc(conn, proteinID)); if (strstr(spDisplayId, spFindAcc(conn, proteinID)) == NULL) { hPrintf(" (aka %s", spDisplayId); /* show once if the new and old displayId are the same */ oldDisplayId = oldSpDisplayId(spDisplayId); if (oldDisplayId != NULL) { if (!sameWord(spDisplayId, oldDisplayId)) { hPrintf(" or %s", oldSpDisplayId(spDisplayId)); } } hPrintf(")\n"); } hPrintf("</font><br>"); protSeq = getAA(proteinID); if (protSeq == NULL) { errAbort("%s is not a current valid entry in UniProt(SWISS-PROT/TrEMBL)\n", proteinID); } protSeqLen = strlen(protSeq); fflush(stdout); iypos = 15; doTracks(proteinID, mrnaID, protSeq, &iypos, psOutput); if (!hTableExists(database, "pbStamp")) goto histDone; pbScale = 3; pixWidth = 520; insideWidth = pixWidth-gfxBorder; pixHeight = 350; if (psOutput2) { vg2 = vgOpenPostScript(pixWidth, pixHeight, psOutput2); } else { trashDirFile(&gifTn2, "pbt", "pbt", ".gif"); vg2 = vgOpenGif(pixWidth, pixHeight, gifTn2.forCgi, FALSE); } g_vg = vg2; pbRed = vgFindColorIx(vg2, 0xf9, 0x51, 0x59); pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0); normalColor = pbBlue; abnormalColor = pbRed; bkgColor = vgFindColorIx(vg2, 255, 254, 232); vgBox(vg2, 0, 0, insideWidth, pixHeight, bkgColor); /* Start up client side map. */ mapName=cloneString("pbStamps"); hPrintf("\n<MAP Name=%s>\n", mapName); vgSetClip(vg2, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder); iypos = 15; /* Draw stamps. */ doStamps(proteinID, mrnaID, protSeq, vg2, &iypos); /* Finish map. */ hPrintf("</MAP>\n"); /* Save out picture and tell html file about it. */ vgClose(&vg2); hPrintf("<P>"); hPrintf("\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>", gifTn2.forCgi, pixWidth, pixHeight, mapName); if (proteinInSupportedGenome) { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } else { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbGsid/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } hPrintf("Explanation of Protein Property Histograms</A><BR>"); hPrintf("<P>"); histDone: hPrintf("<P>"); fflush(stdout); printFASTA(proteinID, protSeq); }
void sortGenes(struct sqlConnection *conn) /* Put up sort gene page. */ { cartWebStart(cart, database, "Finding Candidate Genes for Gene Sorter"); if (!hgNearOk(database)) errAbort("Sorry, gene sorter not available for this database."); /* Get list of regions. */ struct genoGraph *gg = ggFirstVisible(); double threshold = getThreshold(); struct bed3 *bed, *bedList = regionsOverThreshold(gg); /* Figure out what table and column are the sorter's main gene set. */ struct hash *genomeRa = hgReadRa(genome, database, "hgNearData", "genome.ra", NULL); char *geneTable = hashMustFindVal(genomeRa, "geneTable"); char *idColumn = hashMustFindVal(genomeRa, "idColumn"); /* if marker labels were present when the file was uploaded, they are saved here */ char cgmName[256]; safef(cgmName, sizeof(cgmName), "%s.cgm", gg->binFileName); struct lineFile *m = lineFileMayOpen(cgmName, TRUE); char *cgmRow[4]; cgmRow[0] = ""; /* dummy row */ cgmRow[1] = ""; cgmRow[2] = "0"; cgmRow[3] = "0"; FILE *g = NULL; int markerCount = 0; struct tempName snpTn; if (m) { /* Create custom column output file. */ trashDirFile(&snpTn, "hgg", "marker", ".mrk"); g = mustOpen(snpTn.forCgi, "w"); fprintf(g, "column name=\"%s Markers\" shortLabel=\"%s Markers over threshold\" longLabel=\"%s Markers in regions over threshold\" " "visibility=on priority=99 " "\n" , gg->shortLabel , gg->shortLabel , gg->shortLabel ); } /*** Build up hash of all transcriptHash that are in region. */ struct hash *transcriptHash = hashNew(16); /* This loop handles one chromosome at a time. It depends on * the bedList being sorted by chromosome. */ for (bed = bedList; bed != NULL; ) { /* Make binKeeper and stuff in all regions in this chromosome into it. */ char *chrom = bed->chrom; int chromSize = hChromSize(database, chrom); struct binKeeper *bk = binKeeperNew(0, chromSize); while (bed != NULL && sameString(chrom, bed->chrom)) { binKeeperAdd(bk, bed->chromStart, bed->chromEnd, bed); bed = bed->next; } struct binKeeper *bkGenes = NULL; if (m) bkGenes = binKeeperNew(0, chromSize); /* Query database to find out bounds of all genes on this chromosome * and if they overlap any of the regions then put them in the hash. */ char query[512]; safef(query, sizeof(query), "select name,txStart,txEnd from %s where chrom='%s'", geneTable, chrom); struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { char *name = row[0]; int start = sqlUnsigned(row[1]); int end = sqlUnsigned(row[2]); if (binKeeperAnyOverlap(bk, start, end)) { hashStore(transcriptHash, name); if (m) binKeeperAdd(bkGenes, start, end, cloneString(name)); } } sqlFreeResult(&sr); if (m) { /* Read cgm file if it exists, looking at all markers on this chromosome * and if they overlap any of the regions and genes then output them. */ do { // marker, chrom, chromStart, val char *marker = cgmRow[0]; char *chr = cgmRow[1]; int start = sqlUnsigned(cgmRow[2]); int end = start+1; double val = sqlDouble(cgmRow[3]); int cmp = strcmp(chr,chrom); if (cmp > 0) break; if (cmp == 0) { if (val >= threshold) { struct binElement *el, *bkList = binKeeperFind(bkGenes, start, end); for (el = bkList; el; el=el->next) { /* output to custom column trash file */ fprintf(g, "%s %s\n", (char *)el->val, marker); } if (bkList) { ++markerCount; slFreeList(&bkList); } } } } while (lineFileRow(m, cgmRow)); } /* Clean up for this chromosome. */ binKeeperFree(&bk); if (m) { /* For speed, we do not free up the values (cloned the kg names earlier) */ binKeeperFree(&bkGenes); } } /* Get list of all transcripts in regions. */ struct hashEl *el, *list = hashElListHash(transcriptHash); /* Create file with all matching gene IDs. */ struct tempName keyTn; trashDirFile(&keyTn, "hgg", "key", ".key"); FILE *f = mustOpen(keyTn.forCgi, "w"); for (el = list; el != NULL; el = el->next) fprintf(f, "%s\n", el->name); carefulClose(&f); /* Print out some info. */ hPrintf("Thresholding <i>%s</i> at %g. ", gg->shortLabel, threshold); hPrintf("There are %d regions covering %lld bases.<BR>\n", slCount(bedList), bedTotalSize((struct bed*)bedList) ); hPrintf("Installed a Gene Sorter filter that selects only genes in these regions.<BR>\n"); if (m) { hPrintf("There are %d markers in the regions over threshold that overlap knownGenes.<BR>\n", markerCount); hPrintf("Installed a Gene Sorter custom column called \"%s Markers\" with these markers.<BR>\n", gg->shortLabel); } /* close custom column output file */ if (m) { lineFileClose(&m); carefulClose(&g); } /* Stuff cart variable with name of file. */ char keyCartName[256]; safef(keyCartName, sizeof(keyCartName), "%s%s.keyFile", advFilterPrefix, idColumn); cartSetString(cart, keyCartName, keyTn.forCgi); cartSetString(cart, customFileVarName, snpTn.forCgi); char snpVisCartNameTemp[256]; char *snpVisCartName = NULL; safef(snpVisCartNameTemp, sizeof(snpVisCartNameTemp), "%s%s Markers.vis", colConfigPrefix, gg->shortLabel); snpVisCartName = replaceChars(snpVisCartNameTemp, " ", "_"); cartSetString(cart, snpVisCartName, "1"); freeMem(snpVisCartName); hPrintf("<FORM ACTION=\"../cgi-bin/hgNear\" METHOD=GET>\n"); cartSaveSession(cart); hPrintf("<CENTER>"); cgiMakeButton("submit", "go to gene sorter"); hPrintf("</CENTER>"); hPrintf("</FORM>"); cartWebEnd(); }
static void generateImgFiles(struct hgdpGeo *geo, char finalEpsFile[PATH_LEN], char finalPdfFile[PATH_LEN], char finalPngFile[PATH_LEN]) /* Using the frequencies given in geo and the population latitude and longitude * given above, plot allele frequency pie charts for each population on a world map. * Work in a temporary trash dir and then move result files to the given paths. */ { // The Generic Mapping Tools commands must have a writeable ./ and $HOME. // Use trashDirFile as a directory name, cd to that and work there. char cwd[PATH_LEN]; if (getcwd(cwd, sizeof(cwd)) == NULL) errAbort("PATH_LEN (%d) is too short.", PATH_LEN); struct tempName dirTn; trashDirFile(&dirTn, "hgc", "hgdpGeo", ""); makeDirs(dirTn.forCgi); mustChdir(dirTn.forCgi); char *realHome = getenv("HOME"); setenv("HOME", ".", TRUE); // Make trash files with coordinate specs for pie charts and full circles: char rootName[FILENAME_LEN]; splitPath(dirTn.forCgi, NULL, rootName, NULL); char pieFile[FILENAME_LEN], circleFile[FILENAME_LEN]; safef(pieFile, sizeof(pieFile), "%s_pie.txt", rootName); safef(circleFile, sizeof(circleFile), "%s_circle.txt", rootName); FILE *fPie = mustOpen(pieFile, "w"); FILE *fCir = mustOpen(circleFile, "w"); int i; for (i = 0; i < HGDPGEO_POP_COUNT; i++) { FILE *f = (geo->popFreqs[i] == 1.0) ? fCir : fPie; fprintf(f, "%.4f %.4f 0.65 0 %.4f\n", pops[i].latitude, pops[i].longitude, geo->popFreqs[i]*360); } fclose(fPie); fclose(fCir); // Build up an EPS image: copy a baseline EPS (map background), add SNP and allele labels, // and use ps2xy commands to allele frequency pie charts. char epsFile[FILENAME_LEN]; safef(epsFile, sizeof(epsFile), "%s.eps", rootName); char mapBgEps[PATH_LEN]; safef(mapBgEps, sizeof(mapBgEps), "%s/hgcData/hgdpGeoMap.eps", cwd); copyFile(mapBgEps, epsFile); FILE *fEps = mustOpen(epsFile, "a"); fprintf(fEps, hgdpGeoLabelFormat, geo->name, geo->name, geo->ancestralAllele, geo->ancestralAllele, geo->derivedAllele, geo->derivedAllele); fclose(fEps); //- run psxy on circle/pie spec trash files for AfrEurAsia and America char *psxy = cfgOption("hgc.psxyPath"); if (isEmpty(psxy)) errAbort("How did this get called? hg.conf doesn't have hgc.psxyPath."); runCommandAppend(psxyOrangeAeaCmd, psxy, pieFile, epsFile); runCommandAppend(psxyPieAeaCmd, psxy, pieFile, epsFile); runCommandAppend(psxyBlueAeaCmd, psxy, circleFile, epsFile); runCommandAppend(psxyOrangeAmCmd, psxy, pieFile, epsFile); runCommandAppend(psxyPieAmCmd, psxy, pieFile, epsFile); runCommandAppend(psxyBlueAmCmd, psxy, circleFile, epsFile); // Make PDF and PNG: struct pipeline *pl; char pdfFile[FILENAME_LEN], pngFile[FILENAME_LEN]; safef(pdfFile, sizeof(pdfFile), "%s.pdf", rootName); safef(pngFile, sizeof(pngFile), "%s.png", rootName); char *ps2pdfCmd[] = {"ps2pdf", epsFile, pdfFile, NULL}; char **cmdsPdf[] = {ps2pdfCmd, NULL}; pl = pipelineOpen(cmdsPdf, pipelineWrite, "/dev/null", NULL); pipelineClose(&pl); char *ps2raster = cfgOption("hgc.ps2rasterPath"); char *ghostscript = cfgOption("hgc.ghostscriptPath"); char gsOpt[PATH_LEN]; safef(gsOpt, sizeof(gsOpt), "-G%s", ghostscript); char *ps2RasterPngCmd[] = {ps2raster, gsOpt, "-P", "-A", "-Tg", "-E150", epsFile, NULL}; char **cmdsPng[] = {ps2RasterPngCmd, NULL}; pl = pipelineOpen(cmdsPng, pipelineRead, "/dev/null", NULL); pipelineClose(&pl); // Back to our usual working directory and $HOME: if (realHome == NULL) unsetenv("HOME"); else setenv("HOME", realHome, TRUE); mustChdir(cwd); // Move the result files into place: char tmpPath[PATH_LEN]; safef(tmpPath, sizeof(tmpPath), "%s/%s", dirTn.forCgi, epsFile); mustRename(tmpPath, finalEpsFile); safef(tmpPath, sizeof(tmpPath), "%s/%s", dirTn.forCgi, pdfFile); mustRename(tmpPath, finalPdfFile); safef(tmpPath, sizeof(tmpPath), "%s/%s", dirTn.forCgi, pngFile); mustRename(tmpPath, finalPngFile); // Clean up the temporary working directory (trash cleaner script doesn't // remove empty dirs: removeDir(dirTn.forCgi); }