-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod.ml
195 lines (119 loc) · 4.53 KB
/
mod.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
open! Core
(* wrt: with respect to *)
module rec Position : sig
type one_indexed
type zero_indexed
type aln
type raw
type ('indexing, 'wrt) t
type zero_indexed_aln = (zero_indexed, aln) t
type zero_indexed_raw = (zero_indexed, raw) t
type one_indexed_aln = (one_indexed, aln) t
type one_indexed_raw = (one_indexed, raw) t
module Map_wrt : sig
(* For mapping from one indexing to the other. *)
type ('indexing, 'from, 'to_) t
val empty_zero_raw_aln : unit -> (zero_indexed, raw, aln) t
val add_exn :
('indexing, 'from, 'to_) t
-> from:('indexing, 'from) Position.t
-> to_:('indexing, 'to_) Position.t
-> ('indexing, 'from, 'to_) t
val find_or_error :
('indexing, 'from, 'to_) t
-> ('indexing, 'from) Position.t
-> ('indexing, 'to_) Position.t Or_error.t
val length : ('indexing, 'from, 'to_) t -> int
end
module List : sig
type ('indexing, 'wrt) t
val to_list : ('indexing, 'wrt) t -> int list
val one_raw_of_list : int list -> (one_indexed, raw) t
val one_to_zero : (one_indexed, 'wrt) t -> (zero_indexed, 'wrt) t
val zero_raw_to_zero_aln :
(zero_indexed, raw, aln) Map_wrt.t
-> (* (int, int, Int.comparator_witness) Map.t -> *)
(zero_indexed, raw) t
-> (zero_indexed, aln) t Or_error.t
end
val ( + ) : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> ('indexing, 'wrt) t
val add : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> ('indexing, 'wrt) t
val to_int : ('indexing, 'wrt) t -> int
(* You can only compare positions that have the same indexing and wrt. *)
val compare : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> int
val equal : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> bool
val ( < ) : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> bool
val ( <= ) : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> bool
val ( > ) : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> bool
val ( >= ) : ('indexing, 'wrt) t -> ('indexing, 'wrt) t -> bool
val zero_raw_of_int : int -> (zero_indexed, raw) t
val one_raw_of_int : int -> (one_indexed, raw) t
val zero_aln_of_int : int -> (zero_indexed, aln) t
val one_aln_of_int : int -> (one_indexed, aln) t
val one_to_zero : (one_indexed, 'wrt) t -> (zero_indexed, 'wrt) t
val zero_raw_to_zero_aln :
(zero_indexed, raw, aln) Map_wrt.t
-> (* (int, int, Int.comparator_witness) Map.t -> *)
(zero_indexed, raw) t
-> (zero_indexed, aln) t Or_error.t
end = struct
type one_indexed
type zero_indexed
type aln
type raw
type ('indexing, 'wrt) t = int
type zero_indexed_aln = (zero_indexed, aln) t
type zero_indexed_raw = (zero_indexed, raw) t
type one_indexed_aln = (one_indexed, aln) t
type one_indexed_raw = (one_indexed, raw) t
module Map_wrt = struct
type ('indexing, 'from, 'to_) t =
(int, int, Int.comparator_witness) Core.Map.t
let empty_zero_raw_aln () = Core.Map.empty (module Int)
let add_exn map ~from ~to_ = Map.add_exn map ~key:from ~data:to_
let find_or_error map key = Map.find_or_error map key
let length map = Map.length map
end
module List = struct
type ('indexing, 'wrt) t = int list
let to_list x = x
let one_raw_of_list x = x
let one_to_zero positions = List.map positions ~f:Position.one_to_zero
let zero_raw_to_zero_aln pos_map positions =
Or_error.all
@@ List.map positions ~f:(Position.zero_raw_to_zero_aln pos_map)
end
let add x y = x + y
let ( + ) = add
let to_int x = x
let compare = Int.compare
let equal = Int.equal
let ( < ) = Int.( < )
let ( <= ) = Int.( <= )
let ( > ) = Int.( > )
let ( >= ) = Int.( >= )
let zero_raw_of_int x = x
let one_raw_of_int x = x
let zero_aln_of_int x = x
let one_aln_of_int x = x
let one_to_zero x = x - 1
let zero_raw_to_zero_aln pos_map x = Map.find_or_error pos_map x
end
and Record : sig
type 'position t
val aln_of_fasta_record : Bio_io.Fasta.Record.t -> Position.aln t
val raw_of_fasta_record : Bio_io.Fasta.Record.t -> Position.raw t
val to_fasta_record : 'positions t -> Bio_io.Fasta.Record.t
val get_aln_residues :
(Position.zero_indexed, Position.aln) Position.List.t
-> Position.aln t
-> string list
end = struct
type 'position t = Bio_io.Fasta.Record.t
let aln_of_fasta_record x = x
let raw_of_fasta_record x = x
let to_fasta_record x = x
let get_aln_residues positions record =
let seq = Bio_io.Fasta.Record.seq record in
List.map positions ~f:(fun aln_i -> String.of_char @@ String.get seq aln_i)
end