| 
									
										
										
										
											2008-02-16 23:17:41 -05:00
										 |  |  | USING: kernel io io.files splitting strings io.encodings.ascii | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  |        hashtables sequences assocs math namespaces prettyprint | 
					
						
							| 
									
										
										
										
											2008-02-01 19:26:32 -05:00
										 |  |  |        math.parser combinators arrays sorting unicode.case ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | IN: benchmark.knucleotide | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : float>string ( float places -- string )
 | 
					
						
							|  |  |  |     swap >float number>string | 
					
						
							|  |  |  |     "." split1 rot
 | 
					
						
							|  |  |  |     over length over <
 | 
					
						
							|  |  |  |     [ CHAR: 0 pad-right ]  | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     [ head ] if "." swap 3append ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : discard-lines ( -- )
 | 
					
						
							|  |  |  |     readln
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     [ ">THREE" head? [ discard-lines ] unless ] when* ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : read-input ( -- input )
 | 
					
						
							|  |  |  |     discard-lines | 
					
						
							|  |  |  |     ">" read-until drop
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     CHAR: \n swap remove >upper ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : tally ( x exemplar -- b )
 | 
					
						
							|  |  |  |     clone tuck | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |       [ [ 1+ ] [ 1 ] if* ] change-at
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     ] curry each ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : small-groups ( x n -- b )
 | 
					
						
							|  |  |  |     swap
 | 
					
						
							|  |  |  |     [ length swap - 1+ ] 2keep
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     [ >r over + r> subseq ] 2curry map ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : handle-table ( inputs n -- )
 | 
					
						
							|  |  |  |     small-groups | 
					
						
							|  |  |  |     [ length ] keep
 | 
					
						
							|  |  |  |     H{ } tally >alist
 | 
					
						
							|  |  |  |     sort-values reverse
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |       dup first write bl
 | 
					
						
							|  |  |  |       second 100 * over / 3 float>string print
 | 
					
						
							|  |  |  |     ] each
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     drop ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : handle-n ( inputs x -- )
 | 
					
						
							|  |  |  |     tuck length
 | 
					
						
							|  |  |  |     small-groups H{ } tally | 
					
						
							|  |  |  |     at [ 0 ] unless*
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     number>string 8 CHAR: \s pad-right write ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : process-input ( input -- )
 | 
					
						
							|  |  |  |     dup 1 handle-table nl
 | 
					
						
							|  |  |  |     dup 2 handle-table nl
 | 
					
						
							|  |  |  |     { "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" } | 
					
						
							|  |  |  |     [ [ dupd handle-n ] keep print ] each
 | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     drop ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : knucleotide ( -- )
 | 
					
						
							|  |  |  |     "extra/benchmark/knucleotide/knucleotide-input.txt" resource-path | 
					
						
							| 
									
										
										
										
											2008-02-16 23:17:41 -05:00
										 |  |  |     ascii [ read-input ] with-file-reader | 
					
						
							| 
									
										
										
										
											2007-11-25 00:50:12 -05:00
										 |  |  |     process-input ;
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:55:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | MAIN: knucleotide |