void doMiddle()
/* Write middle part of .html. */
{
DNA *targetDna;
char *chrom;
int tStart, tEnd;
struct xaAli *xa;
int bothStart, bothEnd;
char cbCosmidName[256];
char *s;

/* Get input variables from CGI. */
char *qOrganism = cgiString("qOrganism");
char *tOrganism = cgiString("tOrganism");
char *query = cgiString("query");
char *target = cgiString("target");
char *strandString = cgiString("strand");
char strand = strandString[0];
boolean showSym = cgiBoolean("symbols");
boolean gotClickPos = cgiVarExists("clickPos");
double clickPos;
if (gotClickPos) clickPos = cgiDouble("clickPos");

strcpy(cbCosmidName, query);
if ((s = strrchr(cbCosmidName, '.')) != NULL)
    *s = 0;


/* Get xaAli. */
xa = getOneXaAli(qOrganism, query);

printf("<H2>Alignment of <I>C. briggsae</I> %s:%d-%d and <I>C. elegans</I> %s</H2>\n",
    cbCosmidName, xa->qStart, xa->qEnd, target);


htmlParagraph("<I>C. briggsae</I> appears on top. Coding regions in <I>C. elegans</I> are in upper case.");


/* Get display window. */
if (!wormParseChromRange(target, &chrom, &tStart, &tEnd))
    errAbort("Target %s isn't formatted correctly", target);

/* Figure out intersection of display window and xeno-alignment */
bothStart = max(xa->tStart, tStart);
bothEnd = min(xa->tEnd, tEnd);

/* Get upper-cased-exon target DNA. */
targetDna = wormChromPartExonsUpper(chrom, bothStart, bothEnd - bothStart);
upcCorresponding(targetDna, bothEnd - bothStart, xa->tSym, bothStart - xa->tStart);


printf("<TT><PRE>");
showTargetRange(xa, bothStart - xa->tStart, bothEnd-bothStart, strand, showSym);
printf("</TT></PRE>");
}
Example #2
0
void doFuzzyFind()
/* Do fuzzy-finder alignment. */
{
char *bacAcc = cgiString("bacAcc");
char *repeatMask = cgiString("repeatMask");
int contig = cgiInt("contig");
int qStart = cgiInt("qStart");
int qSize = cgiInt("qSize");
int tStart = cgiInt("tStart");
int tSize = cgiInt("tSize");
showDetailedMatch(bacAcc, contig, qStart, qSize, tStart, tSize, repeatMask);
}
void checkYbr(char *agpFile, char *faFile, char *mdFile)
/* checkYbr - Check NCBI assembly (aka Yellow Brick Road). */
{
struct hash *hash = newHash(0);
struct contig *contigList = NULL, *contig;
int problemCount = 0;

contigList = contigsFromAgp(agpFile, hash);
printf("Read %d contigs from %s\n", slCount(contigList), agpFile);
if (cgiVarExists("checkUs"))
    {
    printf("Checking our fa files for size\n");
    checkOurDir(cgiString("checkUs"), contigList, hash);
    }
else
    {
    problemCount += flagMd(mdFile, hash);
    printf("Verifying sequence sizes in %s\n", faFile);
    problemCount += flagFa(faFile, hash);
    for (contig = contigList; contig != NULL; contig = contig->next)
	{
	if (contig->gotFa && contig->gotMd)
	    continue;
	++problemCount;
	if (!contig->gotFa)
	    printf("No %s in %s\n", contig->name, faFile);
	if (!contig->gotMd)
	    printf("No %s in %s\n", contig->name, mdFile);
	}
    printf("%d problems detected\n", problemCount);
    }
}
Example #4
0
void stopUpload(struct sqlConnection *conn)
/* Try and stop current upload. */
{
char *url = trimSpaces(cgiString("url"));
cgiMakeHiddenVar("url", url);
struct edwSubmit *sub = edwMostRecentSubmission(conn, url);
if (sub == NULL)
    {
    /* Submission hasn't happened yet - remove it from job queue. */
    unsigned edwSubmitJobId = 0;
    int posInQueue = edwSubmitPositionInQueue(conn, url, &edwSubmitJobId);
    if (posInQueue >= 0)
        {
	char query[256];
	sqlSafef(query, sizeof(query), "delete from edwSubmitJob where id=%u", edwSubmitJobId);
	sqlUpdate(conn, query);
	printf("Removed submission from %s from job queue\n", url);
	}
    }
else
    {
    char query[256];
    sqlSafef(query, sizeof(query), 
	"update edwSubmit set errorMessage='Stopped by user.' where id=%u", sub->id);
    sqlUpdate(conn, query);
    }
monitorSubmission(conn);
}
void doMiddle()
{
char *preIntron, *startIntron, *endIntron, *postIntron;
int count = 0;
int matchCount = 0;
int maxCount;
struct nameOff *matchList;
boolean invert = cgiVarExists("Invert");

preIntron = cgiString("preIntron");
startIntron = cgiString("startIntron");
endIntron = cgiString("endIntron");
postIntron = cgiString("postIntron");

/* Just for debugging cut search short if matches special magic */
maxCount = atoi(preIntron);
if (maxCount <= 0)
    maxCount = 0x7ffffff;


eraseWhiteSpace(preIntron);
eraseWhiteSpace(startIntron);
eraseWhiteSpace(endIntron);
eraseWhiteSpace(postIntron);

tolowers(preIntron);
tolowers(startIntron);
tolowers(endIntron);
tolowers(postIntron);

matchList = scanIntronFile(preIntron, startIntron, endIntron, postIntron, invert);
if (matchList == NULL)
    errAbort("Sorry, no matches to %s%s %s %s %s", (invert ? "inverted " : ""), preIntron, startIntron, endIntron, postIntron);
printf("<P>%d introns matching %s%s(%s %s)%s. ", slCount(matchList),
    (invert ? "inverted " : ""), preIntron, startIntron, endIntron, postIntron);
printf("Shortcut to <A HREF=\"#1\">frequency counts.</A></P>");

htmlHorizontalLine();
showMatches(matchList);
htmlHorizontalLine();
printf("<TT><PRE>");
printf("<A NAME=\"1\"></A>");
printAllHistograms();
printf("</TT></PRE>");
}
Example #6
0
struct edwScriptRegistry *edwScriptRegistryFromCgi()
/* Get script registery from cgi variables.  Does authentication too. */
{
struct sqlConnection *conn = edwConnect();
char *user = sqlEscapeString(cgiString("user"));
char *password = sqlEscapeString(cgiString("password"));
char query[256];
sqlSafef(query, sizeof(query), "select * from edwScriptRegistry where name='%s'", user);
struct edwScriptRegistry *reg = edwScriptRegistryLoadByQuery(conn, query);
if (reg == NULL)
    accessDenied();
char key[EDW_SID_SIZE];
edwMakeSid(password, key);
if (!sameString(reg->secretHash, key))
    accessDenied();
sqlDisconnect(&conn);
return reg;
}
Example #7
0
void doMiddle()
{
char *commandLine = cgiString("commandLine");
char *words[50];
int wordCount;
wordCount = chopString(commandLine, whiteSpaceChopper, words, ArraySize(words));
printf("<PRE>");
test(wordCount, words);
printf("</PRE>");
}
Example #8
0
int main(int argc, char *argv[])
{
char *geneName;
char title[256];

if (argc == 2 && sameWord(argv[1], "test"))
    putenv("QUERY_STRING=geneName=I:4000-5500&hiliteNear=0.917112&intronsLowerCase=On");
geneName = cgiString("geneName");
sprintf(title, "%s DNA Sequence", geneName);
dnaUtilOpen();
htmShell(title, doMiddle, "QUERY");
return 0;
}
Example #9
0
void doMiddle()
/* Print middle parts of web page.  Get database and transcript
 * ID from CGI, and print info about that transcript. */
{
char *transId = cgiString("transId");
char *db = cgiString("db");
struct knownInfo *ki, *kiList = NULL;
struct sqlConnection *conn = sqlConnect(db);
struct sqlResult *sr;
char **row;
char query[256];

/* Get a list of all that have that ID. */
sqlSafef(query, sizeof query, "select * from knownInfo where transId = '%s'", transId);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    ki = knownInfoLoad(row);
    slAddHead(&kiList, ki);
    }
