Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 49 additions and 33 deletions.
  1. +1 −1 src/ext/xmlm-1.0.2/src/xmlm.ml
  2. +19 −18 src/lib/biocaml_mzData.ml
  3. +4 −6 src/lib/biocaml_mzData.mli
  4. +25 −8 src/lib/biocaml_mzData_stubs.c
View
2 src/ext/xmlm-1.0.2/src/xmlm.ml
@@ -1152,7 +1152,7 @@ module Buffer = struct
else if u <= 0xFFFF then
(buf (0xE0 lor (u lsr 12));
buf (0x80 lor ((u lsr 6) land 0x3F));
- buf (0x80 lor (u land 0x3F)))
+ buf (0x80 lor (u land 0x3F)))
else
(buf (0xF0 lor (u lsr 18));
buf (0x80 lor ((u lsr 12) land 0x3F));
View
37 src/lib/biocaml_mzData.ml
@@ -29,25 +29,33 @@ module Base64 = struct
external init : unit -> unit = "biocaml_base64_init"
let () = init ()
- external decode32 :
+ external little32 :
string -> npeaks:int -> (float, float64_elt, _) Array1.t -> unit
- = "biocaml_base64_decode32"
+ = "biocaml_base64_little32"
- external decode64 :
+ external big32 :
string -> npeaks:int -> (float, float64_elt, _) Array1.t -> unit
- = "biocaml_base64_decode64"
+ = "biocaml_base64_big32"
- let decode ~precision s =
+ external little64 :
+ string -> npeaks:int -> (float, float64_elt, _) Array1.t -> unit
+ = "biocaml_base64_little64"
+
+ external big64 :
+ string -> npeaks:int -> (float, float64_elt, _) Array1.t -> unit
+ = "biocaml_base64_big64"
+
+ let decode ~precision ~little_endian s =
if precision = 32 then
(* One 32 bits (thus 4 bytes) floats per peak *)
let npeaks = (String.length s / 4) * 3 / 4 in
let v = Array1.create float64 fortran_layout npeaks in
- decode32 s ~npeaks v;
+ if little_endian then little32 s ~npeaks v else big32 s ~npeaks v;
v
else if precision = 64 then
let npeaks = (String.length s / 4) * 3 / 8 in
let v = Array1.create float64 fortran_layout npeaks in
- decode64 s ~npeaks v;
+ if little_endian then little64 s ~npeaks v else big64 s ~npeaks v;
v
else invalid_arg "Biocaml_mzData: <peak> precision must be 32 or 64"
end
@@ -152,8 +160,6 @@ type spectrum = {
id: int;
mslevel: int;
precursor: Precursor.t list;
- start_mz: float;
- end_mz: float;
mz: vec;
int: vec;
sup: (string * vec) list;
@@ -163,13 +169,11 @@ type spectrum = {
let rec vec_of_binary_data xml =
match Xmlm.input xml with
| `El_start((_, "data"), atts) ->
- (* FIXME: both byte order are accepted *)
- if attribute_exn "endian" atts <> "little" then
- failwith "Biocaml_mzData: byte order must be little endian";
let precision = int_of_string(attribute_exn "precision" atts) in
let length = int_of_string(attribute_exn "length" atts) in
+ let little_endian = attribute_exn "endian" atts = "little" in
let data = get_next_data xml in
- let v = Base64.decode ~precision data in
+ let v = Base64.decode ~precision ~little_endian data in
if Array1.dim v <> length then
failwith(sprintf "Biocaml_mzData: Invalid XML: <data> expected \
length: %i, got: %i" length (Array1.dim v));
@@ -181,10 +185,8 @@ let rec vec_of_binary_data xml =
let rec get_spectrum xml spec depth =
match Xmlm.input xml with
| `El_start((_, "spectrumInstrument"), atts) ->
- let mslevel = int_of_string(attribute_exn "msLevel" atts)
- and start_mz = float_of_string(attribute_exn "mzRangeStart" atts)
- and end_mz = float_of_string(attribute_exn "mzRangeStop" atts) in
- let spec = { spec with mslevel; start_mz; end_mz } in
+ let mslevel = int_of_string(attribute_exn "msLevel" atts) in
+ let spec = { spec with mslevel } in
get_spectrum xml spec (depth + 1)
| `El_start((_, "precursorList"), _) ->
let spec = { spec with precursor = Precursor.list xml } in
@@ -215,7 +217,6 @@ let spectrums fname =
let id = int_of_string(attribute_exn "id" atts) in
(* retentionTime ? *)
let scan = { id; mslevel = 0; precursor = [];
- start_mz = nan; end_mz = nan;
mz = empty_vec; int = empty_vec; sup = [] } in
let scan = get_spectrum xml scan 0 in
scans := scan :: !scans
View
10 src/lib/biocaml_mzData.mli
@@ -20,25 +20,23 @@ module Precursor : sig
}
val mass : t -> float
- (** [mass p] return the mass of the precursor [p] WITHOUT charge. *)
+ (** [mass p] return the mass of the precursor [p] {i without} charge. *)
end
-(** MS spectrum. *)
+(** Individual mass spectrum. *)
type spectrum = {
id: int; (** index of the spectrum in the file (starting with 1). *)
mslevel: int; (** 1: MS, 2: MS/MS,... *)
precursor: Precursor.t list; (** List of precursors to the spectrum
currently being described. *)
- start_mz: float;
- end_mz: float;
mz: vec; (** m/z *)
int: vec; (** intensities *)
sup: (string * vec) list; (** Supplemental (name, arrays), if any *)
}
val spectrums : string -> spectrum list
-(** [spectrums fname] returns the spectrums contained in the file
- [fname]. *)
+(** [spectrums fname] returns the spectra contained in the file
+ [fname]. *)
;;
View
33 src/lib/biocaml_mzData_stubs.c
@@ -235,9 +235,7 @@ value biocaml_base64_init(value vunit)
} \
}
-#define TO_HOST_LITTLE_ENDIAN(data) /* void; host order is little-endian */
-
-#define DECODE(ty, lenbuf, to_host_big_endian) \
+#define DECODE(ty, lenbuf, to_host_little_endian, to_host_big_endian) \
const char *peaks = String_val(vpeaks); \
int i, npeaks = Int_val(vnpeaks); \
unsigned int index; \
@@ -246,12 +244,14 @@ value biocaml_base64_init(value vunit)
double *vec = (double *) Data_bigarray_val(vvec); \
\
if (is_little_endian) { \
- DECODE_BODY(ty, lenbuf, INDEX_LITTLE_ENDIAN, TO_HOST_LITTLE_ENDIAN); \
+ DECODE_BODY(ty, lenbuf, INDEX_LITTLE_ENDIAN, to_host_little_endian); \
} \
else { \
DECODE_BODY(ty, lenbuf, INDEX_BIG_ENDIAN, to_host_big_endian); \
}
+#define TO_HOST_IDENTITY(data) /* Do nothing */
+
static void swap_bytes32(unsigned char *b)
{
/* From little-endian to big endian (for 1 float). */
@@ -261,11 +261,20 @@ static void swap_bytes32(unsigned char *b)
c = b[1]; b[1] = b[2]; b[2] = c;
}
-CAMLexport value biocaml_base64_decode32(value vpeaks, value vnpeaks,
+/* Decode data stored in little endian */
+CAMLexport value biocaml_base64_little32(value vpeaks, value vnpeaks,
value vvec)
{
CAMLparam2(vpeaks, vvec);
- DECODE(float, 12, swap_bytes32);
+ DECODE(float, 12, TO_HOST_IDENTITY, swap_bytes32);
+ CAMLreturn(Val_unit);
+}
+
+CAMLexport value biocaml_base64_big32(value vpeaks, value vnpeaks,
+ value vvec)
+{
+ CAMLparam2(vpeaks, vvec);
+ DECODE(float, 12, swap_bytes32, TO_HOST_IDENTITY);
CAMLreturn(Val_unit);
}
@@ -279,11 +288,19 @@ static void swap_bytes64(unsigned char *b)
c = b[3]; b[3] = b[4]; b[4] = c; /* bytes 3, 4 */
}
-CAMLexport value biocaml_base64_decode64(value vpeaks, value vnpeaks,
+CAMLexport value biocaml_base64_little64(value vpeaks, value vnpeaks,
value vvec)
{
CAMLparam2(vpeaks, vvec);
- DECODE(double, 24, swap_bytes64);
+ DECODE(double, 24, TO_HOST_IDENTITY, swap_bytes64);
+ CAMLreturn(Val_unit);
+}
+
+CAMLexport value biocaml_base64_big64(value vpeaks, value vnpeaks,
+ value vvec)
+{
+ CAMLparam2(vpeaks, vvec);
+ DECODE(double, 24, swap_bytes64, TO_HOST_IDENTITY);
CAMLreturn(Val_unit);
}

No commit comments for this range

Something went wrong with that request. Please try again.