Commit 0110190d authored by Yakubov, Sergey's avatar Yakubov, Sergey
Browse files

add example for running a single tool

parent 0fa354bc
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
.idea
.pyc
+15 −0
Original line number Diff line number Diff line
#### To run examples:

- install python _bioblend_ package
- set _GALAXY_URL_ to _https://calvera.ornl.gov_
- on Calvera web site - go to _User->Preferences->Manage API Key_ and 
set _GALAXY_API_KEY_  

#### Documentation

some documentation for Bioblend can be found here:
https://bioblend.readthedocs.io/en/latest

you may also want to go through tutorial:
https://training.galaxyproject.org/training-material/topics/dev/tutorials/bioblend-api/tutorial.html
+41 −0
Original line number Diff line number Diff line
import os

from bioblend import galaxy
from bioblend.galaxy.tools.inputs import inputs

galaxy_url = os.getenv("GALAXY_URL")
galaxy_user_api_key = os.getenv("GALAXY_API_KEY")

# connect to a Galaxy instance, create dataset client
galaxy_instance = galaxy.GalaxyInstance(url=galaxy_url, key=galaxy_user_api_key)
dataset_client = galaxy.datasets.DatasetClient(galaxy_instance)

# get active history id
history_id = galaxy_instance.histories.get_histories()[0]["id"]
# or create a new one
# history_id = gi.histories.create_history(name="New history")["id"]

# upload a file and wait until upload is finished
uploaded_dataset_id = galaxy_instance.tools.upload_file('test.json', history_id)['outputs'][0]['id']
dataset_client.wait_for_dataset(uploaded_dataset_id)

# set tool inputs, run tool and wait it finishes
# wc_gnu - id of the Galaxy's Line/Word/Character count tool
# so one needs to know tool id and tool inputs and outputs. This tool takes an input file and options for what to count
# and returns a single output file (hence ['outputs'][0]['id'])
tool_inputs = inputs().set("options", ["lines", "words"]).set("input", uploaded_dataset_id)
result_dataset_id = galaxy_instance.tools.run_tool(history_id, 'wc_gnu', tool_inputs)['outputs'][0]['id']
dataset_client.wait_for_dataset(result_dataset_id)

# export results
exported_data = dataset_client.download_dataset(dataset_id=result_dataset_id,
                                                file_path=None,  # set file_path to output to file
                                                use_default_filename=False)
print(exported_data)

# uncomment to delete datasets
# galaxy_instance.histories.delete_dataset(history_id, uploaded_dataset_id, purge=True)
# galaxy_instance.histories.delete_dataset(history_id, result_dataset_id, purge=True)

# uncomment to delete history and all data, purge=True might be not allowed by Galaxy admin
# galaxy_instance.histories.delete_history(history_id, purge=True)
+3 −0
Original line number Diff line number Diff line
{
  "hello": "world"
}
 No newline at end of file