<jupyter_start><jupyter_text>AlphaPept Test Runs and Visualization ExamplesThis notebooks is intended to show how a IRT File can be processed.  Download Test Data<jupyter_code>import os
try:
    import wget
except ModuleNotFoundError:
    !pip install wget
    import wget
    
FILE_DICT = {}
FILE_DICT['thermo_IRT.raw'] = 'https://datashare.biochem.mpg.de/s/GpXsATZtMwgQoQt/download'
FILE_DICT['IRT_fasta.fasta'] = 'https://datashare.biochem.mpg.de/s/p8Qu3KolzbSiCHH/download'

tmp_folder = os.path.join(os.getcwd(),'/temp_test_run')

if not os.path.isdir(tmp_folder):
    os.mkdir(tmp_folder)
    
for file in FILE_DICT:
    target = os.path.join(tmp_folder, file)
    if not os.path.isfile(target):
        wget.download(FILE_DICT[file], target)<jupyter_output><empty_output><jupyter_text>Test Run<jupyter_code>from alphapept.settings import load_settings
from alphapept.paths import DEFAULT_SETTINGS_PATH

settings = load_settings(DEFAULT_SETTINGS_PATH)

settings['experiment']['file_paths'] =  [os.path.join(tmp_folder, 'thermo_IRT.raw')]
settings['experiment']['fasta_paths'] = [os.path.join(tmp_folder, 'IRT_fasta.fasta')]
    
import alphapept.interface

settings_ = alphapept.interface.run_complete_workflow(settings)<jupyter_output>2021-07-22 23:46:48> Logging to C:\Users\admin\alphapept\logs\log_20210722234648.txt.
2021-07-22 23:46:48> Platform information:
2021-07-22 23:46:48> system     - Windows
2021-07-22 23:46:48> release    - 10
2021-07-22 23:46:48> version    - 10.0.18363
2021-07-22 23:46:48> machine    - AMD64
2021-07-22 23:46:48> processor  - Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
2021-07-22 23:46:48> cpu count  - 24
2021-07-22 23:46:48> ram memory - 121.3/127.7 Gb (available/total)
2021-07-22 23:46:48> 
2021-07-22 23:46:48> Python information:
2021-07-22 23:46:48> SQLAlchemy       - 1.3.22
2021-07-22 23:46:48> alphapept        - 0.3.27
2021-07-22 23:46:48> biopython        - 1.78
2021-07-22 23:46:48> click            - 7.1.2
2021-07-22 23:46:48> comtypes         - 1.1.7
2021-07-22 23:46:48> fastcore         - 1.3.19
2021-07-22 23:46:48> h5py             - 3.1.0
2021-07-22 23:46:48> lxml             - 4.6.2
2021-07-22 23:46:48> matplotlib       - 3.3.3
2021-07-22 23:46:48> networkx         -[...]<jupyter_text>Basic file accessFiles can be read via the alphapept.io class and displayed as pandas dataframe<jupyter_code>import alphapept.io

_ = settings['experiment']['file_paths'][0]
base, ext = os.path.splitext(_)

ms_file = alphapept.io.MS_Data_File(base+'.ms_data.hdf')

print(ms_file.read())

df = ms_file.read(dataset_name='peptide_fdr')

df.head()<jupyter_output>['Raw', 'corrected_fragment_mzs', 'feature_table', 'features', 'first_search', 'ions', 'peptide_fdr', 'second_search']<jupyter_text>MS2 SpectrumVisualize PSMS<jupyter_code>try:
    import matplotlib.pyplot as plt
except ModuleNotFoundError:
    !pip install matplotlib
    import matplotlib.pyplot as plt

def plot_psms(precursor, ms_file):

    df = ms_file.read(dataset_name='peptide_fdr')
    
    ion_dict = {}
    ion_dict[0] = ''
    ion_dict[1] = '-H20'
    ion_dict[2] = '-NH3'

    spectrum = df[df['precursor'] == precursor].iloc[0]
    start = spectrum['ion_idx']
    end = spectrum['n_ions'] + start

    query_data = ms_file.read_DDA_query_data()
    ions = ms_file.read(dataset_name="ions")

    ion = [('b'+str(int(_))).replace('b-','y') for _ in ions.iloc[start:end]['ion_index']]
    losses = [ion_dict[int(_)] for _ in ions.iloc[start:end]['ion_type']]
    ion = [a+b for a,b in zip(ion, losses)]
    ints = ions.iloc[start:end]['ion_int'].astype('int').values
    masses = ions.iloc[start:end]['ion_mass'].astype('float').values
    ion_type = ions.iloc[start:end]['ion_type'].abs().values

    query_idx = spectrum['raw_idx']

    query_indices = query_data["indices_ms2"]
    query_charges = query_data['charge2']
    query_frags = query_data['mass_list_ms2']
    query_ints = query_data['int_list_ms2']

    query_idx_start = query_indices[query_idx]
    query_idx_end = query_indices[query_idx + 1]
    query_frag = query_frags[query_idx_start:query_idx_end]
    query_int = query_ints[query_idx_start:query_idx_end]

    ax = plt.figure(figsize=(15, 5))

    plt.vlines(query_frag, 0, query_int, "k", label="Query", alpha=0.5)

    plt.vlines(masses, ints, max(query_int)*(1+0.1*ion_type), "k", label="Hits", alpha=0.5, linestyle=':')

    plt.vlines(masses, 0, ints, "r", label="Hits", alpha=0.5)

    for i in range(len(masses)):
        plt.text(masses[i], (1+0.1*ion_type[i])*max(query_int), ion[i])

    figure_title = f"{spectrum['precursor']} - b-hits {spectrum['b_hits']}, y-hits {spectrum['y_hits']}, matched int {spectrum['matched_int_ratio']*100:.2f} %"

    plt.xlabel("m/z")
    plt.ylabel('Intensity')
    plt.ylim([0, (1+0.1*max(ion_type)+0.1)*max(query_int)])
    plt.legend()
    plt.title(figure_title)
    plt.show()
    
    
for index in range(3):
    precursor = df['precursor'].iloc[index]
    print(f" Plotting PSMS for {precursor}")
    plot_psms(precursor, ms_file)<jupyter_output>Plotting PSMS for LGGNEQVTR_2
{'fraction_non_alphanumeric': 0.15292265302105884, 'fraction_numerical': 0.08108640031489864, 'mean_word_length': 4.244582043343653, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '421125', 'license': 'Apache-2.0', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2007, 'n_words': 341, 'path': 'sandbox/Test_Run.ipynb', 'repo_name': 'PatrickvanZalm/alphapept', 'size': '5081'}