<jupyter_start><jupyter_text>Paper Figure 4: SearchThis notebook uses GPU, so please run in an environment with CUDA installed.<jupyter_code>import os
from test_files import get_files, prepare_test

files = ['thermo_HeLa.raw', 'human.fasta']
!nvcc --version
tmp_folder = os.path.join(os.getcwd(),'temp/')
test_folder = 'fig4'
get_files(tmp_folder, files)
prepare_test(files, tmp_folder, test_folder)<jupyter_output>Creating dir F:\alphapept\sandbox\temp/fig4.<jupyter_text>Convert raw and find features<jupyter_code>import alphapept.settings
import alphapept.paths
import alphapept.interface
import alphapept.fasta

test_folder = os.path.join(tmp_folder, test_folder)

file_name = os.path.join(test_folder, files[0])
settings = alphapept.settings.load_settings(alphapept.paths.DEFAULT_SETTINGS_PATH)
settings['experiment']['file_paths'] = [file_name]
settings['experiment']['fasta_paths'] = [os.path.join(test_folder, files[1])]
settings['experiment']['database_path'] = os.path.join(test_folder, 'database.hdf')

settings_ = alphapept.interface.create_database(settings)
settings_ = alphapept.interface.import_raw_data(settings)
settings_ = alphapept.interface.feature_finding(settings)
base, ext = os.path.splitext(file_name)
ms_file_ = alphapept.io.MS_Data_File(f"{base}.ms_data.hdf", is_read_only=True)
query_data = ms_file_.read_DDA_query_data()

query_data = ms_file_.read_DDA_query_data(
    calibrated_fragments=True,
    database_file_name=settings['experiment']['database_path']
)

db_data = alphapept.fasta.read_database(settings['experiment']['database_path'])
features = ms_file_.read(dataset_name="features")
import alphapept.search
from time import time
import importlib

timing_dict = {}
for mode in ['cuda','numba-multithread','numba','python']:

    alphapept.performance.set_compilation_mode(mode)

    importlib.reload(alphapept.search)
    start = time()
    psms, num_specs_compared = alphapept.search.get_psms(query_data, db_data, features, **settings["search"])
    end = time()

    print(f"Time elapsed {end-start}, found {len(psms):,}")
    
    
    timing_dict[mode] = end-start
timing_dict = {'cuda': 104.90830993652344,
 'numba-multithread': 12.823620080947876,
 'numba': 125.81679391860962,
 'python': 83825.712246418}
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib

dark_blue = '#17212b'
light_blue = '#3dc5ef'
teal= '#42dee1'
green = '#6eecb9'
yellow = '#eef5b3'

colors = [light_blue, teal, green, yellow]
data = pd.DataFrame(timing_dict.values(), index = timing_dict.keys())
data = data.sort_values(0)

hfont = {'fontname':'Arial', 'size':10}
plt.figure(figsize=(2.363,2.363)) #60x60


python_time = timing_dict['python']/60/60
text = [f'Python ({python_time:.1f} h)', f"Numba ({timing_dict['numba']:.1f} s)", f"Cuda ({timing_dict['cuda']:.1f} s)", f"Numba, threaded ({timing_dict['numba-multithread']:.1f} s)"]

height=0.5

for i in range(len(data)): 
    t = data.iloc[i][0]
    plt.barh(i, t, height, color = colors[i], linewidth=1, edgecolor='black')
    
    if i == 3:
        plt.text(t/1000, i, text[::-1][i], **hfont, va='center')
    else:
        plt.text(t*1.2, i, text[::-1][i], **hfont, va='center')

plt.yticks(range(len(data)), data.index, **hfont)
plt.xticks(**hfont)

plt.xscale('log')
plt.xlim([0, 100000])
plt.xlabel('Time (seconds)', **hfont)

ax = plt.gca()
ax.set_yticklabels([])
plt.xticks([1e1, 1e2 , 1e3, 1e4, 1e5])

plt.tight_layout()
plt.savefig('./figures/04_search.pdf')  
plt.show()<jupyter_output>C:\Users\admin\AppData\Local\Temp/ipykernel_16816/2714091246.py:38: UserWarning: Attempted to set non-positive left xlim on a log-scaled axis.
Invalid limit will be ignored.
  plt.xlim([0, 100000])
{'fraction_non_alphanumeric': 0.15712742980561556, 'fraction_numerical': 0.04400647948164147, 'mean_word_length': 6.111324376199616, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '484453', 'license': 'Apache-2.0', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1407, 'n_words': 251, 'path': 'sandbox/Figure_Notebooks/P_04_Search.ipynb', 'repo_name': 'PatrickvanZalm/alphapept', 'size': '3704'}