Locked History Actions

attachment:workflows_1.py of Events/GCC2013/TrainingDay/API

Attachment 'workflows_1.py'

Download

   1 #!/usr/bin/env python
   2 
   3 """
   4 Access a Galaxy instance and get data for Workflows.
   5 
   6 Creating three functions at once in this file.
   7 """
   8 import os
   9 import sys
  10 import pprint
  11 
  12 import setup
  13 import common
  14 
  15 RESOURCE_URL = '/api/workflows'
  16 
  17 # adding things quickly now - three functions at once
  18 
  19 # ----------------------------------------------------------------------------- functions
  20 def get_workflows():
  21     """
  22     Return a list of dictionaries of summary information for all workflows.
  23     """
  24     apikey = setup.get_apikey()
  25     full_url = setup.get_base_url() + RESOURCE_URL
  26     return common.get( apikey, full_url )
  27 
  28 def get_workflow( workflow_id ):
  29     """
  30     Return a dictionary of detailed information for a specific workflow.
  31     :param workflow_id: the encoded id of the workflow
  32     """
  33     apikey = setup.get_apikey()
  34     full_url = setup.get_base_url() + RESOURCE_URL + '/' + workflow_id
  35     return common.get( apikey, full_url )
  36 
  37 def run_single_input_workflow_on_hda( workflow_id, history_id, hda_id, source_step ):
  38     """
  39     Run a workflow that only needs one input using an hda. The outputs
  40     from the workflow will be kept in the history with `history_id`.
  41 
  42     Some of the options of this part of the API were not included here to
  43     improve simplicity.
  44 
  45     :param workflow_id: the encoded id of the workflow to run
  46     :param history_id: the id of the history for input/output
  47     :param hda_id: the id of the HDA to use as the workflow input
  48     :param source_step: the id of the initial, input workflow step
  49     """
  50     apikey = setup.get_apikey()
  51     full_url = setup.get_base_url() + RESOURCE_URL
  52 
  53     # a bit complex here...
  54     # build these first since they need to be contained in the following structures
  55     step = {
  56         'src'   : 'hda',
  57         'id'    : hda_id
  58     }
  59     ds_map = {}
  60     ds_map[ source_step ] = step
  61     post_data = {
  62         'workflow_id'   : workflow_id,
  63         'history'       : 'hist_id=' + history_id,
  64         'ds_map'        : ds_map
  65     }
  66     # above is an example of building complex input arguments for an API call
  67     #   The documentation for each API function and resource should help in creating these.
  68     return common.post( apikey, full_url, post_data )
  69 
  70 
  71 # ----------------------------------------------------------------------------- main
  72 if __name__ == '__main__':
  73     # we can make this script do double duty by changing functions based on the number of args passed in:
  74     if   len( sys.argv ) <= 1:
  75         # no args: get all workflows
  76         returned = get_workflows()
  77         pprint.pprint( returned, indent=2 )
  78 
  79     elif len( sys.argv ) <= 2:
  80         # 1 arg: get a specific workflow
  81         #NOTE: it's good practice to provide usage/help - in this case we could check if the arg was '-h' and do that
  82         workflow_id = sys.argv[1]
  83         returned = get_workflow( workflow_id )
  84         pprint.pprint( returned, indent=2 )
  85 
  86     # we won't test run_single_input_workflow_on_hda in this script

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-06-24 16:01:09, 8.2 KB) [[attachment:Galaxy-Workflow-Joined_Solexa_QC.ga]]
  • [get | view] (2013-06-24 16:46:36, 14.0 KB) [[attachment:all-scripts.tar.gz]]
  • [get | view] (2013-06-24 16:01:23, 5.2 KB) [[attachment:common.py]]
  • [get | view] (2013-06-24 16:04:07, 0.9 KB) [[attachment:datasets_1.py]]
  • [get | view] (2013-06-24 16:04:15, 1.2 KB) [[attachment:datasets_2.py]]
  • [get | view] (2013-06-24 16:04:22, 3.4 KB) [[attachment:datasets_3.py]]
  • [get | view] (2013-06-24 16:04:33, 1.5 KB) [[attachment:hdas_1.py]]
  • [get | view] (2013-06-24 16:04:50, 1.7 KB) [[attachment:hdas_2.py]]
  • [get | view] (2013-06-24 16:05:07, 2.2 KB) [[attachment:hdas_3.py]]
  • [get | view] (2013-06-24 16:03:38, 0.9 KB) [[attachment:histories_1.py]]
  • [get | view] (2013-06-24 16:03:52, 2.1 KB) [[attachment:histories_2.py]]
  • [get | view] (2013-06-24 16:05:25, 2.2 KB) [[attachment:histories_3.py]]
  • [get | view] (2013-06-24 16:05:34, 3.3 KB) [[attachment:lddas_1.py]]
  • [get | view] (2013-06-24 16:05:41, 1.3 KB) [[attachment:libraries_1.py]]
  • [get | view] (2013-06-24 16:01:36, 0.8 KB) [[attachment:setup.py]]
  • [get | view] (2013-06-24 16:02:45, 1.1 KB) [[attachment:step_1.py]]
  • [get | view] (2013-06-24 16:07:15, 9.9 KB) [[attachment:step_10.py]]
  • [get | view] (2013-06-24 16:03:28, 1.4 KB) [[attachment:step_2.py]]
  • [get | view] (2013-06-24 16:06:01, 1.6 KB) [[attachment:step_3.py]]
  • [get | view] (2013-06-24 16:06:11, 1.1 KB) [[attachment:step_4.py]]
  • [get | view] (2013-06-24 16:06:20, 1.9 KB) [[attachment:step_5.py]]
  • [get | view] (2013-06-24 16:06:44, 2.5 KB) [[attachment:step_6.py]]
  • [get | view] (2013-06-24 16:06:53, 4.9 KB) [[attachment:step_7.py]]
  • [get | view] (2013-06-24 16:07:05, 5.9 KB) [[attachment:step_8.py]]
  • [get | view] (2013-06-30 13:51:46, 8.0 KB) [[attachment:step_9.py]]
  • [get | view] (2013-06-24 16:41:51, 1.8 KB) [[attachment:tools_1.py]]
  • [get | view] (2013-06-24 16:44:32, 2.0 KB) [[attachment:upload_to_history.py]]
  • [get | view] (2013-06-24 16:03:03, 1.3 KB) [[attachment:users_1.py]]
  • [get | view] (2013-06-24 16:44:44, 2.9 KB) [[attachment:workflows_1.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.