Locked History Actions

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

Attachment 'lddas_1.py'

Download

   1 #!/usr/bin/env python
   2 
   3 """
   4 Access a Galaxy instance and get data for LibraryDatasetDatasetAssociations
   5 and LibraryFolders.
   6 
   7 Methods to list a library's contents - not unlike hdas_1, 2, 3.
   8 Libraries, however, are somewhat more complex in that they can contain both
   9 LDDAs and LibraryFolders (which themselves can contain both).
  10 
  11 For the purposes of this workshop - we won't explore the 'nesting' aspect
  12 of Libraries and will focus on simplicity.
  13 """
  14 import os
  15 import sys
  16 import pprint
  17 
  18 import setup
  19 import common
  20 
  21 # same as libraries - but we're getting contents
  22 RESOURCE_URL = '/api/libraries'
  23 
  24 # ----------------------------------------------------------------------------- functions
  25 def get_lddas( library_id ):
  26     """
  27     Return a list of dictionaries that describe all lddas from a specific library.
  28     :param library_id: the id of the library which we want to query.
  29     """
  30     apikey = setup.get_apikey()
  31     container_url = setup.get_base_url() + RESOURCE_URL
  32     full_url = container_url + '/' + library_id + '/contents'
  33     return common.get( apikey, full_url )
  34 
  35 def get_ldda( library_id, ldda_id ):
  36     """
  37     Return a dictionary that the gives details of a specific ldda.
  38     :param library_id: the id of the library which we want to query.
  39     :param ldda_id: the id of the LDDA which we want to query.
  40     """
  41     apikey = setup.get_apikey()
  42     container_url = setup.get_base_url() + RESOURCE_URL
  43     full_url = container_url + '/' + library_id + '/contents/' + ldda_id
  44     return common.get( apikey, full_url )
  45 
  46 def copy_hda_to_ldda( library_id, library_folder_id, hda_id, message='' ):
  47     """
  48     Copy an HDA into a LDDA (that the current user has add permissions on)
  49     in the given library and library folder.
  50     :param library_id: the id of the library which we want to query.
  51     :param library_folder_id: the id of the folder to copy into.
  52     :param hda_id: the id of the HDA we want to copy.
  53     :param message: an optional message to add to the new LDDA.
  54     """
  55     apikey = setup.get_apikey()
  56     container_url = setup.get_base_url() + RESOURCE_URL
  57     full_url = container_url + '/' + library_id + '/contents'
  58 
  59     post_data = {
  60         'folder_id'     : library_folder_id,
  61         'create_type'   : 'file',
  62         'from_hda_id'   : hda_id,
  63     }
  64     if message:
  65         post_data[ 'ldda_message' ] = message
  66 
  67     return common.post( apikey, full_url, post_data )
  68 
  69 
  70 # ----------------------------------------------------------------------------- main
  71 if __name__ == '__main__':
  72     if   len( sys.argv ) < 2:
  73         # no args: help
  74         print 'USAGE: lddas_1.py <library id> [<ldda id>] [<id of hda to copy>]'
  75         sys.exit( 1 )
  76 
  77     elif len( sys.argv ) == 2:
  78         # 1 arg: get all lddas in a library
  79         library_id = sys.argv[1]
  80         returned = get_lddas( library_id )
  81         pprint.pprint( returned, indent=2 )
  82 
  83     elif len( sys.argv ) == 3:
  84         # 2 args: get a specific LDDA from a library
  85         library_id = sys.argv[1]
  86         ldda_id = sys.argv[2]
  87         returned = get_ldda( library_id, ldda_id )
  88         pprint.pprint( returned, indent=2 )
  89 
  90     elif len( sys.argv ) >= 4:
  91         # 3 args: copy an HDA into a specific folder in a library
  92         ( library_id, library_folder_id, hda_id ) = sys.argv[1:4]
  93         returned = copy_hda_to_ldda( library_id, library_folder_id, hda_id )

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.