void writeTab(struct hash *stageHash, struct hash *seqHash, 
	char *sourceImageDir, char *parsedTab, 
	struct hash *nameHash, char *outName)
/* Synthasize data and write out tab-separated file with one line for
 * each image. */
{
char sourceImage[PATH_LEN];
FILE *f = mustOpen(outName, "w");
struct lineFile *lf = lineFileOpen(parsedTab, TRUE);
char *row[6];

/* Write header. */
fprintf(f, "#");
fprintf(f, "gene\t");
fprintf(f, "submitId\t");
fprintf(f, "fileName\t");
fprintf(f, "imageWidth\t");
fprintf(f, "imageHeight\t");
fprintf(f, "bodyPart\t");
fprintf(f, "age\t");
fprintf(f, "minAge\t");
fprintf(f, "maxAge\t");
fprintf(f, "seq\n");

while (lineFileRowTab(lf, row))
    {
    char *clone = row[0];
    char *stage = row[1];
    char *part = row[2];
    char *dir = row[3];
    char *subdir = row[4];
    char *file = row[5];
    char *gene = hashFindVal(nameHash, clone);
    struct dnaSeq *seq = hashFindVal(seqHash, clone);
    int width, height;

    safef(sourceImage, sizeof(sourceImage), "%s/%s/%s/%s",
    	sourceImageDir, dir, subdir, file);
    jpegSize(sourceImage, &width, &height);

    if (gene == NULL)
        gene = clone;
    fprintf(f, "%s\t", gene);
    fprintf(f, "%s\t", clone);
    fprintf(f, "%s/%s\t", subdir, file);
    fprintf(f, "%d\t", width);
    fprintf(f, "%d\t", height);
    fprintf(f, "%s\t", part);
    if (sameString(stage, "mixed"))
	fprintf(f, "1\t0\t3\t");
    else
	{
	char *age = hashMustFindVal(stageHash, stage);
	fprintf(f, "%s\t", age);
	fprintf(f, "%s\t", age);
	fprintf(f, "%s\t", age);
	}
    if (seq != NULL)
	fprintf(f, "%s\n", seq->dna);
    else
        fprintf(f, "\n");
    }

carefulClose(&f);
}
void doUserCommits(char *u, struct commit *commits, int *saveUlc, int *saveUfc)
/* process one user, commit-view */
{


char userPath[1024];
safef(userPath, sizeof(userPath), "%s/%s/%s/%s/index.html", outDir, outPrefix, "user", u);

FILE *h = mustOpen(userPath, "w");
fprintf(h, "<html>\n<head>\n<title>Commits for %s</title>\n</head>\n</body>\n", u);
fprintf(h, "<h1>Commits for %s</h1>\n", u);

fprintf(h, "switch to <A href=\"index-by-file.html\">files view</A>, <A href=\"../index.html\">user index</A>\n");
fprintf(h, "<h3>%s to %s (%s to %s) %s</h3>\n", startTag, endTag, startDate, endDate, title);

fprintf(h, "<ul>\n");


int userLinesChanged = 0;
int userFileCount = 0;

char *cDiff = NULL, *cHtml = NULL, *fDiff = NULL, *fHtml = NULL;
char *relativePath = NULL;
char *commonPath = NULL;

struct commit *c = NULL;
struct files *f = NULL;
for(c = commits; c; c = c->next)
    {
    if (sameString(c->author, u))
	{
	//fprintf(h, "%s\n", c->commitId);
	//fprintf(h, "%s\n", c->date);

	char *cc = htmlEncode(c->comment);
	char *ccc = replaceChars(cc, "\n", "<br>\n");
	fprintf(h, "<li>%s\n", ccc);
	freeMem(cc);
	freeMem(ccc);

	makeDiffAndSplit(c, u, FALSE);
	makeDiffAndSplit(c, u, TRUE);
	for(f = c->files; f; f = f->next)
	    {
	    char path[1024];

            // context unified
	    safef(path, sizeof(path), "%s/%s%s", "context", f->path, c->commitId);
	    relativePath = cloneString(path);

	    safef(path, sizeof(path), "%s/%s/%s/%s/%s", outDir, outPrefix, "user", u, relativePath);
	    commonPath = cloneString(path);

	    safef(path, sizeof(path), "%s.html", commonPath);
	    cHtml = cloneString(path);

	    safef(path, sizeof(path), "%s.diff", commonPath);
	    cDiff = cloneString(path);

	    // make context html page
	    f->linesChanged = makeHtml(cDiff, cHtml, f->path, c->commitId);

	    userLinesChanged += f->linesChanged;
	    ++userFileCount;

	    freeMem(cDiff);
	    freeMem(cHtml);
	    safef(path, sizeof(path), "%s.html", relativePath);
	    cHtml = cloneString(path);
	    safef(path, sizeof(path), "%s.diff", relativePath);
	    cDiff = cloneString(path);



            // full text (up to 10,000 lines)
	    freeMem(relativePath);
	    safef(path, sizeof(path), "%s/%s%s", "full", f->path, c->commitId);
	    relativePath = cloneString(path);

	    safef(path, sizeof(path), "%s/%s/%s/%s/%s", outDir, outPrefix, "user", u, relativePath);
	    freeMem(commonPath);
	    commonPath = cloneString(path);

	    safef(path, sizeof(path), "%s.html", commonPath);
	    fHtml = cloneString(path);

	    safef(path, sizeof(path), "%s.diff", commonPath);
	    fDiff = cloneString(path);


	    //git show --unified=10000 11a20b6cd113d75d84549eb642b7f2ac7a2594fe src/utils/qa/weeklybld/buildEnv.csh

	    // make full html page
	    makeHtml(fDiff, fHtml, f->path, c->commitId);

	    freeMem(fDiff);
	    freeMem(fHtml);
	    safef(path, sizeof(path), "%s.html", relativePath);
	    fHtml = cloneString(path);
	    safef(path, sizeof(path), "%s.diff", relativePath);
	    fDiff = cloneString(path);

	    // make file diff links
	    fprintf(h, "<ul><li> %s - lines changed %d, "
		"context: <A href=\"%s\">html</A>, <A href=\"%s\">text</A>, "
		"full: <A href=\"%s\">html</A>, <A href=\"%s\">text</A></li></ul>\n"
		, f->path, f->linesChanged
		, cHtml, cDiff, fHtml, fDiff);

	    freeMem(relativePath);
	    freeMem(commonPath);
	    freeMem(cDiff);
	    freeMem(cHtml);
	    freeMem(fDiff);
	    freeMem(fHtml);

	    }
	fprintf(h, "</li>\n");
	}
    }
fprintf(h, "</ul>\n");
fprintf(h, "switch to <A href=\"index-by-file.html\">files view</A>, <A href=\"../index.html\">user index</A>\n");
fprintf(h, "</body>\n</html>\n");
fclose(h);
*saveUlc = userLinesChanged;
*saveUfc = userFileCount;
}
Exemple #3
0
static void webStartWrapperDetailedInternal(struct cart *theCart,
	char *db, char *headerText, char *textOutBuf,
	boolean withHttpHeader, boolean withLogo, boolean skipSectionHeader,
	boolean withHtmlHeader)
/* output a CGI and HTML header with the given title in printf format */
{
char uiState[256];
char *scriptName = cgiScriptName();
boolean isEncode = FALSE;
if (theCart)
    {
    char *theGenome = NULL;
    char *genomeEnc = NULL;

    getDbAndGenome(theCart, &db, &theGenome, NULL);
    genomeEnc = cgiEncode(theGenome);

    safef(uiState, sizeof(uiState), "?%s=%s&%s=%s&%s=%u",
	     orgCgiName, genomeEnc,
	     dbCgiName, db,
	     cartSessionVarName(), cartSessionId(theCart));
    }
else
    {
    uiState[0] = 0;
    uiState[1] = 0;
    }
if (db == NULL)
    db = hDefaultDb();
boolean dbIsFound = hDbExists(db);
boolean haveBlat = FALSE;
if (dbIsFound)
    haveBlat = hIsBlatIndexedDatabase(db);

if (scriptName == NULL)
    scriptName = cloneString("");
/* don't output two headers */
if(webHeadAlreadyOutputed)
    return;

if (sameString(cgiUsualString("action",""),"encodeReleaseLog") ||
    rStringIn("EncodeDataVersions", scriptName))
        isEncode = TRUE;

/* Preamble. */
dnaUtilOpen();

if (withHttpHeader)
    puts("Content-type:text/html\n");

if (withHtmlHeader)
    {
    char *newString, *ptr1, *ptr2;

    char *browserVersion;
    if (btIE == cgiClientBrowser(&browserVersion, NULL, NULL) && *browserVersion < '8')
        puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">");
    else
        puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
             "\"http://www.w3.org/TR/html4/loose.dtd\">");
    // Strict would be nice since it fixes atleast one IE problem (use of :hover CSS pseudoclass)
    puts(
	"<HTML>" "\n"
	"<HEAD>" "\n"
	);
    printf("\t%s\n", headerText);
    printf("\t<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;CHARSET=iso-8859-1\">" "\n"
	 "\t<META http-equiv=\"Content-Script-Type\" content=\"text/javascript\">" "\n"
         "\t<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" "\n"
         "\t<META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\">" "\n"
	 "\t<TITLE>"
	 );
    /* we need to take any HTML formatting out of the titlebar string */
    newString = cloneString(textOutBuf);

    for(ptr1=newString, ptr2=textOutBuf; *ptr2 ; ptr2++)
	{
	if (*ptr2 == '<')
	    {
	    for(; *ptr2 && (*ptr2 != '>'); ptr2++)
		;
	    }
	else
	    *ptr1++ = *ptr2;
	}
    *ptr1 = 0;
    htmlTextOut(newString);
    printf("	</TITLE>\n    ");
    webIncludeResourceFile("HGStyle.css");
    if (extraStyle != NULL)
        puts(extraStyle);
    printf("</HEAD>\n");
    printBodyTag(stdout);
    htmlWarnBoxSetup(stdout);// Sets up a warning box which can be filled with errors as they occur
    puts(commonCssStyles());
    }
puts(
    "<A NAME=\"TOP\"></A>" "\n"
    "" "\n"
    "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%\">" "\n");

if (withLogo)
    {
    puts("<TR><TH COLSPAN=1 ALIGN=\"left\">");
    if (isEncode)
	{
	puts("<A HREF=\"http://www.genome.gov/10005107\" TARGET=\"_BLANK\">"
	     "<IMG SRC=\"../images/ENCODE_scaleup_logo.png\" height=50 ALT=\"ENCODE Project at NHGRI\">"
	     "</A>");
	puts("<IMG SRC=\"../images/encodeDcc.jpg\" ALT=\"ENCODE Project at UCSC\">");
	}
    else
	{
	puts("<IMG SRC=\"../images/title.jpg\">");
	}
    puts("</TH></TR>" "\n"
         "" "\n" );
    }

/* Put up the hot links bar. */

char *menuStr = menuBar(theCart);
if(menuStr)
    {
    puts(menuStr);
    }

if (endsWith(scriptName, "hgGateway") && geoMirrorEnabled())
    {
    // Show an opt-out alert if user is on a host to which user has been automatically redirected (just once, right after they have been redirected)
    char *source = cgiOptionalString("source");
    char *redirect = cgiOptionalString("redirect");
    if (source != NULL && redirect != NULL && sameString(redirect, "auto"))
	{
	char *domain = cgiServerName();
	char *port = cgiServerPort();
        // We don't bother maintaining stuff in request URI, because it may contain items like hgsid and other host specific values
        int newUriSize = 2048;
	char *newUri = needMem(newUriSize);
	safef(newUri, newUriSize, "http%s://%s:%s/cgi-bin/hgGateway?redirect=manual&source=%s", 
	    cgiServerHttpsIsOn() ? "s" : "", source, port, domain);

	printf("<TR><TD COLSPAN=3 id='redirectTd' onclick=\"javascript:document.getElementById('redirectTd').innerHTML='';\">"
	    "<div style=\"margin: 10px 25%%; border-style:solid; border-width:thin; border-color:#97D897;\">"
	    "<h3 style=\"background-color: #97D897; text-align: left; margin-top:0px; margin-bottom:0px;\">"
	    "&nbsp;You've been redirected to your nearest mirror - %s"
	    "<idiv style=\"float:right;\">[x]</idiv>"
	    "</h3> "
	    "<ul style=\"margin:5px;\">"
	    "<li>Take me back to <a href=\"%s\">%s</a>"
	    "<idiv style=\"float:right;\"><a href=\"../goldenPath/help/genomeEuro.html\">What is this?</a></idiv>"
	    "</li>"
	    "</ul>"
	    "</div>"
	    "</TD></TR>\n"
	    , domain, newUri, source );
	}
    }