sqlFreeResult(&sr);
slReverse(&kiList);

/* Print title that says how many match. */
printf("<H2>Transcript %s - %d match</H2>\n", transId, slCount(kiList));

/* Print some info for each match */
for (ki = kiList; ki != NULL; ki = ki->next)
    {
    printf("<B>geneId</B>: %s<BR>\n", ki->geneId);
    printf("<B>geneName</B>: %s<BR>\n", 
    	lookupName(conn, "geneName", ki->geneName));
    /*  ~~~ Todo: fill in other info.  ~~~ */
    }

knownInfoFreeList(&kiList);
sqlDisconnect(&conn);
}
Example #10
0
void doMiddle()
/* Write HTML file to stdout. */
{
char *mapName;
if ((mapName = cgiOptionalString("map")) != NULL)
    {
    printf("<TT>\n");
    doMap(mapName);
    }
else if (cgiVarExists("contig"))
    {
    doFuzzyFind();
    }
else
    {
    char *bacAcc = cgiString("bacAcc");
    char *repeatMask = cgiString("repeatMask");
    int trim = cgiInt("trim");
    if (trim < 0)
        trim = 0;
    bacTrack(bacAcc, trim, repeatMask);
    }
}
int main(int argc, char *argv[])
/* Process command line. */
{
struct hash *liftHash = NULL;
cgiSpoof(&argc, argv);
if (argc != 6)
    usage();
if (cgiVarExists("spacing"))
    chromInsertsSetDefaultGapSize(cgiInt("spacing"));
if (cgiVarExists("lift"))
    liftHash = readLift(cgiString("lift"));
ctgToChromFa(argv[1], argv[2], argv[3], argv[4], argv[5], liftHash);
return 0;
}
int main(int argc, char *argv[])
{
struct altGraphX *agList = NULL;
int cassetteCount = 0;
float minConfidence = 0;
char *bedFileName = NULL;
char *faFile = NULL;
FILE *faOut = NULL;
FILE *bedOut = NULL;
boolean mrnaFilter = FALSE;
float estPrior = 0.0;
int minSize = 0;
if(argc < 4)
    usage();
cgiSpoof(&argc, argv);
warn("Loading graphs.");
agList = altGraphXLoadAll(argv[1]);
bedFileName = cgiOptionalString("bedFile");
minConfidence = cgiDouble("minConf");
db = cgiString("db");
faFile = cgiOptionalString("faFile");
estPrior = cgiOptionalDouble("estPrior", 10);
minSize = cgiOptionalInt("minSize", 0);
mrnaFilter = cgiBoolean("mrnaFilter");
if(mrnaFilter)
    loadMrnaHash();
warn("Counting cassette exons from %d clusters above confidence: %f", slCount(agList), minConfidence);
if(bedFileName != NULL)
    {
    bedOut = mustOpen(bedFileName, "w");
    printCommandState(argc, argv, bedOut);
    fprintf(bedOut, "track name=cass_conf-%4.2f_est-%3.2f description=\"spliceStats minConf=%4.2f estPrior=%3.2f minSize=%d\"\n", 
	    minConfidence, estPrior, minConfidence, estPrior, minSize);
    }
if(faFile != NULL)
    faOut = mustOpen(faFile, "w");
cassetteCount = countCassetteExons(agList, minConfidence, faOut,bedOut );
carefulClose(&faOut);
carefulClose(&bedOut);
warn("%d cassette exons out of %d clusters in %s", cassetteCount, slCount(agList), argv[1]);
altGraphXFreeList(&agList);
return 0;
}
Example #13
0
void submitUrl(struct sqlConnection *conn)
/* Submit validated manifest if it is not already in process.  Show
 * progress once it is in progress. */
{
/* Parse email and URL out of CGI vars. Do a tiny bit of error checking. */
char *url = trimSpaces(cgiString("url"));
if (!stringIn("://", url))
    errAbort("%s doesn't seem to be a valid URL, no '://'", url);

/* Do some reality checks that email and URL actually exist. */
edwMustGetUserFromEmail(conn, userEmail);
int sd = netUrlMustOpenPastHeader(url);
close(sd);

edwAddSubmitJob(conn, userEmail, url, cgiBoolean("update"));

/* Give the system a half second to react and then put up status info about submission */
sleep1000(1000);
monitorSubmission(conn);
}
void autoXml(char *dtdxFile, char *outRoot)
/* autoXml - Generate structures code and parser for XML file from DTD-like spec. */
{
struct dtdElement *elList = NULL;
struct hash *elHash = NULL;
char hName[512], cName[512];
char outDir[256];

splitPath(outRoot, outDir, prefix, NULL);
if (cgiVarExists("prefix"))
    strcpy(prefix, cgiString("prefix"));
if (outDir[0] != 0)
    makeDir(outDir);
dtdParse(dtdxFile, prefix, textField, &elList, &elHash);
printf("Parsed %d elements in %s\n", slCount(elList), dtdxFile);
sprintf(hName, "%s.h", outRoot);
makeH(elList, hName);
sprintf(cName, "%s.c", outRoot);
makeC(elList, cName, hName);
printf("Generated code in %s\n", cName);
}
Example #15
0
int main(int argc, char *argv[])
{
long enteredMainTime = clock1000();
measureTime(NULL);
browserName = hBrowserName();
organization = "UCSC";

/* Push very early error handling - this is just
 * for the benefit of the cgiVarExists, which
 * somehow can't be moved effectively into doMiddle. */
htmlPushEarlyHandlers();
cgiSpoof(&argc, argv);
char * link = webTimeStampedLinkToResourceOnFirstCall("HGStyle.css",TRUE); // resource file link
if (link)                                                                  // wrapped in html
    htmlSetStyle(link);

oldVars = hashNew(10);

if (cgiVarExists("hgt.redirectTool"))
    {
    printf("Content-type: text/html\n\n");
    errAbortSetDoContentType(FALSE);
    cart = cartForSession(hUserCookie(), NULL, NULL);
    extToolRedirect(cart, cgiString("hgt.redirectTool"));
    }
else
    cartHtmlShell("UCSC Genome Browser v"CGI_VERSION, doMiddle, hUserCookie(), excludeVars, oldVars);

if (measureTiming)
    measureTime("Time to write and close cart");
if (measureTiming)
    {
    fprintf(stdout, "<span class='timing'>Overall total time: %ld millis<br /></span>\n",
            clock1000() - enteredMainTime);
    }
cgiExitTime("hgTracks", enteredMainTime);
return 0;
}
Example #16
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;
}
Example #17
0
int main(int argc, char *argv[])
{
long enteredMainTime = clock1000();
struct dyString *output = newDyString(10000);

setUdcCacheDir();
cgiSpoof(&argc, argv);
pushWarnHandler(htmlVaBadRequestAbort);
pushAbortHandler(htmlVaBadRequestAbort);

char *database = cgiString("db");
char *cmd = cgiString("cmd");
char *jsonp = cgiOptionalString("jsonp");
if (!hDbExists(database))
    errAbort("Invalid database '%s'", database);

if (!strcmp(cmd, "defaultPos"))
    {
    dyStringPrintf(output, "{\"pos\": \"%s\"}", hDefaultPos(database));
    }
else if (!strcmp(cmd, "metaDb"))
    {
    // Return list of values for given metaDb var
    // e.g. http://genome.ucsc.edu/hgApi?db=hg18&cmd=metaDb&var=cell

    struct sqlConnection *conn = hAllocConn(database);
    boolean metaDbExists = sqlTableExists(conn, "metaDb");
    if (metaDbExists)
        {
        char *var = cgiOptionalString("var");
        if (!var)
            errAbort("Missing var parameter");
        boolean fileSearch = (cgiOptionalInt("fileSearch",0) == 1);
        struct slPair *pairs = mdbValLabelSearch(conn, var, MDB_VAL_STD_TRUNCATION, FALSE,
                                                 !fileSearch, fileSearch);
        struct slPair *pair;
        dyStringPrintf(output, "[\n");
        for (pair = pairs; pair != NULL; pair = pair->next)
            {
            if (pair != pairs)
                dyStringPrintf(output, ",\n");
            dyStringPrintf(output, "['%s','%s']", javaScriptLiteralEncode(mdbPairLabel(pair)),
                           javaScriptLiteralEncode(mdbPairVal(pair)));
            }
        dyStringPrintf(output, "\n]\n");
        }
    else
        errAbort("Assembly does not support metaDb");
    }
// TODO: move to lib since hgTracks and hgApi share
#define METADATA_VALUE_PREFIX    "hgt_mdbVal"
else if (startsWith(METADATA_VALUE_PREFIX, cmd))
    {
    // Returns metaDb value control: drop down or free text, with or without help link.
    // e.g. http://genome.ucsc.edu/hgApi?db=hg18&cmd=hgt_mdbVal3&var=cell

    // TODO: Move guts to lib, so that hgTracks::searchTracks.c and hgApi.c can share

    struct sqlConnection *conn = hAllocConn(database);
    boolean metaDbExists = sqlTableExists(conn, "metaDb");
    if (metaDbExists)
        {
        char *var = cgiOptionalString("var");
        if (!var)
            errAbort("Missing var parameter");

        int ix = atoi(cmd+strlen(METADATA_VALUE_PREFIX)); // 1 based index
        if (ix == 0) //
            errAbort("Unsupported 'cmd' parameter");

        enum cvSearchable searchBy = cvSearchMethod(var);
        char name[128];
        safef(name,sizeof name,"%s%i",METADATA_VALUE_PREFIX,ix);
        if (searchBy == cvSearchBySingleSelect || searchBy == cvSearchByMultiSelect)
            {
            boolean fileSearch = (cgiOptionalInt("fileSearch",0) == 1);
            struct slPair *pairs = mdbValLabelSearch(conn, var, MDB_VAL_STD_TRUNCATION, FALSE,
                                                     !fileSearch, fileSearch);
            if (slCount(pairs) > 0)
                {
                char *dropDownHtml =
                                cgiMakeSelectDropList((searchBy == cvSearchByMultiSelect),
                                                      name, pairs, NULL, ANYLABEL, "mdbVal",
                                                      "style='min-width: 200px; font-size: .9em;' "
                                                      "onchange='findTracksMdbValChanged(this);'");
                if (dropDownHtml)
                    {
                    dyStringAppend(output,dropDownHtml);
                    freeMem(dropDownHtml);
                    }
                slPairFreeList(&pairs);
                }
            }
        else if (searchBy == cvSearchByFreeText)
            {
            dyStringPrintf(output,"<input type='text' name='%s' value='' class='mdbVal freeText' "
                           "onchange='findTracksMdbValChanged(this);' style='max-width:310px; "
                           "width:310px; font-size:.9em;'>", name);
            }
        else if (searchBy == cvSearchByWildList)
            {
            dyStringPrintf(output,"<input type='text' name='%s' value='' class='mdbVal wildList' "
                           "title='enter comma separated list of values' "
                           "onchange='findTracksMdbValChanged(this);' style='max-width:310px; "
                           "width:310px; font-size:.9em;'>", name);
            }
        else if (searchBy == cvSearchByDateRange || searchBy == cvSearchByIntegerRange)
            {
            // TO BE IMPLEMENTED
            }
        else
            errAbort("Metadata variable not searchable");

        dyStringPrintf(output,"<span id='helpLink%i'>&nbsp;</span>",ix);
        }
    else
        errAbort("Assembly does not support metaDb");
    }
else if (!strcmp(cmd, "tableMetadata"))
    { // returns an html table with metadata for a given track
    char *trackName = cgiOptionalString("track");
    boolean showLonglabel = (NULL != cgiOptionalString("showLonglabel"));
    boolean showShortLabel = (NULL != cgiOptionalString("showShortLabel"));
    if (trackName != NULL)
        {
        // hTrackDbForTrackAndAncestors avoids overhead of getting whole track list!
        struct trackDb *tdb = hTrackDbForTrackAndAncestors(database, trackName);
        if (tdb != NULL)
            {
            char * html = metadataAsHtmlTable(database,tdb,showLonglabel,showShortLabel);
            if (html)
                {
                dyStringAppend(output,html);
                freeMem(html);
                }
            else
                dyStringPrintf(output,"No metadata found for track %s.",trackName);
            }
        else
            dyStringPrintf(output,"Track %s not found",trackName);
        }
    else
        dyStringAppend(output,"No track variable found");
    }
else if (sameString(cmd, "codonToPos") || sameString(cmd, "exonToPos"))
    {
    char query[256];
    struct sqlResult *sr;
    char **row;
    struct genePred *gp;
    char *name = cgiString("name");
    char *table = cgiString("table");
    int num = cgiInt("num");
    struct sqlConnection *conn = hAllocConn(database);
    sqlSafef(query, sizeof(query), "select name, chrom, strand, txStart, txEnd, cdsStart, cdsEnd, exonCount, exonStarts, exonEnds from %s where name = '%s'", table, name);
    sr = sqlGetResult(conn, query);
    if ((row = sqlNextRow(sr)) != NULL)
        {
        gp = genePredLoad(row);
        boolean found;
        int start, end;
        if (sameString(cmd, "codonToPos"))
            found = codonToPos(gp, num, &start, &end);
        else
            found = exonToPos(gp, num, &start, &end);
        if (found)
            dyStringPrintf(output, "{\"pos\": \"%s:%d-%d\"}", gp->chrom, start + 1, end);
        else
            dyStringPrintf(output, "{\"error\": \"%d is an invalid %s for this gene\"}", num, sameString(cmd, "codonToPos") ? "codon" : "exon");
        }
    else
        dyStringPrintf(output, "{\"error\": \"Couldn't find item: %s\"}", name);
    sqlFreeResult(&sr);
    hFreeConn(&conn);
    }
else
    {
    warn("unknown cmd: %s",cmd);
    errAbort("Unsupported 'cmd' parameter");
    }

apiOut(dyStringContents(output), jsonp);
cgiExitTime("hgApi", enteredMainTime);
return 0;
}
Example #18
0
void doMiddle()
{
char *seqName;
boolean intronsLowerCase = TRUE;
boolean intronsParenthesized = FALSE;
boolean hiliteNear = FALSE;
int startRange = 0;
int endRange = 0;
boolean gotRange = FALSE;
struct dnaSeq *cdnaSeq;
boolean isChromRange = FALSE;
DNA *dna;
char *translation = NULL;

seqName = cgiString("geneName");
seqName = trimSpaces(seqName);
if (cgiVarExists("intronsLowerCase"))
    intronsLowerCase = cgiBoolean("intronsLowerCase");
if (cgiVarExists("intronsParenthesized"))
    intronsParenthesized = cgiBoolean("intronsParenthesized");
if (cgiVarExists("startRange") && cgiVarExists("endRange" ))
    {
    startRange = cgiInt("startRange");
    endRange = cgiInt("endRange");
    gotRange = TRUE;
    }
if (cgiVarExists("hiliteNear"))
    {
    hiliteNear = TRUE;
    }
fprintf(stdout, "<P><TT>\n");

/* The logic here is a little complex to optimize speed.
 * If we can decide what type of thing the name refers to by
 * simply looking at the name we do.  Otherwise we have to
 * search the database in various ways until we get a hit. */
if (wormIsNamelessCluster(seqName))
    {
    isChromRange = TRUE;
    }
else if (wormIsChromRange(seqName))
    {
    isChromRange = TRUE;
    }
else if (getWormGeneDna(seqName, &dna, TRUE))
    {
    if (cgiBoolean("litLink"))
        {
        char nameBuf[64];
        char *geneName = NULL;
        char *productName = NULL;
        char *coding;
        int transSize;
        struct wormCdnaInfo info;

        printf("<H3>Information and Links for %s</H3>\n", seqName);
        if (wormInfoForGene(seqName, &info))
            {
            if (info.description)
                printf("<P>%s</P>\n", info.description);
            geneName = info.gene;
            productName = info.product;
            }
        else
            {
            if (wormIsGeneName(seqName))
                geneName = seqName;
            else if (wormGeneForOrf(seqName, nameBuf, sizeof(nameBuf)))
                geneName = nameBuf;
            }
        coding = cloneUpperOnly(dna);
        transSize = 1 + (strlen(coding)+2)/3;
        translation = needMem(1+strlen(coding)/3);
        dnaTranslateSome(coding, translation, transSize);
        freez(&coding);

        if (geneName)
            {
            printf("<A HREF=\"http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query?form=4&db=m"
                    "&term=C+elegans+%s&dispmax=50&relentrezdate=No+Limit\">", geneName);
            printf("PubMed search on gene: </A>%s<BR>\n", geneName);
            }
        if (productName)
            {
            char *encoded = cgiEncode(productName);
            printf("<A HREF=\"http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query?form=4&db=m"
                    "&term=%s&dispmax=50&relentrezdate=No+Limit\">", encoded);
            printf("PubMed search on product:</A> %s<BR>\n", productName);
            freeMem(encoded);
            }
        /* Process name to get rid of isoform letter for Proteome. */
        if (geneName)
            strcpy(nameBuf, geneName);
        else
            {
            strcpy(nameBuf, seqName);
#ifdef NEVER
            /* Sometimes Proteome requires the letter after the orf name
             * in alt-spliced cases, sometimes it can't handle it.... */
            nameLen = strlen(nameBuf);
            if (wormIsOrfName(nameBuf) && isalpha(nameBuf[nameLen-1]))
                {
                char *dotPos = strrchr(nameBuf, '.');
                if (dotPos != NULL && isdigit(dotPos[1]))
                    nameBuf[nameLen-1] = 0;
                }
#endif /* NEVER */
            }
	printf("<A HREF=\"http://www.wormbase.org/db/seq/sequence?name=%s;class=Sequence\">", seqName);
	printf("WormBase link on:</A> %s<BR>\n", seqName);
        printf("<A HREF=\"http://www.proteome.com/databases/WormPD/reports/%s.html\">", nameBuf);
        printf("Proteome link on:</A> %s<BR>\n<BR>\n", nameBuf);


        printf("<A HREF=#DNA>Genomic DNA Sequence</A><BR>\n");
        if (hiliteNear)
            printf("<A HREF=\"#CLICKED\">Shortcut to where you clicked in gene</A><BR>");
        printf("<A HREF=#protein>Translated Protein Sequence</A><BR>\n");
        htmlHorizontalLine();
	printf("<A NAME=DNA></A>");
        printf("<H3>%s Genomic DNA sequence</H3>", seqName);
        }
    if (!intronsLowerCase)
        tolowers(dna);
    if (hiliteNear)
	{
	if (!gotRange)
	    {
	    double nearPos = cgiDouble("hiliteNear");
	    int rad = 5;
	    int dnaSize = strlen(dna);
	    long mid = (int)(dnaSize * nearPos);
	    startRange = mid - rad;
	    if (startRange < 0) startRange = 0;
	    endRange = mid + rad;
	    if (endRange >= dnaSize) endRange = dnaSize - 1;
	    }
	}
    outputSeq(dna, strlen(dna), hiliteNear, startRange, endRange, stdout);
    freez(&dna);
    }
else if (wormCdnaSeq(seqName, &cdnaSeq, NULL))
    {
    outputSeq(cdnaSeq->dna, cdnaSeq->size, FALSE, 0, 0, stdout);
    }
else
    {
    isChromRange = TRUE;
    }
if (isChromRange)
    {
    char *chromId;
    int start, end;
    char strand = '+';
    int size;

    if (!wormGeneRange(seqName, &chromId, &strand, &start, &end))
        errAbort("Can't find %s",seqName);
    size = end - start;
    if (intronsLowerCase)
        dna = wormChromPartExonsUpper(chromId, start, size);
    else
        {
        dna = wormChromPart(chromId, start, size);
        touppers(dna);
        }
    if (cgiVarExists("strand"))
        strand = cgiString("strand")[0];
    if (strand == '-')
        reverseComplement(dna, size);
    outputSeq(dna, size, FALSE, 0, 0, stdout);
    }
if (translation != NULL)
    {
    htmlHorizontalLine();
    printf("<A NAME=protein></A>");
    printf("<H3>Translated Protein of %s</H3>\n", seqName);
    outputSeq(translation, strlen(translation), FALSE, 0, 0, stdout);
    freez(&translation);
    }
fprintf(stdout, "</TT></P>\n");

}
Example #19
0
void blatSeq(char *userSeq, char *organism)
/* Blat sequence user pasted in. */
{
FILE *f;
struct dnaSeq *seqList = NULL, *seq;
struct tempName pslTn, faTn;
int maxSingleSize, maxTotalSize, maxSeqCount;
int minSingleSize = minMatchShown;
char *genome, *db;
char *type = cgiString("type");
char *seqLetters = cloneString(userSeq);
struct serverTable *serve;
int conn;
int oneSize, totalSize = 0, seqCount = 0;
boolean isTx = FALSE;
boolean isTxTx = FALSE;
boolean txTxBoth = FALSE;
struct gfOutput *gvo;
boolean qIsProt = FALSE;
enum gfType qType, tType;
struct hash *tFileCache = gfFileCacheNew();
boolean feelingLucky = cgiBoolean("Lucky");

getDbAndGenome(cart, &db, &genome, oldVars);
if(!feelingLucky)
    cartWebStart(cart, db, "%s BLAT Results",  trackHubSkipHubName(organism));
/* Load user sequence and figure out if it is DNA or protein. */
if (sameWord(type, "DNA"))
    {
    seqList = faSeqListFromMemText(seqLetters, TRUE);
    uToT(seqList);
    isTx = FALSE;
    }
else if (sameWord(type, "translated RNA") || sameWord(type, "translated DNA"))
    {
    seqList = faSeqListFromMemText(seqLetters, TRUE);
    uToT(seqList);
    isTx = TRUE;
    isTxTx = TRUE;
    txTxBoth = sameWord(type, "translated DNA");
    }
else if (sameWord(type, "protein"))
    {
    seqList = faSeqListFromMemText(seqLetters, FALSE);
    isTx = TRUE;
    qIsProt = TRUE;
    }
else 
    {
    seqList = faSeqListFromMemTextRaw(seqLetters);
    isTx = !seqIsDna(seqList);
    if (!isTx)
	{
	for (seq = seqList; seq != NULL; seq = seq->next)
	    {
	    seq->size = dnaFilteredSize(seq->dna);
	    dnaFilter(seq->dna, seq->dna);
	    toLowerN(seq->dna, seq->size);
	    subChar(seq->dna, 'u', 't');
	    }
	}
    else
	{
	for (seq = seqList; seq != NULL; seq = seq->next)
	    {
	    seq->size = aaFilteredSize(seq->dna);
	    aaFilter(seq->dna, seq->dna);
	    toUpperN(seq->dna, seq->size);
	    }
	qIsProt = TRUE;
	}
    }
if (seqList != NULL && seqList->name[0] == 0)
    {
    freeMem(seqList->name);
    seqList->name = cloneString("YourSeq");
    }
trimUniq(seqList);

/* If feeling lucky only do the first on. */
if(feelingLucky && seqList != NULL)
    {
    seqList->next = NULL;
    }

/* Figure out size allowed. */
maxSingleSize = (isTx ? 10000 : 75000);
maxTotalSize = maxSingleSize * 2.5;
#ifdef LOWELAB
maxSeqCount = 200;
#else
maxSeqCount = 25;
#endif

/* Create temporary file to store sequence. */
trashDirFile(&faTn, "hgSs", "hgSs", ".fa");
faWriteAll(faTn.forCgi, seqList);

/* Create a temporary .psl file with the alignments against genome. */
trashDirFile(&pslTn, "hgSs", "hgSs", ".pslx");
f = mustOpen(pslTn.forCgi, "w");
gvo = gfOutputPsl(0, qIsProt, FALSE, f, FALSE, TRUE);
serve = findServer(db, isTx);
/* Write header for extended (possibly protein) psl file. */
if (isTx)
    {
    if (isTxTx)
        {
	qType = gftDnaX;
	tType = gftDnaX;
	}
    else
        {
	qType = gftProt;
	tType = gftDnaX;
	}
    }
else
    {
    qType = gftDna;
    tType = gftDna;
    }
pslxWriteHead(f, qType, tType);

if (qType == gftProt)
    {
    minSingleSize = 14;
    }
else if (qType == gftDnaX)
    {
    minSingleSize = 36;
    }


/* Loop through each sequence. */
for (seq = seqList; seq != NULL; seq = seq->next)
    {
    printf(" "); fflush(stdout);  /* prevent apache cgi timeout by outputting something */
    oneSize = realSeqSize(seq, !isTx);
    if ((seqCount&1) == 0)	// Call bot delay every 2nd time starting with first time
	hgBotDelay();
    if (++seqCount > maxSeqCount)
        {
	warn("More than 25 input sequences, stopping at %s.",
	    seq->name);
	break;
	}
    if (oneSize > maxSingleSize)
	{
	warn("Sequence %s is %d letters long (max is %d), skipping",
	    seq->name, oneSize, maxSingleSize);
	continue;
	}
    if (oneSize < minSingleSize)
        {
	warn("Warning: Sequence %s is only %d letters long (%d is the recommended minimum)", 
		seq->name, oneSize, minSingleSize);
	// we could use "continue;" here to actually enforce skipping, 
	// but let's give the short sequence a chance, it might work.
	// minimum possible length = tileSize+stepSize, so mpl=16 for dna stepSize=5, mpl=10 for protein.
	if (qIsProt && oneSize < 1) // protein does not tolerate oneSize==0
	    continue;
	}
    totalSize += oneSize;
    if (totalSize > maxTotalSize)
        {
	warn("Sequence %s would take us over the %d letter limit, stopping here.",
	     seq->name, maxTotalSize);
	break;
	}
    conn = gfConnect(serve->host, serve->port);
    if (isTx)
	{
	gvo->reportTargetStrand = TRUE;
	if (isTxTx)
	    {
	    gfAlignTransTrans(&conn, serve->nibDir, seq, FALSE, 5, 
	    	tFileCache, gvo, !txTxBoth);
	    if (txTxBoth)
		{
		reverseComplement(seq->dna, seq->size);
		conn = gfConnect(serve->host, serve->port);
		gfAlignTransTrans(&conn, serve->nibDir, seq, TRUE, 5, 
			tFileCache, gvo, FALSE);
		}
	    }
	else
	    {
	    gfAlignTrans(&conn, serve->nibDir, seq, 5, tFileCache, gvo);
	    }
	}
    else
	{
	gfAlignStrand(&conn, serve->nibDir, seq, FALSE, minMatchShown, tFileCache, gvo);
	reverseComplement(seq->dna, seq->size);
	conn = gfConnect(serve->host, serve->port);
	gfAlignStrand(&conn, serve->nibDir, seq, TRUE, minMatchShown, tFileCache, gvo);
	}
    gfOutputQuery(gvo, f);
    }
carefulClose(&f);
showAliPlaces(pslTn.forCgi, faTn.forCgi, serve->db, qType, tType, 
	      organism, feelingLucky);
if(!feelingLucky)
    cartWebEnd();
gfFileCacheFree(&tFileCache);
}
Example #20
0
void doMiddle()
/* Write what goes between BODY and /BODY */
{
pushWarnHandler(localWarn);
if (!cgiServerHttpsIsOn())
     usage();
struct sqlConnection *conn = edwConnectReadWrite();
printf("<FORM ACTION=\"edwWebRegisterScript\" METHOD=POST>\n");
printf("<B>Register Script with ENCODE Data Warehouse</B><BR>\n");
#ifdef SOON
uglyf("HTTP_AUTHENTICATION: '%s'<BR>\n", getenv("HTTP_AUTHENTICATION"));
uglyf("HTTP_AUTHORIZATION: '%s'<BR>\n", getenv("HTTP_AUTHORIZATION"));
dumpEnv(mainEnv);
#endif
if (userEmail == NULL)
    {
    printf("Please sign in:");
    printf("<INPUT TYPE=BUTTON NAME=\"signIn\" VALUE=\"sign in\" id=\"signin\">");
    }
else if (cgiVarExists("description"))
    {
    struct edwUser *user = edwUserFromEmail(conn, userEmail);
    if (user == NULL)
	edwWarnUnregisteredUser(userEmail);
    else
	{
	char password[HEXED_32_SIZE];
	edwRandomHexed32(password);
	char babyName[HEXED_32_SIZE];
	edwRandomBabble(babyName, sizeof(babyName));

	edwRegisterScript(conn, user, babyName, password, cgiString("description"));
	printf("Script now registered.<BR>\n");
	printf("The script user name is %s.<BR>\n", babyName);
	printf("The script password is %s.<BR>\n", password);
	printf("Please save the script user name and password somewhere. ");
	puts("Please pass these two and the URL");
	puts(" of your validated manifest file (validated.txt) to our server to submit data.");
	puts("Construct a URL of the form:<BR>");
	printf("<PRE>https://encodedcc.sdsc.edu/cgi-bin/edwScriptSubmit"
	       "?user=%s&password=%s&url=%s\n</PRE>", 
	       babyName, password,
	       cgiEncode("http://your.host.edu/your_dir/validated.txt"));
	puts("That is pass the CGI encoded variables user, password, and url to the ");
	puts("web services CGI at");
	puts("https://encodedcc.sdsc.edu/cgi-bin/edwScriptSubmit. ");
	puts("You can use the http://encodedcc.sdsc.edu/cgi-bin/edwWebBrowse site to ");
	puts("monitor your submission interactively. Please contact your wrangler if you ");
	puts("have any questions.<BR>");
	cgiMakeButton("submit", "Register another script");
	}
    printf(" ");
    edwPrintLogOutButton();
    }
else
    {
    struct edwUser *user = edwUserFromEmail(conn, userEmail);
    edwPrintLogOutButton();
    if (user == NULL)
	edwWarnUnregisteredUser(userEmail);
    else
	{
	printf("%s is authorized to register a new script<BR>\n", userEmail);
	printf("<BR>Script description:\n");
	cgiMakeTextVar("description", NULL, 80);
	cgiMakeSubmitButton();
	}
    }
printf("</FORM>\n");
}
Example #21
0
void edwScriptSubmitStatus()
/* edwScriptSubmitStatus - Programatically check status of submission.. */
{
/* Pause a second - prevent inadvertent harsh denial of service from scripts. */
sleep(2);

edwScriptRegistryFromCgi();

/* Get submission from url. */
struct sqlConnection *conn = edwConnect();
char query[512];
char *url = cgiString("url");
struct edwSubmit *sub = edwMostRecentSubmission(conn, url);
char *status = NULL;
if (sub == NULL)
    {
    int posInQueue = edwSubmitPositionInQueue(conn, url, NULL);
    if (posInQueue == -1)
         errAbort("%s has not been submitted", url);
    else
         status = "pending";
    }
else
    {
    time_t endUploadTime = sub->endUploadTime;
    if (!isEmpty(sub->errorMessage))
        {
	status = "error";
	}
    else if (endUploadTime == 0)  
	{
	status = "uploading";
	}
    else
        {
	safef(query, sizeof(query), 
	    "select count(*) from edwFile where submitId=%u and errorMessage != ''",
	    sub->id);
	int errCount = sqlQuickNum(conn, query);
	int newValid = edwSubmitCountNewValid(sub, conn);
	if (newValid + errCount < sub->newFiles)
	    status = "validating";
	else if (errCount > 0)
	    status = "error";
	else
	    status = "success";
	}
    }

/* Construct JSON result */
struct dyString *dy = dyStringNew(0);
dyStringPrintf(dy, "{\n");
dyStringPrintf(dy, "    \"status\": \"%s\"", status);
if (sameString(status, "error"))
    {
    dyStringPrintf(dy, ",\n");
    dyStringPrintf(dy, "    \"errors\": [\n");
    int errCount = 0;
    if (!isEmpty(sub->errorMessage))
        {
	addErrFile(dy, errCount, sub->url, sub->errorMessage);
	++errCount;
	}
    safef(query, sizeof(query), "select * from edwFile where submitId=%u and errorMessage != ''",
	sub->id);
    struct edwFile *file, *fileList = edwFileLoadByQuery(conn, query);
    for (file = fileList; file != NULL; file = file->next)
        {
	addErrFile(dy, errCount, file->submitFileName, file->errorMessage);
	++errCount;
	}
    dyStringPrintf(dy, "\n    ]\n");
    dyStringPrintf(dy, "}\n");
    }
else
    {
    dyStringPrintf(dy, "\n}\n");
    }

/* Write out HTTP response */
printf("Content-Length: %d\r\n", dy->stringSize);
puts("Content-Type: application/json; charset=UTF-8\r");
puts("\r");
printf("%s", dy->string);
}
void doMiddle(struct cart *theCart)
/* Set up globals and make web page */
{
/* struct liftOverChain *chainList = NULL, *chain; */
char *userData;
/* char *dataFile; */
char *dataFormat;
char *organism;
char *db;
float minBlocks, minMatch;
boolean multiple, fudgeThick;
int minSizeQ, minSizeT;
boolean refreshOnly = FALSE;

/* char *err = NULL; */
struct liftOverChain *chainList = NULL, *choice;

cart = theCart;

if (cgiOptionalString(HGLFT_ERRORHELP_VAR))
    {
    puts("<PRE>");
    puts(liftOverErrHelp());
    //system("/usr/bin/cal");
    puts("</PRE>");
    return;
    }

/* Get data to convert - from userData variable, or if 
 * that is empty from a file. */

if (cartOptionalString(cart, "SubmitFile"))
    userData = cartOptionalString(cart, HGLFT_DATAFILE_VAR);
else
    userData = cartOptionalString(cart, HGLFT_USERDATA_VAR);
dataFormat = cartCgiUsualString(cart, HGLFT_DATAFORMAT_VAR, DEFAULT_FORMAT);
cartWebStart(cart, NULL, "Lift Genome Annotations");

getDbAndGenome(cart, &db, &organism, oldVars);

chainList = liftOverChainListFiltered();

choice = defaultChoices(chainList, db);
if (choice == NULL)
    errAbort("Sorry, no conversions available from this assembly\n");

minSizeQ = cartCgiUsualInt(cart, HGLFT_MINSIZEQ, choice->minSizeQ);
minSizeT = cartCgiUsualInt(cart, HGLFT_MINSIZET, choice->minSizeT);
minBlocks = cartCgiUsualDouble(cart, HGLFT_MINBLOCKS, choice->minBlocks);
minMatch = cartCgiUsualDouble(cart, HGLFT_MINMATCH, choice->minMatch);
fudgeThick = cartCgiUsualBoolean(cart, HGLFT_FUDGETHICK, (choice->fudgeThick[0]=='Y') ? TRUE : FALSE);
multiple = cartCgiUsualBoolean(cart, HGLFT_MULTIPLE, (choice->multiple[0]=='Y') ? TRUE : FALSE);
refreshOnly = cartCgiUsualInt(cart, HGLFT_REFRESHONLY_VAR, 0);

webMain(choice, dataFormat, multiple);
liftOverChainFreeList(&chainList);

if (!refreshOnly && userData != NULL && userData[0] != '\0')
    {
    struct hash *chainHash = newHash(0);
    char *chainFile;
    struct tempName oldTn, mappedTn, unmappedTn;
    FILE *old, *mapped, *unmapped;
    char *line;
    int lineSize;
    char *fromDb, *toDb;
    int ct = 0, errCt = 0;

    /* read in user data and save to file */
    makeTempName(&oldTn, HGLFT, ".user");
    old = mustOpen(oldTn.forCgi, "w");
    fputs(userData, old);
    fputs("\n", old);           /* in case user doesn't end last line */
    carefulClose(&old);
    chmod(oldTn.forCgi, 0666);

    /* setup output files -- one for converted lines, the other
     * for lines that could not be mapped */
    makeTempName(&mappedTn, HGLFT, ".bed");
    makeTempName(&unmappedTn, HGLFT, ".err");
    mapped = mustOpen(mappedTn.forCgi, "w");
    chmod(mappedTn.forCgi, 0666);
    unmapped = mustOpen(unmappedTn.forCgi, "w");
    chmod(unmappedTn.forCgi, 0666);

    fromDb = cgiString(HGLFT_FROMDB_VAR);
    toDb = cgiString(HGLFT_TODB_VAR);
    chainFile = liftOverChainFile(fromDb, toDb);
    if (chainFile == NULL)
        errAbort("ERROR: Can't convert from %s to %s: no chain file loaded",
                                fromDb, toDb);
    readLiftOverMap(chainFile, chainHash);
    if (sameString(dataFormat, WIGGLE_FORMAT))
        /* TODO: implement Wiggle */
	{}
    else if (sameString(dataFormat, POSITION_FORMAT))
	{
	/* minSizeT here and in liftOverChain.c/h has been renamed minChainT in liftOver.c */
	/* ignore multiple, it must be false when position is used */
	ct = liftOverPositions(oldTn.forCgi, chainHash, 
			minMatch, minBlocks, 0, minSizeQ,
			minSizeT, 0, 
			fudgeThick, mapped, unmapped, FALSE, NULL, &errCt);

	
        }
    else if (sameString(dataFormat, BED_FORMAT))
        {
	/* minSizeT here and in liftOverChain.c/h has been renamed minChainT in liftOver.c */
        ct = liftOverBed(oldTn.forCgi, chainHash, 
			minMatch, minBlocks, 0, minSizeQ,
			minSizeT, 0,
			fudgeThick, mapped, unmapped, multiple, NULL, &errCt);
        }
    else
        /* programming error */
        errAbort("ERROR: Unsupported data format: %s\n", dataFormat);

    webNewSection("Results");
    if (ct)
        {
        /* some records succesfully converted */
        cgiParagraph("");
        printf("Successfully converted %d record", ct);
        printf("%s: ", ct > 1 ? "s" : "");
        printf("<A HREF=%s TARGET=_blank>View Conversions</A>\n", mappedTn.forCgi);
        }
    if (errCt)
        {
        /* some records not converted */
        cgiParagraph("");
        printf("Conversion failed on %d record", errCt);
        printf("%s. &nbsp;&nbsp;&nbsp;", errCt > 1 ? "s" : "");
        printf("<A HREF=%s TARGET=_blank>Display failure file</A>&nbsp; &nbsp;\n",
                         unmappedTn.forCgi);
        printf("<A HREF=\"../cgi-bin/hgLiftOver?%s=1\" TARGET=_blank>Explain failure messages</A>\n", HGLFT_ERRORHELP_VAR);
        puts("<P>Failed input regions:\n");
        struct lineFile *errFile = lineFileOpen(unmappedTn.forCgi, TRUE);
        puts("<BLOCKQUOTE><PRE>\n");
        while (lineFileNext(errFile, &line, &lineSize))
            puts(line);
        lineFileClose(&errFile);
        puts("</PRE></BLOCKQUOTE>\n");
        }
    if (sameString(dataFormat, POSITION_FORMAT) && multiple)
	{
        puts("<BLOCKQUOTE><PRE>\n");
        puts("Note: multiple checkbox ignored since it is not supported for position format.");
        puts("</PRE></BLOCKQUOTE>\n");
	}
    carefulClose(&unmapped);
    }
webDataFormats();
webDownloads();
cartWebEnd();
}
Example #23
0
void tryToDeprecate(struct sqlConnection *conn)
/* CGI variables are set - if possible deprecate, otherwise put up error message. */
{
pushWarnHandler(localWarn);
fileList = cgiString("fileList");
reason = cloneString(trimSpaces(cgiString("reason")));
if (isEmpty(reason))
   {
   warn("Please enter a reason for deprecation.");
   getFileListAndReason(conn);
   }
else
   {
   /* Go through list of accessions and make sure they are all well formed and correspond to files that exist. */
   boolean ok = TRUE;
   struct slName *accList = slNameListOfUniqueWords(cloneString(fileList), FALSE);
   struct slName *acc;
   struct slInt *idList = NULL, *idEl;
   for (acc = accList; acc != NULL; acc = acc->next)
       {
       char *licensePlate = acc->name;
       if (!startsWith(edwLicensePlatePrefix, licensePlate))
           {
	   ok = FALSE;
	   warn("%s is not an accession, doesn't start with %s", licensePlate, edwLicensePlatePrefix);
	   break;
	   }
	char query[256];
	sqlSafef(query, sizeof(query), "select fileId from edwValidFile where licensePlate='%s'", licensePlate);
	int id = sqlQuickNum(conn, query);
	if (id == 0)
	   {
	   ok = FALSE;
	   warn("%s - no such accession. ", licensePlate);
	   break;
	   }
	/* check to see is it ok tor deprecate this file */
	if (!okToDeprecateThisFile(conn, id, userEmail))
	    {
	    ok = FALSE;
	    warn("You can not deprecate %s which was originally uploaded by %s.\n",
	    licensePlate, edwFindOwnerNameFromFileId(conn, id));
	    warn("Please click the check box below to override this rule.");
	    break;
	    }

	idEl = slIntNew(id);
	slAddTail(&idList, idEl);
	}

    if (accList == NULL)
        {
	warn("Please enter some file accessions");
	ok = FALSE;
	}

    /* If a problem then put up page to try again,   otherwise do deprecation. */
    if (!ok)
        getFileListAndReason(conn);
    else
        {
	deprecateFileList(conn, idList, reason);
	printf("Deprecated %d files<BR>\n", slCount(idList));
	cgiMakeButton("submit", "Deprecate More Files");
	printf(" ");
	edwPrintLogOutButton();
	}
    }
}
static void hgSeqConcatRegionsDb(char *db, char *chrom, int chromSize, char strand, char *name,
                                 int rCount, unsigned *rStarts, unsigned *rSizes,
                                 boolean *exonFlags, boolean *cdsFlags)
