htslib 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +68 -17
- data/lib/hts/bam/cigar.rb +9 -6
- data/lib/hts/bam/flag.rb +93 -0
- data/lib/hts/bam/header.rb +12 -6
- data/lib/hts/bam/record.rb +195 -0
- data/lib/hts/bam.rb +67 -32
- data/lib/hts/bcf/format.rb +52 -0
- data/lib/hts/bcf/header.rb +19 -0
- data/lib/hts/bcf/info.rb +93 -0
- data/lib/hts/bcf/record.rb +110 -0
- data/lib/hts/bcf.rb +73 -0
- data/lib/hts/faidx.rb +59 -0
- data/lib/hts/ffi_ext/README.md +8 -0
- data/lib/hts/ffi_ext/struct.rb +45 -0
- data/lib/hts/{ffi → libhts}/bgzf.rb +2 -2
- data/lib/hts/{ffi → libhts}/constants.rb +144 -76
- data/lib/hts/{ffi → libhts}/faidx.rb +1 -1
- data/lib/hts/{ffi → libhts}/hfile.rb +2 -2
- data/lib/hts/{ffi → libhts}/hts.rb +9 -3
- data/lib/hts/{ffi → libhts}/kfunc.rb +1 -1
- data/lib/hts/{ffi → libhts}/sam.rb +60 -30
- data/lib/hts/{ffi → libhts}/tbx.rb +1 -1
- data/lib/hts/{ffi → libhts}/vcf.rb +215 -12
- data/lib/hts/libhts.rb +33 -0
- data/lib/hts/tabix.rb +28 -0
- data/lib/hts/version.rb +1 -1
- data/lib/htslib.rb +32 -17
- metadata +49 -28
- data/lib/hts/bam/alignment.rb +0 -156
- data/lib/hts/fai.rb +0 -18
- data/lib/hts/ffi.rb +0 -43
- data/lib/hts/tbx.rb +0 -16
- data/lib/hts/vcf.rb +0 -32
@@ -1,7 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTS
|
4
|
-
module
|
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
|
+
|
5
22
|
# macros
|
6
23
|
class << self
|
7
24
|
def bam_cigar_op(c)
|
@@ -13,7 +30,7 @@ module HTS
|
|
13
30
|
end
|
14
31
|
|
15
32
|
def bam_cigar_opchr(c)
|
16
|
-
(BAM_CIGAR_STR
|
33
|
+
("#{BAM_CIGAR_STR}??????")[bam_cigar_op(c)]
|
17
34
|
end
|
18
35
|
|
19
36
|
def bam_cigar_gen(l, o)
|
@@ -25,6 +42,19 @@ module HTS
|
|
25
42
|
end
|
26
43
|
end
|
27
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
|
+
|
28
58
|
# macros
|
29
59
|
# function-like macros
|
30
60
|
class << self
|
@@ -148,13 +178,13 @@ module HTS
|
|
148
178
|
# Returns a complete line of formatted text for a given type and ID.
|
149
179
|
attach_function \
|
150
180
|
:sam_hdr_find_line_id,
|
151
|
-
[SamHdr, :string, :string, :string,
|
181
|
+
[SamHdr, :string, :string, :string, KString],
|
152
182
|
:int
|
153
183
|
|
154
184
|
# Returns a complete line of formatted text for a given type and index.
|
155
185
|
attach_function \
|
156
186
|
:sam_hdr_find_line_pos,
|
157
|
-
[SamHdr, :string, :int,
|
187
|
+
[SamHdr, :string, :int, KString],
|
158
188
|
:int
|
159
189
|
|
160
190
|
# Remove a line with given type / id from a header
|
@@ -208,13 +238,13 @@ module HTS
|
|
208
238
|
# Return the value associated with a key for a header line identified by ID_key:ID_val
|
209
239
|
attach_function \
|
210
240
|
:sam_hdr_find_tag_id,
|
211
|
-
[SamHdr, :string, :string, :string, :string,
|
241
|
+
[SamHdr, :string, :string, :string, :string, KString],
|
212
242
|
:int
|
213
243
|
|
214
244
|
# Return the value associated with a key for a header line identified by position
|
215
245
|
attach_function \
|
216
246
|
:sam_hdr_find_tag_pos,
|
217
|
-
[SamHdr, :string, :int, :string,
|
247
|
+
[SamHdr, :string, :int, :string, KString],
|
218
248
|
:int
|
219
249
|
|
220
250
|
# Remove the key from the line identified by type, ID_key and ID_value.
|
@@ -410,7 +440,7 @@ module HTS
|
|
410
440
|
# Get the next read from a SAM/BAM/CRAM iterator
|
411
441
|
def self.sam_itr_next(htsfp, itr, r)
|
412
442
|
# FIXME: check if htsfp is compressed BGZF
|
413
|
-
hts_log_error(
|
443
|
+
hts_log_error("Null iterator") if itr.null?
|
414
444
|
# FIXME: check multi
|
415
445
|
hts_itr_next(htsfp[:fp][:bgzf], itr, r, htsfp)
|
416
446
|
end
|
@@ -445,12 +475,12 @@ module HTS
|
|
445
475
|
|
446
476
|
attach_function \
|
447
477
|
:sam_parse1,
|
448
|
-
[
|
478
|
+
[KString, SamHdr, Bam1],
|
449
479
|
:int
|
450
480
|
|
451
481
|
attach_function \
|
452
482
|
:sam_format1,
|
453
|
-
[SamHdr, Bam1,
|
483
|
+
[SamHdr, Bam1, KString],
|
454
484
|
:int
|
455
485
|
|
456
486
|
# Read a record from a file
|
@@ -553,52 +583,52 @@ module HTS
|
|
553
583
|
attach_function \
|
554
584
|
:bam_plp_init,
|
555
585
|
%i[bam_plp_auto_f pointer],
|
556
|
-
|
586
|
+
:bam_plp
|
557
587
|
|
558
588
|
attach_function \
|
559
589
|
:bam_plp_destroy,
|
560
|
-
[
|
590
|
+
[:bam_plp],
|
561
591
|
:void
|
562
592
|
|
563
593
|
attach_function \
|
564
594
|
:bam_plp_push,
|
565
|
-
[
|
595
|
+
[:bam_plp, Bam1],
|
566
596
|
:int
|
567
597
|
|
568
598
|
attach_function \
|
569
599
|
:bam_plp_next,
|
570
|
-
[
|
571
|
-
|
600
|
+
%i[bam_plp pointer pointer pointer],
|
601
|
+
BamPileup1.by_ref
|
572
602
|
|
573
603
|
attach_function \
|
574
604
|
:bam_plp_auto,
|
575
|
-
[
|
576
|
-
|
605
|
+
%i[bam_plp pointer pointer pointer],
|
606
|
+
BamPileup1.by_ref
|
577
607
|
|
578
608
|
attach_function \
|
579
609
|
:bam_plp64_next,
|
580
|
-
[
|
581
|
-
|
610
|
+
%i[bam_plp pointer pointer pointer],
|
611
|
+
BamPileup1.by_ref
|
582
612
|
|
583
613
|
attach_function \
|
584
614
|
:bam_plp64_auto,
|
585
|
-
[
|
586
|
-
|
615
|
+
%i[bam_plp pointer pointer pointer],
|
616
|
+
BamPileup1.by_ref
|
587
617
|
|
588
618
|
attach_function \
|
589
619
|
:bam_plp_set_maxcnt,
|
590
|
-
[
|
620
|
+
%i[bam_plp int],
|
591
621
|
:void
|
592
622
|
|
593
623
|
attach_function \
|
594
624
|
:bam_plp_reset,
|
595
|
-
[
|
625
|
+
[:bam_plp],
|
596
626
|
:void
|
597
627
|
|
598
628
|
# sets a callback to initialise any per-pileup1_t fields.
|
599
629
|
attach_function \
|
600
630
|
:bam_plp_insertion,
|
601
|
-
[
|
631
|
+
[BamPileup1, KString, :pointer],
|
602
632
|
:int
|
603
633
|
|
604
634
|
# sets a callback to initialise any per-pileup1_t fields.
|
@@ -612,36 +642,36 @@ module HTS
|
|
612
642
|
attach_function \
|
613
643
|
:bam_mplp_init,
|
614
644
|
%i[int bam_plp_auto_f pointer],
|
615
|
-
|
645
|
+
:bam_mplp
|
616
646
|
|
617
647
|
attach_function \
|
618
648
|
:bam_mplp_init_overlaps,
|
619
|
-
[
|
649
|
+
[:bam_mplp],
|
620
650
|
:int
|
621
651
|
|
622
652
|
attach_function \
|
623
653
|
:bam_mplp_destroy,
|
624
|
-
[
|
654
|
+
[:bam_mplp],
|
625
655
|
:void
|
626
656
|
|
627
657
|
attach_function \
|
628
658
|
:bam_mplp_set_maxcnt,
|
629
|
-
[
|
659
|
+
%i[bam_mplp int],
|
630
660
|
:void
|
631
661
|
|
632
662
|
attach_function \
|
633
663
|
:bam_mplp_auto,
|
634
|
-
[
|
664
|
+
%i[bam_mplp pointer pointer pointer pointer], # BamPileup1T
|
635
665
|
:int
|
636
666
|
|
637
667
|
attach_function \
|
638
668
|
:bam_mplp64_auto,
|
639
|
-
[
|
669
|
+
%i[bam_mplp pointer pointer pointer pointer], # BamPileup1T
|
640
670
|
:int
|
641
671
|
|
642
672
|
attach_function \
|
643
673
|
:bam_mplp_reset,
|
644
|
-
[
|
674
|
+
[:bam_mplp],
|
645
675
|
:void
|
646
676
|
|
647
677
|
# bam_mplp_constructor
|
@@ -1,7 +1,210 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTS
|
4
|
-
module
|
4
|
+
module LibHTS
|
5
|
+
# constants
|
6
|
+
BCF_HL_FLT = 0 # header line
|
7
|
+
BCF_HL_INFO = 1
|
8
|
+
BCF_HL_FMT = 2
|
9
|
+
BCF_HL_CTG = 3
|
10
|
+
BCF_HL_STR = 4 # structured header line TAG=<A=..,B=..>
|
11
|
+
BCF_HL_GEN = 5 # generic header line
|
12
|
+
BCF_HT_FLAG = 0 # header type
|
13
|
+
|
14
|
+
BCF_HT_INT = 1
|
15
|
+
BCF_HT_REAL = 2
|
16
|
+
BCF_HT_STR = 3
|
17
|
+
BCF_HT_LONG = (BCF_HT_INT | 0x100) # BCF_HT_INT, but for int64_t values; VCF only!
|
18
|
+
|
19
|
+
BCF_VL_FIXED = 0 # variable length
|
20
|
+
BCF_VL_VAR = 1
|
21
|
+
BCF_VL_A = 2
|
22
|
+
BCF_VL_G = 3
|
23
|
+
BCF_VL_R = 4
|
24
|
+
|
25
|
+
BCF_DT_ID = 0 # dictionary type
|
26
|
+
BCF_DT_CTG = 1
|
27
|
+
BCF_DT_SAMPLE = 2
|
28
|
+
|
29
|
+
BCF_BT_NULL = 0
|
30
|
+
BCF_BT_INT8 = 1
|
31
|
+
BCF_BT_INT16 = 2
|
32
|
+
BCF_BT_INT32 = 3
|
33
|
+
BCF_BT_INT64 = 4 # Unofficial, for internal use only.
|
34
|
+
BCF_BT_FLOAT = 5
|
35
|
+
BCF_BT_CHAR = 7
|
36
|
+
|
37
|
+
VCF_REF = 0
|
38
|
+
VCF_SNP = 1
|
39
|
+
VCF_MNP = 2
|
40
|
+
VCF_INDEL = 4
|
41
|
+
VCF_OTHER = 8
|
42
|
+
VCF_BND = 16 # breakend
|
43
|
+
VCF_OVERLAP = 32 # overlapping deletion, ALT=*
|
44
|
+
|
45
|
+
BCF1_DIRTY_ID = 1
|
46
|
+
BCF1_DIRTY_ALS = 2
|
47
|
+
BCF1_DIRTY_FLT = 4
|
48
|
+
BCF1_DIRTY_INF = 8
|
49
|
+
|
50
|
+
BCF_ERR_CTG_UNDEF = 1
|
51
|
+
BCF_ERR_TAG_UNDEF = 2
|
52
|
+
BCF_ERR_NCOLS = 4
|
53
|
+
BCF_ERR_LIMITS = 8
|
54
|
+
BCF_ERR_CHAR = 16
|
55
|
+
BCF_ERR_CTG_INVALID = 32
|
56
|
+
BCF_ERR_TAG_INVALID = 64
|
57
|
+
|
58
|
+
# macros
|
59
|
+
class << self
|
60
|
+
alias bcf_open hts_open
|
61
|
+
alias vcf_open hts_open
|
62
|
+
alias bcf_close hts_close
|
63
|
+
alias vcf_close hts_close
|
64
|
+
|
65
|
+
def bcf_hdr_nsamples(hdr)
|
66
|
+
hdr[:n][BCF_DT_SAMPLE]
|
67
|
+
end
|
68
|
+
|
69
|
+
def bcf_update_info_int32(hdr, line, key, values, n)
|
70
|
+
bcf_update_info(hdr, line, key, values, n, BCF_HT_INT)
|
71
|
+
end
|
72
|
+
|
73
|
+
def bcf_update_info_float(hdr, line, key, values, n)
|
74
|
+
bcf_update_info(hdr, line, key, values, n, BCF_HT_REAL)
|
75
|
+
end
|
76
|
+
|
77
|
+
def bcf_update_info_flag(hdr, line, key, string, n)
|
78
|
+
bcf_update_info(hdr, line, key, string, n, BCF_HT_FLAG)
|
79
|
+
end
|
80
|
+
|
81
|
+
def bcf_update_info_string(hdr, line, key, string)
|
82
|
+
bcf_update_info(hdr, line, key, string, 1, BCF_HT_STR)
|
83
|
+
end
|
84
|
+
|
85
|
+
def bcf_update_format_int32(hdr, line, key, values, n)
|
86
|
+
bcf_update_format(hdr, line, key, values, n,
|
87
|
+
BCF_HT_INT)
|
88
|
+
end
|
89
|
+
|
90
|
+
def bcf_update_format_float(hdr, line, key, values, n)
|
91
|
+
bcf_update_format(hdr, line, key, values, n,
|
92
|
+
BCF_HT_REAL)
|
93
|
+
end
|
94
|
+
|
95
|
+
def bcf_update_format_char(hdr, line, key, values, n)
|
96
|
+
bcf_update_format(hdr, line, key, values, n,
|
97
|
+
BCF_HT_STR)
|
98
|
+
end
|
99
|
+
|
100
|
+
def bcf_update_genotypes(hdr, line, gts, n)
|
101
|
+
bcf_update_format(hdr, line, "GT", gts, n, BCF_HT_INT)
|
102
|
+
end
|
103
|
+
|
104
|
+
def bcf_gt_phased(idx)
|
105
|
+
((idx + 1) << 1 | 1)
|
106
|
+
end
|
107
|
+
|
108
|
+
def bcf_gt_unphased(idx)
|
109
|
+
((idx + 1) << 1)
|
110
|
+
end
|
111
|
+
|
112
|
+
def bcf_gt_missing
|
113
|
+
0
|
114
|
+
end
|
115
|
+
|
116
|
+
def bcf_gt_is_missing(val)
|
117
|
+
((val) >> 1 ? 0 : 1)
|
118
|
+
end
|
119
|
+
|
120
|
+
def bcf_gt_is_phased(idx)
|
121
|
+
((idx) & 1)
|
122
|
+
end
|
123
|
+
|
124
|
+
def bcf_gt_allele(val)
|
125
|
+
(((val) >> 1) - 1)
|
126
|
+
end
|
127
|
+
|
128
|
+
def bcf_alleles2gt(a, b)
|
129
|
+
((a) > (b) ? (a * (a + 1) / 2 + b) : (b * (b + 1) / 2 + a))
|
130
|
+
end
|
131
|
+
|
132
|
+
def bcf_get_info_int32(hdr, line, tag, dst, ndst)
|
133
|
+
bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_INT)
|
134
|
+
end
|
135
|
+
|
136
|
+
def bcf_get_info_float(hdr, line, tag, dst, ndst)
|
137
|
+
bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_REAL)
|
138
|
+
end
|
139
|
+
|
140
|
+
def bcf_get_info_string(hdr, line, tag, dst, ndst)
|
141
|
+
bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_STR)
|
142
|
+
end
|
143
|
+
|
144
|
+
def bcf_get_info_flag(hdr, line, tag, dst, ndst)
|
145
|
+
bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_FLAG)
|
146
|
+
end
|
147
|
+
|
148
|
+
def bcf_get_format_int32(hdr, line, tag, dst, ndst)
|
149
|
+
bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_INT)
|
150
|
+
end
|
151
|
+
|
152
|
+
def bcf_get_format_float(hdr, line, tag, dst, ndst)
|
153
|
+
bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_REAL)
|
154
|
+
end
|
155
|
+
|
156
|
+
def bcf_get_format_char(hdr, line, tag, dst, ndst)
|
157
|
+
bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_STR)
|
158
|
+
end
|
159
|
+
|
160
|
+
def bcf_get_genotypes(hdr, line, dst, ndst)
|
161
|
+
bcf_get_format_values(hdr, line, "GT", dst, ndst, BCF_HT_INT)
|
162
|
+
end
|
163
|
+
|
164
|
+
def bcf_hdr_int2id(hdr, type, int_id)
|
165
|
+
LibHTS::BcfIdpair.new(
|
166
|
+
hdr[:id][type].to_ptr +
|
167
|
+
LibHTS::BcfIdpair.size * int_id # offsets
|
168
|
+
)[:key]
|
169
|
+
end
|
170
|
+
|
171
|
+
def bcf_hdr_name2id(hdr, id)
|
172
|
+
bcf_hdr_id2int(hdr, BCF_DT_CTG, id)
|
173
|
+
end
|
174
|
+
|
175
|
+
def bcf_hdr_id2name(hdr, rid)
|
176
|
+
return nil if hdr.null? || rid < 0 || rid >= hdr[:n][LibHTS::BCF_DT_CTG]
|
177
|
+
|
178
|
+
LibHTS::BcfIdpair.new(
|
179
|
+
hdr[:id][LibHTS::BCF_DT_CTG].to_ptr +
|
180
|
+
LibHTS::BcfIdpair.size * rid # offset
|
181
|
+
)[:key]
|
182
|
+
end
|
183
|
+
|
184
|
+
def bcf_hdr_id2length(hdr, type, int_id)
|
185
|
+
LibHTS::BcfIdpair.new(
|
186
|
+
hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
|
187
|
+
LibHTS::BcfIdpair.size * int_id # offset
|
188
|
+
)[:val][:info][type] >> 8 & 0xf
|
189
|
+
end
|
190
|
+
|
191
|
+
def bcf_hdr_id2number(hdr, type, int_id)
|
192
|
+
LibHTS::BcfIdpair.new(
|
193
|
+
hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
|
194
|
+
LibHTS::BcfIdpair.size * int_id # offset
|
195
|
+
)[:val][:info][type] >> 12
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# constants
|
200
|
+
BCF_UN_STR = 1 # up to ALT inclusive
|
201
|
+
BCF_UN_FLT = 2 # up to FILTER
|
202
|
+
BCF_UN_INFO = 4 # up to INFO
|
203
|
+
BCF_UN_SHR = (BCF_UN_STR | BCF_UN_FLT | BCF_UN_INFO) # all shared information
|
204
|
+
BCF_UN_FMT = 8 # unpack format and each sample
|
205
|
+
BCF_UN_IND = BCF_UN_FMT # a synonym of BCF_UN_FMT
|
206
|
+
BCF_UN_ALL = (BCF_UN_SHR | BCF_UN_FMT) # everything
|
207
|
+
|
5
208
|
attach_function \
|
6
209
|
:bcf_hdr_init,
|
7
210
|
[:string],
|
@@ -14,7 +217,7 @@ module HTS
|
|
14
217
|
|
15
218
|
attach_function \
|
16
219
|
:bcf_init,
|
17
|
-
[
|
220
|
+
[],
|
18
221
|
Bcf1.by_ref
|
19
222
|
|
20
223
|
attach_function \
|
@@ -54,7 +257,7 @@ module HTS
|
|
54
257
|
|
55
258
|
attach_function \
|
56
259
|
:vcf_parse,
|
57
|
-
[
|
260
|
+
[KString, BcfHdr, Bcf1],
|
58
261
|
:int
|
59
262
|
|
60
263
|
attach_function \
|
@@ -64,7 +267,7 @@ module HTS
|
|
64
267
|
|
65
268
|
attach_function \
|
66
269
|
:vcf_format,
|
67
|
-
[BcfHdr, Bcf1,
|
270
|
+
[BcfHdr, Bcf1, KString],
|
68
271
|
:int
|
69
272
|
|
70
273
|
attach_function \
|
@@ -119,7 +322,7 @@ module HTS
|
|
119
322
|
|
120
323
|
attach_function \
|
121
324
|
:vcf_write_line,
|
122
|
-
[HtsFile,
|
325
|
+
[HtsFile, KString],
|
123
326
|
:int
|
124
327
|
|
125
328
|
attach_function \
|
@@ -144,7 +347,7 @@ module HTS
|
|
144
347
|
|
145
348
|
attach_function \
|
146
349
|
:bcf_hdr_format,
|
147
|
-
[BcfHdr, :int,
|
350
|
+
[BcfHdr, :int, KString],
|
148
351
|
:int
|
149
352
|
|
150
353
|
attach_function \
|
@@ -204,7 +407,7 @@ module HTS
|
|
204
407
|
|
205
408
|
attach_function \
|
206
409
|
:bcf_hrec_format,
|
207
|
-
[BcfHrec,
|
410
|
+
[BcfHrec, KString],
|
208
411
|
:int
|
209
412
|
|
210
413
|
attach_function \
|
@@ -369,27 +572,27 @@ module HTS
|
|
369
572
|
|
370
573
|
attach_function \
|
371
574
|
:bcf_fmt_array,
|
372
|
-
[
|
575
|
+
[KString, :int, :int, :pointer],
|
373
576
|
:int
|
374
577
|
|
375
578
|
attach_function \
|
376
579
|
:bcf_fmt_sized_array,
|
377
|
-
[
|
580
|
+
[KString, :pointer],
|
378
581
|
:uint8_t
|
379
582
|
|
380
583
|
attach_function \
|
381
584
|
:bcf_enc_vchar,
|
382
|
-
[
|
585
|
+
[KString, :int, :string],
|
383
586
|
:int
|
384
587
|
|
385
588
|
attach_function \
|
386
589
|
:bcf_enc_vint,
|
387
|
-
[
|
590
|
+
[KString, :int, :pointer, :int],
|
388
591
|
:int
|
389
592
|
|
390
593
|
attach_function \
|
391
594
|
:bcf_enc_vfloat,
|
392
|
-
[
|
595
|
+
[KString, :int, :pointer],
|
393
596
|
:int
|
394
597
|
|
395
598
|
attach_function \
|
data/lib/hts/libhts.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "ffi_ext/struct"
|
4
|
+
|
5
|
+
module HTS
|
6
|
+
module LibHTS
|
7
|
+
extend FFI::Library
|
8
|
+
|
9
|
+
begin
|
10
|
+
ffi_lib HTS.lib_path
|
11
|
+
rescue LoadError => e
|
12
|
+
raise LoadError, "#{e}\nCould not find #{HTS.lib_path}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.attach_function(*)
|
16
|
+
super
|
17
|
+
rescue FFI::NotFoundError => e
|
18
|
+
warn e.message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require_relative "libhts/constants"
|
24
|
+
|
25
|
+
# This is alphabetical order.
|
26
|
+
require_relative "libhts/bgzf"
|
27
|
+
require_relative "libhts/faidx"
|
28
|
+
require_relative "libhts/hfile"
|
29
|
+
require_relative "libhts/hts"
|
30
|
+
require_relative "libhts/sam"
|
31
|
+
require_relative "libhts/kfunc"
|
32
|
+
require_relative "libhts/tbx"
|
33
|
+
require_relative "libhts/vcf"
|
data/lib/hts/tabix.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Based on hts-python
|
4
|
+
# https://github.com/quinlan-lab/hts-python
|
5
|
+
|
6
|
+
module HTS
|
7
|
+
class Tabix
|
8
|
+
class << self
|
9
|
+
alias open new
|
10
|
+
end
|
11
|
+
def initialize
|
12
|
+
# IO like API
|
13
|
+
if block_given?
|
14
|
+
begin
|
15
|
+
yield self
|
16
|
+
ensure
|
17
|
+
close
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def build; end
|
23
|
+
|
24
|
+
def sequences; end
|
25
|
+
|
26
|
+
# def __call__\
|
27
|
+
end
|
28
|
+
end
|
data/lib/hts/version.rb
CHANGED
data/lib/htslib.rb
CHANGED
@@ -1,30 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "ffi"
|
4
4
|
|
5
|
-
require
|
5
|
+
require "hts/version"
|
6
6
|
|
7
7
|
module HTS
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
10
|
class << self
|
11
|
-
attr_accessor :
|
12
|
-
end
|
13
|
-
|
14
|
-
suffix = ::FFI::Platform::LIBSUFFIX
|
11
|
+
attr_accessor :lib_path
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
def search_htslib(name = nil)
|
14
|
+
name ||= "libhts.#{FFI::Platform::LIBSUFFIX}"
|
15
|
+
lib_path = if ENV["HTSLIBDIR"]
|
16
|
+
File.expand_path(name, ENV["HTSLIBDIR"])
|
18
17
|
else
|
19
|
-
File.expand_path("../vendor
|
18
|
+
File.expand_path("../vendor/#{name}", __dir__)
|
20
19
|
end
|
21
|
-
|
22
|
-
|
20
|
+
return lib_path if File.exist?(lib_path)
|
21
|
+
|
22
|
+
begin
|
23
|
+
require "pkg-config"
|
24
|
+
lib_dir = PKGConfig.variable("htslib", "libdir")
|
25
|
+
lib_path = File.expand_path(name, lib_dir)
|
26
|
+
rescue PackageConfig::NotFoundError
|
27
|
+
warn "htslib.pc was not found in the pkg-config search path."
|
28
|
+
end
|
29
|
+
return lib_path if File.exist?(lib_path)
|
30
|
+
|
31
|
+
warn "htslib shared library '#{name}' not found."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
self.lib_path = search_htslib
|
23
36
|
|
24
|
-
#
|
25
|
-
|
37
|
+
# You can change the path of the shared library with `HTS.lib_path=`
|
38
|
+
# before calling the LibHTS module.
|
39
|
+
autoload :LibHTS, "hts/libhts"
|
40
|
+
end
|
26
41
|
|
27
|
-
require_relative
|
28
|
-
require_relative
|
29
|
-
require_relative
|
30
|
-
require_relative
|
42
|
+
require_relative "hts/bam"
|
43
|
+
require_relative "hts/faidx"
|
44
|
+
require_relative "hts/tabix"
|
45
|
+
require_relative "hts/bcf"
|