def add_library_datasets(context,galaxy,dest,file,file_type, dbkey,from_server,link): """ Add datasets to a data library. Uploads one or more FILEs as new datasets in the data library folder DEST in GALAXY. DEST should be a path to a data library or library folder of the form 'data_library[/folder[/subfolder[...]]]'. The library and folder must already exist. """ # Get a Galaxy instance gi = context.galaxy_instance(galaxy) if gi is None: logger.critical("Failed to connect to Galaxy instance") return 1 # Add the datasets libraries.add_library_datasets(gi,dest,file, from_server=from_server, link_only=link, file_type=file_type, dbkey=dbkey)
def manage_libraries(args=None): """ Implements the 'manage_libraries' utility """ deprecation_warning() if args is None: args = sys.argv[1:] p = base_parser(usage=\ "\n\t%prog list GALAXY_URL [options]" "\n\t%prog create_library GALAXY_URL [options] NAME" "\n\t%prog create_folder GALAXY_URL [options] PATH" "\n\t%prog add_datasets GALAXY_URL [options] DEST FILE...", description="Manage and populate data libraries in a " "Galaxy instance") commands = ['list','create_library','create_folder','add_datasets'] # Get compulsory arguments if len(args) == 1: if args[0] == '-h' or args[0] == '--help': p.print_usage() elif args[0] == '--version': p.print_version() sys.exit(0) if len(args) < 2: p.error("need to supply a command and a Galaxy URL/alias") command = args[0] galaxy_url = args[1] # Setup additional command line options if command not in commands: p.error("unrecognised command: '%s'" % command) elif command == 'list': p.set_usage("%prog list GALAXY_URL [options]") p.add_option('-l',action='store_true', dest='long_listing_format',default=False, help="use a long listing format (include ids, " "descriptions and file sizes and paths)") elif command == 'create_library': p.set_usage("%prog create_library GALAXY_URL [options] NAME") p.add_option('-d','--description',action='store', dest='description',default=None, help="optional description") p.add_option('-s','--synopsis',action='store',dest='synopsis', default=None,help="optional synopsis") elif command == 'create_folder': p.set_usage("%prog create_folder GALAXY_URL [options] PATH") p.add_option('-d','--description',action='store', dest='description',default=None, help="optional description") elif command == 'add_datasets': p.set_usage("%prog add_datasets GALAXY_URL [options] DEST FILE...") p.add_option('--server',action='store_true',dest='from_server', default=False, help="upload files from Galaxy server file system " "paths (default is to upload files from local " "system)") p.add_option('--link',action='store_true',dest='link', default=False, help="create symlinks to files on server (only " "valid if used with --server; default is to copy " "files into Galaxy)") p.add_option('--dbkey',action='store',dest='dbkey',default='?', help="dbkey to assign to files (default is '?')") p.add_option('--file_type',action='store',dest='file_type', default='auto', help="file type to assign to files (default is " "'auto')") # Process remaining arguments on command line if args[1] in ('-h','--help','--version'): args = args[1:] else: args = args[2:] options,args = p.parse_args(args) handle_debug(debug=options.debug) handle_suppress_warnings(suppress_warnings=options.suppress_warnings) handle_ssl_warnings(verify=(not options.no_verify)) # Handle password if required email,password = handle_credentials(options.username, options.galaxy_password, prompt="Password for %s: " % galaxy_url) # Get a Galaxy instance gi = get_galaxy_instance(galaxy_url,api_key=options.api_key, email=email,password=password, verify_ssl=(not options.no_verify)) if gi is None: logger.critical("Failed to connect to Galaxy instance") sys.exit(1) # Execute command if command == 'list': if len(args) == 1: # List folders in data library libraries.list_library_contents(gi,args[0],long_listing_format= options.long_listing_format) else: # List data libraries libraries.list_data_libraries(gi) elif command == 'create_library': # Create a new data library if len(args) == 1: libraries.create_library(gi,args[0], description=options.description, synopsis=options.synopsis) else: p.error("Usage: create_library NAME") elif command == 'create_folder': # Create a new folder data library if len(args) == 1: libraries.create_folder(gi,args[0], description=options.description) else: p.error("Usage: create_folder PATH") elif command == 'add_datasets': # Add a dataset to a library if len(args) < 2: p.error("Usage: add_datasets DEST FILE [FILE...]") libraries.add_library_datasets(gi,args[0],args[1:], from_server=options.from_server, link_only=options.link, file_type=options.file_type, dbkey=options.dbkey)