if(!skipSectionHeader)
/* this HTML must be in calling code if skipSectionHeader is TRUE */
    {
    puts( // TODO: Replace nested tables with CSS (difficulty is that tables are closed elsewhere)
         "<!-- +++++++++++++++++++++ CONTENT TABLES +++++++++++++++++++ -->" "\n"
         "<TR><TD COLSPAN=3>\n"
         "<div id=firstSection>"
         "      <!--outer table is for border purposes-->\n"
         "      <TABLE WIDTH='100%' BGCOLOR='#" HG_COL_BORDER "' BORDER='0' CELLSPACING='0' "
                     "CELLPADDING='1'><TR><TD>\n"
         "    <TABLE BGCOLOR='#" HG_COL_INSIDE "' WIDTH='100%'  BORDER='0' CELLSPACING='0' "
                     "CELLPADDING='0'><TR><TD>\n"
         "     <div class='subheadingBar'><div class='windowSize' id='sectTtl'>"
         );
    htmlTextOut(textOutBuf);

    puts("     </div></div>\n"
         "     <TABLE BGCOLOR='#" HG_COL_INSIDE "' WIDTH='100%' CELLPADDING=0>"
              "<TR><TH HEIGHT=10></TH></TR>\n"
         "     <TR><TD WIDTH=10>&nbsp;</TD><TD>\n\n"
         );
    };
webPushErrHandlers();
/* set the flag */
webHeadAlreadyOutputed = TRUE;
}	/*	static void webStartWrapperDetailedInternal()	*/
Exemple #4
0
static void parseSteppedSection(struct lineFile *lf, boolean clipDontDie, 
	struct hash *chromSizeHash, char *initialLine, 
	struct lm *lm, int itemsPerSlot, struct bwgSection **pSectionList)
/* Parse out a variableStep or fixedStep section and add it to list, breaking it up as need be. */
{
/* Parse out first word of initial line and make sure it is something we recognize. */
char *typeWord = nextWord(&initialLine);
enum bwgSectionType type = bwgTypeFixedStep;
if (sameString(typeWord, "variableStep"))
    type = bwgTypeVariableStep;
else if (sameString(typeWord, "fixedStep"))
    type = bwgTypeFixedStep;
else
    errAbort("Unknown type %s\n", typeWord);

/* Set up defaults for values we hope to parse out of rest of line. */
int span = 0;
bits32 step = 0;
bits32 start = 0;
char *chrom = NULL;

/* Parse out var=val pairs. */
char *varEqVal;
while ((varEqVal = nextWord(&initialLine)) != NULL)
    {
    char *wordPairs[2];
    int wc = chopByChar(varEqVal, '=', wordPairs, 2);
    if (wc != 2)
        errAbort("strange var=val pair line %d of %s", lf->lineIx, lf->fileName);
    char *var = wordPairs[0];
    char *val = wordPairs[1];
    if (sameString(var, "chrom"))
        chrom = cloneString(val);
    else if (sameString(var, "span"))
	span = parseUnsignedVal(lf, var, val);
    else if (sameString(var, "step"))
	step = parseUnsignedVal(lf, var, val);
    else if (sameString(var, "start"))
	{
        start = parseUnsignedVal(lf, var, val);
	}
    else
	errAbort("Unknown setting %s=%s line %d of %s", var, val, lf->lineIx, lf->fileName);
    }

/* Check that we have all that are required and no more, and call type-specific routine to parse
 * rest of section. */
if (chrom == NULL)
    errAbort("Missing chrom= setting line %d of %s\n", lf->lineIx, lf->fileName);
bits32 chromSize = (chromSizeHash ? hashIntVal(chromSizeHash, chrom) : BIGNUM);
if (start > chromSize)
    {
    warn("line %d of %s: chromosome %s has %u bases, but item starts at %u",
    	lf->lineIx, lf->fileName, chrom, chromSize, start);
    if (!clipDontDie)
        noWarnAbort();
    }
if (type == bwgTypeFixedStep)
    {
    if (start == 0)
	errAbort("Missing start= setting line %d of %s\n", lf->lineIx, lf->fileName);
    if (step == 0)
	errAbort("Missing step= setting line %d of %s\n", lf->lineIx, lf->fileName);
    if (span == 0)
	span = step;
    parseFixedStepSection(lf, clipDontDie, lm, itemsPerSlot, 
    	chrom, chromSize, span, start-1, step, pSectionList);
    }
else
    {
    if (start != 0)
	errAbort("Extra start= setting line %d of %s\n", lf->lineIx, lf->fileName);
    if (step != 0)
	errAbort("Extra step= setting line %d of %s\n", lf->lineIx, lf->fileName);
    if (span == 0)
	span = 1;
    parseVariableStepSection(lf, clipDontDie, lm, itemsPerSlot, 
    	chrom, chromSize, span, pSectionList);
    }
}
struct commit* getCommits()
/* Get all commits from startTag to endTag */
{
int numCommits = 0;
safef(gitCmd,sizeof(gitCmd), ""
"git log %s..%s --name-status > commits.tmp"
, startTag, endTag);
runShell(gitCmd);
struct lineFile *lf = lineFileOpen("commits.tmp", TRUE);
int lineSize;
char *line;
struct commit *commits = NULL, *commit = NULL;
struct files *files = NULL, *f = NULL;
char *sep = "";
while (lineFileNext(lf, &line, &lineSize))
    {
    boolean isMerge = FALSE;
    char *w = nextWord(&line);
    AllocVar(commit);
    if (!sameString("commit", w))
	errAbort("expected keyword commit parsing commits.tmp\n");
    commit->commitId = cloneString(nextWord(&line));
    commit->commitNumber = ++numCommits;

    lineFileNext(lf, &line, &lineSize);
    w = nextWord(&line);
    if (sameString("Merge:", w))
	{
	isMerge = TRUE;
	lineFileNext(lf, &line, &lineSize);
	w = nextWord(&line);
	}
    if (!sameString("Author:", w))
	errAbort("expected keyword Author: parsing commits.tmp\n");

    /* by request, keep just the email account name */
    char *lc = strchr(line, '<');
    if (!lc)
	errAbort("expected '<' char in email address in Author: parsing commits.tmp\n");
    ++lc;
    char *rc = strchr(lc, '>');
    if (!rc)
	errAbort("expected '>' char in email address in Author: parsing commits.tmp\n");
    char *ac = strchr(lc, '@');
    if (ac)
	rc = ac;
    commit->author = cloneStringZ(lc, rc-lc);

    lineFileNext(lf, &line, &lineSize);
    w = nextWord(&line);
    if (!sameString("Date:", w))
	errAbort("expected keyword Date: parsing commits.tmp\n");
    commit->date = cloneString(line);

    lineFileNext(lf, &line, &lineSize);
    if (!sameString("", line))
	errAbort("expected blank line parsing commits.tmp\n");

    /* collect the comment-lines */
    struct dyString *dy = NULL;
    dy = dyStringNew(0);
    sep = "";
    files = NULL;
    while (lineFileNext(lf, &line, &lineSize))
	{
	if (sameString("", line))
	    break;
	w = skipLeadingSpaces(line);
	dyStringPrintf(dy, "%s%s", w, sep);
	sep = "\n";
	}
    commit->comment = cloneString(dy->string);
    freeDyString(&dy);

    if (!isMerge)
	{
	/* collect the files-list */
	while (lineFileNext(lf, &line, &lineSize))
	    {
	    if (sameString("", line))
		break;
	    AllocVar(f);
	    w = nextWord(&line);
	    f->type = w[0];
	    f->path = cloneString(line);
	    slAddHead(&files, f);
	    }
	slReverse(&files);
	}

    commit->files = files;

    
    if (!isMerge  /* for now, default to filtering out the records for automatic-merges */
        && !endsWith(commit->comment, "elease log update"))  /* filter out automatic release log commits */
	slAddHead(&commits, commit);

    verbose(2, 
 "commitId: %s\n"
 "author: %s\n"
 "date: %s\n"
 "comment: [%s]\n"
 "file(s): \n"
, commit->commitId
, commit->author
, commit->date
, commit->comment);

    for (f=commit->files; f; f = f->next)
	{
    	verbose(2, "%c %s\n", f->type, f->path);

	// anything other than M or A?
	if (f->type != 'M' && f->type != 'A' )
	    verbose(2, "special type: %c %s\n", f->type, f->path);
	}


    verbose(2, "------------\n");

    }
lineFileClose(&lf);
/* We want to keep them chronological order,
so do not need slReverse since the addHead reversed git log's rev chron order already */


unlink("commits.tmp");
return commits;
}
boolean subtrackMergeIsBpWise()
/* Return TRUE if the subtrack merge operation is base pair-wise. */
{
char *op = cartUsualString(cart, hgtaSubtrackMergeOp, "any");
return (sameString(op, "and") || sameString(op, "or"));
}
Exemple #7
0
void fixLine(struct lineFile *lf, char *line, FILE *f)
/* Fix up a single line. */
{
char *group;            /* Last. */
char *words[8];		/* First words. */
int i;
char fixStart[16], fixEnd[16];
char *type, *strand;

/* Pass through comments. */
if (line[0] == '#')
    {
    fprintf(f, "%s\n", line);
    return;
    }

/* Find the start of the "group" field. */
group = line;
for (i=0; i<8; ++i)
    {
    group = skipToSpaces(group);
    if (group == NULL)
       errAbort("Expecting at least 9 fields line %d of %s\n", lf->lineIx, lf->fileName);
    group = skipLeadingSpaces(group);
    }

/* Truncate initial string before group field and chop it up. */
group[-1] = 0;
chopLine(line, words);

#ifdef FLAKY    /* This doesn't fix all problems, we'll just ignore start/stop_codons. */
/* Fix up start and stop codons. */
type = words[2];
strand = words[6];
if (sameString(type, "start_codon") && sameString(strand, "-"))
    {
    sprintf(fixStart, "%d", atoi(words[3])-3);
    sprintf(fixEnd, "%d", atoi(words[4])-3);
    words[3] = fixStart;
    words[4] = fixEnd;
    }
else if (sameString(type, "stop_codon"))
    {
    /* Start and end reversed on both strands. */
    int start = atoi(words[4]);
    int end = atoi(words[3]);
    if (sameString(strand, "-"))
        {
	start += 3;
	end += 3;
	}
    sprintf(fixStart, "%d", start);
    sprintf(fixEnd, "%d", end);
    words[3] = fixStart;
    words[4] = fixEnd;
    }
#endif /* FLAKY */

/* Skip start/stop codons.  Code will then assume all exons are CDS. */
type = words[2];
if (sameString(type, "start_codon") || sameString(type, "stop_codon"))
    return;

/* Write fixed output. */
for (i=0; i<8; ++i)
    fprintf(f, "%s\t", words[i]);
fprintf(f, "%s\n", group);
}
void initGapAid(char *gapFileName)
/* Initialize gap aid structure for faster gap
 * computations. */
{
int i, tableSize, startLong = -1;
char *sizeDesc[2];
char *words[128];

if (gapFileName != NULL)
    {
    struct lineFile *lf = lineFileOpen(gapFileName, TRUE);
    int count;

    lineFileNextRowTab(lf, sizeDesc, 2);
    tableSize = atoi(sizeDesc[1]);
    AllocArray(gapInitPos,tableSize);
    AllocArray(gapInitQGap,tableSize);
    AllocArray(gapInitTGap,tableSize);
    AllocArray(gapInitBothGap,tableSize);
    while (count = lineFileChopNext(lf, words, tableSize+1))
        {
        if (sameString(words[0],"smallSize"))
            {
            aid.smallSize = atoi(words[1]);
            }
        if (sameString(words[0],"position"))
            {
            for (i=0 ; i<count-1 ; i++)
                gapInitPos[i] = atoi(words[i+1]);
            }
        if (sameString(words[0],"qGap"))
            {
            for (i=0 ; i<count-1 ; i++)
                gapInitQGap[i] = atoi(words[i+1]);
            }
        if (sameString(words[0],"tGap"))
            {
            for (i=0 ; i<count-1 ; i++)
                gapInitTGap[i] = atoi(words[i+1]);
            }
        if (sameString(words[0],"bothGap"))
            {
            for (i=0 ; i<count-1 ; i++)
                gapInitBothGap[i] = atoi(words[i+1]);
            }
            
        }
    if (aid.smallSize == 0)
        errAbort("missing smallSize parameter in %s\n",gapFileName);
    lineFileClose(&lf);
    }
else
    {
    /* if no gap file, then setup default values */ 
    /* Set up to handle small values */
    aid.smallSize = 111;
    tableSize = 11;
    AllocArray(gapInitPos,tableSize);
    AllocArray(gapInitQGap,tableSize);
    AllocArray(gapInitTGap,tableSize);
    AllocArray(gapInitBothGap,tableSize);
    for (i = 0 ; i < tableSize ; i++)
        {
        gapInitPos[i] = gapInitPosDefault[i];
        gapInitTGap[i] = gapInitTGapDefault[i];
        gapInitQGap[i] = gapInitQGapDefault[i];
        gapInitBothGap[i] = gapInitBothGapDefault[i];
        }
    }
    AllocArray(aid.qSmall, aid.smallSize);
    AllocArray(aid.tSmall, aid.smallSize);
    AllocArray(aid.bSmall, aid.smallSize);
    for (i=1; i<aid.smallSize; ++i)
        {
        aid.qSmall[i] = 
            interpolate(i, gapInitPos, gapInitQGap, tableSize);
        aid.tSmall[i] = 
            interpolate(i, gapInitPos, gapInitTGap, tableSize);
        aid.bSmall[i] = interpolate(i, gapInitPos, 
            gapInitBothGap, tableSize);
        }

    /* Set up to handle intermediate values. */
    for (i=0; i<tableSize; ++i)
        {
        if (aid.smallSize == gapInitPos[i])
            {
            startLong = i;
            break;
            }
        }
    if (startLong < 0)
        errAbort("No position %d in initGapAid()\n", aid.smallSize);
    aid.longCount = tableSize - startLong;
    aid.qPosCount = tableSize - startLong;
    aid.tPosCount = tableSize - startLong;
    aid.bPosCount = tableSize - startLong;
    aid.longPos = cloneMem(gapInitPos + startLong, aid.longCount * sizeof(int));
    aid.qLong = cloneMem(gapInitQGap + startLong, aid.qPosCount * sizeof(double));
    aid.tLong = cloneMem(gapInitTGap + startLong, aid.tPosCount * sizeof(double));
    aid.bLong = cloneMem(gapInitBothGap + startLong, aid.bPosCount * sizeof(double));

    /* Set up to handle huge values. */
    aid.qLastPos = aid.longPos[aid.qPosCount-1];
    aid.tLastPos = aid.longPos[aid.tPosCount-1];
    aid.bLastPos = aid.longPos[aid.bPosCount-1];
    aid.qLastPosVal = aid.qLong[aid.qPosCount-1];
    aid.tLastPosVal = aid.tLong[aid.tPosCount-1];
    aid.bLastPosVal = aid.bLong[aid.bPosCount-1];
    aid.qLastSlope = calcSlope(aid.qLastPosVal, aid.qLong[aid.qPosCount-2],
                               aid.qLastPos, aid.longPos[aid.qPosCount-2]);
    aid.tLastSlope = calcSlope(aid.tLastPosVal, aid.tLong[aid.tPosCount-2],
                               aid.tLastPos, aid.longPos[aid.tPosCount-2]);
    aid.bLastSlope = calcSlope(aid.bLastPosVal, aid.bLong[aid.bPosCount-2],
                               aid.bLastPos, aid.longPos[aid.bPosCount-2]);
    // uglyf("qLastPos %d, qlastPosVal %f, qLastSlope %f\n", aid.qLastPos, aid.qLastPosVal, aid.qLastSlope);
    // uglyf("tLastPos %d, tlastPosVal %f, tLastSlope %f\n", aid.tLastPos, aid.tLastPosVal, aid.tLastSlope);
    // uglyf("bLastPos %d, blastPosVal %f, bLastSlope %f\n", aid.bLastPos, aid.bLastPosVal, aid.bLastSlope);
}
Exemple #9
0
void simplifyPathToDirSelfTest()
{
/* First test some cases which should remain the same. */
assert(sameString(simplifyPathToDir(""),""));
assert(sameString(simplifyPathToDir("a"),"a"));
assert(sameString(simplifyPathToDir("a/b"),"a/b"));
assert(sameString(simplifyPathToDir("/"),"/"));
assert(sameString(simplifyPathToDir("/.."),"/.."));
assert(sameString(simplifyPathToDir("/../a"),"/../a"));

/* Now test removing trailing slash. */
assert(sameString(simplifyPathToDir("a/"),"a"));
assert(sameString(simplifyPathToDir("a/b/"),"a/b"));

/* Test .. removal. */
assert(sameString(simplifyPathToDir("a/.."),""));
assert(sameString(simplifyPathToDir("a/../"),""));
assert(sameString(simplifyPathToDir("a/../b"),"b"));
assert(sameString(simplifyPathToDir("/a/.."),"/"));
assert(sameString(simplifyPathToDir("/a/../"),"/"));
assert(sameString(simplifyPathToDir("/a/../b"),"/b"));
assert(sameString(simplifyPathToDir("a/b/.."),"a"));
assert(sameString(simplifyPathToDir("a/b/../"),"a"));
assert(sameString(simplifyPathToDir("a/b/../c"),"a/c"));
assert(sameString(simplifyPathToDir("a/../b/../c"),"c"));
assert(sameString(simplifyPathToDir("a/../b/../c/.."),""));
assert(sameString(simplifyPathToDir("/a/../b/../c/.."),"/"));

/* Test // removal */
assert(sameString(simplifyPathToDir("//"),"/"));
assert(sameString(simplifyPathToDir("//../"),"/.."));
assert(sameString(simplifyPathToDir("a//b///c"),"a/b/c"));
assert(sameString(simplifyPathToDir("a/b///"),"a/b"));
}
Exemple #10
0
void txCdsToGene(char *txBed, char *txFa, char *txCds, char *outGtf, char *outFa)
/* txCdsToGene - Convert transcript bed and best cdsEvidence to genePred and 
 * protein sequence. */
{
struct hash *txSeqHash = faReadAllIntoHash(txFa, dnaLower);
verbose(2, "Read %d transcript sequences from %s\n", txSeqHash->elCount, txFa);
struct hash *cdsHash = cdsEvidenceReadAllIntoHash(txCds);
verbose(2, "Read %d cdsEvidence from %s\n", cdsHash->elCount, txCds);
struct lineFile *lf = lineFileOpen(txBed, TRUE);
FILE *fGtf = mustOpen(outGtf, "w");
FILE *fFa = mustOpen(outFa, "w");
char *row[12];
while (lineFileRow(lf, row))
    {
    struct bed *bed = bedLoad12(row);
    verbose(2, "processing %s\n", bed->name);
    struct cdsEvidence *cds = hashFindVal(cdsHash, bed->name);
    struct dnaSeq *txSeq = hashFindVal(txSeqHash, bed->name);
    char *cdsSource = NULL;
    boolean freeOfCdsErrors = TRUE;
    if (txSeq == NULL)
        errAbort("%s is in %s but not %s", bed->name, txBed, txFa);
    if (cds != NULL)
	{
        freeOfCdsErrors = outputProtein(cds, txSeq, fFa);
	if (cds->cdsCount > 1)
	    {
	    struct bed *newBed = breakUpBedAtCdsBreaks(cds, bed);
	    if (fTweaked)
	        fprintf(fTweaked, "%s\n", newBed->name);
	    bedFree(&bed);
	    bed = newBed;
	    }
	cdsSource = cds->accession;
	if (sameString(cds->accession, "."))
	    cdsSource = cds->source;
	}

    /* Set bed CDS bounds and optionally output bed. */
    cdsEvidenceSetBedThick(cds, bed, freeOfCdsErrors);
    if (fBed)
        bedTabOutN(bed, 12, fBed);

    /* Parse out bed name, which is in format chrom.geneId.txId.accession */
    char *geneName = cloneString(bed->name);
    char *accession = strrchr(geneName, '.');
    assert(accession != NULL);
    *accession++ = 0;
    chopSuffix(geneName);

    /* Output as GTF */
    bedToGtf(bed, accession, cdsSource, geneName, fGtf);

    /* Clean up for next iteration of loop. */
    freez(&geneName);
    bedFree(&bed);
    }
lineFileClose(&lf);
carefulClose(&fFa);
carefulClose(&fGtf);
}
Exemple #11
0
static void setSpecificCodingSoTerm(struct gpFx *effect, char *oldAa, char *newAa,
				    int cdsBasesAdded)
