Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file bar.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114openCFStreamtypeheader=(string*string)list(* list of tag-value pairs *)typesection={sec_num:int;sec_name:string;sec_data:(int*float)list(* stored in ascending order by int *)}typet=header*sectionlist(* section list in ascending order by sec_name *)exceptionBadofstringletraise_badmsg=raise(Badmsg)let(<--)ab=funx->a(bx)letget_assoc_exnal=List.Assoc.find_exn~equal:String.equallaletnum_sections=List.length<--sndletdata_type=get_assoc_exn"Data"<--fstletscale=get_assoc_exn"Scale"<--fstletgenomic_map=get_assoc_exn"Genomic_Map"<--fstletalg_name=get_assoc_exn"AlgName"<--fstletalg_version=get_assoc_exn"AlgVersion"<--fstletcoord_convention=get_assoc_exn"probe_coordinate_convention"<--fstletsections=sndletsection(_,secs)nm=matchList.find~f:(funs->String.(s.sec_name=nm))secswith|None->failwith(sprintf"section %s not found"nm)|Somes->sletsectioni(_,secs)i=matchList.find~f:(funs->s.sec_num=i)secswith|None->failwith(sprintf"section %d not found"i)|Somes->sletto_list(_,sections)=letfs=letchr=s.sec_nameinList.map~f:(fun(i,v)->chr,i,v)s.sec_datainList.concat(List.map~fsections)moduleParser=structletjunk_blank_lineslines=Stream.drop_while~f:(String.for_all~f:Char.is_whitespace)lineslettag_value(s':string):string*string=lets=String.strip(String.drop_prefixs'1)inmatchString.splits~on:'\t'with|[t;v]->(t,v)|_->raise_bad(sprintf"invalid tag-value pair %s"s')(* lines should point to beginning of file, upon return will point
to start of first section *)letheaderlines=letlines'=Stream.take_while~f:(funs->not(String.for_all~f:Char.is_whitespaces))linesinletfaccuml=(tag_valuel)::accuminletans=List.rev(Stream.fold~f~init:[]lines')injunk_blank_lineslines;ans(* lines should point to start of a section, upon return will point
to start of next section or end of file *)letsectionlines=lettvlines=snd(tag_value(Stream.next_exnlines))inletseq_num=int_of_string(tvlines)inletseq_name=tvlinesinletnum_hits=int_of_string(tvlines)injunk_blank_lineslines;letlines'=Stream.take_while~f:(funs->not(String.for_all~f:Char.is_whitespaces))linesinletparse_lines=matchString.splits~on:'\t'with|[i;f]->(Int.of_stringi,Float.of_stringf)|_->raise_bad("data row must contain exactly two fields")inletdata=Stream.to_list(Stream.map~f:parse_linelines')inletdata=List.sort~compare:(fun(p1,_)(p2,_)->Stdlib.comparep1p2)datainletsec={sec_num=seq_num;sec_name=seq_name;sec_data=data}inifList.lengthdata=num_hitsthen(junk_blank_lineslines;sec)elseraise_bad(sprintf"expected %d hits but found %d"num_hits(List.lengthdata))letof_filefile=letof_channelcin=letlines=Stream.map~f:(fun(x:Lines.item)->String.rstrip(x:>string))(Lines.of_channelcin)inleterrmsg=Msg.err~pos:(Pos.make~source:file~line:(Stream.countlines)())msgintrylethdr=headerlinesinletsecs=ref[]inlet()=whilenot(Stream.is_emptylines)dosecs:=(sectionlines)::!secsdoneinletsecs=List.sort~compare:(funs1s2->Stdlib.compares1.sec_names2.sec_name)!secsinletexpected_num_secs=int_of_string(get_assoc_exn"Number Sequences"hdr)inletactual_num_secs=List.lengthsecsinifactual_num_secs=expected_num_secsthen(hdr,secs)elseraise_bad(sprintf"expected %d sequences but found %d"expected_num_secsactual_num_secs)withFailuremsg|Badmsg->raise_bad(errmsg)inIn_channel.with_filefile~f:of_channelendletof_file=Parser.of_file