示例#1
0
void colTransform(char *column, char *input, char *addFactor, char *mulFactor, char *output)
/* colTransform - Add and/or multiply column by constant.. */
{
int col = sqlUnsigned(column) - 1;
double add = sqlDouble(addFactor);
double mul = sqlDouble(mulFactor);
struct lineFile *lf = lineFileOpen(input, TRUE);
FILE *f = mustOpen(output, "w");
char *words[512];
int wordCount;
while ((wordCount = lineFileChop(lf, words)) > 0)
    {
    lineFileExpectAtLeast(lf, col, wordCount);
    double x = lineFileNeedDouble(lf, words, col);
    int i;
    for (i=0; i<wordCount; ++i)
        {
	if (i != 0)
	    fputc('\t', f);
	if (i == col)
	    fprintf(f, "%g", x*mul+add);
	else
	    fputs(words[i], f);
	}
    fputc('\n', f);
    }
carefulClose(&f);
}
示例#2
0
struct subjInfo *doubleAdvFilter(struct column *col,
	struct sqlConnection *conn, struct subjInfo *list)
/* Do advanced filter on string in main table. */
{
char *minString = advFilterVal(col, "min");
char *maxString = advFilterVal(col, "max");
if (minString || maxString)
    {
    double min = minString ? sqlDouble(minString) : 0.0;
    double max = maxString ? sqlDouble(maxString) : 0.0;
    struct subjInfo *newList = NULL, *next, *si;
    for (si = list; si != NULL; si = next)
        {
	char *cell = col->cellVal(col, si, conn);
	boolean invalid = sameString(cell,".");
	double val = invalid ? 0.0 : sqlDouble(cell);
	freez(&cell);
	next = si->next;
	if (!invalid && !((minString && (val < min)) || (maxString && (val > max))))
	    {
	    slAddHead(&newList, si);
	    }
	}
    slReverse(&newList);
    list = newList;
    }
return list;
}
示例#3
0
void gtexInfoStaticLoad(char **row, struct gtexInfo *ret)
/* Load a row from gtexInfo table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{

ret->version = row[0];
ret->releaseDate = row[1];
ret->maxScore = sqlDouble(row[2]);
ret->maxMedianScore = sqlDouble(row[3]);
}
示例#4
0
文件: sax.c 项目: hjanime/bwtool
void bwtool_sax(struct hash *options, char *favorites, char *regions, unsigned decimals, char *alpha_s, char *bigfile,
		char *outputfile)
/* bwtool_sax - main for the sax symbol program */
{
    struct metaBig *mb = metaBigOpen_check(bigfile, regions);
    struct bed *bed;
    int alpha = (alpha_s != NULL) ? sqlUnsigned(alpha_s) : 8;
    unsigned itStart = sqlUnsigned((char *)hashOptionalVal(options, "iterate-start", (alpha_s != NULL) ? alpha_s : "8"));
    unsigned itEnd = sqlUnsigned((char *)hashOptionalVal(options, "iterate-end", (alpha_s != NULL) ? alpha_s : "8"));
    unsigned window = sqlUnsigned((char *)hashOptionalVal(options, "sax-window", "0"));
    char *mean_s = (char *)hashOptionalVal(options, "mean", NULL);
    char *std_s = (char *)hashOptionalVal(options, "std", NULL);
    if (mb->type != isaBigWig)
	errAbort("%s doesn't seem to be a bigWig", bigfile);
    double mean = bigWigMean(mb->big.bbi);
    double std = bigWigStd(mb->big.bbi);
    if (mean_s)
	mean = sqlDouble(mean_s);
    if (std_s)
	std = sqlDouble(std_s);
    FILE *out;
    boolean do_std = (hashLookup(options, "std") != NULL);
    boolean do_mean = (hashLookup(options, "mean") != NULL);
    boolean bed4 = (hashLookup(options, "bed4") != NULL);
    boolean wig_out = (hashLookup(options, "add-wig-out") != NULL);
    if (do_mean || do_std)
    {
	if (!do_std || !do_mean)
	    errAbort("if -mean is specified, -std is required, and vice versa");
	else if (std <= 0)
	    errAbort("-std must be > 0");
    }
    out = mustOpen(outputfile, "w");
    for (bed = mb->sections; bed != NULL; bed = bed->next)
    {
	/* print a header */
	if ((itStart == itEnd) && !bed4)
	{
	    if (bed == mb->sections)
		fprintf(out, "# alphabet size = %d\n", alpha);
	    wigsax_fasta(out, mb, bed, alpha, window, mean, std);
	}
	else
	{
	    if (bed == mb->sections)
		fprintf(out, "# alphabet size = %d\n", alpha);
	    wigsax_bed4(out, mb, bed, alpha, window, mean, std, wig_out);
	}
    }
    metaBigClose(&mb);
    carefulClose(&out);
}
示例#5
0
struct gtexInfo *gtexInfoLoad(char **row)
/* Load a gtexInfo from row fetched with select * from gtexInfo
 * from database.  Dispose of this with gtexInfoFree(). */
{
struct gtexInfo *ret;

AllocVar(ret);
ret->version = cloneString(row[0]);
ret->releaseDate = cloneString(row[1]);
ret->maxScore = sqlDouble(row[2]);
ret->maxMedianScore = sqlDouble(row[3]);
return ret;
}
示例#6
0
struct peakSource *peakSourceLoadAll(char *fileName, int dimCount)
/* Read file, parse it line by line and return list of peakSources. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
int rowSize = dimCount + 6;
char *row[rowSize];
struct peakSource *sourceList = NULL, *source;
while (lineFileNextRow(lf, row, rowSize))
    {
    /* Allocate struct and read in fixed fields. */
    AllocVar(source);
    source->dataSource = cloneString(row[0]);
    source->chromColIx = sqlUnsigned(row[1]);
    source->startColIx = sqlUnsigned(row[2]);
    source->endColIx = sqlUnsigned(row[3]);
    source->scoreColIx = sqlUnsigned(row[4]);
    source->normFactor = sqlDouble(row[5]);

    /* Read in dimension labels. */
    AllocArray(source->labels, dimCount);
    int i;
    for (i=0; i<dimCount; ++i)
        source->labels[i] = cloneString(row[i+6]);

    /* Calculate required columns. */
    int minColCount = max(source->chromColIx, source->startColIx);
    minColCount = max(minColCount, source->endColIx);
    minColCount = max(minColCount, source->scoreColIx);
    source->minColCount = minColCount + 1;
    slAddHead(&sourceList, source);
    }
