# HG changeset patch # User ric # Date 1474550961 14400 # Node ID 1fcf2875d39da19b72cb2ba0ba3c982aaf7a0b39 # Parent f833f23d38a38bec34bba2d563b317034979556d Deleted selected files diff -r f833f23d38a3 -r 1fcf2875d39d galaxy-tools/biobank/updater/discard_from_collection.py --- a/galaxy-tools/biobank/updater/discard_from_collection.py Thu Sep 22 09:28:03 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -import csv, argparse, sys, os - -from bl.vl.kb import KnowledgeBase as KB -import bl.vl.utils.ome_utils as vlu -from bl.vl.utils import get_logger, LOG_LEVELS - -COLLECTION_TYPES = {'VesselsCollection' : 'VesselsCollectionItem', - 'DataCollection' : 'DataCollectionItem'} - -def make_parser(): - parser = argparse.ArgumentParser(description='remove elements from a Vessels or Data Collection') - parser.add_argument('--logfile', type=str, help='log file (default=stderr)') - parser.add_argument('--loglevel', type=str, choices=LOG_LEVELS, - help='logger level', default='INFO') - parser.add_argument('-H', '--host', type=str, help='omero hostname') - parser.add_argument('-U', '--user', type=str, help='omero user') - parser.add_argument('-P', '--passwd', type=str, help='omero password') - parser.add_argument('-I', '--ifile', type=str, required=True, - help='list of collection items that will be removed') - parser.add_argument('--collection_type', type=str, required=True, - choices=COLLECTION_TYPES.keys(), - help='type of the collection') - parser.add_argument('--collection_label', type=str, required=True, - help='label of the collection') - - return parser - -def load_collection(coll_type, coll_label, kb): - query = 'SELECT coll FROM %s coll WHERE coll.label = :coll_label' % coll_type - coll = kb.find_all_by_query(query, {'coll_label' : coll_label}) - return coll[0] if len(coll) > 0 else None - -def load_collection_items(collection, coll_type, kb): - if COLLECTION_TYPES[coll_type] == 'VesselsCollectionItem': - citems = kb.get_vessels_collection_items(collection) - elif COLLECTION_TYPES[coll_type] == 'DataCollectionItem': - citems = kb.get_data_collection_items(collection) - else: - raise ValueError('Unknown data collection type %s' % COLLECTION_TYPES[coll_type]) - ci_map = {} - for ci in citems: - ci_map[ci.id] = ci - return ci_map - - -def main(argv): - parser = make_parser() - args = parser.parse_args(argv) - - logger = get_logger('discard_from_collection', level=args.loglevel, - filename=args.logfile) - - try: - host = args.host or vlu.ome_host() - user = args.user or vlu.ome_user() - passwd = args.passwd or vlu.ome_passwd() - except ValueError, ve: - logger.critical(ve) - sys.exit(ve) - - kb = KB(driver='omero')(host, user, passwd) - logger.info('Loading collection %s from %s' % (args.collection_label, - args.collection_type)) - coll = load_collection(args.collection_type, args.collection_label, kb) - if not coll: - msg = 'No %s found with label %s' % (args.collection_type, - args.collection_label) - logger.error(msg) - sys.exit(msg) - logger.info('Loading items from collection') - coll_items = load_collection_items(coll, args.collection_type, kb) - logger.info('Fetched %d elements' % len(coll_items)) - - with open(args.ifile) as infile: - reader = csv.DictReader(infile, delimiter='\t') - to_be_deleted = [row['collection_item'] for row in reader] - logger.info('Found %d items to be deleted' % len(to_be_deleted)) - - for tbd in to_be_deleted: - try: - kb.delete(coll_items[tbd]) - logger.info('%s with ID %s deleted' % (COLLECTION_TYPES[args.collection_type], - tbd)) - except KeyError, ke: - logger.warning('No %s related to ID %s' % (COLLECTION_TYPES[args.collection_type], - ke)) - logger.info('Job completed') - - -if __name__ == '__main__': - main(sys.argv[1:]) diff -r f833f23d38a3 -r 1fcf2875d39d galaxy-tools/biobank/updater/discard_from_collection.xml --- a/galaxy-tools/biobank/updater/discard_from_collection.xml Thu Sep 22 09:28:03 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ - - - Discard input elements from the selected collection - - - discard_from_collection.py - #if $advanced_configuration.configuration_level == 'advanced' - --host=$advanced_configuration.vl_host - --user=$advanced_configuration.vl_user - --passwd=$advanced_configuration.vl_passwd - #end if - --loglevel=$__app__.config.vl_loglevel - --logfile=${logfile} - --ifile=${ifile} - #if str($collection_selector.collection_type) != 'no_coll_selected' - --collection_type=${collection_selector.collection_type} - #if str($collection_selector.collection_type) == 'DataCollection' - #if str($collection_selector.dcoll_label) != 'no_label_selected' - --collection_label=${collection_selector.dcoll_label} - #end if - #elif str($collection_selector.collection_type) == 'VesselsCollection' - #if str($collection_selector.vcoll_label) != 'no_label_selected' - --collection_label=${collection_selector.vcoll_label} - #end if - #end if - #end if - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -This tool discard from a DataCollection or a VesselCollection one or -more items. - -The expected input file must be like - -+---------------+ -|collection_item| -+---------------+ -|V013AFF22311 | -+---------------+ -|V0ABB3451516 | -+---------------+ -|V012441AAEEC | -+---------------+ - -Input file rows must be VIDs obtained using the **map_vid** tool. - -Collection must be selected using the specific selection lists that -show only the ones imported into the system. - - \ No newline at end of file