6499bc383779f7d646664256926350b94ca0ecc4
galt
  Fri Jun 1 17:42:28 2012 -0700
fix for #4009, so hgTables identifiers are used in filtering even if no fields from the primary table are selected for output
diff --git src/hg/hgTables/joining.c src/hg/hgTables/joining.c
index b3738e3..6c14dcf 100644
--- src/hg/hgTables/joining.c
+++ src/hg/hgTables/joining.c
@@ -944,30 +944,55 @@
 
 
 void tabOutSelectedFields(
 	char *primaryDb,		/* The primary database. */
 	char *primaryTable, 		/* The primary table. */
 	FILE *f,			/* file for output, null for stdout */
 	struct slName *fieldList)	/* List of db.table.field */
 /* Do tab-separated output on selected fields, which may
  * or may not include multiple tables. */
 {
 struct joinerDtf *dtfList = NULL;
 struct joinerDtf *filterTables = NULL;
 boolean doJoin = joinRequired(primaryDb, primaryTable,
 			      fieldList, &dtfList, &filterTables);
 
+boolean hasIdentifiers = (identifierFileName() != NULL);
+if (hasIdentifiers)
+    {
+    boolean hasPrimary = FALSE;
+    struct joinerDtf *temp;
+    for (temp = dtfList; temp; temp = temp->next)
+	if (sameString(temp->database, primaryDb) && sameString(temp->table, primaryTable))
+	    hasPrimary = TRUE;
+    for (temp = filterTables; temp; temp = temp->next)
+	if (sameString(temp->database, primaryDb) && sameString(temp->table, primaryTable))
+	    hasPrimary = TRUE;
+    /* if primary table is not in output or filter, 
+     *  add it to the filterTables list to trigger joining and identifier filtering */
+    if (!hasPrimary)
+	{	    
+	struct joinerDtf *dtf;
+	AllocVar(dtf);
+	dtf->database = cloneString(primaryDb);
+	dtf->table = cloneString(primaryTable);
+	slAddTail(&filterTables, dtf);
+	doJoin = TRUE;
+	}
+    }
+
+
 if (! doJoin)
     {
     struct sqlConnection *conn = hAllocConn(dtfList->database);
     struct dyString *dy = dyStringNew(0);
     
     if (isBigBed(database, dtfList->table, NULL, ctLookupName))
 	makeBigBedOrderedCommaFieldList(dtfList, dy);
     else if (isBamTable(dtfList->table))
         makeBamOrderedCommaFieldList(dtfList, dy);
     else if (isVcfTable(dtfList->table))
         makeVcfOrderedCommaFieldList(dtfList, dy);
     else if (isCustomTrack(dtfList->table))
         makeCtOrderedCommaFieldList(dtfList, dy);
     else
 	makeDbOrderedCommaFieldList(conn, dtfList->table, dtfList, dy);