2eff21b32f29ea544fc203846bcb58c63c89363f tdreszer Thu Mar 17 17:05:35 2011 -0700 Integrated mdbPrint/mdbUpdate -encodeExp with the encodeExp APIs. diff --git src/hg/inc/mdb.h src/hg/inc/mdb.h index 9d217a4..3dbe230 100644 --- src/hg/inc/mdb.h +++ src/hg/inc/mdb.h @@ -80,41 +80,30 @@ #define mdbTabOut(el,f) mdbOutput(el,f,'\t','\n'); /* Print out mdb as a line in a tab-separated file. */ #define mdbCommaOut(el,f) mdbOutput(el,f,',',','); /* Print out mdb as a comma separated list including final comma. */ void mdbJsonOutput(struct mdb *el, FILE *f); /* Print out mdb in JSON format. */ /* -------------------------------- End autoSql Generated Code -------------------------------- */ #include "trackDb.h" #define MDB_DEFAULT_NAME "metaDb" -/* These are needed for experiment table to understand a few - * critical metaDb typeOfTerms. Need someway to tie to cv.ra */ - -#define MDB_FIELD_LAB "lab" -#define MDB_FIELD_DATA_TYPE "dataType" -#define MDB_FIELD_CELL_TYPE "cell" - -/* metaDb project used for production ENCODE */ -// TODO: move to ENCODE-specific mdb header file when it exists -#define ENCODE_MDB_PROJECT "wgEncode" - // The mdb holds metadata primarily for tables. // Many types of objects could be supported, though currently files are the only other type. // It is easy to imagine using the current mdb to support hierarchical trees of metadata. // For example a composite type object called "myComposte" could have metadata that is valid for // all tables that have the var=composite val=myComposte metadata defined. // // There are 2 ways to look at the metadata: By Obj: obj->[var=val] and By Var: var->[val->[obj]]. // By Obj: an object has many var/val pairs but only one val for each unique var. Querying by // object creates a single (2 level) one to many structure. // By Var: a variable has many possible values and each value may be defined for more than one object. // Therefore, querying by var results in a (3 level) one to many to many structure. struct mdbVar // The metadata var=val construct. This is contained by mdbObj { @@ -160,30 +149,34 @@ struct hash* valHash; // if NOT NULL: hash of vals (val str to limbVal struct) }; // ------ Parsing lines ------ struct mdbObj *metadataLineParse(char *line); /* Parses a single formatted metadata line into mdbObj for updates or queries. */ struct mdbByVar *mdbByVarsLineParse(char *line); /* Parses a line of "var1=val1 var2=val2 into a mdbByVar object for queries. */ // ------ Loading from args, hashes ------ struct mdbObj *mdbObjCreate(char *obj,char *var, char *val); /* Creates a singular mdbObj query object based on obj and all other optional params. */ +struct mdbObj *mdbObjNew(char *obj,struct mdbVar *mdbVars); +// Returns a new mdbObj with whatever was passed in. +// An mdbObj requires and obj, so if one is not supplied it will be "[unknown]" + struct mdbByVar *mdbByVarCreate(char *var, char *val); /* Creates a singular var=val pair struct for metadata queries. */ boolean mdbByVarAppend(struct mdbByVar *mdbByVars,char *var, char *val,boolean notEqual); /* Adds a another var to a list of mdbByVar pairs to be used in metadata queries. */ struct mdbObj *mdbObjsLoadFromHashes(struct hash *objsHash); // Load all mdbObjs from a file containing metadata formatted lines // ------ Loading from files ------ struct mdbObj *mdbObjsLoadFromFormattedFile(char *fileName,boolean *validated); // Load all mdbObjs from a file containing metadata formatted lines // If requested, will determine if a magic number at the end of the file matches contents @@ -331,36 +324,55 @@ struct mdbObj *mdbObjClone(const struct mdbObj *mdbObj); // Clones a single mdbObj, including hash and maintining order struct slName *mdbObjToSlName(struct mdbObj *mdbObjs); // Creates slNames list of mdbObjs->obj. mdbObjs remains untouched int mdbVarCmp(const void *va, const void *vb); /* Compare to sort on label. */ // ----------------- Validateion and specialty APIs ----------------- int mdbObjsValidate(struct mdbObj *mdbObjs, boolean full); // Validates vars and vals against cv.ra. Returns count of errors found. // Full considers vars not defined in cv as invalids -struct mdbObj *mdbObjsEncodeExperimentify(struct sqlConnection *conn,char *db,char *tableName,struct mdbObj **pMdbObjs,int warn); +struct mdbObj *mdbObjsEncodeExperimentify(struct sqlConnection *conn,char *db,char *tableName,struct mdbObj **pMdbObjs, + int warn,boolean createExpIfNecessary); // Organizes objects into experiments and validates experiment IDs. Will add/update the ids in the structures. // If warn=1, then prints to stdout all the experiments/obs with missing or wrong expIds; // warn=2, then print line for each obj with expId or warning. +// createExpIfNecessary means go ahead and add to the hgFixed.encodeExp table to get an ID // Returns a new set of mdbObjs that is what can (and should) be used to update the mdb via mdbObjsSetToDb(). +// -- Requested by Kate: -- +#define MDB_FIELD_LAB "lab" +#define MDB_FIELD_DATA_TYPE "dataType" +#define MDB_FIELD_CELL_TYPE "cell" +#define ENCODE_MDB_PROJECT "wgEncode" + +boolean mdbObjIsEncode(struct mdbObj *mdbObj); +// Returns TRUE if MDB object is an ENCODE object (project=wgEncode) + +boolean mdbObjInComposite(struct mdbObj *mdb, char *composite); +// Returns TRUE if metaDb object is in specified composite. +// If composite is NULL, always return true // FIXME: KATE Why return true if composite not defined??? + +//struct encodeExp *encodeExps(char *composite,char *expTable); +//struct mdbObjs *mdbObjsForDefinedExpId(int expId); +// Returns the mdb objects belonging to a single encode experiment defined in the encodExp table + // --------------- Free at last ---------------- void mdbObjsFree(struct mdbObj **mdbObjsPtr); // Frees one or more metadata objects and any contained mdbVars. Will free any hashes as well. void mdbByVarsFree(struct mdbByVar **mdbByVarsPtr); // Frees one or more metadata vars and any contained vals and objs. Will free any hashes as well. // ----------------- CGI specific routines for use with tdb ----------------- const struct mdbObj *metadataForTable(char *db,struct trackDb *tdb,char *table); // Returns the metadata for a table. NEVER FREE THIS STRUCT! // This is the main routine for CGIs to access metadata const char *metadataFindValue(struct trackDb *tdb, char *var); @@ -410,24 +422,15 @@ cvsNotSearchable =0, // Txt is default cvsSearchByMultiSelect =1, // Search by drop down multi-select of supplied list (NOT YET IMPLEMENTED) cvsSearchBySingleSelect =2, // Search by drop down single-select of supplied list cvsSearchByFreeText =3, // Search by free text field (NOT YET IMPLEMENTED) cvsSearchByDateRange =4, // Search by discovered date range (NOT YET IMPLEMENTED) cvsSearchByIntegerRange =5 // Search by discovered integer range (NOT YET IMPLEMENTED) }; enum mdbCvSearchable mdbCvSearchMethod(char *term); // returns whether the term is searchable // TODO: replace with mdbCvWhiteList() returning struct const char *cvLabel(char *term); // returns cv label if term found or else just term #endif /* MDB_H */ -int mdbObjIsEncode(struct mdbObj *mdb); -/* Return true if this metaDb object is for ENCODE */ - -int mdbObjInComposite(struct mdbObj *mdb, char *composite); -/* Return true if metaDb object is in specified composite. - If composite is NULL, always return true */ - -struct mdbObj *mdbObjNew(char *name, struct mdbVar *vars); -/* Create an mdbObj */