Read and write BAM format.
The implementation does its best to comply with the official
specification.
module Biocaml_bam_alt:
sig
Biocaml.SAM
module.BAM header files contain a plain text SAM header, plus additional
information related to the encoding of the file.
module Header:
sig
end
typealignment =
Biocaml_sam.alignment
Representation of partially parsed alignments. When traversing a
BAM file for a specific calculation, it may be that only some
fields of the alignment records are actually used. In that case,
it can be significantly faster to use this representation. As a
downside, some encoding errors in the BAM file can go
unnoticed.
module Alignment0:
sig
type
t
val flags : t -> Biocaml_sam.Flags.t Core.Std.Or_error.t
val rname : t ->
Biocaml_bam_alt.Header.t -> string option Core.Std.Or_error.t
val cigar : t -> Biocaml_sam.cigar_op list Core.Std.Or_error.t
val rnext : t ->
Biocaml_bam_alt.Header.t -> Biocaml_sam.rnext option Core.Std.Or_error.t
val qual : t ->
Biocaml_phred_score.t list Core.Std.Or_error.t
val optional_fields : t ->
Biocaml_sam.optional_field list Core.Std.Or_error.t
val decode : t ->
Biocaml_bam_alt.Header.t -> Biocaml_bam_alt.alignment Core.Std.Or_error.t
val encode : Biocaml_bam_alt.alignment ->
Biocaml_bam_alt.Header.t -> t Core.Std.Or_error.t
end
val read0 : Pervasives.in_channel ->
(Header.t *
Alignment0.t Core.Std.Or_error.t Stream.t)
Core.Std.Or_error.t
read0 ic
returns an error if a valid header cannot be read from
ic
or a pair containing a header and a stream of possibly
errored (partially parsed) alignments. The stream stops after the first error.val with_file0 : string ->
f:(Header.t ->
Alignment0.t Core.Std.Or_error.t Stream.t ->
'a Core.Std.Or_error.t) ->
'a Core.Std.Or_error.t
with_file fn ~f
opens a BAM file for reading, applies f
and
closes the file after that, even if f
raises an exception. Beware: the result of f
should not lazily depend on the
stream it receives as a second argument, since after the call to
with_file
the underlying channel is closed.val write0 : Header.t ->
Alignment0.t Stream.t -> Pervasives.out_channel -> unit
write0 h xs oc
writes the header h
and (partially parsed)
alignments xs
to oc
.val read : Pervasives.in_channel ->
(Header.t *
alignment Core.Std.Or_error.t Stream.t)
Core.Std.Or_error.t
read ic
returns an error if a valid header cannot be read from
ic
or a pair containing a header and a stream of possibly
errored alignments. The stream stops after the first error.val with_file : string ->
f:(Header.t ->
alignment Core.Std.Or_error.t Stream.t ->
'a Core.Std.Or_error.t) ->
'a Core.Std.Or_error.t
with_file fn ~f
opens a BAM file for reading, applies f
and
closes the file after that, even if f
raises an exception. Beware: the result of f
should not lazily depend on the
stream it receives as a second argument, since after the call to
with_file
the underlying channel is closed.end