Locked History Actions

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

Attachment 'step_6.py'

Download

   1 #!/usr/bin/env python
   2 
   3 """
   4 Step 6
   5 ======
   6 In this step, we'll create a new history named 'Step 6', upload a file
   7 to it to create a new HDA, and wait for that HDA to move into the 'ok' state.
   8 """
   9 import os
  10 import sys
  11 import pprint
  12 # we'll use the python library time to get a function called sleep
  13 import time
  14 
  15 import users_1
  16 import histories_3
  17 import tools_1
  18 import hdas_2
  19 
  20 NEW_HISTORY_NAME = 'Step 6'
  21 DATA_TO_UPLOAD = 'data/myIlluminaRun.solexa.fastq'
  22 
  23 # ----------------------------------------------------------------------------- main
  24 if __name__ == '__main__':
  25     try:
  26         # check the connection
  27         users = users_1.get_users()
  28 
  29         # create a new history
  30         new_history = histories_3.create_history( NEW_HISTORY_NAME )
  31         print 'created history!', new_history[ 'name' ]
  32         new_history_id = new_history[ 'id' ]
  33         new_history_details = histories_3.get_history( new_history_id )
  34 
  35         # upload a file
  36         tool_output_datasets = tools_1.upload_hda( new_history_id, DATA_TO_UPLOAD )
  37         uploaded_file_data = tool_output_datasets[ 'outputs' ][0]
  38         print 'uploaded hda!', uploaded_file_data[ 'name' ]
  39         uploaded_file_id = uploaded_file_data[ 'id' ]
  40 
  41         # and use get_hda to get details on the new, uploaded HDA
  42         uploaded_hda_details = hdas_2.get_hda( new_history_id, uploaded_file_id )
  43         uploaded_hda_state = uploaded_hda_details[ 'state' ]
  44 
  45         # here, we'll loop while the uploaded HDA state isn't where we want it
  46         # NOTE: it may happen that the HDA will error! If that's the case - this will loop
  47         #   forever. You could press 'ctrl+c' to stop this script - but it's a better
  48         #   idea to add more code to handle the possibility. We'll be optimistic and
  49         #   (for simplicity) assume everything will work.
  50         while uploaded_hda_state != 'ok':
  51             print '\t uploaded_hda_state:', uploaded_hda_state
  52             print '\t (waiting 4 seconds...)'
  53             time.sleep( 4.0 )
  54 
  55             # keep checking to get any new state the HDA might move into
  56             uploaded_hda_details = hdas_2.get_hda( new_history_id, uploaded_file_id )
  57             uploaded_hda_state = uploaded_hda_details[ 'state' ]
  58 
  59         # here - we've exited the loop, so the state should be 'ok'
  60         
  61     except Exception, exc:
  62         print 'Error uploading file to history:', str( exc )
  63         sys.exit( 1 )
  64 
  65     print 'Uploaded:'
  66     pprint.pprint( uploaded_hda_details, indent=2 )
  67     print 'State:', uploaded_hda_state

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.