<jupyter_start><jupyter_text>Sequential DDA environment test<jupyter_code>from vimms.Common import POSITIVE
from vimms.ChemicalSamplers import UniformRTAndIntensitySampler, GaussianChromatogramSampler, UniformMZFormulaSampler

from vimms_gym.env import DDAEnv
from vimms_gym.features import obs_to_dfs
# n_chemicals = (200, 500)
# mz_range = (100, 600)
# rt_range = (0, 300)
# intensity_range = (1E5, 1E10)
n_chemicals = (2000, 5000)
mz_range = (100, 600)
rt_range = (200, 1000)
intensity_range = (1E4, 1E10)
min_mz = mz_range[0]
max_mz = mz_range[1]
min_rt = rt_range[0]
max_rt = rt_range[1]
min_log_intensity = np.log(intensity_range[0])
max_log_intensity = np.log(intensity_range[1])
isolation_window = 0.7
N = 10
rt_tol = 15
mz_tol = 10
min_ms1_intensity = 5000
ionisation_mode = POSITIVE

enable_spike_noise = True
noise_density = 0.1
noise_max_val = 1E3
mz_sampler = UniformMZFormulaSampler(min_mz=min_mz, max_mz=max_mz)
ri_sampler = UniformRTAndIntensitySampler(min_rt=min_rt, max_rt=max_rt,
                                          min_log_intensity=min_log_intensity,
                                          max_log_intensity=max_log_intensity)
cr_sampler = GaussianChromatogramSampler()
samplers = {
    'mz': mz_sampler,
    'rt_intensity': ri_sampler,
    'chromatogram': cr_sampler
}
params = {
    'chemical_creator': {
        'mz_range': mz_range,
        'rt_range': rt_range,
        'intensity_range': intensity_range,
        'n_chemicals': n_chemicals,
        'mz_sampler': mz_sampler,
        'ri_sampler': ri_sampler,
        'cr_sampler': cr_sampler,
    },
    'noise': {
        'enable_spike_noise': enable_spike_noise,
        'noise_density': noise_density,
        'noise_max_val': noise_max_val,
        'mz_range': mz_range
    },
    'env': {
        'ionisation_mode': ionisation_mode,
        'rt_range': rt_range,
        'isolation_window': isolation_window,
        'mz_tol': mz_tol,
        'rt_tol': rt_tol,
    }
}<jupyter_output><empty_output><jupyter_text>Initialise a new DDA environment that tracks the top most intense peaks.<jupyter_code>max_peaks = 100
env = DDAEnv(max_peaks, params)
check_env(env)<jupyter_output><empty_output><jupyter_text>Generate an initial observation (MS1 scan)<jupyter_code>observation = env.reset()
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features
env.render()<jupyter_output><empty_output><jupyter_text>Generate 10 ms1 scans<jupyter_code>for i in range(10):
    action = max_peaks # ms1
    observation, reward, done, info = env.step(action)

print('reward', reward)
print('done', done)
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features
env.render()<jupyter_output><empty_output><jupyter_text>Target the most intense precursor for fragmentation, and generate an MS2 scan from that<jupyter_code>action = 0
observation, reward, done, info = env.step(action)

print('reward', reward)
print('done', done)
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features
env.render()<jupyter_output><empty_output><jupyter_text>Target the next most intense precursor for fragmentation, and generate an MS2 scan<jupyter_code>action = 1
observation, reward, done, info = env.step(action)

print('reward', reward)
print('done', done)
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features
env.render()<jupyter_output><empty_output><jupyter_text>Repeat targeting of the same precursor will end up producing 0 or negative reward.<jupyter_code>for i in range(10):
    action = 0
    observation, reward, done, info = env.step(action)
    print('reward', reward)
    # print('done', done)
    # pp.pprint(observation)
    # env.render()
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features<jupyter_output><empty_output><jupyter_text>Making an invalid move produces negative reward.<jupyter_code>action = 90 # no precursor to fragment at this index
observation, reward, done, info = env.step(action)

print('reward', reward)
print('done', done)
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features
env.render()<jupyter_output><empty_output><jupyter_text>Generate lots of MS1 scans<jupyter_code>for i in range(100):
    action = max_peaks # ms1
    observation, reward, done, info = env.step(action)

print('reward', reward)
print('done', done)
scan_df, count_df = obs_to_dfs(observation, env.features)
scan_df, count_df
observation['valid_actions']
env.features
env.render()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup