text
stringlengths 0
601k
|
---|
let rec map ( f : ? prefix : string -> ? is_last : bool -> _ -> _ ) xs = match xs with | [ ] -> [ ] | [ x ] -> [ f ~ is_last : true x ] | x :: xs -> f ~ is_last : false x :: map f xs
|
let string_of_prec_value ( x : prec_value ) = match x with | Num_prec n -> string_of_int n | Named_prec name -> str name
|
let pp_value ~ is_last ( s : string ) = [ Line ( s |> comma is_last ) ]
|
let pp_prec_value ~ is_last x = let s = string_of_prec_value x in pp_value ~ is_last s
|
let rec pp_body ( ? prefix = " " ) ( ? is_last = true ) body = let cons , args = match body with | SYMBOL s -> rule s , None | STRING s -> str s , None | PATTERN s -> pattern s , None | BLANK -> " " " \\ /* blank " , */ None | REPEAT x -> " repeat " , Some ( pp_body x ) | REPEAT1 x -> " repeat1 " , Some ( pp_body x ) | CHOICE [ x ; BLANK ] -> " optional " , Some ( pp_body x ) | CHOICE xs -> " choice " , Some ( map pp_body xs |> flatten ) | SEQ xs -> " seq " , Some ( map pp_body xs |> flatten ) | PREC ( prec_value , x ) -> " prec " , Some [ Inline ( pp_prec_value ~ is_last : false prec_value ) ; Inline ( pp_body ~ is_last : true x ) ; ] | PREC_DYNAMIC ( n , x ) -> " prec . dynamic " , Some [ Inline ( pp_value ~ is_last : false ( string_of_int n ) ) ; Inline ( pp_body ~ is_last : true x ) ] | PREC_LEFT ( opt_prec_value , x ) -> " prec . left " , Some ( pp_opt_prec opt_prec_value x ) | PREC_RIGHT ( opt_prec_value , x ) -> " prec . right " , Some ( pp_opt_prec opt_prec_value x ) | ALIAS x -> " alias " , Some ( pp_alias x ) | FIELD ( name , x ) -> " field " , Some ( pp_field name x ) | IMMEDIATE_TOKEN x -> " token . immediate " , Some ( pp_body x ) | TOKEN x -> " token " , Some ( pp_body x ) in match args with | None -> [ Line ( sprintf " % s % s " prefix ( cons |> comma is_last ) ) ] | Some args -> [ Line ( sprintf " % s % s ( " prefix cons ) ; Block args ; Line ( " ) " |> comma is_last ) ] let body = pp_body ~ is_last : true x in match opt_prec_value with | None -> body | Some prec_value -> [ Inline ( pp_prec_value ~ is_last : false prec_value ) ; Inline body ; ] let new_name = match x . named with | true -> rule x . value | false -> str x . value in [ Inline ( pp_body ~ is_last : false x . content ) ; Line new_name ; ] [ Line ( str name ^ " , " ) ; Inline ( pp_body ~ is_last : true x ) ; ]
|
let pp_rule ? prefix : _ ? is_last ( name , body ) = pp_body ~ prefix ( : sprintf " % s : $ => " name ) ? is_last body
|
let pp_word ( x : ident option ) = match x with | None -> [ ] | Some s -> [ Line ( sprintf " word : $ => % s , " ( rule s ) ) ]
|
let string_of_named_prec_level x = match x with | Prec_symbol name -> rule name | Prec_string s -> str s
|
let pp_precedence_level ? prefix : _ ( ? is_last = true ) level = let level = level |> List . map string_of_named_prec_level |> String . concat " , " in [ Line ( sprintf " [ % s ] " level |> comma is_last ) ]
|
let pp_grammar ( x : grammar ) : Indent . t = [ Line " // JavaScript grammar recovered from JSON by ' ocaml - tree - sitter to - js ' " ; Line " module . exports = grammar ( { " ; Block [ Line ( sprintf " name : % s , " ( str x . name ) ) ; Inline ( pp_word x . word ) ; Line " externals : $ => [ " ; Block ( map pp_body x . externals |> flatten ) ; Line " ] , " ; Line " conflicts : $ => [ " ; Block ( map pp_conflict x . conflicts |> flatten ) ; Line " ] , " ; Line " inline : $ => [ " ; Block ( map ( fun ? prefix : _ ( ? is_last = true ) name -> Line ( rule name |> comma is_last ) ) x . inline ) ; Line " ] , " ; Line " precedences : $ => [ " ; Block ( map pp_precedence_level x . precedences |> flatten ) ; Line " ] , " ; Line " supertypes : $ => [ " ; Block ( map ( fun ? prefix : _ ( ? is_last = true ) name -> Line ( rule name |> comma is_last ) ) x . supertypes ) ; Line " ] , " ; Line " extras : $ => [ " ; Block ( map pp_body x . extras |> flatten ) ; Line " ] , " ; Line " rules : { " ; Block ( map pp_rule x . rules |> flatten ) ; Line " } " ; ] ; Line " } ) ; " ; ]
|
let run input_path output_path = let grammar = match input_path with | None -> Atdgen_runtime . Util . Json . from_channel Tree_sitter_j . read_grammar stdin | Some file -> Atdgen_runtime . Util . Json . from_file Tree_sitter_j . read_grammar file in let tree = pp_grammar grammar in match output_path with | None -> Indent . to_channel stdout tree | Some file -> Indent . to_file file tree
|
type ' a repr = var_count : int -> json
|
type ' a observation = json
|
let lambda f = fun ~ var_count -> let var_name = sprintf " var % d " var_count in let var_repr = fun ~ var_count -> ` String var_name in let applied = f var_repr ~ var_count ( : var_count + 1 ) in ` Assoc [ " lambda " , ` String var_name ; " body " , applied ; ]
|
let apply f v = fun ~ var_count -> let func = f ~ var_count in let arg = v ~ var_count in ` Assoc [ " function " , func ; " argument " , arg ; ]
|
let observe f = f ( ) ~ var_count : 0
|
let to_unit j = j
|
let list l = fun ~ var_count -> ` List ( List . map ~ f ( : fun a -> a ~ var_count ) l )
|
let list_map l ~ f = fun ~ var_count -> ` Assoc [ " list - map " , f ~ var_count ; " argument " , l ~ var_count ; ]
|
module Make_serializer ( How : sig type t val input_value : string -> ( string * string ) list -> var_count : int -> t val function_call : string -> ( string * t ) list -> t val string : string -> t end ) = struct open How let input_url u = input_value " Input " [ " URL " , u ; ] let save ~ name thing = fun ~ var_count -> function_call name ( [ " save - as " , string name ; " element " , thing ~ var_count ] ) let fastq_or_gz name ~ sample_name ? fragment_id ~ r1 ? r2 ( ) = fun ~ var_count -> function_call name ( [ " sample_name " , string sample_name ; " fragment_id " , string ( Option . value ~ default " : NONE " fragment_id ) ; " R1 " , r1 ~ var_count ; ] @ Option . value_map ~ default [ ] : ~ f ( : fun r2 -> [ " R2 " , r2 ~ var_count ] ) r2 ) let fastq ~ sample_name ? fragment_id ~ r1 ? r2 ( ) = fastq_or_gz " fastq " ~ sample_name ? fragment_id ~ r1 ? r2 ( ) let fastq_gz ~ sample_name ? fragment_id ~ r1 ? r2 ( ) = fastq_or_gz " fastq - gz " ~ sample_name ? fragment_id ~ r1 ? r2 ( ) let bam ~ sample_name ? sorting ~ reference_build input = fun ~ var_count -> function_call " bam " [ " sample_name " , string sample_name ; " sorting " , string ( Option . value_map ~ default " : NONE " sorting ~ f ( : function ` Coordinate -> " Coordinate " | ` Read_name -> " Read - name " ) ) ; " reference_build " , string reference_build ; " file " , input ~ var_count ; ] let bed file = fun ~ var_count -> function_call " bed " [ " path " , file ~ var_count ] let mhc_alleles = function | ` Names sl -> input_value " mhc_alleles " [ " inline " , ( String . concat " , " sl ) ] | ` File p -> fun ~ var_count -> function_call " mhc_alleles " [ " file " , p ~ var_count ; ] let pair a b ( ~ var_count : int ) = function_call " make - pair " [ " first " , a ~ var_count ; " second " , b ~ var_count ; ] let pair_first p ( ~ var_count : int ) = function_call " pair - first " [ " pair " , p ~ var_count ; ] let pair_second p ( ~ var_count : int ) = function_call " pair - second " [ " pair " , p ~ var_count ; ] let aligner name conf_name ~ reference_build fq : var_count : int -> How . t = fun ~ var_count -> let fq_compiled = fq ~ var_count in function_call name [ " configuration " , string conf_name ; " reference_build " , string reference_build ; " input " , fq_compiled ; ] let one_to_one name conf_name input_file = fun ( ~ var_count : int ) -> let input_file_compiled = input_file ~ var_count in function_call name [ " configuration " , string conf_name ; " input " , input_file_compiled ; ] let bwa_aln ( ? configuration = Tools . Bwa . Configuration . Aln . default ) = aligner " bwa - aln " ( Tools . Bwa . Configuration . Aln . name configuration ) let bwa_mem ( ? configuration = Tools . Bwa . Configuration . Mem . default ) = aligner " bwa - mem " ( Tools . Bwa . Configuration . Mem . name configuration ) let bwa_mem_opt ( ? configuration = Tools . Bwa . Configuration . Mem . default ) ~ reference_build input = match input with | ` Fastq f -> aligner " bwa - mem - opt - fq " ( Tools . Bwa . Configuration . Mem . name configuration ) ~ reference_build f | ` Fastq_gz f -> aligner " bwa - mem - opt - fqz " ( Tools . Bwa . Configuration . Mem . name configuration ) ~ reference_build f | ` Bam ( f , _ ) -> aligner " bwa - mem - opt - bam " ( Tools . Bwa . Configuration . Mem . name configuration ) ~ reference_build f let gunzip gz ( ~ var_count : int ) = function_call " gunzip " [ " input " , gz ~ var_count ] let gunzip_concat gzl ( ~ var_count : int ) = function_call " gunzip - concat " [ " input - list " , gzl ~ var_count ] let concat l ( ~ var_count : int ) = function_call " concat " [ " input - list " , l ~ var_count ] let merge_bams ? delete_input_on_success ? attach_rg_tag ? uncompressed_bam_output ? compress_level_one ? combine_rg_headers ? combine_pg_headers bl ( ~ var_count : int ) = function_call " merge - bams " [ " input - list " , bl ~ var_count ] let star ( ? configuration = Tools . Star . Configuration . Align . default ) = aligner " star " ( Tools . Star . Configuration . Align . name configuration ) let hisat ( ? configuration = Tools . Hisat . Configuration . default_v1 ) = aligner " hisat " ( configuration . Tools . Hisat . Configuration . name ) let mosaik = aligner " mosaik " " default " let stringtie ( ? configuration = Tools . Stringtie . Configuration . default ) = one_to_one " stringtie " configuration . Tools . Stringtie . Configuration . name let bam_left_align ~ reference_build = one_to_one " bam_left_align " reference_build let sambamba_filter ~ filter = one_to_one " filter " ( Tools . Sambamba . Filter . to_string filter ) let indel_real_config ( indel , target ) = ( sprintf " I % s - TC % s " indel . Tools . Gatk . Configuration . Indel_realigner . name target . Tools . Gatk . Configuration . Realigner_target_creator . name ) let gatk_indel_realigner ( ? configuration = Tools . Gatk . Configuration . default_indel_realigner ) = one_to_one " gatk_indel_realigner " ( indel_real_config configuration ) let gatk_indel_realigner_joint ( ? configuration = Tools . Gatk . Configuration . default_indel_realigner ) = one_to_one " gatk_indel_realigner_joint " ( indel_real_config configuration ) let picard_mark_duplicates ( ? configuration = Tools . Picard . Mark_duplicates_settings . default ) = one_to_one " picard_mark_duplicates " configuration . Tools . Picard . Mark_duplicates_settings . name let picard_reorder_sam ? mem_param ? reference_build = one_to_one " picard_reorder_sam " ( sprintf " ref -% s " ( match reference_build with None -> " inputs " | Some r -> r ) ) let picard_clean_bam = one_to_one " picard_clean_bam " " default " let gatk_bqsr ( ? configuration = Tools . Gatk . Configuration . default_bqsr ) = let ( bqsr , preads ) = configuration in one_to_one " gatk_bqsr " ( sprintf " B % s - PR % s " bqsr . Tools . Gatk . Configuration . Bqsr . name preads . Tools . Gatk . Configuration . Print_reads . name ) let seq2hla = one_to_one " seq2hla " " default " let hlarp input = let name , v = match input with | ` Seq2hla f -> " hlarp - seq2hla " , f | ` Optitype f -> " hlarp - optitype " , f in one_to_one name " hlarp " v let filter_to_region vcf bed = fun ( ~ var_count : int ) -> function_call " filter_to_region " [ " bed " , bed ~ var_count ; " vcf " , vcf ~ var_count ] let index_bam = one_to_one " index_bam " " default " let kallisto ~ reference_build ? bootstrap_samples = let samples = match bootstrap_samples with | None -> " default " | Some s -> sprintf " % d " s in one_to_one " kallisto " ( sprintf " % s - samples :% s " reference_build samples ) let cufflinks ? reference_build = let build = match reference_build with | None -> " bam ' s build " | Some s -> s in one_to_one " cufflinks " ( sprintf " build :% s " build ) let fastqc = one_to_one " fastqc " " default " let flagstat = one_to_one " flagstat " " default " let vcf_annotate_polyphen = one_to_one " vcf_annotate_polyphen " " default " let snpeff = one_to_one " snpeff " " default " let isovar ( ? configuration = Tools . Isovar . Configuration . default ) vcf bam = fun ( ~ var_count : int ) -> let vcf_compiled = vcf ~ var_count in let bam_compiled = bam ~ var_count in function_call " isovar " [ " configuration " , string Tools . Isovar . Configuration . ( name configuration ) ; " vcf " , vcf_compiled ; " bam " , bam_compiled ; ] let topiary ( ? configuration = Tools . Topiary . Configuration . default ) vcfs predictor alleles = fun ( ~ var_count : int ) -> let vcfs_compiled = List . map vcfs ~ f ( : fun v -> v ~ var_count ) in function_call " topiary " ( [ " configuration " , string Tools . Topiary . Configuration . ( name configuration ) ; " alleles " , alleles ~ var_count ; " predictor " , string Hla_utils . ( predictor_to_string predictor ) ; ] @ ( List . mapi ~ f ( : fun i v -> ( sprintf " vcf % d " i , v ) ) vcfs_compiled ) ) let vaxrank ( ? configuration = Tools . Vaxrank . Configuration . default ) vcfs bam predictor alleles = fun ( ~ var_count : int ) -> let vcfs_compiled = List . map vcfs ~ f ( : fun v -> v ~ var_count ) in let bam_compiled = bam ~ var_count in function_call " vaxrank " ( [ " configuration " , string Tools . Vaxrank . Configuration . ( name configuration ) ; " alleles " , alleles ~ var_count ; " predictor " , string Hla_utils . ( predictor_to_string predictor ) ; " bam " , bam_compiled ; ] @ ( List . mapi ~ f ( : fun i v -> ( sprintf " vcf % d " i , v ) ) vcfs_compiled ) ) let optitype how = one_to_one " optitype " ( match how with ` DNA -> " DNA " | ` RNA -> " RNA " ) let gatk_haplotype_caller = one_to_one " gatk_haplotype_caller " " default " let bam_to_fastq ? fragment_id se_or_pe bam = fun ( ~ var_count : int ) -> let bamc = bam ~ var_count in function_call " bam_to_fastq " [ " fragment_id " , Option . value_map ~ f : string ~ default ( : string " N / A " ) fragment_id ; " endness " , string ( match se_or_pe with | ` SE -> " SE " | ` PE -> " PE " ) ; " input " , bamc ; ] let variant_caller name conf_name ~ normal ~ tumor ( ) ( ~ var_count : int ) = function_call name [ " configuration " , string conf_name ; " normal " , normal ~ var_count ; " tumor " , tumor ~ var_count ; ] let mutect ( ? configuration = Tools . Mutect . Configuration . default ) = variant_caller " mutect " configuration . Tools . Mutect . Configuration . name let mutect2 ( ? configuration = Tools . Gatk . Configuration . Mutect2 . default ) = variant_caller " mutect2 " configuration . Tools . Gatk . Configuration . Mutect2 . name let delly2 ( ? configuration = Tools . Delly2 . Configuration . default ) = variant_caller " delly2 " configuration . Tools . Delly2 . Configuration . name let somaticsniper ( ? configuration = Tools . Somaticsniper . Configuration . default ) = variant_caller " somaticsniper " configuration . Tools . Somaticsniper . Configuration . name let strelka ( ? configuration = Tools . Strelka . Configuration . default ) = variant_caller " strelka " configuration . Tools . Strelka . Configuration . name let varscan_somatic ? adjust_mapq = variant_caller " varscan_somatic " ( Option . value_map ~ f ( : sprintf " amap % d " ) ~ default " : default " adjust_mapq ) let muse ( ? configuration = Tools . Muse . Configuration . default ` WGS ) = variant_caller " muse " configuration . Tools . Muse . Configuration . name let virmid ( ? configuration = Tools . Virmid . Configuration . default ) = variant_caller " virmid " configuration . Tools . Virmid . Configuration . name let seqtk_shift_phred_scores = one_to_one " seqtk_shift_phred_scores " " default " end type t = json let input_value name kv = fun ~ var_count -> ` Assoc ( ( " input - value " , ` String name ) :: List . map kv ~ f ( : fun ( k , v ) -> k , ` String v ) ) let function_call name params = ` Assoc ( ( " function - call " , ` String name ) :: params ) let string s = ` String s end )
|
module Rf = struct let tag ? loc : _ ( ? attrs = [ ] ) a b c = Parsetree . Rtag ( a , attrs , b , c ) end
|
let rec of_type_desc ? loc typ = match typ with | Ptyp_var None -> Typ . any ? loc ( ) | Ptyp_var ( Some name ) -> Typ . var ? loc name . txt | Ptyp_poly ( _ , typ ) -> of_type_expr typ | Ptyp_arrow ( typ1 , typ2 , _ , label ) -> Typ . arrow ? loc label ( of_type_expr typ1 ) ( of_type_expr typ2 ) | Ptyp_ctor { var_ident = name ; var_params = params ; _ } -> Typ . constr ? loc name ( List . map ~ f : of_type_expr params ) | Ptyp_tuple typs -> Typ . tuple ? loc ( List . map ~ f : of_type_expr typs ) | Ptyp_prover typ -> of_type_expr typ | Ptyp_conv ( typ1 , typ2 ) -> mk_typ_t ? loc typ1 typ2 | Ptyp_opaque typ -> Typ . constr ? loc ( Location . mkloc ( Option . value_exn ( Longident . unflatten [ " Snarky " ; " As_prover " ; " Ref " ; " t " ] ) ) ( Option . value ~ default : Location . none loc ) ) [ of_type_expr typ ] | Ptyp_alias ( typ , name ) -> Typ . alias ? loc ( of_type_expr typ ) name . txt | Ptyp_row ( tags , closed , min_tags ) -> Typ . variant ? loc ( List . map tags ~ f ( : fun { rtag_ident ; rtag_arg ; rtag_loc } -> match rtag_arg with | [ ] -> Rf . tag ~ loc : rtag_loc rtag_ident true [ ] | _ -> Rf . tag ~ loc : rtag_loc rtag_ident false [ Typ . tuple ~ loc : rtag_loc ( List . map ~ f : of_type_expr rtag_arg ) ] ) ) closed ( Option . map ~ f ( : List . map ~ f ( : fun { Location . txt ; _ } -> txt ) ) min_tags ) | Ptyp_row_subtract ( typ , _tags ) -> of_type_expr typ let typ1 = of_type_expr typ1 in let typ2 = of_type_expr typ2 in let typ_t = Option . value_exn ( Longident . unflatten [ " Snarky " ; " Types " ; " Typ " ; " t " ] ) in let typ_t = Location . mkloc typ_t loc in Typ . constr ~ loc typ_t [ typ1 ; typ2 ; Typ . any ~ loc ( ) ; Typ . any ~ loc ( ) ]
|
let of_field_decl { fld_ident = name ; fld_type = typ ; fld_loc = loc ; _ } = Type . field ~ loc name ( of_type_expr typ )
|
let of_ctor_args = function | Ctor_tuple args -> Parsetree . Pcstr_tuple ( List . map ~ f : of_type_expr args ) | Ctor_record fields -> Parsetree . Pcstr_record ( List . map ~ f : of_field_decl fields )
|
let of_ctor_decl { ctor_ident = name ; ctor_args = args ; ctor_ret = ret ; ctor_loc = loc } = Type . constructor name ~ loc ~ args ( : of_ctor_args args ) ? res ( : Option . map ~ f : of_type_expr ret )
|
let of_ctor_decl_ext { ctor_ident = name ; ctor_args = args ; ctor_ret = ret ; ctor_loc = loc } = Te . decl ~ loc ~ args ( : of_ctor_args args ) name ? res ( : Option . map ~ f : of_type_expr ret )
|
let of_type_decl decl = let loc = decl . tdec_loc in let name = decl . tdec_ident in let params = List . map ~ f ( : fun t -> ( of_type_expr t , Invariant ) ) decl . tdec_params in match decl . tdec_desc with | Pdec_abstract -> Type . mk name ~ loc ~ params | Pdec_alias typ -> Type . mk name ~ loc ~ params ~ manifest ( : of_type_expr typ ) | Pdec_record fields -> Type . mk name ~ loc ~ params ~ kind ( : Parsetree . Ptype_record ( List . map ~ f : of_field_decl fields ) ) | Pdec_variant ctors -> Type . mk name ~ loc ~ params ~ kind ( : Parsetree . Ptype_variant ( List . map ~ f : of_ctor_decl ctors ) ) | Pdec_open -> Type . mk name ~ loc ~ params ~ kind : Parsetree . Ptype_open | Pdec_extend _ -> failwith " Cannot convert TExtend to OCaml "
|
let of_literal = function | Int i -> Const . int i | Int32 i -> Const . int32 i | Int64 i -> Const . int64 i | Nativeint i -> Const . nativeint i | Float f -> Const . float ( string_of_float f ) | Char c -> Const . char c | String s -> Const . string s | Bool _ | Field _ -> assert false
|
let rec of_pattern_desc ? loc = function | Ppat_any -> Pat . any ? loc ( ) | Ppat_variable str -> Pat . var ? loc str | Ppat_constraint ( p , typ ) -> Pat . constraint_ ? loc ( of_pattern p ) ( of_type_expr typ ) | Ppat_tuple ps -> Pat . tuple ? loc ( List . map ~ f : of_pattern ps ) | Ppat_or ( p1 , p2 ) -> Pat . or_ ? loc ( of_pattern p1 ) ( of_pattern p2 ) | Ppat_integer ( i , suffix ) -> Pat . constant ? loc ( Const . integer i ? suffix ) | Ppat_literal l -> Pat . constant ? loc ( of_literal l ) | Ppat_record fields -> Pat . record ? loc ( List . map fields ~ f ( : fun ( f , p ) -> ( f , of_pattern p ) ) ) Open | Ppat_ctor ( name , arg ) -> Pat . construct ? loc name ( Option . map ~ f : of_pattern arg ) | Ppat_row_ctor ( name , args ) -> let args = match args with | [ ] -> None | [ arg ] -> Some ( of_pattern arg ) | _ -> Some ( Pat . tuple ? loc ( List . map ~ f : of_pattern args ) ) in Pat . variant ? loc name . txt args
|
let exp_of_literal ? loc = function | Bool _ -> failwith " Unhandled boolean literal " | Field _f -> failwith " Unhandled field literal " | ( Int _ | Int32 _ | Int64 _ | Nativeint _ | Float _ | Char _ | String _ ) as l -> Exp . constant ? loc ( of_literal l )
|
let rec of_expression_desc ? loc = function | Pexp_apply ( f , es ) -> Exp . apply ? loc ( of_expression f ) ( List . map ~ f ( : fun ( label , x ) -> ( label , of_expression x ) ) es ) | Pexp_variable name -> Exp . ident ? loc name | Pexp_integer ( i , suffix ) -> Exp . constant ? loc ( Const . integer i ? suffix ) | Pexp_literal l -> exp_of_literal ? loc l | Pexp_fun ( label , p , body , _ ) -> Exp . fun_ ? loc label None ( of_pattern p ) ( of_expression body ) | Pexp_newtype ( name , body ) -> Exp . newtype ? loc name ( of_expression body ) | Pexp_constraint ( e , typ ) -> Exp . constraint_ ? loc ( of_expression e ) ( of_type_expr typ ) | Pexp_seq ( e1 , e2 ) -> Exp . sequence ? loc ( of_expression e1 ) ( of_expression e2 ) | Pexp_let ( p , e_rhs , e ) -> Exp . let_ ? loc Nonrecursive [ Vb . mk ( of_pattern p ) ( of_expression e_rhs ) ] ( of_expression e ) | Pexp_instance ( name , e_rhs , e ) -> Exp . let_ ? loc Nonrecursive [ Vb . mk ( Pat . var ~ loc : name . loc name ) ( of_expression e_rhs ) ] ( of_expression e ) | Pexp_tuple es -> Exp . tuple ? loc ( List . map ~ f : of_expression es ) | Pexp_match ( e , cases ) -> Exp . match_ ? loc ( of_expression e ) ( List . map cases ~ f ( : fun ( p , e ) -> Exp . case ( of_pattern p ) ( of_expression e ) ) ) | Pexp_field ( e , field ) -> Exp . field ? loc ( of_expression e ) field | Pexp_record ( fields , ext ) -> Exp . record ? loc ( List . map fields ~ f ( : fun ( f , e ) -> ( f , of_expression e ) ) ) ( Option . map ~ f : of_expression ext ) | Pexp_ctor ( name , arg ) -> Exp . construct ? loc name ( Option . map ~ f : of_expression arg ) | Pexp_row_ctor ( name , args ) -> let args = match args with | [ ] -> None | [ arg ] -> Some ( of_expression arg ) | _ -> Some ( Exp . tuple ? loc ( List . map ~ f : of_expression args ) ) in Exp . variant ? loc name . txt args | Pexp_unifiable { expression = Some e ; _ } -> of_expression e | Pexp_unifiable { name ; _ } -> Exp . ident ? loc ( mk_lid name ) | Pexp_if ( e1 , e2 , e3 ) -> Exp . ifthenelse ? loc ( of_expression e1 ) ( of_expression e2 ) ( Option . map ~ f : of_expression e3 ) | Pexp_prover e -> of_expression e Parsetree . ( [ % expr function | With { request = [ % p match ctor_ident with | Some ctor_ident -> Pat . construct ~ loc ( mk_lid ctor_ident ) ( Option . map ~ f : of_pattern args ) | None -> ( match args with | Some args -> of_pattern args | None -> Pat . any ( ) ) ] ; respond } -> let unhandled = Snarky . Request . unhandled in [ % e of_expression body ] | _ -> Snarky . Request . unhandled ] )
|
let of_conv_type = function | Ptconv_with ( _mode , decl ) -> Some ( of_type_decl decl ) | Ptconv_to _ -> None
|
let rec of_signature_desc ? loc = function | Psig_value ( name , typ ) | Psig_instance ( name , typ ) -> Sig . value ? loc ( Val . mk ? loc name ( of_type_expr typ ) ) | Psig_type decl -> Sig . type_ ? loc Recursive [ of_type_decl decl ] | Psig_convtype _ -> assert false | Psig_rectype decls -> Sig . type_ ? loc Recursive ( List . map ~ f : of_type_decl decls ) | Psig_module ( name , msig ) -> let msig = match of_module_sig msig with | Some msig -> msig | None -> failwith " Cannot generate OCaml for a module with an abstract signature " in Sig . module_ ? loc ( Md . mk ? loc name msig ) | Psig_modtype ( name , msig ) -> Sig . modtype ? loc ( Mtd . mk ? loc ? typ ( : of_module_sig msig ) name ) | Psig_open name -> Sig . open_ ? loc ( Opn . mk ? loc name ) | Psig_typeext ( variant , ctors ) -> let params = List . map variant . var_params ~ f ( : fun typ -> ( of_type_expr typ , Invariant ) ) in let ctors = List . map ~ f : of_ctor_decl_ext ctors in Sig . type_extension ? loc ( Te . mk ~ params variant . var_ident ctors ) | Psig_request ( _ , ctor ) -> let params = [ ( Typ . any ? loc ( ) , Invariant ) ] in let ident = Location . mkloc Longident . ( Ldot ( Ldot ( Lident " Snarky " , " Request " ) , " t " ) ) ( Option . value ~ default : Location . none loc ) in Sig . type_extension ? loc ( Te . mk ~ params ident [ of_ctor_decl_ext ctor ] ) | Psig_multiple sigs | Psig_prover sigs -> Sig . include_ ? loc { pincl_mod = Mty . signature ? loc ( of_signature sigs ) ; pincl_loc = Option . value ~ default : Location . none loc ; pincl_attributes = [ ] } | Psig_convert ( name , typ ) -> Sig . value ? loc ( Val . mk ? loc name ( of_type_expr typ ) ) | Pmty_sig signature -> Some ( Mty . signature ? loc ( of_signature signature ) ) | Pmty_name name -> Some ( Mty . ident ? loc name ) | Pmty_alias name -> Some ( Mty . alias ? loc name ) | Pmty_abstract -> None | Pmty_functor ( name , f , msig ) -> let msig = match of_module_sig msig with | Some msig -> msig | None -> failwith " Cannot generate OCaml for a functor signature with an abstract \ signature " in Some ( Mty . functor_ ? loc name ( of_module_sig f ) msig )
|
let rec of_statement_desc ? loc = function | Pstmt_value ( p , e ) -> Str . value ? loc Nonrecursive [ Vb . mk ( of_pattern p ) ( of_expression e ) ] | Pstmt_instance ( name , e ) -> Str . value ? loc Nonrecursive [ Vb . mk ( Pat . var ? loc name ) ( of_expression e ) ] | Pstmt_type decl -> Str . type_ ? loc Nonrecursive [ of_type_decl decl ] | Pstmt_convtype _ -> assert false | Pstmt_rectype decls -> Str . type_ ? loc Recursive ( List . map ~ f : of_type_decl decls ) | Pstmt_module ( name , m ) -> Str . module_ ? loc ( Mb . mk ? loc name ( of_module_expr m ) ) | Pstmt_modtype ( name , msig ) -> Str . modtype ? loc ( Mtd . mk ? loc ? typ ( : of_module_sig msig ) name ) | Pstmt_open name -> Str . open_ ? loc ( Opn . mk ? loc ( Meja_of_ocaml . open_of_name name ) ) | Pstmt_open_instance _ -> Str . eval ? loc ( Exp . construct ? loc ( Location . mknoloc ( Longident . Lident " ( ) " ) ) None ) | Pstmt_typeext ( variant , ctors ) -> let params = List . map variant . var_params ~ f ( : fun typ -> ( of_type_expr typ , Invariant ) ) in let ctors = List . map ~ f : of_ctor_decl_ext ctors in Str . type_extension ? loc ( Te . mk ~ params variant . var_ident ctors ) | Pstmt_request ( _ , ctor , handler ) -> let params = [ ( Typ . any ? loc ( ) , Invariant ) ] in let ident = Location . mkloc Longident . ( Ldot ( Ldot ( Lident " Snarky " , " Request " ) , " t " ) ) ( Option . value ~ default : Location . none loc ) in let typ_ext = Str . type_extension ? loc ( Te . mk ~ params ident [ of_ctor_decl_ext ctor ] ) in let handler = Option . map handler ~ f : Parsetree . ( fun ( args , body ) -> let { txt = name ; loc } = ctor . ctor_ident in [ % stri let [ % p Pat . var ~ loc ( Location . mkloc ( " handle_ " ^ name ) loc ) ] = function | With { request = [ % p Pat . construct ~ loc ( mk_lid ctor . ctor_ident ) ( Option . map ~ f : of_pattern args ) ] ; respond } -> let unhandled = Snarky . Request . unhandled in [ % e of_expression body ] | _ -> Snarky . Request . unhandled ] ) in Str . include_ ? loc { pincl_mod = Mod . structure ? loc ( typ_ext :: Option . to_list handler ) ; pincl_loc = Option . value ~ default : Location . none loc ; pincl_attributes = [ ] } | Pstmt_multiple stmts | Pstmt_prover stmts -> Str . include_ ? loc { pincl_mod = Mod . structure ? loc ( List . map ~ f : of_statement stmts ) ; pincl_loc = Option . value ~ default : Location . none loc ; pincl_attributes = [ ] } | Pstmt_convert _ -> assert false | Pmod_struct stmts -> Mod . structure ? loc ( List . map ~ f : of_statement stmts ) | Pmod_name name -> Mod . ident ? loc name | Pmod_functor ( name , f , m ) -> Mod . functor_ ? loc name ( of_module_sig f ) ( of_module_expr m )
|
let of_file = List . map ~ f : of_statement
|
let sexp_of_month x = CCSexp . atom @@ CCOption . get_exn_or " Expected valid month " @@ Time . abbr_string_of_month x
|
let sexp_of_weekday x = CCSexp . atom @@ Time . abbr_string_of_weekday x
|
let sexp_of_int64 x = CCSexp . atom @@ Int64 . to_string x
|
let sexp_of_int x = CCSexp . atom @@ string_of_int x
|
let sexp_list_of_ints l = List . map sexp_of_int l
|
let sexp_of_tz_name t = CCSexp . atom ( Timedesc . Time_zone . name t )
|
let sexp_of_points ( { pick ; tz_info } : Points . t ) = let open CCSexp in let open Points in list ( CCList . filter_map CCFun . id [ Some ( atom " points " ) ; Some ( list ( atom " pick " :: ( match pick with | N ns -> [ atom " n " ; sexp_of_int ns ] | SN { second ; ns } -> [ atom " sn " ; sexp_of_int second ; sexp_of_int ns ] | MSN { minute ; second ; ns } -> [ atom " msn " ; sexp_of_int minute ; sexp_of_int second ; sexp_of_int ns ; ] | HMSN { hour ; minute ; second ; ns } -> [ atom " hmsn " ; sexp_of_int hour ; sexp_of_int minute ; sexp_of_int second ; sexp_of_int ns ; ] | WHMSN { weekday ; hour ; minute ; second ; ns } -> [ atom " whmsn " ; sexp_of_weekday weekday ; sexp_of_int hour ; sexp_of_int minute ; sexp_of_int second ; sexp_of_int ns ; ] | DHMSN { month_day ; hour ; minute ; second ; ns } -> [ atom " dhmsn " ; sexp_of_int month_day ; sexp_of_int hour ; sexp_of_int minute ; sexp_of_int second ; sexp_of_int ns ; ] | MDHMSN { month ; month_day ; hour ; minute ; second ; ns } -> [ atom " mdhmsn " ; sexp_of_month month ; sexp_of_int month_day ; sexp_of_int hour ; sexp_of_int minute ; sexp_of_int second ; sexp_of_int ns ; ] | YMDHMSN { year ; month ; month_day ; hour ; minute ; second ; ns } -> [ atom " ymdhmsn " ; sexp_of_int year ; sexp_of_month month ; sexp_of_int month_day ; sexp_of_int hour ; sexp_of_int minute ; sexp_of_int second ; sexp_of_int ns ; ] ) ) ) ; CCOption . map Timedesc . Time_zone_info . to_sexp tz_info ; ] )
|
let sexp_of_range ( ~ f : ' a -> CCSexp . t ) ( r : ' a Time . Range . range ) = match r with | ` Range_inc ( x , y ) -> CCSexp . ( list [ atom " range_inc " ; f x ; f y ] ) | ` Range_exc ( x , y ) -> CCSexp . ( list [ atom " range_exc " ; f x ; f y ] )
|
let sexp_of_iso_week_pattern ( years : Int_set . t ) ( weeks : Int_set . t ) : CCSexp . t = let years = Int_set . to_list years |> sexp_list_of_ints in let weeks = Int_set . to_list weeks |> sexp_list_of_ints in CCSexp . ( list [ atom " iso_week_pattern " ; list years ; list weeks ] )
|
let sexp_of_pattern ( pat : Pattern . t ) : CCSexp . t = let years = pat . years |> Int_set . to_list |> sexp_list_of_ints in let months = pat . months |> Int_set . to_list |> List . map sexp_of_month in let month_days = pat . month_days |> Int_set . to_list |> sexp_list_of_ints in let weekdays = pat . weekdays |> Weekday_set . to_list |> List . map sexp_of_weekday in let hours = pat . hours |> Int_set . to_list |> sexp_list_of_ints in let minutes = pat . minutes |> Int_set . to_list |> sexp_list_of_ints in let seconds = pat . seconds |> Int_set . to_list |> sexp_list_of_ints in let ns = Diet . Int . fold ( fun interval acc -> ( Diet . Int . Interval . x interval , Diet . Int . Interval . y interval ) :: acc ) pat . ns [ ] |> List . rev |> List . map ( fun ( x , y ) -> ` List [ sexp_of_int x ; sexp_of_int y ] ) in let open CCSexp in [ Some ( atom " pattern " ) ; ( match years with [ ] -> None | _ -> Some ( list ( atom " years " :: years ) ) ) ; ( match months with | [ ] -> None | _ -> Some ( list ( atom " months " :: months ) ) ) ; ( match month_days with | [ ] -> None | _ -> Some ( list ( atom " month_days " :: month_days ) ) ) ; ( match weekdays with | [ ] -> None | _ -> Some ( list ( atom " weekdays " :: weekdays ) ) ) ; ( match hours with [ ] -> None | _ -> Some ( list ( atom " hours " :: hours ) ) ) ; ( match minutes with | [ ] -> None | _ -> Some ( list ( atom " minutes " :: minutes ) ) ) ; ( match seconds with | [ ] -> None | _ -> Some ( list ( atom " seconds " :: seconds ) ) ) ; ( match ns with [ ] -> None | _ -> Some ( list ( atom " ns " :: ns ) ) ) ; ] |> CCList . filter_map CCFun . id |> list
|
let sexp_list_of_unary_op ( op : Time_ast . unary_op ) = match op with | Not -> [ CCSexp . atom " not " ] | Shift n -> [ CCSexp . atom " shift " ; sexp_of_span n ] | Lengthen n -> [ CCSexp . atom " lengthen " ; sexp_of_span n ] | With_tz tz -> [ CCSexp . atom " with_tz " ; CCSexp . atom ( Timedesc . Time_zone . name tz ) ]
|
let to_sexp ( t : Time_ast . t ) : CCSexp . t = let rec aux ( t : Time_ast . t ) = match t with | All -> CCSexp . ( list [ atom " all " ] ) | Empty -> CCSexp . ( list [ atom " empty " ] ) | Intervals s -> let l = s |> CCList . of_seq |> List . map ( fun ( x , y ) -> CCSexp . list [ sexp_of_timestamp x ; sexp_of_timestamp y ] ) in CCSexp . list ( CCSexp . atom " intervals " :: l ) | ISO_week_pattern ( years , weeks ) -> sexp_of_iso_week_pattern years weeks | Pattern pat -> sexp_of_pattern pat | Unary_op ( op , t ) -> CCSexp . list ( sexp_list_of_unary_op op @ [ aux t ] ) | Inter_seq s -> CCSexp . ( list ( atom " inter " :: ( s |> Seq . map aux |> CCList . of_seq ) ) ) | Union_seq s -> CCSexp . ( list ( atom " union " :: ( s |> Seq . map aux |> CCList . of_seq ) ) ) | Pattern_intervals { mode ; bound ; start ; end_ } -> CCSexp . ( list [ atom " pattern_intervals " ; ( match mode with | ` Whole_inc -> atom " whole_inc " | ` Whole_exc -> atom " whole_exc " | ` Fst -> atom " fst " | ` Snd -> atom " snd " ) ; sexp_of_span bound ; sexp_of_points start ; sexp_of_points end_ ; ] ) | Unchunk chunked -> CCSexp . ( list [ atom " unchunk " ; aux_chunked chunked ] ) and aux_chunked chunked = let sexp_list_of_unary_op_on_t op = let open CCSexp in match op with | Time_ast . Chunk_disjoint_interval -> [ atom " chunk_disjoint_intervals " ] | Chunk_at_year_boundary -> [ atom " chunk_at_year_boundary " ] | Chunk_at_month_boundary -> [ atom " chunk_at_month_boundary " ] | Chunk_by_duration { chunk_size ; drop_partial } -> [ Some ( atom " chunk_by_duration " ) ; Some ( sexp_of_span chunk_size ) ; ( if drop_partial then Some ( atom " drop_partial " ) else None ) ; ] |> CCList . filter_map CCFun . id in match chunked with | Unary_op_on_t ( op , t ) -> CCSexp . ( list ( sexp_list_of_unary_op_on_t op @ [ aux t ] ) ) | Unary_op_on_chunked ( op , chunked ) -> CCSexp . ( list ( match op with | Drop n -> [ atom " drop " ; sexp_of_int n ; aux_chunked chunked ] | Take n -> [ atom " take " ; sexp_of_int n ; aux_chunked chunked ] | Take_nth n -> [ atom " take_nth " ; sexp_of_int n ; aux_chunked chunked ] | Nth n -> [ atom " nth " ; sexp_of_int n ; aux_chunked chunked ] | Chunk_again op -> [ atom " chunk_again " ; list ( sexp_list_of_unary_op_on_t op @ [ aux_chunked chunked ] ) ; ] ) ) in aux t
|
let wrap_to_sexp_into_to_sexp_string ( f : ' a -> CCSexp . t ) x = CCSexp . to_string ( f x )
|
let to_sexp_string = wrap_to_sexp_into_to_sexp_string to_sexp
|
module File_type_specification = struct open Biokepi_run_environment . Common . KEDSL type t = . . type t += | To_unit : t -> t | Fastq : fastq_reads workflow_node -> t | Bam : bam_file workflow_node -> t | Vcf : vcf_file workflow_node -> t | Bed : single_file workflow_node -> t | Gtf : single_file workflow_node -> t | Seq2hla_result : Biokepi_bfx_tools . Seq2HLA . product workflow_node -> t | Optitype_result : Biokepi_bfx_tools . Optitype . product workflow_node -> t | Fastqc_result : list_of_files workflow_node -> t | Flagstat_result : single_file workflow_node -> t | Isovar_result : single_file workflow_node -> t | Topiary_result : single_file workflow_node -> t | Vaxrank_result : Biokepi_bfx_tools . Vaxrank . product workflow_node -> t | MHC_alleles : single_file workflow_node -> t | Bai : single_file workflow_node -> t | Kallisto_result : single_file workflow_node -> t | Cufflinks_result : single_file workflow_node -> t | Raw_file : single_file workflow_node -> t | Gz : t -> t | List : t list -> t | Pair : t * t -> t | Lambda : ( t -> t ) -> t let to_string_functions : ( t -> string option ) list ref = ref [ ] let add_to_string f = to_string_functions := f :: ! to_string_functions let rec to_string : type a . t -> string = function | To_unit a -> sprintf " ( to_unit % s ) " ( to_string a ) | Fastq _ -> " Fastq " | Bam _ -> " Bam " | Vcf _ -> " Vcf " | Bed _ -> " Bed " | Gtf _ -> " Gtf " | Seq2hla_result _ -> " Seq2hla_result " | Optitype_result _ -> " Optitype_result " | Fastqc_result _ -> " Fastqc_result " | Flagstat_result _ -> " Flagstat_result " | Isovar_result _ -> " Isovar_result " | Topiary_result _ -> " Topiary_result " | Vaxrank_result _ -> " Vaxrank_result " | MHC_alleles _ -> " MHC_alleles " | Bai _ -> " Bai " | Kallisto_result _ -> " Kallisto_result " | Cufflinks_result _ -> " Cufflinks_result " | Raw_file _ -> " Input_url " | Gz a -> sprintf " ( gz % s ) " ( to_string a ) | List l -> sprintf " [ % s ] " ( List . map l ~ f : to_string |> String . concat ~ sep " ; : " ) | Pair ( a , b ) -> sprintf " ( % s , % s ) " ( to_string a ) ( to_string b ) | Lambda _ -> " -- LAMBDA " -- | other -> begin match List . find_map ! to_string_functions ~ f ( : fun f -> f other ) with | None -> " ## UNKNOWN " ## | Some s -> s end let fail_get other name = ksprintf failwith " Error while extracting File_type_specification . t \ ( % s case , in % s ) , this usually means that the type \ has been wrongly extended " ( to_string other ) name let get_fastq : t -> fastq_reads workflow_node = function | Fastq b -> b | o -> fail_get o " Fastq " let get_bam : t -> bam_file workflow_node = function | Bam b -> b | o -> fail_get o " Bam " let get_vcf : t -> vcf_file workflow_node = function | Vcf v -> v | o -> fail_get o " Vcf " let get_bed : t -> single_file workflow_node = function | Bed v -> v | o -> fail_get o " Bed " let get_gtf : t -> single_file workflow_node = function | Gtf v -> v | o -> fail_get o " Gtf " let get_raw_file : t -> single_file workflow_node = function | Raw_file v -> v | o -> fail_get o " Raw_file " let get_seq2hla_result : t -> Biokepi_bfx_tools . Seq2HLA . product workflow_node = function | Seq2hla_result v -> v | o -> fail_get o " Seq2hla_result " let get_fastqc_result : t -> list_of_files workflow_node = function | Fastqc_result v -> v | o -> fail_get o " Fastqc_result " let get_flagstat_result : t -> single_file workflow_node = function | Flagstat_result v -> v | o -> fail_get o " Flagstat_result " let get_isovar_result : t -> single_file workflow_node = function | Isovar_result v -> v | o -> fail_get o " Isovar_result " let get_topiary_result : t -> single_file workflow_node = function | Topiary_result v -> v | o -> fail_get o " Topiary_result " let get_vaxrank_result : t -> Biokepi_bfx_tools . Vaxrank . product workflow_node = function | Vaxrank_result v -> v | o -> fail_get o " Vaxrank_result " let get_mhc_alleles : t -> single_file workflow_node = function | MHC_alleles v -> v | o -> fail_get o " Topiary_result " let get_bai : t -> single_file workflow_node = function | Bai v -> v | o -> fail_get o " Bai " let get_kallisto_result : t -> single_file workflow_node = function | Kallisto_result v -> v | o -> fail_get o " Kallisto_result " let get_cufflinks_result : t -> single_file workflow_node = function | Cufflinks_result v -> v | o -> fail_get o " Cufflinks_result " let get_optitype_result : t -> Biokepi_bfx_tools . Optitype . product workflow_node = function | Optitype_result v -> v | o -> fail_get o " Optitype_result " let pair_fst = function | Pair ( a , _ ) -> a | other -> fail_get other " Pair - fst " let pair_snd = function | Pair ( _ , b ) -> b | other -> fail_get other " Pair - snd " let get_gz : t -> t = function | Gz v -> v | o -> fail_get o " Gz " let get_list : t -> t list = function | List v -> v | o -> fail_get o " List " let to_deps_functions : ( t -> workflow_edge list option ) list ref = ref [ ] let add_to_dependencies_edges_function f = to_deps_functions := f :: ! to_deps_functions let rec as_dependency_edges : type a . t -> workflow_edge list = let one_depends_on wf = [ depends_on wf ] in function | To_unit v -> as_dependency_edges v | Fastq wf -> one_depends_on wf | Bam wf -> one_depends_on wf | Vcf wf -> one_depends_on wf | Gtf wf -> one_depends_on wf | Seq2hla_result wf -> one_depends_on wf | Fastqc_result wf -> one_depends_on wf | Flagstat_result wf -> one_depends_on wf | Isovar_result wf -> one_depends_on wf | Optitype_result wf -> one_depends_on wf | Topiary_result wf -> one_depends_on wf | Vaxrank_result wf -> one_depends_on wf | Cufflinks_result wf -> one_depends_on wf | Bai wf -> one_depends_on wf | Kallisto_result wf -> one_depends_on wf | MHC_alleles wf -> one_depends_on wf | Raw_file w -> one_depends_on w | List l -> List . concat_map l ~ f : as_dependency_edges | Pair ( a , b ) -> as_dependency_edges a @ as_dependency_edges b | other -> begin match List . find_map ! to_deps_functions ~ f ( : fun f -> f other ) with | None -> fail_get other " as_dependency_edges " | Some s -> s end let get_unit_workflow : name : string -> t -> unknown_product workflow_node = fun ~ name f -> match f with | To_unit v -> workflow_node without_product ~ name ~ edges ( : as_dependency_edges v ) | other -> fail_get other " get_unit_workflow " end
|
module type Compiler_configuration = sig val work_dir : string val results_dir : string option val machine : Machine . t val map_reduce_gatk_indel_realigner : bool val input_files : [ ` Copy | ` Link | ` Do_nothing ] end
|
module Defaults = struct let map_reduce_gatk_indel_realigner = true let input_files = ` Link let results_dir = None end
|
module Provenance_description = struct type t = { name : string ; sub_tree_arguments : ( string * t ) list ; string_arguments : ( string * string ) list ; json_arguments : ( string * Yojson . Basic . json ) list ; } let rec to_yojson t : Yojson . Basic . json = let fields = List . concat [ List . map t . sub_tree_arguments ~ f ( : fun ( k , v ) -> k , to_yojson v ) ; List . map t . string_arguments ~ f ( : fun ( k , v ) -> k , ` String v ) ; t . json_arguments ; ] in ` Assoc ( ( " node - name " , ` String t . name ) :: fields ) end
|
module Annotated_file = struct type t = { file : File_type_specification . t ; provenance : Provenance_description . t ; functional : ( t -> Provenance_description . t ) option ; } let with_provenance ? functional ( ? string_arguments = [ ] ) ( ? json_arguments = [ ] ) name arguments file = { file ; provenance = { Provenance_description . name ; sub_tree_arguments = arguments ; string_arguments ; json_arguments } ; functional ; } let get_file t = t . file let get_provenance t = t . provenance let get_functional_provenance t = t . functional |> Option . value_exn ~ msg " : get_functional_provenance " end
|
module Saving_utilities = struct let base_path ? results_dir ~ work_dir ~ name ( ) = let name = String . map name ~ f ( : function | ' 0 ' . . ' 9 ' | ' a ' . . ' z ' | ' A ' . . ' Z ' | ' ' - | ' _ ' as c -> c | other -> ' _ ' ) in match results_dir with | None -> work_dir // " results " // name | Some r -> r // name end
|
let get_workflow : name : string -> Annotated_file . t -> unknown_product workflow_node = fun ~ name f -> let v = Annotated_file . get_file f in workflow_node without_product ~ name ~ edges ( : File_type_specification . as_dependency_edges v )
|
module Make ( Config : Compiler_configuration ) : Semantics . Bioinformatics_base with type ' a repr = Annotated_file . t and type ' a observation = Annotated_file . t open File_type_specification module AF = Annotated_file module Tools = Biokepi_bfx_tools module KEDSL = Common . KEDSL let failf fmt = ksprintf failwith fmt type ' a repr = Annotated_file . t type ' a observation = Annotated_file . t let observe : ( unit -> ' a repr ) -> ' a observation = fun f -> f ( ) let lambda : ( ' a repr -> ' b repr ) -> ( ' a -> ' b ) repr = fun f -> Lambda ( fun x -> let annot = f ( x |> AF . with_provenance " variable " [ ] ) in AF . get_file annot ) |> AF . with_provenance " lamda " [ ] ~ functional ( : fun x -> f x |> AF . get_provenance ) let apply : ( ' a -> ' b ) repr -> ' a repr -> ' b repr = fun f_repr x -> let annot_f = AF . get_functional_provenance f_repr in let annot_x = AF . get_provenance x in match AF . get_file f_repr with | Lambda f -> f ( AF . get_file x ) |> AF . with_provenance " apply " [ " function " , annot_f x ; " argument " , annot_x ; ] | _ -> assert false let list : ' a repr list -> ' a list repr = fun l -> let ann = List . mapi ~ f ( : fun i x -> sprintf " element_ % d " i , AF . get_provenance x ) l in List ( List . map l ~ f : AF . get_file ) |> AF . with_provenance " list " ann let list_map : ' a list repr -> f ( ' : a -> ' b ) repr -> ' b list repr = fun l ~ f -> let ann_l = AF . get_provenance l in match AF . get_file l with | List l -> let applied_annotated = List . map ~ f ( : fun v -> apply f ( v |> AF . with_provenance " X " [ ] ) ) l in let prov = ( " list " , ann_l ) :: List . map applied_annotated ~ f ( : fun x -> " applied " , AF . get_provenance x ) in List ( List . map applied_annotated ~ f : AF . get_file ) |> AF . with_provenance " list - map " prov | _ -> assert false let pair a b = Pair ( AF . get_file a , AF . get_file b ) |> AF . with_provenance " pair " [ " left " , AF . get_provenance a ; " right " , AF . get_provenance b ] let pair_first x = match AF . get_file x with | Pair ( a , _ ) -> a |> AF . with_provenance " pair - first " [ " pair " , AF . get_provenance x ] | other -> fail_get other " Pair " let pair_second x = match AF . get_file x with | Pair ( _ , b ) -> b |> AF . with_provenance " pair - second " [ " pair " , AF . get_provenance x ] | other -> fail_get other " Pair " let to_unit x = To_unit ( AF . get_file x ) |> AF . with_provenance " to - unit " [ " argument " , AF . get_provenance x ] let host = Machine . as_host Config . machine let run_with = Config . machine let deal_with_input_file ( ifile : _ KEDSL . workflow_node ) ~ make_product = let open KEDSL in let new_path = Name_file . in_directory Config . work_dir ~ readable_suffix ( : Filename . basename ifile # product # path ) [ ifile # product # path ] in let make = Machine . quick_run_program Config . machine Program . ( shf " mkdir - p % s " Config . work_dir && ( match Config . input_files with | ` Link -> shf " cd % s " Config . work_dir && shf " ln - s % s % s " ifile # product # path new_path | ` Copy -> shf " cp % s % s " ifile # product # path new_path | ` Do_nothing -> shf " echo ' No input action on % s ' " ifile # product # path ) ) in let host = ifile # product # host in let product = match Config . input_files with | ` Do_nothing -> ifile # product | ` Link | ` Copy -> make_product new_path in let name = sprintf " Input file % s ( % s ) " ( Filename . basename new_path ) ( match Config . input_files with | ` Link -> " link " | ` Copy -> " copy " | ` Do_nothing -> " as - is " ) in let ensures = ` Is_verified Condition . ( chain_and [ volume_exists Volume . ( create ~ host ~ root : Config . work_dir ( dir " . " [ ] ) ) ; product # is_done |> Option . value_exn ~ msg " : File without is_done " ; ? ] ) in workflow_node product ~ ensures ~ name ~ make ~ edges [ : depends_on ifile ] let input_url url = let open KEDSL in let uri = Uri . of_string url in let path_of_uri uri = let basename = match Uri . get_query_param uri " filename " with | Some f -> f | None -> Digest . ( string url |> to_hex ) ^ ( Uri . path uri |> Filename . basename ) in Config . work_dir // basename in begin match Uri . scheme uri with | None | Some " file " -> let raw_file = workflow_node ( Uri . path uri |> single_file ~ host ) ~ name ( : sprintf " Input file : % s " url ) in Raw_file ( deal_with_input_file raw_file ( single_file ~ host ) ) | Some " http " | Some " https " -> let path = path_of_uri uri in Raw_file Biokepi_run_environment . ( Workflow_utilities . Download . wget ~ host ~ run_program ( : Machine . run_download_program Config . machine ) url path ) | Some " gs " -> let path = path_of_uri uri in Raw_file Biokepi_run_environment . ( Workflow_utilities . Download . gsutil_cp ~ host ~ run_program ( : Machine . run_download_program Config . machine ) ~ url ~ local_path : path ) | Some other -> ksprintf failwith " URI scheme % S ( in % s ) NOT SUPPORTED " other url end |> AF . with_provenance " input - url " ~ string_arguments [ " : url " , url ] [ ] let save ~ name thing = let open KEDSL in let basename = Filename . basename in let canonicalize path = let suffix = " " / in if Filename . check_suffix path suffix then String . chop_suffix_exn ~ suffix path else path in let base_path = Saving_utilities . base_path ? results_dir : Config . results_dir ~ work_dir : Config . work_dir ~ name ( ) in let move ( ? and_gzip = false ) ~ from_path ~ wf product = let json = ` Assoc [ " base - path " , ` String base_path ; " saved - from " , ` String from_path ; " provenance " , AF . get_provenance thing |> Provenance_description . to_yojson ; ] |> Yojson . Basic . pretty_to_string in let make = Machine . quick_run_program Config . machine Program . ( shf " mkdir - p % s " base_path && shf " rsync - a % s % s " from_path base_path && ( match and_gzip with | true -> shf " for f in ( $ find % s - type f ) ; do \ gzip -- force -- keep $ f ; \ done " base_path | false -> sh " echo ' No GZipping Requested ' " ) && shf " echo % s > % s . json " ( Filename . quote json ) base_path ) in let name = sprintf " Saving " \% s " " \ name in workflow_node product ~ name ~ make ~ edges [ : depends_on wf ] in let tf path = transform_single_file ~ path in begin match AF . get_file thing with | Bam wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Bam ( move ~ from_path ~ wf ( transform_bam ~ path : to_path wf # product ) ) | Vcf wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Vcf ( move ~ and_gzip : true ~ from_path ~ wf ( transform_vcf ~ path : to_path wf # product ) ) | Gtf wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Gtf ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Flagstat_result wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Flagstat_result ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Isovar_result wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Isovar_result ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Topiary_result wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Topiary_result ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Vaxrank_result wf -> let from_path = canonicalize wf # product # output_folder_path in let to_path = base_path // basename from_path in let vp = Tools . Vaxrank . move_vaxrank_product ~ output_folder_path : to_path wf # product in Vaxrank_result ( move ~ from_path ~ wf vp ) | Optitype_result wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in let o = Tools . Optitype . move_optitype_product ~ path : to_path wf # product in let from_path = wf # product # path in Optitype_result ( move ~ from_path ~ wf o ) | Seq2hla_result wf -> let from_path = canonicalize wf # product # work_dir_path in let to_path = base_path // basename from_path in let s = Tools . Seq2HLA . move_seq2hla_product ~ path : to_path wf # product in Seq2hla_result ( move ~ from_path ~ wf s ) | Fastqc_result wf -> let from_path = wf # product # paths |> List . hd_exn |> Filename . dirname |> canonicalize in let fqc = let paths = List . map wf # product # paths ~ f ( : fun p -> base_path // ( basename from_path ) // ( basename p ) ) in list_of_files paths in Fastqc_result ( move ~ from_path ~ wf fqc ) | Cufflinks_result wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Cufflinks_result ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Bai wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Bai ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Kallisto_result wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in Kallisto_result ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | MHC_alleles wf -> let from_path = wf # product # path in let to_path = base_path // basename from_path in MHC_alleles ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Raw_file wf -> let from_path = canonicalize wf # product # path in let to_path = base_path // basename from_path in Raw_file ( move ~ from_path ~ wf ( tf to_path wf # product ) ) | Gz _ -> failwith " Cannot ` save ` Gz . " | List _ -> failwith " Cannot ` save ` List . " | Pair _ -> failwith " Cannot ` save ` Pair . " | Lambda _ -> failwith " Cannot ` save ` Lambda . " | _ -> failwith " Shouldn ' t get here : pattern match for ` save ` must be exhaustive . " end |> AF . with_provenance " save " [ " product " , AF . get_provenance thing ] ~ string_arguments [ " : name " , name ] let fastq ~ sample_name ? fragment_id ~ r1 ? r2 ( ) = Fastq ( let open KEDSL in let read1 = get_raw_file ( AF . get_file r1 ) in let read2 = Option . map r2 ~ f ( : fun r -> AF . get_file r |> get_raw_file ) in fastq_node_of_single_file_nodes ? fragment_id ~ host ~ name : sample_name read1 read2 ) |> AF . with_provenance " fastq " ( ( " r1 " , AF . get_provenance r1 ) :: Option . value_map ~ default [ ] : r2 ~ f ( : fun r -> [ " r2 " , AF . get_provenance r ] ) ) ~ string_arguments ( : ( " sample - name " , sample_name ) :: Option . value_map fragment_id ~ default [ ] : ~ f ( : fun id -> [ " fragment - id " , id ] ) ) let fastq_gz ~ sample_name ? fragment_id ~ r1 ? r2 ( ) = let fq = fastq ~ sample_name ? fragment_id ~ r1 ? r2 ( ) in Gz ( AF . get_file fq ) |> AF . with_provenance " gz " [ " fastq " , AF . get_provenance fq ] let bam ~ sample_name ? sorting ~ reference_build input = Bam ( let open KEDSL in let host = Machine . as_host Config . machine in let f = get_raw_file ( AF . get_file input ) in let bam = bam_file ~ host ~ name : sample_name ? sorting ~ reference_build f # product # path in workflow_node bam ~ equivalence ` : None ~ name ( : sprintf " Input - bam : % s " sample_name ) ~ edges [ : depends_on f ] ) |> AF . with_provenance " bam " [ " file " , AF . get_provenance input ] ~ string_arguments [ : " sample - name " , sample_name ; " sorting " , ( match sorting with | Some ` Coordinate -> " coordinate " | None -> " none " | Some ` Read_name -> " read - name " ) ; " reference - build " , reference_build ; ] let bed file = Bed ( get_raw_file ( AF . get_file file ) ) |> AF . with_provenance " bed " [ " file " , AF . get_provenance file ] let mhc_alleles how = match how with | ` File raw -> MHC_alleles ( get_raw_file ( AF . get_file raw ) ) |> AF . with_provenance " mhc - alleles " [ " file " , AF . get_provenance raw ] | ` Names strlist -> let path = Name_file . in_directory ~ readable_suffix " : MHC_allleles . txt " Config . work_dir strlist in let open KEDSL in let host = Machine . as_host Config . machine in let product = single_file ~ host path in let node = workflow_node product ~ name ( : sprintf " Inline - MHC - alleles : % s " ( String . concat ~ sep " , : " strlist ) ) ~ make ( : Machine . quick_run_program Config . machine Program . ( let line s = shf " echo % s >> % s " ( Filename . quote s ) ( Filename . quote path ) in shf " mkdir - p % s " ( Filename . dirname path ) && shf " rm - f % s " ( Filename . quote path ) && chain ( List . map ~ f : line strlist ) ) ) in MHC_alleles node |> AF . with_provenance " mhc - allelles " [ ] ~ string_arguments ( : List . mapi strlist ~ f ( : fun i s -> sprintf " allele -% d " i , s ) ) let index_bam bam = let input_bam = get_bam ( AF . get_file bam ) in let sorted_bam = Tools . Samtools . sort_bam_if_necessary ~ run_with ~ by ` : Coordinate input_bam in Bai ( Tools . Samtools . index_to_bai ~ run_with ~ check_sorted : true sorted_bam ) |> AF . with_provenance " index - bam " [ " bam " , AF . get_provenance bam ] let kallisto ~ reference_build ( ? bootstrap_samples = 100 ) fastq = let fq = get_fastq ( AF . get_file fastq ) in let result_prefix = Name_file . in_directory ~ readable_suffix " : kallisto " Config . work_dir [ fq # product # escaped_sample_name ; sprintf " % d " bootstrap_samples ; reference_build ; ] in Kallisto_result ( Tools . Kallisto . run ~ reference_build ~ fastq : fq ~ run_with ~ result_prefix ~ bootstrap_samples ) |> AF . with_provenance " kallisto " [ " fastq " , AF . get_provenance fastq ] ~ string_arguments [ : " reference - build " , reference_build ; " bootstrap - samples " , Int . to_string bootstrap_samples ; ] let delly2 ( ? configuration = Tools . Delly2 . Configuration . default ) ~ normal ~ tumor ( ) = let normal_bam = get_bam ( AF . get_file normal ) in let tumor_bam = get_bam ( AF . get_file tumor ) in let output_path = Name_file . in_directory ~ readable_suffix " :- delly2 . vcf " Config . work_dir [ normal_bam # product # path ; tumor_bam # product # path ; Tools . Delly2 . Configuration . name configuration ; ] in let bcf = Tools . Delly2 . run_somatic ~ configuration ~ run_with ~ normal : normal_bam ~ tumor : tumor_bam ~ output_path ( : output_path ^ " . bcf " ) in Vcf ( Tools . Bcftools . bcf_to_vcf ~ run_with ~ reference_build : normal_bam # product # reference_build ~ bcf output_path ) |> AF . with_provenance " delly2 " [ " normal " , AF . get_provenance normal ; " tumor " , AF . get_provenance tumor ] ~ string_arguments [ : " configuration - name " , Tools . Delly2 . Configuration . name configuration ; ] ~ json_arguments [ : " configuration " , Tools . Delly2 . Configuration . to_json configuration ; ] let cufflinks ? reference_build bamf = let bam = get_bam ( AF . get_file bamf ) in let reference_build = match reference_build with | None -> bam # product # reference_build | Some r -> r in let result_prefix = Name_file . in_directory ~ readable_suffix " : cufflinks " Config . work_dir [ bam # product # escaped_sample_name ; reference_build ] in Cufflinks_result ( Tools . Cufflinks . run ~ reference_build ~ bam ~ run_with ~ result_prefix ) |> AF . with_provenance " cufflinks " [ " bam " , AF . get_provenance bamf ] ~ string_arguments [ " : reference - build " , reference_build ] let make_aligner name ~ make_workflow ~ config_name ~ config_to_json ~ configuration ~ reference_build fastq = let freads = get_fastq ( AF . get_file fastq ) in let result_prefix = Name_file . in_directory ~ readable_suffix : name Config . work_dir [ config_name configuration ; freads # product # escaped_sample_name ; freads # product # fragment_id_forced ; name ; ] in Bam ( make_workflow ~ reference_build ~ configuration ~ result_prefix ~ run_with freads ) |> AF . with_provenance name [ " fastq " , AF . get_provenance fastq ] ~ string_arguments [ : " configuration - name " , config_name configuration ; " reference - build " , reference_build ; ] ~ json_arguments [ " : configuration " , config_to_json configuration ] let bwa_aln ( ? configuration = Tools . Bwa . Configuration . Aln . default ) = make_aligner " bwaaln " ~ configuration ~ config_name : Tools . Bwa . Configuration . Aln . name ~ config_to_json : Tools . Bwa . Configuration . Aln . to_json ~ make_workflow ( : fun ~ reference_build ~ configuration ~ result_prefix ~ run_with freads -> Tools . Bwa . align_to_sam ~ reference_build ~ configuration ~ fastq : freads ~ result_prefix ~ run_with ( ) |> Tools . Samtools . sam_to_bam ~ reference_build ~ run_with ) let bwa_mem ( ? configuration = Tools . Bwa . Configuration . Mem . default ) = make_aligner " bwamem " ~ configuration ~ config_name : Tools . Bwa . Configuration . Mem . name ~ config_to_json : Tools . Bwa . Configuration . Mem . to_json ~ make_workflow ( : fun ~ reference_build ~ configuration ~ result_prefix ~ run_with freads -> Tools . Bwa . mem_align_to_sam ~ reference_build ~ configuration ~ fastq : freads ~ result_prefix ~ run_with ( ) |> Tools . Samtools . sam_to_bam ~ reference_build ~ run_with ) let bwa_mem_opt ( ? configuration = Tools . Bwa . Configuration . Mem . default ) ~ reference_build input = let bwa_mem_opt input annot = let result_prefix = Name_file . in_directory ~ readable_suffix " : bwamemopt " Config . work_dir [ Tools . Bwa . Configuration . Mem . name configuration ; Tools . Bwa . Input_reads . sample_name input ; Tools . Bwa . Input_reads . read_group_id input ; ] in Bam ( Tools . Bwa . mem_align_to_bam ~ configuration ~ reference_build ~ run_with ~ result_prefix input ) |> AF . with_provenance " bwa - mem - opt " [ " input " , annot ] ~ string_arguments [ : " reference - build " , reference_build ; " configuration - name " , Tools . Bwa . Configuration . Mem . name configuration ; ] ~ json_arguments [ : " configuration " , Tools . Bwa . Configuration . Mem . to_json configuration ; ] in let of_input = function | ` Fastq fastq -> let fq = get_fastq ( AF . get_file fastq ) in bwa_mem_opt ( ` Fastq fq ) ( AF . get_provenance fastq ) | ` Fastq_gz fqz -> let fq = get_gz ( AF . get_file fqz ) |> get_fastq in bwa_mem_opt ( ` Fastq fq ) ( AF . get_provenance fqz ) | ` Bam ( b , p ) -> let bam = get_bam ( AF . get_file b ) in bwa_mem_opt ( ` Bam ( bam , ` PE ) ) ( AF . get_provenance b ) in of_input input let star ( ? configuration = Tools . Star . Configuration . Align . default ) = make_aligner " star " ~ configuration ~ config_name : Tools . Star . Configuration . Align . name ~ config_to_json : Tools . Star . Configuration . Align . to_json ~ make_workflow ( : fun ~ reference_build ~ configuration ~ result_prefix ~ run_with fastq -> Tools . Star . align ~ configuration ~ reference_build ~ fastq ~ result_prefix ~ run_with ( ) ) let hisat ( ? configuration = Tools . Hisat . Configuration . default_v1 ) = make_aligner " hisat " ~ configuration ~ config_name : Tools . Hisat . Configuration . name ~ config_to_json : Tools . Hisat . Configuration . to_json ~ make_workflow ( : fun ~ reference_build ~ configuration ~ result_prefix ~ run_with fastq -> Tools . Hisat . align ~ configuration ~ reference_build ~ fastq ~ result_prefix ~ run_with ( ) |> Tools . Samtools . sam_to_bam ~ reference_build ~ run_with ) let mosaik = make_aligner " mosaik " ~ configuration ( ) : ~ config_name ( : fun _ -> " default " ) ~ config_to_json ( : fun _ -> ` Assoc [ " name " , ` String " default " ] ) ~ make_workflow ( : fun ~ reference_build ~ configuration ~ result_prefix ~ run_with fastq -> Tools . Mosaik . align ~ reference_build ~ fastq ~ result_prefix ~ run_with ( ) ) let gunzip : Annotated_file . t -> Annotated_file . t = fun gz -> let inside = get_gz ( AF . get_file gz ) in begin match inside with | Fastq f -> let make_result_path read = let base = Filename . basename read in Config . work_dir // ( match base with | fastqgz when Filename . check_suffix base " . fastq . gz " -> Filename . chop_suffix base " . gz " | fqz when Filename . check_suffix base " . fqz " -> Filename . chop_suffix base " . fqz " ^ " . fastq " | other -> ksprintf failwith " To_workflow . gunzip : cannot recognize Gz - Fastq \ extension : % S " other ) in let gunzip read = let result_path = make_result_path read # product # path in Workflow_utilities . Gunzip . concat ~ run_with [ read ] ~ result_path in let fastq_r1 = gunzip ( KEDSL . read_1_file_node f ) in let fastq_r2 = Option . map ( KEDSL . read_2_file_node f ) ~ f : gunzip in Fastq ( KEDSL . fastq_node_of_single_file_nodes ~ host ~ name : f # product # sample_name ? fragment_id : f # product # fragment_id fastq_r1 fastq_r2 ) |> AF . with_provenance " gunzip " [ " fastq - gz " , AF . get_provenance gz ] | other -> ksprintf failwith " To_workflow . gunzip : non - FASTQ input not implemented " end let gunzip_concat gzl = ksprintf failwith " To_workflow . gunzip_concat : not implemented " let concat : Annotated_file . t -> Annotated_file . t = fun l -> begin match get_list ( AF . get_file l ) with | Fastq one :: [ ] -> Fastq one |> AF . with_provenance " concat " [ " single - element " , AF . get_provenance l ] | Fastq first_fastq :: _ as lfq -> let fqs = List . map lfq ~ f : get_fastq in let r1s = List . map fqs ~ f ( : KEDSL . read_1_file_node ) in let r2s = List . filter_map fqs ~ f : KEDSL . read_2_file_node in let concat_files ~ read l = let result_path = Name_file . in_directory Config . work_dir ~ readable_suffix ( : sprintf " % s - Read % d - Concat . fastq " first_fastq # product # escaped_sample_name read ) ( first_fastq # product # escaped_sample_name :: first_fastq # product # fragment_id_forced :: List . map l ~ f ( : fun wf -> wf # product # path ) ) in Workflow_utilities . Cat . concat ~ run_with l ~ result_path in let read_1 = concat_files r1s ~ read : 1 in let read_2 = match r2s with [ ] -> None | more -> Some ( concat_files more ~ read : 2 ) in Fastq ( KEDSL . fastq_node_of_single_file_nodes ~ host ~ name : first_fastq # product # sample_name ~ fragment_id " : edsl - concat " read_1 read_2 ) |> AF . with_provenance " concat " [ " fastq - list " , AF . get_provenance l ] | other -> ksprintf failwith " To_workflow . concat : not implemented " end let merge_bams ( ? delete_input_on_success = true ) ( ? attach_rg_tag = false ) ( ? uncompressed_bam_output = false ) ( ? compress_level_one = false ) ( ? combine_rg_headers = false ) ( ? combine_pg_headers = false ) bam_list = match AF . get_file bam_list with | List [ one_bam ] -> one_bam |> AF . with_provenance " merge - bams " [ " pass - through " , AF . get_provenance bam_list ] | List bam_files -> let bams = List . map bam_files ~ f : get_bam in let output_path = Name_file . in_directory ~ readable_suffix " : samtoolsmerge . bam " Config . work_dir ( List . map bams ~ f ( : fun bam -> bam # product # path ) ) in Bam ( Tools . Samtools . merge_bams ~ delete_input_on_success ~ attach_rg_tag ~ uncompressed_bam_output ~ compress_level_one ~ combine_rg_headers ~ combine_pg_headers ~ run_with bams output_path ) |> AF . with_provenance " merge - bams " [ " bam - list " , AF . get_provenance bam_list ] ~ string_arguments [ : " delete - input - on - success " , string_of_bool delete_input_on_success ; " attach - rg - tag " , string_of_bool attach_rg_tag ; " uncompressed - bam - output " , string_of_bool uncompressed_bam_output ; " compress - level - one " , string_of_bool compress_level_one ; " combine - rg - headers " , string_of_bool combine_rg_headers ; " combine - pg - headers " , string_of_bool combine_pg_headers ; ] | other -> fail_get other " To_workflow . merge_bams : not a list of bams " ? let stringtie ( ? configuration = Tools . Stringtie . Configuration . default ) bamt = let bam = get_bam ( AF . get_file bamt ) in let result_prefix = Name_file . from_path bam # product # path ~ readable_suffix " : stringtie " [ configuration . Tools . Stringtie . Configuration . name ; ] in Gtf ( Tools . Stringtie . run ~ configuration ~ bam ~ result_prefix ~ run_with ( ) ) |> AF . with_provenance " stringtie " [ " bam " , AF . get_provenance bamt ] ~ string_arguments [ " : configuration - name " , configuration . Tools . Stringtie . Configuration . name ] ~ json_arguments [ " : configuration " , Tools . Stringtie . Configuration . to_json configuration ] let indel_realigner_function : type a . configuration : _ -> a KEDSL . bam_or_bams -> a = fun ~ configuration on_what -> match Config . map_reduce_gatk_indel_realigner with | true -> Tools . Gatk . indel_realigner_map_reduce ~ run_with ~ compress : false ~ configuration on_what | false -> Tools . Gatk . indel_realigner ~ run_with ~ compress : false ~ configuration on_what let indel_realigner_provenance ~ configuration t_arguments product = let config_indel , config_target = configuration in AF . with_provenance " gatk - indel - realigner " t_arguments product ~ string_arguments [ : " indel - realigner - configuration - name " , config_indel . Tools . Gatk . Configuration . Indel_realigner . name ; " target - creator - configuration - name " , config_target . Tools . Gatk . Configuration . Realigner_target_creator . name ; ] ~ json_arguments [ : " indel - realigner - configuration " , Tools . Gatk . Configuration . Indel_realigner . to_json config_indel ; " target - creator - configuration " , Tools . Gatk . Configuration . Realigner_target_creator . to_json config_target ; ] let gatk_indel_realigner ( ? configuration = Tools . Gatk . Configuration . default_indel_realigner ) bam = let input_bam = get_bam ( AF . get_file bam ) in Bam ( indel_realigner_function ~ configuration ( KEDSL . Single_bam input_bam ) ) |> indel_realigner_provenance ~ configuration [ " bam " , AF . get_provenance bam ] let gatk_indel_realigner_joint ( ? configuration = Tools . Gatk . Configuration . default_indel_realigner ) bam_pair = let bam1 = ( AF . get_file bam_pair ) |> pair_fst |> get_bam in let bam2 = ( AF . get_file bam_pair ) |> pair_snd |> get_bam in let bam_list_node = indel_realigner_function ( KEDSL . Bam_workflow_list [ bam1 ; bam2 ] ) ~ configuration in begin match KEDSL . explode_bam_list_node bam_list_node with | [ realigned_normal ; realigned_tumor ] -> Pair ( Bam realigned_normal , Bam realigned_tumor ) |> indel_realigner_provenance ~ configuration [ " bam - pair " , AF . get_provenance bam_pair ] | other -> failf " Gatk . indel_realigner did not return the correct list \ of length 2 ( tumor , normal ) : it gave % d bams " ( List . length other ) end let picard_mark_duplicates ( ? configuration = Tools . Picard . Mark_duplicates_settings . default ) bam = let input_bam = get_bam ( AF . get_file bam ) in let output_bam = Name_file . from_path input_bam # product # path ~ readable_suffix " : mark_dups . bam " [ ] in Bam ( Tools . Picard . mark_duplicates ~ settings : configuration ~ run_with ~ input_bam output_bam ) |> AF . with_provenance " picard - mark - duplicates " [ " bam " , AF . get_provenance bam ] let picard_reorder_sam ? mem_param ? reference_build bam = let input_bam = get_bam ( AF . get_file bam ) in let reference_build_param = match reference_build with | None -> input_bam # product # reference_build | Some r -> r in let output_bam_path = Name_file . from_path input_bam # product # path ~ readable_suffix " : reorder_sam . bam " [ reference_build_param ] in Bam ( Tools . Picard . reorder_sam ? mem_param ? reference_build ~ run_with ~ input_bam output_bam_path ) |> AF . with_provenance " picard - reorder - sam " [ " bam " , AF . get_provenance bam ] ~ string_arguments [ " : reference - build " , reference_build_param ] let picard_clean_bam bam = let input_bam = get_bam ( AF . get_file bam ) in let output_bam_path = Name_file . from_path input_bam # product # path ~ readable_suffix " : cleaned . bam " [ ] in Bam ( Tools . Picard . clean_bam ~ run_with input_bam output_bam_path ) |> AF . with_provenance " picard - clean - bam " [ " bam " , AF . get_provenance bam ] let gatk_bqsr ( ? configuration = Tools . Gatk . Configuration . default_bqsr ) bam = let input_bam = get_bam ( AF . get_file bam ) in let output_bam = let ( bqsr , preads ) = configuration in Name_file . from_path input_bam # product # path ~ readable_suffix " : gatk_bqsr . bam " [ bqsr . Tools . Gatk . Configuration . Bqsr . name ; preads . Tools . Gatk . Configuration . Print_reads . name ; ] in let config_bqsr , config_print_reads = configuration in Bam ( Tools . Gatk . base_quality_score_recalibrator ~ configuration ~ run_with ~ input_bam ~ output_bam ) |> AF . with_provenance " gatk - bqsr " [ " bam " , AF . get_provenance bam ] ~ string_arguments [ : " bqsr - configuration - name " , config_bqsr . Tools . Gatk . Configuration . Bqsr . name ; " print - reads - configuration - name " , config_print_reads . Tools . Gatk . Configuration . Print_reads . name ; ] ~ json_arguments [ : " bqsr - configuration " , Tools . Gatk . Configuration . Bqsr . to_json config_bqsr ; " print - reads - configuration " , Tools . Gatk . Configuration . Print_reads . to_json config_print_reads ; ] let seqtk_shift_phred_scores fastq = let input_fastq = get_fastq ( AF . get_file fastq ) in let output_folder = Name_file . from_path input_fastq # product # sample_name ~ readable_suffix " : phred33 - fastq " [ " seqtk " ; ] in Fastq ( Tools . Seqtk . shift_phred_scores ~ run_with ~ output_postfix " . : fastq " ~ input_fastq ~ output_folder ( : Config . work_dir // output_folder ) ) |> AF . with_provenance " seqtk - shift - phred - scores " [ " fastq " , AF . get_provenance fastq ] let seq2hla fq = let fastq = get_fastq ( AF . get_file fq ) in let r1 = KEDSL . read_1_file_node fastq in let r2 = match KEDSL . read_2_file_node fastq with | Some r -> r | None -> failf " Seq2HLA doesn ' t support Single_end_sample ( s ) . " in let work_dir = Name_file . in_directory Config . work_dir ~ readable_suffix " : seq2hla - workdir " [ fastq # product # escaped_sample_name ; fastq # product # fragment_id_forced ; ] in Seq2hla_result ( Tools . Seq2HLA . hla_type ~ work_dir ~ run_with ~ run_name : fastq # product # escaped_sample_name ~ r1 ~ r2 ) |> AF . with_provenance " seq2hla " [ " fastq " , AF . get_provenance fq ] let hlarp input = let out o = Name_file . from_path o ~ readable_suffix " : hlarp . csv " [ ] in let hlarp = Tools . Hlarp . run ~ run_with in let hla_result , output_path , prov_argument = match input with | ` Seq2hla v -> let r = get_seq2hla_result ( AF . get_file v ) in ` Seq2hla r , out r # product # work_dir_path , ( " seq2hla " , AF . get_provenance v ) | ` Optitype v -> let r = get_optitype_result ( AF . get_file v ) in ` Optitype r , out r # product # path , ( " optitype " , AF . get_provenance v ) in let res = hlarp ~ hla_result ~ output_path in MHC_alleles res |> AF . with_provenance " hlarp " [ prov_argument ] let filter_to_region vcf bed = let vcff = get_vcf ( AF . get_file vcf ) in let bedf = get_bed ( AF . get_file bed ) in let output = Name_file . from_path vcff # product # path ~ readable_suffix " : _intersect . vcf " [ Filename . basename bedf # product # path |> Filename . chop_extension ] in Vcf ( Tools . Bedtools . intersect ~ primary : vcff ~ intersect_with [ : bedf ] ~ run_with output ) |> AF . with_provenance " filter - to - region " [ " vcf " , AF . get_provenance vcf ; " bed " , AF . get_provenance bed ] let bam_left_align ~ reference_build bamf = let bam = get_bam ( AF . get_file bamf ) in let output = Name_file . from_path bam # product # path ~ readable_suffix " : _left - aligned . bam " [ Filename . basename bam # product # path ] in Bam ( Tools . Freebayes . bam_left_align ~ reference_build ~ bam ~ run_with output ) |> AF . with_provenance " bam - left - align " [ " bam " , AF . get_provenance bamf ] ~ string_arguments [ " : reference - build " , reference_build ] let sambamba_filter ~ filter bami = let bam = get_bam ( AF . get_file bami ) in let output = Name_file . from_path bam # product # path ~ readable_suffix " : _filtered . bam " [ Filename . basename bam # product # path ; Tools . Sambamba . Filter . to_string filter ] in Bam ( Tools . Sambamba . view ~ bam ~ run_with ~ filter output ) |> AF . with_provenance " sambamba - filter " [ " bam " , AF . get_provenance bami ] ~ json_arguments [ " : filter " , ( filter :> Yojson . Basic . json ) ] let fastqc fq = let fastq = get_fastq ( AF . get_file fq ) in let output_folder = Name_file . in_directory ~ readable_suffix " : fastqc_result " Config . work_dir [ fastq # product # escaped_sample_name ; fastq # product # fragment_id_forced ; ] in Fastqc_result ( Tools . Fastqc . run ~ run_with ~ fastq ~ output_folder ) |> AF . with_provenance " fastqc " [ " fastq " , AF . get_provenance fq ] let flagstat bami = let bam = get_bam ( AF . get_file bami ) in Flagstat_result ( Tools . Samtools . flagstat ~ run_with bam ) |> AF . with_provenance " flagstat " [ " bam " , AF . get_provenance bami ] let vcf_annotate_polyphen vcf = let v = get_vcf ( AF . get_file vcf ) in let output_vcf = ( Filename . chop_extension v # product # path ) ^ " _polyphen . vcf " in let reference_build = v # product # reference_build in Vcf ( Tools . Vcfannotatepolyphen . run ~ run_with ~ reference_build ~ vcf : v ~ output_vcf ) |> AF . with_provenance " vcf - annotate - polyphen " [ " vcf " , AF . get_provenance vcf ] let snpeff vcf = let open KEDSL in let v = get_vcf ( AF . get_file vcf ) in let reference_build = v # product # reference_build in let out_folder = Name_file . in_directory ~ readable_suffix " : snpeff " Config . work_dir [ Filename . basename v # product # path ; reference_build ; ] in let snpeff_run = Tools . Snpeff . annotate ~ run_with ~ reference_build ~ input_vcf : v ~ out_folder in Vcf ( workflow_node ( transform_vcf v # product ~ path ( : snpeff_run # product # path ) ) ~ name ( : sprintf " Fetch annotated VCF : % s " v # render # name ) ~ edges [ : depends_on snpeff_run ; ] ) |> AF . with_provenance " snpeff " [ " vcf " , AF . get_provenance vcf ] let isovar ( ? configuration = Tools . Isovar . Configuration . default ) vcf bam = let v = get_vcf ( AF . get_file vcf ) in let b = get_bam ( AF . get_file bam ) in let reference_build = if v # product # reference_build = b # product # reference_build then v # product # reference_build else ksprintf failwith " VCF and Bam do not agree on their reference build : \ bam : % s Vs vcf : % s " b # product # reference_build v # product # reference_build in let output_file = Name_file . in_directory ~ readable_suffix " : isovar . csv " Config . work_dir [ Tools . Isovar . Configuration . name configuration ; reference_build ; ( Filename . chop_extension ( Filename . basename v # product # path ) ) ; ( Filename . chop_extension ( Filename . basename b # product # path ) ) ; ] in Isovar_result ( Tools . Isovar . run ~ configuration ~ run_with ~ reference_build ~ vcf : v ~ bam : b ~ output_file ) |> AF . with_provenance " isovar " [ " vcf " , AF . get_provenance vcf ; " bam " , AF . get_provenance bam ] ~ string_arguments [ : " reference - build " , reference_build ; " configuration - name " , Tools . Isovar . Configuration . name configuration ; ] ~ json_arguments [ : " configuration " , Tools . Isovar . Configuration . to_json configuration ; ] let topiary ( ? configuration = Tools . Topiary . Configuration . default ) vcfs predictor alleles = let vs = List . map ~ f ( : fun x -> AF . get_file x |> get_vcf ) vcfs in let refs = vs |> List . map ~ f ( : fun v -> v # product # reference_build ) |> List . dedup in let reference_build = if List . length refs > 1 then ksprintf failwith " VCFs do not agree on their reference build : % s " ( String . concat ~ sep " , : " refs ) else List . nth_exn refs 0 in let mhc = get_mhc_alleles ( AF . get_file alleles ) in let output_file = Name_file . in_directory ~ readable_suffix " : topiary . tsv " Config . work_dir ( [ Hla_utilities . predictor_to_string predictor ; Tools . Topiary . Configuration . name configuration ; Filename . chop_extension ( Filename . basename mhc # product # path ) ; ] @ ( List . map vs ~ f ( : fun v -> v # product # path ) ) ) in Topiary_result ( Tools . Topiary . run ~ configuration ~ run_with ~ reference_build ~ vcfs : vs ~ predictor ~ alleles_file : mhc ~ output ( ` : CSV output_file ) ) |> AF . with_provenance " topiary " ( ( " alleles " , AF . get_provenance alleles ) :: List . mapi vcfs ~ f ( : fun i v -> sprintf " vcf_ % d " i , AF . get_provenance v ) ) ~ string_arguments [ : " predictor " , Hla_utilities . predictor_to_string predictor ; " configuration - name " , Tools . Topiary . Configuration . name configuration ; ] ~ json_arguments [ : " configuration " , Tools . Topiary . Configuration . to_json configuration ; ] let vaxrank ( ? configuration = Tools . Vaxrank . Configuration . default ) vcfs bam predictor alleles = let vs = List . map ~ f ( : fun x -> AF . get_file x |> get_vcf ) vcfs in let b = get_bam ( AF . get_file bam ) in let reference_build = if List . exists vs ~ f ( : fun v -> v # product # reference_build <> b # product # reference_build ) then ksprintf failwith " VCFs and Bam do not agree on their reference build : \ bam : % s Vs vcfs : % s " b # product # reference_build ( List . map vs ~ f ( : fun v -> v # product # reference_build ) |> String . concat ~ sep " , : " ) else b # product # reference_build in let mhc = get_mhc_alleles ( AF . get_file alleles ) in let outdir = Name_file . in_directory ~ readable_suffix " : vaxrank " Config . work_dir ( [ Tools . Vaxrank . Configuration . name configuration ; Hla_utilities . predictor_to_string predictor ; ( Filename . chop_extension ( Filename . basename mhc # product # path ) ) ; ] @ ( List . map vs ~ f ( : fun v -> ( Filename . chop_extension ( Filename . basename v # product # path ) ) ) ) ) in Vaxrank_result ( Tools . Vaxrank . run ~ configuration ~ run_with ~ reference_build ~ vcfs : vs ~ bam : b ~ predictor ~ alleles_file : mhc ~ output_folder : outdir ) |> AF . with_provenance " vaxrank " ( ( " alleles " , AF . get_provenance alleles ) :: ( " bam " , AF . get_provenance bam ) :: List . mapi vcfs ~ f ( : fun i v -> sprintf " vcf_ % d " i , AF . get_provenance v ) ) ~ string_arguments [ : " predictor " , Hla_utilities . predictor_to_string predictor ; " configuration - name " , Tools . Vaxrank . Configuration . name configuration ; ] ~ json_arguments [ : " configuration " , Tools . Vaxrank . Configuration . to_json configuration ; ] let optitype how fq = let fastq = get_fastq ( AF . get_file fq ) in let intput_type = match how with ` RNA -> " RNA " | ` DNA -> " DNA " in let work_dir = Name_file . in_directory Config . work_dir ~ readable_suffix " : optitype . d " [ fastq # product # escaped_sample_name ; intput_type ; fastq # product # fragment_id_forced ; ] in let run_name = fastq # product # escaped_sample_name in Optitype_result ( match how with | ` DNA -> Tools . Optitype . dna_hla_type_with_bwamem ~ configuration : Tools . Bwa . Configuration . Mem . default ~ work_dir ~ run_with ~ fastq ~ run_name | ` RNA -> Tools . Optitype . hla_type ~ work_dir ~ run_with ~ fastq ~ run_name ` RNA ) |> AF . with_provenance " optitype " [ " fastq " , AF . get_provenance fq ] ~ string_arguments [ " : input - type " , intput_type ] let gatk_haplotype_caller bam = let input_bam = get_bam ( AF . get_file bam ) in let result_prefix = Filename . chop_extension input_bam # product # path ^ sprintf " _gatkhaplo " in Vcf ( Tools . Gatk . haplotype_caller ~ run_with ~ input_bam ~ result_prefix ` Map_reduce ) |> AF . with_provenance " gatk - haplotype - caller " [ " bam " , AF . get_provenance bam ] let bam_to_fastq ? fragment_id how bam = let input_bam = get_bam ( AF . get_file bam ) in let sample_type = match how with ` SE -> ` Single_end | ` PE -> ` Paired_end in let sample_type_str = match how with ` PE -> " PE " | ` SE -> " SE " in let output_prefix = Config . work_dir // sprintf " % s - b2fq -% s " Filename . ( chop_extension ( basename input_bam # product # path ) ) sample_type_str in Fastq ( Tools . Picard . bam_to_fastq ~ run_with ~ sample_type ~ output_prefix input_bam ) |> AF . with_provenance " bam - to - fastq " [ " bam " , AF . get_provenance bam ] ~ string_arguments ( ( " : sample - type " , sample_type_str ) :: Option . value_map ~ default [ ] : fragment_id ~ f ( : fun fi -> [ " fragment - id " , fi ] ) ) let somatic_vc name confname confjson default_conf runfun ? configuration ~ normal ~ tumor ( ) = let normal_bam = get_bam ( AF . get_file normal ) in let tumor_bam = get_bam ( AF . get_file tumor ) in let configuration = Option . value configuration ~ default : default_conf in let result_prefix = Name_file . from_path tumor_bam # product # path ~ readable_suffix ( : sprintf " _ % s -% s " name ( confname configuration ) ) [ normal_bam # product # path |> Filename . basename |> Filename . chop_extension ; ] in Vcf ( runfun ~ configuration ~ run_with ~ normal : normal_bam ~ tumor : tumor_bam ~ result_prefix ) |> AF . with_provenance name [ " normal " , AF . get_provenance normal ; " tumor " , AF . get_provenance tumor ] ~ string_arguments [ : " configuration - name " , confname configuration ; ] ~ json_arguments [ : " configuration " , confjson configuration ; ] let mutect = somatic_vc " mutect " Tools . Mutect . Configuration . name Tools . Mutect . Configuration . to_json Tools . Mutect . Configuration . default ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Mutect . run ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix ` Map_reduce ) let mutect2 = somatic_vc " mutect2 " Tools . Gatk . Configuration . Mutect2 . name Tools . Gatk . Configuration . Mutect2 . to_json Tools . Gatk . Configuration . Mutect2 . default ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Gatk . mutect2 ~ configuration ~ run_with ~ input_normal_bam : normal ~ input_tumor_bam : tumor ~ result_prefix ` Map_reduce ) let somaticsniper = somatic_vc " somaticsniper " Tools . Somaticsniper . Configuration . name Tools . Somaticsniper . Configuration . to_json Tools . Somaticsniper . Configuration . default ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Somaticsniper . run ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix ( ) ) let strelka = somatic_vc " strelka " Tools . Strelka . Configuration . name Tools . Strelka . Configuration . to_json Tools . Strelka . Configuration . default ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Strelka . run ~ configuration ~ normal ~ tumor ~ run_with ~ result_prefix ( ) ) let varscan_somatic ? adjust_mapq = somatic_vc " varscan_somatic " ( fun ( ) -> sprintf " Amq % s " ( Option . value_map adjust_mapq ~ default " : N " ~ f : Int . to_string ) ) ( fun ( ) -> ` Assoc [ " adjust - mapq " , Option . value_map adjust_mapq ~ default ( ` : String " None " ) ~ f ( : fun i -> ` Int i ) ] ) ( ) ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Varscan . somatic_map_reduce ? adjust_mapq ~ run_with ~ normal ~ tumor ~ result_prefix ( ) ) ~ configuration ( ) : let muse = somatic_vc " muse " Tools . Muse . Configuration . name Tools . Muse . Configuration . to_json ( Tools . Muse . Configuration . default ` WGS ) ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Muse . run ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix ` Map_reduce ) let virmid = somatic_vc " virmid " Tools . Virmid . Configuration . name Tools . Virmid . Configuration . to_json Tools . Virmid . Configuration . default ( fun ~ configuration ~ run_with ~ normal ~ tumor ~ result_prefix -> Tools . Virmid . run ~ configuration ~ normal ~ tumor ~ run_with ~ result_prefix ( ) ) end
|
module Id = struct type t = int64 let t = Irmin . Type . int64 let to_string : t -> string = Fmt . to_to_string ( Irmin . Type . pp_json t ) let compare = Int64 . compare let of_int = Int64 . of_int let random ? x y = let x = match x with | Some x -> Int64 . of_int x | None -> 0L in let y = Int64 . of_int y in Int64 . add ( Random . int64 ( Int64 . sub y x ) ) x end
|
type item_req = { _ol_num : int32 ; _ol_i_id : id ; _ol_supply_w_id : id ; _ol_qty : int32 }
|
let counter_merge lca v1 v2 = let ( ) + a b = Int32 . add a b in let ( ) - a b = Int32 . sub a b in lca + ( v1 - lca ) + ( v2 - lca )
|
let minf f l = List . fold_left ( fun acc x -> match acc with | None -> Some x | Some x ' -> if Int64 . compare ( f x ) ( f x ' ) < 0 then Some x else acc ) None l
|
module Warehouse = struct type t = { w_id : id ; w_ytd : int32 } let merge ~ ancestor : lca { w_ytd = y1 } { w_ytd = y2 } = { lca with w_ytd = ( counter_merge lca . w_ytd y1 y2 ) } end
|
module District = struct type t = { d_w_id : id ; d_id : id ; d_ytd : int32 ; } let merge ~ ancestor : lca { d_ytd = y1 } { d_ytd = y2 } = { lca with d_ytd = counter_merge lca . d_ytd y1 y2 } end
|
module Order = struct type t = { o_w_id : id ; o_d_id : id ; o_id : id ; o_c_id : id ; o_ol_cnt : int32 ; o_carrier_id : bool } let merge ~ ancestor : lca ( { o_carrier_id = b1 } as v1 ) ( { o_carrier_id = b2 } as v2 ) = if lca . o_carrier_id = true then ( assert ( lca = v1 && v1 = v2 ) ; lca ) else { lca with o_carrier_id = b1 || b2 } end
|
module NewOrder = struct type t = { no_w_id : id ; no_d_id : id ; no_o_id : id } let merge ~ ancestor : lca v1 v2 = failwith " new_order is immutable " end
|
module OrderLine = struct type t = { ol_w_id : id ; ol_d_id : id ; ol_o_id : id ; ol_i_id : id ; ol_num : int32 ; ol_supply_w_id : id ; ol_amt : int32 ; ol_qty : int32 ; ol_delivery_d : float option } let merge ~ ancestor : lca { ol_delivery_d = d1 } { ol_delivery_d = d2 } = let d = match d1 , d2 with | None , None -> None | Some d1 , None -> Some d1 | None , Some d2 -> Some d2 | Some d1 , Some d2 -> Some ( min d1 d2 ) in { lca with ol_delivery_d = d } end
|
module Item = struct type t = { i_id : id ; i_name : string ; i_price : int32 } let merge ~ ancestor v1 v2 = failwith " Item is immutable " end
|
module Hist = struct type t = { h_c_id : id ; h_c_d_id : id ; h_c_w_id : id ; h_d_id : id ; h_w_id : id ; h_amt : int32 } let merge ~ ancestor v1 v2 = failwith " Hist is immutable " end
|
module Stock = struct type t = { s_w_id : id ; s_i_id : id ; s_qty : int32 ; s_ytd : int32 ; s_order_cnt : int32 } let merge ~ ancestor { : s_i_id ; s_w_id ; s_qty = q ; s_ytd = y ; s_order_cnt = c } { s_qty = q1 ; s_ytd = y1 ; s_order_cnt = c1 } { s_qty = q2 ; s_ytd = y2 ; s_order_cnt = c2 } = let q ' = counter_merge q q1 q2 in let y ' = counter_merge y y1 y2 in let c ' = counter_merge c c1 c2 in { s_i_id ; s_w_id ; s_qty = q ' ; s_ytd = y ' ; s_order_cnt = c ' } end
|
module Customer = struct type t = { c_w_id : id ; c_d_id : id ; c_id : id ; c_bal : int32 ; c_ytd_payment : int32 ; c_payment_cnt : int32 ; c_delivery_cnt : int32 ; } let merge ~ ancestor { : c_id ; c_d_id ; c_w_id ; c_bal = b ; c_ytd_payment = y ; c_payment_cnt = p ; c_delivery_cnt = d } { c_bal = b1 ; c_ytd_payment = y1 ; c_payment_cnt = p1 ; c_delivery_cnt = d1 } { c_bal = b2 ; c_ytd_payment = y2 ; c_payment_cnt = p2 ; c_delivery_cnt = d2 } = let b ' = counter_merge b b1 b2 in let y ' = counter_merge y y1 y2 in let p ' = counter_merge p p1 p2 in let d ' = counter_merge d d1 d2 in { c_id ; c_d_id ; c_w_id ; c_bal = b ' ; c_ytd_payment = y ' ; c_payment_cnt = p ' ; c_delivery_cnt = d ' } end
|
module IdPair = struct type t = id * id let t = let open Irmin . Type in pair id id let to_string : t -> string = Fmt . to_to_string ( Irmin . Type . pp_json t ) let compare ( x1 , y1 ) ( x2 , y2 ) = match Id . compare x1 x2 , Id . compare y1 y2 with | 0 , v2 -> v2 | v1 , _ -> v1 end
|
module IdTriple = struct type t = id ( * id * id ) let t = let open Irmin . Type in pair id ( pair id id ) let to_string : t -> string = Fmt . to_to_string ( Irmin . Type . pp_json t ) let compare ( x1 , ( y1 , z1 ) ) ( x2 , ( y2 , z2 ) ) = match Id . compare x1 x2 , Id . compare y1 y2 , Id . compare z1 z2 with | 0 , 0 , v3 -> v3 | 0 , v2 , _ -> v2 | v1 , _ , _ -> v1 end
|
module IdQuad = struct type t = id ( * id ( * id * id ) ) let t = let open Irmin . Type in pair id ( pair id ( pair id id ) ) let to_string : t -> string = Fmt . to_to_string ( Irmin . Type . pp_json t ) let compare ( w1 , ( x1 , ( y1 , z1 ) ) ) ( w2 , ( x2 , ( y2 , z2 ) ) ) = match Id . compare w1 w2 , Id . compare x1 x2 , Id . compare y1 y2 , Id . compare z1 z2 with | 0 , 0 , 0 , v4 -> v4 | 0 , 0 , v3 , _ -> v3 | 0 , v2 , _ , _ -> v2 | v1 , _ , _ , _ -> v1 end
|
module IdQuin = struct type t = id ( * id ( * id ( * id * id ) ) ) let t = let open Irmin . Type in ( pair id ( pair id ( pair id ( pair id id ) ) ) ) let to_string : t -> string = Fmt . to_to_string ( Irmin . Type . pp_json t ) let compare ( u1 , ( w1 , ( x1 , ( y1 , z1 ) ) ) ) ( u2 , ( w2 , ( x2 , ( y2 , z2 ) ) ) ) = match Id . compare u1 u2 , Id . compare w1 w2 , Id . compare x1 x2 , Id . compare y1 y2 , Id . compare z1 z2 with | 0 , 0 , 0 , 0 , v5 -> v5 | 0 , 0 , 0 , v4 , _ -> v4 | 0 , 0 , v3 , _ , _ -> v3 | 0 , v2 , _ , _ , _ -> v2 | v1 , _ , _ , _ , _ -> v1 end
|
type db = { warehouse_table : WarehouseTable . t ; district_table : DistrictTable . t ; order_table : OrderTable . t ; neworder_table : NewOrderTable . t ; orderline_table : OrderLineTable . t ; item_table : ItemTable . t ; hist_table : HistTable . t ; stock_table : StockTable . t ; customer_table : CustomerTable . t }
|
module Txn = struct type ' a t = db -> ' a * db let bind m f = fun db -> let ( a , db ' ) = m db in f a db ' let return a = fun db -> ( a , db ) end
|
module Insert = struct let order_table o db = let open Order in let t = db . order_table in let t ' = OrderTable . insert ( o . o_w_id , ( o . o_d_id , o . o_id ) ) o t in ( ( ) , { db with order_table = t ' } ) let neworder_table no db = let open NewOrder in let t = db . neworder_table in let t ' = NewOrderTable . insert ( no . no_w_id , ( no . no_d_id , no . no_o_id ) ) no t in ( ( ) , { db with neworder_table = t ' } ) let orderline_table r db = let open OrderLine in let t = db . orderline_table in let t ' = OrderLineTable . insert ( r . ol_w_id , ( r . ol_d_id , ( r . ol_o_id , r . ol_i_id ) ) ) r t in ( ( ) , { db with orderline_table = t ' } ) let hist_table r db = let open Hist in let t = db . hist_table in let t ' = HistTable . insert ( r . h_w_id , ( r . h_d_id , ( r . h_c_w_id , ( r . h_c_d_id , r . h_c_id ) ) ) ) r t in ( ( ) , { db with hist_table = t ' } ) let item_table o db = let open Item in let t = db . item_table in let t ' = ItemTable . insert ( o . i_id ) o t in ( ( ) , { db with item_table = t ' } ) let warehouse_table o db = let open Warehouse in let t = db . warehouse_table in let t ' = WarehouseTable . insert ( o . w_id ) o t in ( ( ) , { db with warehouse_table = t ' } ) let district_table o db = let open District in let t = db . district_table in let t ' = DistrictTable . insert ( o . d_w_id , o . d_id ) o t in ( ( ) , { db with district_table = t ' } ) let customer_table o db = let open Customer in let t = db . customer_table in let t ' = CustomerTable . insert ( o . c_w_id , ( o . c_d_id , o . c_id ) ) o t in ( ( ) , { db with customer_table = t ' } ) let stock_table o db = let open Stock in let t = db . stock_table in let t ' = StockTable . insert ( o . s_w_id , o . s_i_id ) o t in ( ( ) , { db with stock_table = t ' } ) end
|
module Update = struct let warehouse_table sigf updf db = let t = db . warehouse_table in let t ' = WarehouseTable . update sigf updf t in ( ( ) , { db with warehouse_table = t ' } ) let district_table sigf updf db = let t = db . district_table in let t ' = DistrictTable . update sigf updf t in ( ( ) , { db with district_table = t ' } ) let order_table sigf updf db = let t = db . order_table in let t ' = OrderTable . update sigf updf t in ( ( ) , { db with order_table = t ' } ) let orderline_table sigf updf db = let t = db . orderline_table in let t ' = OrderLineTable . update sigf updf t in ( ( ) , { db with orderline_table = t ' } ) let stock_table sigf updf db = let t = db . stock_table in let t ' = StockTable . update sigf updf t in ( ( ) , { db with stock_table = t ' } ) let customer_table sigf updf db = let t = db . customer_table in let t ' = CustomerTable . update sigf updf t in ( ( ) , { db with customer_table = t ' } ) end
|
module Delete = struct let neworder_table ( no_w_id , no_d_id , no_o_id ) db = let t = db . neworder_table in let t ' = NewOrderTable . remove ( no_w_id , ( no_d_id , no_o_id ) ) t in ( ( ) , { db with neworder_table = t ' } ) end
|
module Select1 = struct open Printf let warehouse_table x db = try let t = db . warehouse_table in let res = WarehouseTable . find x t in ( res , db ) with Not_found -> failwith @@ sprintf " Warehouse <% s > not found " ( Id . to_string x ) let district_table ( x , y ) db = try let t = db . district_table in let res = DistrictTable . find ( x , y ) t in ( res , db ) with Not_found -> failwith @@ sprintf " District <% s > not found " ( IdPair . to_string ( x , y ) ) let item_table x db = try let t = db . item_table in let res = ItemTable . find x t in ( res , db ) with Not_found -> failwith @@ sprintf " Item <% s > not found " ( Id . to_string x ) let order_table ( x , y , z ) db = try let t = db . order_table in let res = OrderTable . find ( x , ( y , z ) ) t in ( res , db ) with Not_found -> failwith @@ sprintf " Order <% s > not found " ( IdTriple . to_string ( x , ( y , z ) ) ) let stock_table ( x , y ) db = try let t = db . stock_table in let res = StockTable . find ( x , y ) t in ( res , db ) with Not_found -> failwith @@ sprintf " Stock <% s > not found " ( IdPair . to_string ( x , y ) ) let customer_table ( x , y , z ) db = try let t = db . customer_table in let res = CustomerTable . find ( x , ( y , z ) ) t in ( res , db ) with Not_found -> failwith @@ sprintf " Customer <% s > not found " ( IdTriple . to_string ( x , ( y , z ) ) ) end
|
module Select = struct let warehouse_table sigf db = let t = db . warehouse_table in let res = WarehouseTable . select sigf t in ( res , db ) let district_table sigf db = let t = db . district_table in let res = DistrictTable . select sigf t in ( res , db ) let item_table sigf db = let t = db . item_table in let res = ItemTable . select sigf t in ( res , db ) let order_table sigf db = let t = db . order_table in let res = OrderTable . select sigf t in ( res , db ) let orderline_table sigf db = let t = db . orderline_table in let res = OrderLineTable . select sigf t in ( res , db ) let neworder_table sigf db = let t = db . neworder_table in let res = NewOrderTable . select sigf t in ( res , db ) let stock_table sigf db = let t = db . stock_table in let res = StockTable . select sigf t in ( res , db ) let customer_table sigf db = let t = db . customer_table in let res = CustomerTable . select sigf t in ( res , db ) let hist_table sigf db = let t = db . hist_table in let res = HistTable . select sigf t in ( res , db ) end
|
module Temp = struct let ( ) + = Int32 . add let ( ) - = Int32 . sub let ( * ) = Int32 . mul let ( ) >>= = Txn . bind end
|
let dump_stock_keys db = let fp = open_out " stock_keys . db " in let dump2 k v = fprintf fp " % s \ n " @@ IdPair . to_string k in begin fprintf fp " \ n > Stock \ n " ; StockTable . iter dump2 db . stock_table ; close_out fp ; printf " Dumped keys in stock_keys . db \ n " ; ( ( ) , db ) end
|
let new_order_txn w_id d_id c_id ( ireqs : item_req list ) : unit Txn . t = let _ = printf " new_order_txn \ n " in let _ = flush_all ( ) in let o_id = Random . int64 10000000000L in let ord = let open Order in { o_id = o_id ; o_w_id = w_id ; o_d_id = d_id ; o_c_id = c_id ; o_ol_cnt = Int32 . of_int @@ List . length ireqs ; o_carrier_id = false } in let new_ord = let open NewOrder in { no_o_id = o_id ; no_w_id = w_id ; no_d_id = d_id } in Insert . order_table ord >>= fun _ -> Insert . neworder_table new_ord >>= fun _ -> List . fold_left ( fun pre ireq -> pre >>= fun ( ) -> Select1 . stock_table ( ireq . _ol_supply_w_id , ireq . _ol_i_id ) >>= fun stk -> Select1 . item_table ireq . _ol_i_id >>= fun item -> let ol = { ol_o_id = o_id ; ol_d_id = d_id ; ol_w_id = w_id ; ol_num = ireq . _ol_num ; ol_i_id = ireq . _ol_i_id ; ol_supply_w_id = ireq . _ol_supply_w_id ; ol_amt = item . i_price * ireq . _ol_qty ; ol_qty = ireq . _ol_qty ; ol_delivery_d = None } in let s_qty = if Int32 . compare stk . s_qty ( ireq . _ol_qty + 10l ) >= 0 then stk . s_qty - ireq . _ol_qty else stk . s_qty - ireq . _ol_qty + 91l in Update . stock_table ( fun stock_key -> IdPair . compare stock_key ( ireq . _ol_supply_w_id , ireq . _ol_i_id ) ) ( fun s -> { s with s_qty = s_qty ; s_ytd = stk . s_ytd + ireq . _ol_qty ; s_order_cnt = stk . s_order_cnt + 1l } ) >>= fun ( ) -> Insert . orderline_table ol ) ( Txn . return ( ) ) ireqs
|
let payment_txn w_id d_id c_id h_amt = let _ = printf " payment_txn \ n " in let _ = flush_all ( ) in let d_w_id = w_id in let c_w_id = w_id in let c_d_id = d_id in Select1 . warehouse_table ( w_id ) >>= fun w -> Select1 . district_table ( d_w_id , d_id ) >>= fun d -> Select1 . customer_table ( c_w_id , c_d_id , c_id ) >>= fun c -> let h_item = { h_c_id = c_id ; h_c_d_id = c_d_id ; h_c_w_id = c_w_id ; h_d_id = d_id ; h_w_id = w_id ; h_amt = h_amt } in Update . warehouse_table ( fun wh_id -> Id . compare wh_id w_id ) ( fun wh -> { wh with w_ytd = wh . w_ytd + h_amt } ) >>= fun ( ) -> Update . district_table ( fun dist_key -> IdPair . compare dist_key ( d_w_id , d_id ) ) ( fun dist -> { dist with d_ytd = dist . d_ytd + h_amt } ) >>= fun ( ) -> Update . customer_table ( fun ckey -> IdTriple . compare ckey ( c_w_id , ( c_d_id , c_id ) ) ) ( fun c -> { c with c_bal = c . c_bal - h_amt ; c_ytd_payment = c . c_ytd_payment + h_amt ; c_payment_cnt = c . c_payment_cnt + 1l } ) >>= fun ( ) -> Insert . hist_table h_item
|
let delivery_txn w_id = let _ = printf " delivery_txn \ n " in let _ = flush_all ( ) in Select . district_table ( fun ( dist_w_id , _ ) -> Id . compare dist_w_id w_id ) >>= fun dists -> List . fold_left ( fun pre d -> pre >>= fun ( ) -> Select . neworder_table ( fun ( no_w_id , ( no_d_id , _ ) ) -> IdPair . compare ( no_w_id , no_d_id ) ( w_id , d . d_id ) ) >>= fun nords -> let nop = minf ( fun no -> no . no_o_id ) nords in match nop with | Some no -> begin Delete . neworder_table ( no . no_w_id , no . no_d_id , no . no_o_id ) >>= fun ( ) -> Select1 . order_table ( w_id , d . d_id , no . no_o_id ) >>= fun o -> Update . order_table ( fun okey -> IdTriple . compare okey ( w_id , ( d . d_id , no . no_o_id ) ) ) ( fun o -> { o with o_carrier_id = true } ) >>= fun ( ) -> Update . orderline_table ( fun ( k_w_id , ( k_d_id , ( k_o_id , _ ) ) ) -> IdTriple . compare ( k_w_id , ( k_d_id , k_o_id ) ) ( o . o_w_id , ( o . o_d_id , o . o_id ) ) ) ( fun ol -> { ol with ol_delivery_d = Some ( Unix . time ( ) ) } ) >>= fun ( ) -> Select . orderline_table ( fun ( k_w_id , ( k_d_id , ( k_o_id , _ ) ) ) -> IdTriple . compare ( k_w_id , ( k_d_id , k_o_id ) ) ( o . o_w_id , ( o . o_d_id , o . o_id ) ) ) >>= fun ols -> let amt = List . fold_left ( fun acc ol -> acc + ol . ol_amt ) 0l ols in Update . customer_table ( fun ckey -> IdTriple . compare ckey ( w_id , ( d . d_id , o . o_c_id ) ) ) ( fun c -> { c with c_bal = c . c_bal + amt ; c_delivery_cnt = c . c_delivery_cnt + 1l } ) end | None -> Txn . return ( ) ) ( Txn . return ( ) ) dists
|
let init ( ) = match Sys . getenv_opt " OCAMLI2PARAM " with Some " rules " -> Eval . showrules := true | _ -> ( )
|
let rec to_ocaml_heap_value expr = match expr . e with Value x -> x | ArrayExpr arr -> let x = Obj . new_block 0 ( Array . length arr ) in for i = 0 to Array . length arr - 1 do Obj . set_field x i ( to_ocaml_heap_value arr . ( i ) ) done ; x | Cons ( { e = Value h } , t ) -> let cell = Obj . new_block 0 2 in Obj . set_field cell 0 h ; Obj . set_field cell 1 ( to_ocaml_heap_value t ) ; cell | Function _ -> Eval . make_native expr . lets expr | _ -> failwith " to_ocaml_heap_value : unknown "
|
let eval_full env x = let program = ( Marshal . from_string x 0 : Type . t ) in match Eval . eval_full ! env program with { Type . e = Type . Value x } -> x | x -> to_ocaml_heap_value x
|
let eval_full_from_typedtree env x = let typedtree = ( Marshal . from_string x 0 : Typedtree . expression ) in let program = Read . finaltype_of_expression ! env typedtree in match Eval . eval_full ! env program with { Type . e = Type . Value x } -> x | x -> to_ocaml_heap_value x
|
let addenv envref printas n v t = let binding = { Type . e = Type . Value v ; Type . typ = Read . debug_type ( Read . remove_links ( Marshal . from_string t 0 : Types . type_expr ) ) ; Type . lets = [ ] ; Type . peek = None ; Type . printbefore = None ; Type . printafter = None ; Type . printas = printas } in envref := ( false , ref [ ( n , binding ) ] ) ::! envref
|
let eval_full_function : expression option ref = ref None
|
let template_string : expression option ref = ref None
|
let last_global_type : Types . type_expr option ref = ref None
|
let newmapper argv = { default with expr = ( fun mapper expr -> match expr with | { exp_attributes = [ { attr_name = { txt = " interpret " } ; attr_payload = payload } ] ; exp_type ; exp_desc } -> print_endline " Found a [ @ interpret ] annotation \ n " ; let tinyocaml_expression = match ! template_string with None -> failwith " no template string " | Some x -> { x with exp_desc = Texp_constant ( Const_string ( Marshal . to_string ( ( Read . finaltype_of_expression [ ] expr ) ) [ ] , None ) ) } in let exp_desc ' = let eval_full = match ! eval_full_function with None -> failwith " no eval_full found " | Some x -> x in Texp_apply ( eval_full , [ ( Nolabel , Some tinyocaml_expression ) ] ) in { expr with exp_desc = exp_desc ' } | { exp_desc = Texp_let ( recflag , [ binding ] , ( { exp_desc = Texp_sequence ( whole_addenv , expr ' ) } as sequence ) ) } as other -> begin match whole_addenv with { exp_desc = Texp_apply ( { exp_desc = Texp_ident ( path , _ , _ ) } as addenv , [ a ; a ' ; ( ( _ , Some { exp_desc = Texp_constant ( Const_string ( name , _ ) ) } ) as b ) ; c ; ( arg_label , Some typ ) ] ) } when Path . name path = " Tppxsupport . addenv " -> Printf . printf " **** Found an addenv instance ! for % s \ n " name ; let typ ' = match ! template_string with None -> failwith " no template string 2 " | Some s -> { s with exp_desc = Texp_constant ( Const_string ( Marshal . to_string other . exp_type [ ] , None ) ) } in { other with exp_desc = Texp_let ( recflag , [ binding ] , { sequence with exp_desc = Texp_sequence ( { whole_addenv with exp_desc = Texp_apply ( addenv , [ a ; a ' ; b ; c ; ( arg_label , Some typ ' ) ] ) } , default . expr mapper expr ' ) } ) } | _ -> default . expr mapper other end | other -> default . expr mapper other ) ; structure_item = ( fun mapper sitem -> match sitem with { str_desc = Tstr_value ( _ , [ { vb_pat = { pat_desc = Tpat_var ( varname , _ ) } ; vb_expr } ] ) } when Ident . name varname = " eval_full " -> eval_full_function := Some vb_expr ; default . structure_item mapper sitem | { str_desc = Tstr_value ( _ , [ { vb_pat = { pat_desc = Tpat_var ( varname , _ ) } ; vb_expr } ] ) } when Ident . name varname = " template_string " -> template_string := Some vb_expr ; default . structure_item mapper sitem | { str_desc = Tstr_value ( vlhs , [ { vb_pat = { pat_desc = Tpat_construct ( { txt = Lident " ( ) " } , _ , _ ) } ; vb_expr = { exp_desc = Texp_apply ( { exp_desc = Texp_ident ( path , _ , _ ) } as addenv , [ a ; a ' ; ( ( _ , Some { exp_desc = Texp_constant ( Const_string ( name , _ ) ) } ) as b ) ; c ; ( arg_label , Some typ ) ] ) } as vbexpr } as vbinding ] ) } when Path . name path = " Tppxsupport . addenv " -> let typ ' = match ! template_string with None -> failwith " no template string 2 " | Some s -> match ! last_global_type with None -> failwith " no last_global_type " | Some typ -> { s with exp_desc = Texp_constant ( Const_string ( Marshal . to_string typ [ ] , None ) ) } in Printf . printf " *** found let ( ) = . . . \ n " ; let vbinding ' = { vbinding with vb_expr = { vbexpr with exp_desc = Texp_apply ( addenv , [ a ; a ' ; b ; c ; ( arg_label , Some typ ' ) ] ) } } in { sitem with str_desc = Tstr_value ( vlhs , [ vbinding ' ] ) } | { str_desc = Tstr_value ( _ , [ { vb_expr ; vb_pat = { pat_desc = Tpat_var ( varname , _ ) } ; _ } ] ) } -> Printf . printf " *** storing type for % s \ n " ( Ident . name varname ) ; last_global_type := Some ( vb_expr . exp_type ) ; default . structure_item mapper sitem | _ -> default . structure_item mapper sitem ) }
|
let ( ) = Tast_mapper . register " tppx_interpret " newmapper
|
try printf " d / i positive \ n " ; %! test ( sprintf " % d /% i " 42 43 = " 42 / 43 " ) ; test ( sprintf " %- 4d /%- 5i " 42 43 = " 42 / 43 " ) ; test ( sprintf " % 04d /% 05i " 42 43 = " 0042 / 00043 " ) ; test ( sprintf " %+ d /%+ i " 42 43 = " + 42 /+ 43 " ) ; test ( sprintf " % d /% i " 42 43 = " 42 / 43 " ) ; test ( sprintf " %# d /%# i " 42 43 = " 42 / 43 " ) ; test ( sprintf " %# d /%# i " 123 123 = " 123 / 123 " ) ; test ( sprintf " %# d /%# i " 1234 1234 = " 1_234 / 1_234 " ) ; test ( sprintf " %# d /%# i " 12345 12345 = " 12_345 / 12_345 " ) ; test ( sprintf " %# d /%# i " 123456 123456 = " 123_456 / 123_456 " ) ; test ( sprintf " %# 4d /%# 5i " 1234 1234 = " 1_234 / 1_234 " ) ; test ( sprintf " %#- 6d /%#- 7i " 1234 1234 = " 1_234 / 1_234 " ) ; test ( sprintf " % 4d /% 5i " 42 43 = " 42 / 43 " ) ; test ( sprintf " %* d " ( - 4 ) 42 = " 42 " ) ; test ( sprintf " %* d /%* i " 4 42 5 43 = " 42 / 43 " ) ; printf " \ nd / i negative \ n " ; %! test ( sprintf " % d /% i " ( - 42 ) ( - 43 ) = " - 42 /- 43 " ) ; test ( sprintf " %- 4d /%- 5i " ( - 42 ) ( - 43 ) = " - 42 /- 43 " ) ; test ( sprintf " % 04d /% 05i " ( - 42 ) ( - 43 ) = " - 042 /- 0043 " ) ; test ( sprintf " %+ d /%+ i " ( - 42 ) ( - 43 ) = " - 42 /- 43 " ) ; test ( sprintf " % d /% i " ( - 42 ) ( - 43 ) = " - 42 /- 43 " ) ; test ( sprintf " %# d /%# i " ( - 42 ) ( - 43 ) = " - 42 /- 43 " ) ; test ( sprintf " %# d /%# i " ( - 123 ) ( - 123 ) = " - 123 /- 123 " ) ; test ( sprintf " %# d /%# i " ( - 1234 ) ( - 1234 ) = " - 1_234 /- 1_234 " ) ; test ( sprintf " %# d /%# i " ( - 12345 ) ( - 12345 ) = " - 12_345 /- 12_345 " ) ; test ( sprintf " %# d /%# i " ( - 123456 ) ( - 123456 ) = " - 123_456 /- 123_456 " ) ; test ( sprintf " %# 4d /%# 5i " ( - 1234 ) ( - 1234 ) = " - 1_234 /- 1_234 " ) ; test ( sprintf " %#- 6d /%#- 7i " ( - 1234 ) ( - 1234 ) = " - 1_234 /- 1_234 " ) ; test ( sprintf " % 4d /% 5i " ( - 42 ) ( - 43 ) = " - 42 / - 43 " ) ; test ( sprintf " %* d " ( - 4 ) ( - 42 ) = " - 42 " ) ; test ( sprintf " %* d /%* i " 4 ( - 42 ) 5 ( - 43 ) = " - 42 / - 43 " ) ; printf " \ nu positive \ n " ; %! test ( sprintf " % u " 42 = " 42 " ) ; test ( sprintf " %- 4u " 42 = " 42 " ) ; test ( sprintf " % 04u " 42 = " 0042 " ) ; test ( sprintf " %# u " 42 = " 42 " ) ; test ( sprintf " %# u " 123 = " 123 " ) ; test ( sprintf " %# u " 1234 = " 1_234 " ) ; test ( sprintf " %# u " 12345 = " 12_345 " ) ; test ( sprintf " %# u " 123456 = " 123_456 " ) ; test ( sprintf " %# 4u " 1234 = " 1_234 " ) ; test ( sprintf " %# 6u " 1234 = " 1_234 " ) ; test ( sprintf " % 4u " 42 = " 42 " ) ; test ( sprintf " %* u " 4 42 = " 42 " ) ; test ( sprintf " %* u " ( - 4 ) 42 = " 42 " ) ; printf " \ nu negative \ n " ; %! begin match Sys . word_size with | 32 -> test ( sprintf " % u " ( - 1 ) = " 2147483647 " ) ; test ( sprintf " %# u " ( - 1 ) = " 2_147_483_647 " ) ; | 64 -> test ( sprintf " % u " ( - 1 ) = " 9223372036854775807 " ) ; test ( sprintf " %# u " ( - 1 ) = " 9_223_372_036_854_775_807 " ) ; | _ -> test false end ; printf " \ nx positive \ n " ; %! test ( sprintf " % x " 42 = " 2a " ) ; test ( sprintf " %- 4x " 42 = " 2a " ) ; test ( sprintf " % 04x " 42 = " 002a " ) ; test ( sprintf " %# x " 42 = " 0x2a " ) ; test ( sprintf " % 4x " 42 = " 2a " ) ; test ( sprintf " %* x " 5 42 = " 2a " ) ; test ( sprintf " %* x " ( - 5 ) 42 = " 2a " ) ; test ( sprintf " %#* x " 5 42 = " 0x2a " ) ; test ( sprintf " %#* x " ( - 5 ) 42 = " 0x2a " ) ; test ( sprintf " %#-* x " 5 42 = " 0x2a " ) ; test ( sprintf " %- 0 + #* x " 5 42 = " 0x2a " ) ; printf " \ nx negative \ n " ; %! begin match Sys . word_size with | 32 -> test ( sprintf " % x " ( - 42 ) = " 7fffffd6 " ) ; | 64 -> test ( sprintf " % x " ( - 42 ) = " 7fffffffffffffd6 " ) ; | _ -> test false end ; printf " \ nX positive \ n " ; %! test ( sprintf " % X " 42 = " 2A " ) ; test ( sprintf " %- 4X " 42 = " 2A " ) ; test ( sprintf " % 04X " 42 = " 002A " ) ; test ( sprintf " %# X " 42 = " 0X2A " ) ; test ( sprintf " % 4X " 42 = " 2A " ) ; test ( sprintf " %* X " 5 42 = " 2A " ) ; printf " \ nx negative \ n " ; %! begin match Sys . word_size with | 32 -> test ( sprintf " % X " ( - 42 ) = " 7FFFFFD6 " ) ; | 64 -> test ( sprintf " % X " ( - 42 ) = " 7FFFFFFFFFFFFFD6 " ) ; | _ -> test false end ; printf " \ no positive \ n " ; %! test ( sprintf " % o " 42 = " 52 " ) ; test ( sprintf " %- 4o " 42 = " 52 " ) ; test ( sprintf " % 04o " 42 = " 0052 " ) ; test ( sprintf " %# o " 42 = " 052 " ) ; test ( sprintf " % 4o " 42 = " 52 " ) ; test ( sprintf " %* o " 5 42 = " 52 " ) ; printf " \ no negative \ n " ; %! begin match Sys . word_size with | 32 -> test ( sprintf " % o " ( - 42 ) = " 17777777726 " ) ; | 64 -> test ( sprintf " % o " ( - 42 ) = " 777777777777777777726 " ) ; | _ -> test false end ; printf " \ ns \ n " ; %! test ( sprintf " % s " " foo " = " foo " ) ; test ( sprintf " %- 5s " " foo " = " foo " ) ; test ( sprintf " % 5s " " foo " = " foo " ) ; test ( sprintf " % 1s " " foo " = " foo " ) ; test ( sprintf " %* s " 6 " foo " = " foo " ) ; test ( sprintf " %* s " ( - 6 ) " foo " = " foo " ) ; test ( sprintf " %* s " 2 " foo " = " foo " ) ; test ( sprintf " % s " @ " foo " = " foo " ) ; @ test ( sprintf " % s @ inria . fr " " foo " = " foo @ inria . fr " ) ; test ( sprintf " % s @% s " " foo " " inria . fr " = " foo @ inria . fr " ) ; printf " \ nS \ n " ; %! test ( sprintf " % S " " fo " \ o " = " " \ fo " \\\ o " " ) ; \ test ( sprintf " % 1S " " foo " = " " \ foo " " ) ; \ test ( sprintf " %* S " 8 " foo " = " " \ foo " " ) ; \ test ( sprintf " %* S " ( - 8 ) " foo " = " " \ foo " \ " ) ; test ( sprintf " %* S " 2 " foo " = " " \ foo " " ) ; \ test ( sprintf " % S " @ " foo " = " " \ foo " " ) ; \@ test ( sprintf " % S @ inria . fr " " foo " = " " \ foo " \@ inria . fr " ) ; test ( sprintf " % S @% S " " foo " " inria . fr " = " " \ foo " " \@\ inria . fr " " ) ; \ printf " \ nc \ n " ; %! test ( sprintf " % c " ' c ' = " c " ) ; printf " \ nC \ n " ; %! test ( sprintf " % C " ' c ' = " ' c ' " ) ; test ( sprintf " % C " ' ' ' \ = " ' ' ' " ) ; \\ printf " \ nf \ n " ; %! test ( sprintf " % f " ( - 42 . 42 ) = " - 42 . 420000 " ) ; test ( sprintf " %- 13f " ( - 42 . 42 ) = " - 42 . 420000 " ) ; test ( sprintf " % 013f " ( - 42 . 42 ) = " - 00042 . 420000 " ) ; test ( sprintf " %+ f " 42 . 42 = " + 42 . 420000 " ) ; test ( sprintf " % f " 42 . 42 = " 42 . 420000 " ) ; test ( sprintf " % 13f " 42 . 42 = " 42 . 420000 " ) ; test ( sprintf " %* f " 12 42 . 42 = " 42 . 420000 " ) ; test ( sprintf " . % 3f " ( - 42 . 42 ) = " - 42 . 420 " ) ; test ( sprintf " . %* f " ( - 3 ) 42 . 42 = " 42 . 420 " ) ; test ( sprintf " %- 13 . 3f " ( - 42 . 42 ) = " - 42 . 420 " ) ; test ( sprintf " % 013 . 3f " ( - 42 . 42 ) = " - 00000042 . 420 " ) ; test ( sprintf " . %+ 3f " 42 . 42 = " + 42 . 420 " ) ; test ( sprintf " % . 3f " 42 . 42 = " 42 . 420 " ) ; test ( sprintf " % 13 . 3f " 42 . 42 = " 42 . 420 " ) ; test ( sprintf " . %** f " 12 3 42 . 42 = " 42 . 420 " ) ; let ( =* ) s1 s2 = let ss1 = s1 ^ " " $ in let ss2 = s2 ^ " " $ in let rec loop i1 i2 extra missing = if i1 = String . length ss1 && i2 = String . length ss2 then begin if extra then true else not missing end else if i1 = String . length ss1 || i2 = String . length ss2 then false else begin match ss1 . [ i1 ] , ss2 . [ i2 ] with | x , y when x = y -> loop ( i1 + 1 ) ( i2 + 1 ) extra missing | ' 0 ' , _ when not extra -> loop ( i1 + 1 ) i2 true missing | _ , ( ' ' ' | 0 ' ) when not missing -> loop i1 ( i2 + 1 ) extra true | _ , _ -> false end in loop 0 0 false false in printf " \ nF \ n " ; %! test ( sprintf " % F " 42 . 42 = " 42 . 42 " ) ; test ( sprintf " % F " 42 . 42e42 =* " 4 . 242e + 43 " ) ; test ( sprintf " % F " 42 . 00 = " 42 . " ) ; test ( sprintf " % F " 0 . 042 = " 0 . 042 " ) ; test ( sprintf " % 4F " 3 . = " 3 . " ) ; test ( sprintf " %- 4F " 3 . = " 3 . " ) ; test ( sprintf " % 04F " 3 . = " 003 . " ) ; test ( sprintf " %+ 4F " 3 . = " + 3 . " ) ; test ( sprintf " . % 3F " 42 . 42 = " 42 . 4 " ) ; test ( sprintf " % 12 . 3F " 42 . 42e42 =* " 4 . 24e + 43 " ) ; test ( sprintf " . % 3F " 42 . 00 = " 42 . " ) ; test ( sprintf " . % 3F " 0 . 0042 = " 0 . 0042 " ) ; test ( sprintf " % F " nan = " nan " ) ; test ( sprintf " % F " ( . - nan ) = " nan " ) ; test ( sprintf " % F " infinity = " infinity " ) ; test ( sprintf " % F " neg_infinity = " neg_infinity " ) ; printf " \ n # F \ n " ; %! test ( sprintf " %+# F " ( + 0 . ) = " + 0x0p + 0 " ) ; test ( sprintf " %+# F " ( - 0 . ) = " - 0x0p + 0 " ) ; test ( sprintf " %+# F " ( + 1 . ) = " + 0x1p + 0 " ) ; test ( sprintf " %+# F " ( - 1 . ) = " - 0x1p + 0 " ) ; test ( sprintf " %+# F " ( + 1024 . ) = " + 0x1p + 10 " ) ; test ( sprintf " % # F " ( + 1024 . ) = " 0x1p + 10 " ) ; test ( sprintf " %+# F " ( - 1024 . ) = " - 0x1p + 10 " ) ; test ( sprintf " %# F " 0x123 . 456 = " 0x1 . 23456p + 8 " ) ; test ( sprintf " %# F " 0x123456789ABCDE . = " 0x1 . 23456789abcdep + 52 " ) ; test ( sprintf " %# F " epsilon_float = " 0x1p - 52 " ) ; test ( sprintf " %# F " nan = " nan " ) ; test ( sprintf " %# F " ( . - nan ) = " nan " ) ; test ( sprintf " %# F " infinity = " infinity " ) ; test ( sprintf " %# F " neg_infinity = " neg_infinity " ) ; printf " \ nh \ n " ; %! test ( sprintf " %+ h " ( + 0 . ) = " + 0x0p + 0 " ) ; test ( sprintf " %+ h " ( - 0 . ) = " - 0x0p + 0 " ) ; test ( sprintf " %+ h " ( + 1 . ) = " + 0x1p + 0 " ) ; test ( sprintf " %+ h " ( - 1 . ) = " - 0x1p + 0 " ) ; test ( sprintf " %+ h " ( + 1024 . ) = " + 0x1p + 10 " ) ; test ( sprintf " %+ h " ( - 1024 . ) = " - 0x1p + 10 " ) ; test ( sprintf " % h " 0x123 . 456 = " 0x1 . 23456p + 8 " ) ; test ( sprintf " % h " 0x123456789ABCDE . = " 0x1 . 23456789abcdep + 52 " ) ; test ( sprintf " % h " epsilon_float = " 0x1p - 52 " ) ; test ( sprintf " % h " nan = " nan " ) ; test ( sprintf " % h " infinity = " infinity " ) ; test ( sprintf " % h " neg_infinity = " - infinity " ) ; test ( sprintf " % h " ( 4 . . * atan 1 . ) = " 0x1 . 921fb54442d18p + 1 " ) ; printf " \ nH \ n " ; %! test ( sprintf " %+ H " ( + 0 . ) = " + 0X0P + 0 " ) ; test ( sprintf " %+ H " ( - 0 . ) = " - 0X0P + 0 " ) ; test ( sprintf " %+ H " ( + 1 . ) = " + 0X1P + 0 " ) ; test ( sprintf " %+ H " ( - 1 . ) = " - 0X1P + 0 " ) ; test ( sprintf " %+ H " ( + 1024 . ) = " + 0X1P + 10 " ) ; test ( sprintf " %+ H " ( - 1024 . ) = " - 0X1P + 10 " ) ; test ( sprintf " % H " 0X123 . 456 = " 0X1 . 23456P + 8 " ) ; test ( sprintf " % H " 0X123456789ABCDE . = " 0X1 . 23456789ABCDEP + 52 " ) ; test ( sprintf " % H " epsilon_float = " 0X1P - 52 " ) ; test ( sprintf " % H " nan = " NAN " ) ; test ( sprintf " % H " infinity = " INFINITY " ) ; test ( sprintf " % H " neg_infinity = " - INFINITY " ) ; test ( sprintf " % H " ( 4 . . * atan 1 . ) = " 0X1 . 921FB54442D18P + 1 " ) ; printf " \ ne \ n " ; %! test ( sprintf " % e " ( - 42 . 42 ) =* " - 4 . 242000e + 01 " ) ; test ( sprintf " %- 15e " ( - 42 . 42 ) =* " - 4 . 242000e + 01 " ) ; test ( sprintf " % 015e " ( - 42 . 42 ) =* " - 004 . 242000e + 01 " ) ; test ( sprintf " %+ e " 42 . 42 =* " + 4 . 242000e + 01 " ) ; test ( sprintf " % e " 42 . 42 =* " 4 . 242000e + 01 " ) ; test ( sprintf " % 15e " 42 . 42 =* " 4 . 242000e + 01 " ) ; test ( sprintf " %* e " 14 42 . 42 =* " 4 . 242000e + 01 " ) ; test ( sprintf " . % 3e " ( - 42 . 42 ) =* " - 4 . 242e + 01 " ) ; test ( sprintf " %- 15 . 3e " ( - 42 . 42 ) =* " - 4 . 242e + 01 " ) ; test ( sprintf " % 015 . 3e " ( - 42 . 42 ) =* " - 000004 . 242e + 01 " ) ; test ( sprintf " . %+ 3e " 42 . 42 =* " + 4 . 242e + 01 " ) ; test ( sprintf " % . 3e " 42 . 42 =* " 4 . 242e + 01 " ) ; test ( sprintf " % 15 . 3e " 42 . 42 =* " 4 . 242e + 01 " ) ; test ( sprintf " . %** e " 11 3 42 . 42 =* " 4 . 242e + 01 " ) ; printf " \ nE \ n " ; %! test ( sprintf " % E " ( - 42 . 42 ) =* " - 4 . 242000E + 01 " ) ; test ( sprintf " %- 15E " ( - 42 . 42 ) =* " - 4 . 242000E + 01 " ) ; test ( sprintf " % 015E " ( - 42 . 42 ) =* " - 004 . 242000E + 01 " ) ; test ( sprintf " %+ E " 42 . 42 =* " + 4 . 242000E + 01 " ) ; test ( sprintf " % E " 42 . 42 =* " 4 . 242000E + 01 " ) ; test ( sprintf " % 15E " 42 . 42 =* " 4 . 242000E + 01 " ) ; test ( sprintf " %* E " 14 42 . 42 =* " 4 . 242000E + 01 " ) ; test ( sprintf " . % 3E " ( - 42 . 42 ) =* " - 4 . 242E + 01 " ) ; test ( sprintf " %- 15 . 3E " ( - 42 . 42 ) =* " - 4 . 242E + 01 " ) ; test ( sprintf " % 015 . 3E " ( - 42 . 42 ) =* " - 000004 . 242E + 01 " ) ; test ( sprintf " . %+ 3E " 42 . 42 =* " + 4 . 242E + 01 " ) ; test ( sprintf " % . 3E " 42 . 42 =* " 4 . 242E + 01 " ) ; test ( sprintf " % 15 . 3E " 42 . 42 =* " 4 . 242E + 01 " ) ; test ( sprintf " . %** E " 11 3 42 . 42 =* " 4 . 242E + 01 " ) ; printf " \ ng \ n " ; %! test ( sprintf " % g " ( - 42 . 42 ) = " - 42 . 42 " ) ; test ( sprintf " . % 3g " ( - 4242 . ) =* " - 4 . 24e + 03 " ) ; test ( sprintf " %- 15g " ( - 42 . 42 ) = " - 42 . 42 " ) ; test ( sprintf " % 015g " ( - 42 . 42 ) = " - 00000000042 . 42 " ) ; test ( sprintf " %+ g " 42 . 42 = " + 42 . 42 " ) ; test ( sprintf " % g " 42 . 42 = " 42 . 42 " ) ; test ( sprintf " % 15g " 42 . 42 = " 42 . 42 " ) ; test ( sprintf " %* g " 14 42 . 42 = " 42 . 42 " ) ; test ( sprintf " . % 3g " ( - 42 . 42 ) = " - 42 . 4 " ) ; printf " \ nG \ n " ; %! test ( sprintf " % G " ( - 42 . 42 ) = " - 42 . 42 " ) ; test ( sprintf " . % 3G " ( - 4242 . ) =* " - 4 . 24E + 03 " ) ; test ( sprintf " %- 15G " ( - 42 . 42 ) = " - 42 . 42 " ) ; test ( sprintf " % 015G " ( - 42 . 42 ) = " - 00000000042 . 42 " ) ; test ( sprintf " %+ G " 42 . 42 = " + 42 . 42 " ) ; test ( sprintf " % G " 42 . 42 = " 42 . 42 " ) ; test ( sprintf " % 15G " 42 . 42 = " 42 . 42 " ) ; test ( sprintf " %* G " 14 42 . 42 = " 42 . 42 " ) ; test ( sprintf " . % 3G " ( - 42 . 42 ) = " - 42 . 4 " ) ; printf " \ nB \ n " ; %! test ( sprintf " % B " true = " true " ) ; test ( sprintf " % 8B " true = " true " ) ; test ( sprintf " % B " false = " false " ) ; test ( sprintf " %- 8B " false = " false " ) ; printf " \ nld / li positive \ n " ; %! test ( sprintf " % ld /% li " 42l 43l = " 42 / 43 " ) ; test ( sprintf " %- 4ld /%- 5li " 42l 43l = " 42 / 43 " ) ; test ( sprintf " % 04ld /% 05li " 42l 43l = " 0042 / 00043 " ) ; test ( sprintf " %+ ld /%+ li " 42l 43l = " + 42 /+ 43 " ) ; test ( sprintf " % ld /% li " 42l 43l = " 42 / 43 " ) ; test ( sprintf " % 4ld /% 5li " 42l 43l = " 42 / 43 " ) ; test ( sprintf " %* ld /%* li " 4 42l 5 43l = " 42 / 43 " ) ; printf " \ nld / li negative \ n " ; %! test ( sprintf " % ld /% li " ( - 42l ) ( - 43l ) = " - 42 /- 43 " ) ; test ( sprintf " %- 4ld /%- 5li " ( - 42l ) ( - 43l ) = " - 42 /- 43 " ) ; test ( sprintf " % 04ld /% 05li " ( - 42l ) ( - 43l ) = " - 042 /- 0043 " ) ; test ( sprintf " %+ ld /%+ li " ( - 42l ) ( - 43l ) = " - 42 /- 43 " ) ; test ( sprintf " % ld /% li " ( - 42l ) ( - 43l ) = " - 42 /- 43 " ) ; test ( sprintf " % 4ld /% 5li " ( - 42l ) ( - 43l ) = " - 42 / - 43 " ) ; test ( sprintf " %* ld /%* li " 4 ( - 42l ) 5 ( - 43l ) = " - 42 / - 43 " ) ; printf " \ nlu positive \ n " ; %! test ( sprintf " % lu " 42l = " 42 " ) ; test ( sprintf " %- 4lu " 42l = " 42 " ) ; test ( sprintf " % 04lu " 42l = " 0042 " ) ; test ( sprintf " % 4lu " 42l = " 42 " ) ; test ( sprintf " %* lu " 4 42l = " 42 " ) ; printf " \ nlu negative \ n " ; %! test ( sprintf " % lu " ( - 1l ) = " 4294967295 " ) ; printf " \ nlx positive \ n " ; %! test ( sprintf " % lx " 42l = " 2a " ) ; test ( sprintf " %- 4lx " 42l = " 2a " ) ; test ( sprintf " % 04lx " 42l = " 002a " ) ; test ( sprintf " %# lx " 42l = " 0x2a " ) ; test ( sprintf " % 4lx " 42l = " 2a " ) ; test ( sprintf " %* lx " 5 42l = " 2a " ) ; printf " \ nlx negative \ n " ; %! test ( sprintf " % lx " ( - 42l ) = " ffffffd6 " ) ; printf " \ nlX positive \ n " ; %! test ( sprintf " % lX " 42l = " 2A " ) ; test ( sprintf " %- 4lX " 42l = " 2A " ) ; test ( sprintf " % 04lX " 42l = " 002A " ) ; test ( sprintf " %# lX " 42l = " 0X2A " ) ; test ( sprintf " % 4lX " 42l = " 2A " ) ; test ( sprintf " %* lX " 5 42l = " 2A " ) ; printf " \ nlx negative \ n " ; %! test ( sprintf " % lX " ( - 42l ) = " FFFFFFD6 " ) ; printf " \ nlo positive \ n " ; %! test ( sprintf " % lo " 42l = " 52 " ) ; test ( sprintf " %- 4lo " 42l = " 52 " ) ; test ( sprintf " % 04lo " 42l = " 0052 " ) ; test ( sprintf " %# lo " 42l = " 052 " ) ; test ( sprintf " % 4lo " 42l = " 52 " ) ; test ( sprintf " %* lo " 5 42l = " 52 " ) ; printf " \ nlo negative \ n " ; %! test ( sprintf " % lo " ( - 42l ) = " 37777777726 " ) ; printf " \ nLd / Li positive \ n " ; %! test ( sprintf " % Ld /% Li " 42L 43L = " 42 / 43 " ) ; test ( sprintf " %- 4Ld /%- 5Li " 42L 43L = " 42 / 43 " ) ; test ( sprintf " % 04Ld /% 05Li " 42L 43L = " 0042 / 00043 " ) ; test ( sprintf " % 4Ld /% 5Li " 42L 43L = " 42 / 43 " ) ; test ( sprintf " %* Ld /%* Li " 4 42L 5 43L = " 42 / 43 " ) ; printf " \ nLd / Li negative \ n " ; %! test ( sprintf " % Ld /% Li " ( - 42L ) ( - 43L ) = " - 42 /- 43 " ) ; test ( sprintf " %- 4Ld /%- 5Li " ( - 42L ) ( - 43L ) = " - 42 /- 43 " ) ; test ( sprintf " % 04Ld /% 05Li " ( - 42L ) ( - 43L ) = " - 042 /- 0043 " ) ; test ( sprintf " % 4Ld /% 5Li " ( - 42L ) ( - 43L ) = " - 42 / - 43 " ) ; test ( sprintf " %* Ld /%* Li " 4 ( - 42L ) 5 ( - 43L ) = " - 42 / - 43 " ) ; printf " \ nLu positive \ n " ; %! test ( sprintf " % Lu " 42L = " 42 " ) ; test ( sprintf " %- 4Lu " 42L = " 42 " ) ; test ( sprintf " % 04Lu " 42L = " 0042 " ) ; test ( sprintf " % 4Lu " 42L = " 42 " ) ; test ( sprintf " %* Lu " 4 42L = " 42 " ) ; printf " \ nLu negative \ n " ; %! test ( sprintf " % Lu " ( - 1L ) = " 18446744073709551615 " ) ; printf " \ nLx positive \ n " ; %! test ( sprintf " % Lx " 42L = " 2a " ) ; test ( sprintf " %- 4Lx " 42L = " 2a " ) ; test ( sprintf " % 04Lx " 42L = " 002a " ) ; test ( sprintf " %# Lx " 42L = " 0x2a " ) ; test ( sprintf " % 4Lx " 42L = " 2a " ) ; test ( sprintf " %* Lx " 5 42L = " 2a " ) ; printf " \ nLx negative \ n " ; %! test ( sprintf " % Lx " ( - 42L ) = " ffffffffffffffd6 " ) ; printf " \ nLX positive \ n " ; %! test ( sprintf " % LX " 42L = " 2A " ) ; test ( sprintf " %- 4LX " 42L = " 2A " ) ; test ( sprintf " % 04LX " 42L = " 002A " ) ; test ( sprintf " %# LX " 42L = " 0X2A " ) ; test ( sprintf " % 4LX " 42L = " 2A " ) ; test ( sprintf " %* LX " 5 42L = " 2A " ) ; printf " \ nLx negative \ n " ; %! test ( sprintf " % LX " ( - 42L ) = " FFFFFFFFFFFFFFD6 " ) ; printf " \ nLo positive \ n " ; %! test ( sprintf " % Lo " 42L = " 52 " ) ; test ( sprintf " %- 4Lo " 42L = " 52 " ) ; test ( sprintf " % 04Lo " 42L = " 0052 " ) ; test ( sprintf " %# Lo " 42L = " 052 " ) ; test ( sprintf " % 4Lo " 42L = " 52 " ) ; test ( sprintf " %* Lo " 5 42L = " 52 " ) ; printf " \ nLo negative \ n " ; %! test ( sprintf " % Lo " ( - 42L ) = " 1777777777777777777726 " ) ; printf " \ na \ n " ; %! let x = ref ( ) in let f ( ) y = if y == x then " ok " else " wrong " in test ( sprintf " % a " f x = " ok " ) ; printf " \ nt \ n " ; %! let f ( ) = " ok " in test ( sprintf " % t " f = " ok " ) ; printf " \ n { . . . } %%\ n " ; %! let f = format_of_string " % 4g /% s " in test ( sprintf " { . %% 4F % 5S } " % f = " % f % s " ) ; printf " \ n ( . . . ) %%\ n " ; %! let f = format_of_string " % d / foo /% s " in test ( sprintf " ( %% d % s ) " % f 42 " bar " = " 42 / foo / bar " ) ; printf " \ n ! %% @ , and constants \ n " ; %! test ( sprintf " " %! = " " ) ; test ( sprintf " " %% = " " ) ; % test ( sprintf " " %@ = " " ) ; @ test ( sprintf " , " % = " " ) ; test ( sprintf " " @ = " " ) ; @ test ( sprintf " " @@ = " " ) ; @@ test ( sprintf " " @%% = " " ) ; @% printf " \ nend of tests \ n " ; %! printf " unexpected exception : % s \ n " %! ( Printexc . to_string e ) ; test false ; ; ;
|
type traced_function = { path : Path . t ; closure : Obj . t ; actual_code : codeptr ; instrumented_fun : codeptr -> Obj . t -> Obj . t -> Obj . t }
|
let traced_functions = ref ( [ ] : traced_function list )
|
let is_traced clos = let rec is_traced = function [ ] -> None | tf :: rem -> if tf . closure == clos then Some tf . path else is_traced rem in is_traced ! traced_functions
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.