<jupyter_start><jupyter_text>Interacting with histories in BioBlend.objects==============================================**You need to insert the API key for your Galaxy server in the cell below**:1. Open the Galaxy server in another browser tab2. Click on "User" on the top menu, then "Preferences"3. Click on "Manage API key"4. Generate an API key if needed, then copy the alphanumeric string and paste it as the value of the `api_key` variable below.The user interacts with a Galaxy server through a `GalaxyInstance` object:<jupyter_code>from __future__ import print_function

import bioblend.galaxy.objects

server = 'https://usegalaxy.org/'
api_key = ''
gi = bioblend.galaxy.objects.GalaxyInstance(url=server, api_key=api_key)<jupyter_output><empty_output><jupyter_text>All `GalaxyInstance` method calls have the `client.method()` format, where `client` is the name of the resources you dealing with. There are 2 methods to get the list of resources: - `get_previews()`: lightweight (one GET request), retrieves basic resources' info, returns a list of **preview** objects - `list()`: one GET request for each resource, retrieves full resources' info, returns a list of **full** objects.<jupyter_code>gi.histories.get_previews()<jupyter_output><empty_output><jupyter_text>Both methods usually have **filtering** capabilities, e.g. it is possible to filter histories **by name**:<jupyter_code>hists = gi.histories.list(name='Unnamed history')
hists<jupyter_output><empty_output><jupyter_text>Both `HistoryPreview` and `History` objects have many of their properties available as **attributes**, e.g. the id.If you need to specify the unique **id** of the resource to retrieve, you can use the `get()` method:<jupyter_code>hist0_id = hists[0].id
print(hist0_id)
h = gi.histories.get(hist0_id)
h<jupyter_output>153e591de2140b59<jupyter_text>To get the list of **datasets contained** in a history, simply look at the `content_infos` attribute of the `History` objects.<jupyter_code>hdas = h.content_infos
hdas<jupyter_output><empty_output><jupyter_text>To get the details about one dataset, you can use the `get_dataset()` method of `History` objects:<jupyter_code>hda0_id = hdas[0].id
print(hda0_id)
h.get_dataset(hda0_id)<jupyter_output>bbd44e69cb8906b58bced975c2813624<jupyter_text>You can also filter history datasets by name using the `get_datasets()` method of `History` objects.**New resources** are created with `create()` methods, e.g. to create a new history:<jupyter_code>new_hist = gi.histories.create(name='New history')
new_hist<jupyter_output><empty_output><jupyter_text>As you can see, the `create()` methods in BioBlend.objects returns an object, not a dictionary.To **update** a resource, use the `update()` method of its object, e.g. to change the history name:<jupyter_code>new_hist.update(name='Updated history')<jupyter_output><empty_output><jupyter_text>The return value of `update()` methods is the updated object.Finally to **delete** a resource, you can use the `delete()` method of the object, e.g.:<jupyter_code>new_hist.delete()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11787564766839378, 'fraction_numerical': 0.014572538860103627, 'mean_word_length': 7.023376623376623, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '474423', 'license': 'MIT', 'n_tokens_mistral': 1004, 'n_tokens_neox': 958, 'n_words': 321, 'path': 'bioblend.objects_histories.ipynb', 'repo_name': 'MiguelJulia/GCC2019_BioBlend_tutorial', 'size': '3088'}