/* Assuming that deletions are marked with dashes in newCodingSequence, 
 * and that effect fields aside from soNumber are already populated, use the
 * pep seqs and number of dashes to determine the appropriate SO term.
 * Probably the majority of cases will be synonymous_variant or missense_variant,
 * but we have to check for several other special cases esp. indels. */
{
struct codingChange *cc = &effect->details.codingChange;
int oldAaSize = strlen(oldAa), newAaSize = strlen(newAa);
if (sameString(newAa, oldAa))
    {
    if (cc->pepPosition == oldAaSize-1 && cc->aaOld[0] == 'Z')
	effect->soNumber = stop_retained_variant;
    else
	effect->soNumber = synonymous_variant;
    }
else
    {
    if (cdsBasesAdded < 0)
	{
	// Got a deletion variant -- check frame (and whether we lost a stop codon):
	if ((cdsBasesAdded % 3) == 0)
	    {
	    if (strchr(cc->aaOld, 'Z') && !strchr(cc->aaNew, 'Z'))
		effect->soNumber = stop_lost;
	    else
		effect->soNumber = inframe_deletion;
	    }
	else
	    effect->soNumber = frameshift_variant;
	}
    else
	{
	// Not a deletion; could be single-base (including early stop) or insertion
	if (newAaSize < oldAaSize)
	    {
	    // Not a deletion but protein got smaller; must have been an early stop codon,
	    // possibly following a frameshift caused by an insertion.
	    if (cc->aaNew[0] != 'Z')
		{
		if (newAa[newAaSize-1] != 'Z')
		    errAbort("gpFx: new protein is smaller but last base in new sequence "
			     "is '%c' not 'Z'.\n"
			     "oldAa (%daa): %s\nnewAa (%daa): %s\n"
			     , newAa[newAaSize-1], oldAaSize, oldAa, newAaSize, newAa);
		effect->soNumber = frameshift_variant;
		}
	    else
		effect->soNumber = stop_gained;
	    }
	else if (newAaSize > oldAaSize)
	    {
	    // protein got bigger; insertion or lost stop codon
	    if (cc->aaOld[0] == 'Z')
		effect->soNumber = stop_lost;
	    else if ((cdsBasesAdded % 3) == 0)
		effect->soNumber = inframe_insertion;
	    else
		effect->soNumber = frameshift_variant;
	    }
	else
	    {
	    // Single aa change
	    if (cc->pepPosition == 0 && cc->aaOld[0] == 'M')
		effect->soNumber = initiator_codon_variant;
	    else if (cc->pepPosition == oldAaSize-1)
		{
		if (oldAa[oldAaSize-1] == 'Z')
		    effect->soNumber = stop_lost;
		else
		    effect->soNumber = incomplete_terminal_codon_variant;
		}
	    else
		effect->soNumber = missense_variant;
	    }
	}
    }
}
void processSnps(char *chromName)
/* read through all rows in snpTmp */
/* look up class and observed */
/* write to output file */
{
char query[512];
struct sqlConnection *conn = hAllocConn();
struct sqlResult *sr;
char **row;
char tableName[64];
char fileName[64];
FILE *f;
struct hashEl *univarElement = NULL;
struct snpData *dataElement = NULL;
int classInt = 0;
char *classString = NULL;
int loc_type = 0;
int skipCount = 0;

safef(tableName, ArraySize(tableName), "%s_snpTmp", chromName);
safef(fileName, ArraySize(fileName), "%s_snpTmp.tab", chromName);
f = mustOpen(fileName, "w");

safef(query, sizeof(query), 
     "select snp_id, chromStart, chromEnd, loc_type, orientation, allele, refUCSC, refUCSCReverseComp, weight from %s ", tableName);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    loc_type = sqlUnsigned(row[3]);
    /* get univarElement from snpHash */
    univarElement = hashLookup(snpHash, row[0]);
    if (univarElement == NULL)
       {
        {
	fprintf(errorFileHandle, "no data for %s (dropping)\n", row[0]);
	skipCount++;
	continue;
	}
       }
    dataElement = (struct snpData *)univarElement->val;
    classInt = dataElement->classInt;
    // verbose(1, "classInt = %d\n", classInt);
    assert(classInt >= 1 && classInt <= classCount);
    /* lookup classString */
    classString = classStrings[classInt-1];
    /* special handling for class = in-del; split into classes of our own construction */
    if (sameString(classString, "in-del"))
        {
        if (loc_type == 3) 
	    classString = cloneString("insertion");
	if (loc_type == 1 || loc_type == 2) 
	    classString = cloneString("deletion");
	}
    fprintf(f, "%s\t%s\t%s\t%d\t%s\t", row[0], row[1], row[2], loc_type, classString);
    fprintf(f, "%s\t%s\t%s\t%s\t%s\t%s\n", row[4], row[5], row[6], row[7], dataElement->observed, row[8]);
    }

