Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Aug 26, 2017
1 parent 565f3ea commit 8b86679
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hts.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@


import hts/hts_concat
include hts/enums
import strutils
include hts/flag
include hts/cigar
Expand Down
13 changes: 13 additions & 0 deletions hts/bam.nim
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ proc open_hts*(path: cstring, threads: int=0, fai: cstring=nil, index: bool=fals

return bam

proc hts_set_opt*(fp: ptr htsFile; opt: FormatOption): cint {.varargs, cdecl,
importc: "hts_set_opt", dynlib: libname.}

proc set_fields*(b: Bam, fields: varargs[SamField]): int =
var opt : int = 0
for f in fields:
opt = opt or int(f)

var ret = int(hts_set_opt(b.hts, CRAM_OPT_REQUIRED_FIELDS, cint(opt)))
if ret != 0:
stderr.write_line("couldn't set opts")
return ret

iterator items*(bam: Bam): Record =
## items iterates over a bam. A single element is used and overwritten
## on each iteration so use `Record.copy` to retain.
Expand Down
2 changes: 2 additions & 0 deletions tests/htstest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ suite "flag hts-suite":
check b.hdr.targets[0].name == "1"
check b.hdr.targets[0].length == 249250621
check len(b.hdr.targets) == b.hdr.hdr.n_targets

check b.set_fields(SamField.SAM_POS, SamField.SAM_RNEXT) == 0

0 comments on commit 8b86679

Please sign in to comment.