fdb4b5d215ff23b0f066a9b7d7a96ae31045a347
braney
  Fri Jan 15 12:27:29 2016 -0800
yet more work on support CRAM under htslib

diff --git src/hg/hgTables/bam.c src/hg/hgTables/bam.c
index 4066b77..f71ad8a 100644
--- src/hg/hgTables/bam.c
+++ src/hg/hgTables/bam.c
@@ -15,30 +15,31 @@
 #include "bed.h"
 #include "hdb.h"
 #include "trackDb.h"
 #include "obscure.h"
 #include "hmmstats.h"
 #include "correlate.h"
 #include "asParse.h"
 #include "bbiFile.h"
 #include "bigBed.h"
 #include "hubConnect.h"
 #include "trackHub.h"
 #include "hgTables.h"
 #include "asFilter.h"
 #include "xmlEscape.h"
 #include "hgBam.h"
+#include "hgConfig.h"
 
 boolean isBamTable(char *table)
 /* Return TRUE if table corresponds to a BAM file. */
 {
 if (isHubTrack(table))
     {
     struct trackDb *tdb = hashFindVal(fullTableToTdbHash, table);
     return startsWithWord("bam", tdb->type);
     }
 else
     return trackIsType(database, table, curTrack, "bam", ctLookupName);
 }
 
 char *bamFileName(char *table, struct sqlConnection *conn, char *seqName)
 /* Return file name associated with BAM.  This handles differences whether it's
@@ -154,38 +155,39 @@
 struct asFilter *filter = NULL;
 
 if (anyFilter())
     {
     filter = asFilterFromCart(cart, db, table, as);
     if (filter)
         {
 	fprintf(f, "# Filtering on %d columns\n", slCount(filter->columnList));
 	}
     }
 
 /* Loop through outputting each region */
 struct region *region, *regionList = getRegions();
 
 struct trackDb *tdb = findTdbForTable(db, curTrack, table, ctLookupName);
-cramInit(tdb);
 int maxOut = bigFileMaxOutput();
+char *cacheDir =  cfgOption("cramRef");
+char *refUrl = trackDbSetting(tdb, "refUrl");
 for (region = regionList; region != NULL && (maxOut > 0); region = region->next)
     {
     struct lm *lm = lmInit(0);
     char *fileName = bamFileName(table, conn, region->chrom);
-    struct samAlignment *sam, *samList = bamFetchSamAlignment(fileName, region->chrom,
-    	region->start, region->end, lm);
+    struct samAlignment *sam, *samList = bamFetchSamAlignmentPlus(fileName, region->chrom,
+    	region->start, region->end, lm, refUrl, cacheDir );
     char *row[SAMALIGNMENT_NUM_COLS];
     char numBuf[BAM_NUM_BUF_SIZE];
     for (sam = samList; sam != NULL && (maxOut > 0); sam = sam->next)
         {
 	samAlignmentToRow(sam, numBuf, row);
 	if (asFilterOnRow(filter, row))
 	    {
 	    /* if we're looking for identifiers, check if this matches */
 	    if ((idHash != NULL)&&(hashLookup(idHash, row[idFieldNum]) == NULL))
 		continue;
 
 	    int i;
 	    fprintf(f, "%s", row[columnArray[0]]);
 	    for (i=1; i<fieldCount; ++i)
 		fprintf(f, "\t%s", row[columnArray[i]]);