<jupyter_start><jupyter_text>Dependency code<jupyter_code>import imp
import os
import sys
import numpy as np
import glob
import cmdbench

fp, pathname, description = imp.find_module('benchmark', ['../lib'])
benchmark = imp.load_module('benchmark', fp, pathname, description)

# Summarize numpy array if it has more than 10 elements
np.set_printoptions(threshold=10)<jupyter_output><empty_output><jupyter_text>Software versionsCOBS will have to be built directly from source . Version used is commit `1915fc061bbe47946116b4a051ed7b4e3f3eca15`. I have included the binary in the directory `../lib/bin`.<jupyter_code>cobs_bin = '../lib/bin/cobs'
!ls ../lib/bin
!{cobs_bin}<jupyter_output><empty_output><jupyter_text>Benchmarking Input data and constants<jupyter_code>input_dir = '../data/input-files/reads'

input_files_1 = [os.path.basename(f) for f in glob.glob(f'{input_dir}/*_1.fastq.gz')]
input_samples = [f.replace('_1.fastq.gz','') for f in input_files_1]
input_samples.sort()
print(input_samples)

nproc=32
kmer=31
hashes=3

sample_sizes = [1,10,20,30,40,50,60,70,80]

benchmark.create_folder_if_doesnt_exist("cobs-data")
benchmark.create_folder_if_doesnt_exist("cobs-data/samples")<jupyter_output><empty_output><jupyter_text>Benchmark functions<jupyter_code>def sampling_func(sample_size):
    # Copy files we want to be part of the sample
    # from inputs to cobs-data/samples/ and return their path
    samples = input_samples[:sample_size]
    samples_out = []
    for sample in samples:
        infile1, infile2 = os.path.abspath(f"{input_dir}/{sample}_1.fastq.gz"), os.path.abspath(f"{input_dir}/{sample}_2.fastq.gz")
        outfile1, outfile2 = f"cobs-data/samples/{sample}_1.fastq.gz", f"cobs-data/samples/{sample}_2.fastq.gz"
        os.symlink(infile1, outfile1)
        os.symlink(infile2, outfile2)
    return ["cobs-data/samples/"]

def reset_func():
    benchmark.clean_if_exists("cobs-data/samples/")
    benchmark.clean_if_exists("cobs-data/example.cobs_compact")
    benchmark.clean_if_exists("cobs-data/example.cobs_compact.tmp")

build_command = {
    "command": f"{cobs_bin} compact-construct -k {kmer} --threads {nproc} --num-hashes {hashes} cobs-data/samples/ cobs-data/example.cobs_compact",
}

query_repeat_count = 2
query_sequence = "GAAGAAGATGGTGTACGCGGTGCGCGCCGCTATCTCGACCACCTTAAAATGGAATATGCCTTCTGGATGGACG"

query_command = {
    "command": f"{cobs_bin} query -i cobs-data/example.cobs_compact %",
    "parallel_argfiles": [query_sequence] * query_repeat_count,
    "parallel_args": f"-j {nproc} -I%"
}<jupyter_output><empty_output><jupyter_text>Benchmark<jupyter_code>multibench_results, debug_str = benchmark.multibench.multi_cmdbench({
        "index": [build_command],
        "query": [query_command]
    },
    reset_func = reset_func, iterations = 1, sampling_func = sampling_func, sample_sizes = sample_sizes, 
    benchmark_list_to_results=benchmark.benchmark_list_to_results, active_output_print = True
)<jupyter_output><empty_output><jupyter_text>Save and reload results<jupyter_code>save_path = "cobs-results.txt"

samples_per_sample_size = []
for sample_size in sample_sizes:
        samples_per_sample_size.append(input_samples[:sample_size])

benchmark.multibench.save_multibench_results(multibench_results, samples_per_sample_size, save_path)
multibench_results, samples_per_sample_size = benchmark.multibench.read_multibench_results(save_path)
print(samples_per_sample_size)<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
from pylab import rcParams
rcParams['figure.figsize'] = 15, 3
# Indexing Plots
benchmark.multibench.plot_resources(multibench_results, sample_sizes, "index")
# Querying Plots
benchmark.multibench.plot_resources(multibench_results, sample_sizes, "query")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11819354838709678, 'fraction_numerical': 0.01858064516129032, 'mean_word_length': 6.43953934740883, 'pattern_counts': {'":': 6, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '169985', 'license': 'Apache-2.0', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1405, 'n_words': 227, 'path': 'cobs/Benchmark-COBS.ipynb', 'repo_name': 'apetkau/thesis-benchmarking', 'size': '3875'}