1859400ffa0d1aa7af657780447cb1544060be76 tdreszer Fri Mar 25 14:01:06 2011 -0700 Added useful functions to mdb, including encode specific ones. Fixed encodeExp retreival by mdb obj. diff --git src/hg/inc/mdb.h src/hg/inc/mdb.h index 6b1c769..50aa1c3 100644 --- src/hg/inc/mdb.h +++ src/hg/inc/mdb.h @@ -243,30 +243,49 @@ struct mdbObj *mdbObjQueryByObj(struct sqlConnection *conn,char *table,char *obj,char *var); // Query a single metadata object and optional var from a table (default mdb). struct mdbByVar *mdbByVarsQuery(struct sqlConnection *conn,char *table,struct mdbByVar *mdbByVars); // Query the metadata table by one or more var=val pairs to find the distinct set of objs that satisfy ANY conditions. // Returns new mdbByVar struct fully populated and sorted in var,val,obj order. #define mdbByVarsQueryAll(conn,table) mdbByVarsQuery((conn),(table),NULL) struct mdbByVar *mdbByVarQueryByVar(struct sqlConnection *conn,char *table,char *varName,char *val); // Query a single metadata variable and optional val from a table (default mdb) for searching val->obj. struct mdbObj *mdbObjsQueryByVars(struct sqlConnection *conn,char *table,struct mdbByVar *mdbByVars); // Query the metadata table by one or more var=val pairs to find the distinct set of objs that satisfy ALL conditions. // Returns new mdbObj struct fully populated and sorted in obj,var order. +struct mdbObj *mdbObjsQueryByVarValString(struct sqlConnection *conn,char *tableName,char *varVals); +// returns mdbObjs matching varVals in form of: [var1=val1 var2=val2a,val2b var3=v%3 var4="val 4" var5!=val5 var6=] +// var2=val2a,val2b: matches asny of comma separated list +// var3=v%3 : matches '%' and '?' wild cards. +// var4="val 4" : matches simple double quoted strings. +// var5!=val5 : matches not equal. +// var6= : matches that var exists (same as var6=%). var6!= also works. +#define mdbObjsQueryByVarVals(conn,varVals) mdbObjsQueryByVarValString((conn),NULL,(varVals)) + +struct mdbObj *mdbObjsQueryByVarPairs(struct sqlConnection *conn,char *tableName,struct slPair *varValPairs); +// returns mdbObjs matching varValPairs provided. +// The != logic of mdbObjsQueryByVarValString() is not possible, but other cases are supported: +// as val may be NULL, a comma delimited list, double quoted string, containing wilds: % and ? +#define mdbObjsQueryByVarValPairs(conn,varValPairs) mdbObjsQueryByVarPairs((conn),NULL,(varValPairs)) + +struct mdbObj *mdbObjQueryCompositeObj(struct sqlConnection *conn,char *tableName,struct mdbObj *mdbObj); +// returns NULL or the composite mdbObj associated with the object passed in. +#define mdbObjQueryComposite(conn,mdbObj) mdbObjQueryCompositeObj((conn),NULL,(mdbObj)) + // ----------- Printing and Counting ----------- void mdbObjPrint(struct mdbObj *mdbObjs,boolean raStyle); // prints objs and var=val pairs as formatted metadata lines or ra style void mdbObjPrintToFile(struct mdbObj *mdbObjs,boolean raStyle, char *file); // prints (to file) objs and var=val pairs as formatted metadata lines or ra style void mdbObjPrintToStream(struct mdbObj *mdbObjs,boolean raStyle, FILE *outF); // prints (to stream) objs and var=val pairs as formatted metadata lines or ra style int mdbObjPrintToTabFile(struct mdbObj *mdbObjs, char *file); // prints all objs as tab delimited obj var val into file for SQL LOAD DATA. Returns count. char *mdbObjVarValPairsAsLine(struct mdbObj *mdbObj,boolean objTypeExclude); @@ -352,67 +371,80 @@ // List b is untouched but pA will contain the resulting intersection void mdbObjTransformToUpdate(struct mdbObj *mdbObjs, char *var, char *val,boolean deleteThis); // Turns one or more mdbObjs into the stucture needed to add/update or delete. 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 ----------------- +// ----------------- Validation and specialty APIs ----------------- + +boolean mdbObjIsComposite(struct mdbObj *mdbObj); +// returns TRUE if this is a valid composite object + +boolean mdbObjIsCompositeMember(struct mdbObj *mdbObj); +// returns TRUE if this is a valid member of a composite. DOES not confirm that composite obj exists + 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 slName *mdbObjFindCompositeEncodeEdvNames(struct sqlConnection *conn,char *tableName,struct mdbObj *mdbObj); +// returns NULL or the Experiment Defining Variable names for this composite +#define mdbObjFindCompositeEncodeEdvs(conn,mdbObj) mdbObjFindCompositeEncodeEdvNames((conn),NULL,(mdbObj)) + +struct mdbVar *mdbObjFindEncodeEdvPairs(struct sqlConnection *conn,char *tableName,struct mdbObj *mdbObj,boolean includeNone); +// returns NULL or the Experiment Defining Variables and values for this composite member object +// If includeNone, then defined variables not found in obj will be included as {var}="None". +#define mdbObjFindEncodeEdvs(conn,mdbObj,includeNone) mdbObjFindEncodeEdvPairs((conn),NULL,(mdbObj),(includeNone)) + 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 MDB_VAR_LAB -#define MDB_FIELD_DATA_TYPE MDB_VAR_DATATYPE -#define MDB_FIELD_CELL_TYPE MDB_VAR_CELL -#define ENCODE_MDB_PROJECT MDB_VAL_ENCODE_PROJECT - 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??? +// -- Requested by Kate? -- //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. +#define mdbObjFree(mdbObjPtr) mdbObjsFree(mdbObjPtr) void mdbByVarsFree(struct mdbByVar **mdbByVarsPtr); // Frees one or more metadata vars and any contained vals and objs. Will free any hashes as well. +#define mdbByVarFree(mdbByVarPtr) mdbByVarsFree(mdbByVarPtr) // ----------------- 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); // Finds the val associated with the var or retruns NULL #define MDB_VAL_STD_TRUNCATION 64 struct mdbObj *mdbObjSearch(struct sqlConnection *conn, char *var, char *val, char *op, int limit); // Search the metaDb table for objs by var and val. Can restrict by op "is", "like", "in" and accept (non-zero) limited string size // Search is via mysql, so it's case-insensitive. Return is sorted on obj.