示例#1
0
void metaNodeAddVarVals(struct metaNode *node, char *varVals)
/* Add string of var=vals to node */
{
if (varVals == NULL)
    return;
struct slPair *pair, *pairList = slPairListFromString(varVals, FALSE);
for (pair = pairList; pair != NULL; pair = pair->next)
    metaNodeAddVar(node, pair->name, pair->val);
}
示例#2
0
static struct hash *buildCompositeHash(char *database,struct trackDb *tdbList)
/* Create a hash of all composite tracks.  This is keyed by their name with
 * subGroupData values. */
{
struct hash *compositeHash = newHash(8);

/* process all composite tracks */
struct trackDb *td, *tdNext;
for (td = tdbList; td != NULL; td = tdNext)
    {
    tdNext = td->next;
    if (trackDbLocalSetting(td, "compositeTrack"))
	{
	int i;
	struct subGroupData *sgd;
        char subGroupName[256];
        AllocVar(sgd);
	sgd->compositeTdb = td;

	verbose(3,"getting subgroups for %s\n", td->track);
	for(i=1; ; i++)
	    {
	    safef(subGroupName, sizeof(subGroupName), "subGroup%d", i);
	    char *sgSetting = trackDbSetting(td, subGroupName);
	    if (!sgSetting)
		break;
            sgSetting = cloneString(sgSetting);
            char *sgWord = sgSetting;
            char *sgName = nextWord(&sgWord);
            validateTag(database,td,subGroupName,sgName,TRUE);
            nextWord(&sgWord);  /* skip word not used */
            struct hash *subGroupHash = newHash(3);
            struct slPair *slPair, *slPairList = slPairListFromString(sgWord,TRUE); // respect ""
            for (slPair = slPairList; slPair; slPair = slPair->next)
                {
                validateTag(database,td,sgName,slPair->name,TRUE);
                hashAdd(subGroupHash, slPair->name, slPair->val);
                }
            if (sgd->nameHash == NULL)
		sgd->nameHash = newHash(3);
	    verbose(3,"   adding group %s\n", sgName);
	    hashAdd(sgd->nameHash, sgName, subGroupHash);
	    }
	hashAdd(compositeHash, td->track, sgd);
	}
    }
return compositeHash;
}
示例#3
0
文件: hash.c 项目: davidhoover/kent
struct hash *hashFromString(char *string)
/* parse a whitespace-separated string with tuples in the format name=val or
 * name="val" to a hash name->val */
{
if (string==NULL)
    return NULL;

struct slPair *keyVals = slPairListFromString(string, TRUE);
if (keyVals==NULL)
    return NULL;

struct hash *nameToVal = newHash(0);
struct slPair *kv;
for (kv = keyVals; kv != NULL; kv = kv->next)
    hashAdd(nameToVal, kv->name, kv->val);
return nameToVal;
}
示例#4
0
文件: encodeExp.c 项目: bowhan/kent
void expId()
/* Print id */
{
struct encodeExp *exps = NULL;
int count;
struct slPair *varPairs = NULL;

/* transform var:val to var=val. Can't use var=val on command-line as it conflicts with standard options processing */
if (expVars == NULL)
    varPairs = NULL;
else
    {
    memSwapChar(expVars, strlen(expVars), ':', '=');
    varPairs = slPairListFromString(expVars,FALSE); // don't expect quoted EDVs which should always be simple tokens.
    }
exps = encodeExpGetFromTable(organism, lab, dataType, cellType, varPairs, table);
count = slCount(exps);
verbose(2, "Results: %d\n", count);
if (count == 0)
    errAbort("Experiment not found in table %s", table);
if (count > 1)
    errAbort("Found more than 1 match for experiment");
printf("%d\n", exps->ix);
}
示例#5
0
void encodeExpToTab(char *outExp, char *outSeries, char *outResults)
/* encodeExpToCvDb - Convert encode experiments table to a table more suitable for cvDb. */
{
struct hash *optHash = optionalFieldsHash();
struct mdbObj *mdbList = getMdbList(metaDbs, ArraySize(metaDbs));
struct hash *mdbHash = mdbHashKeyedByExpId(mdbList);
struct hash *seriesHash = hashNew(0);
struct series *seriesList = NULL;
verbose(1, "read %d mdb objects from %s in %d databases\n", mdbHash->elCount, metaTable, 
    (int)ArraySize(metaDbs));
struct sqlConnection *expDbConn = sqlConnect(expDb);
struct sqlConnection *cvDbConn = sqlConnect(cvDb);
char query[256];
sqlSafef(query, sizeof(query), "select * from %s", expTable);
struct sqlResult *sr = sqlGetResult(expDbConn, query);
FILE *f = mustOpen(outExp, "w");
char **row;
while ((row = sqlNextRow(sr)) != NULL)
    {
    /* Read in database structure. */
    struct encodeExp *ee = encodeExpLoad(row);
    
    /* Much of the data we're processing comes from lists of the form 
     * "a=aVal b=bVal c=cVal." We'll convert these to id's in the appropriate 
     * tables and store the IDs in the optCol array declared below.  */
    int optColCount = ArraySize(expOptionalFields);
    int optCol[optColCount];
    int i;
    for (i=0; i<optColCount; ++i)
	optCol[i] = 0;

    /* Convert var=val string in encodeExp.expVars into list of slPairs, and loop through it. */
    struct slPair *varList = slPairListFromString(ee->expVars, TRUE);
    struct slPair *var;
    for (var = varList; var != NULL; var = var->next)
	 {
	 /* Figure out name of table and the term within that table. */
	 char *table = var->name;
	 char *term = var->val;
	 if (sameString(table, "antibody")) // Deal with antibody special case
	    {
	    if (sameString(term, "Control") || sameString(term, "Input") 
	    || sameString(term, "RevXlinkChromatin") || sameString(term, "ripInput"))
		{
		table = "control";
		}
	    }

	 /* If it looks like we have a valid table and term, store result in
	  * optCol array we'll output soon. */
	 struct hashEl *hel;
	 if ((hel = hashLookup(optHash, table)) != NULL)
	     {
	     int id = lookupId(cvDbConn, table, term);
	     if (id == 0)
		  {
	          warn("No id in cvDb for %s=%s\n", table, term);
		  continue;
		  }
	     int optColIx = ptToInt(hel->val);
	     optCol[optColIx] = id;
	     }
	 else
	     verbose(2, "%s %s ?\n", table, term);
	 }

    /* Now we want to process metaDb, which has some info encodeExp does not. */
    char *composite = NULL;
    char ixAsString[16];
    safef(ixAsString, sizeof(ixAsString), "%d", ee->ix);
    struct mdbObj *mdb = hashFindVal(mdbHash, ixAsString);
    if (mdb != NULL)
	{
	struct mdbVar *v;
	for (v = mdb->vars; v != NULL; v = v->next)
	    {
	    /* Look up table and term and change table name if need be */
	    char *table = v->var;
	    char *term = v->val;
	    if (sameString(table, "antibody")) 
		 table = "ab";
	    else if (sameString(table, "grant"))
	         table = "grantee";

	    /* Squirrel away the ever-important composite term for later. */
	    if (sameString("composite", table))
	         composite = term;

	    struct hashEl *hel;
	    if ((hel = hashLookup(optHash, table)) != NULL)
		{
		int optColIx = ptToInt(hel->val);
		if (optCol[optColIx] == 0)  // Only use mdb if encodeExp has no data.
		    {
		    int id = lookupId(cvDbConn, table, term);
		    optCol[optColIx] = id;
		    }
		}
	    }
	}

    /* If we've got a composite, then make up a series record. */
    if (composite != NULL)
        {
	assert(mdb != NULL);
	struct series *series = hashFindVal(seriesHash, composite);
	if (series == NULL)
	    {
	    series = seriesFromMdb(mdb, composite);
	    hashAdd(seriesHash, composite, series);
	    slAddHead(&seriesList, series);
	    }
	}

    if (ee->accession != NULL)
	{
	/* Write out required fields.  Order of required fields
	 * here needs to follow order in expRequiredFields. */
	fprintf(f, "%u", ee->ix);
	fprintf(f, "\t%s", ee->updateTime);
	fprintf(f, "\t%s", naForNull(composite));
	fprintf(f, "\t%s", ee->accession);
	fprintf(f, "\t%d", lookupId(cvDbConn, "organism", ee->organism));
	fprintf(f, "\t%d", lookupId(cvDbConn, "lab", ee->lab));
	fprintf(f, "\t%d", lookupId(cvDbConn, "dataType", ee->dataType));
	fprintf(f, "\t%d", lookupId(cvDbConn, "cellType", ee->cellType));

	/* Now write out optional fields. */
	for (i=0; i<optColCount; ++i)
	    fprintf(f, "\t%d", optCol[i]);

	/* End output record. */
	fprintf(f, "\n");
	}
    }

/* Write out series list to a separate file. */
slReverse(&seriesList);
writeSeriesList(outSeries, seriesList);

/* Write out results to a separate file. */
writeMdbListAsResults(mdbList, outResults);

/* Clean up and go home. */
carefulClose(&f);
sqlFreeResult(&sr);
sqlDisconnect(&expDbConn);
sqlDisconnect(&cvDbConn);
}