lineFileClose(&lf);
slReverse(&sourceList);
return sourceList;
}
struct chromGraph *chromGraphListWithTable(char *fileName, char *db, char *table)
/* Read the chromGraph file and convert to the  chr,chromStart format. */
{
    struct sqlConnection *conn = sqlConnect(db);
    struct hash *posHash = NULL;
    struct lineFile *lf;
    struct chromGraph *list = NULL;
    char *words[2];
    checkTableForFields(conn, table);
    posHash = posHashFromTable(conn, table);
    sqlDisconnect(&conn);
    lf = lineFileOpen(fileName, TRUE);
    while (lineFileRow(lf, words))
    {
        struct chromGraph *cg;
        /* Look up ID in hash. */
        struct slPair *infoFromHash = hashFindVal(posHash, words[0]);
        if (!infoFromHash)
            warn("%s line %d: %s not found in %s table", fileName, lf->lineIx, words[0], table);
        else
        {
            AllocVar(cg);
            cg->chrom = cloneString(infoFromHash->name);
            cg->chromStart = ptToInt(infoFromHash->val);
            cg->val = sqlDouble(words[1]);
            slAddHead(&list, cg);
        }
    }
    slReverse(&list);
    /* Free stuff up. */
    lineFileClose(&lf);
    hashFreeWithVals(&posHash, slPairFree);
    return list;
}
示例#8
0
static double getSignalAt(char *table, struct bed *cluster)
/* Get (average) signal from table entries that overlap cluster */
{
struct sqlConnection *conn = hAllocConn(database);
int count = 0;
double sum = 0;
if (sqlTableExists(conn, table))  // Table might be withdrawn from data thrash
    {
    int rowOffset;
    struct sqlResult *sr = hRangeQuery(conn, table, cluster->chrom, cluster->chromStart, 
	    cluster->chromEnd, NULL, &rowOffset);
    int signalCol = sqlFieldColumn(sr, "signalValue");
    if (signalCol < 0)
	internalErr();
    char **row;
    while ((row = sqlNextRow(sr)) != NULL)
	{
	count += 1;
	sum += sqlDouble(row[signalCol]);
	}
    sqlFreeResult(&sr);
    }
hFreeConn(&conn);
if (count > 0)
    return sum/count;
else
    return 0;
}
示例#9
0
void peakClusterMakerAddFromSource(struct peakClusterMaker *maker, struct peakSource *source)
/* Read through data source and add items to it to rangeTrees in maker */
{
struct hash *chromHash = maker->chromHash;
struct lineFile *lf = lineFileOpen(source->dataSource, TRUE);
struct lm *lm = chromHash->lm;	/* Local memory pool - share with hash */
char *row[source->minColCount];
struct peakItem *item;
char *line;
while (lineFileNextReal(lf, &line))
    {
    char *asciiLine = lmCloneString(lm, line);
    int wordCount = chopByWhite(line, row, source->minColCount);
    lineFileExpectAtLeast(lf, source->minColCount, wordCount);
    char *chrom = row[source->chromColIx];
    struct hashEl *hel = hashLookup(chromHash, chrom);
    if (hel == NULL)
        {
	struct rbTree *tree = rangeTreeNewDetailed(lm, maker->stack);
	hel = hashAdd(chromHash, chrom, tree);
	}
    struct rbTree *tree = hel->val;
    lmAllocVar(lm, item);
    item->chrom = hel->name;
    item->chromStart = sqlUnsigned(row[source->startColIx]);
    item->chromEnd = sqlUnsigned(row[source->endColIx]);
    item->score = sqlDouble(row[source->scoreColIx]) * source->normFactor;
    if (item->score > 1000) item->score = 1000;
    item->source = source;
    item->asciiLine = asciiLine;
    rangeTreeAddValList(tree, item->chromStart, item->chromEnd, item);
    }
lineFileClose(&lf);
}
示例#10
0
double calcNormScoreFactor(char *fileName, int scoreCol)
/* Figure out what to multiply things by to get a nice browser score (0-1000) */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[scoreCol+1];
double sum = 0, sumSquares = 0;
int n = 0;
double minVal=0, maxVal=0;
int fieldCount;
while ((fieldCount = lineFileChop(lf, row)) != 0)
    {
    lineFileExpectAtLeast(lf, scoreCol+1, fieldCount);
    double x = sqlDouble(row[scoreCol]);
    if (n == 0)
        minVal = maxVal = x;
    if (x < minVal) minVal = x;
    if (x > maxVal) maxVal = x;
    sum += x;
    sumSquares += x*x;
    n += 1;
    }
