49d55b9f5352a988c08588424eb2e256cbb301a7
hiram
  Thu Nov 10 15:33:48 2016 -0800
allow chrom trix file index to change chr names from hal file into chr names in ucsc browser refs #13553

diff --git src/hg/hgTracks/snakeTrack.c src/hg/hgTracks/snakeTrack.c
index 37f94ff..70405da 100644
--- src/hg/hgTracks/snakeTrack.c
+++ src/hg/hgTracks/snakeTrack.c
@@ -11,30 +11,31 @@
 #include "jksql.h"
 #include "hdb.h"
 #include "hgTracks.h"
 #include "chainBlock.h"
 #include "chainLink.h"
 #include "chainDb.h"
 #include "chainCart.h"
 #include "errCatch.h"
 #include "twoBit.h"
 #include "bigWarn.h"
 #include <pthread.h>
 #include "trackHub.h"
 #include "limits.h"
 #include "snakeUi.h"
 #include "bits.h"
+#include "trix.h"
 
 #include "halBlockViz.h"
 
 // this is the number of pixels used by the target self-align bar
 #define DUP_LINE_HEIGHT	4
 
 struct snakeFeature
     {
     struct snakeFeature *next;
     int start, end;			/* Start/end in browser coordinates. */
     int qStart, qEnd;			/* query start/end */
     int level;				/* level in snake */
     int orientation;			/* strand... -1 is '-', 1 is '+' */
     boolean drawn;			/* did we draw this feature? */
     char *qSequence;			/* may have sequence, or NULL */
@@ -1171,58 +1172,85 @@
 		    }
 		}
 	    }
 	}
     if (sf->orientation == -1)
 	lastX = sx;
     else
 	lastX = ex;
     lastS = s;
     lastE = e;
     lastLevel = sf->level;
     lastQEnd = qe;
     }
 }
 
+static char *doChromIxSearch(char *trixFile, char *searchName)
+/* search ixFile for the searchName, return name if found */
+{
+struct trix *trix = trixOpen(trixFile);
+char *trixWords[1];
+int trixWordCount = 1;
+trixWords[0] = strLower(searchName);
+char *name = NULL;  // assume NOT found
+
+struct trixSearchResult *tsList = trixSearch(trix, trixWordCount, trixWords, tsmExact);
+if (tsList)
+   name = tsList->itemId;  // FOUND
+return name;
+}
+
 void halSnakeLoadItems(struct track *tg)
 // load up a snake from a HAL file.   This code is called in threads
 // so *no* use of globals please. All but full snakes are read into a single
 // linked feature.
 {
 unsigned showSnpWidth = cartOrTdbInt(cart, tg->tdb, 
     SNAKE_SHOW_SNP_WIDTH, SNAKE_DEFAULT_SHOW_SNP_WIDTH);
 
+char * chromAlias = NULL;
+char * chromAliasFile = trackDbSetting(tg->tdb, "searchTrix");
+if (chromAliasFile)
+   chromAlias = doChromIxSearch(chromAliasFile, chromName);
+
+char *aliasName = chromName;
+if (chromAlias)
+   {
+       if (differentWord(chromAlias, aliasName))
+          aliasName = chromAlias;
+   }
+
 // if we have a network error we want to put out a message about it
 struct errCatch *errCatch = errCatchNew();
 if (errCatchStart(errCatch))
     {
     char *fileName = trackDbSetting(tg->tdb, "bigDataUrl");
     char *otherSpecies = trackDbSetting(tg->tdb, "otherSpecies");
     char *errString;
     int handle = halOpenLOD(fileName, &errString);
     if (handle < 0)
 	warn("HAL open error: %s\n", errString);
     boolean isPackOrFull = (tg->visibility == tvFull) || 
 	(tg->visibility == tvPack);
     hal_dup_type_t dupMode =  (isPackOrFull) ? HAL_QUERY_AND_TARGET_DUPS :
 	HAL_QUERY_DUPS;
     hal_seqmode_type_t needSeq = isPackOrFull && (winBaseCount < showSnpWidth) ? HAL_LOD0_SEQUENCE : HAL_NO_SEQUENCE;
     int mapBackAdjacencies = (tg->visibility == tvFull);
     char codeVarName[1024];
     safef(codeVarName, sizeof codeVarName, "%s.coalescent", tg->tdb->track);
     char *coalescent = cartOptionalString(cart, codeVarName);
-    struct hal_block_results_t *head = halGetBlocksInTargetRange(handle, otherSpecies, trackHubSkipHubName(database), chromName, winStart, winEnd, 0, needSeq, dupMode,mapBackAdjacencies, coalescent, &errString);
+    struct hal_block_results_t *head = halGetBlocksInTargetRange(handle, otherSpecies, trackHubSkipHubName(database), aliasName, winStart, winEnd, 0, needSeq, dupMode,mapBackAdjacencies, coalescent, &errString);
 
     // did we get any blocks from HAL
     if (head == NULL)
 	{
 	warn("HAL get blocks error: %s\n", errString);
 	errCatchEnd(errCatch);
 	return;
 	}
     struct hal_block_t* cur = head->mappedBlocks;
     struct linkedFeatures *lf = NULL;
     struct hash *qChromHash = newHash(5);
     struct linkedFeatures *lfList = NULL;
     char buffer[4096];
 
 #ifdef NOTNOW