fasta_file = FASTA(sys.argv[1]) fasta_file.read() alphabet = list(set(fasta_file.data)) alphabet.sort() tree = WaveletTree() tree.build(alphabet, fasta_file.data) if task == 'access': index = int(sys.argv[4]) result = tree.access(index) elif task == 'rank': position = int(sys.argv[4]) character = sys.argv[5] result = tree.rank(position, character) elif task == 'select': nth_occurence = int(sys.argv[4]) character = sys.argv[5] result = tree.select(nth_occurence, character) elif task == 'build': result = 'OK' # Save result to out file out_file = open(sys.argv[2], 'w') out_file.write(str(result)) out_file.close()
fasta_file = FASTA(sys.argv[1]) fasta_file.read() alphabet = list(set(fasta_file.data)) alphabet.sort() tree = WaveletTree() tree.build(alphabet, fasta_file.data) if task == 'access': index = int(sys.argv[4]) result = tree.access(index) elif task == 'rank': position = int(sys.argv[4]) character = sys.argv[5] result = tree.rank(position, character) elif task == 'select': nth_occurence = int(sys.argv[4]) character = sys.argv[5] result = tree.select(nth_occurence, character) elif task == 'build': result = 'OK' # Save result to out file out_file = open(sys.argv[2], 'w') out_file.write(str(result)) out_file.close()
stopwatch = Utils.Stopwatch() time_access = 0 time_select = 0 time_rank = 0 for i in xrange(test_runs): # Access stopwatch.restart() stopwatch.start() tree.access(test_idx) stopwatch.stop() time_access = time_access + stopwatch.elapsed_ms() # Select stopwatch.restart() stopwatch.start() tree.select(test_nth_occurence, test_character) stopwatch.stop() time_select = time_select + stopwatch.elapsed_ms() stopwatch.restart() # Rank stopwatch.start() tree.rank(test_idx, test_character) stopwatch.stop() time_rank += stopwatch.elapsed_ms() time_select /= test_runs time_rank /= test_runs time_access /= test_runs report_3(read_stopwatch, build_stopwatch, time_select, time_rank,
stopwatch = Utils.Stopwatch() time_access = 0 time_select = 0 time_rank = 0 for i in xrange(test_runs): # Access stopwatch.restart() stopwatch.start() tree.access(test_idx) stopwatch.stop() time_access = time_access + stopwatch.elapsed_ms() # Select stopwatch.restart() stopwatch.start() tree.select(test_nth_occurence, test_character) stopwatch.stop() time_select = time_select + stopwatch.elapsed_ms() stopwatch.restart() # Rank stopwatch.start() tree.rank(test_idx, test_character) stopwatch.stop() time_rank += stopwatch.elapsed_ms() time_select /= test_runs time_rank /= test_runs time_access /= test_runs report_3(read_stopwatch, build_stopwatch, time_select, time_rank, time_access)