Browse code

Update for Rhtslib compatibility. (Patch by Hervé Pagès)

Daniel C. Jones authored on 22/03/2019 20:05:41
Showing 14 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 Package: seqbias
2
-Version: 1.31.0
3
-Date: 25-12-2010
2
+Version: 1.31.1
3
+Date: 2019-03-15
4 4
 Title: Estimation of per-position bias in high-throughput sequencing
5 5
         data
6 6
 Description: This package implements a model of per-position sequencing
... ...
@@ -9,10 +9,9 @@ Description: This package implements a model of per-position sequencing
9 9
         set of aligned reads and a reference genome sequence.
10 10
 Author: Daniel Jones <dcjones@cs.washington.edu>
11 11
 Maintainer: Daniel Jones <dcjones@cs.washington.edu>
12
-Depends: R (>= 2.13.0), GenomicRanges (>= 0.1.0), Biostrings (>=
12
+Depends: R (>= 3.0.2), GenomicRanges (>= 0.1.0), Biostrings (>=
13 13
         2.15.0), methods
14
-LinkingTo: Rsamtools (>= 1.19.38)
15
-Imports: zlibbioc
14
+LinkingTo: Rhtslib (>= 1.15.3)
16 15
 Suggests: Rsamtools, ggplot2
17 16
 LazyLoad: yes
18 17
 License: LGPL-3
... ...
@@ -1,3 +1,2 @@
1 1
 exportPattern("^[^\\.]")
2 2
 useDynLib(seqbias)
3
-import(zlibbioc)
... ...
@@ -1,19 +1,14 @@
1 1
 include Makevars.common
2 2
 
3
-SAMTOOLS_PATH=\
4
-    `echo 'cat(system.file("usrlib", .Platform[["r_arch"]], \
5
-        package="Rsamtools", mustWork=TRUE))' |\
6
-        "${R_HOME}/bin/R" --vanilla --slave`
7
-SAMTOOLS_LIBS="$(SAMTOOLS_PATH)/libbam.a" "$(SAMTOOLS_PATH)/libbcf.a"\
8
-    "$(SAMTOOLS_PATH)/libtabix.a" -lz -pthread
9
-SAMTOOLS_CPPFLAGS=-D_USE_KNETFILE -DBGZF_CACHE -D_FILE_OFFSET_BITS=64 \
10
-    -D_LARGEFILE64_SOURCE
3
+RHTSLIB_LIBS=`echo 'Rhtslib::pkgconfig("PKG_LIBS")'|\
4
+    "${R_HOME}/bin/R" --vanilla --slave`
5
+RHTSLIB_CPPFLAGS=`echo 'Rhtslib::pkgconfig("PKG_CPPFLAGS")'|\
6
+    "${R_HOME}/bin/R" --vanilla --slave`
11 7
 
12
-PKG_LIBS=$(SAMTOOLS_LIBS)
13
-PKG_CPPFLAGS=$(SAMTOOLS_CPPFLAGS)
8
+PKG_LIBS=$(RHTSLIB_LIBS)
9
+PKG_CPPFLAGS=$(RHTSLIB_CPPFLAGS)
14 10
 
15
-OBJECTS = $(SEQBIAS_OBJ) \
16
-		  $(YAML_CPP_OBJ:%=yaml-cpp/%)
11
+OBJECTS = $(SEQBIAS_OBJ) $(YAML_CPP_OBJ:%=yaml-cpp/%)
17 12
 
18 13
 all : $(SHLIB)
19 14
 
... ...
@@ -7,10 +7,12 @@ YAML_CPP_OBJ = aliasmanager.o conversion.o directives.o \
7 7
 
8 8
 
9 9
 
10
-SEQBIAS_OBJ = common.o \
10
+SEQBIAS_OBJ = sam.o \
11
+              bam_plbuf.o \
12
+              bam_aux.o \
13
+              common.o \
11 14
               miscmath.o \
12 15
               pos_table.o \
13
-              samtools_extra.o \
14 16
               kmer_matrix.o \
15 17
               logger.o \
16 18
               motif.o \
... ...
@@ -1,15 +1,14 @@
1 1
 include Makevars.common
2 2
 
3
-SAMVARS=$(shell echo 'cat(system.file("usretc", .Platform[["r_arch"]],\
4
-    "Rsamtools.mk", package="Rsamtools", mustWork=TRUE))' |\
3
+RHTSLIB_LIBS=$(shell echo 'Rhtslib::pkgconfig("PKG_LIBS")'|\
4
+    "${R_HOME}/bin/R" --vanilla --slave)
5
+RHTSLIB_CPPFLAGS=$(shell echo 'Rhtslib::pkgconfig("PKG_CPPFLAGS")'|\
5 6
     "${R_HOME}/bin/R" --vanilla --slave)