lineFileClose(&lf);
double std = calcStdFromSums(sum, sumSquares, n);
double mean = sum/n;
double highEnd = mean + std;
if (highEnd > maxVal) highEnd = maxVal;
return 1000.0/highEnd;
}
示例#11
0
static boolean singleFilter(struct annoFilter *filter, char **row, int rowSize)
/* Apply one filter, using either filterFunc or type-based filter on column value.
 * Return TRUE if isExclude and filter passes, or if !isExclude and filter fails. */
{
boolean fail = FALSE;
if (filter->filterFunc != NULL)
    fail = filter->filterFunc(filter, row, rowSize);
else if (filter->op == afMatch)
    fail = !wildMatch((char *)(filter->values), row[filter->columnIx]);
else if (filter->op == afNotMatch)
    fail = wildMatch((char *)(filter->values), row[filter->columnIx]);
else
    {
    // column is a number -- integer or floating point?
    enum asTypes type = filter->type;
    if (asTypesIsFloating(type))
	fail = annoFilterDouble(filter, sqlDouble(row[filter->columnIx]));
    else if (asTypesIsInt(type))
	fail = annoFilterLongLong(filter, sqlLongLong(row[filter->columnIx]));
    else
	errAbort("annoFilterRowFails: unexpected enum asTypes %d for numeric filter op %d",
		 type, filter->op);
    }
if ((filter->isExclude && !fail) || (!filter->isExclude && fail))
    return TRUE;
return FALSE;
}
示例#12
0
void protFeatStaticLoad(char **row, struct protFeat *ret)
/* Load a row from protFeat table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{

ret->protein = row[0];
ret->start = sqlSigned(row[1]);
ret->end = sqlSigned(row[2]);
ret->feature = row[3];
ret->score = sqlDouble(row[4]);
}
struct autoTest *autoTestLoad(char **row)
/* Load a autoTest from row fetched with select * from autoTest
 * from database.  Dispose of this with autoTestFree(). */
{
struct autoTest *ret;

AllocVar(ret);
ret->ptCount = sqlSigned(row[5]);
ret->difCount = sqlSigned(row[7]);
ret->valCount = sqlSigned(row[10]);
ret->id = sqlUnsigned(row[0]);
safecpy(ret->shortName, sizeof(ret->shortName), row[1]);
ret->longName = cloneString(row[2]);
{
char *s = cloneString(row[3]);
sqlStringArray(s, ret->aliases, 3);
}
{
char *s = row[4];
if(s != NULL && differentString(s, ""))
   ret->threeD = pointCommaIn(&s, NULL);
}
{
int sizeOne;
sqlShortDynamicArray(row[6], &ret->pts, &sizeOne);
assert(sizeOne == ret->ptCount);
}
{
int sizeOne;
sqlUbyteDynamicArray(row[8], &ret->difs, &sizeOne);
assert(sizeOne == ret->difCount);
}
sqlSignedArray(row[9], ret->xy, 2);
{
int sizeOne;
sqlStringDynamicArray(row[11], &ret->vals, &sizeOne);
assert(sizeOne == ret->valCount);
}
ret->dblVal = sqlDouble(row[12]);
ret->fltVal = sqlFloat(row[13]);
{
int sizeOne;
sqlDoubleDynamicArray(row[14], &ret->dblArray, &sizeOne);
assert(sizeOne == ret->valCount);
}
{
int sizeOne;
sqlFloatDynamicArray(row[15], &ret->fltArray, &sizeOne);
assert(sizeOne == ret->valCount);
}
return ret;
}
示例#14
0
static void viewLimitsCompositeOverride(struct trackDb *tdb,char *name, double *retMin,
                                        double *retMax,double *absMin, double *absMax)
