int palOutPredsInBeds(struct sqlConnection *conn, struct cart *cart, struct bed *beds, char *table ) /* output the alignments whose names and coords match a bed*/ { struct genePred *list = NULL; for(; beds; beds = beds->next) { char where[10 * 1024]; sqlSafefFrag(where, sizeof where, "name = '%s' and chrom='%s' and txEnd > %d and txStart <= %d", beds->name, beds->chrom, beds->chromStart, beds->chromEnd); struct genePredReader *reader = genePredReaderQuery( conn, table, where); struct genePred *pred; while ((pred = genePredReaderNext(reader)) != NULL) slAddHead(&list, pred); genePredReaderFree(&reader); } int outCount = 0; if (list != NULL) { slReverse(&list); outCount = palOutPredList( conn, cart, list); genePredFreeList(&list); } return outCount; }
static void fakePslFromGenePred(char *db, char *fileTbl, char *pslOut, char *cdsOut) /* check a genePred */ { struct genePredReader *gpr; struct genePred *gp; FILE *pslFh = mustOpen(pslOut, "w"); FILE *cdsFh = mustOpen(cdsOut, "w"); struct hash *chromHash = getChromHash(db); if (fileExists(fileTbl)) { gpr = genePredReaderFile(fileTbl, NULL); } else { struct sqlConnection *conn = hAllocConn(db); gpr = genePredReaderQuery(conn, fileTbl, NULL); hFreeConn(&conn); } while ((gp = genePredReaderNext(gpr)) != NULL) { cnvGenePred(chromHash, gp, pslFh, cdsFh); } genePredReaderFree(&gpr); carefulClose(&pslFh); carefulClose(&cdsFh); }
struct genePred *getPredsFromBeds(char *file, char *table, char *db) { struct sqlConnection *conn = hAllocConn(db); struct lineFile *lf = lineFileOpen(file, TRUE); char *words[5000]; int wordsRead; struct genePred *list = NULL; while( (wordsRead = lineFileChopNext(lf, words, sizeof(words)/sizeof(char *)) )) { if (wordsRead != 4) errAbort("file '%s' must be bed4. Line %d has %d fields", file, lf->lineIx, wordsRead); char where[10 * 1024]; sqlSafefFrag(where, sizeof where, "name = '%s' and chrom='%s' and txStart = %d and txEnd = %d", words[3], words[0], sqlUnsigned(words[1]), sqlUnsigned(words[2])); //printf("table %s where %s\n",table,where); struct genePredReader *reader = genePredReaderQuery( conn, table, where); struct genePred *pred; while ((pred = genePredReaderNext(reader)) != NULL) slAddHead(&list, pred); genePredReaderFree(&reader); } hFreeConn(&conn); if (list != NULL) slReverse(&list); return list; }
static void checkGenePred(char *fileTbl) /* check a genePred file or table */ { struct sqlConnection *conn = NULL; struct genePredReader *gpr; struct genePred *gp; int iRec = 0; if (fileExists(fileTbl)) { gpr = genePredReaderFile(fileTbl, NULL); } else if (gDb != NULL) { conn = hAllocConn(gDb); gpr = genePredReaderQuery(conn, fileTbl, NULL); } else { errAbort("file %s doesn't exist, must specify -db=db if this is a table", fileTbl); } while ((gp = genePredReaderNext(gpr)) != NULL) { checkAGenePred(fileTbl, ++iRec, gp); genePredFree(&gp); } genePredReaderFree(&gpr); hFreeConn(&conn); }
struct genePred *genePredReaderLoadFile(char* gpFile, char* chrom) /* Function that encapsulates reading a genePred file */ { struct genePredReader *gpr = genePredReaderFile(gpFile, chrom); struct genePred *gpList = genePredReaderAll(gpr); genePredReaderFree(&gpr); return gpList; }
struct genePred *genePredReaderLoadQuery(struct sqlConnection* conn, char* table, char* where) /* Function that encapsulates doing a query and loading the results */ { struct genePredReader *gpr = genePredReaderQuery(conn, table, where); struct genePred *gpList = genePredReaderAll(gpr); genePredReaderFree(&gpr); return gpList; }
struct genePred *genePredReaderLoadRangeQuery(struct sqlConnection* conn, char* table, char* chrom, int start, int end, char* extraWhere) /* Function that encapsulates doing a range query and loading the results */ { struct genePredReader *gpr = genePredReaderRangeQuery(conn, table, chrom, start, end, extraWhere); struct genePred *gpList = genePredReaderAll(gpr); genePredReaderFree(&gpr); return gpList; }
static void printCcdsHgGeneUrl(struct sqlConnection *conn, char *ccdsId, char* kgId) /* output a URL to hgGene for a ccds */ { char where[128]; struct genePredReader *gpr; struct genePred *ccdsGene = NULL, *kgGene = NULL; /* get ccds genePred to get location */ sqlSafefFrag(where, sizeof(where), "chrom = '%s' and name = '%s'", seqName, ccdsId); gpr = genePredReaderQuery(conn, "ccdsGene", where); ccdsGene = genePredReaderAll(gpr); genePredReaderFree(&gpr); if (ccdsGene == NULL) errAbort("%s not found in ccdsGene table for chrom %s", ccdsId, seqName); else if (ccdsGene->next != NULL) errAbort("multiple %s rows found in ccdsGene table for chrom %s", ccdsId, seqName); /* get KG genePred, as need exact location for link */ sqlSafefFrag(where, sizeof(where), "name = '%s' and strand = '%s'", kgId, ccdsGene->strand); gpr = genePredReaderRangeQuery(conn, "knownGene", seqName, ccdsGene->txStart, ccdsGene->txEnd, where); kgGene = genePredReaderAll(gpr); genePredReaderFree(&gpr); if (kgGene == NULL) errAbort("%s not found in knownGene table for chrom %s", kgId, seqName); else if (kgGene->next != NULL) errAbort("multiple %s rows found in knownGene table for chrom %s", kgId, seqName); printf("../cgi-bin/hgGene?%s&%s=%s&%s=%s&%s=%s&%s=%d&%s=%d", cartSidUrlString(cart), "db", database, "hgg_gene", kgId, "hgg_chrom", seqName, "hgg_start", kgGene->txStart, "hgg_end", kgGene->txEnd); genePredFree(&ccdsGene); genePredFree(&kgGene); }
static void loadGenes(struct orgGenes *genes, char *genePredFile) /* load genePred file into object */ { struct genePredReader *gpr = genePredReaderFile(genePredFile, NULL); struct genePred *gp; while ((gp = genePredReaderNext(gpr)) != NULL) { if ((gp->optFields & genePredExonFramesFld) == 0) genePredAddExonFrames(gp); loadGene(genes, gp); } genePredReaderFree(&gpr); }
static void getGeneAnns(struct sqlConnection *conn, struct hash *refSeqVerInfoTbl, char *outFile) /* get request genePred annotations from database */ { struct genePredReader *gpr = genePredReaderQuery(conn, "refGene", NULL); FILE *fh = mustOpen(outFile, "w"); struct genePred *gp; while ((gp = genePredReaderNext(gpr)) != NULL) { processGenePred(fh, refSeqVerInfoTbl, gp); genePredFree(&gp); } carefulClose(&fh); genePredReaderFree(&gpr); }
static void genePredHisto(char *what, char *gpFile, char *outFile) /* get data for generating histograms from a genePred file. */ { struct genePredReader *gpr = genePredReaderFile(gpFile, NULL); histoFuncType histoFunc = getHistoFunc(what); struct genePred *gp; FILE *outFh = mustOpen(outFile, "w"); while ((gp = genePredReaderNext(gpr)) != NULL) { histoFunc(gp, outFh); genePredFree(&gp); } carefulClose(&outFh); genePredReaderFree(&gpr); }
/* load one or more genePreds from the database */ struct genePred *getPredsForName(char *name, char *geneTable, char *db) { struct sqlConnection *conn = hAllocConn(db); struct genePred *list = NULL; char splitTable[HDB_MAX_TABLE_STRING]; struct genePred *gene; boolean hasBin; struct genePredReader *reader; boolean found = hFindSplitTable(db, NULL, geneTable, splitTable, &hasBin); if (!found) errAbort("can't find table %s\n", geneTable); char extra[2048]; if (onlyChrom != NULL) safef(extra, sizeof extra, "name='%s' and chrom='%s'", name, onlyChrom); else safef(extra, sizeof extra, "name='%s'", name); reader = genePredReaderQuery( conn, splitTable, extra); while ((gene = genePredReaderNext(reader)) != NULL) { verbose(2, "got gene %s\n",gene->name); slAddHead(&list, gene); } if (list == NULL) errAbort("no genePred for gene %s in %s\n",name, geneTable); slReverse(&list); genePredReaderFree(&reader); hFreeConn(&conn); return list; }