Mercurial > repos > bebatut > extract_sequence_file
annotate test-data/src/compare_files.py @ 1:bbde61ab5519 draft default tip
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit 5c45ed58045ce1686aa069403f8a9426ea20bac5-dirty
author | bebatut |
---|---|
date | Tue, 12 Apr 2016 02:59:22 -0400 |
parents | 14fd6f3b0898 |
children |
rev | line source |
---|---|
0
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
1 #!/usr/bin/python |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
3 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
4 import sys |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
5 import os |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
6 import argparse |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
7 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
8 def readfile(filepath): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
9 content = [] |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
10 with open(filepath, 'r') as open_file: |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
11 for row in open_file.readlines(): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
12 content.append(row[:-1].split(" ")) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
13 return content |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
14 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
15 def compare_content(expected, observed, comparison): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
16 if len(expected) != len(observed): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
17 string = comparison + ': ' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
18 string += 'difference in line number\n' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
19 string += '\t\texpected:' + str(len(expected)) + '\n' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
20 string += '\t\tobserved:' + str(len(observed)) + '\n' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
21 raise ValueError(string) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
22 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
23 for i in range(len(expected)): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
24 if expected[i] != observed[i]: |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
25 string = comparison + ': ' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
26 string += 'difference in line ' + str(i) + '\n' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
27 string += '\t' + ' '.join(expected[i]) + '\n' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
28 string += '\t' + ' '.join(observed[i]) + '\n' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
29 raise ValueError(string) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
30 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
31 def test_file(filepath): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
32 if not os.path.exists(filepath): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
33 string = os.path.basename(__file__) + ':' + filepath |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
34 string += ' does not exist' |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
35 raise ValueError(string) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
36 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
37 def compare_files(expected_filepath, observed_filepath, comparison): |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
38 test_file(expected_filepath) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
39 test_file(observed_filepath) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
40 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
41 expected_file_content = readfile(expected_filepath) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
42 observed_file_content = readfile(observed_filepath) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
43 compare_content(expected_file_content, observed_file_content, comparison) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
44 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
45 if __name__ == "__main__": |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
46 parser = argparse.ArgumentParser() |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
47 parser.add_argument('--exp_file', required=True) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
48 parser.add_argument('--obs_file', required=True) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
49 parser.add_argument('--comparison', required=True) |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
50 args = parser.parse_args() |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
51 |
14fd6f3b0898
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/extract_sequence_file/ commit ffb68b2ddd94854a34a2533105f7bc08884c6e38-dirty
bebatut
parents:
diff
changeset
|
52 compare_files(args.exp_file, args.obs_file, args.comparison) |