/* If aquiring min/max for composite level wig cfg. Look in parents as well as self. */
{
if (isNameAtParentLevel(tdb,name))
    {
    char *setting = NULL;
    if (absMin != NULL && absMax != NULL)
        {
        setting = trackDbSettingByView(tdb,MIN_LIMIT);
        if (setting != NULL)
            {
            if (setting[0] != '\0')
                *absMin = sqlDouble(setting);
            }
        setting = trackDbSettingByView(tdb,MAX_LIMIT);
        if (setting != NULL)
            {
            if (setting[0] != '\0')
                *absMax = sqlDouble(setting);
            }
        else
            {
            setting = trackDbSettingByView(tdb,VIEWLIMITSMAX);  // Legacy
            if (setting != NULL)
                {
                parseColonRange(setting, absMin, absMax);
                }
            }
        }

    setting = trackDbSettingByView(tdb, VIEWLIMITS);
    if (setting != NULL)
        {
        parseColonRange(setting, retMin, retMax);
        }
    }
}
示例#15
0
static struct rqlParse *rqlParseAtom(struct tokenizer *tkz)
/* Return low level (symbol or literal) */
{
char *tok = tokenizerMustHaveNext(tkz);
struct rqlParse *p;
AllocVar(p);
char c = tok[0];
if (c == '\'' || c == '"')
    {
    p->op = rqlOpLiteral;
    p->type = rqlTypeString;
    int len = strlen(tok+1);
    p->val.s = cloneStringZ(tok+1, len-1);
    }
else if (isalpha(c) || c == '_')
    {
    p->op = rqlOpSymbol;
    p->type = rqlTypeString;	/* String until promoted at least. */
    p->val.s = cloneString(tok);
    }
else if (isdigit(c))
    {
    p->op = rqlOpLiteral;
    p->type = rqlTypeInt;
    p->val.i = sqlUnsigned(tok);
    if ((tok = tokenizerNext(tkz)) != NULL)
	{
	if (tok[0] == '.')
	    {
	    char buf[32];
	    tok = tokenizerMustHaveNext(tkz);
	    safef(buf, sizeof(buf), "%d.%s", p->val.i, tok);
	    p->type = rqlTypeDouble;
	    p->val.x = sqlDouble(buf);
	    }
	else
	    tokenizerReuse(tkz);
	}
    }
else if (c == '(')
    {
    p = rqlParseExpression(tkz);
    skipOverRequired(tkz, ")");
    }
else
    {
    errAbort("Unexpected %s line %d of %s", tok, tkz->lf->lineIx, tkz->lf->fileName);
    }
return p;
}
示例#16
0
struct protFeat *protFeatLoad(char **row)
/* Load a protFeat from row fetched with select * from protFeat
 * from database.  Dispose of this with protFeatFree(). */
{
struct protFeat *ret;

AllocVar(ret);
ret->protein = cloneString(row[0]);
ret->start = sqlSigned(row[1]);
ret->end = sqlSigned(row[2]);
ret->feature = cloneString(row[3]);
ret->score = sqlDouble(row[4]);
return ret;
}
示例#17
0
static void parseColonRange(char *setting, double *retMin, double *retMax)
/* Parse setting's two colon-separated numbers into ret{Min,Max}, unless setting
 * is NULL or empty or retMin/retMax is NULL.  errAbort if invalid format. */
{
if (isNotEmpty(setting))
    {
    char tmp[64]; // Intentionally small -- should be only 2 floating point #s + ':'
    safecpy(tmp, sizeof(tmp), setting);
    char *words[3];
    if (chopByChar(tmp, ':', words, ArraySize(words)) == 2)
        {
	double low = sqlDouble(words[0]);
        double high = sqlDouble(words[1]);
        correctOrder(low, high);
	if (retMin)
	    *retMin = low;
	if (retMax)
	    *retMax = high;
        }
    else
	errAbort("Can't parse colon range '%s'", setting);
    }
}
示例#18
0
void doubleCellPrint(struct column *col, struct subjInfo *si,
        struct sqlConnection *conn)
