package molenc

  1. Overview
  2. Docs

Source file fpMol.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
(* Copyright (C) 2020, Francois Berenger

   Yamanishi laboratory,
   Department of Bioscience and Bioinformatics,
   Faculty of Computer Science and Systems Engineering,
   Kyushu Institute of Technology,
   680-4 Kawazu, Iizuka, Fukuoka, 820-8502, Japan. *)

(* A fingerprint-encoded molecule *)

module A = Array
module Fp = Fingerprint
module Ht = Hashtbl
module L = MyList
module LO = Line_oriented

open Printf

type t = { name: string;
           index: int; (* position in input file *)
           value: float;
           fp: Fp.t }

let create name index value bitstring =
  { name; index; value; fp = Fp.of_string bitstring }

(* read one molecule from an FP file *)
let read_one_mol line =
  try Scanf.sscanf line "%s@,%f,%s"
        (fun name value bitstring ->
           (name, value, bitstring)
        )
  with Scanf.Scan_failure msg ->
    failwith ("FpMol.read_one_mol: fmt: %s@,%f,%s err: " ^ msg ^
              " line: " ^ line)

let parse_one index line =
  let name, value, bitstring = read_one_mol line in
  create name index value bitstring

(* go back to the line format you came from *)
let to_string (m: t): string =
  sprintf "%s,%g,[%s]"
    m.name
    m.value
    (Fp.to_string m.fp)

let to_out out m =
  fprintf out "%s\n" (to_string m)

let molecules_of_file fn =
  LO.mapi fn parse_one

let dist m1 m2 =
  Fp.distance m1.fp m2.fp

let tani m1 m2 =
  Fp.tanimoto m1.fp m2.fp

let get_name x =
  x.name

let get_value x =
  x.value

let get_index x =
  x.index

let get_fp x =
  x.fp

let nb_features x =
  Fp.nb_features x.fp

let mol_is_active line =
  BatString.starts_with line "active"

let is_active x =
  mol_is_active x.name

let drop_features to_drop x =
  { x with fp = Fp.drop_features to_drop x.fp }
OCaml

Innovation. Community. Security.