text
stringlengths
12
786k
type head = { }
type hhea = { }
type loca = int32 array
type maxp = { }
type os2 = { }
type ttf = { }
type ttf_config = { }
module type TEST_PIPELINE = functor ( Bfx : Biokepi . EDSL . Semantics ) -> sig val run : unit -> unit Bfx . observation end
module Run_test ( Test_pipeline : TEST_PIPELINE ) = struct let write_file file ~ content = let out_file = open_out file in try output_string out_file content ; close_out out_file with _ -> close_out out_file let cmdf fmt = ksprintf ( fun s -> printf " CMD : % s \ n " %! s ; match Sys . command s with | 0 -> ( ) | other -> ksprintf failwith " non - zero - exit : % s -> % d " s other ) fmt let ( ) // = Filename . concat let test_dir = " _build / ttfi - test - results " / let main prefix = let start_time = Unix . gettimeofday ( ) in cmdf " mkdir - p % s " test_dir ; let results = ref [ ] in let add_result fmt = ksprintf ( fun s -> results := s :: ! results ) fmt in let add_result_file name path = let size = let s = Unix . stat path in match s . Unix . st_size with | 0 -> " EMPTY " | small when small < 1024 -> sprintf " % d B " small | avg when avg < ( 1024 * 1024 ) -> sprintf " . % 2f KB " ( float avg . / 1024 . ) | big -> sprintf " . % 2f MB " ( float big . / ( 1024 . . * 1024 . ) ) in add_result " % s : ` % s ` ( % s ) " name path size ; in let output_path suffix = test_dir // prefix ^ suffix in begin let module Display_pipeline = Test_pipeline ( Biokepi . EDSL . Compile . To_display ) in let pseudocode = output_path " - pseudocode . txt " in write_file pseudocode ~ content ( : Display_pipeline . run ( ) |> SmartPrint . to_string 80 2 ) ; add_result_file " Pseudo - code " pseudocode ; end ; begin let module Jsonize_pipeline = Test_pipeline ( Biokepi . EDSL . Compile . To_json ) in let json = output_path " . json " in write_file json ~ content ( : Jsonize_pipeline . run ( ) |> Yojson . Basic . pretty_to_string ~ std : true ) ; add_result_file " JSON " json ; end ; let output_dot sm dot png = try let out = open_out dot in SmartPrint . to_out_channel 80 2 out sm ; close_out out ; add_result_file " DOT " dot ; let dotlog = png ^ " . log " in cmdf " dot - v - x - Tpng % s - o % s > % s 2 >& 1 " dot png dotlog ; add_result_file " PNG " png ; with e -> add_result " FAILED TO OUTPUT : % s ( % s ) " dot ( Printexc . to_string e ) ; in begin let module Dotize_pipeline = Test_pipeline ( Biokepi . EDSL . Compile . To_dot ) in let sm_dot = Dotize_pipeline . run ( ) Biokepi . EDSL . Compile . To_dot . default_parameters in let dot = output_path " - 1 . dot " in let png = output_path " - 1 . png " in output_dot sm_dot dot png end ; begin let module Dotize_twice_beta_reduced_pipeline = Test_pipeline ( Biokepi . EDSL . Transform . Apply_functions ( Biokepi . EDSL . Transform . Apply_functions ( Biokepi . EDSL . Compile . To_dot ) ) ) in let dot = output_path " - double - beta . dot " in let sm_dot = Dotize_twice_beta_reduced_pipeline . run ( ) ~ parameters : Biokepi . EDSL . Compile . To_dot . default_parameters in let png = output_path " - double - beta . png " in output_dot sm_dot dot png end ; begin let module Workflow_compiler = Biokepi . EDSL . Compile . To_workflow . Make ( struct include Biokepi . EDSL . Compile . To_workflow . Defaults let processors = 42 let work_dir = " / work / dir " / let results_dir = Some " / result / dir " let machine = Biokepi . Setup . Build_machine . create " ssh :// example . com / tmp / KT " / end ) in let module Ketrew_pipeline = Test_pipeline ( Workflow_compiler ) in let workflow = Ketrew_pipeline . run ( ) |> Biokepi . EDSL . Compile . To_workflow . get_workflow ~ name " : Biokepi TTFI test top - level node " in ignore workflow end ; let end_time = Unix . gettimeofday ( ) in add_result " Total - time : . % 2f s " ( end_time . - start_time ) ; List . rev ! results end
module Pipeline_insane ( Bfx : Biokepi . EDSL . Semantics ) = struct let fastq_list ~ dataset files = List . map files ~ f : begin function | ` Pair ( r1 , r2 ) -> if Filename . check_suffix r1 " . gz " || Filename . check_suffix r1 " . fqz " then Bfx . ( fastq_gz ~ sample_name : dataset ~ r1 ( : input_url r1 ) ~ r2 ( : input_url r2 ) ( ) |> gunzip ) else Bfx . ( fastq ~ sample_name : dataset ~ r1 ( : input_url r1 ) ~ r2 ( : input_url r2 ) ( ) ) end |> Bfx . list let every_vc_on_fastqs ~ reference_build ~ normal ~ tumor = let aligner which_one = Bfx . lambda ( fun fq -> which_one ~ reference_build fq ) in let align_list how ( list_of_fastqs : [ ` Fastq ] list Bfx . repr ) = Bfx . list_map list_of_fastqs ~ f : how |> Bfx . merge_bams in let aligners = Bfx . list [ aligner @@ Bfx . bwa_aln ? configuration : None ; aligner @@ Bfx . bwa_mem ? configuration : None ; aligner @@ Bfx . hisat ~ configuration : Biokepi . Tools . Hisat . Configuration . default_v1 ; aligner @@ Bfx . hisat ~ configuration : Biokepi . Tools . Hisat . Configuration . default_v2 ; aligner @@ Bfx . star ~ configuration : Biokepi . Tools . Star . Configuration . Align . default ; aligner @@ Bfx . mosaik ; aligner @@ ( fun ~ reference_build fastq -> Bfx . bwa_aln ~ reference_build fastq |> Bfx . bam_to_fastq ` PE |> Bfx . bwa_mem ? configuration : None ~ reference_build ) ; ] in let somatic_of_pair how = Bfx . lambda ( fun pair -> let normal = Bfx . pair_first pair in let tumor = Bfx . pair_second pair in how ~ normal ~ tumor ( ) ) in let somatic_vcs = List . map ~ f : somatic_of_pair [ Bfx . mutect ~ configuration : Biokepi . Tools . Mutect . Configuration . default ; Bfx . mutect2 ~ configuration : Biokepi . Tools . Gatk . Configuration . Mutect2 . default ; Bfx . somaticsniper ~ configuration : Biokepi . Tools . Somaticsniper . Configuration . default ; Bfx . strelka ~ configuration : Biokepi . Tools . Strelka . Configuration . default ; Bfx . varscan_somatic ? adjust_mapq : None ; Bfx . muse ~ configuration : Biokepi . Tools . Muse . Configuration . wes ; Bfx . virmid ~ configuration : Biokepi . Tools . Virmid . Configuration . default ; ] in let aligned_pairs : ( ( [ ` Fastq ] list * [ ` Fastq ] list ) -> ( [ ` Bam ] * [ ` Bam ] ) list ) Bfx . repr = Bfx . lambda ( fun pair -> Bfx . list_map aligners ~ f ( : Bfx . lambda ( fun ( al : ( [ ` Fastq ] -> [ ` Bam ] ) Bfx . repr ) -> Bfx . pair ( align_list al ( Bfx . pair_first pair : [ ` Fastq ] list Bfx . repr ) ) ( align_list al ( Bfx . pair_second pair ) ) ) ) ) in let vcfs = Bfx . lambda ( fun pair -> List . map somatic_vcs ~ f ( : fun vc -> Bfx . list_map ( Bfx . apply aligned_pairs pair ) ~ f ( : Bfx . lambda ( fun bam_pair -> let ( ) ||> x f = Bfx . apply f x in let indelreal = Bfx . lambda ( fun pair -> Bfx . gatk_indel_realigner_joint ~ configuration : Biokepi . Tools . Gatk . Configuration . default_indel_realigner pair ) in let map_pair f = Bfx . lambda ( fun pair -> let b1 = Bfx . pair_first pair in let b2 = Bfx . pair_second pair in Bfx . pair ( f b1 ) ( f b2 ) ) in let bqsr_pair = Bfx . gatk_bqsr ~ configuration : Biokepi . Tools . Gatk . Configuration . default_bqsr |> map_pair in let markdups_pair = Bfx . picard_mark_duplicates ~ configuration : Biokepi . Tools . Picard . Mark_duplicates_settings . default |> map_pair in bam_pair ||> markdups_pair ||> indelreal ||> bqsr_pair ||> vc ||> Bfx . lambda Bfx . to_unit ) ) ) |> Bfx . list ) in let workflow_of_pair = Bfx . lambda ( fun pair -> Bfx . list [ ( Bfx . apply aligned_pairs pair |> Bfx . list_map ~ f ( : Bfx . lambda ( fun p -> Bfx . pair_first p |> Bfx . stringtie ~ configuration : Biokepi . Tools . Stringtie . Configuration . default ) ) ) |> Bfx . to_unit ; Bfx . apply vcfs pair |> Bfx . to_unit ; begin Bfx . apply ( Bfx . lambda ( fun p -> Bfx . pair_first p |> Bfx . concat |> Bfx . seq2hla ) ) pair |> Bfx . to_unit end ; begin Bfx . apply ( Bfx . lambda ( fun p -> Bfx . pair_first p |> Bfx . concat |> Bfx . fastqc ) ) pair |> Bfx . to_unit end ; begin Bfx . apply ( Bfx . lambda ( fun p -> Bfx . pair_second p |> Bfx . concat |> Bfx . optitype ` RNA ) ) pair |> Bfx . to_unit end ; begin Bfx . apply aligned_pairs pair |> Bfx . list_map ~ f ( : Bfx . lambda ( fun p -> Bfx . pair_first p |> Bfx . gatk_haplotype_caller ) ) |> Bfx . to_unit end ; ] |> Bfx . to_unit ) in Bfx . apply workflow_of_pair ( Bfx . pair normal tumor ) let normal = ( " normal - 1 " , [ ` Pair ( " / input / normal - 1 - 001 - r1 . fastq " , " / input / normal - 1 - 001 - r2 . fastq " ) ; ` Pair ( " / input / normal - 1 - 002 - r1 . fastq " , " / input / normal - 1 - 002 - r2 . fastq " ) ; ` Pair ( " / input / normal - 1 - 003 - r1 . fqz " , " / input / normal - 1 - 003 - r2 . fqz " ) ; ] ) let tumor = ( " tumor - 1 " , [ ` Pair ( " / input / tumor - 1 - 001 - r1 . fastq . gz " , " / input / tumor - 1 - 001 - r2 . fastq . gz " ) ; ` Pair ( " / input / tumor - 1 - 002 - r1 . fastq . gz " , " / input / tumor - 1 - 002 - r2 . fastq . gz " ) ; ] ) let run ( ) = Bfx . observe ( fun ( ) -> every_vc_on_fastqs ~ reference_build " : b37 " ~ normal ( : fastq_list ~ dataset ( : fst normal ) ( snd normal ) ) ~ tumor ( : fastq_list ~ dataset ( : fst tumor ) ( snd tumor ) ) ) end
module Somatic_simplish ( Bfx : Biokepi . EDSL . Semantics ) = struct module Insane_library = Pipeline_insane ( Bfx ) let vc = let normal = Insane_library . ( fastq_list ~ dataset ( : fst normal ) ( snd normal ) ) in let tumor = Insane_library . ( fastq_list ~ dataset ( : fst tumor ) ( snd tumor ) ) in let ot_hla = normal |> Bfx . concat |> Bfx . optitype ` DNA |> Bfx . to_unit in let align fastq = Bfx . list_map fastq ~ f ( : Bfx . lambda ( fun fq -> Bfx . bwa_mem fq ~ reference_build " : b37 " |> Bfx . picard_mark_duplicates ~ configuration : Biokepi . Tools . Picard . Mark_duplicates_settings . default ) ) in let normal_bam = align normal |> Bfx . merge_bams in let tumor_bam = align tumor |> Bfx . merge_bams in let bam_pair = Bfx . pair normal_bam tumor_bam in let indel_realigned_pair = Bfx . gatk_indel_realigner_joint bam_pair ~ configuration : Biokepi . Tools . Gatk . Configuration . default_indel_realigner in let final_normal_bam = Bfx . pair_first indel_realigned_pair |> Bfx . gatk_bqsr ~ configuration : Biokepi . Tools . Gatk . Configuration . default_bqsr in let final_tumor_bam = Bfx . pair_second indel_realigned_pair |> Bfx . gatk_bqsr ~ configuration : Biokepi . Tools . Gatk . Configuration . default_bqsr in let vcfs = let normal , tumor = final_normal_bam , final_tumor_bam in Bfx . list [ Bfx . mutect ~ normal ~ tumor ( ) |> Bfx . save ~ name " : Mutect VCF " ; Bfx . somaticsniper ~ normal ~ tumor ( ) |> Bfx . save ~ name " : SS VCF " ; Bfx . strelka ~ normal ~ tumor ( ) |> Bfx . save ~ name " : Strelka VCF " ; ] in Bfx . list [ Bfx . to_unit vcfs ; ot_hla ; ] |> Bfx . to_unit let run ( ) = Bfx . observe ( fun ( ) -> vc ) end
let ( ) = let module Go_insane = Run_test ( Pipeline_insane ) in let insane_result = Go_insane . main " pipeline - insane " in let module Go_simple_somatic = Run_test ( Somatic_simplish ) in let simple_somatic_result = Go_simple_somatic . main " pipeline - simple - somatic " in let display_result mod_name results = printf " - ` % s ` :\ n % s \ n " %! mod_name ( List . map results ~ f ( : sprintf " * % s \ n " ) |> String . concat " " ) ; in printf " \ n ### Test results :\ n \ n " ; display_result " Pipeline_insane " insane_result ; display_result " Somatic_simplish " simple_somatic_result ; ( )
type ctx = { }
let parse_header ctx = { }
let parse_directory ctx header = } done ; directory
let parse_head_table ctx = { }
let parse_hhea_table ctx = { }
let parse_maxp_table ctx = { }
let parse_loca_table head maxp ctx = else
let parse_hmtx_table maxp hhea ctx = ! last_advance_width else in { } )
let parse_cmap_table ctx = { } } } } | 12 -> { } } in { } in { }
let parse_glyf_table maxp loca cmap hmtx ctx = v 1 end in end end ; } ) arg1 , arg2 arg1 , arg2 NoScale in } ; in in )
let parse_kern_table ctx = { } } } in { } } { }
let parse_name_table ctx = { } in r { } , ! ttf_name
let parse_os2_table ctx = { }
let parse file : ttf = } in try in try None in { }
let num_bits x = 0 else in
let round x = int_of_float ( floor ( x . + 0 . 5 ) 5 ) 5
let to_twips v = round ( v . * 20 ) .
type ctx = { }
let align_bits x nbits = x land ( ( 1 lsl nbits ) - 1 ) 1
let move_to ctx x y = }
let line_to ctx x y = }
let curve_to ctx cx cy ax ay = }
let write_paths ctx paths = try ( ) { }
let rec write_glyph ctx key glyf = { }
let write_font_layout ctx lut = { { }
let bi v = if v then 1 else 0
let write_font2 ch b f2 = ) f2 . font_glyphs ;
let to_swf ttf config = { } ; ;
type glyf_transformation_matrix = { }
type glyf_path = { }
type simple_point = { }
let mk_path t x y cx cy = { }
let identity ( ) = { }
let multiply m x y =
let matrix_from_composite gc = in { }
let relative_matrix m = { m with tx = 0 . 0 ; ty = 0 . 0 } 0
let make_coords relative mo g = match mo with )
let build_paths relative mo g = true false in in } ; in end ; end ; end done ;
let rec build_glyph_paths ttf relative ( ? transformation = None ) None glyf = [ ]
let map_char_code cc c4 = else end done ; ! index end
let parse_range_str str = done ; end lut
let build_lut ttf range_str = end in done ; done in ( ) ( ) lut
type tvsymbol = { tv_name : Ident . t } [ @@ deriving show ]
let tv_equal x y = Ident . equal x . tv_name y . tv_name
module Tvar = struct type t = tvsymbol let equal = tv_equal let compare x y = Ident . compare x . tv_name y . tv_name let hash tv = Ident . hash tv . tv_name end
module Htv = Hashtbl . Make ( Tvar )
module Mtv = Map . Make ( Tvar )
let create_tv id = { tv_name = id }
let fresh_tv ( ? loc = Location . none ) s = { tv_name = Ident . create ~ loc s }
let tv_of_string = let hs = Hashtbl . create 0 in fun ( ? loc = Location . none ) s -> try Hashtbl . find hs s with Not_found -> let tv = create_tv ( Ident . create ~ loc s ) in Hashtbl . add hs s tv ; tv
type ty = { ty_node : ty_node } [ @@ deriving show ] ts_ident : Ident . t ; ts_args : tvsymbol list ; ts_alias : ty option ; }
let ts_equal x y = Ident . equal x . ts_ident y . ts_ident
let rec ty_equal x y = match ( x . ty_node , y . ty_node ) with | Tyvar tvx , Tyvar tvy -> tv_equal tvx tvy | Tyapp ( tsx , tylx ) , Tyapp ( tsy , tyly ) -> ts_equal tsx tsy && List . for_all2 ty_equal tylx tyly | _ -> false
module Ts = struct type t = tysymbol let equal = ts_equal let hash x = x . ts_ident . id_tag let compare x y = Ident . compare x . ts_ident y . ts_ident end
module Mts = Map . Make ( Ts )
module Hts = Hashtbl . Make ( Ts )
let ts id args = { ts_ident = id ; ts_args = args ; ts_alias = None }
let mk_ts id args alias = { ts_ident = id ; ts_args = args ; ts_alias = alias }
let ts_ident ts = ts . ts_ident
let ts_args ts = ts . ts_args
let ts_alias ts = ts . ts_alias
let ts_arity ts = List . length ts . ts_args
let fresh_ty_var ( ? loc = Location . none ) s = { ty_node = Tyvar { tv_name = Ident . create ~ loc s } }
let ty_of_var tv = { ty_node = Tyvar tv }
let ty_app ts tyl = if ts_arity ts = List . length tyl then { ty_node = Tyapp ( ts , tyl ) } else W . error ~ loc : ts . ts_ident . id_loc ( W . Bad_type_arity ( ts . ts_ident . id_str , ts_arity ts , List . length tyl ) )
let rec ty_full_inst m ty = match ty . ty_node with | Tyvar tv -> Mtv . find tv m | Tyapp ( ts , tyl ) -> ty_app ts ( List . map ( ty_full_inst m ) tyl )
let ts_match_args ts tl = try List . fold_right2 Mtv . add ts . ts_args tl Mtv . empty with Invalid_argument _ -> W . error ~ loc : ts . ts_ident . id_loc ( W . Bad_type_arity ( ts . ts_ident . id_str , ts_arity ts , List . length tl ) )
let ty_app ts tyl = match ts . ts_alias with | None -> ty_app ts tyl | Some ty -> ty_full_inst ( ts_match_args ts tyl ) ty
let rec ts_subst_ts old_ts new_ts ( { ts_ident ; ts_args ; ts_alias } as ts ) = if ts_equal old_ts ts then new_ts else let ts_alias = Option . map ( ty_subst_ts old_ts new_ts ) ts_alias in mk_ts ts_ident ts_args ts_alias match ty . ty_node with | Tyvar _ -> ty | Tyapp ( ts , tyl ) -> let ts = if ts_equal old_ts ts then new_ts else ts in ty_app ts ( List . map ( ty_subst_ts old_ts new_ts ) tyl )
let rec ty_subst_ty old_ts new_ts new_ty ty = match ty . ty_node with | Tyvar _ -> ty | Tyapp ( ts , tyl ) -> if ts_equal old_ts ts then ty_full_inst ( ts_match_args new_ts tyl ) new_ty else let subst ty = ty_subst_ty old_ts new_ts new_ty ty in let tyl = List . map subst tyl in ty_app ts tyl let subst ty = ty_subst_ty old_ts new_ts new_ty ty in let ts_alias = Option . map subst ts . ts_alias in mk_ts ts . ts_ident ts . ts_args ts_alias
let rec ty_match mtv ty1 ty2 = let set = function | None -> Some ty2 | Some ty1 as r when ty_equal ty1 ty2 -> r | _ -> raise Exit in match ( ty1 . ty_node , ty2 . ty_node ) with | Tyvar tv1 , _ -> Mtv . update tv1 set mtv | Tyapp ( ts1 , tyl1 ) , Tyapp ( ts2 , tyl2 ) when ts_equal ts1 ts2 -> List . fold_left2 ty_match mtv tyl1 tyl2 | _ -> raise Exit
let ty_match mtv ty1 ty2 = let rec ty_inst mtv ty = match ty . ty_node with | Tyvar n -> ( try Mtv . find n mtv with Not_found -> ty ) | Tyapp ( ts , tyl ) -> { ty_node = Tyapp ( ts , List . map ( ty_inst mtv ) tyl ) } in try ty_match mtv ty1 ty2 with Exit -> raise ( TypeMismatch ( ty_inst mtv ty1 , ty2 ) )
let ty_equal_check ty1 ty2 = if not ( ty_equal ty1 ty2 ) then raise ( TypeMismatch ( ty1 , ty2 ) )
let ts_unit = ts ( Ident . create ~ loc : Location . none " unit " ) [ ]
let ts_integer = ts ( Ident . create ~ loc : Location . none " integer " ) [ ]
let ts_int = ts ( Ident . create ~ loc : Location . none " int " ) [ ]
let ts_char = ts ( Ident . create ~ loc : Location . none " char " ) [ ]
let ts_bytes = ts ( Ident . create ~ loc : Location . none " bytes " ) [ ]
let ts_string = ts ( Ident . create ~ loc : Location . none " string " ) [ ]
let ts_float = ts ( Ident . create ~ loc : Location . none " float " ) [ ]
let ts_bool = ts ( Ident . create ~ loc : Location . none " bool " ) [ ]
let ts_exn = ts ( Ident . create ~ loc : Location . none " exn " ) [ ]
let ts_array = ts ( Ident . create ~ loc : Location . none " array " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_list = ts ( Ident . create ~ loc : Location . none " list " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_option = ts ( Ident . create ~ loc : Location . none " option " ) [ fresh_tv ~ loc : Location . none " a " ]
let ts_int32 = ts ( Ident . create ~ loc : Location . none " int32 " ) [ ]
let ts_int64 = ts ( Ident . create ~ loc : Location . none " int64 " ) [ ]
let ts_nativeint = ts ( Ident . create ~ loc : Location . none " nativeint " ) [ ]