/* print double value */
{
char *s = col->cellVal(col, si, conn);
char buf[256];
if (sameString(s,"."))  // known bad data value
    safef(buf,sizeof(buf),"%s", s);
else
    safef(buf,sizeof(buf),"%.1f",sqlDouble(s));
freeMem(s);
hPrintf("<TD align=right>");
hPrintf("%s", buf);
hPrintf("</TD>");
}
示例#19
0
void megablastInfoStaticLoad(char **row, struct megablastInfo *ret)
/* Load a row from megablastInfo table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{

    ret->chrom = row[0];
    ret->chromStart = sqlUnsigned(row[1]);
    ret->chromEnd = sqlUnsigned(row[2]);
    ret->name = row[3];
    ret->score = sqlUnsigned(row[4]);
    safecpy(ret->strand, sizeof(ret->strand), row[5]);
    ret->evalue = sqlDouble(row[6]);
    ret->percentident = sqlUnsigned(row[7]);
    ret->fullname = row[8];
    ret->taxid = sqlUnsigned(row[9]);
}
void cdsPickStaticLoad(char **row, struct cdsPick *ret)
/* Load a row from cdsPick table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{

ret->name = row[0];
ret->start = sqlSigned(row[1]);
ret->end = sqlSigned(row[2]);
ret->source = row[3];
ret->score = sqlDouble(row[4]);
ret->startComplete = sqlUnsigned(row[5]);
ret->endComplete = sqlUnsigned(row[6]);
ret->swissProt = row[7];
ret->uniProt = row[8];
ret->refProt = row[9];
ret->refSeq = row[10];
ret->ccds = row[11];
}
void aveNoQuartiles(char *fileName)
/* aveNoQuartiles - Compute only min,max,mean,stdDev no quartiles */
{
bits64 count = 0;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *words[128], *word;
int wordCount;
int wordIx = col-1;
double sumData = 0.0, sumSquares = 0.0;
double minVal = DBL_MAX, maxVal = -DBL_MAX;

while ((wordCount = lineFileChop(lf, words)) > 0)
    {
    word = words[wordIx];
    if (word[0] == '-' || isdigit(word[0]))
        {
	double val = sqlDouble(word);
	if (minVal > val) minVal = val;
	if (maxVal < val) maxVal = val;
	sumData += val;
	sumSquares += val * val;
	++count;
	}
    }
if (count == 0)
    errAbort("No numerical data column %d of %s", col, fileName);
double average = sumData/count;
double stdDev = calcStdFromSums(sumData, sumSquares, count);
if (tableOut)
    {
    printf("# min max mean N sum stddev\n");
    printf("%g %g %g %llu %g %g\n",
	minVal, maxVal, average, count, sumData, stdDev);
    }
else
    {
    printf("average %f\n", average);
    printf("min %f\n", minVal);
    printf("max %f\n", maxVal);
    printf("count %llu\n", count);
    printf("total %f\n", sumData);
    printf("standard deviation %f\n", stdDev);
    }
}
void txgGoodEdges(char *inTxg, char *inWeights, char *asciiThreshold,
                  char *outType, char *outEdges)
