0c7a2612a25ebffaa7e2387b0a46920c87b72f8b tdreszer Wed Apr 13 13:32:44 2011 -0700 Fixed mdbUpdate -encodeExp to not require two rounds when updating both tables. diff --git src/hg/lib/mdb.c src/hg/lib/mdb.c index a426599..ae6a708 100644 --- src/hg/lib/mdb.c +++ src/hg/lib/mdb.c @@ -2817,44 +2817,45 @@ } // Work on one experiment at a time verbose(2, "mdbObjsEncodeExperimentify() working on EDVs: %s.\n",dyStringContents(dyVars)); struct mdbObj *mdbExpObjs = mdbObjsFilterByVars(&mdbCompositeObjs,dyStringContents(dyVars),TRUE,TRUE); // None={notFound} // --- At this point we have nibbled off an experiment worth of objects from the composite set of objects int objsInExp = slCount(mdbExpObjs); assert(objsInExp > 0); expCount++; expObjsCount += objsInExp; // Total of all experimental objects across the composite // Look up each exp in EXPERIMENTS_TABLE char experimentId[128]; - int expId = -1; + int expId = ENCODE_EXP_IX_UNDEFINED; struct encodeExp *exp = encodeExpGetByMdbVarsFromTable(db, edvVarVals, expTable); if (exp == NULL && createExpIfNecessary) exp = encodeExpGetOrCreateByMdbVarsFromTable(db, edvVarVals, expTable); mdbVarsFree(&edvVarVals); // No longer needed // Make sure the accession is set if requested. - if (createExpIfNecessary && updateAccession && exp->ix != -1 && exp->accession == NULL) + if (createExpIfNecessary && updateAccession + && exp->ix != ENCODE_EXP_IX_UNDEFINED && exp->accession == NULL) encodeExpSetAccession(exp, expTable); if (exp != NULL) expId = exp->ix; - if (expId == -1) + if (expId == ENCODE_EXP_IX_UNDEFINED) { safef(experimentId,sizeof(experimentId),"{missing}"); if (warn > 0) printf("Experiment %s EDV: [%s] is not defined in %s.%s table.\n",experimentId,dyStringContents(dyVars), ENCODE_EXP_DATABASE, expTable); //printf("Experiment %s EDV: [%s] is not defined in %s table. Remaining:%d and %d\n",experimentId,dyStringContents(dyVars),EXPERIMENTS_TABLE,slCount(mdbCompositeObjs),slCount(mdbObjs)); if (warn < 2) // From mdbUpdate (warn=1), just interested in testing waters. From mdbPrint (warn=2) list all objs in exp. { expMissing++; mdbProcessedObs = slCat(mdbProcessedObs,mdbExpObjs); mdbExpObjs = NULL; encodeExpFree(&exp); continue; } } else @@ -2874,62 +2875,62 @@ while(mdbExpObjs != NULL) { struct mdbObj *obj = slPopHead(&mdbExpObjs); { // NOTE: This list could expand but we expect only tables and files to be objs in an experiment char *objType = mdbObjFindValue(obj,MDB_OBJ_TYPE); assert(objType != NULL && (sameString(objType,MDB_OBJ_TYPE_TABLE) || sameString(objType,MDB_OBJ_TYPE_FILE))); } boolean updateObj = FALSE; char *val = mdbObjFindValue(obj,MDB_VAR_ENCODE_EXP_ID); if (val != NULL) { foundId = TRUE; // warn==1 will give only 1 exp wide error if no individual errors. NOTE: would be nice if those with expId sorted to beginning, but can't have everything. int thisId = atoi(val); - if (expId == -1 || thisId != expId) + if (expId == ENCODE_EXP_IX_UNDEFINED || thisId != expId) { updateObj = TRUE; if (warn > 0) printf(" %s %s has bad %s=%s.\n",experimentId,obj->obj,MDB_VAR_ENCODE_EXP_ID,val); } else { char *acc = mdbObjFindValue(obj,MDB_VAR_DCC_ACCESSION); // FIXME: Add code to update accession to encodeExp if (exp->accession != NULL && (acc == NULL || differentString(acc,exp->accession))) { updateObj = TRUE; if (warn > 1) // NOTE: Could give more info for each obj as per wrangler's desires { if (acc == NULL) printf(" %s %s %s set, needs %s.\n",experimentId,obj->obj,MDB_VAR_ENCODE_EXP_ID,MDB_VAR_DCC_ACCESSION); else printf(" %s %s %s set, has wrong %s: %s.\n",experimentId,obj->obj, MDB_VAR_ENCODE_EXP_ID,MDB_VAR_DCC_ACCESSION,exp->accession); } } else { errors--; // One less error if (warn > 1) // NOTE: Could give more info for each obj as per wrangler's desires - printf(" %s %s\n",experimentId,obj->obj); + printf(" %s %s %s\n",experimentId,obj->obj,(exp->accession != NULL ? exp->accession : "")); } } } else { - updateObj = (expId != -1); + updateObj = (expId != ENCODE_EXP_IX_UNDEFINED); if ((foundId && warn > 0) || warn > 1) { if (updateObj) printf(" %s %s needs updating to mdb.\n",experimentId,obj->obj); else printf(" %s %s\n",experimentId,obj->obj); // missing } } // This object needs to be updated. if (updateObj) { mdbObjSetVarInt(obj,MDB_VAR_ENCODE_EXP_ID,expId); struct mdbObj *newObj = mdbObjCreate(obj->obj,MDB_VAR_ENCODE_EXP_ID, experimentId); assert(exp != NULL);