4727e0251c76f69905d0748adab43484166d6870
angie
  Fri Mar 14 16:42:14 2014 -0700
In code review, Max pointed out that it's non-standard to conditionallyinclude header files in the middle of a .c file.  While looking at it,
I realized that there were a lot of unnecessary #ifdef's for KNETFILE_HOOKS
in general, all because there was not yet an #else implementation of
knetUdcInstall, which can be a no-op if KNETFILE_HOOKS is not used.
So I yanked out a lot of unnecessary old stuff, and tested basic bam and
vcf track operations with a few settings:

USE_SAMTABIX   USE_BAM   USE_TABIX   KNETFILE_HOOKS
1     (these tree are all implied by USE_SAMTABIX)
0        1          0       0
0        1          0       1
0        0          1       1
USE_TABIX without KNETFILE_HOOKS doesn't work because the tabix lib
wants to download .tbi files into the current working directory,
cgi-bin, and we don't allow that (and shouldn't!).  If we were going
to support that, we could add a change-dir solution as in bamFile.c,
but I don't think we need to support it now that there's samtabix.

refs #6235, refs #12850

diff --git src/lib/linefile.c src/lib/linefile.c
index 7b29406..3c1e231 100644
--- src/lib/linefile.c
+++ src/lib/linefile.c
@@ -196,34 +196,34 @@
 struct lineFile *lineFileOnString(char *name, bool zTerm, char *s)
 /* Wrap a line file object around string in memory. This buffer
  * have zeroes written into it and be freed when the line file
  * is closed. */
 {
 struct lineFile *lf;
 AllocVar(lf);
 lf->fileName = cloneString(name);
 lf->fd = -1;
 lf->bufSize = lf->bytesInBuf = strlen(s);
 lf->zTerm = zTerm;
 lf->buf = s;
 return lf;
 }
 
-#if (defined USE_SAMTABIX || (defined USE_TABIX && !defined KNETFILE_HOOKS))
+#if (defined USE_TABIX && defined KNETFILE_HOOKS && !defined USE_SAMTABIX)
 // UCSC aliases for backwards compatibility with independently patched & linked samtools and tabix:
-#define ti_bgzf_tell bgzf_tell
-#define ti_bgzf_read bgzf_read
+#define bgzf_tell ti_bgzf_tell
+#define bgzf_read ti_bgzf_read
 #endif
 
 struct lineFile *lineFileTabixMayOpen(char *fileOrUrl, bool zTerm)
 /* Wrap a line file around a data file that has been compressed and indexed
  * by the tabix command line program.  The index file <fileOrUrl>.tbi must be
  * readable in addition to fileOrUrl. If there's a problem, warn & return NULL.
  * This works only if kent/src has been compiled with USE_TABIX=1 and linked
  * with the tabix C library. */
 {
 #ifdef USE_TABIX
 if (fileOrUrl == NULL)
     errAbort("lineFileTabixMayOpen: fileOrUrl is NULL");
 int tbiNameSize = strlen(fileOrUrl) + strlen(".tbi") + 1;
 char tbiName[tbiNameSize];
 safef(tbiName, sizeof(tbiName), "%s.tbi", fileOrUrl);
@@ -264,31 +264,31 @@
     errAbort("lineFileSetTabixRegion: lf->tabix is NULL.  Did you open lf with lineFileTabixMayOpen?");
 if (seqName == NULL)
     return FALSE;
 int tabixSeqId = ti_get_tid(lf->tabix->idx, seqName);
 if (tabixSeqId < 0 && startsWith("chr", seqName))
     // We will get some files that have chr-less Ensembl chromosome names:
     tabixSeqId = ti_get_tid(lf->tabix->idx, seqName+strlen("chr"));
 if (tabixSeqId < 0)
     return FALSE;
 ti_iter_t iter = ti_queryi(lf->tabix, tabixSeqId, start, end);
 if (iter == NULL)
     return FALSE;
 if (lf->tabixIter != NULL)
     ti_iter_destroy(lf->tabixIter);
 lf->tabixIter = iter;
-lf->bufOffsetInFile = ti_bgzf_tell(lf->tabix->fp);
+lf->bufOffsetInFile = bgzf_tell(lf->tabix->fp);
 lf->bytesInBuf = 0;
 lf->lineIx = -1;
 lf->lineStart = 0;
 lf->lineEnd = 0;
 return TRUE;
 #else // no USE_TABIX
 warn(COMPILE_WITH_TABIX, "lineFileSetTabixRegion");
 return FALSE;
 #endif // no USE_TABIX
 }
 
 struct lineFile *lineFileUdcMayOpen(char *fileOrUrl, bool zTerm)
 /* Create a line file object with an underlying UDC cache. NULL if not found. */
 {
 if (fileOrUrl == NULL)
@@ -544,31 +544,31 @@
     int oldEnd = lf->lineEnd;
     int sizeLeft = bytesInBuf - oldEnd;
     int bufSize = lf->bufSize;
     int readSize = bufSize - sizeLeft;
 
     if (oldEnd > 0 && sizeLeft > 0)
 	{
 	memmove(buf, buf+oldEnd, sizeLeft);
 	}
     lf->bufOffsetInFile += oldEnd;
     if (lf->fd >= 0)
 	readSize = lineFileLongNetRead(lf->fd, buf+sizeLeft, readSize);
 #ifdef USE_TABIX
     else if (lf->tabix != NULL && readSize > 0)
 	{
-	readSize = ti_bgzf_read(lf->tabix->fp, buf+sizeLeft, readSize);
+	readSize = bgzf_read(lf->tabix->fp, buf+sizeLeft, readSize);
 	if (readSize < 1)
 	    return FALSE;
 	}
 #endif // USE_TABIX
     else
         readSize = 0;
 
     if ((readSize == 0) && (endIx > oldEnd))
 	{
 	endIx = sizeLeft;
 	buf[endIx] = 0;
 	lf->bytesInBuf = newStart = lf->lineStart = 0;
 	lf->lineEnd = endIx;
 	++lf->lineIx;
 	if (retSize != NULL)