Esempio n. 1
0
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;
}
Esempio n. 2
0
int dyOutSize(int token)
// Returns the current length of the buffer starting at the level corresponding to token.
// Unlike other cases, the token does not have to correspond to the top of the stack!
{
struct dyString *dsTarget = dyOutPointerFromToken(token);
assert(dsTarget != NULL);

int len = dyStringLen(dsTarget);
struct dyString *ds = dyOutStack;
for (; ds != dsTarget && ds != NULL; ds = ds->next) // assertable != NULL, but still
    len += dyStringLen(ds);
return len;
}
Esempio n. 3
0
void addClusterMapItem(struct hacTree *ht, int x1, int y1, int x2, int y2, struct titleHelper *helper)
/* If using imageV2, add mouseover text (no link) with info about this cluster. */
{
if (theImgBox && curImgTrack)
    {
    struct dyString *dy = dyStringNew(0);
    struct hapCluster *c = (struct hapCluster *)ht->itemOrCluster;
    dyStringPrintf(dy, "N=%d ", c->leafCount);
    while (dyStringLen(dy) < 7)
	dyStringAppendC(dy, ' ');
    if (helper->startIx > 0)
	dyStringAppend(dy, "...");
    int i, nHapsForClustering = helper->endIx - helper->startIx;
    for (i=0;  i < nHapsForClustering;  i++)
	{
	boolean isCenter = (helper->startIx+i == helper->centerIx);
	char *allele = isRef(c, i) ? helper->refs[i] : helper->alts[i];
	if (isCenter)
	    dyStringAppendC(dy, '[');
	int altCount = c->leafCount - c->refCounts[i] - c->unkCounts[i];
	if (c->refCounts[i] > 0 && altCount > 0)
	    dyStringAppendC(dy, '*');
	else if (strlen(allele) == 1)
	    dyStringAppendC(dy, allele[0]);
	else
	    dyStringPrintf(dy, "(%s)", allele);
	if (isCenter)
	    dyStringAppendC(dy, ']');
	}
    if (helper->endIx < helper->nRecords)
	dyStringAppend(dy, "...");
    imgTrackAddMapItem(curImgTrack, TITLE_BUT_NO_LINK, dy->string,
		       x1, y1, x2, y2, helper->track);
    }
}
Esempio n. 4
0
static boolean mdbSelectsAddFoundComposites(struct slPair **pMdbSelects,struct trackDb *tdbsFound)
// Adds a composite mdbSelect (if found in tdbsFound) to the head of the pairs list.
// If tdbsFound is NULL, then add dummy composite search criteria
{
// create comma separated list of composites
struct dyString *dyComposites = dyStringNew(256);
struct trackDb *tdb = tdbsFound;
for (;tdb != NULL; tdb = tdb->next)
    {
    if (tdbIsComposite(tdb))
        dyStringPrintf(dyComposites,"%s,",tdb->track);
    else if (tdbIsCompositeChild(tdb))
        {
        struct trackDb *composite = tdbGetComposite(tdb);
        dyStringPrintf(dyComposites,"%s,",composite->track);
        }
    }
if (dyStringLen(dyComposites) > 0)
    {
    char *composites = dyStringCannibalize(&dyComposites);
    composites[strlen(composites) - 1] = '\0';  // drop the last ','
    slPairAdd(pMdbSelects,MDB_VAR_COMPOSITE,composites); 
    // Composite should not already be in the list, because it is only indirectly sortable
    return TRUE;
    }

//warn("No composites found");
dyStringFree(&dyComposites);
return FALSE;
}
Esempio n. 5
0
int dsPrintEmpty(int token)
// Empties the top buffer in stack (abandoning content), but leave buffer in place
// Returns the length abandoned.
{
    dsAssertToken(token);
    int len = dyStringLen(dsStack);
    dyStringClear(dsStack);
    return len;
}
Esempio n. 6
0
int dsPrintClose(int token)
// Abandons the top buffer and its content, freeing memory.
// Returns the length abandoned.
{
    dsAssertToken(token);
    int len = dyStringLen(dsStack);
    struct dyString *ds = slPopHead(&dsStack);
    dyStringFree(&ds);
    return len;
}
Esempio n. 7
0
int dsPrintSize(int token)
// Returns the curent length of the buffer starting at the level corresponding to token.
// Unlike other cases, the token does not have to correspond to the top of the stack!
{
//dsAssertToken(token);
//return dyStringLen(dsStack);
    int ix = dsPrintStackIxFromToken(token);
    assert(ix >= 0);

    int len = 0;
    struct dyString *ds = NULL;
    for (; ix>0; ix--)
    {
        ds = dsPrintStackMemberFromIx(ix);
        assert(ds != NULL);
        len += dyStringLen(ds);
    }
    len += dyStringLen(dsStack);
    return len;
}
static void cartJsonPrintWarnings(struct jsonWrite *jw)
/* If there are warnings, write them out as JSON: */
{
if (dyWarn && dyStringLen(dyWarn) > 0)
    {
    //#*** TODO: move jsonStringEscape inside jsonWriteString
    char *encoded = jsonStringEscape(dyWarn->string);
    jsonWriteString(jw, "warning", encoded);
    freeMem(encoded);
    }
}
Esempio n. 9
0
int dsPrintSizeAll()
// returns combined current size of all buffers
{
    int len = 0;
    if (dsStack != NULL)
    {
        struct dyString *ds = dsStack;
        for (; ds != NULL; ds = ds->next)
            len += dyStringLen(ds);
    }
    return len;
}
Esempio n. 10
0
static void gtfGroupToGenePred(struct gffFile *gtf, struct gffGroup *group, FILE *gpFh,
                               FILE *infoFh)