sqlFreeResult(&sr);
hFreeConn(&conn);
carefulClose(&f);
if (skipCount > 0)
    verbose(1, "%d rows dropped\n", skipCount);
}
Exemple #13
0
void checkFilename(struct sqlConnection *conn, char *table, struct hash *allBbiNames)
{
char buffer[10 * 1024];
char fileName[10 * 1024];
char oldSymlink[10 * 1024];

verbose(2, "checking for fileName field in table %s \n", table);

// see if this is even a bbi table 
boolean bbiTable = FALSE;
struct slName *fnames = sqlFieldNames(conn, table);
if ((slCount(fnames) == 1) && (sameString(fnames->name, "fileName")))
    bbiTable = TRUE;
slFreeList(&fnames);
if (!bbiTable)
    return;

sqlSafef(buffer, sizeof buffer, "select fileName from %s limit 1", table);
if (sqlQuickQuery(conn, buffer, fileName, sizeof fileName) != NULL)
    {
    while(1)  // loop to catch .bai as well as .bam
	{


	hashAdd(allBbiNames, fileName, NULL);

	verbose(2,"got table.fileName %s\n", fileName);

	// file exists
	FILE *f = fopen(fileName, "r");
	if (f == NULL)
	    {
	    warn("fileName %s from table %s can't be opened", fileName, table);
	    return;
	    }
	else
	    fclose(f);

        // check that the filename and object base match
	char *base = strrchr(fileName, '/');
	if (base == NULL)
	    {
	    warn("fileName %s in table %s not absolute path", fileName, table);
	    return;
	    }
	else
	    {
	    base++;
	    char *dot = strchr(base, '.');
	    if (dot == NULL)
		{
		warn("fileName %s in table %s does not have suffix", fileName, table);
		return;
		}
	    else
		{
		char saveChar = *dot;
		*dot = 0;
		if (!sameString(table, base))
		    {
		    warn("fileName %s doesn't match table  %s", base, table);
		    return;
		    }
		*dot = saveChar;
		}
	    }

        // this file is really a symlink, so check its link target
	ssize_t bufRead = readlink(fileName, oldSymlink, sizeof oldSymlink);
	if (bufRead == -1)
	    {
	    errnoWarn("error reading symlink %s", fileName);
	    return;
	    }
	else
	    {		
	    oldSymlink[bufRead] = 0;  // needs termination.
	    if (!fileExists(oldSymlink))
		{
		warn("symlink target %s does not exist!", oldSymlink);
		return;
		}
	    else
		verbose(2,"got symlink %s\n", oldSymlink);
	    }

        // check that the symlink and object base match
	base = strrchr(oldSymlink, '/');
	if (base == NULL)
	    {
	    warn("symlink %s in fileName %s not absolute path",oldSymlink, fileName);
	    return;
	    }
	else
	    {
	    base++;
	    char *dot = strchr(base, '.');
	    if (dot == NULL)
		{
		warn("symlink %s in fileName %s does not have suffix", oldSymlink, fileName);
		return;
		}
	    else
		{
		char saveChar = *dot;
		*dot = 0;
		if (!sameString(table, base))
		    {
		    warn("symlink %s doesn't match table  %s", base, table);
		    return;
		    }
		*dot = saveChar;
		}
	    }

        /* Note "fileIndex" for .bai has been made obsolete
         so we'll just hard-wire in the .bai support */
	if (!endsWith(fileName, ".bam"))
	    break;
	safecat(fileName, sizeof(fileName), ".bai");
	}

    }
}
Exemple #14
0
void checkMetaFiles(struct mdbObj *mdbObj, char *downDir, struct hash *allNames)
{
verbose(1, "----------------------------------------------\n");
verbose(1, "Checking that files specified in metaDb exist in download dir\n");
verbose(1, "----------------------------------------------\n");
for(; mdbObj != NULL; mdbObj=mdbObj->next)
    {
    struct mdbVar *mdbVar = hashFindVal(mdbObj->varHash, "objType");
    if (mdbVar == NULL)
        {
        warn("objType not found in object %s", mdbObj->obj);
        continue;
        }
    if (sameString(mdbVar->val, "composite"))  // skip objType composite
        continue;

    mdbObj->deleteThis = FALSE;
    mdbVar = hashFindVal(mdbObj->varHash, "composite");

    if (mdbVar == NULL)
        {
        warn("composite not found in object %s", mdbObj->obj);
        continue;
        }
    // char *composite = mdbVar->val;

    mdbVar = hashFindVal(mdbObj->varHash, "fileName");

    if (mdbVar == NULL)
        {
        mdbObj->deleteThis = TRUE;
        warn("fileName not found in object %s", mdbObj->obj);
        continue;
        }

    char *fileName = mdbVar->val;
    char buffer[10 * 1024];

    struct hash *bamNames = hashNew(8);
    struct slName *list = slNameListFromString(fileName, ','), *el;
    for(el=list; el; el=el->next)
	{
	if (hashLookup(allNames, el->name))
	    {
	    warn("duplicate fileName entry: %s", el->name);
	    }
	else
	    {
	    hashAdd(allNames, el->name, NULL);
	    }
        if (endsWith(el->name,".bam"))
	    {
	    hashAdd(bamNames, el->name, NULL);
	    }
        if (endsWith(el->name,".bam.bai"))
	    {
	    el->name[strlen(el->name)-4] = 0;
	    struct hashEl *hel = hashLookup(bamNames, el->name);
	    el->name[strlen(el->name)] = '.';
	    if (hel == NULL)
		{
		warn(".bam.bai without corresponding .bam: %s", el->name);
		}
	    else
		{
		hel->val = (void *)1;
		}
	    }
	}


    // see if we have to add any .bam.bai to the list 
    for(el=list; el; el=el->next)
	{
        if (endsWith(el->name,".bam"))
	    {
	    struct hashEl *hel = hashLookup(bamNames, el->name);
	    if (hel->val == NULL)
		{  // we have to add a .bam.bai to the list 
		char *bambai = addSuffix(el->name, ".bai");
		warn(".bam.bai not found for corresponding .bam in meta.fileName: %s", el->name);
		slNameAddTail(&list, bambai);		
		if (hashLookup(allNames, bambai))
		    {
		    warn("duplicate fileName entry: %s", bambai);
		    }
		else
		    hashAdd(allNames, bambai, NULL);		
		}
	    }
	}

    // make sure the files are there
    for(el=list; el; el=el->next)
	{
	if (!startsWith(mdbObj->obj, el->name))
	    {
	    warn("fileName %s does not start with object name %s", el->name, mdbObj->obj);
	    }

	safef(buffer, sizeof buffer, "%s/%s", downDir, el->name);

	verbose(2, "checking for fileExists %s\n", buffer);
	if (!fileExists(buffer))
	    {
	    mdbObj->deleteThis = TRUE;
	    warn("metaDb file %s not found in download dir %s",buffer, downDir);
	    }
	}
    }
}
void doBigBedReplicate(struct sqlConnection *conn, char *format, struct edwAssembly *assembly,
    struct edwFile *elderEf, struct edwValidFile *elderVf,
    struct edwFile *youngerEf, struct edwValidFile *youngerVf)
/* Do correlation analysis between elder and younger and save result to
 * a new edwQaPairCorrelation record. Do this for a format where we have a bigBed file. */
{
/* If got both pairs, work is done already */
if (pairExists(conn, elderEf->id, youngerEf->id, "edwQaPairSampleOverlap") 
    && pairExists(conn, elderEf->id, youngerEf->id, "edwQaPairCorrelation"))
    return;

int numColIx = 0;
if (sameString(format, "narrowPeak") || sameString(format, "broadPeak"))
    numColIx = 6;	// signalVal
else
    numColIx = 4;	// score
numColIx -= 3;		// Subtract off chrom/start/end
char *enrichedIn = elderVf->enrichedIn;
struct genomeRangeTree *targetGrt = NULL;
if (!isEmpty(enrichedIn) && !sameString(enrichedIn, "unknown"))
    targetGrt = genomeRangeTreeForTarget(conn, assembly, enrichedIn);

/* Get open big bed files for both younger and older. */
char *elderPath = edwPathForFileId(conn, elderEf->id);
char *youngerPath = edwPathForFileId(conn, youngerEf->id);
struct bbiFile *elderBbi = bigBedFileOpen(elderPath);
struct bbiFile *youngerBbi = bigBedFileOpen(youngerPath);

/* Loop through a chromosome at a time adding to correlation, and at the end save result in r.*/
struct correlate *c = correlateNew(), *cInEnriched = correlateNew();
struct bbiChromInfo *chrom, *chromList = bbiChromList(elderBbi);
long long elderTotalSpan = 0, youngerTotalSpan = 0, overlapTotalSpan = 0;
for (chrom = chromList; chrom != NULL; chrom = chrom->next)
    {
    addBbCorrelations(chrom, targetGrt, elderBbi, youngerBbi, numColIx, c, cInEnriched,
	&elderTotalSpan, &youngerTotalSpan, &overlapTotalSpan);
    }

/* Make up correlation structure and save. */
if (!pairExists(conn, elderEf->id, youngerEf->id, "edwQaPairCorrelation"))
    {
    struct edwQaPairCorrelation *cor;
    AllocVar(cor);
    cor->elderFileId = elderVf->fileId;
    cor->youngerFileId = youngerVf->fileId;
    cor->pearsonOverall = correlateResult(c);
    cor->pearsonInEnriched = correlateResult(cInEnriched);
    edwQaPairCorrelationSaveToDb(conn, cor, "edwQaPairCorrelation", 128);
    freez(&cor);
    }

/* Also make up sample structure and save.  */
if (!pairExists(conn, elderEf->id, youngerEf->id, "edwQaPairSampleOverlap"))
    {
    struct edwQaPairSampleOverlap *sam;
    AllocVar(sam);
    sam->elderFileId = elderVf->fileId;
    sam->youngerFileId = youngerVf->fileId;
    sam->elderSampleBases = elderTotalSpan;
    sam->youngerSampleBases = youngerTotalSpan;
    sam->sampleOverlapBases = overlapTotalSpan;
    setSampleSampleEnrichment(sam, format, assembly, elderVf, youngerVf);
    edwQaPairSampleOverlapSaveToDb(conn, sam, "edwQaPairSampleOverlap", 128);
    freez(&sam);
    }

genomeRangeTreeFree(&targetGrt);
correlateFree(&c);
bigBedFileClose(&youngerBbi);
bigBedFileClose(&elderBbi);
freez(&youngerPath);
freez(&elderPath);
}
Exemple #16
0
void bwtool_roll(struct hash *options, char *favorites, char *regions, unsigned decimals, double fill,
		 enum wigOutType wot, char *command, char *size_s, char *bigfile, char *tmp_dir, char *outputfile)
