f04cc66905720a6146a43fbb5aa5d9df797d32cb
kent
  Tue Apr 29 11:11:46 2014 -0700
Renaming samMustOpen to bamMustOpenLocal and putting in library.
diff --git src/lib/bamFile.c src/lib/bamFile.c
index 70b9fd2..25f9841 100644
--- src/lib/bamFile.c
+++ src/lib/bamFile.c
@@ -116,32 +116,49 @@
     boolean usingUrl = (strstr(fileOrUrl, "tp://") || strstr(fileOrUrl, "https://"));
     struct dyString *urlWarning = dyStringNew(0);
     if (usingUrl && fh == NULL)
 	{
 	dyStringAppend(urlWarning,
 		       ". If you are able to access the URL with your web browser, "
 		       "please try reloading this page.");
 	}
     else if (fh != NULL && fh->header == NULL)
 	dyStringAppend(urlWarning, ": parser error while reading the file header.");
     errAbort("Failed to open %s%s", fileOrUrl, urlWarning->string);
     }
 return fh;
 }
 
+samfile_t *bamMustOpenLocal(char *fileName, char *mode, void *extraHeader)
+/* Open up sam or bam file or die trying.  The mode parameter is 
+ *    "r" - open SAM to read
+ *    "rb" - open BAM to read
+ *    "w" - open SAM to write
+ *    "wb" - open BAM to write
+ * The extraHeader is generally NULL in the read case, and the write case
+ * contains a pointer to a bam_header_t with information about the header.
+ * The implementation is just a wrapper around samopen from the samtools library
+ * that aborts with error message if there's a problem with the open. */
+{
+samfile_t *sf = samopen(fileName, mode, extraHeader);
+if (sf == NULL)
+    errnoAbort("Couldn't open %s.\n", fileName);
+return sf;
+}
+
 void bamClose(samfile_t **pSamFile)
-/* Close down a samefile_t */
+/* Close down a samfile_t */
 {
 if (pSamFile != NULL)
     {
     samclose(*pSamFile);
     *pSamFile = NULL;
     }
 }
 
 void bamFileAndIndexMustExist(char *fileOrUrl)
 /* Open both a bam file and its accompanying index or errAbort; this is what it
  * takes for diagnostic info to propagate up through errCatches in calling code. */
 {
 samfile_t *bamF = bamOpen(fileOrUrl, NULL);
 bam_index_t *idx = bamOpenIdx(fileOrUrl);
 if (idx == NULL)
@@ -605,30 +622,45 @@
 
 void bamFileAndIndexMustExist(char *fileOrUrl)
 /* Open both a bam file and its accompanying index or errAbort; this is what it
  * takes for diagnostic info to propagate up through errCatches in calling code. */
 {
 errAbort(COMPILE_WITH_SAMTOOLS, "bamFileAndIndexMustExist");
 }
 
 samfile_t *bamOpen(char *fileOrUrl, char **retBamFileName)
 /* Return an open bam file */
 {
 warn(COMPILE_WITH_SAMTOOLS, "bamOpen");
 return FALSE;
 }
 
+samfile_t *bamMustOpenLocal(char *fileName, char *mode, void *extraHeader)
+/* Open up sam or bam file or die trying.  The mode parameter is 
+ *    "r" - open SAM to read
+ *    "rb" - open BAM to read
+ *    "w" - open SAM to write
+ *    "wb" - open BAM to write
+ * The extraHeader is generally NULL in the read case, and the write case
+ * contains a pointer to a bam_header_t with information about the header.
+ * The implementation is just a wrapper around samopen from the samtools library
+ * that aborts with error message if there's a problem with the open. */
+{
+warn(COMPILE_WITH_SAMTOOLS, "bamMustOpenLocal");
+return FALSE;
+}
+
 void bamClose(samfile_t **pSamFile)
 /* Close down a samefile_t */
 {
 errAbort(COMPILE_WITH_SAMTOOLS, "bamClose");
 }
 
 void bamFetch(char *fileOrUrl, char *position, bam_fetch_f callbackFunc, void *callbackData,
 	      samfile_t **pSamFile)
 /* Open the .bam file, fetch items in the seq:start-end position range,
  * and call callbackFunc on each bam item retrieved from the file plus callbackData.
  * This handles BAM files with "chr"-less sequence names, e.g. from Ensembl.
  * The pSamFile parameter is optional.  If non-NULL it will be filled in, just for
  * the benefit of the callback function, with the open samFile.  */
 {
 errAbort(COMPILE_WITH_SAMTOOLS, "bamFetch");