<jupyter_start><jupyter_text>Explore colocalized annotations  Setup %matplotlib inline%load_ext autoreload%autoreload 2 %matplotlib inline%load_ext autoreload%autoreload 2 %matplotlib inline%load_ext autoreload%autoreload 2<jupyter_code>%matplotlib inline
%load_ext autoreload
%autoreload 2
import matplotlib.pyplot as plt

from metaspace import SMInstance
sm = SMInstance(host='https://metaspace2020.eu')
ds = sm.dataset(id='2016-09-22_11h16m41s')
ds<jupyter_output><empty_output><jupyter_text>Explore<jupyter_code>def fetch_images(ds, annotations):
    ann_images = {}
    for formula, adduct in annotations:
        image = ds.isotope_images(formula, adduct, only_first_isotope=True)[0]
        ann_images[(formula, adduct)] = image
    return ann_images
database = 'HMDB-v4'
fdr = 0.1
formula, adduct = 'C44H86NO8P', '+K'
coloc_with = f'{formula}{adduct}+'
coloc_with
df = ds.results(database=database, fdr=fdr, coloc_with=coloc_with)
df.shape
df.head()
top_n = 10
top_coloc_anns = df.head(top_n).index.tolist()
len(top_coloc_anns)
most_coloc_images = fetch_images(ds, top_coloc_anns)
len(most_coloc_images)
fig, axes = plt.subplots(5, 2, figsize=(15, 30))
axes = axes.flatten()
for i, row in enumerate(df.head(top_n).itertuples()):
    formula, adduct = row.Index
    image = most_coloc_images[(formula, adduct)]
    axes[i].imshow(image)
    axes[i].set_title(f'{formula}, {adduct}: {row.colocCoeff}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12595685455810718, 'fraction_numerical': 0.027139874739039668, 'mean_word_length': 6.648936170212766, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '198409', 'license': 'Apache-2.0', 'n_tokens_mistral': 599, 'n_tokens_neox': 546, 'n_words': 100, 'path': 'metaspace/python-client/docs/source/content/examples/colocalized-annotations.ipynb', 'repo_name': 'mrmattuschka/metaspace', 'size': '1437'}