Ejemplo n.º 1
0
void hgTrackDb(char *org, char *database, char *trackDbName, char *sqlFile, char *hgRoot,
               boolean strict)
/* hgTrackDb - Create trackDb table from text files. */
{
struct trackDb *td;
char tab[PATH_LEN];
safef(tab, sizeof(tab), "%s.tab", trackDbName);

struct trackDb *tdbList = buildTrackDb(org, database, hgRoot, strict);
tdbList = flatten(tdbList);
slSort(&tdbList, trackDbCmp);
verbose(1, "Loaded %d track descriptions total\n", slCount(tdbList));

/* Write to tab-separated file; hold off on html, since it must be encoded */
    {
    verbose(2, "Starting write of tabs to %s\n", tab);
    FILE *f = mustOpen(tab, "w");
    for (td = tdbList; td != NULL; td = td->next)
        {
        hVarSubstTrackDb(td, database);
        char *hold = td->html;
        td->html = "";
	subChar(td->type, '\t', ' ');	/* Tabs confuse things. */
	subChar(td->shortLabel, '\t', ' ');	/* Tabs confuse things. */
	subChar(td->longLabel, '\t', ' ');	/* Tabs confuse things. */
	trackDbTabOut(td, f);
        td->html = hold;
        }
    carefulClose(&f);
    verbose(2, "Wrote tab representation to %s\n", tab);
    }

/* Update database */
    {
    char *create, *end;
    char query[256];
    struct sqlConnection *conn = sqlConnect(database);

    /* Load in table definition. */
    readInGulp(sqlFile, &create, NULL);
    create = trimSpaces(create);
    create = substituteTrackName(create, trackDbName);
    end = create + strlen(create)-1;
    if (*end == ';') *end = 0;
    sqlRemakeTable(conn, trackDbName, create);

    /* Load in regular fields. */
    sqlSafef(query, sizeof(query), "load data local infile '%s' into table %s", tab, trackDbName);
    verbose(2, "sending mysql \"%s\"\n", query);
    sqlUpdate(conn, query);
    verbose(2, "done tab file load");

    /* Load in html and settings fields. */
    for (td = tdbList; td != NULL; td = td->next)
	{
        if (isEmpty(td->html))
	    {
	    if (strict && !trackDbLocalSetting(td, "parent") && !trackDbLocalSetting(td, "superTrack") &&
	        !sameString(td->track,"cytoBandIdeo"))
		{
		fprintf(stderr, "Warning: html missing for %s %s %s '%s'\n",org, database, td->track, td->shortLabel);
		}
	    }
	else
	    {
	    updateBigTextField(conn,  trackDbName, "tableName", td->track, "html", td->html);
	    }
	if (td->settingsHash != NULL)
	    {
	    char *settings = settingsFromHash(td->settingsHash);
	    updateBigTextField(conn, trackDbName, "tableName", td->track,
	        "settings", settings);
	    if (showSettings)
		{
		verbose(1, "%s: type='%s';", td->track, td->type);
		if (isNotEmpty(settings))
		    {
		    char *oneLine = replaceChars(settings, "\n", "; ");
		    eraseTrailingSpaces(oneLine);
		    verbose(1, " %s", oneLine);
		    freeMem(oneLine);
		    }
		verbose(1, "\n");
		}
	    freeMem(settings);
	    }
	}

    sqlDisconnect(&conn);
    verbose(1, "Loaded database %s\n", database);
    }
}
Ejemplo n.º 2
0
void hgFindSpec(char *org, char *database, char *hgFindSpecName, char *sqlFile,
                char *hgRoot, boolean strict)
/* hgFindSpec - Create hgFindSpec table from text files. */
{
    struct hash *uniqHash = newHash(8);
    struct hash *htmlHash = newHash(8);
    struct hgFindSpec *hfsList = NULL, *hfs;
    char rootDir[512], orgDir[512], asmDir[512];
    char tab[512];
    snprintf(tab, sizeof(tab), "%s.tab", hgFindSpecName);

    /* Create track list from hgRoot and hgRoot/org and hgRoot/org/assembly
     * ra format database. */
    sprintf(rootDir, "%s", hgRoot);
    sprintf(orgDir, "%s/%s", hgRoot, org);
    sprintf(asmDir, "%s/%s/%s", hgRoot, org, database);
    layerOn(strict, database, asmDir, uniqHash, htmlHash, FALSE, &hfsList);
    layerOn(strict, database, orgDir, uniqHash, htmlHash, FALSE, &hfsList);
    layerOn(strict, database, rootDir, uniqHash, htmlHash, TRUE, &hfsList);
    slSort(&hfsList, hgFindSpecCmp);
    if (verboseLevel() > 0)
        printf("Loaded %d search specs total\n", slCount(hfsList));

    /* Write to tab-separated file. */
    {
        FILE *f = mustOpen(tab, "w");
        for (hfs = hfsList; hfs != NULL; hfs = hfs->next)
            hgFindSpecTabOut(hfs, f);
        carefulClose(&f);
    }

    /* Update database */
    {
        char *create, *end;
        char query[256];
        struct sqlConnection *conn = sqlConnect(database);

        /* Load in table definition. */
        readInGulp(sqlFile, &create, NULL);
        create = trimSpaces(create);
        create = subTrackName(create, hgFindSpecName);
        end = create + strlen(create)-1;
        if (*end == ';') *end = 0;
        sqlRemakeTable(conn, hgFindSpecName, create);

        /* Load in regular fields. */
        sqlSafef(query, sizeof query, "load data local infile '%s' into table %s", tab,
                 hgFindSpecName);
        sqlUpdate(conn, query);

        /* Load in settings fields. */
        for (hfs = hfsList; hfs != NULL; hfs = hfs->next)
        {
            if (hfs->settingsHash != NULL)
            {
                char *settings = settingsFromHash(hfs->settingsHash);
                updateBigTextField(conn, hgFindSpecName, "searchName",
                                   hfs->searchName,
                                   "searchSettings", settings);
                freeMem(settings);
            }
        }

        sqlDisconnect(&conn);
        if (verboseLevel() > 0)
            printf("Loaded database %s\n", database);
    }
}