4898794edd81be5285ea6e544acbedeaeb31bf78
max
Tue Nov 23 08:10:57 2021 -0800
Fixing pointers to README file for license in all source code files. refs #27614
diff --git src/hg/encode3/encodeDataWarehouse/edwWebBrowse/edwWebBrowse.c src/hg/encode3/encodeDataWarehouse/edwWebBrowse/edwWebBrowse.c
index 25dcfc3..018533d 100644
--- src/hg/encode3/encodeDataWarehouse/edwWebBrowse/edwWebBrowse.c
+++ src/hg/encode3/encodeDataWarehouse/edwWebBrowse/edwWebBrowse.c
@@ -1,486 +1,486 @@
/* edwWebBrowse - Browse ENCODE data warehouse.. */
/* Copyright (C) 2014 The Regents of the University of California
- * See README in this or parent directory for licensing information. */
+ * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
#include "common.h"
#include "linefile.h"
#include "hash.h"
#include "options.h"
#include "cheapcgi.h"
#include "htmshell.h"
#include "portable.h"
#include "paraFetch.h"
#include "encodeDataWarehouse.h"
#include "edwLib.h"
void usage()
/* Explain usage and exit. */
{
errAbort(
"edwWebBrowse is a cgi script not meant to be run from command line.\n"
);
}
char *userEmail = NULL; /* User's email handle. */
boolean noPrevSubmission; /* No previous submission */
boolean queryIntoTable(struct sqlConnection *conn, char *query, char *title, struct hash *wraps)
/* Make query and show result in a html table. Return FALSE (and make no output)
* if there is no result to query. */
{
boolean didHeader = FALSE;
struct sqlResult *sr = sqlGetResult(conn, query);
int colCount = sqlCountColumns(sr);
char *fields[colCount];
if (colCount > 0)
{
char **row;
while ((row = sqlNextRow(sr)) != NULL)
{
if (!didHeader)
{
printf("
%s
\n", title);
printf("
\n");
printf("
");
char *field;
int fieldIx = 0;
while ((field = sqlFieldName(sr)) != NULL)
{
fields[fieldIx++] = cloneString(field);
printf("
%s
", field);
}
printf("
\n");
didHeader = TRUE;
}
printf("
");
int i;
for (i=0; i");
boolean done = FALSE;
if (wraps != NULL)
{
char *format = hashFindVal(wraps, fields[i]);
char *val = row[i];
if (format != NULL && val != NULL)
{
printf(format, val, val);
done = TRUE;
}
}
if (!done)
printf("%s", naForNull(row[i]));
printf("");
}
printf("
\n");
}
printf("
\n");
}
sqlFreeResult(&sr);
return didHeader;
}
void printSubmitState(struct edwSubmit *submit, struct sqlConnection *conn)
/* Try and summarize submission status in a short statement. */
{
if (!isEmpty(submit->errorMessage))
printf("has problems");
else if (submit->endUploadTime != 0)
{
int validCount = edwSubmitCountNewValid(submit, conn);
if (validCount == submit->newFiles)
{
printf("is uploaded and validated"); // Would be nice to report enrichment/qa status here
}
else
{
printf("is uploaded and is being validated");
}
}
else /* Upload not complete. */
{
long long lastAlive = edwSubmitMaxStartTime(submit, conn);
struct edwFile *ef = edwFileInProgress(conn, submit->id);
long long now = edwNow();
if (ef != NULL)
{
char path[PATH_LEN];
safef(path, sizeof(path), "%s%s", edwRootDir, ef->edwFileName);
if (ef->endUploadTime > 0)
lastAlive = fileModTime(path);
else
lastAlive = paraFetchTempUpdateTime(path);
}
long long duration = now - lastAlive;
long long oneHourInSeconds = 60*60;
// uglyf("now %lld, lastAlive %lld, duration %lld, oneHourInSeconds %lld \n", now, lastAlive, duration, oneHourInSeconds);
if (duration < oneHourInSeconds)
{
struct dyString *time = edwFormatDuration(now - submit->startUploadTime);
printf("has been in progress for %s", time->string);
}
else
{
struct dyString *time = edwFormatDuration(duration);
printf("has been stalled for %s", time->string);
dyStringFree(&time);
}
}
}
void printSubmitSummary(struct edwSubmit *submit, struct sqlConnection *conn)
/* Print a little summary information about the submission overall */
{
if (!isEmpty(submit->errorMessage))
printf("%s \n", submit->errorMessage);
printf("%d files in validated.txt including %d already in warehouse \n",
submit->fileCount, submit->oldFiles);
if (submit->newFiles > 0)
printf("%d of %d new files are uploaded \n", submit->newFiles,
submit->fileCount-submit->oldFiles);
else
printf("No file in validated.txt has been uploaded or validated again \n");
if (submit->metaChangeCount != 0)
printf("%d of %d old files have updated tags \n",
submit->metaChangeCount, submit->oldFiles);
int newValid = edwSubmitCountNewValid(submit, conn);
if (submit->newFiles > 0)
printf("%d of %d uploaded files are validated \n", newValid, submit->newFiles);
}
struct edwValidFile *newReplicatesList(struct edwSubmit *submit, struct sqlConnection *conn)
/* Return list of new files in submission that are supposed to be part of replicated set. */
{
char query[256];
sqlSafef(query, sizeof(query),
"select v.* from edwFile f,edwValidFile v"
" where f.id = v.fileId and f.submitId=%u and v.replicate != '' and v.replicate != 'n/a' "
" and v.replicate != 'pooled'",
// If expanding this list of special replicate case, remember to expand bits in
// edwMakeReplicateQa as well
submit->id);
return edwValidFileLoadByQuery(conn, query);
}
boolean matchInListExceptSelf(struct edwValidFile *v, struct edwValidFile *list)
/* Return TRUE if there's something in list that is a different replica than ours */
{
struct edwValidFile *el;
for (el = list; el != NULL; el = el->next)
{
if (sameString(el->format, v->format) && sameString(el->outputType, el->outputType)
&& sameString(el->experiment, v->experiment) && !sameString(el->replicate, v->replicate))
{
return TRUE;
}
}
return FALSE;
}
static void countPairings(struct sqlConnection *conn, struct edwValidFile *replicatesList,
int *retOldPairs, int *retInnerPairs, int *retUnpaired,
int *retPairCount, int *retPairsDone)
/* Show users files grouped by submission sorted with most recent first. */
{
int oldPairs = 0, innerPairs = 0, unpaired = 0, pairCount = 0, pairsDone = 0;
struct edwValidFile *v;
for (v = replicatesList; v != NULL; v = v->next)
{
struct edwValidFile *elderList = edwFindElderReplicates(conn, v);
boolean isInternallyReplicated = matchInListExceptSelf(v, replicatesList);
if (isInternallyReplicated)
++innerPairs;
else if (elderList != NULL)
++oldPairs;
else
++unpaired;
struct edwValidFile *ev;
for (ev = elderList; ev != NULL; ev = ev->next)
{
char query[256];
boolean onePairDone = FALSE;
sqlSafef(query, sizeof(query),
"select count(*) from edwQaPairCorrelation"
" where elderFileId=%lld and youngerFileId=%lld"
, (long long)ev->fileId, (long long)v->fileId);
if (sqlQuickNum(conn, query) > 0)
onePairDone = TRUE;
else
{
sqlSafef(query, sizeof(query),
"select count(*) from edwQaPairSampleOverlap"
" where elderFileId=%lld and youngerFileId=%lld"
, (long long)ev->fileId, (long long)v->fileId);
if (sqlQuickNum(conn, query) > 0)
onePairDone = TRUE;
}
if (onePairDone)
++pairsDone;
pairCount += 1;
}
}
*retOldPairs = oldPairs, *retInnerPairs=innerPairs;
*retUnpaired = unpaired, *retPairCount = pairCount, *retPairsDone = pairsDone;
}
void slNameToCharArray(struct slName *list, int *retCount, char ***retArray)
/* Return an array filled with the strings in list. */
{
int count = slCount(list);
char **array = NULL;
if (count != 0)
{
AllocArray(array, count);
int i;
struct slName *el;
for (i=0, el=list; el != NULL; el = el->next, ++i)
array[i] = el->name;
}
else /* No submission record from this user */
{
AllocArray(array, 1);
array[0] = userEmail;
count = 1;
noPrevSubmission = TRUE;
}
*retCount = count;
*retArray = array;
}
char *printUserControl(struct sqlConnection *conn, char *cgiVarName, char *defaultUser)
/* Print out control and return currently selected user. */
{
char query[256];
if (edwUserIsAdmin(conn,userEmail))
sqlSafef(query, sizeof(query),
"select distinct email from edwUser,edwSubmit where edwUser.id = edwSubmit.userId order by email");
else
sqlSafef(query, sizeof(query),
"select distinct email from edwUser,edwSubmit where edwUser.id = edwSubmit.userId and email='%s' order by email", defaultUser);
struct slName *userList = sqlQuickList(conn, query);
int userCount = 0;
char **userArray;
slNameToCharArray(userList, &userCount, &userArray);
char *curUser = cgiUsualString(cgiVarName, defaultUser);
cgiMakeDropList(cgiVarName, userArray, userCount, curUser);
freez(&userArray);
return curUser;
}
void showRecentFiles(struct sqlConnection *conn)
/* Show users files grouped by submission sorted with most recent first. */
{
char *user = userEmail;
if (edwUserIsAdmin(conn, userEmail))
{
printf("
");
printf("Select whose files to browse: ");
user = printUserControl(conn, "selectUser", userEmail);
printf("
");
}
puts("
");
puts("Maximum number of submissions to view: ");
/* Get user choice from CGI var or cookie */
int maxSubCount = 0;
if (!cgiVarExists("maxSubCount"))
{
char *subs = findCookieData("edwWeb.maxSubCount");
if (subs)
maxSubCount = atoi(subs);
}
if (maxSubCount == 0)
maxSubCount = cgiOptionalInt("maxSubCount", 3);
cgiMakeIntVar("maxSubCount", maxSubCount, 3);
puts(" ");
cgiMakeButton("Submit", "update view");
puts("
");
/* Get id for user. */
char query[1024];
sqlSafef(query, sizeof(query), "select id from edwUser where email='%s'", user);
int userId = sqlQuickNum(conn, query);
if (userId == 0)
{
printf("No user with email %s. Contact your wrangler to make an account", user);
return;
}
/* Select all submissions, most recent first. */
sqlSafef(query, sizeof(query),
"select * from edwSubmit where userId=%d "
"and (newFiles != 0 or metaChangeCount != 0 or errorMessage is not NULL or fileIdInTransit != 0)"
" order by id desc limit %d", userId, maxSubCount);
struct edwSubmit *submit, *submitList = edwSubmitLoadByQuery(conn, query);
int printedSubCount = 0;
if (noPrevSubmission)
{
printf("
There are no files submitted by %s
\n",user);
return;
}
for (submit = submitList; submit != NULL; submit = submit->next)
{
/* Figure out and print upload time */
sqlSafef(query, sizeof(query),
"select from_unixtime(startUploadTime) from edwSubmit where id=%u", submit->id);
char *dateTime = sqlQuickString(conn, query);
printf("
\n");
/* Print a little summary information about the submission overall */
printSubmitSummary(submit, conn);
}
}
void doMiddle()
/* Write what goes between BODY and /BODY */
{
userEmail = edwGetEmailAndVerify();
noPrevSubmission = FALSE;
if (userEmail == NULL)
printf("
Welcome to the ENCODE data submission browser
\n");
else
printf("
Browse submissions
\n");
edwWebBrowseMenuItem(FALSE);
printf("
");
if (userEmail == NULL)
{
edwWebSubmitMenuItem(FALSE);
printf("Please sign in with Persona ");
printf("");
}
printf("
");
printf("\n");
#ifdef AUTO_REFRESH
// auto-refresh page
if (userEmail != NULL && !cgiOptionalString("noRefresh"))
edwWebAutoRefresh(5000);
#endif
}
int main(int argc, char *argv[])
/* Process command line. */
{
boolean isFromWeb = cgiIsOnWeb();
if (!isFromWeb && !cgiSpoof(&argc, argv))
usage();
if (cgiVarExists("maxSubCount"))
htmlSetCookie("edwWeb.maxSubCount", cgiString("maxSubCount"), NULL, NULL, NULL, FALSE);
edwWebHeaderWithPersona("");
// TODO: find a better place for menu update
htmEmptyShell(doMiddle, NULL);
edwWebFooterWithPersona();
return 0;
}