fcda64e213150b3bd0ade930139e2893e1da42a4
braney
  Tue Aug 4 12:09:19 2015 -0700
first cut at bigPsl support in the browser.  #14241

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 6b58cb4..4fa7c97 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -235,30 +235,31 @@
 #include "gbWarn.h"
 #include "lsSnpPdbChimera.h"
 #include "mammalPsg.h"
 #include "net.h"
 #include "jsHelper.h"
 #include "virusClick.h"
 #include "gwasCatalog.h"
 #include "parClick.h"
 #include "mdb.h"
 #include "yaleGencodeAssoc.h"
 #include "itemDetailsHtml.h"
 #include "trackVersion.h"
 #include "numtsClick.h"
 #include "geneReviewsClick.h"
 #include "bigBed.h"
+#include "bigPsl.h"
 
 static char *rootDir = "hgcData";
 
 #define LINESIZE 70  /* size of lines in comp seq feature */
 
 struct cart *cart;	/* User's settings. */
 char *seqName;		/* Name of sequence we're working on. */
 int winStart, winEnd;   /* Bounds of sequence. */
 char *database;		/* Name of mySQL database. */
 char *organism;		/* Colloquial name of organism. */
 char *genome;		/* common name, e.g. Mouse, Human */
 char *scientificName;	/* Scientific name of organism. */
 
 struct hash *trackHash;	/* A hash of all tracks - trackDb valued */
 
@@ -2845,30 +2846,71 @@
 }
 
 void pslDumpHtml(struct psl *pslList)
 /* print out psl header and data */
 {
 struct psl* psl;
 printf("<PRE><TT>\n");
 printf("#match\tmisMatches\trepMatches\tnCount\tqNumInsert\tqBaseInsert\ttNumInsert\tBaseInsert\tstrand\tqName\tqSize\tqStart\tqEnd\ttName\ttSize\ttStart\ttEnd\tblockCount\tblockSizes\tqStarts\ttStarts\n");
 for (psl = pslList; psl != NULL; psl = psl->next)
     {
     pslTabOut(psl, stdout);
     }
 printf("</TT></PRE>\n");
 }
 
+void genericBigPslClick(struct sqlConnection *conn, struct trackDb *tdb,
+                     char *item, int start, int end)
+/* Handle click in big psl track. */
+{
+struct psl* pslList;
+char *fileName = bbiNameFromSettingOrTable(tdb, conn, tdb->table);
+struct bbiFile *bbi = bigBedFileOpen(fileName);
+struct lm *lm = lmInit(0);
+int ivStart = start, ivEnd = end;
+if (start == end)
+    {  
+    // item is an insertion; expand the search range from 0 bases to 2 so we catch it:
+    ivStart = max(0, start-1);
+    ivEnd++;
+    }  
+
+struct bigBedInterval *bbList = bigBedIntervalQuery(bbi, seqName, ivStart, ivEnd, 0, lm);
+pslList = pslFromBigPsl(seqName, bbList,  hChromSize(database, seqName), NULL);
+
+/* check if there is an alignment available for this sequence.  This checks
+ * both genbank sequences and other sequences in the seq table.  If so,
+ * set it up so they can click through to the alignment. */
+if ( 1) //hGenBankHaveSeq(database, item, NULL))
+    {
+    printf("<H3>%s/Genomic Alignments</H3>", item);
+    /*
+    if (sameString("protein", subType))
+        printAlignments(pslList, start, "htcProteinAli", tdb->table, item);
+    else
+    */
+        printAlignments(pslList, start, "htcCdnaAli", tdb->table, item);
+    }
+else
+    {
+    /* just dump the psls */
+    pslDumpHtml(pslList);
+    }
+pslFreeList(&pslList);
+printItemDetailsHtml(tdb, item);
+}
+
 void genericPslClick(struct sqlConnection *conn, struct trackDb *tdb,
                      char *item, int start, char *subType)
 /* Handle click in generic psl track. */
 {
 struct psl* pslList = getAlignments(conn, tdb->table, item);
 
 /* check if there is an alignment available for this sequence.  This checks
  * both genbank sequences and other sequences in the seq table.  If so,
  * set it up so they can click through to the alignment. */
 if (hGenBankHaveSeq(database, item, NULL))
     {
     printf("<H3>%s/Genomic Alignments</H3>", item);
     if (sameString("protein", subType))
         printAlignments(pslList, start, "htcProteinAli", tdb->table, item);
     else
@@ -3910,30 +3952,34 @@
 	}
     else if (sameString(type, "sample"))
 	{
 	int num = 9;
         genericSampleClick(conn, tdb, item, start, num);
 	}
     else if (sameString(type, "genePred"))
         {
 	char *pepTable = NULL, *mrnaTable = NULL;
 	if ((wordCount > 1) && !sameString(words[1], "."))
 	    pepTable = words[1];
 	if ((wordCount > 2) && !sameString(words[2], "."))
 	    mrnaTable = words[2];
 	genericGenePredClick(conn, tdb, item, start, pepTable, mrnaTable);
 	}
+    else if ( sameString(type, "bigPsl"))
+        {
+	genericBigPslClick(conn, tdb, item, start, end);
+	}
     else if (sameString(type, "psl"))
         {
 	char *subType = ".";
 	if (wordCount > 1)
 	    subType = words[1];
 	genericPslClick(conn, tdb, item, start, subType);
 	}
     else if (sameString(type, "netAlign"))
         {
 	if (wordCount < 3)
 	    errAbort("Missing field in netAlign track type field");
 	genericNetClick(conn, tdb, item, start, words[1], words[2]);
 	}
     else if (sameString(type, "chain"))
         {