12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061typet=int[@@derivingsexp]typeoffset=[`Offset33|`Offset64][@@derivingsexp]letint_of_offset=function`Offset33->33|`Offset64->64letmin_as_char=int_of_offsetletmax_as_char=126letround_float_to_intx=ifFloat.(mod_floatx1.0<0.5)thenFloat.(to_int(round_downx))elseFloat.(to_int(round_upx))letto_intt=tletto_probabilityt=10.0**(Float.of_intt/.-10.0)letto_char?(offset=`Offset33)t=letoffset'=int_of_offsetoffsetinletx=t+offset'inifoffset'<=x&&x<=max_as_charthenOk(Char.of_int_exnx)elseerror"cannot convert PHRED score with requested offset to a \
visible ASCII character"(t,offset)[%sexp_of:t*offset]letof_intx=ifx>=0thenOkxelseerror"invalid PHRED score"xsexp_of_intletof_char?(offset=`Offset33)x=letoffset'=int_of_offsetoffsetinletc=Char.to_intxinifoffset'<=c&&c<=max_as_charthenOk(c-offset')elseerror"character with given offset is not a valid PHRED score"(x,offset)[%sexp_of:char*offset]letof_probability?(f=round_float_to_int)x=ifFloat.(0.0<x&&x<=1.0)thenOk(f(-10.*.Float.log10x))elseerror"invalid probability"xsexp_of_floatletof_solexa_score?(f=round_float_to_int)x=f(10.*.Float.log10((10.**(Float.of_intx/.10.))+.1.))letto_solexa_score?(f=round_float_to_int)t=f(10.*.Float.log10((10.**(Float.of_intt/.10.))-.1.))