/* convert one gtf group to a genePred */
{
unsigned optFields = (clGenePredExt ? genePredAllFlds : 0);
struct errCatch *errCatch = errCatchNew();

if (errCatchStart(errCatch))
    {
    struct genePred *gp = genePredFromGroupedGtf(gtf, group, group->name, optFields, clGxfOptions);
    if (gp == NULL)
        {
        if (!clIgnoreGroupsWithoutExons)
            {
            char *msg = "no exons defined for group %s, feature %s (perhaps try -ignoreGroupsWithoutExons)";
            if (clAllErrors)
                {
                fprintf(stderr, msg, group->name, group->lineList->feature);
                fputc('\n', stderr);
                badGroupCount++;
                }
            else
                errAbort(msg, group->name, group->lineList->feature);
            }
        }
    else
        {
        genePredTabOut(gp, gpFh);
        genePredFree(&gp);
        }
    }
errCatchEnd(errCatch);
if (errCatch->gotError)
    {
    // drop trailing newline in caught message
    if (endsWith(errCatch->message->string, "\n"))
        dyStringResize(errCatch->message, dyStringLen(errCatch->message)-1);
    if (clAllErrors)
        {
        fprintf(stderr, "%s\n", errCatch->message->string);
        badGroupCount++;
        }
    else
        errAbort("%s", errCatch->message->string);
    }
else
    {
    if (infoFh != NULL)
        writeInfo(infoFh, group);
    }
errCatchFree(&errCatch); 
}
Esempio n. 11
0
int dsPrintDirectly(int token,FILE *file)
// Prints the contents of the top buffer directly to a file.
// Will leave the filled buffer at top of stack
// Returns the length printed.
{
    dsAssertToken(token);

    int len = dyStringLen(dsStack);
    if (len != 0)
        fprintf(file,"%s",dyStringContents(dsStack));
    fflush(file);
    return len;
}
Esempio n. 12
0
int dsPrintf(char *format, ...)
// Prints into end of the top ds buffer, and return resulting string length
// If there is no current buffer, this acts like a simple printf and returns -1
{
    int len = -1; // caller could assert returned length > 0 to ensure dsPrint is open!
    va_list args;
    va_start(args, format);
    if (dsStack != NULL)
    {
        dyStringVaPrintf(dsStack, format, args);
        len = dyStringLen(dsStack);
    }
    else
    {
        dsInitializeOut()
        vfprintf(dsOut,format, args);
    }
    va_end(args);
    return len;
}
Esempio n. 13
0
int dsPrintFlush(int token)
// Flushes the top buffer to the next lower one and empties top buffer.
// If there is no lower buffer then the content is printed to STDOUT (or registered out).
// Returns the length flushed.
{
    dsAssertToken(token);

    int len = dyStringLen(dsStack);
    if (len != 0)
    {
        if (dsStack->next == NULL)
        {
            dsInitializeOut();
            fprintf(dsOut,"%s",dyStringContents(dsStack));
            fflush(dsOut);
        }
        else
            dyStringAppend(dsStack->next,dyStringContents(dsStack));
        dyStringClear(dsStack);
    }
    return len;
}
Esempio n. 14
0
boolean lineFileNextFull(struct lineFile *lf, char **retFull, int *retFullSize,
                        char **retRaw, int *retRawSize)
