Mercurial > repos > galaxyp > percolator
view nested_collection.py @ 3:abed51712ed0 draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit b3873302e7bb7917a43b455875208e6e9fcf8f66
author | galaxyp |
---|---|
date | Sat, 08 Apr 2017 08:23:12 -0400 |
parents | 7a0951d0e13e |
children | 154147805a33 |
line wrap: on
line source
import argparse import os import re from collections import OrderedDict def get_filename_index_with_identifier(realnames, pool_id): pool_indices = [] for index, fn in enumerate(realnames): if re.search(pool_id, fn) is not None: pool_indices.append(index) return pool_indices def get_batches_of_galaxyfiles(realnames, batchsize, pool_ids): """For an amount of input files, pool identifiers and a batch size, return batches of files for a list of lists""" if pool_ids: filegroups = OrderedDict([(p_id, get_filename_index_with_identifier( realnames, p_id)) for p_id in pool_ids]) else: filegroups = {1: range(len(realnames))} batch = [] for pool_id, grouped_indices in filegroups.items(): if pool_id == 1: pool_id = 'pool0' for index in grouped_indices: batch.append(index) if batchsize and len(batch) == int(batchsize): yield pool_id, batch batch = [] if len(batch) > 0: yield pool_id, batch batch = [] def main(): parser = argparse.ArgumentParser() parser.add_argument('--batchsize', dest='batchsize', default=False) parser.add_argument('--real-names', dest='realnames', nargs='+') parser.add_argument('--galaxy-files', dest='galaxyfiles', nargs='+') parser.add_argument('--pool-ids', dest='poolids', nargs='+', default=False) args = parser.parse_args() for batchcount, (pool_id, batch) in enumerate(get_batches_of_galaxyfiles( args.realnames, args.batchsize, args.poolids)): for fncount, batchfile in enumerate([args.galaxyfiles[index] for index in batch]): dsetname = '{}_batch{}___inputfn{}.data'.format(pool_id, batchcount, fncount) print('producing', dsetname) os.symlink(batchfile, dsetname) if __name__ == '__main__': main()