Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
agarwal committed Jan 17, 2012
2 parents 352b508 + b500dd4 commit a571a8f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
1 change: 1 addition & 0 deletions _tags
Expand Up @@ -86,3 +86,4 @@
<src/app/*.ml{,i}>: pkg_getopt
<src/app/*.ml{,i}>: pkg_batteries
# OASIS_STOP
true: annot
49 changes: 35 additions & 14 deletions src/lib/biocaml_genomeMap.ml
Expand Up @@ -7,23 +7,18 @@ module Range = Biocaml_range
module Accu = Biocaml_accu

let rec iset_intersects_range i j s = ISet.(BatAvlTree.(
if i > j then raise (Invalid_argument "iset_intersects_range") ;
if is_empty s then false
else
let v1, v2 = root s in
if j < v1 then iset_intersects_range i j (left_branch s)
else if v2 < i then iset_intersects_range i j (right_branch s)
else true
))
if i > j then raise (Invalid_argument "iset_intersects_range") ;
if is_empty s then false
else
let v1, v2 = root s in
if j < v1 then iset_intersects_range i j (left_branch s)
else if v2 < i then iset_intersects_range i j (right_branch s)
else true
))

module Selection = struct
type 'a t = ('a, ISet.t) Map.t

let of_locations e =
let accu = Accu.create ISet.empty fst (fun (_,r) -> Range.(ISet.add_range r.lo r.hi)) in
Enum.iter (fun loc -> Accu.add accu loc loc ) e ;
Map.of_enum (Accu.enum accu)

let inter u v =
Map.foldi
(fun k set_u accu ->
Expand Down Expand Up @@ -63,6 +58,11 @@ module Selection = struct
let enum dom =
(Map.enum dom) /@ (fun (k,s) -> Enum.map (fun (lo,hi) -> k, Range.make lo hi) (ISet.enum s))
|> Enum.concat

let of_enum e =
let accu = Accu.create ISet.empty fst (fun (_,r) -> Range.(ISet.add_range r.lo r.hi)) in
Enum.iter (fun loc -> Accu.add accu loc loc ) e ;
Map.of_enum (Accu.enum accu)
end


Expand Down Expand Up @@ -93,7 +93,28 @@ module type LSet = sig
val add : 'a location -> 'a t -> 'a t
end

module type LMap = sig
module LMap = struct
module T = Biocaml_intervalTree

type ('a,'b) t = ('a, 'b T.t) Map.t

let intersects (k,r) dom =
try Range.(iset_intersects_range r.lo r.hi (Map.find k dom))
with Not_found -> false

let enum dom =
(Map.enum dom)
/@ (fun (k,t) -> Enum.map (fun (lo,hi,x) -> (k, Range.make lo hi), x) (T.enum t))
|> Enum.concat

let of_enum e =
let accu = Accu.create T.empty (fst |- fst) (fun ((_,r),v) -> Range.(T.add r.lo r.hi v)) in
Enum.iter (fun loc -> Accu.add accu loc loc ) e ;
Map.of_enum (Accu.enum accu)

end

module type LMap_spec = sig
type ('a,'b) t

val make : ('a location * 'b) Enum.t -> ('a,'b) t
Expand Down
18 changes: 14 additions & 4 deletions src/lib/biocaml_genomeMap.mli
Expand Up @@ -6,9 +6,6 @@ type 'a location = 'a * range
module Selection : sig
type 'a t

val of_locations : 'a location Enum.t -> 'a t
(** [of_locations e] computes a selection as the union of the locations contained in [e] *)

val inter : 'a t -> 'a t -> 'a t
val diff : 'a t -> 'a t -> 'a t
val size : 'a t -> int
Expand All @@ -17,6 +14,10 @@ module Selection : sig
val intersection_size : 'a location -> 'a t -> int

val enum : 'a t -> 'a location Enum.t

val of_enum : 'a location Enum.t -> 'a t
(** [of_enum e] computes a selection as the union of the locations contained in [e] *)

end

(** Partial function over the genome: each base may be associated to a value. *)
Expand Down Expand Up @@ -54,7 +55,16 @@ module type LSet = sig
end

(** A set of locations with an attached value on each of them *)
module type LMap = sig
module LMap : sig
type ('a,'b) t

val enum : ('a, 'b) t -> ('a location * 'b) Enum.t
val of_enum : ('a location * 'b) Enum.t -> ('a, 'b) t
end


(** A set of locations with an attached value on each of them *)
module type LMap_spec = sig
type ('a,'b) t

val make : ('a location * 'b) Enum.t -> ('a,'b) t
Expand Down

0 comments on commit a571a8f

Please sign in to comment.