Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file genomeMap.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182openCFStreamopenStream.InfixmoduletypeChromosome=sigtypetvalcompare:t->t->intendmoduleMake(Chromosome:Chromosome)=structtyperange=Range.ttypelocation=Chromosome.t*rangemoduleMap=structincludeMap.Make(structincludeChromosomeletsexp_of_t_=assertfalselett_of_sexp_=assertfalseend)letto_streamt=Stream.of_list(to_alistt)letof_streamxs=Stream.foldxs~init:empty~f:(funaccu(key,data)->setaccu~key~data)endmoduleSelection=structtypet=Iset.tMap.tletempty=Map.emptyletaddsel(chr,{Range.lo;hi})=letset_chr=matchMap.findselchrwith|None->Iset.empty|Somes->sinletset_chr=Iset.add_rangeset_chrlohiinMap.setsel~key:chr~data:set_chrletinteruv=Map.foldu~init:Map.empty~f:(fun~key:k~data:set_uaccu->matchMap.findvkwith|Someset_v->Map.setaccu~key:k~data:(Iset.interset_uset_v)|None->accu)letunionuv=letkeys=List.dedup_and_sort~compare:Chromosome.compare(Map.keysu@Map.keysv)inList.foldkeys~init:Map.empty~f:(funaccuk->Map.setaccu~key:k~data:(Iset.union(Option.value(Map.finduk)~default:Iset.empty)(Option.value(Map.findvk)~default:Iset.empty)))letdiffuv=Map.foldu~init:Map.empty~f:(fun~key:k~data:set_uaccu->letset_u'=matchMap.findvkwith|Someset_v->Iset.diffset_uset_v|None->set_uinMap.set~key:k~data:set_u'accu)letsizex=Map.foldx~init:0~f:(fun~key:_~data:setaccu->Iset.cardinalset+accu)letoverlapsel(k,r)=Iset.(matchMap.findselkwith|Somex->interRange.(add_rangeemptyr.lor.hi)x|>cardinal|None->0)letintersectssel(k,r)=Option.value_map(Map.findselk)~default:false~f:(funx->Range.(Iset.intersects_rangexr.lor.hi))letto_streamsel=Map.to_streamsel|>Stream.map~f:(fun(k,s)->Stream.map(Iset.to_streams)~f:(fun(lo,hi)->k,ok_exn(Range.makelohi)))|>Stream.concatletof_streame=letaccu=Accu.create~bin:fst~zero:Iset.empty~add:(fun(_,r)->Range.(funx->Iset.add_rangexr.lor.hi))()inStream.iter~f:(funloc->Accu.addacculocloc)e;Map.of_stream(Accu.streamaccu)endmoduletypeSignal=sigtype'atvaleval:'at->default:'a->Chromosome.t->int->'a(** function evaluation at some point in the genome *)valfold:'at->init:'c->f:('c->location->'b->'c)->'c(** folds on constant intervals of the function, in increasing order *)valto_stream:'at->(location*'a)Stream.t(** enumeration over all constant intervals of the function, in
increasing order *)valof_stream:('a->'a->'a)->(location*'a)Stream.t->'atendmoduleLMap=structmoduleT=Interval_treetype'at='aT.tMap.tletintersectslmap(k,r)=Option.value_map(Map.findlmapk)~default:false~f:(funx->Range.(T.intersectsx~low:r.lo~high:r.hi))letclosestlmap(k,r)=Option.bind(Map.findlmapk)~f:Range.(funx->tryletlo,hi,label,d=T.find_closestr.lor.hixinSome((k,ok_exn(makelohi)),label,d)withT.Empty_tree->None)letintersecting_elemslmap(k,{Range.lo;hi})=matchMap.findlmapkwith|Somex->T.find_intersecting_elemlohix/@(fun(lo,hi,x)->(k,ok_exn(Range.makelohi)),x)|None->Stream.empty()letto_streamlmap=(Map.to_streamlmap)/@(fun(k,t)->Stream.map~f:(fun(lo,hi,x)->(k,ok_exn(Range.makelohi)),x)(T.to_streamt))|>Stream.concatletof_streame=letaccu=Accu.create~bin:(funx->fstx|>fst)~zero:T.empty~add:(fun((_,r),v)->Range.(T.add~data:v~low:r.lo~high:r.hi))()inStream.iter~f:(funloc->Accu.addacculocloc)e;Map.of_stream(Accu.streamaccu)endmoduleLSet=structmoduleT=Interval_treetypet=unitT.tMap.tletintersects=LMap.intersectsletclosestlsetloc=Option.map(LMap.closestlsetloc)~f:(fun(loc',(),d)->loc',d)letintersecting_elemslsetloc=LMap.intersecting_elemslsetloc/@fstletto_streamlset=LMap.to_streamlset/@fstletof_streame=e/@(funx->x,())|>LMap.of_streamendend