/* txgGoodEdges - Get edges that are above a certain threshold.. */
{
    struct txGraph *txgList = txGraphLoadAll(inTxg);
    verbose(2, "LOaded %d txGraphs from %s\n", slCount(txgList), inTxg);
    struct hash *weightHash = hashWeights(inWeights);
    verbose(2, "Loaded %d weights from %s\n", weightHash->elCount, inWeights);
    double threshold = sqlDouble(asciiThreshold);
    verbose(2, "Threshold %f\n", threshold);
    struct txGraph *txg;
    FILE *f = mustOpen(outEdges, "w");
    for (txg = txgList; txg != NULL; txg = txg->next)
    {
        verbose(2, "%s edgeCount %d\n", txg->name, txg->edgeCount);
        processOneGraph(txg, weightHash, threshold, outType, f);
    }
    carefulClose(&f);
}
示例#23
0
struct megablastInfo *megablastInfoLoad(char **row)
/* Load a megablastInfo from row fetched with select * from megablastInfo
 * from database.  Dispose of this with megablastInfoFree(). */
{
    struct megablastInfo *ret;

    AllocVar(ret);
    ret->chrom = cloneString(row[0]);
    ret->chromStart = sqlUnsigned(row[1]);
    ret->chromEnd = sqlUnsigned(row[2]);
    ret->name = cloneString(row[3]);
    ret->score = sqlUnsigned(row[4]);
    safecpy(ret->strand, sizeof(ret->strand), row[5]);
    ret->evalue = sqlDouble(row[6]);
    ret->percentident = sqlUnsigned(row[7]);
    ret->fullname = cloneString(row[8]);
    ret->taxid = sqlUnsigned(row[9]);
    return ret;
}
示例#24
0
struct subjInfo *getOrderedList(struct column *ord,
        struct column *colList, struct sqlConnection *conn,
        int maxCount)