/* bwtool_roll - main for the rolling-mean program */
/* this function is too long. it'd be nice to break it up some time. */
{
    struct metaBig *mb = metaBigOpenWithTmpDir(bigfile, tmp_dir, regions);
    int step = (int)sqlUnsigned((char *)hashOptionalVal(options, "step", "1"));
    int max_na = (int)sqlSigned((char *)hashOptionalVal(options, "max-NA", "-1"));
    char *min_mean_s = (char *)hashOptionalVal(options, "min-mean", "unused");
    double min_mean = -DBL_MAX;
    if (!sameString(min_mean_s,"unused"))
	min_mean = sqlDouble(min_mean_s);
    int size = sqlSigned(size_s);
    if (max_na == -1)
	max_na = size/2;
    else if (max_na > size)
	max_na = size - 1;
    if (size < 1)
	errAbort("size must be >= 1 for bwtool window");
    FILE *out = (outputfile) ? mustOpen(outputfile, "w") : stdout;
    struct bed *section;
    boolean broken = TRUE;  /* for headers */
    enum roll_command com;
    if (sameWord(command, "mean"))
	com = roll_mean;
    else if (sameWord(command, "total"))
	com = roll_total;
    else
	errAbort("Pick a roll command: mean or total");
    for (section = mb->sections; section != NULL; section = section->next)
    {
	if (size <= section->chromEnd - section->chromStart)
	{
	    struct perBaseWig *pbw = perBaseWigLoadSingleContinue(mb, section->chrom, section->chromStart,
								  section->chromEnd, FALSE, fill);
	    int i, j;
	    int len = section->chromEnd - section->chromStart;
	    double total = 0;
	    int num_na = 0;
	    /* load data */
	    for (i = 0; i < size; i++)
		add_to_tots(pbw->data[i], &num_na, &total);
	    i = 0;
	    do
	    {
		int s = pbw->chromStart + i;
		int e = pbw->chromStart + i + size;
 		int st = step;
		double mean = total/(size - num_na);
		/* the next two calculations center it */
		s += size/2 - step/2;
		e = s + step;
		/* output */
		if ((num_na <= max_na) && (mean >= min_mean))
		{
		    double out_val;
		    if (com == roll_mean)
			out_val = mean;
		    else
			out_val = total;
		    if (wot == fixStepOut)
		    {
			if (broken)
			    fprintf(out, "fixedStep chrom=%s start=%d step=%d span=%d\n", pbw->chrom, s+1, step, step);
			fprintf(out, "%0.*f\n", decimals, out_val);
		    }
		    else if (wot == varStepOut)
		    {
			if (broken)
			    fprintf(out, "variableStep chrom=%s span=%d\n", pbw->chrom, step);
			fprintf(out, "%d\t%0.*f\n", s+1, decimals, out_val);
		    }
		    else
			fprintf(out, "%s\t%d\t%d\t%0.*f\n", pbw->chrom, s, e, decimals, out_val);
		    broken = FALSE;
		}
		else
		    broken = TRUE;
		/* move */
		while (st > 0)
		{
		    if (i + size <= pbw->len)
		    {
			add_to_tots(pbw->data[i+size], &num_na, &total);
			sub_from_tots(pbw->data[i], &num_na, &total);
		    }
		    else
			break;
		    i++;
		    st--;
		}
	    } while (i <= pbw->len - size);
	    perBaseWigFree(&pbw);
	}
    }
    metaBigClose(&mb);
    carefulClose(&out);
}
char *describeSubtrackMerge(char *linePrefix)
/* Return a multi-line string that describes the specified subtrack merge,
 * with each line beginning with linePrefix. */
{
struct dyString *dy = dyStringNew(512);
struct trackDb *primary = subTdbFind(curTrack,curTable), *tdb = NULL;
dyStringAppend(dy, linePrefix);
dyStringPrintf(dy, "Subtrack merge, primary table = %s (%s)\n",
	       curTable, primary->longLabel);
dyStringAppend(dy, linePrefix);
dyStringPrintf(dy, "Subtrack merge operation: ");
if (isWiggle(database, curTable) || isBedGraph(curTable) || isBigWigTable(curTable))
    {
    char *op = cartString(cart, hgtaSubtrackMergeWigOp);
    dyStringPrintf(dy, "%s of %s and selected subtracks:\n", op, curTable);
    }
else
    {
    char *op = cartString(cart, hgtaSubtrackMergeOp);
    if (sameString(op, "any"))
	dyStringPrintf(dy, "All %s records that have any overlap with "
		       "any other selected subtrack:\n",
		       curTable);
    else if (sameString(op, "none"))
	dyStringPrintf(dy, "All %s records that have no overlap with "
		       "any other selected subtrack:\n",
		       curTable);
    else if (sameString(op, "more"))
	{
	dyStringPrintf(dy, "All %s records that have at least %s ",
		       curTable,
		       cartString(cart, hgtaNextSubtrackMergeMoreThreshold));
	dyStringPrintf(dy, " %% overlap with any other selected subtrack:\n");
	}
    else if (sameString(op, "less"))
	{
	dyStringPrintf(dy, "All %s records that have at most %s ",
		       curTable,
		       cartString(cart, hgtaNextSubtrackMergeLessThreshold));
	dyStringPrintf(dy, " %% overlap with any other selected subtrack:\n");

	}
    else if (sameString(op, "cat"))
	dyStringPrintf(dy, "All %s records, as well as all records from "
		       "all other selected subtracks:\n", curTable);
    else if (sameString(op, "and"))
	dyStringPrintf(dy, "Base-pair-wise intersection (AND) of %s and "
		       "other selected subtracks:\n", curTable);
    else if (sameString(op, "or"))
	dyStringPrintf(dy, "Base-pair-wise union (OR) of %s and other "
		       "selected subtracks:\n",
       curTable);
    else
	errAbort("describeSubtrackMerge: unrecognized op %s", op);
    }
struct slRef *tdbRef, *tdbRefList = trackDbListGetRefsToDescendantLeaves(curTrack->subtracks);
for (tdbRef = tdbRefList; tdbRef != NULL; tdbRef = tdbRef->next)
    {
    tdb = tdbRef->val;
    if (!sameString(tdb->table, curTable) &&
	isSubtrackMerged(tdb->table) &&
	sameString(tdb->type, primary->type))
	{
	dyStringAppend(dy, linePrefix);
	dyStringPrintf(dy, "  %s (%s)\n", tdb->table, tdb->longLabel);
	}
    }
return dyStringCannibalize(&dy);
}
static struct hgPositions *genomePosCJ(struct jsonWrite *jw,
				       char *db, char *spec, char **retChromName,
				       int *retWinStart, int *retWinEnd, struct cart *cart)
/* Search for positions in genome that match user query.
 * Return an hgp unless there is a problem.  hgp->singlePos will be set if a single
 * position matched.
 * Otherwise display list of positions, put # of positions in retWinStart,
 * and return NULL. */
{
char *hgAppName = "cartJson";
struct hgPositions *hgp = NULL;
char *chrom = NULL;
int start = BIGNUM;
int end = 0;

char *terms[16];
int termCount = chopByChar(cloneString(spec), ';', terms, ArraySize(terms));
boolean multiTerm = (termCount > 1);

int i = 0;
for (i = 0;  i < termCount;  i++)
    {
    trimSpaces(terms[i]);
    if (isEmpty(terms[i]))
	continue;
    hgp = hgPositionsFind(db, terms[i], "", hgAppName, cart, multiTerm);
    if (hgp == NULL || hgp->posCount == 0)
	{
	jsonWriteStringf(jw, "error",
			 "Sorry, couldn't locate %s in genome database", htmlEncode(terms[i]));
	if (multiTerm)
	    jsonWriteStringf(jw, "error",
			     "%s not uniquely determined -- can't do multi-position search.",
			     terms[i]);
	*retWinStart = 0;
	return NULL;
	}
    if (hgp->singlePos != NULL)
	{
	if (chrom != NULL && !sameString(chrom, hgp->singlePos->chrom))
	    {
	    jsonWriteStringf(jw, "error",
			     "Sites occur on different chromosomes: %s, %s.",
			     chrom, hgp->singlePos->chrom);
	    return NULL;
	    }
	chrom = hgp->singlePos->chrom;
	if (hgp->singlePos->chromStart < start)
	    start = hgp->singlePos->chromStart;
	if (hgp->singlePos->chromEnd > end)
	    end = hgp->singlePos->chromEnd;
	}
    else
	{
	hgPositionsJson(jw, db, hgp, cart);
	if (multiTerm && hgp->posCount != 1)
	    {
	    jsonWriteStringf(jw, "error",
			     "%s not uniquely determined (%d locations) -- "
			     "can't do multi-position search.",
			     terms[i], hgp->posCount);
	    return NULL;
	    }
	break;
	}
    }
if (hgp != NULL)
    {
    *retChromName = chrom;
    *retWinStart  = start;
    *retWinEnd    = end;
    }
return hgp;
}
static void makeWigOpButton(char *val, char *selVal)
/* Make merge-wiggle-op radio button. */
{
cgiMakeRadioButton(hgtaNextSubtrackMergeWigOp, val, sameString(val, selVal));
}
void doStandard(struct cart *theCart)
{
cart = theCart;
cartWebStart(cart, database, "ENCODE DCC Submissions");
struct sqlConnection *conn = sqlConnect(database);
struct docIdSub *docIdSub;
char query[10 * 1024];
struct sqlResult *sr;
char **row;
struct tempName tn;
trashDirFile(&tn, "docId", "meta", ".txt");
char *tempFile = tn.forCgi;
//printf("tempFile is %s\n<BR>", tempFile);

    // <Data type> <Cell Type> <Key Metadata> <View>
printf("<table border=1><tr>");
printf("<th>dataType</th>");
printf("<th>cell type</th>");
printf("<th>metadata</th>");
printf("<th>view</th>");
printf("<th>fileType</th>");
printf("<th>file</th>");
printf("<th>lab</th>");
printf("<th>assembly</th>");
printf("<th>subId</th>");
printf("<th>val-report</th>");
printf("</tr>\n");
safef(query, sizeof query, "select * from %s", docIdTable);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    docIdSub = docIdSubLoad(row);
    verbose(2, "ix %d\n", docIdSub->ix);
    verbose(2, "submitDate %s\n", docIdSub->submitDate);
    verbose(2, "md5sum %s\n", docIdSub->md5sum);
    verbose(2, "valReport %s\n", docIdSub->valReport);
    verbose(2, "metaData %s\n", docIdSub->metaData);
    verbose(2, "submitPath %s\n", docIdSub->submitPath);
    verbose(2, "submitter %s\n", docIdSub->submitter);

    cgiDecode(docIdSub->metaData, docIdSub->metaData, strlen(docIdSub->metaData));
    //printf("tempFile %s\n", tempFile);
    FILE *f = mustOpen(tempFile, "w");
    fwrite(docIdSub->metaData, strlen(docIdSub->metaData), 1, f);
    fclose(f);
    boolean validated;
    struct mdbObj *mdbObj = mdbObjsLoadFromFormattedFile(tempFile, &validated);
    unlink(tempFile);

    // <Data type> <Cell Type> <Key Metadata> <View>
    char *docIdType = mdbObjFindValue(mdbObj, "type");
    char *docIdComposite = mdbObjFindValue(mdbObj, "composite");
    char buffer[10 * 1024];
    safef(buffer, sizeof buffer, "%d", docIdSub->ix);
    if (sameString(database, "encpipeline_beta"))
        docIdDir = docIdDirBeta;

    printf("<tr>");
    printf("<td>%s</td> ",   mdbObjFindValue(mdbObj, "dataType"));
    printf("<td>%s</td> ",   mdbObjFindValue(mdbObj, "cell"));
    struct dyString *str = newDyString(100);
    addValue(str,  mdbObjFindValue(mdbObj, "antibody"));
    addValue(str,  mdbObjFindValue(mdbObj, "treatment"));
    addValue(str,  mdbObjFindValue(mdbObj, "rnaExtract"));
    addValue(str,  mdbObjFindValue(mdbObj, "localization"));
    printf("<td>%s<a href=docIdView?docId=%s&db=%s&meta=\"\"> ...</a></td>", str->string,buffer, database);
    freeDyString(&str);
        
    printf("<td>%s</td> ",   mdbObjFindValue(mdbObj, "view"));
    printf("<td>%s</td> ",   mdbObjFindValue(mdbObj, "type"));
    printf("<td><a href=%s> %s</a></td>", 
        docIdGetPath(buffer, docIdDir, docIdType, NULL) , 
        docIdDecorate(docIdComposite,docIdSub->ix));
    char *lab = mdbObjFindValue(mdbObj, "lab");
    char *subId = mdbObjFindValue(mdbObj, "subId");
    printf("<td><a href=docIdView?docId=%s&db=%s&lab=\"%s\"> %s</a></td>",buffer, database, subId, lab);
    printf("<td>%s</td> ",   mdbObjFindValue(mdbObj, "assembly"));
    printf("<td>%s</td> ",   subId);
    printf("<td><a href=docIdView?docId=%s&db=%s&report=\"\"> report</a></td>", buffer, database);
    printf("</tr>\n");
    }

