boolean cartDbHasSessionKey(struct sqlConnection *conn, char *table) /* Check to see if the table has the sessionKey field */ { static boolean userDbHasSessionKey = FALSE; static boolean sessionDbHasSessionKey = FALSE; if (sameString(table, userDbTable())) { if (!userDbInitialized) { userDbInitialized = TRUE; if (sqlFieldIndex(conn, table, "sessionKey") >= 0) { userDbHasSessionKey = TRUE; } } return userDbHasSessionKey; } else if (sameString(table, sessionDbTable())) { if (!sessionDbInitialized) { sessionDbInitialized = TRUE; if (sqlFieldIndex(conn, table, "sessionKey") >= 0) { sessionDbHasSessionKey = TRUE; } } return sessionDbHasSessionKey; } else errAbort("Unknown table %s", table); return FALSE; }
static void getXrefInfo(struct sqlConnection *conn, char **retXrefTable, char **retIdField, char **retAliasField) /* See if curTrack specifies an xref/alias table for lookup of IDs. */ { char *xrefSpec = curTrack ? trackDbSetting(curTrack, "idXref") : NULL; char *xrefTable = NULL, *idField = NULL, *aliasField = NULL; if (xrefSpec != NULL) { char *words[3]; chopLine(cloneString(xrefSpec), words); if (isEmpty(words[2])) errAbort("trackDb error: track %s, setting idXref must be followed " "by three words (xrefTable, idField, aliasField).", curTrack->track); xrefTable = words[0]; idField = words[1]; aliasField = words[2]; if (!sqlTableExists(conn, xrefTable) || sqlFieldIndex(conn, xrefTable, idField) < 0 || sqlFieldIndex(conn, xrefTable, aliasField) < 0) xrefTable = idField = aliasField = NULL; } if (retXrefTable != NULL) *retXrefTable = xrefTable; if (retIdField != NULL) *retIdField = idField; if (retAliasField != NULL) *retAliasField = aliasField; }
char *bamFileNameFromTable(struct sqlConnection *conn, char *table, char *bamSeqName) /* Return file name from table. If table has a seqName column, then grab the * row associated with bamSeqName (which can be e.g. '1' not 'chr1' if that is the * case in the bam file). */ { boolean checkSeqName = (sqlFieldIndex(conn, table, "seqName") >= 0); if (checkSeqName && bamSeqName == NULL) errAbort("bamFileNameFromTable: table %s has seqName column, but NULL seqName passed in", table); char query[512]; if (checkSeqName) sqlSafef(query, sizeof(query), "select fileName from %s where seqName = '%s'", table, bamSeqName); else sqlSafef(query, sizeof(query), "select fileName from %s", table); char *fileName = sqlQuickString(conn, query); if (fileName == NULL && checkSeqName) { if (startsWith("chr", bamSeqName)) sqlSafef(query, sizeof(query), "select fileName from %s where seqName = '%s'", table, bamSeqName+strlen("chr")); else sqlSafef(query, sizeof(query), "select fileName from %s where seqName = 'chr%s'", table, bamSeqName); fileName = sqlQuickString(conn, query); } if (fileName == NULL) { if (checkSeqName) errAbort("Missing fileName for seqName '%s' in %s table", bamSeqName, table); else errAbort("Missing fileName in %s table", table); } return fileName; }
static void chkGenePredRows(struct gbSelect* select, struct sqlConnection* conn, char* table, boolean isRefFlat, struct metaDataTbls* metaDataTbls, unsigned typeFlags) /* check rows of genePred or refFlat table */ { unsigned iRow = 0; char **row; char *geneName = NULL; int rowOff = (isRefFlat ? 1 : 0); /* columns to skip to genePred */ if (sqlFieldIndex(conn, table, "bin") >= 0) rowOff++; char query[512]; sqlSafef(query, sizeof(query), "SELECT * FROM %s", table); struct sqlResult *sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { struct genePred* gene = genePredLoad(row+rowOff); if (isRefFlat) geneName = row[0]; chkGenePred(gene, geneName, iRow, select->release->genome->database, table, metaDataTbls, typeFlags); genePredFree(&gene); iRow++; } sqlFreeResult(&sr); }
static struct hash *makeChromHashForTable(struct sqlConnection *conn, char *table) /* Get a hash of all the chroms that are actually being used for the table. * This is helpful for assemblies with huge numbers of chroms. */ { char query[1024]; // Make sure that the table has a chrom field. // a bbi table will NOT have a chrom field int cIdx = sqlFieldIndex(conn, table, "chrom"); if (cIdx < 0) return NULL; sqlSafef(query, sizeof query, "select distinct chrom, 'dummyvalue' from %s", table); struct hash *hash = sqlQuickHash(conn, query); return hash; }
void doOutGff(char *table, struct sqlConnection *conn, boolean outputGtf) /* Save as GFF/GTF. */ { struct hTableInfo *hti = getHti(database, table, conn); struct bed *bedList; struct hash *chromHash = NULL; struct slName *exonFramesList = NULL; char source[HDB_MAX_TABLE_STRING]; int itemCount; struct region *region, *regionList = getRegions(); textOpen(); int efIdx = -1; safef(source, sizeof(source), "%s_%s", database, table); if (conn) { boolean simpleTableExists = sqlTableExists(conn, table); // simpleTable means not split table, not custom track // However it still can include bbi table with bam fileName path if (simpleTableExists) // no tables having exonFrames are split tables anyway efIdx = sqlFieldIndex(conn, table, "exonFrames"); itemCount = 0; int regionCount = slCount(regionList); // regionList can have many thousands of items e.g. rheMac3 has 34000 chroms! // This regionCount threshold should be just above the # chroms in the latest human assembly if (simpleTableExists && (regionCount > 500)) { chromHash = makeChromHashForTable(conn, table); } } // Note: code could be added here to extract exonFrames from bigGenePred // Process each region for (region = regionList; region != NULL; region = region->next) { if (chromHash && (!hashFindVal(chromHash, region->chrom))) continue; struct lm *lm = lmInit(64*1024); int fieldCount; bedList = cookedBedList(conn, table, region, lm, &fieldCount); // Use exonFrames field if available for better accuracy instead of calculating from coordinates if (efIdx != -1) exonFramesList = getExonFrames(table, conn, bedList); itemCount += bedToGffLines(bedList, exonFramesList, hti, fieldCount, source, outputGtf); lmCleanup(&lm); } if (itemCount == 0) hPrintf(NO_RESULTS); }
void checkTable(struct sqlConnection *conn, char *table, struct hash *mdbHash, struct hash *allBbiNames) // check to see if table is represented in the metaDb.ra // Also check gbdb referencing tables to see if files exist and have // the correct name { verbose(2, "checking table %s\n", table); if (hashLookup(mdbHash, table) == NULL) warn("table %s is not in metaDb", table); int result = sqlFieldIndex(conn, table, "fileName"); if (result >= 0) checkFilename(conn, table, allBbiNames); }
void checkNotRealCartTable(struct sqlConnection *conn, char *database, char *table) /* Abort unless either table doesn't exist, or table exists and is in fake prefix format. */ { if (!sqlTableExists(conn, table)) return; int contentsFieldIx = sqlFieldIndex(conn, table, "contents"); if (contentsFieldIx < 0) errAbort("%s.%s doesn't have a contents field", database, table); char query[256]; sqlSafef(query, sizeof(query), "select contents from %s limit 1", table); char *firstContents = sqlQuickString(conn, query); if (firstContents != NULL && !startsWith(fakePrefix, firstContents)) errAbort("%s.%s.contents doesn't start with '%s'", database, table, firstContents); freez(&firstContents); }
static struct gbGeneTbl *gbGeneTblNew(struct sqlConnection* conn, char *tbl, char *flatTbl, char *alnTbl, char *tmpDir) /* construct a new gbGeneTbl object */ { struct gbGeneTbl *ggt; AllocVar(ggt); ggt->tbl = cloneString(tbl); ggt->flatTbl = cloneString(flatTbl); ggt->alnTbl = cloneString(alnTbl); if (!sqlTableExists(conn, ggt->tbl)) { ggt->hasBin = TRUE; ggt->hasExtCols = TRUE; } else { ggt->hasBin = (sqlFieldIndex(conn, ggt->tbl, "bin") >= 0); ggt->hasExtCols = (sqlFieldIndex(conn, ggt->tbl, "exonFrames") >= 0); } safecpy(ggt->tmpDir, sizeof(ggt->tmpDir), tmpDir); return ggt; }
static void insertHubUrlInStatus(char *url) /* add a url to the hubStatus table */ { struct sqlConnection *conn = hConnectCentral(); char query[4096]; char *statusTable = getHubStatusTableName(); if (sqlFieldIndex(conn, statusTable, "firstAdded") >= 0) sqlSafef(query, sizeof(query), "insert into %s (hubUrl,firstAdded) values (\"%s\",now())", statusTable, url); else sqlSafef(query, sizeof(query), "insert into %s (hubUrl) values (\"%s\")", statusTable, url); sqlUpdate(conn, query); hDisconnectCentral(&conn); }
static struct hash *makePrivateHash(struct sqlConnection *conn) /* Build up hash of all submission sets that are private. * This is keyed by the ascii version of submissionSet.id */ { struct hash *hash = hashNew(0); if (sqlFieldIndex(conn, "submissionSet", "privateUser") >= 0) { struct sqlResult *sr; char **row; sr = sqlGetResult(conn, "select id from submissionSet where privateUser!=0"); while ((row = sqlNextRow(sr)) != NULL) hashAdd(hash, row[0], NULL); sqlFreeResult(&sr); } return hash; }
struct transMapGene *transMapGeneQuery(struct sqlConnection *geneConn, char *table, char *srcDb, char *srcId) /* load a single transMapSrc object for an srcDb and srcId from a table, * or return NULL if not found */ { /* geneId field was added after original table definition. Return empty string * in query for legacy tables. */ if (sqlFieldIndex(geneConn, table, "geneId") >= 0) return sqlQueryObjs(geneConn, (sqlLoadFunc)transMapGeneLoad, sqlQuerySingle, "SELECT %-s FROM %s WHERE (db=\"%s\") and (id = \"%s\")", transMapGeneCommaSepFieldNames, table, srcDb, srcId); else return sqlQueryObjs(geneConn, (sqlLoadFunc)transMapGeneLoad, sqlQuerySingle, "SELECT %-s,\"\" FROM %s WHERE (db=\"%s\") and (id = \"%s\")", transMapGeneCommaSepFieldNames4, table, srcDb, srcId); }
void renameTable(char *database, char *oldTableName, char *newTableName, char *oldFileName, char *newFileName, char *downDir) { struct sqlConnection *conn = sqlConnect(database); if (sqlTableExists(conn, oldTableName)) { // do we need to change the gbdb fileName ? int result = sqlFieldIndex(conn, oldTableName, "fileName"); if (result >= 0) { // this may be the same file we just renamed char *newPath = mayRenameFile(conn, oldTableName, oldFileName, newFileName, downDir); if (!doTest && (newPath != NULL)) { // change fileName in table char query[10 * 1024]; safef(query, sizeof query, "update %s set fileName='%s'", oldTableName, newPath); verbose(2, "sending query '%s' to database\n", query); } } if (!doTest) { verbose(2, "renaming table %s to %s\n", oldTableName, newTableName); //sqlRenameTable(conn, oldTableName, newTableName); } } else errAbort("can't find table %s in database %s\n", oldTableName, database); }
struct annoStreamer *annoStreamDbNew(char *db, char *table, struct annoAssembly *aa, struct asObject *asObj, int maxOutRows) /* Create an annoStreamer (subclass) object from a database table described by asObj. */ { struct sqlConnection *conn = hAllocConn(db); if (!sqlTableExists(conn, table)) errAbort("annoStreamDbNew: table '%s' doesn't exist in database '%s'", table, db); struct annoStreamDb *self = NULL; AllocVar(self); struct annoStreamer *streamer = &(self->streamer); int dbtLen = strlen(db) + strlen(table) + 2; char dbTable[dbtLen]; safef(dbTable, dbtLen, "%s.%s", db, table); annoStreamerInit(streamer, aa, asObj, dbTable); streamer->rowType = arWords; streamer->setRegion = asdSetRegion; streamer->nextRow = asdNextRow; streamer->close = asdClose; self->conn = conn; self->table = cloneString(table); char *asFirstColumnName = streamer->asObj->columnList->name; if (sqlFieldIndex(self->conn, self->table, "bin") == 0) { self->hasBin = 1; self->minFinestBin = binFromRange(0, 1); } if (self->hasBin && !sameString(asFirstColumnName, "bin")) self->omitBin = 1; if (!asdInitBed3Fields(self)) errAbort("annoStreamDbNew: can't figure out which fields of %s.%s to use as " "{chrom, chromStart, chromEnd}.", db, table); self->makeBaselineQuery = asdMakeBaselineQuery; // When a table has an index on endField, sometimes the query optimizer uses it // and that ruins the sorting. Fortunately most tables don't anymore. self->endFieldIndexName = sqlTableIndexOnField(self->conn, self->table, self->endField); self->notSorted = FALSE; // Special case: genbank-updated tables are not sorted because new mappings are // tacked on at the end. if (isIncrementallyUpdated(table)) self->notSorted = TRUE; self->mergeBins = FALSE; self->maxOutRows = maxOutRows; self->useMaxOutRows = (maxOutRows > 0); self->needQuery = TRUE; self->chromList = annoAssemblySeqNames(aa); if (slCount(self->chromList) > 1000) { // Assembly has many sequences (e.g. scaffold-based assembly) -- // don't break up into per-sequence queries. Take our chances // with mysql being unhappy about the sqlResult being open too long. self->doQuery = asdDoQuerySimple; self->nextRowRaw = nextRowFromSqlResult; } else { // All-chromosome assembly -- if table is large, perform a series of // chunked queries. self->doQuery = asdDoQueryChunking; self->nextRowRaw = nextRowFromBuffer; } return (struct annoStreamer *)self; }
void gbMetaDataInit(struct sqlConnection *conn, unsigned srcDb, struct dbLoadOptions* options, char *gbdbGenBank, char *tmpDir) /* initialize for parsing metadata */ { gOptions = options; gSrcDb = srcDb; gGbdbGenBank[0] = '\0'; if (gbdbGenBank != NULL) strcpy(gGbdbGenBank, gbdbGenBank); strcpy(gTmpDir, tmpDir); if (seqTbl == NULL) seqTbl = seqTblNew(conn, gTmpDir, (gbVerbose >= 4)); if (imageCloneTbl == NULL) imageCloneTbl = imageCloneTblNew(conn, gTmpDir, (gbVerbose >= 4)); if (!sqlTableExists(conn, "gbCdnaInfo")) { sqlUpdate(conn, gbCdnaInfoCreate); haveGi = TRUE; haveMol = TRUE; } else { haveGi = sqlFieldIndex(conn, "gbCdnaInfo", "gi") >= 0; haveMol = sqlFieldIndex(conn, "gbCdnaInfo", "mol") >= 0; if (haveMol && !haveGi) errAbort("must have gi column to have mol"); } setGeneTblFlags(conn, options); if (!sqlTableExists(conn, "gbMiscDiff")) sqlUpdate(conn, gbMiscDiffCreate); if (!sqlTableExists(conn, "gbWarn")) sqlUpdate(conn, gbWarnCreate); if (gbCdnaInfoUpd == NULL) gbCdnaInfoUpd = sqlUpdaterNew("gbCdnaInfo", gTmpDir, (gbVerbose >= 4), &allUpdaters); if (gSrcDb == GB_REFSEQ) { if (!sqlTableExists(conn, "refSeqStatus")) { sqlUpdate(conn, refSeqStatusCreate); haveRsMol = TRUE; } else { haveRsMol = sqlFieldIndex(conn, "refSeqStatus", "mol") >= 0; } if (refSeqStatusUpd == NULL) refSeqStatusUpd = sqlUpdaterNew("refSeqStatus", gTmpDir, (gbVerbose >= 4), &allUpdaters); if (!sqlTableExists(conn, "refSeqSummary")) sqlUpdate(conn, refSeqSummaryCreate); if (refSeqSummaryUpd == NULL) refSeqSummaryUpd = sqlUpdaterNew("refSeqSummary", gTmpDir, (gbVerbose >= 4), &allUpdaters); if (!sqlTableExists(conn, "refLink")) sqlUpdate(conn, refLinkCreate); if (refLinkUpd == NULL) refLinkUpd = sqlUpdaterNew("refLink", gTmpDir, (gbVerbose >= 4), &allUpdaters); } }
void findToFixBedGraphLimits(char *input, char *output) /* findToFixBedGraphLimits - Scan through ra file of bedGraphs and calculate limits.. */ { struct lineFile *lf = lineFileOpen(input, TRUE); FILE *f = mustOpen(output, "w"); struct slPair *el, *list; while ((list = raNextRecordAsSlPairList(lf)) != NULL) { /* Find required fields for calcs. */ char *db = mustFindVal(list, "db", lf); char *track = mustFindVal(list, "track", lf); char *type = cloneString(mustFindVal(list, "type", lf)); /* Parse out type value, which should be "bedGraph 4" and put the 4 or whatever other number * in dataFieldIndex. */ char *typeWords[3]; int typeWordCount = chopLine(type, typeWords); if (typeWordCount != 2 || !sameString(typeWords[0], "bedGraph")) errAbort("Not well formed bedGraph type line %d of %s", lf->lineIx, lf->fileName); int dataFieldIndex = sqlUnsigned(typeWords[1]); /* Figure out field corresponding to dataFieldIndex. */ struct sqlConnection *conn = sqlConnect(db); struct slName *fieldList = sqlFieldNames(conn, track); struct slName *pastBin = fieldList; if (sameString(pastBin->name, "bin")) pastBin = pastBin->next; struct slName *fieldName = slElementFromIx(pastBin, dataFieldIndex - 1); if (fieldName == NULL) errAbort("%s doesn't have enough fields", track); char *field = fieldName->name; assert(sqlFieldIndex(conn, track, field) >= 0); /* Print reassuring status message */ verbose(1, "%s.%s has %d elements. Data field is %s\n", db, track, sqlTableSize(conn, track), field); /* Get min/max dataValues in fields. Do it ourselves rather than using SQL min/max because sometimes * the data field is a name column.... */ char query[512]; safef(query, sizeof(query), "select %s from %s", field, track); struct sqlResult *sr = sqlGetResult(conn, query); char **row; row = sqlNextRow(sr); assert(row != NULL); double val = sqlDouble(row[0]); double minLimit = val, maxLimit = val; while ((row = sqlNextRow(sr)) != 0) { double val = sqlDouble(row[0]); if (val < minLimit) minLimit = val; if (val > maxLimit) maxLimit = val; } sqlFreeResult(&sr); verbose(1, " %g %g\n", minLimit, maxLimit); /* Output original table plus new minLimit/maxLimit. */ for (el = list; el != NULL; el = el->next) fprintf(f, "%s %s\n", el->name, (char *)el->val); fprintf(f, "minLimit %g\n", minLimit); fprintf(f, "maxLimit %g\n", maxLimit); fprintf(f, "\n"); sqlDisconnect(&conn); slFreeList(&fieldList); slPairFreeValsAndList(&list); } lineFileClose(&lf); carefulClose(&f); }
static void displayMappingInfo(struct sqlConnection *conn, struct mappingInfo *mi) /* display information from a transMap table */ { struct ucscRetroInfo *pg = mi->pg; double wt[12]; /* weights on score function*/ char query[512]; char *name; char alignTbl[128]; char scoreSql[128]; struct psl *psl; float coverFactor = 0; float maxOverlap = 0; if (mi->suffix == NULL) { safef(alignTbl, sizeof(alignTbl), "%s%sAli", mi->tblPre, mi->geneSet); sqlSafef(scoreSql, sizeof(scoreSql), "select max(score) from %s%sInfo", mi->tblPre, mi->geneSet); } else { safef(alignTbl, sizeof(alignTbl), "%s%sAli%s", mi->tblPre, mi->geneSet, mi->suffix); sqlSafef(scoreSql, sizeof(scoreSql), "select max(score) from %s%sInfo%s", mi->tblPre, mi->geneSet, mi->suffix); } printf("<TABLE class=\"transMap\">\n"); printf("<H3>Retrogene Statistics:</H3>\n"); printf("<THEAD>\n"); printf("<TR><TH>Feature<TH>Value </TR>\n"); printf("</THEAD><TBODY>\n"); if (sameString(pg->type, "singleExon")) printf("<TR><TH>Type of Parent<TD>%s</tr>\n",pg->type); else printf("<TR><TH>Expression of Retrogene<TD>%s</TR>\n",pg->type); printf("<TR><TH>Score <TD>%d (range from 0 - %d)</TR>\n", pg->score, sqlQuickNum(conn, scoreSql) ); printf("<TR><TH>Parent Gene Alignment Coverage (Bases Matching Parent) <TD>%d %% (%d bp) </TR>\n", pg->coverage, pg->matches); printf("<TR><TH>Introns Processed Out <TD>%d out of %d (%d exons covered)\n", pg->processedIntrons, (pg->parentSpliceCount/2), pg->exonCover); printf("<TR><TH>Possible Introns or Gaps in Retrogene<TD>%d,%d\n", pg->intronCount, pg->alignGapCount); printf("<TR><TH>Conserved Splice Sites<TD>%d</TR>\n", pg->conservedSpliceSites); printf("<TR><TH>Parent Splice Sites<TD>%d</TR>\n", pg->parentSpliceCount); psl = getAlignments(conn, alignTbl, mi->pg->name); if (psl != NULL) { maxOverlap = (float)pg->maxOverlap/(float)(psl->match+psl->misMatch+psl->repMatch) ; coverFactor = ((float)(psl->qSize-psl->qEnd)/(float)psl->qSize); } else { maxOverlap = 0; } wt[0] = 0; wt[1] = 0.85; wt[2] = 0.2; wt[3] = 0.3; wt[4] = 0.8; wt[5] = 1; wt[6] = 1 ; wt[7] = 0.5; wt[8] = 0.5; wt[9] = 1; wt[10] = 1; #ifdef debug char table[512]; struct psl *pslList = getParentAligns(conn, mi, &table); if (psl != NULL) { printf("<TR><TH>Blocks in retro:gap%%/intronsSpliced <TD>\n"); printBlocks(psl, MAXBLOCKGAP, pslList); printf("</td></TR>\n"); } if (pslList != NULL) { printf("<TR><TH>Exons in parent:gap%% <TD>\n"); printBlocks(pslList, MAXBLOCKGAP, NULL); printf("</td></TR>\n"); pslFreeList(&pslList); } #endif printf("<TR><TH>Length of PolyA Tail<TD>%d As out of %d bp </TR><TR><TH>%% A's from Parent PolyA tail (Position)<TD>%5.1f %%\n",pg->polyA,pg->polyAlen, (float)pg->polyA*100/(float)pg->polyAlen); if (pg->polyAstart < 0) printf(" (%d bp before end of retrogene)<br>\n",-(pg->polyAstart)); else printf(" (%d bp past end of retrogene)<br>\n",pg->polyAstart); printf("<tr><th>mRNA Expression Evidence<td>"); if (!sameString(pg->overName, "none")) printf("%s (overlap: %d bp)\n", pg->overName, pg->maxOverlap); else printf("No overlapping"); printf("<TR><TH>BESTORF Score (>50 is good)<TD>%4.0f</td></TR>\n",pg->posConf); #ifdef score printf("<TR><TH>score function<TD>1:xon %d %4.1f conSS %d 2: ax %4.1f 3: pA %4.1f 4: net + %4.1f max (%d, %d) 5: procIntrons %d %4.1f 6:in.cnt %d -%4.1f 7:overlap - %4.1f 8:cov %d*(qe %d- qsz %d)/%d=%4.1f 9:tRep - %4.1f 10:oldintron %d %4.1f </td></TR>\n", pg->exonCover, wt[1]*(log(pg->exonCover+1)/log(2))*200 , pg->conservedSpliceSites, wt[2]*(((log(pg->axtScore>0?pg->axtScore:1)/log(2))*170)-1000), wt[3]*(log(pg->polyAlen+2)*200) , wt[4]*overlapOrtholog*10 , pg->overlapMouse, pg->overlapDog, pg->processedIntrons, wt[5]*(((log(pg->processedIntrons > 0 ? pg->processedIntrons : 1))/log(2))*600) , pg->intronCount, wt[6]*pow(pg->intronCount,0.5)*750 , wt[7]*(maxOverlap*300), pg->coverage, pg->qEnd, pg->qSize , pg->qSize, wt[8]*((pg->coverage/100.0)*(1.0-coverFactor)*300.0), wt[9]*(pg->tReps*10), pg->alignGapCount, wt[10]*pg->alignGapCount); printf("<TR><TH>score function<TD>%4.1f+ %4.1f+ %4.1f+ %4.1f+ %4.1f - %4.1f - %4.1f+ %4.1f - %4.1f - %4.1f</td></TR>\n", wt[1]*(log(pg->exonCover+1)/log(2))*200 , wt[2]*(((log(pg->axtScore>0?pg->axtScore:1)/log(2))*170)-1000), wt[3]*(log(pg->polyAlen+2)*200) , wt[4]*overlapOrtholog*10 , wt[5]*(((log(pg->processedIntrons > 0 ? pg->processedIntrons : 1))/log(2))*600) , (float)wt[6]*pow(pg->intronCount,0.5)*750 , (float)wt[7]*(maxOverlap*300), wt[8]*((pg->coverage/100.0)*(1.0-coverFactor)*300.0), wt[9]*(pg->tReps*10), wt[10]*pg->alignGapCount); if (pg->kaku > 0 && pg->kaku < 1000000) printf("<TR><TH>KA/KU mutation rate in non-syn sites vs utr with repect to parent gene<TD>%4.2f</TR>\n", pg->kaku); #endif #ifdef xxx sqlSafef(query, sizeof(query), "select * from refGene where chrom = '%d' and txEnd > %d and txStart %d and name = '%s'", pg->chrom, pg->gStart, pg->gEnd , pg->overName ); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) overlappingGene = genePredLoad(row); if (overlappingGene != NULL) { printf ("CDS exons %d ",genePredcountCdsExons(overlappingGene)); } #endif printf("</tr>\n"); if ( differentString("none",pg->overName) && sqlFieldIndex(conn, "refGene", "exonFrames") != -1) { sqlSafef(query, sizeof(query), "select concat(exonFrames,'(',cdsStart,')') from refGene where name = '%s' and chrom = '%s'" , pg->overName, pg->chrom); if (sqlQuickString(conn, query) != NULL) printf("<TR><TH>Frame of retro %s (start)<TD>%s</TR>\n", pg->overName, sqlQuickString(conn, query)); } name = cloneString(pg->name); chopSuffix(name); sqlSafef(query, sizeof(query), "select concat(exonFrames,'(',cdsStart,')') from rbRetroParent where name like '%s%%' and chrom = '%s'" , name, pg->chrom); if (hTableExists(database, "rbRetroParent")) { if ( sqlQuickString(conn, query) != NULL) printf("<TR><TH>Frames of mapped parent %s (start)<TD>%s</TR>\n", name, sqlQuickString(conn, query)); } printf("</TBODY></TABLE>\n"); }
void txCdsBadBed(char *database, char *altSpliceBed, char *outBed) /* txCdsBadBed - Create a bed file with regions that don't really have CDS, * but that might look like it.. */ { /* Open up database and make sure all the tables we want are there. */ char *refTrack = "refGene"; char *vegaPseudo = "vegaPseudoGene"; char *retroPseudo = "retroMrnaInfo"; struct sqlConnection *conn = sqlConnect(database); if (!sqlTableExists(conn, refTrack)) errAbort("table %s doesn't exist in %s", refTrack, database); if (!sqlTableExists(conn, vegaPseudo)) errAbort("table %s doesn't exist in %s", vegaPseudo, database); if (!sqlTableExists(conn, retroPseudo)) errAbort("table %s doesn't exist in %s", retroPseudo, database); /* Read in alt file and output larger retained and bleeding introns. */ struct bed *bed, *intronyList = loadRetainedAndBleeding(altSpliceBed); FILE *f = mustOpen(outBed, "w"); for (bed = intronyList; bed != NULL; bed = bed->next) { int size = bed->chromEnd - bed->chromStart; if (size > 400) { fprintf(f, "%s\t%d\t%d\t", bed->chrom, bed->chromStart, bed->chromEnd); fprintf(f, "%s%d\t", bed->name, ++id); fprintf(f, "%d\t%s\t", bed->score, bed->strand); fprintf(f, "0\t0\t0\t1\t"); fprintf(f, "%d,\t%d,\n", bed->chromEnd - bed->chromStart, 0); } } /* Read in refGene, and write out larger 3' UTRs, and occassional antisense copies. */ char query[512]; safef(query, sizeof(query), "select * from %s", refTrack); int rowOffset = 0; if (sqlFieldIndex(conn, refTrack, "bin") == 0) rowOffset = 1; struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { struct genePred *gp = genePredLoad(row + rowOffset); int start, end; if (gp->strand[0] == '+') { start = gp->cdsEnd; end = gp->txEnd; } else { start = gp->txStart; end = gp->cdsStart; } if (end - start > 400) { gpPartOutAsBed(gp, start, end, f, "utr", ++id, 400); } if (rand()%20 == 0) { gp->strand[0] = (gp->strand[0] == '+' ? '-' : '+'); gpPartOutAsBed(gp, gp->txStart, gp->txEnd, f, "anti", ++id, 0); } } sqlFreeResult(&sr); /* Write out vega pseudo-genes. */ safef(query, sizeof(query), "select * from %s", vegaPseudo); rowOffset = 0; if (sqlFieldIndex(conn, vegaPseudo, "bin") == 0) rowOffset = 1; sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { struct genePred *gp = genePredLoad(row + rowOffset); gpPartOutAsBed(gp, gp->txStart, gp->txEnd, f, "vega", ++id, 0); } /* Write out retroGenes. */ safef(query, sizeof(query), "select * from %s where score > 600", retroPseudo); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { struct bed *bed = bedLoad12(row); char name[128]; safef(name, sizeof(name), "retro_%d_%s", ++id, bed->name); bed->name = name; bedTabOutN(bed, 12, f); } carefulClose(&f); }
void autoUpgradeTableAddSessionKey(struct sqlConnection *conn, char *tableName) /* Try to upgrade the table by adding sessionKey field * in a safe way handling success failures and retries * with multiple CGIs running. */ { boolean testAgain = checkAutoUpgradeTableResultTimeIsOld(tableName); if (testAgain) { // Get the advisory lock for this table // This prevents multiple CGI processes from trying to upgrade simultaneously char lockName[256]; safef(lockName, sizeof lockName, "AUTO_UPGRADE_%s", tableName); sqlGetLock(conn, lockName); // Make sure that the table has not been already upgraded by some earlier process. // We do not want to upgrade more than once. if (sqlFieldIndex(conn, tableName, "sessionKey") == -1) { char result[4096]; // Put a catch around the table upgrade attempt, // both to allow us to continue if it fails, // and to catch the error message and save it in the results file struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { char query[256]; sqlSafef(query, sizeof query, "alter table %s add column sessionKey varchar(255) NOT NULL default ''", tableName); sqlUpdate(conn, query); } errCatchEnd(errCatch); if (errCatch->gotError) { safef(result, sizeof result, "AUTOUPGRADE FAILED\n%s", errCatch->message->string); } else { safef(result, sizeof result, "OK\n"); } errCatchFree(&errCatch); writeAutoUpgradeTableResult(tableName, result); } // Release the advisory lock for this table sqlReleaseLock(conn, lockName); } else { // in the interests of speed, just use the old result char *oldResult = readAutoUpgradeTableResult(tableName); if (oldResult) { if (startsWith("AUTOUPGRADE FAILED", oldResult)) { // cannot do this here since it is too early and the warn handler does not work right // it ends up writing html and javascript before the cookie and response header have even been finished. // warn("%s", oldResult); // instead, save the error message for access later from select places like hgGateway if (!dyUpgradeError) dyUpgradeError = dyStringNew(256); else dyStringPrintf(dyUpgradeError,"\n"); dyStringPrintf(dyUpgradeError,"%s", oldResult); } } } }