/* Return sorted list of subjects. */
{
struct subjInfo *subjList = advFilterResults(colList, conn);
struct subjInfo *si;
passedFilterCount = slCount(subjList);

for (si=subjList;si;si=si->next)
    {
    char *s = ord->cellVal(ord, si, conn);
    if (sameString(ord->type,"integer"))
	{
	si->sortInteger = sqlSigned(s);
	freeMem(s);
	}
    else if (sameString(ord->type,"double"))
	{
	if (sameString(s,"."))
	    si->sortDouble = 0;
	else
	    si->sortDouble = sqlDouble(s);
	freeMem(s);
	}
    else
	{
	si->sortString = s;
	}
    }

slSort(&subjList, ord->sortCmp);

if (orderOn[0]=='-')
    slReverse(&subjList);

/* Trim list to max number. */
si = slElementFromIx(subjList, maxCount-1);
if (si != NULL)
    si->next = NULL;

return subjList;
}
示例#25
0
void bwtool_find_thresh(struct hash *options, char *favorites, char *regions, double fill,
			char *thresh_type, char *thresh_s, char *bigfile, char *tmp_dir, char *outputfile)
/* the other kind of finding, based on thresholding. */
{
    boolean inverse = (hashFindVal(options, "inverse") != NULL) ? TRUE : FALSE;
    enum bw_op_type op= get_bw_op_type(thresh_type, inverse);
    struct metaBig *mb = metaBigOpen_check(bigfile, tmp_dir, regions);
    double thresh = sqlDouble(thresh_s);
    FILE *out = mustOpen(outputfile, "w");
    struct bed out_bed;
    struct bed *section;
    for (section = mb->sections; section != NULL; section = section->next)
    {
	struct perBaseWig *pbwList = perBaseWigLoadContinue(mb, section->chrom, section->chromStart,
							      section->chromEnd);
	struct perBaseWig *pbw;
	int i, len;
	if (pbwList)
	{
	    out_bed.chrom = pbwList->chrom;
	    for (pbw = pbwList; pbw != NULL; pbw = pbw->next)
	    {
		i = 0;
		len = pbw->chromEnd - pbw->chromStart;
		out_bed.chromStart = out_bed.chromEnd = 0;
		while (i < len)
		{
		    while ((i < len) && (!fit_thresh(pbw->data[i], thresh, op)))
			i++;
		    out_bed.chromStart = i + pbw->chromStart;
		    while ((i < len) && (fit_thresh(pbw->data[i], thresh, op)))
			i++;
		    out_bed.chromEnd = i + pbw->chromStart;
		    if (out_bed.chromEnd > out_bed.chromStart)
			bedTabOutN(&out_bed, 3, out);
		}
	    }
	perBaseWigFree(&pbwList);
	}
    }
    metaBigClose(&mb);
    carefulClose(&out);
}
void txgTrim(char *inTxg, char *inWeights, char *asciiThreshold, char *outTxg)
/* txgTrim - Trim out parts of txGraph that are not of sufficient weight.. */
{
struct txGraph *txgList = txGraphLoadAll(inTxg);
verbose(2, "LOaded %d txGraphs from %s\n", slCount(txgList), inTxg);
struct hash *weightHash = hashWeights(inWeights);
verbose(2, "Loaded %d weights from %s\n", weightHash->elCount, inWeights);
double threshold = sqlDouble(asciiThreshold);
verbose(2, "Threshold %f\n", threshold);
struct txGraph *txg;
FILE *f = mustOpen(outTxg, "w");
for (txg = txgList; txg != NULL; txg = txg->next)
    {
    verbose(2, "%s edgeCount %d\n", txg->name, txg->edgeCount);
    txGraphTrimOne(txg, weightHash, threshold);
    if (txg->edgeCount > 0)
	txGraphTabOut(txg, f);
    }
carefulClose(&f);
}
示例#27
0
文件: wigToBed.c 项目: sktu/kentUtils
void wigToBed(char *inWig, char *thresholdString, char *outBed)
/* wigToBed - Convert wig to bed format using a threshold.  A primitive peak caller.. */
{
    double threshold = sqlDouble(thresholdString);
    uglyf("converting %s to %s at threshold %g\n", inWig, outBed, threshold);
    struct metaWig *mw = metaWigOpen(inWig);
    FILE *f = mustOpen(outBed, "w");

    struct slName *chrom, *chromList = metaWigChromList(mw);
    for (chrom = chromList; chrom != NULL; chrom = chrom->next)
    {
        verbose(2, "Processing %s\n", chrom->name);
        struct lm *lm = lmInit(0);
        struct bbiInterval *intervalList = metaIntervalsForChrom(mw, chrom->name, lm);
        outputIntervalsOverThreshold(chrom->name, intervalList, threshold, f);
        lmCleanup(&lm);
    }

    metaWigClose(&mw);
    carefulClose(&f);
}
struct cdsPick *cdsPickLoad(char **row)
/* Load a cdsPick from row fetched with select * from cdsPick
 * from database.  Dispose of this with cdsPickFree(). */
{
struct cdsPick *ret;

AllocVar(ret);
ret->name = cloneString(row[0]);
ret->start = sqlSigned(row[1]);
ret->end = sqlSigned(row[2]);
ret->source = cloneString(row[3]);
ret->score = sqlDouble(row[4]);
ret->startComplete = sqlUnsigned(row[5]);
ret->endComplete = sqlUnsigned(row[6]);
ret->swissProt = cloneString(row[7]);
ret->uniProt = cloneString(row[8]);
ret->refProt = cloneString(row[9]);
ret->refSeq = cloneString(row[10]);
ret->ccds = cloneString(row[11]);
return ret;
}
示例#29
0
void bedFileStats(char *bedFile, int colCount, FILE *f)
/* Collect stats on sizes of things in a bed file, and scores too. */
{
struct lineFile *lf = lineFileOpen(bedFile, TRUE);
struct slDouble *sizeList=NULL, *scoreList=NULL, *el;
char *row[colCount];
while (lineFileNextRow(lf, row, colCount))
    {
    int size = sqlUnsigned(row[endColIx]) - sqlUnsigned(row[startColIx]);
    el = slDoubleNew(size);
    slAddHead(&sizeList, el);
    double score = sqlDouble(row[scoreColIx]);
    el = slDoubleNew(score);
    slAddHead(&scoreList, el);
    }
fprintf(f, "%s\t%d\tsize:", bedFile, slCount(scoreList));
printStats(f, sizeList);
fprintf(f, "\tscore:");
printStats(f, scoreList);
fprintf(f, "\n");
lineFileClose(&lf);
}
示例#30
0
struct hash *hashGeneLevels(char *fileName, int cellCount)
/* Get a hash with key of gene name and value an array of expression values. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
struct hash *hash = hashNew(16);
int fieldCount = cellCount+1;
char *words[fieldCount+1];
int wordCount;
while ((wordCount = lineFileChop(lf, words)) != 0)
    {
    lineFileExpectWords(lf, fieldCount, wordCount);
    char *name = words[0];
    double *vals;
    AllocArray(vals, cellCount);
    int i;
    for (i=0; i<cellCount; ++i)
        vals[i] = sqlDouble(words[i+1]);
    hashAdd(hash, name, vals);
    }
lineFileClose(&lf);
return hash;
}