void doGenePreds(struct sqlConnection *conn, char *db, char *orthoDb, char *chrom, char *netTable, char *geneFileName, char *geneTableName, char *outBedName, char *selectedFileName, int *foundCount, int *notFoundCount) /* Map over genePreds. */ { FILE *bedOut = NULL; FILE *selectedOut = NULL; FILE *cdsErrorFp = NULL; struct genePred *gene = NULL, *geneList = NULL; struct bed *bed = NULL; //init output files if(optionExists("cdsErrorFile")) { cdsErrorFp = fopen( optionVal("cdsErrorFile", NULL), "w" ); fprintf( cdsErrorFp, "#name\tchrom\ttxStart\ttxEnd\tcdsStart\tcdsEnd\tstrand\texonCount\n" ); fclose(cdsErrorFp); } warn("Loading Gene Predictions."); assert(outBedName); if(geneFileName) geneList=genePredLoadAll(geneFileName); else geneList=loadGeneFromTable(conn, geneTableName, chrom, 0, BIGNUM); /* Convert genePreds. */ warn("Converting genes."); bedOut = mustOpen(outBedName, "w"); if (selectedFileName != NULL) selectedOut = mustOpen(selectedFileName, "w"); for(gene = geneList; gene != NULL; gene = gene->next) { struct genePred *synGene = NULL; if(differentString(gene->chrom, chrom)) continue; synGene = orthoBedFromGene(conn, db, orthoDb, netTable, gene); occassionalDot(); if(synGene != NULL && synGene->exonCount > 0) { (*foundCount)++; genePredTabOut(synGene, bedOut); if (selectedOut != NULL) genePredTabOut(gene, selectedOut); } else (*notFoundCount)++; genePredFree(&synGene); } carefulClose(&selectedOut); carefulClose(&bedOut); }
void mafToSnpBed(char *database, char *mafIn, char *gpIn, char *bedOut) /* mafToSnpBed - finds SNPs in MAF and builds a bed with their functional consequence. */ { struct mafFile *mafFile = mafReadAll(mafIn); struct genePred *genePred = genePredLoadAll(gpIn); FILE *f = mustOpen(bedOut, "w"); struct genePred *gp, *next; for(gp = genePred; gp; gp = next) { next = gp->next; gp->next = NULL; parseOneGp(database, mafFile->alignments, gp, f); } }
int main(int argc, char *argv[]) { struct genePred *gpList = NULL; FILE *out = NULL; optionInit(&argc, argv, NULL); if(argc !=4) usage(); warn("Loading gene predictions."); char *chromSizesFile = argv[1]; if(optionExists("bedFormat")) gpList = gpFromBedFile(argv[2]); else gpList = genePredLoadAll(argv[2]); out = mustOpen(argv[3],"w"); warn("Doing conversion."); pslListFromGenePred(chromSizesFile, gpList, out); carefulClose(&out); warn("Done."); return 0; }
void createAltSplices(char *db, char *outFile, boolean memTest) /* Top level routine, gets genePredictions and runs through them to build altSplice graphs. */ { struct genePred *gp = NULL, *gpList = NULL; struct altGraphX *ag=NULL; FILE *out = NULL; struct sqlConnection *conn = hAllocConn(db); char *gpFile = NULL; char *bedFile = NULL; int count =0; /* Figure out where to get coordinates from. */ bedFile = optionVal("beds", NULL); gpFile = optionVal("genePreds", NULL); if(bedFile != NULL) gpList = convertBedsToGps(bedFile); else if(gpFile != NULL) gpList = genePredLoadAll(gpFile); else { warn("Must specify target loci as either a bed file or a genePred file"); usage(); } if (!gpAllSameChrom(gpList)) errAbort("Multiple chromosomes in bed or genePred file."); /* Sanity check to make sure we got some loci to work with. */ if(gpList == NULL) errAbort("No gene boundaries were found."); slSort(&gpList, genePredCmp); setupTables(gpList->chrom); /* If local memory get things going here. */ if(optionExists("localMem")) { warn("Using local memory. Setting up caches..."); useChromKeeper = TRUE; setupChromKeeper(conn, optionVal("db", NULL), gpList->chrom); if(!optionExists("skipTissues")) { if(optionExists("tissueLibFile")) readTissueLibraryIntoCache(optionVal("tissueLibFile", NULL)); else setupTissueLibraryCache(conn); } warn("Done setting up local caches."); } else /* Have to set up agxSeen binKeeper based on genePreds. */ { int maxPos = 0; int minPos = BIGNUM; for(gp = gpList; gp != NULL; gp = gp->next) { maxPos = max(maxPos, gp->txEnd); minPos = min(minPos, gp->txStart); } agxSeenBin = binKeeperNew(max(0, minPos-10000), min(BIGNUM,maxPos+10000)); } dotForUserInit(max(slCount(gpList)/10, 1)); out = mustOpen(outFile, "w"); for(gp = gpList; gp != NULL && count < 5; ) { dotForUser(); fflush(stderr); ag = agFromGp(db, gp, conn, 5, out); /* memory held in binKeeper. Free * later. */ if (memTest != TRUE) gp = gp->next; } genePredFreeList(&gpList); hFreeConn(&conn); /* uglyf("%d genePredictions with %d clusters, %d cassette exons, %d of are not mod 3.\n", */ /* slCount(gpList), clusterCount, cassetteCount, misSense); */ }