Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file psl.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149moduleResult=Biocaml_resultopenCFStreamtypeitem={matches:int;mismatches:int;rep_matches:int;n_count:int;q_num_insert:int;q_base_insert:int;t_num_insert:int;t_base_insert:int;q_name:string;q_strand:char;q_size:int;q_start:int;q_end:int;t_name:string;t_strand:charoption;t_size:int;t_start:int;t_end:int;block_count:int;block_sizes:intlist;q_starts:intlist;t_starts:intlist;}[@@derivingsexp]moduleError=structtypet=[|`incomplete_inputofPos.t*stringlist*stringoption|`invalid_intofPos.t*string*string|`invalid_strandsofPos.t*string*string|`invalid_number_of_columnsofPos.t*string*int]endletparse_intmsgposs=tryOk(int_of_string(String.strips))with_->Error(`invalid_int(pos,msg,s))letparse_comma_intsmsgposs=(* PSL files from BLAT include extra ending comment,
so strip that too in addition to whitespace *)letdrop=function' '|'\n'|'\t'|'\r'|','->true|_->falseinString.strip~drops|>String.split~on:','|>Result.List.mapi~f:(fun_->parse_intmsgpos)letparse_strings=Ok(String.strips)letparse_strandsmsgposs=matchString.stripswith|"+"->Ok('+',None)|"-"->Ok('-',None)|"++"->Ok('+',Some'+')|"+-"->Ok('+',Some'-')|"-+"->Ok('-',Some'+')|"--"->Ok('-',Some'-')|s->Error(`invalid_strands(pos,msg,s))letparse_lineposline=letopenResult.Monad_infixinmatchLine.split~on:'\t'linewith|[matches;mismatches;rep_matches;n_count;q_num_insert;q_base_insert;t_num_insert;t_base_insert;strands;q_name;q_size;q_start;q_end;t_name;t_size;t_start;t_end;block_count;block_sizes;q_starts;t_starts]->parse_int"matches"posmatches>>=funmatches->parse_int"mismatches"posmismatches>>=funmismatches->parse_int"rep_matches"posrep_matches>>=funrep_matches->parse_int"n_count"posn_count>>=funn_count->parse_int"q_num_insert"posq_num_insert>>=funq_num_insert->parse_int"q_base_insert"posq_base_insert>>=funq_base_insert->parse_int"t_num_insert"post_num_insert>>=funt_num_insert->parse_int"t_base_insert"post_base_insert>>=funt_base_insert->parse_strands"strands"posstrands>>=fun(q_strand,t_strand)->parse_stringq_name>>=funq_name->parse_int"q_size"posq_size>>=funq_size->parse_int"q_start"posq_start>>=funq_start->parse_int"q_end"posq_end>>=funq_end->parse_stringt_name>>=funt_name->parse_int"t_size"post_size>>=funt_size->parse_int"t_start"post_start>>=funt_start->parse_int"t_end"post_end>>=funt_end->parse_int"block_count"posblock_count>>=funblock_count->parse_comma_ints"block_sizes"posblock_sizes>>=funblock_sizes->parse_comma_ints"q_starts"posq_starts>>=funq_starts->parse_comma_ints"t_starts"post_starts>>=funt_starts->Ok{matches;mismatches;rep_matches;n_count;q_num_insert;q_base_insert;t_num_insert;t_base_insert;q_name;q_strand;q_size;q_start;q_end;t_name;t_strand;t_size;t_start;t_end;block_count;block_sizes;q_starts;t_starts}|l->Error(`invalid_number_of_columns(pos,(line:Line.t:>string),List.lengthl))letline_to_item=parse_lineletversion_line="psLayout version 3"letis_spaces_line=String.for_all~f:((=)' ')letheader_line1="match\tmis- \trep. \tN's\tQ gap\tQ gap\tT gap\tT gap\tstrand\tQ \tQ \tQ \tQ \tT \tT \tT \tT \tblock\tblockSizes \tqStarts\t tStarts"letheader_line2=" \tmatch\tmatch\t \tcount\tbases\tcount\tbases\t \tname \tsize\tstart\tend\tname \tsize\tstart\tend\tcount"letis_dashes_line=String.for_all~f:((=)'-')moduleTransform=structletstring_to_item?filename()=letname=sprintf"psl_parser:%s"(Option.value~default:"<>"filename)inLines.Transform.make_merge_error~name?filename~next:(funlinebuf->letopenLines.Bufferinletrecget_line()=matchnext_linelinebufwith|None->`not_ready|Someline->letline'=(line:>string)inifline'=version_line||is_spaces_lineline'||line'=header_line1||line'=header_line2||is_dashes_lineline'thenget_line()else`output(line_to_item(current_positionlinebuf)line)inget_line())()endletin_channel_to_item_stream?(buffer_size=65536)?filenameinp=Tfxm.in_channel_strings_to_stream~buffer_sizeinp(Transform.string_to_item?filename())exceptionErrorofError.tleterror_to_exnerr=Errorerrletin_channel_to_item_stream_exn?(buffer_size=65536)?filenameinp=Stream.result_to_exn~error_to_exn(in_channel_to_item_stream~buffer_size?filenameinp)