printf("</table>");
sqlFreeResult(&sr);
sqlDisconnect(&conn);
cartWebEnd();
}
Exemple #21
0
struct bwgSection *bwgParseWig(
	char *fileName,       /* Name of ascii wig file. */
	boolean clipDontDie,  /* Skip items outside chromosome rather than aborting. */
	struct hash *chromSizeHash,  /* If non-NULL items checked to be inside chromosome. */
	int maxSectionSize,   /* Biggest size of a section.  100 - 100,000 is usual range. */
	struct lm *lm)	      /* Memory pool to allocate from. */
/* Parse out ascii wig file - allocating memory in lm. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line;
struct bwgSection *sectionList = NULL;

/* remove initial browser and track lines */
lineFileRemoveInitialCustomTrackLines(lf);

while (lineFileNextReal(lf, &line))
    {
    verbose(2, "processing %s\n", line);
    if (stringIn("chrom=", line))
	parseSteppedSection(lf, clipDontDie, chromSizeHash, line, lm, maxSectionSize, &sectionList);
    else
        {
	/* Check for bed... */
	char *dupe = cloneString(line);
	char *words[5];
	int wordCount = chopLine(dupe, words);
	if (wordCount != 4)
	    errAbort("Unrecognized line %d of %s:\n%s\n", lf->lineIx, lf->fileName, line);

	/* Parse out a bed graph line just to check numerical format. */
	char *chrom = words[0];
	int start = lineFileNeedNum(lf, words, 1);
	int end = lineFileNeedNum(lf, words, 2);
	double val = lineFileNeedDouble(lf, words, 3);
	verbose(2, "bedGraph %s:%d-%d@%g\n", chrom, start, end, val);

	/* Push back line and call bed parser. */
	lineFileReuse(lf);
	parseBedGraphSection(lf, clipDontDie, chromSizeHash, lm, maxSectionSize, &sectionList);
	}
    }
slSort(&sectionList, bwgSectionCmp);

/* Check for overlap at section level. */
struct bwgSection *section, *nextSection;
for (section = sectionList; section != NULL; section = nextSection)
    {
    nextSection = section->next;
    if (nextSection != NULL)
        {
	if (sameString(section->chrom, nextSection->chrom))
	    {
	    if (section->end > nextSection->start)
	        {
		errAbort("There's more than one value for %s base %d (in coordinates that start with 1).\n",
		    section->chrom, nextSection->start+1);
		}
	    }
	}
    }

return sectionList;
}
Exemple #22
0
boolean isAlt5Prime(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		    int *altBpStart, int *altBpEnd, int *termExonStart, int *termExonEnd)
/* Return TRUE if we have an edge pattern of:
   hs->he----->hs
     \-->he--/
   Which indicates two possible ends to an exon (alt 5' intron starts).

   Use edgesInArea() to investigate an area that begins in the rows with the common
   hard end and finishes with common hard end. 
   esees
   01234 (4 vertices involved in alt splicing)
  0  
  1  ++
  2    +
  3    +
  4   
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;
/* Quick check. */
if(vTypes[vs] != ggHardStart || vTypes[ve1] != ggHardEnd || vTypes[ve2] != ggHardEnd)
    return FALSE;

if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find common start for the two hard ends. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardStart && em[ve1][i] && em[ve2][i])
	    {
	    /* Make sure that they only connect to that one hard start. */
	    if(rowSum(em[ve1],ag->vTypes,ag->vertexCount) == 1 &&
	       rowSum(em[ve2],ag->vTypes,ag->vertexCount) == 1 &&
	       edgesInArea(ag,em,i-1,vs+1) == numAltVerts)
		{
		int *vPos = ag->vPositions;
		struct bed bedUp, bedDown, bedAlt, bedConst;
		
		/* Report the first and last vertexes. */
		*termExonStart = i;
		*termExonEnd = findClosestDownstreamVertex(ag, em, i);
                /* Initialize some beds for reporting. */
		bedConst.chrom = bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
		bedConst.name = bedUp.name = bedDown.name = bedAlt.name = ag->name;
		if(sameString(ag->strand, "+"))
		    bedConst.score = bedUp.score = bedDown.score = bedAlt.score = alt5Prime;
		else
		    bedConst.score = bedUp.score = bedDown.score = bedAlt.score = alt3Prime;
		safef(bedConst.strand, sizeof(bedConst.strand), "%s", ag->strand);
		safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
		safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
		safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);

                /* Alt spliced region. */
		bedAlt.chromStart = vPos[ve1];
		bedAlt.chromEnd = vPos[ve2];
		bedConst.chromStart = vPos[vs];
		bedConst.chromEnd = vPos[ve1];

                /* Upstream/down stream */
		if(sameString(ag->strand, "+"))
		    {
		    bedDown.chromStart = vPos[ve2];
		    bedDown.chromEnd = vPos[ve2]+flankingSize;
		    bedUp.chromStart = vPos[vs]-flankingSize;
		    bedUp.chromEnd = vPos[vs];
		    }
		else 
		    {
		    bedUp.chromStart = vPos[ve2];
		    bedUp.chromEnd = vPos[ve2]+flankingSize;
		    bedDown.chromStart = vPos[vs]-flankingSize;
		    bedDown.chromEnd = vPos[vs];
		    }
		if(altRegion)
		    {
		    bedOutputN(&bedConst, 6, constRegion, '\t','\n');
		    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
		    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
		    }		
		*altBpStart = ve1;
		*altBpEnd = ve2;
		return TRUE;
		}
	    }
	}
    }
return FALSE;
}
Exemple #23
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn, *conn2;
struct sqlResult *sr2;
char query2[256];
char **row2;
char condStr[255];

char *uniProtDb;
char *score;
FILE *outf;
FILE *dupOutf;
char *chrom, *cdsStart, *cdsEnd;
char *displayID;
char *oldDisplayID;

char *chp, *chp1;
int  i;

int  isDuplicate;
    
char *kgTempDb;
char *infileName, *outfileName, *dupOutfileName;

if (argc != 6) usage();
    
kgTempDb    = argv[1];
uniProtDb  = argv[2];
infileName  = argv[3];
outfileName = argv[4];
dupOutfileName = argv[5];
  
inf     = mustOpen(infileName, "r");
outf    = mustOpen(outfileName, "w");
dupOutf = mustOpen(dupOutfileName, "w");
conn    = hAllocConn();
conn2= hAllocConn();

strcpy(oldInfo, "");

isDuplicate   = 0;
oldMrnaStr    = cloneString("");
oldAlignStr   = cloneString("");
oldProteinStr = cloneString("");
oldDisplayID  = cloneString("");

mrnaStr       = cloneString("");
proteinStr    = cloneString("");

while (fgets(line_in, 500, inf) != NULL)
    {
    strcpy(line, line_in);
    strcpy(line2, line_in);

    chp = strstr(line, "\t");	
    *chp = '\0';
    mrnaStr = strdup(line);
    
    chp ++;
    chp1 = chp;
    chp = strstr(chp, "\t");	
    *chp = '\0';
    chrom = strdup(chp1);
    
    chp ++;
    chp1 = chp;
    chp = strstr(chp, "\t");	
    *chp = '\0';
    cdsStart = strdup(chp1);
    
    chp ++;
    chp1 = chp;
    chp = strstr(chp, "\t");	
    *chp = '\0';
    cdsEnd = strdup(chp1);
    chp1 = line2 + (chp - line);
    *chp1 = '\0';
 
    chp ++;
    chp1 = chp;
    chp  = strstr(chp, "\t");	
    *chp = '\0';
    score= strdup(chp1);
   
    chp ++;
    chp1 = chp;
    chp  = strstr(chp, "\n");	
    *chp = '\0';
    proteinStr= strdup(chp1);
    
    strcpy(newInfo, line2);
    if (sameString(oldInfo, newInfo))
	{
	isDuplicate = 1;
 	sqlSafefFrag(condStr, sizeof(condStr), "acc='%s'", proteinStr);
        displayID = sqlGetField(uniProtDb, "displayId", "val", condStr);	
	if (displayID == NULL) 
	    {
	    printf("!!! %s not found\n", proteinStr);fflush(stdout);
	    }
 	sqlSafefFrag(condStr, sizeof(condStr), "acc='%s'", oldProteinStr);
        oldDisplayID = sqlGetField(uniProtDb, "displayId", "val", condStr);	
	if (oldDisplayID == NULL) 
	    {
	    printf("!!! %s not found\n", oldProteinStr);fflush(stdout);
	    }
	fprintf(dupOutf, 
		"%s\t%s\t%s\t%s\n", oldMrnaStr, oldDisplayID, mrnaStr, displayID);fflush(stdout);
	}
    else
	{
	/* remember previous record as old only if it is not a duplicate */
	if (!isDuplicate)
	    {
	    oldMrnaStr 	  = mrnaStr;
	    oldProteinStr = proteinStr;
	    }
	strcpy(oldInfo, newInfo);
	isDuplicate = 0;

	sqlSafef(query2, sizeof(query2), 
	      "select * from %s.kgCandidate2 where name='%s' and proteinID='%s' and chrom='%s' and cdsStart='%s' and cdsEnd='%s'", 
	      kgTempDb, mrnaStr, proteinStr, chrom, cdsStart, cdsEnd);
	sr2 = sqlMustGetResult(conn2, query2);
    	row2 = sqlNextRow(sr2);
    	while (row2 != NULL)
	    {
	    for (i=0; i<10; i++) fprintf(outf, "%s\t", row2[i]);
	    if (!sameWord(proteinStr, row2[10]))
	    	{
		printf("\n??? %s\t%s\n", proteinStr, row2[10]);fflush(stdout);
		}
		
 	    sqlSafefFrag(condStr, sizeof(condStr), "acc='%s'", proteinStr);
            displayID = sqlGetField(uniProtDb, "displayId", "val", condStr);	
	    if (displayID == NULL) 
	    	{
		printf("!!! %s not found\n", proteinStr);fflush(stdout);
		}
	    fprintf(outf, "%s\t", displayID);
	    fprintf(outf, "%s\n", row2[11]);
	    row2 = sqlNextRow(sr2);
	    }
	sqlFreeResult(&sr2);
	}
    }
fclose(inf);
fclose(outf);
fclose(dupOutf);
return(0);
}
Exemple #24
0
boolean isCassette(struct altGraphX *ag, bool **em,  int vs, int ve1, int ve2,
		    int *altBpStartV, int *altBpEndV, int *startV, int *endV)
