comparison refinery_file_splitter.py @ 1:b87749d7a24c draft default tip

planemo upload commit 4fb0a789956149e5a58f4e370d7fe14f4e8bcf79
author refinery-platform
date Thu, 22 Feb 2018 14:14:03 -0500
parents
children
comparison
equal deleted inserted replaced
0:5b28174e774d 1:b87749d7a24c
1 #!/usr/bin/env python
2
3 '''
4 Test tool for splitting output files from Refinery Test Tools
5
6 @author: Scott Ouellette
7
8 Input: one text file
9 Output: N output files based on the amount of input files that
10 got concatenated from Refinery test tool runs
11
12 Requires Python v2.7
13
14 '''
15
16 import re
17 import argparse
18
19
20 def main(args):
21 create_many_files(args.input_file)
22
23
24 def create_many_files(input_file):
25 # Split file's content when we see data that wasn't added by test tool runs
26 file_content = re.split("Output.*|Input.*", input_file.read())
27
28 sanitized_data = [
29 data.lstrip("\n") for data in file_content if data.rstrip("\n")]
30
31 # Create N ouput files based on the number of inputs run through test tools
32 for num, file_content in enumerate(sanitized_data):
33 open("Output file {}.txt".format(num + 1), 'w').write(file_content)
34
35
36 if __name__ == '__main__':
37 version = "%(prog)s 0.1"
38 description = "Test tool for running workflows on Galaxy platform from Refinery"
39 parser = argparse.ArgumentParser(description=description, version=version)
40
41 parser.add_argument('-i', '--in-file', dest='input_file',
42 type=file, metavar='INPUT_FILE', required=True,
43 help='name of the input file')
44
45 # check argument values for errors
46 try:
47 args = parser.parse_args()
48 except IOError as e:
49 parser.error(e)
50
51 main(args)