6
-include $(SAMVARS)
7 7
 
8
-PKG_LIBS=$(SAMTOOLS_LIBS)
9
-PKG_CPPFLAGS=$(SAMTOOLS_CPPFLAGS)
8
+PKG_LIBS=$(RHTSLIB_LIBS)
9
+PKG_CPPFLAGS=$(RHTSLIB_CPPFLAGS)
10 10
 
11
-OBJECTS = $(SEQBIAS_OBJ) \
12
-		  $(YAML_CPP_OBJ:%=yaml-cpp/%)
11
+OBJECTS = $(SEQBIAS_OBJ) $(YAML_CPP_OBJ:%=yaml-cpp/%)
13 12
 
14 13
 all : $(SHLIB)
15 14
 
16 15
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+#include <bam_aux.c>
0 2
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+#include <bam_plbuf.c>
... ...
@@ -24,7 +24,7 @@ extern "C" {
24 24
 #include <stdint.h>
25 25
 #include <stdlib.h>
26 26
 #include <stdbool.h>
27
-#include "samtools/sam.h"
27
+#include "sam.h"
28 28
 
29 29
 
30 30
 /* The table maps positions to counts. */
31 31
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+#include <sam.c>
0 2
deleted file mode 100644
... ...
@@ -1,100 +0,0 @@
1
-
2
-#include "logger.h"
3
-#include "samtools_extra.h"
4
-#include "samtools/khash.h"
5
-
6
-
7
-#ifndef _NO_RAZF
8
-#include "samtools/razf.h"
9
-#else
10
-#ifdef _WIN32
11
-#define ftello(fp) ftell(fp)
12
-#define fseeko(fp, offset, whence) fseek(fp, offset, whence)
13
-#else
14
-extern off_t ftello(FILE *stream);
15
-extern int fseeko(FILE *stream, off_t offset, int whence);
16
-#endif
17
-#define RAZF FILE
18
-#define razf_read(fp, buf, size) fread(buf, 1, size, fp)
19
-#define razf_open(fn, mode) fopen(fn, mode)
20
-#define razf_close(fp) fclose(fp)
21
-#define razf_seek(fp, offset, whence) fseeko(fp, offset, whence)
22
-#define razf_tell(fp) ftello(fp)
23
-#endif
24
-#ifdef _USE_KNETFILE
25
-#include "samtools/knetfile.h"
26
-#endif
27
-
28
-#include <ctype.h>
29
-
30
-
31
-typedef struct {
32
-	int32_t line_len, line_blen;
33
-	int64_t len;
34
-	uint64_t offset;
35
-} faidx1_t;
36
-KHASH_MAP_INIT_STR(s, faidx1_t)
37
-
38
-
39
-struct __faidx_t {
40
-	RAZF *rz;
41
-	int n, m;
42
-	char **name;
43
-	khash_t(s) *hash;
44
-};
45
-
46
-
47
-
48
-
49
-char* faidx_fetch_seq_forced_lower( const faidx_t* fai, const char *c_name, int p_beg_i, int p_end_i )
50
-{
51
-
52
-	int l;
53
-	char c;
54
-    khiter_t iter;
55
-    faidx1_t val;
56
-    char* seq0;
57
-    char* seq = NULL;
58
-
59
-    iter = kh_get(s, fai->hash, c_name);
60
-    if(iter == kh_end(fai->hash)) return 0;
61
-
62
-    seq0 = seq = (char*)malloc( (p_end_i - p_beg_i + 2) * sizeof(char) );
63
-    if( seq0 == NULL ) logger_abort("Out of memory.");
64
-    seq0[p_end_i-p_beg_i+1] = '\0';
65
-
66
-    val = kh_value(fai->hash, iter);
67
-
68
-    /* entirely off the map: all Ns */
69
-    if( p_beg_i >= (int)val.len || p_end_i < 0 ) {
70
-        while( p_beg_i <= p_end_i ) {
71
-            *seq++ ='n';
72
-            ++p_beg_i;
73
-        }
74
-        return seq0;
75
-    }
76
-
77
-    /* beginning is off the map */
78
-    while( p_beg_i < 0 && p_beg_i <= p_end_i ) {
79
-        *seq++ = 'n';
80
-        p_beg_i++;
81
-    }
82
-
83
-    /* end is off the map */
84
-    while( p_end_i >= (int)val.len ) {
85
-        seq[p_end_i-p_beg_i] = 'n';
86
-        p_end_i--;
87
-    }
88
-
89
-    /* retrieve the sequence */
90
-	l = 0;
91
-	razf_seek(fai->rz, val.offset + p_beg_i / val.line_blen * val.line_len + p_beg_i % val.line_blen, SEEK_SET);
92
-	while (razf_read(fai->rz, &c, 1) == 1 && l < p_end_i - p_beg_i + 1)
93
-		if (isgraph(c)) seq[l++] = tolower(c);
94
-    
95
-    while( p_beg_i+l <= p_end_i ) seq[l++] = 'n';
96
-
97
-    return seq0;
98
-}
99
-
100
-
101 0
deleted file mode 100644
... ...
@@ -1,32 +0,0 @@
1
-
2
-#ifndef ISOLATOR_SAMTOOLS_EXTRA_H
3
-#define ISOLATOR_SAMTOOLS_EXTRA_H
4
-
5
-#ifdef __cplusplus
6
-extern "C" {
7
-#endif
8
-
9
-
10
-#include "samtools/faidx.h"
11
-#include "samtools/bam.h"
12
-
13
-
14
-/* exposing a function defined in samtools/bam_aux.c */
15
-void bam_init_header_hash(bam_header_t *header);
16
-
17
-
18
-/* Change the behavior of the faidx_fetch_seq function to be more useful. If
19
- * coordinates are outside the actual sequence, write N's, rather than adjusting
20
- * the start,end. */
21
-char* faidx_fetch_seq_forced_lower(const faidx_t* fai, const char *c_name, int p_beg_i, int p_end_i);
22
-
23
-
24
-
25
-#ifdef __cplusplus
26
-}
27
-#endif
28
-
29
-
30
-#endif
31
-
32
-
... ...
@@ -10,8 +10,8 @@
10 10
 
11 11
 extern "C" {
12 12
 
13
-#include "samtools/faidx.h"
14
-#include "samtools/sam.h"
13
+#include "htslib/faidx.h"
14
+#include "sam.h"
15 15
 
16 16
 
17 17
 #ifdef ERROR
... ...
@@ -9,8 +9,7 @@
9 9
 #include "logger.hpp"
10 10
 #include "twobitseq.hpp"
11 11
 #include "miscmath.h"
12
-#include "samtools_extra.h"
13
-#include "samtools/faidx.h"
12
+#include "htslib/faidx.h"
14 13
 #include <climits>
15 14
 #include <cmath>
16 15
 #include <cctype>
... ...
@@ -219,7 +218,7 @@ void sequencing_bias::build(const char* ref_fn,
219 218
         logger::abort("Can't open bam index '%s.bai'.", reads_fn);
220 219
     }
221 220
 
222
-    bam_init_header_hash(reads_f->header);
221
+    //bam_init_header_hash(reads_f->header);
223 222
 
224 223
     bam1_t* read = bam_init1();
225 224
 
... ...
@@ -485,7 +484,7 @@ kmer_matrix tabulate_bias(double* kl,
485 484
     }
486 485
 
487 486
 
488
-    bam_init_header_hash(reads_f->header);
487
+    //bam_init_header_hash(reads_f->header);
489 488
     bam1_t* read = bam_init1();
490 489
 
491 490
     pos_table T;
... ...
@@ -12,7 +12,7 @@
12 12
 #include "common.h"
13 13
 #include "motif.hpp"
14 14
 #include "pos_table.h"
15
-#include "samtools/faidx.h"
15
+#include "htslib/faidx.h"
16 16
 #include "yaml-cpp/yaml.h"
17 17
 #include <string>
18 18