/* Return TRUE if SIMPLE cassette exon.
   Looking for pattern:
   he--->hs---->he---->hs
     \----------------/

   Use edgesInArea() to investigate that encompasses the common hard
   end and common hard start. Should only be 4 edges in area defined by
   splicing.
   sesese 
   012345 
  0  
  1  + +
  2   + 
  3    +
  4   
  5
*/
{
unsigned char *vTypes = ag->vTypes;
int i=0;
int numAltVerts = 4;
int *vPos = ag->vPositions;
/* Quick check. */
if(vTypes[vs] != ggHardEnd || vTypes[ve1] != ggHardStart || vTypes[ve2] != ggHardStart)
    return FALSE;

if(em[vs][ve1] && em[vs][ve2]) 
    {
    /* Try to find a hard end that connects ve1 and ve2. */
    for(i=0; i<ag->vertexCount; i++)
	{
	if(vTypes[i] == ggHardEnd && em[ve1][i] && em[i][ve2])
	    {
	    /* Make sure that our cassette only connect to downstream. otherwise not
	       so simple...*/
	    if(rowSum(em[i],ag->vTypes,ag->vertexCount) == 1 &&
	       rowSum(em[ve1],ag->vTypes,ag->vertexCount) == 1 &&
	       colSum(em, ag->vTypes, ag->vertexCount, ve1) == 1 &&
	       edgesInArea(ag,em,ve2-1,vs+1) == numAltVerts)
		{
		struct bed bedUp, bedDown, bedAlt;
		/* Initialize some beds for reporting. */
		*startV = findClosestUpstreamVertex(ag, em, vs);
		*endV = findClosestDownstreamVertex(ag, em, ve2);
		bedUp.chrom = bedDown.chrom = bedAlt.chrom = ag->tName;
		bedUp.name = bedDown.name = bedAlt.name = ag->name;
		bedUp.score = bedDown.score = bedAlt.score = altCassette;
		safef(bedUp.strand, sizeof(bedUp.strand), "%s", ag->strand);
		safef(bedDown.strand, sizeof(bedDown.strand), "%s", ag->strand);
		safef(bedAlt.strand, sizeof(bedDown.strand), "%s", ag->strand);
		/* Alt spliced region. */
		bedAlt.chromStart = vPos[ve1];
		bedAlt.chromEnd = vPos[i];

		/* Upstream/down stream */
		if(sameString(ag->strand, "+"))
		    {
		    bedUp.chromStart = vPos[ve1] - flankingSize;
		    bedUp.chromEnd = vPos[ve1];
		    bedDown.chromStart = vPos[i];
		    bedDown.chromEnd = vPos[i] + flankingSize;
		    }
		else 
		    {
		    bedDown.chromStart = vPos[ve1] - flankingSize;
		    bedDown.chromEnd = vPos[ve1];
		    bedUp.chromStart = vPos[i];
		    bedUp.chromEnd = vPos[i] + flankingSize;
		    }
		if(altRegion != NULL)
		    {
		    bedOutputN(&bedAlt, 6, altRegion, '\t','\n');
		    bedOutputN(&bedUp, 6, upStream100, '\t', '\n');
		    bedOutputN(&bedDown, 6, downStream100, '\t', '\n');
		    }
		*altBpStartV = ve1;
		*altBpEndV = i;
		return TRUE;
		}
	    }
	}
    }
return FALSE;
}
void makeDiffAndSplit(struct commit *c, char *u, boolean full)
/* Generate a full diff and then split it up into its parts.
 * This was motivated because no other way to show deleted files
 * since they are not in repo and git paths must actually exist
 * in working repo dir.  However leaving off the path produces
 * a diff with everything we want, we just have to split it up. */
{
safef(gitCmd,sizeof(gitCmd), 
    "git diff -b -w --no-prefix --unified=%d %s^! > %s"  
    , full ? 1000000 : contextSize
    , c->commitId, tempMakeDiffName);
//git shorthand: x^! is equiv to range x^ x, 
//  i.e. just the one commit and nothing more.

// hack until better fix - this is the case where there is no previous commit
if (sameString(c->commitId, "dc78303b079985b5a146d093bbb8a5d06489562d"))
    {
    safef(gitCmd,sizeof(gitCmd), 
	"git show -b -w --no-prefix --unified=%d %s > %s"  
    , full ? 1000000 : contextSize
	, c->commitId, tempMakeDiffName);
    }

runShell(gitCmd);


// now parse it and split it into separate files with the right path.
struct lineFile *lf = lineFileOpen(tempMakeDiffName, TRUE);
int lineSize;
char *line;
FILE *h = NULL;
while (lineFileNext(lf, &line, &lineSize))
    {
    if (startsWith("diff --git ", line))
	{
	if (h)
	    {
	    fclose(h);
	    h = NULL;
	    }
	char *fpath = line + strlen("diff --git ");
	fpath = strchr(fpath, ' ');
	++fpath;   // now we should be pointing to the world

	char path[1024];
	char *r = strrchr(fpath, '/');
	if (r)
	    {
	    *r = 0;
	    /* make internal levels of subdirs */
	    safef(path, sizeof(path), "mkdir -p %s/%s/%s/%s/%s/%s", outDir, outPrefix, "user", u, full ? "full" : "context", fpath);
	    runShell(path);
	    *r = '/';
	    }
	safef(path, sizeof(path), "%s/%s/%s/%s/%s/%s%s.diff"
	    , outDir, outPrefix, "user", u, full ? "full" : "context", fpath, c->commitId);

	h = mustOpen(path, "w");
	fprintf(h, "%s\n", c->commitId);
	fprintf(h, "%s\n", c->author);
	fprintf(h, "%s\n", c->date);
	fprintf(h, "%s\n", c->comment);
	}
    else if (startsWith("@@", line))
	{
	char *end = strchr(line+2, '@');
	*(end+2) = 0;  // chop the weird unwanted context string from here following e.g. 
        //@@ -99,7 +99,9 @@ weird unwanted context string here
        // converts to
        //@@ -99,7 +99,9 @@
	// saves 17 seconds over the more expensive sed command
	}
    if (h)
	fprintf(h, "%s\n", line);
    }
if (h)
    {
    fclose(h);
    h = NULL;
    }
lineFileClose(&lf);
}
struct genePred *getOverlappingGeneDb(struct genePred **list, char *table, char *chrom, int cStart, int cEnd, char *name, int *retOverlap, char *db)
{
/* read all genes from a table find the gene with the biggest overlap. 
   Cache the list of genes to so we only read it once */

struct genePred *el = NULL, *bestMatch = NULL, *gp = NULL;
int overlap = 0 , bestOverlap = 0, i;
int *eFrames;

if (list == NULL)
    return NULL;

if (*list == NULL)
    {
    struct genePred *gpList = NULL;
    struct sqlConnection *conn = sqlConnect(db);
    struct genePredReader *gpr = NULL;
    if (!hTableExistsDb(db,table))
        table = altTable;
    if (!hTableExistsDb(db,table))
        {
        verbose(2,"no table %s in %s\n",table, db);
        return NULL;
        }
    gpr = genePredReaderQuery(conn, table, NULL);
    verbose(1,"Loading Predictions from %s in %s\n",table, db);
    gpList = genePredReaderAll(gpr);
    if (gpList != NULL)
        {
        hashAdd(geneListHash, db, gpList);
        *list = gpList;
        }
    sqlDisconnect(&conn);
    }
for (el = *list; el != NULL; el = el->next)
    {
    if (chrom != NULL && el->chrom != NULL)
        {
        overlap = 0;
        if ( sameString(chrom, el->chrom))
            {
            for (i = 0 ; i<(el->exonCount); i++)
                {
                overlap += positiveRangeIntersection(cStart,cEnd, el->exonStarts[i], el->exonEnds[i]) ;
                }
            if (overlap > 20 && sameString(name, el->name))
                {
                bestMatch = el;
                bestOverlap = overlap;
                *retOverlap = bestOverlap;
                }
            if (overlap > bestOverlap)
                {
                bestMatch = el;
                bestOverlap = overlap;
                *retOverlap = bestOverlap;
                }
            }
        }
    }
if (bestMatch != NULL)
    {
    /* Allocate genePred and fill in values. */
    AllocVar(gp);
    gp->name = cloneString(bestMatch->name);
    gp->chrom = cloneString(bestMatch->chrom);
    gp->strand[1] = bestMatch->strand[1];
    gp->strand[0] = bestMatch->strand[0];
    gp->txStart = bestMatch->txStart;
    gp->txEnd = bestMatch->txEnd;
    gp->cdsStart = bestMatch->cdsStart;
    gp->cdsEnd = bestMatch->cdsEnd;
    gp->exonCount = bestMatch->exonCount;
    AllocArray(gp->exonStarts, bestMatch->exonCount);
    AllocArray(gp->exonEnds, bestMatch->exonCount);
    for (i=0; i<bestMatch->exonCount; ++i)
        {
        gp->exonStarts[i] = bestMatch->exonStarts[i] ;
        gp->exonEnds[i] = bestMatch->exonEnds[i] ;
        }
    gp->optFields = bestMatch->optFields;
    gp->id = bestMatch->id;

    if (bestMatch->optFields & genePredName2Fld)
        gp->name2 = cloneString(bestMatch->name2);
    else
        gp->name2 = NULL;
    if (bestMatch->optFields & genePredCdsStatFld)
        {
        gp->cdsStartStat = bestMatch->cdsStartStat;
        gp->cdsEndStat = bestMatch->cdsEndStat;
        }
    if (bestMatch->optFields & genePredExonFramesFld)
        {
        gp->exonFrames = AllocArray(eFrames, bestMatch->exonCount);
        for (i = 0; i < bestMatch->exonCount; i++)
            gp->exonFrames[i] = bestMatch->exonFrames[i];
        }
    eFrames = gp->exonFrames;
    }

return gp;
}
void doUserFiles(char *u, struct commit *commits)
/* process one user's files-view (or all if u is NULL) */
{

// http://hgwdev.cse.ucsc.edu/cvs-reports/branch/user/galt/index-by-file.html
// if u is NULL
// http://hgwdev.cse.ucsc.edu/cvs-reports/branch/file/index.html
char userPath[1024];
if (u)
    safef(userPath, sizeof(userPath), "%s/%s/%s/%s/index-by-file.html", outDir, outPrefix, "user", u);
else
    safef(userPath, sizeof(userPath), "%s/%s/%s/index.html", outDir, outPrefix, "file");

FILE *h = mustOpen(userPath, "w");
if (u)
    {
    fprintf(h, "<html>\n<head>\n<title>File Changes for %s</title>\n</head>\n</body>\n", u);
    fprintf(h, "<h1>File Changes for %s</h1>\n", u);
    fprintf(h, "switch to <A href=\"index.html\">commits view</A>, <A href=\"../index.html\">user index</A>");
    }
else
    {
    fprintf(h, "<html>\n<head>\n<title>All File Changes</title>\n</head>\n</body>\n");
    fprintf(h, "<h1>All File Changes</h1>\n");
    }

fprintf(h, "<h3>%s to %s (%s to %s) %s</h3>\n", startTag, endTag, startDate, endDate, title);

fprintf(h, "<ul>\n");


int totalLinesChanged = 0;
int totalFileCount = 0;

char *cDiff = NULL, *cHtml = NULL, *fDiff = NULL, *fHtml = NULL;
char *relativePath = NULL;

struct commit *c = NULL;
struct files *f = NULL;

struct comFile *comFiles = NULL, *cf = NULL;

// pre-filter for u if u is not NULL  
for(c = commits; c; c = c->next)
    {
    if (!u || (u && sameString(c->author, u)))
	{
	for(f = c->files; f; f = f->next)
	    {
	    AllocVar(cf);
	    cf->f = f;
	    cf->commit = c;
	    slAddHead(&comFiles, cf);
	    }
	}
    }
// sort by file path, and then by commitNumber
//  so that newest commit is on the bottom.
slSort(&comFiles, slComFileCmp);

char *lastPath = "";
char *closure = "";

for(cf = comFiles; cf; cf = cf->next)
    {
    c = cf->commit;
    f = cf->f;
 
    if (!sameString(f->path, lastPath))
	{
	fprintf(h, "%s", closure);
	lastPath = f->path;
	fprintf(h, "<li>%s\n", f->path);
    	closure = "</li>\n";
	}


    char path[1024];

    // context unified
    if (u)
	safef(path, sizeof(path), "%s/%s%s", "context", f->path, c->commitId);
    else
	safef(path, sizeof(path), "../user/%s/%s/%s%s", c->author, "context", f->path, c->commitId);
    relativePath = cloneString(path);
    safef(path, sizeof(path), "%s.html", relativePath);
    cHtml = cloneString(path);
    safef(path, sizeof(path), "%s.diff", relativePath);
    cDiff = cloneString(path);



    // full text (up to 10,000 lines)
    freeMem(relativePath);
    if (u)
	safef(path, sizeof(path), "%s/%s%s", "full", f->path, c->commitId);
    else
	safef(path, sizeof(path), "../user/%s/%s/%s%s", c->author, "context", f->path, c->commitId);
    relativePath = cloneString(path);
    safef(path, sizeof(path), "%s.html", relativePath);
    fHtml = cloneString(path);
    safef(path, sizeof(path), "%s.diff", relativePath);
    fDiff = cloneString(path);

    // make file view links
    fprintf(h, "<ul><li>");
    fprintf(h, " lines changed %d, "
	"context: <A href=\"%s\">html</A>, <A href=\"%s\">text</A>, "
	"full: <A href=\"%s\">html</A>, <A href=\"%s\">text</A><br>\n"
	, f->linesChanged
	, cHtml, cDiff, fHtml, fDiff);

    //fprintf(h, "  %s\n", c->commitId);
    //fprintf(h, "  %s\n", c->date);
    char *cc = htmlEncode(c->comment);
    char *ccc = replaceChars(cc, "\n", "<br>\n");
    fprintf(h, "    %s\n", ccc);
    freeMem(cc);
    freeMem(ccc);
    fprintf(h, "</li></ul>\n");

    freeMem(relativePath);
    freeMem(cDiff);
    freeMem(cHtml);
    freeMem(fDiff);
    freeMem(fHtml);

    totalLinesChanged += f->linesChanged;
    ++totalFileCount;

    fprintf(h, "\n");
    }
fprintf(h, "%s", closure);
fprintf(h, "</ul>\n");
if (u)
    {
    fprintf(h, "switch to <A href=\"index.html\">commits view</A>, <A href=\"../index.html\">user index</A>");
    }
else
    {
    fprintf(h, "<ul>\n");
    fprintf(h, "<li> lines changed: %d</li>\n", totalLinesChanged);
    fprintf(h, "<li> files changed: %d</li>\n", totalFileCount);
    fprintf(h, "</ul>\n");
    }
fprintf(h, "</body>\n</html>\n");
fclose(h);
}
Exemple #28
0
struct xaAli *xaReadNext(FILE *f, boolean condensed)
/* Read next xaAli from file. If condensed
 * don't fill int query, target, qSym, tSym, or hSym. */
{
char line[512];
char *words[16];
int wordCount;
struct xaAli *xa;
char *parts[5];
int partCount;
double percentScore;
int symCount;
int newOffset = 0;
char *s, *e;

/* Get first line and parse out everything but the sym lines. */
if (fgets(line, sizeof(line), f) == NULL)
    return NULL;
wordCount = chopLine(line, words);
if (wordCount < 9)
    errAbort("Short line in cross-species alignment file");
if (wordCount == 10)
    newOffset = 1;
if (!sameString(words[1], "align"))
    errAbort("Bad line in cross-species alignment file");
AllocVar(xa);
xa->name = cloneString(words[0]);
s = words[5+newOffset];
e = strrchr(s, ':');
if (e == NULL)
    errAbort("Bad line (no colon) in cross-species alignment file");
*e++ = 0;
partCount = chopString(e, "-", parts, ArraySize(parts));
if (partCount != 2)
    errAbort("Bad range format in cross-species alignment file");
if (!condensed)
    xa->query = cloneString(s);
xa->qStart = atoi(parts[0]);
xa->qEnd = atoi(parts[1]);
xa->qStrand = words[6+newOffset][0];
partCount = chopString(words[7+newOffset], ":-", parts, ArraySize(parts));
if (!condensed)
    xa->target = cloneString(parts[0]);
xa->tStart = atoi(parts[1]);
xa->tEnd = atoi(parts[2]);
xa->tStrand = words[8+newOffset][0];
percentScore = atof(words[2]);
xa->milliScore = round(percentScore*10);    
xa->symCount = symCount = atoi(words[4]);

/* Get symbol lines. */
if (condensed)
    {
    eatThroughLf(f);
    eatThroughLf(f);
    eatThroughLf(f);
    }
else
    {
    xa->qSym = needMem(symCount+1);
    mustRead(f, xa->qSym, symCount);
    eatLf(f);

    xa->tSym = needMem(symCount+1);
    mustRead(f, xa->tSym, symCount);
    eatLf(f);

    xa->hSym = needMem(symCount+1);
    mustRead(f, xa->hSym, symCount);
    eatLf(f);
    }
return xa;
}
Exemple #29
0
char *webTimeStampedLinkToResource(char *fileName, boolean wrapInHtml)
// If wrapInHtml
//   returns versioned link embedded in style or script html (free after use).
// else
//   returns full path of a versioned path to the requested resource file (js, or css).
// NOTE: png, jpg and gif should also be supported but are untested.
//
// In production sites we use a versioned softlink that includes the CGI version. This has the following benefits:
// a) flushes user's web browser cache when the user visits a GB site whose version has changed since their last visit;
// b) enforces the requirement that static files are the same version as the CGIs (something that often fails to happen in mirrors).
// (see notes in redmine #3170).
//
// In dev trees we use mtime to create a pseudo-version; this forces web browsers to reload css/js file when it changes,
// so we don't get odd behavior that can be caused by caching of mis-matched javascript and style files in dev trees.
//
// In either case, the actual file has to have been previously created by running make in the appropriate directory (kent/src/hg/js
// or kent/src/hg/htdocs/style).
{
char baseName[PATH_LEN];
char extension[FILEEXT_LEN];
splitPath(fileName, NULL, baseName, extension);
boolean js = sameString(".js",extension);
boolean style = !js && sameString(".css",extension);
boolean image = !js
             && !style
             && (  sameString(".png",extension)
                || sameString(".jpg",extension)
                || sameString(".gif",extension));
if (!js && !style) // && !image) NOTE: This code has not been tested on images but should work.
    errAbort("webTimeStampedLinkToResource: unknown resource type for %s.\n", fileName);

// Build and verify directory
char *dirName = "";
if (js)
    dirName = cfgOptionDefault("browser.javaScriptDir", "js");
else if (style)
    dirName = cfgOptionDefault("browser.styleDir","style");
else if (image)
    dirName = cfgOptionDefault("browser.styleImagesDir","style/images");
struct dyString *fullDirName = NULL;
char *docRoot = hDocumentRoot();
if (docRoot != NULL)
    fullDirName = dyStringCreate("%s/%s", docRoot, dirName);
else
    // tolerate missing docRoot (i.e. when running from command line)
    fullDirName = dyStringCreate("%s", dirName);
if (!fileExists(dyStringContents(fullDirName)))
    errAbort("webTimeStampedLinkToResource: dir: %s doesn't exist.\n",
             dyStringContents(fullDirName));

// build and verify real path to file
struct dyString *realFileName = dyStringCreate("%s/%s", dyStringContents(fullDirName), fileName);
if (!fileExists(dyStringContents(realFileName)))
    errAbort("webTimeStampedLinkToResource: file: %s doesn't exist.\n",
             dyStringContents(realFileName));

// build and verify link path including timestamp in the form of dir/baseName + timeStamp or CGI Version + ext
long mtime = fileModTime(dyStringContents(realFileName));
struct dyString *linkWithTimestamp;

char *scriptName = cgiScriptName();
if (scriptName == NULL)
    scriptName = cloneString("");
boolean nonVersionedLinks = FALSE;
if (endsWith(scriptName, "qaPushQ"))
    nonVersionedLinks = TRUE;
if (nonVersionedLinks)
    linkWithTimestamp = dyStringCreate("%s/%s%s", dyStringContents(fullDirName), baseName, extension);
else if ((cfgOption("versionStamped") == NULL) &&  (hIsPreviewHost() || hIsPrivateHost()))
    linkWithTimestamp = dyStringCreate("%s/%s-%ld%s", dyStringContents(fullDirName), baseName, mtime, extension);
else
    linkWithTimestamp = dyStringCreate("%s/%s-v%s%s", dyStringContents(fullDirName), baseName, CGI_VERSION, extension);

if (!fileExists(dyStringContents(linkWithTimestamp)))
    errAbort("Cannot find correct version of file '%s'; this is due to an installation error\n\nError details: %s does not exist",
             fileName, dyStringContents(linkWithTimestamp));

// Free up all that extra memory
dyStringFree(&realFileName);
dyStringFree(&fullDirName);
char *linkFull = dyStringCannibalize(&linkWithTimestamp);
char *link = linkFull;
if (docRoot != NULL)
    {
    link = cloneString(linkFull + strlen(docRoot) + 1);
    freeMem(linkFull);
    }

if (wrapInHtml) // wrapped for christmas
    {
    struct dyString *wrapped = dyStringNew(0);
    if (js)
        dyStringPrintf(wrapped,"<script type='text/javascript' SRC='/%s'></script>\n", link);
    else if (style)
        dyStringPrintf(wrapped,"<LINK rel='STYLESHEET' href='/%s' TYPE='text/css' />\n", link);
    else // Will be image, since these are the only three choices allowed
        dyStringPrintf(wrapped,"<IMG src='/%s' />\n", link);
    freeMem(link);
    link = dyStringCannibalize(&wrapped);
    }

return link;
}
Exemple #30
0
int main(int argc, char *argv[])
/* Process command line. */
{
pushCarefulMemHandler(100000000);
cgiSpoof(&argc, argv);
htmlSetStyle(htmlStyleUndecoratedLink);
htmlSetBgColor(HG_CL_OUTSIDE);
oldCart = hashNew(10);

cart = cartAndCookie(hUserCookie(), excludeVars, oldCart);

getDbAndGenome(cart, &database, &genome, oldCart);
//hSetDb(database);
conn = hAllocConn(database);

database = strdup("h1n1");

/* Get sortOn.  Revert to default by subject Id. */
orderOn = cartUsualString(cart, orderVarName, "+subjId");

displayCountString = cartUsualString(cart, countVarName, "50");
if (sameString(displayCountString, "all"))
    displayCount = BIGNUM;
else
    displayCount = atoi(displayCountString);
colList = getColumns(conn);

if (cgiVarExists("submit_filter"))
    {
    struct dyString *head = dyStringNew(1024);
    boolean redir = cgiVarExists(redirectName);
    struct subjInfo *subjList = NULL;
    struct column *ordList = colList;
    struct column *ord = curOrder(ordList);
    subjList = getOrderedList(ord, colList, conn, BIGNUM);
    saveSubjList(subjList);
    if ((!subjList || redir))
	{
	if (subjList && redir)
	    {
	    dyStringPrintf(head,
		"<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=/cgi-bin/%s\">"
		"<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">"
		"<META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\">"
		, cgiString(redirectName));
    	    cartRemove(cart, redirectName);
	    }
	htmStartWithHead(stdout, head->string, "GISAID Table View");
	if (!subjList) /* if everything has been filtered out, we'll have to go back */
	    {
	    hPrintf("No subject(s) found with the filtering conditions specified.<br>");
	    hPrintf("Click <a href=\"gisaidTable?gisaidTable.do.advFilter=filter+%%28now+on%%29\">here</a> "
		"to return to Select Subjects.<br>");
	    }
	cartCheckout(&cart);
    	htmlEnd();
	hFreeConn(&conn);
	return 0;
	}
    }

htmStart(stdout, "GISAID Table View");
cartWarnCatcher(doMiddle, cart, htmlVaWarn);
cartCheckout(&cart);
htmlEnd();

hFreeConn(&conn);

return 0;
}