/* Concatenate and print out dna for a series of regions. */
{
// Note: this code use to generate different sequence ids if the global
// database in hdb was different than the db parameter.  This functionality
// has been removed since the global database was removed and it didn't
// appear to be used.

    struct dnaSeq *rSeq = NULL;
    struct dnaSeq *cSeq = NULL;
    char recName[256];
    int seqStart, seqEnd;
    int offset, cSize;
    int i;
    boolean isRc     = (strand == '-') || cgiBoolean("hgSeq.revComp");
    boolean maskRep  = cgiBoolean("hgSeq.maskRepeats");
    int padding5     = cgiOptionalInt("hgSeq.padding5", 0);
    int padding3     = cgiOptionalInt("hgSeq.padding3", 0);
    char *casing     = cgiString("hgSeq.casing");
    char *repMasking = cgiString("hgSeq.repMasking");
    char *granularity  = cgiOptionalString("hgSeq.granularity");
    boolean concatRegions = granularity && sameString("gene", granularity);

    if (rCount < 1)
        return;

    /* Don't support padding if granularity is gene (i.e. concat'ing all). */
    if (concatRegions)
    {
        padding5 = padding3 = 0;
    }

    i = rCount - 1;
    seqStart = rStarts[0]             - (isRc ? padding3 : padding5);
    seqEnd   = rStarts[i] + rSizes[i] + (isRc ? padding5 : padding3);
    /* Padding might push us off the edge of the chrom; if so, truncate: */
    if (seqStart < 0)
    {
        if (isRc)
            padding3 += seqStart;
        else
            padding5 += seqStart;
        seqStart = 0;
    }

    /* if we know the chromSize, don't pad out beyond it */
    if ((chromSize > 0) && (seqEnd > chromSize))
    {
        if (isRc)
            padding5 += (chromSize - seqEnd);
        else
            padding3 += (chromSize - seqEnd);
        seqEnd = chromSize;
    }
    if (seqEnd <= seqStart)
    {
        printf("# Null range for %s_%s (range=%s:%d-%d 5'pad=%d 3'pad=%d) (may indicate a query-side insert)\n",
               db,
               name,
               chrom, seqStart+1, seqEnd,
               padding5, padding3);
        return;
    }
    if (maskRep)
    {
        rSeq = hDnaFromSeq(db, chrom, seqStart, seqEnd, dnaMixed);
        if (sameString(repMasking, "N"))
            lowerToN(rSeq->dna, strlen(rSeq->dna));
        if (!sameString(casing, "upper"))
            tolowers(rSeq->dna);
    }
    else if (sameString(casing, "upper"))
        rSeq = hDnaFromSeq(db, chrom, seqStart, seqEnd, dnaUpper);
    else
        rSeq = hDnaFromSeq(db, chrom, seqStart, seqEnd, dnaLower);

    /* Handle casing and compute size of concatenated sequence */
    cSize = 0;
    for (i=0;  i < rCount;  i++)
    {
        if ((sameString(casing, "exon") && exonFlags[i]) ||
                (sameString(casing, "cds") && cdsFlags[i]))
        {
            int rStart = rStarts[i] - seqStart;
            toUpperN(rSeq->dna+rStart, rSizes[i]);
        }
        cSize += rSizes[i];
    }
    cSize += (padding5 + padding3);
    AllocVar(cSeq);
    cSeq->dna = needLargeMem(cSize+1);
    cSeq->size = cSize;

    offset = 0;
    for (i=0;  i < rCount;  i++)
    {
        int start = rStarts[i] - seqStart;
        int size  = rSizes[i];
        if (i == 0)
        {
            start -= (isRc ? padding3 : padding5);
            assert(start == 0);
            size  += (isRc ? padding3 : padding5);
        }
        if (i == rCount-1)
        {
            size  += (isRc ? padding5 : padding3);
        }
        memcpy(cSeq->dna+offset, rSeq->dna+start, size);
        offset += size;
    }
    assert(offset == cSeq->size);
    cSeq->dna[offset] = 0;
    freeDnaSeq(&rSeq);

    if (isRc)
        reverseComplement(cSeq->dna, cSeq->size);

    safef(recName, sizeof(recName),
          "%s_%s range=%s:%d-%d 5'pad=%d 3'pad=%d "
          "strand=%c repeatMasking=%s",
          db,
          name,
          chrom, seqStart+1, seqEnd,
          padding5, padding3,
          (isRc ? '-' : '+'),
          (maskRep ? repMasking : "none"));
    faWriteNext(stdout, recName, cSeq->dna, cSeq->size);
    freeDnaSeq(&cSeq);
}
Example #25
0
void monitorSubmission(struct sqlConnection *conn)
/* Write out information about submission. */
{
char *url = trimSpaces(cgiString("url"));
cgiMakeHiddenVar("url", url);
struct edwSubmit *sub = edwMostRecentSubmission(conn, url);
time_t startTime = 0, endTime = 0, endUploadTime = 0;
if (sub == NULL)
    {
    int posInQueue = edwSubmitPositionInQueue(conn, url, NULL);
    if (posInQueue == 0)
	printf("%s is first in the submission queue, but upload has not started<BR>\n", url);
    else if (posInQueue > 0)
        printf("%s is in submission queue with %d submissions ahead of it<BR>\n", url, posInQueue);
    else
	{
        printf("%s status unknown.", url);
	}
    }
else
    {
    startTime = sub->startUploadTime;
    endUploadTime = sub->endUploadTime;
    endTime = (endUploadTime ? endUploadTime : edwNow());
    int timeSpan = endTime - startTime;
    long long thisUploadSize = sub->byteCount - sub->oldBytes;
    long long curSize = 0;  // Amount of current file we know we've transferred.

    /* Print title letting them know if upload is done or in progress. */
    printf("<B>Submission by %s is ", userEmail);
    if (!isEmpty(sub->errorMessage))
	{
	if (endUploadTime == 0)
	    printf("having problems...");
	else
	    printf("stopped by uploader request.");
	}
    else if (endUploadTime != 0)  
	{
        printf("uploaded.");
	}
    else
	printf("in progress...");
    printf("</B><BR>\n");

    /* Print URL and how far along we are at the file level. */
    if (!isEmpty(sub->errorMessage))
	{
	printf("<B>error:</B> %s<BR>\n", sub->errorMessage);
	cgiMakeButton("getUrl", "try submission again");
	printf("<BR>");
	}
    printf("<B>url:</B> %s<BR>\n", sub->url);
    printf("<B>files count:</B> %d<BR>\n", sub->fileCount);
    if (sub->oldFiles > 0)
	printf("<B>files already in warehouse:</B> %u<BR>\n", sub->oldFiles);
    if (sub->metaChangeCount > 0)
        printf("<B>old files with new tags in this submission</B> %d<BR>", sub->metaChangeCount);
    if (sub->oldFiles != sub->fileCount)
	{
	printf("<B>files transferred:</B> %u<BR>\n", sub->newFiles);
	printf("<B>files remaining:</B> %u<BR>\n", sub->fileCount - sub->oldFiles - sub->newFiles);
	}

    /* Report validation status */
    printf("<B>new files validated:</B> %u of %u<BR>\n", edwSubmitCountNewValid(sub, conn), 
	sub->newFiles);

    /* Print error message, and in case of error skip file-in-transfer info. */
    if (isEmpty(sub->errorMessage))
	{
	/* If possible print information about file en route */
	if (endUploadTime == 0)
	    {
	    struct edwFile *ef = edwFileInProgress(conn, sub->id);
	    if (ef != NULL)
		{
		char path[PATH_LEN];
		safef(path, sizeof(path), "%s%s", edwRootDir, ef->edwFileName);
		if (ef->endUploadTime > 0)
		    curSize = ef->size;
		else
		    curSize = paraFetchedSoFar(path);
		printf("<B>file in route:</B> %s",  ef->submitFileName);
		printf(" (%d%% transferred)<BR>\n", (int)(100.0 * curSize / ef->size));
		}
	    }
	}
    /* Report bytes transferred */
    long long transferredThisTime = curSize + sub->newBytes;
    printf("<B>total bytes transferred:</B> ");
    long long totalTransferred = transferredThisTime + sub->oldBytes;
    printLongWithCommas(stdout, totalTransferred);
    printf(" of ");
    printLongWithCommas(stdout, sub->byteCount);
    if (sub->byteCount != 0)
	printf(" (%d%%)<BR>\n", (int)(100.0 * totalTransferred / sub->byteCount));
    else
        printf("<BR>\n");

    /* Report transfer speed if possible */
    if (isEmpty(sub->errorMessage))
	{
	if (timeSpan > 0)
	    {
	    printf("<B>transfer speed:</B> ");
	    printLongWithCommas(stdout, (curSize + sub->newBytes)/timeSpan);
	    printf(" bytes/sec<BR>\n");
	    }

	/* Report start time  and duration */
	printf("<B>submission started:</B> %s<BR>\n", ctime(&startTime));
	struct dyString *duration = edwFormatDuration(timeSpan);

	/* Try and give them an ETA if we aren't finished */
	if (endUploadTime == 0 && timeSpan > 0)
	    {
	    printf("<B>time so far:</B> %s<BR>\n", duration->string);
	    double bytesPerSecond = (double)transferredThisTime/timeSpan;
	    long long bytesRemaining = thisUploadSize - curSize - sub->newBytes;
	    if (bytesPerSecond > 0)
		{
		long long estimatedFinish = bytesRemaining/bytesPerSecond;
		struct dyString *eta = edwFormatDuration(estimatedFinish);
		printf("<B>estimated finish in:</B> %s<BR>\n", eta->string);
		}
	    }
	else
	    {
	    printf("<B>submission time:</B> %s<BR>\n", duration->string);
	    cgiMakeButton("getUrl", "submit another data set");
	    }
	}
    }
cgiMakeButton("monitor", "refresh status");
if (endUploadTime == 0 && isEmpty(sub->errorMessage))
    cgiMakeButton(stopButtonName, "stop upload");
printf(" <input type=\"button\" value=\"browse submissions\" "
       "onclick=\"window.location.href='edwWebBrowse';\">\n");

edwPrintLogOutButton();
}