Commit f6cc218e authored by Andreas Tille's avatar Andreas Tille
Browse files

Use official htslib in libucsc

parent b205fae9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
# use_debian_packaged_htslib.patch
unbundle-htslib.patch
+97 −0
Original line number Diff line number Diff line
Author: John Marshall <John.W.Marshall@glasgow.ac.uk>
Last-Update: Fri Jan 24 14:34:54 GMT 2020
Description: Use official htslib in libucsc
Origin: https://alioth-lists.debian.net/pipermail/debian-med-packaging/2020-January/077104.html

--- a/src/lib/bamFile.c
+++ b/src/lib/bamFile.c
@@ -7,10 +7,7 @@
 #include "portable.h"
 #include "bamFile.h"
 #include "htmshell.h"
-#include "cram/cram_samtools.h"
-#include "cram/sam_header.h"
-#include "cram/cram_structs.h"
-#include "htslib/cram.h"
+#include "htslib/sam.h"
 #include "udc.h"
 #include "psl.h"
 
@@ -179,44 +176,6 @@ if (iter == NULL)
 int result;
 while ((result = sam_itr_next(samfile, iter, b)) >= 0) 
     callbackFunc(b, callbackData, header);
-
-// if we're reading a CRAM file and the MD5 string has been set
-// we know there was an error finding the reference and we need
-// to request that it be loaded.
-if (samfile->format.format == cram) 
-    {
-    char *md5String =  cram_get_Md5(samfile);
-    if (!isEmpty(md5String))
-        {
-        char server[4096];
-        char pendingFile[4096];
-        char errorFile[4096];
-
-        char *refPath = cram_get_ref_url(samfile);
-        char *cacheDir = cram_get_cache_dir(samfile);
-
-        sprintf(server, refPath, md5String);
-        sprintf(pendingFile, "%s/pending/",cacheDir);
-        sprintf(errorFile, "%s/error/%s",cacheDir,md5String);
-        makeDirsOnPath(pendingFile);
-        sprintf(pendingFile, "%s/pending/%s",cacheDir,md5String);
-        FILE *downFile;
-        if ((downFile = fopen(errorFile, "r")) != NULL)
-            {
-            char errorBuf[4096];
-            mustGetLine(downFile, errorBuf, sizeof errorBuf);
-            errAbort("cannot find reference %s.  Error: %s\n", md5String,errorBuf);
-            }
-        else
-            {
-            if ((downFile = fopen(pendingFile, "w")) == NULL)
-                errAbort("cannot find reference %s.  Cannot create file %s.",md5String, pendingFile);  
-            fprintf(downFile,  "%s\n", server);
-            fclose(downFile);
-            errAbort("Cannot find reference %s.  Downloading from %s. Please refresh screen to check download status.",md5String, server);
-            }
-        }
-    }
 }
 
 void bamAndIndexFetchPlus(char *fileOrUrl, char *baiFileOrUrl, char *position, bam_fetch_f callbackFunc, void *callbackData,
@@ -231,12 +190,6 @@ void bamAndIndexFetchPlus(char *fileOrUr
 {
 char *bamFileName = NULL;
 samfile_t *fh = bamOpen(fileOrUrl, &bamFileName);
-if (fh->format.format == cram) 
-    {
-    if (cacheDir == NULL)
-        errAbort("CRAM cache dir hg.conf variable (cramRef) must exist for CRAM support");
-    cram_set_cache_url(fh, cacheDir, refUrl);  
-    }
 bam_hdr_t *header = sam_hdr_read(fh);
 if (pSamFile != NULL)
     *pSamFile = fh;
@@ -256,16 +209,9 @@ static int bamGetTargetCount(char *fileO
 {
 int tCount = 0;
 htsFile *htsF = hts_open(fileOrUrl, "r");
-if (htsF->format.format == crai)
-    {
-    SAM_hdr *cramHdr = cram_fd_get_header(htsF->fp.cram);
-    tCount = cramHdr->nref;
-    }
-else
-    {
-    bam_hdr_t *bamHdr = bam_hdr_read(htsF->fp.bgzf);
-    tCount = bamHdr->n_targets;
-    }
+bam_hdr_t *bamHdr = sam_hdr_read(htsF);
+tCount = bamHdr->n_targets;
+bam_hdr_destroy(bamHdr);
 hts_close(htsF);
 return tCount;
 }