Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file cel.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155openCFStreamtypeidata={mean:float;stdv:float;npixels:int}typeirow={xcoord:int;ycoord:int;idata:idata}typeisection=irowlistleticolumns=["X";"Y";"MEAN";"STDV";"NPIXELS"]letisection_name="INTENSITY"letinum_values=List.lengthletifoldfinitl=List.fold_left~f~initlletiiterfl=List.iter~fltypet=isection(* retaining only intensity section for now *)exceptionBadofstringletraise_badmsg=raise(Badmsg)(* Hashtbl representation of intensity data. *)moduleTbl=structmoduleHT=Caml.Hashtbl(* hash table of (mean,stdv,npixels) data *)letof_cel1(cel:t):(int*int,idata)HT.t=lettbl=HT.create(inum_valuescel)inletfr=HT.addtbl(r.xcoord,r.ycoord)r.idatainiiterfcel;tbl(* hash table of mean data *)letof_cel2(cel:t):(int*int,float)HT.t=lettbl=HT.create(inum_valuescel)inletfr=HT.addtbl(r.xcoord,r.ycoord)r.idata.meaniniiterfcel;tbl(* like HT.find but throws more informative exception *)letfindtbl(x,y)=tryHT.findtbl(x,y)withCaml.Not_found->failwith(Msg.err(sprintf"CEL file does not have values for probe \
at position x = %d, y = %d"xy))endletdatabpmapcels=letcels=List.map~f:Tbl.of_cel1celsinletfansr=letdatl=List.mapcels~f:(funcel->Tbl.findcelr.Bpmap.pmcoord,Tbl.findcelr.Bpmap.mmcoord)in(r.Bpmap.probe,datl)::ansinBpmap.foldf[]bpmapletpm_mmbpmapcels=letcels=List.map~f:Tbl.of_cel2celsinletfansr=letdatl=List.mapcels~f:(funcel->(Tbl.findcelr.Bpmap.pmcoord)-.(Tbl.findcelr.Bpmap.mmcoord))in(r.Bpmap.probe,datl)::ansinBpmap.foldf[]bpmapletpmbpmapcels=letcels=List.map~f:Tbl.of_cel2celsinletfansr=letdatl=List.mapcels~f:(funcel->Tbl.findcelr.Bpmap.pmcoord)in(r.Bpmap.probe,datl)::ansinBpmap.foldf[]bpmapletmmbpmapcels=letcels=List.map~f:Tbl.of_cel2celsinletfansr=letdatl=List.map~f:(funcel->Tbl.findcelr.Bpmap.mmcoord)celsin(r.Bpmap.probe,datl)::ansinBpmap.foldf[]bpmapmoduleParser=struct(** parse string of form "\[sss\]" *)letsection_names=lets=String.stripsinletl=String.lengthsinifl<2||notChar.(s.[0]='['&&s.[l-1]=']')thenNoneelseSome(String.slices1(l-1))letline_is_sectionsec_namel=matchsection_namelwith|None->false|Somes->String.(s=sec_name)letintensity_rows=letto_ints=Int.of_string(String.strips)inletto_floats=Float.of_string(String.strips)inmatchString.splits~on:'\t'with|[xcoord;ycoord;mean;stdv;npixels]->{xcoord=to_intxcoord;ycoord=to_intycoord;idata={mean=to_floatmean;stdv=to_floatstdv;npixels=to_intnpixels}}|_->raise_bad"expecting 5 columns"(** lines should point to beginning of intensity section,
upon return lines will point to first blank line after data rows *)letintensity_sectionlines=assert(matchStream.peeklineswith|None->false|Somel->line_is_sectionisection_namel);Stream.junklines;letsl=String.split(Stream.next_exnlines)~on:'='inletnum_cells=int_of_string(String.strip(List.nth_exnsl1))inletsl=String.split(Stream.next_exnlines)~on:'='inletsl=String.split(List.nth_exnsl1)~on:'\t'inletsl=List.map~f:String.stripslinlet()=ifPoly.(sl<>icolumns)thenraise_bad"intensity section column names incorrect"inletlines=Stream.take_while~f:(funs->not(String.for_alls~f:Char.is_whitespace))linesinletlines=Stream.map~f:intensity_rowlinesinletans=Stream.to_listlinesinletcount=List.lengthansinifcount=num_cellsthenanselseraise_bad(sprintf"expected %d intensity rows but found %d"num_cellscount)letcelfile=letof_channelcin=letlines=Lines.of_channelcininleterrmsg=Msg.err~pos:(Pos.make~source:file~line:(Stream.countlines)())msgintryStream.drop_while~f:(fun(s:Lines.item)->not(line_is_sectionisection_name(s:>string)))lines;ifStream.is_emptylinesthenfailwith(isection_name^" section not found");intensity_section(Stream.maplines~f:(fun(x:Lines.item)->(x:>string)))withFailuremsg|Badmsg->raise_bad(errmsg)inIn_channel.with_filefile~f:of_channelendletof_file=Parser.celletof_file_optfile=trySome(of_filefile)withBad_->None