// Fetch next line from file joining up any that are continued by ending '\'
// If requested, and was joined, the unjoined raw lines are also returned
// NOTE: comment lines can't be continued!  ("# comment \ \n more comment" is 2 lines.)
{
// May have requested reusing the last full line.
if (lf->fullLineReuse)
    {
    lf->fullLineReuse = FALSE;
    assert(lf->fullLine != NULL);
    *retFull = dyStringContents(lf->fullLine);
    if (retFullSize)
        *retFullSize = dyStringLen(lf->fullLine);
    if (retRaw != NULL)
        {
        assert(lf->rawLines != NULL);
        *retRaw = dyStringContents(lf->rawLines);
        if (retRawSize)
            *retRawSize = dyStringLen(lf->rawLines);
        }
    return TRUE;
    }

// Empty pointers
*retFull = NULL;
if (retRaw != NULL)
    *retRaw = NULL;

// Prepare lf buffers
if (lf->fullLine == NULL)
    {
    lf->fullLine = dyStringNew(1024);
    lf->rawLines = dyStringNew(1024); // Better to always create it than test every time
    }
else
    {
    dyStringClear(lf->fullLine);
    dyStringClear(lf->rawLines);
    }

char *line;
while (lineFileNext(lf, &line, NULL))
    {
    char *start = skipLeadingSpaces(line);

    // Will the next line continue this one?
    char *end = start;
    if (*start == '#')  // Comment lines can't be continued!
        end = start + strlen(start);
    else
        {
        while (*end != '\0')  // walking forward for efficiency (avoid strlens())
            {
            for (;*end != '\0' && *end != '\\'; end++) ; // Tight loop to find '\'
            if (*end == '\0')
                break;

            // This could be a continuation
            char *slash = end;
            if (*(++end) == '\\')  // escaped
                continue;
            end = skipLeadingSpaces(end);

            if (*end == '\0') // Just whitespace after '\', so true continuation mark
                {
                if (retRaw != NULL) // Only if actually requested.
                    {
                    dyStringAppendN(lf->rawLines,line,(end - line));
                    dyStringAppendC(lf->rawLines,'\n'); // New lines delimit raw lines.
                    }
                end = slash; // Don't need to zero, because of appending by length
                break;
                }
            }
        }

    // Stitch together full lines
    if (dyStringLen(lf->fullLine) == 0)
        dyStringAppendN(lf->fullLine,line,(end - line)); // includes first line's whitespace
    else if (start < end)             // don't include continued line's leading spaces
        dyStringAppendN(lf->fullLine,start,(end - start));

    if (*end == '\\')
        continue;

    // Got a full line now!
    *retFull = dyStringContents(lf->fullLine);
    if (retFullSize)
        *retFullSize = dyStringLen(lf->fullLine);

    if (retRaw != NULL && dyStringLen(lf->rawLines) > 0) // Only if actually requested & continued
        {
        // This is the final line which doesn't have a continuation char
        dyStringAppendN(lf->rawLines,line,(end - line));
        *retRaw = dyStringContents(lf->rawLines);
        if (retRawSize)
            *retRawSize = dyStringLen(lf->rawLines);
        }
    return TRUE;
    }
return FALSE;
}