htslib 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -49
  3. data/TUTORIAL.md +9 -20
  4. data/ext/htslib_native/extconf.rb +41 -0
  5. data/ext/htslib_native/htslib_native.h +11 -0
  6. data/ext/htslib_native/htslib_native_ext.c +48 -0
  7. data/ext/htslib_native/native_bam.c +1108 -0
  8. data/ext/htslib_native/native_bcf.c +369 -0
  9. data/ext/htslib_native/native_faidx.c +155 -0
  10. data/ext/htslib_native/native_tabix.c +246 -0
  11. data/lib/hts/bam/auxi.rb +87 -342
  12. data/lib/hts/bam/base_mod.rb +37 -73
  13. data/lib/hts/bam/cigar.rb +9 -55
  14. data/lib/hts/bam/flag.rb +19 -27
  15. data/lib/hts/bam/header.rb +29 -56
  16. data/lib/hts/bam/mpileup.rb +158 -132
  17. data/lib/hts/bam/pileup.rb +120 -145
  18. data/lib/hts/bam/record.rb +233 -270
  19. data/lib/hts/bam.rb +102 -42
  20. data/lib/hts/bcf/errors.rb +1 -0
  21. data/lib/hts/bcf/format.rb +278 -379
  22. data/lib/hts/bcf/header.rb +38 -122
  23. data/lib/hts/bcf/header_record.rb +9 -35
  24. data/lib/hts/bcf/info.rb +72 -320
  25. data/lib/hts/bcf/record.rb +61 -102
  26. data/lib/hts/bcf.rb +149 -323
  27. data/lib/hts/faidx.rb +28 -87
  28. data/lib/hts/hts.rb +6 -94
  29. data/lib/hts/native.rb +13 -0
  30. data/lib/hts/tabix.rb +93 -48
  31. data/lib/hts/version.rb +1 -1
  32. data/lib/htslib.rb +6 -52
  33. metadata +13 -64
  34. data/lib/hts/ffi_ext/README.md +0 -8
  35. data/lib/hts/ffi_ext/pointer.rb +0 -18
  36. data/lib/hts/ffi_ext/struct.rb +0 -45
  37. data/lib/hts/libhts/bgzf.rb +0 -199
  38. data/lib/hts/libhts/constants.rb +0 -658
  39. data/lib/hts/libhts/cram.rb +0 -471
  40. data/lib/hts/libhts/fai.rb +0 -146
  41. data/lib/hts/libhts/hfile.rb +0 -121
  42. data/lib/hts/libhts/hts.rb +0 -477
  43. data/lib/hts/libhts/kfunc.rb +0 -38
  44. data/lib/hts/libhts/sam.rb +0 -760
  45. data/lib/hts/libhts/sam_funcs.rb +0 -155
  46. data/lib/hts/libhts/tbx.rb +0 -94
  47. data/lib/hts/libhts/tbx_funcs.rb +0 -36
  48. data/lib/hts/libhts/thread_pool.rb +0 -139
  49. data/lib/hts/libhts/vcf.rb +0 -567
  50. data/lib/hts/libhts/vcf_funcs.rb +0 -366
  51. data/lib/hts/libhts.rb +0 -47
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- module LibHTS
5
- # constants
6
- BAM_CMATCH = 0
7
- BAM_CINS = 1
8
- BAM_CDEL = 2
9
- BAM_CREF_SKIP = 3
10
- BAM_CSOFT_CLIP = 4
11
- BAM_CHARD_CLIP = 5
12
- BAM_CPAD = 6
13
- BAM_CEQUAL = 7
14
- BAM_CDIFF = 8
15
- BAM_CBACK = 9
16
-
17
- BAM_CIGAR_STR = "MIDNSHP=XB"
18
- BAM_CIGAR_SHIFT = 4
19
- BAM_CIGAR_MASK = 0xf
20
- BAM_CIGAR_TYPE = 0x3C1A7
21
-
22
- # macros
23
- class << self
24
- def bam_cigar_op(c)
25
- c & BAM_CIGAR_MASK
26
- end
27
-
28
- def bam_cigar_oplen(c)
29
- c >> BAM_CIGAR_SHIFT
30
- end
31
-
32
- def bam_cigar_opchr(c)
33
- "#{BAM_CIGAR_STR}??????"[bam_cigar_op(c)]
34
- end
35
-
36
- def bam_cigar_gen(l, o)
37
- (l << BAM_CIGAR_SHIFT) | o
38
- end
39
-
40
- def bam_cigar_type(o)
41
- (BAM_CIGAR_TYPE >> (o << 1)) & 3
42
- end
43
- end
44
-
45
- BAM_FPAIRED = 1
46
- BAM_FPROPER_PAIR = 2
47
- BAM_FUNMAP = 4
48
- BAM_FMUNMAP = 8
49
- BAM_FREVERSE = 16
50
- BAM_FMREVERSE = 32
51
- BAM_FREAD1 = 64
52
- BAM_FREAD2 = 128
53
- BAM_FSECONDARY = 256
54
- BAM_FQCFAIL = 512
55
- BAM_FDUP = 1024
56
- BAM_FSUPPLEMENTARY = 2048
57
-
58
- # macros
59
- # function-like macros
60
- class << self
61
- # Get whether the query is on the reverse strand
62
- def bam_is_rev(b)
63
- b[:core][:flag] & BAM_FREVERSE != 0
64
- end
65
-
66
- # Get whether the query's mate is on the reverse strand
67
- def bam_is_mrev(b)
68
- b[:core][:flag] & BAM_FMREVERSE != 0
69
- end
70
-
71
- # Get the name of the query
72
- def bam_get_qname(b)
73
- b[:data]
74
- end
75
-
76
- # Get the CIGAR array
77
- def bam_get_cigar(b)
78
- b[:data] + b[:core][:l_qname]
79
- end
80
-
81
- # Get query sequence
82
- def bam_get_seq(b)
83
- b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname]
84
- end
85
-
86
- # Get query quality
87
- def bam_get_qual(b)
88
- b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname] + ((b[:core][:l_qseq] + 1) >> 1)
89
- end
90
-
91
- # Get auxiliary data
92
- def bam_get_aux(b)
93
- b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname] + ((b[:core][:l_qseq] + 1) >> 1) + b[:core][:l_qseq]
94
- end
95
-
96
- # Get length of auxiliary data
97
- def bam_get_l_aux(b)
98
- b[:l_data] - (b[:core][:n_cigar] << 2) - b[:core][:l_qname] - b[:core][:l_qseq] - ((b[:core][:l_qseq] + 1) >> 1)
99
- end
100
-
101
- # Get a base on read
102
- def bam_seqi(s, i)
103
- (s[i >> 1].read_uint8 >> ((~i & 1) << 2)) & 0xf
104
- end
105
-
106
- # Modifies a single base in the bam structure.
107
- def bam_set_seqi(s, i, b)
108
- s[i >> 1] = (s[i >> 1] & (0xf0 >> ((~i & 1) << 2))) | (b << ((~i & 1) << 2))
109
- end
110
-
111
- # Returns the SAM formatted text of the \@HD header line
112
- def sam_hdr_find_hd(h, ks)
113
- sam_hdr_find_line_id(h, "HD", nil, nil, ks)
114
- end
115
-
116
- # Returns the value associated with a given \@HD line tag
117
- def sam_hdr_find_tag_hd(h, key, ks)
118
- sam_hdr_find_tag_id(h, "HD", nil, nil, key, ks)
119
- end
120
-
121
- # Adds or updates tags on the header \@HD line
122
- def sam_hdr_update_hd(h, *args)
123
- sam_hdr_update_line(h, "HD", nil, nil, *args, nil)
124
- end
125
-
126
- # Removes the \@HD line tag with the given key
127
- def sam_hdr_remove_tag_hd(h, key)
128
- sam_hdr_remove_tag_id(h, "HD", nil, nil, key)
129
- end
130
-
131
- BAM_USER_OWNS_STRUCT = 1
132
- BAM_USER_OWNS_DATA = 2
133
-
134
- alias bam_itr_destroy hts_itr_destroy
135
- alias bam_itr_queryi sam_itr_queryi
136
- alias bam_itr_querys sam_itr_querys
137
- alias bam_itr_next sam_itr_next
138
-
139
- # Load/build .csi or .bai BAM index file. Does not work with CRAM.
140
- # It is recommended to use the sam_index_* functions below instead.
141
- def bam_index_load(fn)
142
- hts_idx_load(fn, HTS_FMT_BAI)
143
- end
144
-
145
- alias bam_index_build sam_index_build
146
-
147
- alias sam_itr_destroy hts_itr_destroy
148
-
149
- alias sam_open hts_open
150
- alias sam_open_format hts_open_format
151
- alias sam_flush hts_flush
152
- alias sam_close hts_close
153
- end
154
- end
155
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- module LibHTS
5
- attach_variable :tbx_conf_gff, TbxConf
6
- attach_variable :tbx_conf_bed, TbxConf
7
- attach_variable :tbx_conf_psltbl, TbxConf
8
- attach_variable :tbx_conf_sam, TbxConf
9
- attach_variable :tbx_conf_vcf, TbxConf
10
- attach_variable :tbx_conf_gaf, TbxConf
11
-
12
- attach_function \
13
- :tbx_name2id,
14
- [Tbx, :string],
15
- :int
16
-
17
- attach_function \
18
- :tbx_itr_querys1,
19
- [Tbx, :string],
20
- HtsItr.by_ref
21
-
22
- attach_function \
23
- :tbx_itr_regarray,
24
- [Tbx, :pointer, :uint],
25
- HtsItr.by_ref
26
-
27
- attach_function \
28
- :tbx_itr_next1,
29
- [HtsFile, Tbx, HtsItr, :pointer],
30
- :int
31
-
32
- # Internal helper function used by tbx_itr_next()
33
- attach_function \
34
- :hts_get_bgzfp,
35
- [HtsFile],
36
- BGZF.by_ref
37
-
38
- attach_function \
39
- :tbx_readrec,
40
- [BGZF, :pointer, :pointer, :pointer, :pointer, :pointer],
41
- :int
42
-
43
- # Build an index of the lines in a BGZF-compressed file
44
- attach_function \
45
- :tbx_index,
46
- [BGZF, :int, TbxConf],
47
- Tbx.by_ref
48
-
49
- attach_function \
50
- :tbx_index_build,
51
- [:string, :int, TbxConf],
52
- :int
53
-
54
- attach_function \
55
- :tbx_index_build2,
56
- [:string, :string, :int, TbxConf],
57
- :int
58
-
59
- attach_function \
60
- :tbx_index_build3,
61
- [:string, :string, :int, :int, TbxConf],
62
- :int
63
-
64
- # Load or stream a .tbi or .csi index
65
- attach_function \
66
- :tbx_index_load,
67
- [:string],
68
- Tbx.by_ref
69
-
70
- # Load or stream a .tbi or .csi index
71
- attach_function \
72
- :tbx_index_load2,
73
- %i[string string],
74
- Tbx.by_ref
75
-
76
- # Load or stream a .tbi or .csi index
77
- attach_function \
78
- :tbx_index_load3,
79
- %i[string string int],
80
- Tbx.by_ref
81
-
82
- attach_function \
83
- :tbx_seqnames,
84
- [Tbx, :pointer],
85
- :pointer
86
-
87
- attach_function \
88
- :tbx_destroy,
89
- [Tbx],
90
- :void
91
- end
92
- end
93
-
94
- require_relative "tbx_funcs"
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- module LibHTS
5
- class << self
6
- def tbx_itr_destroy(iter)
7
- hts_itr_destroy(iter)
8
- end
9
-
10
- def tbx_itr_queryi(tbx, tid, beg, end_)
11
- hts_itr_query(tbx[:idx], tid, beg, end_, @ffi_functions[:tbx_readrec])
12
- end
13
-
14
- @@tbx_name2id = proc do |tbx, ss|
15
- LibHTS.tbx_name2id(tbx, ss)
16
- end
17
-
18
- def tbx_itr_querys(tbx, s)
19
- return tbx_itr_querys1(tbx, s) if respond_to?(:tbx_itr_querys1)
20
-
21
- hts_itr_querys(tbx[:idx], s, @@tbx_name2id, tbx, @ffi_functions[:hts_itr_query],
22
- @ffi_functions[:tbx_readrec])
23
- end
24
-
25
- def tbx_itr_next(htsfp, tbx, itr, r)
26
- return tbx_itr_next1(htsfp, tbx, itr, r) if respond_to?(:tbx_itr_next1)
27
-
28
- hts_itr_next(hts_get_bgzfp(htsfp), itr, r, tbx)
29
- end
30
-
31
- def tbx_bgzf_itr_next(bgzfp, tbx, itr, r)
32
- hts_itr_next(bgzfp, itr, r, tbx)
33
- end
34
- end
35
- end
36
- end
@@ -1,139 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- module LibHTS
5
- attach_function \
6
- :hts_tpool_init,
7
- [:int],
8
- HtsTpool.by_ref
9
-
10
- attach_function \
11
- :hts_tpool_size,
12
- [HtsTpool],
13
- :int
14
-
15
- # FIXME: struct
16
- HtsTpoolProcess = :pointer
17
- HtsTpoolResult = :pointer
18
-
19
- attach_function \
20
- :hts_tpool_dispatch,
21
- [HtsTpool, HtsTpoolProcess, :pointer, :pointer],
22
- :int
23
-
24
- attach_function \
25
- :hts_tpool_dispatch2,
26
- [HtsTpool, HtsTpoolProcess, :pointer, :pointer, :int],
27
- :int
28
-
29
- attach_function \
30
- :hts_tpool_dispatch3,
31
- [HtsTpool, HtsTpoolProcess, :pointer, :pointer, :pointer, :pointer, :int],
32
- :int
33
-
34
- attach_function \
35
- :hts_tpool_wake_dispatch,
36
- [HtsTpoolProcess],
37
- :void
38
-
39
- attach_function \
40
- :hts_tpool_process_flush,
41
- [HtsTpoolProcess],
42
- :int
43
-
44
- attach_function \
45
- :hts_tpool_process_reset,
46
- [HtsTpoolProcess, :int],
47
- :int
48
-
49
- attach_function \
50
- :hts_tpool_process_qsize,
51
- [HtsTpoolProcess],
52
- :int
53
-
54
- attach_function \
55
- :hts_tpool_destroy,
56
- [HtsTpool],
57
- :void
58
-
59
- attach_function \
60
- :hts_tpool_kill,
61
- [HtsTpool],
62
- :void
63
-
64
- attach_function \
65
- :hts_tpool_next_result,
66
- [HtsTpoolProcess],
67
- HtsTpoolResult # .by_ref
68
-
69
- attach_function \
70
- :hts_tpool_next_result_wait,
71
- [HtsTpoolProcess],
72
- HtsTpoolResult # .by_ref
73
-
74
- attach_function \
75
- :hts_tpool_delete_result,
76
- [HtsTpoolResult, :int],
77
- :void
78
-
79
- attach_function \
80
- :hts_tpool_result_data,
81
- [HtsTpoolResult],
82
- :pointer
83
-
84
- attach_function \
85
- :hts_tpool_process_init,
86
- [HtsTpool, :int, :int],
87
- HtsTpoolProcess # .by_ref
88
-
89
- attach_function \
90
- :hts_tpool_process_destroy,
91
- [HtsTpoolProcess],
92
- :void
93
-
94
- attach_function \
95
- :hts_tpool_process_empty,
96
- [HtsTpoolProcess],
97
- :int
98
-
99
- attach_function \
100
- :hts_tpool_process_len,
101
- [HtsTpoolProcess],
102
- :int
103
-
104
- attach_function \
105
- :hts_tpool_process_sz,
106
- [HtsTpoolProcess],
107
- :int
108
-
109
- attach_function \
110
- :hts_tpool_process_shutdown,
111
- [HtsTpoolProcess],
112
- :void
113
-
114
- attach_function \
115
- :hts_tpool_process_is_shutdown,
116
- [HtsTpoolProcess],
117
- :int
118
-
119
- attach_function \
120
- :hts_tpool_process_attach,
121
- [HtsTpool, HtsTpoolProcess],
122
- :void
123
-
124
- attach_function \
125
- :hts_tpool_process_detach,
126
- [HtsTpool, HtsTpoolProcess],
127
- :void
128
-
129
- attach_function \
130
- :hts_tpool_process_ref_incr,
131
- [HtsTpoolProcess],
132
- :void
133
-
134
- attach_function \
135
- :hts_tpool_process_ref_decr,
136
- [HtsTpoolProcess],
137
- :void
138
- end
139
- end