Mercurial > repos > galaxyp > percolator
annotate nested_collection.py @ 1:23141085ca9e draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
| author | galaxyp | 
|---|---|
| date | Sat, 04 Mar 2017 20:35:44 -0500 | 
| parents | |
| children | b20ea66c01f0 | 
| rev | line source | 
|---|---|
| 1 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 1 import argparse | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 2 import os | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 3 import re | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 4 from collections import OrderedDict | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 5 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 6 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 7 def get_filename_index_with_identifier(realnames, pool_id): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 8 pool_indices = [] | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 9 for index, fn in enumerate(realnames): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 10 if re.search(pool_id, fn) is not None: | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 11 pool_indices.append(index) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 12 return pool_indices | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 13 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 14 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 15 def get_batches_of_galaxyfiles(realnames, batchsize, pool_ids): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 16 """For an amount of input files, pool identifiers and a batch size, | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 17 return batches of files for a list of lists""" | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 18 if pool_ids: | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 19 filegroups = OrderedDict([(p_id, get_filename_index_with_identifier( | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 20 realnames, p_id)) for p_id in pool_ids]) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 21 else: | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 22 filegroups = {1: range(len(realnames))} | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 23 batch = [] | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 24 for pool_id, grouped_indices in filegroups.items(): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 25 if pool_id == 1: | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 26 pool_id = 'pool0' | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 27 for index in grouped_indices: | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 28 batch.append(index) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 29 if batchsize and len(batch) == int(batchsize): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 30 yield pool_id, batch | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 31 batch = [] | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 32 if len(batch) > 0: | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 33 yield pool_id, batch | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 34 batch = [] | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 35 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 36 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 37 def main(): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 38 parser = argparse.ArgumentParser() | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 39 parser.add_argument('--batchsize', dest='batchsize', default=False) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 40 parser.add_argument('--real-names', dest='realnames', nargs='+') | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 41 parser.add_argument('--galaxy-files', dest='galaxyfiles', nargs='+') | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 42 parser.add_argument('--pool-ids', dest='poolids', nargs='+', default=False) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 43 args = parser.parse_args() | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 44 for batchcount, (pool_id, batch) in enumerate(get_batches_of_galaxyfiles( | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 45 args.realnames, args.batchsize, args.poolids)): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 46 for fncount, batchfile in enumerate([args.galaxyfiles[index] for index in batch]): | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 47 dsetname = '{}___batch{}_inputfn{}.mzid'.format(pool_id, batchcount, fncount) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 48 print('producing', dsetname) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 49 os.symlink(batchfile, dsetname) | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 50 | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 51 if __name__ == '__main__': | 
| 
23141085ca9e
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/percolator commit 0a5f9eb82877545be1c924357e585b17e01cfd1c
 galaxyp parents: diff
changeset | 52 main() | 
