text
stringlengths
12
786k
module Add ( X : Exp with type t = private [ > num | ' a add ] as ' a ) = struct type t = X . t add let show ( ` Add ( e1 , e2 ) : t ) = " ( " ^ X . show e1 " " ^+^ X . show e2 " ) " ^ let eval ( ` Add ( e1 , e2 ) : t ) = let e1 = X . eval e1 and...
type ' a mul = [ ` Mul of ' a * ' a ]
module Mul ( X : Exp with type t = private [ > num | ' a mul ] as ' a ) = struct type t = X . t mul let show ( ` Mul ( e1 , e2 ) : t ) = " ( " ^ X . show e1 " " ^*^ X . show e2 " ) " ^ let eval ( ` Mul ( e1 , e2 ) : t ) = let e1 = X . eval e1 and...
module Ext ( X : sig type t = private [ > ] end ) ( Y : sig type t end ) = struct module type S = sig type t = private [ > ] ~ [ X . t ] val eval : t -> Y . t val show : t -> string end end
module Dummy = struct type t = [ ` Dummy ] end
module Mix ( E : Exp ) ( E1 : Ext ( Dummy ) ( E ) . S ) ( E2 : Ext ( E1 ) ( E ) . S ) = struct type t = [ E1 . t | E2 . t ] let eval = function # E1 . t as x -> E1 . eval x | # E2 . t as x -> E2 . eval x let show = function # E1 . t as x -> E1 . show x ...
module rec EAdd : ( Exp with type t = [ num | EAdd . t add ] ) = Mix ( EAdd ) ( Num ( EAdd ) ) ( Add ( EAdd ) )
module rec E : Exp with type t = [ num | E . t add | E . t mul ] = Mix ( E ) ( Mix ( E ) ( Num ( E ) ) ( Add ( E ) ) ) ( Mul ( E ) )
let e = E . eval ( ` Add ( ` Mul ( ` Num 2 , ` Num 3 ) , ` Num 1 ) )
module rec E : ( Exp with type t = [ num | E . t add | E . t mul ] ) = struct module E1 = Num ( E ) module E2 = Add ( E ) module E3 = Mul ( E ) type t = E . t let show = function | # num as x -> E1 . show x | # add as x -> E2 . show x | # mul as x -> E3 . show x let ev...
module type T = sig type t = private [ > ] end
module type Tnum = sig type t = private [ > num ] end
module Ext ( E : Tnum ) = struct module type S = functor ( Y : Exp with type t = E . t ) -> sig type t = private [ > num ] val eval : t -> Y . t val show : t -> string end end
module Ext ' ( E : Tnum ) ( X : T ) = struct module type S = functor ( Y : Exp with type t = E . t ) -> sig type t = private [ > ] ~ [ X . t ] val eval : t -> Y . t val show : t -> string end end
module Mix ( E : Exp ) ( F1 : Ext ( E ) . S ) ( F2 : Ext ' ( E ) ( F1 ( E ) ) . S ) = struct module E1 = F1 ( E ) module E2 = F2 ( E ) type t = [ E1 . t | E2 . t ] let eval = function # E1 . t as x -> E1 . eval x | # E2 . t as x -> E2 . eval x let ...
module Join ( E : Exp ) ( F1 : Ext ( E ) . S ) ( F2 : Ext ' ( E ) ( F1 ( E ) ) . S ) ( E ' : Exp with type t = E . t ) = Mix ( E ) ( F1 ) ( F2 )
module rec EAdd : ( Exp with type t = [ num | EAdd . t add ] ) = Mix ( EAdd ) ( Num ) ( Add )
module rec EMul : ( Exp with type t = [ num | EMul . t mul ] ) = Mix ( EMul ) ( Num ) ( Mul )
module rec E : ( Exp with type t = [ num | E . t add | E . t mul ] ) = Mix ( E ) ( Join ( E ) ( Num ) ( Add ) ) ( Mul )
module LExt ( X : T ) = struct module type S = sig type t val eval : t -> X . t val show : t -> string end end
module LNum ( E : Exp ) ( X : LExt ( E ) . S with type t = private [ > ] ~ [ num ] ) = struct type t = [ num | X . t ] let show = function ` Num n -> string_of_int n | # X . t as x -> X . show x let eval = function # num as x -> x | # X . t as x -> X . eval x end
module LAdd ( E : Exp with type t = private [ > num | ' a add ] as ' a ) ( X : LExt ( E ) . S with type t = private [ > ] ~ [ add ] ) = struct type t = [ E . t add | X . t ] let show = function ` Add ( e1 , e2 ) -> " ( " ^ E . show e1 " " ^+^ E . ...
module LEnd = struct type t = [ ` Dummy ] let show ` Dummy = " " let eval ` Dummy = ` Dummy end
module rec L : Exp with type t = [ num | L . t add | ` Dummy ] = LAdd ( L ) ( LNum ( L ) ( LEnd ) )
module Num ( X : Exp ) = struct type t = num let map f x = x let eval1 ( ` Num _ as x ) : X . t = x let show ( ` Num n ) = string_of_int n end
module Add ( X : Exp with type t = private [ > num | ' a add ] as ' a ) = struct type t = X . t add let show ( ` Add ( e1 , e2 ) : t ) = " ( " ^ X . show e1 " " ^+^ X . show e2 " ) " ^ let map f ( ` Add ( e1 , e2 ) : t ) = ` Add ( f e1 , f e2 ...
module Mul ( X : Exp with type t = private [ > num | ' a mul ] as ' a ) = struct type t = X . t mul let show ( ` Mul ( e1 , e2 ) : t ) = " ( " ^ X . show e1 " " ^*^ X . show e2 " ) " ^ let map f ( ` Mul ( e1 , e2 ) : t ) = ` Mul ( f e1 , f e2 ...
module Ext ( X : sig type t = private [ > ] end ) ( Y : sig type t end ) = struct module type S = sig type t = private [ > ] ~ [ X . t ] val map : ( Y . t -> Y . t ) -> t -> t val eval1 : t -> Y . t val show : t -> string end end
module Mix ( E : Exp ) ( E1 : Ext ( Dummy ) ( E ) . S ) ( E2 : Ext ( E1 ) ( E ) . S ) = struct type t = [ E1 . t | E2 . t ] let map f = function # E1 . t as x -> ( E1 . map f x : E1 . t :> t ) | # E2 . t as x -> ( E2 . map f x : E2 . t :> t ) l...
module type ET = sig type t val map : ( t -> t ) -> t -> t val eval1 : t -> t val show : t -> string end
module Fin ( E : ET ) = struct include E let rec eval e = eval1 ( map eval e ) end
module rec EAdd : ( Exp with type t = [ num | EAdd . t add ] ) = Fin ( Mix ( EAdd ) ( Num ( EAdd ) ) ( Add ( EAdd ) ) )
module rec E : Exp with type t = [ num | E . t add | E . t mul ] = Fin ( Mix ( E ) ( Mix ( E ) ( Num ( E ) ) ( Add ( E ) ) ) ( Mul ( E ) ) )
let e = E . eval ( ` Add ( ` Mul ( ` Num 2 , ` Num 3 ) , ` Num 1 ) )
module type Wrap = sig type ' a t val ( <: ) : string -> ' a Value . Type . t -> ' a t include Value . Type . S end
module type Var = sig module type Wrap = Wrap type ' a t = { symbol : Symbol . t ; type_ : ' a Value . Type . t } [ @@ deriving fields , sexp_of ] type ' a var := ' a t val create : Symbol . t -> ' a Value . Type . t -> ' a t module Wrap : Wrap with type ' a t := ' a ...
module Alphabet = struct type t = { c1 : string ; c1_len : int ; cn : string ; cn_len : int } let create ~ c1 ~ cn = { c1 ; c1_len = String . length c1 ; cn ; cn_len = String . length cn } let javascript = create ~ c1 " : abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ " ...
type t = { names : ( int , string ) Hashtbl . t ; known : ( int , string ) Hashtbl . t ; cache : ( int * int , string ) Hashtbl . t ; alphabet : Alphabet . t ; mutable last : int ; mutable pretty : bool ; mutable stable : bool }
let name_raw t v nm = Hashtbl . add t . names v nm
let propagate_name t v v ' = try let name = Hashtbl . find t . names v in name_raw t v ' name with Not_found -> ( )
let name t v nm_orig = let len = String . length nm_orig in if len > 0 then ( let buf = Buffer . create ( String . length nm_orig ) in let idx = ref 0 in while ! idx < len && not ( Char . is_alpha nm_orig . [ ! idx ] ) do incr idx done ; let pending = ref false in if ! idx >= len...
let get_name t v = try Some ( Hashtbl . find t . names v ) with Not_found -> None
let format_var t i x = let s = Alphabet . to_string t . alphabet x in if t . stable then Format . sprintf " v % d " i else if t . pretty then Format . sprintf " _ % s_ " s else s
let reserved = ref StringSet . empty
let add_reserved s = reserved := List . fold_left s ~ init :! reserved ~ f ( : fun acc x -> StringSet . add x acc )
let _ = reserved := StringSet . union ! reserved Reserved . keyword
let get_reserved ( ) = ! reserved
let is_reserved s = StringSet . mem s ! reserved
let rec to_string t ? origin i = let origin = match origin with | Some i when t . pretty -> i | _ -> i in try Hashtbl . find t . cache ( i , origin ) with Not_found -> let name = try Hashtbl . find t . known i with Not_found -> t . last <- t . last + 1 ; let j = t . last in let s ...
let set_pretty t b = t . pretty <- b
let set_stable t b = t . stable <- b
let reset t = Hashtbl . clear t . names ; Hashtbl . clear t . known ; Hashtbl . clear t . cache ; t . last <- - 1
let create ( ? pretty = false ) ( ? stable = false ) alphabet = let t = { names = Hashtbl . create 107 ; known = Hashtbl . create 1001 ; cache = Hashtbl . create 1001 ; alphabet ; last = - 1 ; pretty ; stable } in t
module Tensor_id : sig include Hashable . Key val create : unit -> t include Int let create = let current = ref 0 in fun ( ) -> Int . incr current ; ! current end
type t = { name : string ; trainable_tensors : ( Tensor_id . t , Tensor . t ) Hashtbl . t ; all_tensors_by_name : ( string , Tensor . t ) Hashtbl . t ; subs : ( string , t ) Hashtbl . t ; device : Device . t ; mutable frozen : bool }
let create ( ? frozen = false ) ( ? device = Device . Cpu ) ~ name ( ) = { name ; trainable_tensors = Hashtbl . create ( module Tensor_id ) ; subs = Hashtbl . create ( module String ) ; all_tensors_by_name = Hashtbl . create ( module String ) ; device ; frozen }
let first_free_name name table = if Hashtbl . mem table name then ( let rec loop idx = let name = Printf . sprintf " % s_ % d " name idx in if Hashtbl . mem table name then loop ( idx + 1 ) else name in loop 1 ) else name
let sub t sub_name = if String . contains sub_name ' . ' then Printf . failwithf " sub names cannot contain . , % s " sub_name ( ) ; Hashtbl . find_or_add t . subs sub_name ~ default ( : fun ( ) -> { name = t . name ; trainable_tensors = Hashtbl . create ( module Tenso...
let subi t i = sub t ( Int . to_string i )
let ( / ) = sub
let ( // ) = subi
let rec freeze t = t . frozen <- true ; Hashtbl . iter t . trainable_tensors ~ f ( : fun tensor -> ignore ( Tensor . set_requires_grad tensor ~ r : false : Tensor . t ) ) ; Hashtbl . iter t . subs ~ f : freeze
let rec unfreeze t = t . frozen <- false ; Hashtbl . iter t . trainable_tensors ~ f ( : fun tensor -> ignore ( Tensor . set_requires_grad tensor ~ r : true : Tensor . t ) ) ; Hashtbl . iter t . subs ~ f : unfreeze
let rec num_trainable_vars t = let sub_vars = Hashtbl . data t . subs |> List . fold ~ init : 0 ~ f ( : fun acc t -> acc + num_trainable_vars t ) in sub_vars + Hashtbl . length t . trainable_tensors
let iter_trainable_vars t ~ f = let f ~ key ~ data = f key data in let rec loop t = Hashtbl . iter t . subs ~ f : loop ; Hashtbl . iteri t . trainable_tensors ~ f in loop t
let all_vars t = let rec walk t ~ path = let sub_vars = Hashtbl . to_alist t . subs |> List . concat_map ~ f ( : fun ( key , t ) -> walk t ~ path ( : key :: path ) ) in let vars = Hashtbl . to_alist t . all_tensors_by_name |> List . map ~ f ( : fun ( key , tensor ) -> L...
let copy ~ src ~ dst = Tensor . no_grad ( fun ( ) -> let rec walk ~ src ~ dst path = Hashtbl . iteri dst . all_tensors_by_name ~ f ( : fun ~ key ~ data -> match Hashtbl . find src . all_tensors_by_name key with | Some src -> Tensor . copy_ data ~ src | None -> Printf . failwithf "...
let name t = t . name
let device t = t . device
module Init = struct type t = | Zeros | Ones | Const of float | Normal of { mean : float ; stdev : float } | Uniform of float * float | Copy of Tensor . t end
let new_var ( ? trainable = true ) t ~ shape ~ init ~ name = let device = device t in let requires_grad = trainable && not t . frozen in let tensor = match ( init : Init . t ) with | Zeros -> Tensor . zeros shape ~ requires_grad ~ device | Ones -> Tensor . ones shape ~ requires_grad ~...
let new_var_copy ? trainable t ~ src ~ name = new_var ? trainable t ~ shape ( : Tensor . shape src ) ~ init ( : Copy src ) ~ name
module Configuration = struct type t = { name : string ; vaccine_peptide_length : int ; padding_around_mutation : int ; max_vaccine_peptides_per_mutation : int ; max_mutations_in_report : int ; min_mapping_quality : int ; min_variant_sequence_coverage : int ; min_alt_rna_reads : int ; includ...
type product = < host : Ketrew_pure . Host . t ; is_done : Ketrew_pure . Target . Condition . t option ; ascii_report_path : string option ; xlsx_report_path : string option ; pdf_report_path : string option ; debug_log_path : string ; output_folder_path : string ; >
let move_vaxrank_product ? host ~ output_folder_path ( vp : product ) : product = let open KEDSL in let open Option in let host = match host with | None -> vp # host | Some h -> h in let sub path = let base = String . chop_prefix_exn ~ prefix : vp # output_folder_path path in output_folder_path /...
let run ( ~ run_with : Machine . t ) ~ configuration ~ reference_build ~ vcfs ~ bam ~ predictor ~ alleles_file ~ output_folder = let open KEDSL in let open Hla_utilities in let host = Machine . ( as_host run_with ) in let vaxrank = Machine . get_tool run_with Machine . Tool . Default . v...
let ba0 = Bigarray . Array1 . create Bigarray . float32 Bigarray . c_layout 0 ; ;
let display ( vertexBuffer , colourBuffer ) = function ( ) -> glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; glTranslate 0 . 0 . ( - 5 . 0 ) ; glBindBuffer GL_ARRAY_BUFFER vertexBuffer ; glVertexPointer0 3 Coord . ...
let ini_gl ( ) = glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluPerspective 45 . 0 ( 640 . 0 . / 480 . 0 ) 1 . 0 512 . 0 ; glClearColor 0 . 0 0 . 0 0 . 0 1 . 0 ; let vertexData = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layou...
let keyboard ( vertexBuffer , colourBuffer ) = fun ~ key ~ x ~ y -> match key with | ' \ 027 ' -> glDisableClientState GL_VERTEX_ARRAY ; glDisableClientState GL_COLOR_ARRAY ; glDeleteBuffer vertexBuffer ; glDeleteBuffer colourBuffer ; exit ( 0 ) ; | _ -> ( ) ; ;
let ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DEPTH ; GLUT_DOUBLE ] ; glutInitWindowSize 640 480 ; ignore ( glutCreateWindow " VBO demo " ) ; let buffers = ini_gl ( ) in glutDisplayFunc ~ display ( : display buffers ) ; glutKeyboardFun...
let vertexData = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 0 . 0 ; 1 . 0 ; 0 . 0 ; - 1 . 0 ; - 1 . 0 ; 0 . 0 ; 1 . 0 ; - 1 . 0 ; 0 . 0 ; ] |
let colourData = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 0 . 0 ; 0 . 0 ; 1 . 0 ; 0 . 0 ; 1 . 0 ; 1 . 0 ; 1 . 0 ; 0 . 5 ; 0 . 0 ; ] |
let display ( vertexBuffer , colourBuffer ) = function ( ) -> glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; glTranslate 0 . 0 . ( - 5 . 0 ) ; glEnableClientState GL_VERTEX_ARRAY ; glEnableClientState GL_COLOR_ARRAY...
let ini_gl ( ) = glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluPerspective 45 . 0 ( 640 . 0 . / 480 . 0 ) 1 . 0 512 . 0 ; glClearColor 0 . 0 0 . 0 0 . 0 1 . 0 ; let vertexBuffer = glGenBuffer ( ) in glBindBuffer GL_ARRAY_BUFFER vertexBuffer ; glB...
let keyboard ( vertexBuffer , colourBuffer ) = fun ~ key ~ x ~ y -> match key with | ' \ 027 ' -> glDeleteBuffer vertexBuffer ; glDeleteBuffer colourBuffer ; exit ( 0 ) ; | _ -> ( ) ; ;
let ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DEPTH ; GLUT_DOUBLE ] ; glutInitWindowSize 640 480 ; ignore ( glutCreateWindow " VBO demo " ) ; let buffers = ini_gl ( ) in glutDisplayFunc ~ display ( : display buffers ) ; glutKeyboardFun...
let vertexData = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 0 . 0 ; 1 . 0 ; 0 . 0 ; - 1 . 0 ; - 1 . 0 ; 0 . 0 ; 1 . 0 ; - 1 . 0 ; 0 . 0 ; ] |
let colourData = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 0 . 0 ; 0 . 0 ; 1 . 0 ; 0 . 0 ; 1 . 0 ; 1 . 0 ; 1 . 0 ; 0 . 5 ; 0 . 0 ; ] |
let display ( vertexBuffer , colourBuffer ) = function ( ) -> glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; glTranslate 0 . 0 . ( - 5 . 0 ) ; glEnableClientState GL_VERTEX_ARRAY ; glEnableClientState GL_COLOR_ARRAY...
let ini_gl ( ) = glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluPerspective 45 . 0 ( 640 . 0 . / 480 . 0 ) 1 . 0 512 . 0 ; glClearColor 0 . 0 0 . 0 0 . 0 1 . 0 ; let vertexBuffer = glGenBuffer ( ) in glBindBuffer GL_ARRAY_BUFFER vertexBuffer ; glB...
let keyboard ( vertexBuffer , colourBuffer ) = fun ~ key ~ x ~ y -> match key with | ' \ 027 ' -> glDeleteBuffer vertexBuffer ; glDeleteBuffer colourBuffer ; exit ( 0 ) ; | _ -> ( ) ; ;
let ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DEPTH ; GLUT_DOUBLE ] ; glutInitWindowSize 640 480 ; ignore ( glutCreateWindow " VBO demo " ) ; let buffers = ini_gl ( ) in glutDisplayFunc ~ display ( : display buffers ) ; glutKeyboardFun...
module Make ( S : Comb . S ) = struct open S open Circuit open Cyclesim . Api type t = S . t let vcdmin = 33 let vcdmax = 126 let vcdcycle = 10 type trace = { w : int ; id : string ; name : string ; data : S . t ref ; prev : string ref ; } type cyclesim = t Cyclesim . Api . ...
module Gtkwave ( S : Comb . S ) = struct module Vcd = Make ( S ) type t = S . t type cyclesim = t Cyclesim . Api . cyclesim let wrap chan sim = let o s = output_string chan s ; flush chan in Vcd . wrap o sim let gtkwave ( ? args " " ) = sim = let fifoname = Filename . temp_file ...
module Safe = struct type error = [ ` invalid_int of string | ` invalid_float of string ] let int_of_string s = try Ok ( Int . of_string s ) s with _ -> Error ( ` invalid_int s ) s let float_of_string s = try Ok ( Float . of_string s ) s with _ -> Error ( ` invalid_float s ) s e...
let is_valid_dna = String . for_all ~ f ( : String . contains " ACGTN ) "
type vcf_number = | Number of int | OnePerAllele | OnePerGenotype | Unknown
type vcf_format_type = [ ` integer_value | ` float_value | ` character_value | ` string_value ]
type vcf_info_type = [ vcf_format_type | ` flag_value ]