int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc != 5) usage(); acceptString = optionVal("A", NULL); if (acceptString) { acceptExtensionsCount = chopByChar(acceptString, ',', NULL, 0); AllocArray(acceptExtensions, acceptExtensionsCount); chopByChar(acceptString, ',', acceptExtensions, acceptExtensionsCount); verbose(1, "accept-option count: %d\n", acceptExtensionsCount); int i = 0; for(i=0; i<acceptExtensionsCount; ++i) { verbose(2, "accept-option: %s\n", acceptExtensions[i]); } } struct dyString *url = dyStringNew(4096); struct dyString *outPath = dyStringNew(4096); dyStringAppend(url, argv[3]); dyStringAppend(outPath, argv[4]); if (!paraSync(atoi(argv[1]), atoi(argv[2]), url, outPath, optionExists("newer"), optionExists("progress"))) exit(1); return 0; }
void _pf_punt_init() /* Initialize punt/catch system. Mostly just redirects the * errAbort handler. */ { punter.message = dyStringNew(0); punter.source = dyStringNew(0); pushWarnHandler(puntWarnHandler); pushAbortHandler(puntAbortHandler); }
void genotypeAndStrainFromKey(char *genotypeKey, struct sqlConnection *conn, char **retGenotype, char **retStrain) /* Return dynamically allocated string describing genotype */ { int key = atoi(genotypeKey); char *genotype = NULL, *strain = NULL; if (key > 0) { struct dyString *query = dyStringNew(0); struct dyString *geno = dyStringNew(256); struct sqlResult *sr; char **row; /* Figure out genotype. Create string that looks something like: * adh:cheap date,antp:+, * That is a comma separated list gene:allele. */ sqlDyStringPrintf(query, "select MRK_Marker.symbol,ALL_Allele.symbol " "from GXD_AlleleGenotype,MRK_Marker,ALL_Allele " "where GXD_AlleleGenotype._Genotype_key = %s " "and GXD_AlleleGenotype._Marker_key = MRK_Marker._Marker_key " "and GXD_AlleleGenotype._Allele_key = ALL_Allele._Allele_key " , genotypeKey); sr = sqlGetResultVerbose(conn, query->string); while ((row = sqlNextRow(sr)) != NULL) dyStringPrintf(geno, "%s:%s,", row[0], row[1]); sqlFreeResult(&sr); genotype = dyStringCannibalize(&geno); /* Figure out strain */ dyStringClear(query); sqlDyStringPrintf(query, "select PRB_Strain.strain from GXD_Genotype,PRB_Strain " "where GXD_Genotype._Genotype_key = %s " "and GXD_Genotype._Strain_key = PRB_Strain._Strain_key" , genotypeKey); strain = sqlQuickStringVerbose(conn, query->string); if (isUnknown(strain)) freez(&strain); dyStringFree(&query); } if (genotype == NULL) genotype = cloneString(""); if (strain == NULL) strain = cloneString(""); *retGenotype = genotype; *retStrain = strain; }
struct dyString *edwFormatDuration(long long seconds) /* Convert seconds to days/hours/minutes. Return result in a dyString you can free */ { struct dyString *dy = dyStringNew(0); int days = seconds/(3600*24); if (days > 0) dyStringPrintf(dy, "%d days, ", days); seconds -= days*3600*24; int hours = seconds/3600; if (hours > 0 || days > 0) dyStringPrintf(dy, "%d hours", hours); seconds -= hours*3600; if (days == 0) { int minutes = seconds/60; if (minutes > 0) { if (hours > 0) dyStringPrintf(dy, ", "); dyStringPrintf(dy, "%d minutes", minutes); } if (hours == 0) { if (minutes > 0) dyStringPrintf(dy, ", "); seconds -= minutes*60; dyStringPrintf(dy, "%d seconds", (int)seconds); } } return dy; }
void addImagesMatchingStage(struct visiSearcher *searcher, struct sqlConnection *conn, int schemeId, int taxon, char *minAge, int wordIx, int wordCount) /* Given a developmental stage scheme (schemeId) and a specific * stage, return all images that match stage */ { struct dyString *dy = dyStringNew(0); char *maxAge; dyStringClear(dy); dyStringPrintf(dy, "select age from lifeStage where lifeStageScheme = %d ", schemeId); dyStringPrintf(dy, "and age > %s order by age", minAge); maxAge = sqlQuickString(conn, dy->string); dyStringClear(dy); dyStringPrintf(dy, "select image.id from specimen,image "); dyStringPrintf(dy, "where specimen.age >= %s ", minAge); if (maxAge != NULL) dyStringPrintf(dy, "and specimen.age < %s ", maxAge); dyStringPrintf(dy, "and specimen.taxon = %d ", taxon); dyStringPrintf(dy, "and specimen.id = image.specimen"); addImagesMatchingQuery(searcher, conn, dy->string, NULL, NULL, wordIx, wordCount); dyStringFree(&dy); }
static char *findSourcePath(char *baseDir, struct slName *pathList, char *fileName, char *suffix) /* Given a pathList and a fileName, try and find file in path. */ { struct slName *dir; struct dyString *dy = dyStringNew(0); char *path = NULL; if (baseDir[0] == 0) baseDir = "."; dyStringPrintf(dy, "%s/%s%s", baseDir, fileName, suffix); if (fileExists(dy->string)) path = cloneString(dy->string); else { for (dir = pathList; dir != NULL; dir = dir->next) { dyStringClear(dy); dyStringPrintf(dy, "%s/%s%s", dir->name, fileName, suffix); if (fileExists(dy->string)) { path = cloneString(dy->string); break; } } } dyStringFree(&dy); if (path == NULL) errAbort("Couldn't find %s%s", fileName, suffix); return path; }
boolean safeGetOne(char *source, char *dest) /* Fetch file from source to tmp file. When fetch * is done rename temp file to dest and return TRUE. */ { struct dyString *command = dyStringNew(0); boolean ok = TRUE; int err; dyStringClear(command); dyStringPrintf(command, "wget -nv -O %s '%s'", tmpName, source); verbose(2, "%s\n", command->string); if ((err = system(command->string)) != 0) { fprintf(fLog, "Error %d on %s\n", err, command->string); warn("Error %d on %s", err, command->string); ++errCount; if (errCount > maxErrs) errAbort("Aborting after %d wget errors", errCount); ok = FALSE; } verbose(2, "wget returned %d\n", err); /* Rename file to proper name */ if (ok) { if ((err = rename(tmpName, dest)) < 0) { fprintf(fLog, "Couldn't rename %s to %s\n", tmpName, dest); errnoAbort("Couldn't rename %s to %s", tmpName, dest); } } dyStringFree(&command); return ok; }
struct hash *readDescriptionFile(char *fileName) /* Return two column file keyed by first column with * values in second column. Strip any tabs from values. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); char *line; struct hash *hash = newHash(16); while (lineFileNextReal(lf, &line)) { char *key = nextWord(&line); char *val = skipLeadingSpaces(line); if (val != NULL && val[0] != 0) { char *desc = hashFindVal(hash, key); subChar(val, '\t', ' '); stripChar(val, '\r'); /* if gene exists in hash */ if (desc != NULL) { struct dyString *dy = dyStringNew(1024); dyStringPrintf(dy, "%s ", desc); dyStringAppend(dy, val); val = cloneString(dy->string); dyStringFree(&dy); } /* add to gene and description to hash */ hashAdd(hash, key, cloneString(val)); } } lineFileClose(&lf); return hash; }
struct estOrientInfo *estOrientInfoLoadWhere(struct sqlConnection *conn, char *table, char *where) /* Load all estOrientInfo from table that satisfy where clause. The * where clause may be NULL in which case whole table is loaded * Dispose of this with estOrientInfoFreeList(). */ { struct estOrientInfo *list = NULL, *el; struct dyString *query = dyStringNew(256); struct sqlResult *sr; char **row; sqlDyStringPrintf(query, "select * from %s", table); if (where != NULL) dyStringPrintf(query, " where %s", where); sr = sqlGetResult(conn, query->string); int off = sqlFieldColumn(sr, "bin") + 1; // offset of data; function returns -1 if no bin while ((row = sqlNextRow(sr)) != NULL) { el = estOrientInfoLoad(row+off); slAddHead(&list, el); } slReverse(&list); sqlFreeResult(&sr); dyStringFree(&query); return list; }
void tagStormCheck(char *schemaFile, char *tagStormFile) /* tagStormCheck - Check that a tagStorm conforms to a schema.. */ { /* Load up schema from file. Make a hash of all non-wildcard * tags, and a list of wildcard tags. */ struct tagSchema *schema, *schemaList = tagSchemaFromFile(schemaFile); struct slRef *wildSchemaList = NULL, *requiredSchemaList = NULL; /* Split up schemaList into hash and wildSchemaList. Calculate schemaSize */ struct hash *hash = hashNew(0); int schemaSize = 0; for (schema = schemaList; schema != NULL; schema = schema->next) { ++schemaSize; if (anyWild(schema->name)) { refAdd(&wildSchemaList, schema); } else hashAdd(hash, schema->name, schema); if (schema->required != 0) refAdd(&requiredSchemaList, schema); } slReverse(&wildSchemaList); schemaList = NULL; struct tagStorm *tagStorm = tagStormFromFile(tagStormFile); struct dyString *scratch = dyStringNew(0); rCheck(tagStorm->forest, tagStormFile, wildSchemaList, hash, requiredSchemaList, scratch); if (gErrCount > 0) noWarnAbort(); else verbose(1, "No problems detected.\n"); }
void extractAccsFromGb(char *gbFile, boolean missingOk, char *accFile, char **accNames, int accCount) /* Parse records of genBank file and print ones that match accession names. */ { FILE *out = stdout; struct hash *accTbl = hashNew(0); struct lineFile *lf; struct dyString* headLines = dyStringNew(4096); int i; if (accFile != NULL) loadAccs(accFile, accTbl); for (i = 0; i < accCount; i++) addAcc(accTbl, accNames[i]); /* process file */ lf = lineFileOpen(gbFile, TRUE); while (seekLocus(lf)) processEntry(lf, accTbl, headLines, out); lineFileClose(&lf); /* flush and check for errors */ carefulClose(&out); if (!missingOk) checkMissedAccs(accTbl); }
static struct slName *getListFromCgapSageLibs(struct sqlConnection *conn, char *column, boolean returnIds, boolean distinct) /* Return [unique] list of tissues sorted alphabetically. */ { struct slName *list = NULL; struct dyString *dy = dyStringNew(0); char **row; struct sqlResult *sr; sqlDyStringPrintf(dy, "select "); if (distinct) dyStringAppend(dy, "distinct "); sqlDyStringPrintf(dy, "%s", column); if (returnIds) dyStringAppend(dy, ",libId"); sqlDyStringPrintf(dy, " from cgapSageLib order by %s", column); sr = sqlGetResult(conn, dy->string); while ((row = sqlNextRow(sr)) != NULL) { char *word = (returnIds) ? row[1] : row[0]; slNameAddHead(&list, word); } slReverse(&list); sqlFreeResult(&sr); dyStringFree(&dy); return list; }
struct spFeature *spFeatures(struct sqlConnection *conn, char *acc, int classId, /* Feature class ID, 0 for all */ int typeId) /* Feature type ID, 0 for all */ /* Get feature list. slFreeList this when done. */ { struct dyString *dy = dyStringNew(0); struct spFeature *list = NULL, *el; char **row; struct sqlResult *sr; dyStringAppend(dy, "select start,end,featureClass,featureType,softEndBits from feature "); dyStringPrintf(dy, "where acc = '%s'", acc); if (classId != 0) dyStringPrintf(dy, " and featureClass=%d", classId); if (typeId != 0) dyStringPrintf(dy, " and featureType=%d", typeId); sr = sqlGetResult(conn, dy->string); while ((row = sqlNextRow(sr)) != NULL) { AllocVar(el); el->start = sqlUnsigned(row[0]); el->end = sqlUnsigned(row[1]); el->featureClass = sqlUnsigned(row[2]); el->featureType = sqlUnsigned(row[3]); el->softEndBits = sqlUnsigned(row[4]); slAddHead(&list, el); } sqlFreeResult(&sr); dyStringFree(&dy); slReverse(&list); return list; }
void gensatFixFull(char *captionFile) /* Fix missing captions. */ { struct lineFile *lf = lineFileOpen(captionFile, TRUE); char *row[2]; struct dyString *sql = dyStringNew(0); struct sqlConnection *conn = sqlConnect(database); struct hash *capHash = newHash(16); while (lineFileRowTab(lf, row)) { int captionId; char *submitId = row[0]; char *caption = row[1]; captionId = hashIntValDefault(capHash, caption, 0); if (captionId == 0) { dyStringClear(sql); dyStringAppend(sql, "insert into caption values(default, \""); dyStringAppend(sql, caption); dyStringAppend(sql, "\")"); sqlUpdate(conn, sql->string); verbose(1, "%s\n", sql->string); captionId = sqlLastAutoId(conn); hashAddInt(capHash, caption, captionId); } dyStringClear(sql); dyStringPrintf(sql, "update imageFile set caption=%d ", captionId); dyStringPrintf(sql, "where submissionSet=%d ", gensatId); dyStringPrintf(sql, "and submitId = \"%s\"", submitId); sqlUpdate(conn, sql->string); verbose(1, "%s\n", sql->string); } dyStringFree(&sql); }
char *identifierWhereClause(char *idField, struct hash *idHash) /* If the number of pasted IDs is reasonably low, return a where-clause component for the IDs. */ { if (idHash == NULL || idField == NULL) return NULL; int numIds = hashNumEntries(idHash); int maxIdsInWhere = cartUsualInt(cart, "hgt_maxIdsInWhere", DEFAULT_MAX_IDS_IN_WHERE); if (numIds > 0 && numIds <= maxIdsInWhere) { struct dyString *dy = dyStringNew(16 * numIds); dyStringPrintf(dy, "%s in (", idField); struct hashCookie hc = hashFirst(idHash); boolean first = TRUE; char *id; while ((id = hashNextName(&hc)) != NULL) { if (first) first = FALSE; else dyStringAppend(dy, ", "); dyStringPrintf(dy, "'%s'", id); } dyStringAppend(dy, ")"); return dyStringCannibalize(&dy); } return NULL; }
static void addPrimaryIdsToHash(struct sqlConnection *conn, struct hash *hash, char *idField, struct slName *tableList, struct lm *lm, char *extraWhere) /* For each table in tableList, query all idField values and add to hash, * id -> uppercased id for case-insensitive matching. */ { struct slName *table; struct sqlResult *sr; char **row; struct dyString *query = dyStringNew(0); for (table = tableList; table != NULL; table = table->next) { dyStringClear(query); sqlDyStringPrintf(query, "select %s from %s", idField, table->name); if (extraWhere != NULL) dyStringPrintf(query, " where %s", extraWhere); sr = sqlGetResult(conn, query->string); while ((row = sqlNextRow(sr)) != NULL) { if (isNotEmpty(row[0])) { char *origCase = lmCloneString(lm, row[0]); touppers(row[0]); hashAdd(hash, row[0], origCase); } } sqlFreeResult(&sr); } }
void addImagesMatchingStage(struct visiSearcher *searcher, struct sqlConnection *conn, int schemeId, int taxon, char *minAge, int wordIx, int wordCount) /* Given a developmental stage scheme (schemeId) and a specific * stage, return all images that match stage */ { struct dyString *dy = dyStringNew(0); char *maxAge; // note in the code below minAge and maxAge are strings // but they should contain float values. Putting single-quotes // around them and escaping their contents is something that will // protect against sql injection. dyStringClear(dy); sqlDyStringPrintf(dy, "select age from lifeStage where lifeStageScheme = %d ", schemeId); sqlDyStringPrintf(dy, "and age > '%s' order by age", minAge); maxAge = sqlQuickString(conn, dy->string); dyStringClear(dy); sqlDyStringPrintf(dy, "select image.id from specimen,image "); sqlDyStringPrintf(dy, "where specimen.age >= '%s' ", minAge); if (maxAge != NULL) sqlDyStringPrintf(dy, "and specimen.age < '%s' ", maxAge); dyStringPrintf(dy, "and specimen.taxon = %d ", taxon); dyStringPrintf(dy, "and specimen.id = image.specimen"); addImagesMatchingQuery(searcher, conn, dy->string, NULL, NULL, wordIx, wordCount); dyStringFree(&dy); }
char *aliasString(char *id, struct sqlConnection *conn) /* return alias string as it would be printed in html, can free after use */ { char query[256]; struct sqlResult *sr = NULL; char **row; int totalCount; int cnt = 0; totalCount = countAlias(id,conn); if (totalCount > 0) { struct dyString *aliasReturn = dyStringNew(0); dyStringPrintf(aliasReturn, "<B>Alternate Gene Symbols:</B> "); safef(query, sizeof(query), "select alias from kgAlias where kgId = '%s' order by alias", id); sr = sqlGetResult(conn, query); row = sqlNextRow(sr); while (cnt < totalCount) { /* skip kgId and the maint gene symbol (curGeneName) */ if ((!sameWord(id, row[0])) && (!sameWord(row[0], curGeneName))) { dyStringPrintf(aliasReturn, "%s", row[0]); if (cnt < (totalCount-1)) dyStringPrintf(aliasReturn, ", "); cnt++; } row = sqlNextRow(sr); } dyStringPrintf(aliasReturn, "<BR>"); sqlFreeResult(&sr); return dyStringCannibalize(&aliasReturn); } return NULL; }
struct dyString *unrepFileName(char *fileName, boolean isSingle) /* Return string with Rep# in fileName replaced with "Merged" */ { char *s = strstr(fileName, "Rep"); struct dyString *dy = dyStringNew(0); if (s == NULL) { if (isSingle) dyStringAppend(dy, fileName); else errAbort("No 'Rep' in fileName %s", fileName); } else { char *pastRep = s + strlen("Rep"); int digitCount = countLeadingDigits(pastRep); if (digitCount < 1) errAbort("No digits after 'Rep' in filename %s", fileName); pastRep += digitCount; dyStringAppendN(dy, fileName, s-fileName); dyStringAppend(dy, "Merged"); int len = strlen(pastRep); if (!isSingle && endsWith(pastRep, ".gz")) len -= strlen(".gz"); dyStringAppendN(dy, pastRep, len); } return dy; }
char *getDescription(struct hash *ra,char *alternateSetting) // Returns allocated string that is description. Will include DEPRECATED if appropriate { struct dyString *dyDescription = dyStringNew(256); char *deprecated = hashFindVal(ra, "deprecated"); if (deprecated != NULL) dyStringPrintf(dyDescription,"DEPRECATED - %s",deprecated); char *description = hashFindVal(ra, CV_DESCRIPTION); if (description == NULL && alternateSetting != NULL) description = hashFindVal(ra, alternateSetting); if (description == NULL) description = hashFindVal(ra, CV_TITLE); if (description == NULL) description = hashFindVal(ra, CV_LABEL); if (description != NULL) { if (dyStringLen(dyDescription) > 0) dyStringAppend(dyDescription,"<BR>"); dyStringAppend(dyDescription,description); } if (dyStringLen(dyDescription) > 0) return dyStringCannibalize(&dyDescription); dyStringFree(&dyDescription); return NULL; }
static void getItemLabel(struct sqlConnection *conn, char *retroInfoTbl, unsigned labelSet, struct linkedFeatures *lf) /* get label for a retro item */ { struct ucscRetroInfo *info = NULL; info = ucscRetroInfoQuery(conn, retroInfoTbl, lf->name); char *geneSymbol = getRetroParentSymbol(info, lf->name); //lf->extra = geneSymbol; struct dyString *label = dyStringNew(64); dyStringAppend(label, "retro-"); if ((labelSet & useGene) && (retroInfoTbl != NULL)) { if ((geneSymbol != NULL) && (strlen(geneSymbol) > 0)) dyStringAppend(label, geneSymbol); else labelSet |= useAcc; // no gene, so force acc } /* if both accession and gene are selected, add to item label */ if (labelSet & useAcc) { if (labelSet & useGene) { dyStringAppend(label, "/"); dyStringAppend(label, lf->name); } else dyStringAppend(label, lf->name); } ucscRetroInfoFree(&info); lf->extra = dyStringCannibalize(&label); }
struct repBundle *bundleReplicates(struct replicate **pRepList) /* Bundle together replicates, eating *pRepList in the process. */ { struct replicate *rep, *nextRep; struct repBundle *bundleList = NULL, *bundle; struct dyString *hashName = dyStringNew(0); struct hash *bundleHash = hashNew(0); for (rep = *pRepList; rep != NULL; rep = nextRep) { nextRep = rep->next; // Going to clobber ->next field dyStringClear(hashName); struct slPair *tag; for (tag = rep->tagList; tag != NULL; tag = tag->next) { if (!sameString(tag->name, "replicate") && !sameString(tag->name, "fileName")) dyStringPrintf(hashName, "%s=%s;", tag->name, (char *)(tag->val)); } bundle = hashFindVal(bundleHash, hashName->string); if (bundle == NULL) { AllocVar(bundle); slAddHead(&bundleList, bundle); hashAddSaveName(bundleHash, hashName->string, bundle, &bundle->hashName); } slAddTail(&bundle->repList, rep); } slReverse(&bundleList); *pRepList = NULL; return bundleList; }
samfile_t *bamOpen(char *fileOrUrl, char **retBamFileName) /* Return an open bam file, dealing with FUSE caching if need be. * Return parameter if NON-null will return the file name after FUSing */ { char *bamFileName = fileOrUrl; if (retBamFileName != NULL) *retBamFileName = bamFileName; #ifdef BAM_VERSION // suppress too verbose messages in samtools >= 0.1.18; see redmine #6491 // This variable didn't exist in older versions of samtools (where BAM_VERSION wasn't defined). bam_verbose = 1; #endif samfile_t *fh = samopen(bamFileName, "rb", NULL); if (fh == NULL) { boolean usingUrl = (strstr(fileOrUrl, "tp://") || strstr(fileOrUrl, "https://")); struct dyString *urlWarning = dyStringNew(0); if (usingUrl) { dyStringAppend(urlWarning, ". If you are able to access the URL with your web browser, " "please try reloading this page."); } errAbort("Failed to open %s%s", fileOrUrl, urlWarning->string); } return fh; }
struct meta *metaNextStanza(struct lineFile *lf) /* Return next stanza in a meta file. Does not set parent/child/next pointers. * Returns NULL at end of file. Does a little error checking, making sure * that indentation level is consistent across all lines of stanza. Returns * indentation level. */ { /* See if anything left in file, and if not return. */ if (!raSkipLeadingEmptyLines(lf, NULL)) return NULL; /* Allocate return structure and vars to help parse. */ struct meta *meta; AllocVar(meta); struct dyString *dy = dyStringNew(256); char *tag,*val; /* Loop to get all tags in stanza. */ boolean firstTime = TRUE; int initialIndent = 0; for (;;) { dyStringClear(dy); if (!raNextTagVal(lf, &tag, &val, dy)) break; /* Make tag/val and add it to list. */ struct metaTagVal *mtv; AllocVar(mtv); mtv->tag = cloneString(tag); mtv->val = cloneString(val); slAddHead(&meta->tagList, mtv); /* Check indentation. */ int indent = countLeadingSpacesDetabbing(dy->string, 8); if (firstTime) { initialIndent = indent; firstTime = FALSE; } else { if (indent != initialIndent) { warn("Error line %d of %s\n", lf->lineIx, lf->fileName); warn("Indentation level %d doesn't match level %d at start of stanza.", indent, initialIndent); if (strchr(dy->string, '\t')) warn("There are tabs in the indentation, be sure tab stop is set to 8 spaces."); noWarnAbort(); } } } slReverse(&meta->tagList); /* Set up remaining fields and return. */ assert(meta->tagList != NULL); meta->name = meta->tagList->val; meta->indent = initialIndent; return meta; }
char *updateDescription(char *description, char *orf, struct hash *orfToGene, struct hash *classDesc, struct hash *geneDesc) /* The descriptions I got from Lincoln of known genes are quite * poor - only containing the gene name. Here we update the * description with something better if possible. */ { char *update = NULL; char *geneName = hashFindVal(orfToGene, orf); if (geneName != NULL) { update = hashFindVal(geneDesc, geneName); /* if this does not exist in the hash or the entry is "NULL" */ if ((update == NULL) || sameString(update, "NULL") ) { char *class = cloneString(geneName); char *desc; subChar(class, '-', 0); desc = hashFindVal(classDesc, class); if (desc != NULL) { struct dyString *dy = dyStringNew(0); dyStringPrintf(dy, "%s - a member of the gene class ", geneName); dyStringAppend(dy, desc); update = cloneString(dy->string); dyStringFree(&dy); } }
void fixMotif(struct dnaMotif *motif, int targetSize, char *motifTable, struct sqlConnection *conn) /* Try and fix motif by trimming degenerate columns. */ { struct dyString *dy = dyStringNew(0); printf("Fixing %s in %s from:\n", motif->name, motifTable); dnaMotifPrintProb(motif, uglyOut); while (targetSize < motif->columnCount) { double startInfo = dnaMotifBitsOfInfo(motif, 0); double endInfo = dnaMotifBitsOfInfo(motif, motif->columnCount-1); motif->columnCount -= 1; if (startInfo < endInfo) { memcpy(motif->aProb, motif->aProb+1, sizeof(motif->aProb[0]) * motif->columnCount); memcpy(motif->cProb, motif->cProb+1, sizeof(motif->cProb[0]) * motif->columnCount); memcpy(motif->gProb, motif->gProb+1, sizeof(motif->gProb[0]) * motif->columnCount); memcpy(motif->tProb, motif->tProb+1, sizeof(motif->tProb[0]) * motif->columnCount); } } printf("to:\n"); dnaMotifPrintProb(motif, uglyOut); dyStringPrintf(dy, "update %s set ", motifTable); formatProb(dy, "aProb", motif->aProb, motif->columnCount); formatProb(dy, "cProb", motif->cProb, motif->columnCount); formatProb(dy, "gProb", motif->gProb, motif->columnCount); formatProb(dy, "tProb", motif->tProb, motif->columnCount); dyStringPrintf(dy, "columnCount=%d ", motif->columnCount); dyStringPrintf(dy, "where name = '%s'", motif->name); sqlUpdate(conn, dy->string); dyStringFree(&dy); }
struct dyString *readAndReplaceTableName(char *fileName, char *table) /* Read file into string. While doing so strip any leading comments * and insist that the first non-comment line contain the words * "create table" followed by a table name. Replace the table name, * and copy the rest of the file verbatem. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); struct dyString *dy = dyStringNew(0); char *line, *word; if (!lineFileNextReal(lf, &line)) errAbort("No real lines in %s\n", fileName); word = nextWord(&line); if (!sameWord(word, "create")) errAbort("Expecting first word in file to be CREATE. Got %s", word); word = nextWord(&line); if (word == NULL || !sameWord(word, "table")) errAbort("Expecting second word in file to be table. Got %s", emptyForNull(word)); word = nextWord(&line); if (word == NULL) errAbort("Expecting table name on same line as CREATE TABLE"); sqlDyStringPrintf(dy, "CREATE TABLE %s ", table); if (line != NULL) dyStringAppend(dy, line); dyStringAppendC(dy, '\n'); while (lineFileNext(lf, &line, NULL)) { dyStringAppend(dy, line); dyStringAppendC(dy, '\n'); } lineFileClose(&lf); return dy; }
struct annoStreamer *annoStreamVcfNew(char *fileOrUrl, boolean isTabix, struct annoAssembly *aa, int maxRecords) /* Create an annoStreamer (subclass) object from a VCF file, which may * or may not have been compressed and indexed by tabix. */ { int maxErr = -1; // don't errAbort on VCF format warnings/errs struct vcfFile *vcff; if (isTabix) vcff = vcfTabixFileMayOpen(fileOrUrl, NULL, 0, 0, maxErr, 0); else vcff = vcfFileMayOpen(fileOrUrl, maxErr, 0, FALSE); if (vcff == NULL) errAbort("annoStreamVcfNew: unable to open VCF: '%s'", fileOrUrl); struct annoStreamVcf *self; AllocVar(self); struct annoStreamer *streamer = &(self->streamer); struct asObject *asObj = vcfAsObj(); annoStreamerInit(streamer, aa, asObj, fileOrUrl); streamer->rowType = arWords; streamer->setRegion = asvSetRegion; streamer->getHeader = asvGetHeader; streamer->nextRow = asvNextRow; streamer->close = asvClose; self->vcff = vcff; self->dyGt = dyStringNew(1024); self->chromNameHash = hashNew(0); self->isTabix = isTabix; self->numCols = slCount(asObj->columnList); self->numFileCols = 8; if (vcff->genotypeCount > 0) self->numFileCols = 9 + vcff->genotypeCount; self->maxRecords = maxRecords; return (struct annoStreamer *)self; }
void printSections(struct section *sectionList, struct sqlConnection *conn, char *geneId) /* Print each section in turn. */ { struct section *section; for (section = sectionList; section != NULL; section = section->next) { boolean isOpen = sectionIsOpen(section); char *otherState = (isOpen ? "1" : "0"); char *indicator = (isOpen ? "-" : "+"); char *indicatorImg = (isOpen ? "../images/remove.gif" : "../images/add.gif"); struct dyString *header = dyStringNew(0); //keep the following line for future debugging need //printf("<br>printing %s section\n", section->name);fflush(stdout); dyStringPrintf(header, "<A NAME=\"%s\"></A>", section->name); char *closeVarName = sectionCloseVar(section->name); dyStringPrintf(header, "<A HREF=\"%s?%s&%s=%s#%s\" class=\"bigBlue\"><IMG src=\"%s\" alt=\"%s\" class=\"bigBlue\"></A> ", geneCgi, cartSidUrlString(cart), closeVarName, otherState, section->name, indicatorImg, indicator); dyStringAppend(header, section->longLabel); webNewSection("%s",header->string); if (isOpen) { long startTime = clock1000(); section->print(section, conn, geneId); section->printTime = clock1000() - startTime; } else { printf("Press \"+\" in the title bar above to open this section."); } dyStringFree(&header); } }
static void parseSourceOrganism() /* parse source /organism fields, output as srcOrg if different from org */ { int numOrgs, i; char **orgs; if (gbSourceOrganism->val->stringSize == 0) return; if (srcOrgBuf == NULL) srcOrgBuf = dyStringNew(256); dyStringClear(srcOrgBuf); numOrgs = chopString(gbSourceOrganism->val->string, ";", NULL, 0); AllocArray(orgs, numOrgs); chopString(gbSourceOrganism->val->string, ";", orgs, numOrgs); for (i = 0; i < numOrgs; i++) { if (!sameString(orgs[i], gbOrganismField->val->string)) { if (srcOrgBuf->stringSize > 0) dyStringAppendC(srcOrgBuf, ';'); dyStringAppend(srcOrgBuf, orgs[i]); } } freeMem(orgs); if (srcOrgBuf->stringSize > 0) kvtAdd(kvt, "srcOrg", srcOrgBuf->string); }