Mercurial > repos > stevecassidy > ziptools
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:fe887de9b4b5 | 1:278da6e5ab11 |
---|---|
1 from __future__ import print_function | 1 from __future__ import print_function |
2 import argparse | 2 import argparse |
3 from zipfile import ZipFile | 3 from zipfile import ZipFile |
4 import os | |
5 | |
4 | 6 |
5 def parser(): | 7 def parser(): |
6 parser = argparse.ArgumentParser(description="Find matching segments in a TextGrid") | 8 parser = argparse.ArgumentParser(description="Find matching segments in a TextGrid") |
7 parser.add_argument('--dataset', required=True, action="store", type=str, help="TextGrid files (comma separated)") | 9 parser.add_argument('--dataset', required=True, action="store", type=str, help="TextGrid files (comma separated)") |
8 parser.add_argument('--identifier', required=True, action="store", type=str, help="Dataset identifiers (comma separated)") | 10 parser.add_argument('--identifier', required=True, action="store", type=str, help="Dataset identifiers (comma separated)") |
11 parser.add_argument('--extension', required=False, action='store', default='', type=str, help="Extension for stored files") | |
9 parser.add_argument('--output', required=True, action="store", type=str, help="Path to output file") | 12 parser.add_argument('--output', required=True, action="store", type=str, help="Path to output file") |
10 return parser.parse_args() | 13 return parser.parse_args() |
11 | 14 |
12 | 15 |
13 def main(): | 16 def main(): |
19 | 22 |
20 pairs = zip(datasets, identifiers) | 23 pairs = zip(datasets, identifiers) |
21 | 24 |
22 with ZipFile(args.output, 'w') as zipfile: | 25 with ZipFile(args.output, 'w') as zipfile: |
23 for dataset, identifier in pairs: | 26 for dataset, identifier in pairs: |
24 zipfile.write(dataset, identifier) | 27 |
28 # rewrite extension if asked | |
29 if args.extension != '': | |
30 base, ext = os.path.splitext(identifier) | |
31 outname = base + "." + args.extension | |
32 else: | |
33 outname = identifier | |
34 | |
35 zipfile.write(dataset, outname) | |
25 | 36 |
26 | 37 |
27 if __name__ == '__main__': | 38 if __name__ == '__main__': |
28 main() | 39 main() |