annotate zipcollection.py @ 1:278da6e5ab11 draft default tip

planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
author stevecassidy
date Mon, 20 Nov 2017 22:51:12 -0500
parents fe887de9b4b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
1 from __future__ import print_function
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
2 import argparse
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
3 from zipfile import ZipFile
1
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
4 import os
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
5
0
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
6
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
7 def parser():
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
8 parser = argparse.ArgumentParser(description="Find matching segments in a TextGrid")
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
9 parser.add_argument('--dataset', required=True, action="store", type=str, help="TextGrid files (comma separated)")
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
10 parser.add_argument('--identifier', required=True, action="store", type=str, help="Dataset identifiers (comma separated)")
1
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
11 parser.add_argument('--extension', required=False, action='store', default='', type=str, help="Extension for stored files")
0
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
12 parser.add_argument('--output', required=True, action="store", type=str, help="Path to output file")
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
13 return parser.parse_args()
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
14
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
15
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
16 def main():
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
17 args = parser()
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
18
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
19 datasets = args.dataset.split(',')
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
20 identifiers = args.identifier.split(',')
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
21 assert len(datasets) == len(identifiers), "number of datasets must match number of identifiers"
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
22
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
23 pairs = zip(datasets, identifiers)
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
24
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
25 with ZipFile(args.output, 'w') as zipfile:
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
26 for dataset, identifier in pairs:
1
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
27
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
28 # rewrite extension if asked
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
29 if args.extension != '':
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
30 base, ext = os.path.splitext(identifier)
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
31 outname = base + "." + args.extension
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
32 else:
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
33 outname = identifier
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
34
278da6e5ab11 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit f2432aaedd36ae7662873623d8861d0982dffdd2
stevecassidy
parents: 0
diff changeset
35 zipfile.write(dataset, outname)
0
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
36
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
37
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
38 if __name__ == '__main__':
fe887de9b4b5 planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
stevecassidy
parents:
diff changeset
39 main()