Mercurial > repos > devteam > subtract_query
comparison subtract_query.py @ 3:f58ba0382c26 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract_query commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
author | devteam |
---|---|
date | Thu, 22 Jun 2017 18:51:44 -0400 |
parents | df4bce472400 |
children |
comparison
equal
deleted
inserted
replaced
2:659a1c095357 | 3:f58ba0382c26 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Greg Von Kuster | 2 # Greg Von Kuster |
3 | |
4 """ | 3 """ |
5 Subtract an entire query from another query | 4 Subtract an entire query from another query |
6 usage: %prog in_file_1 in_file_2 begin_col end_col output | 5 usage: %prog in_file_1 in_file_2 begin_col end_col output |
7 --ignore-empty-end-cols: ignore empty end columns when subtracting | 6 --ignore-empty-end-cols: ignore empty end columns when subtracting |
8 """ | 7 """ |
8 from __future__ import print_function | |
9 | |
9 import sys | 10 import sys |
11 | |
10 from bx.cookbook import doc_optparse | 12 from bx.cookbook import doc_optparse |
11 | 13 |
12 # Older py compatibility | 14 # Older py compatibility |
13 try: | 15 try: |
14 set() | 16 set() |
79 begin_col = end_col = '' | 81 begin_col = end_col = '' |
80 | 82 |
81 try: | 83 try: |
82 fo = open(out_file, 'w') | 84 fo = open(out_file, 'w') |
83 except: | 85 except: |
84 print >> sys.stderr, "Unable to open output file" | 86 print("Unable to open output file", file=sys.stderr) |
85 sys.exit() | 87 sys.exit() |
86 | 88 |
87 """ | 89 """ |
88 len1 is the number of lines in inp1_file | 90 len1 is the number of lines in inp1_file |
89 lines1 is the set of unique lines in inp1_file | 91 lines1 is the set of unique lines in inp1_file |
95 | 97 |
96 lines1.difference_update(lines2) | 98 lines1.difference_update(lines2) |
97 """lines1 is now the set of unique lines in inp1_file - the set of unique lines in inp2_file""" | 99 """lines1 is now the set of unique lines in inp1_file - the set of unique lines in inp2_file""" |
98 | 100 |
99 for line in lines1: | 101 for line in lines1: |
100 print >> fo, line | 102 print(line, file=fo) |
101 | 103 |
102 fo.close() | 104 fo.close() |
103 | 105 |
104 info_msg = 'Subtracted %d lines. ' % ((len1 - diff1) - len(lines1)) | 106 info_msg = 'Subtracted %d lines. ' % ((len1 - diff1) - len(lines1)) |
105 | 107 |
107 info_msg += 'Restricted to columns c' + str(begin_col) + ' thru c' + str(end_col) + '. ' | 109 info_msg += 'Restricted to columns c' + str(begin_col) + ' thru c' + str(end_col) + '. ' |
108 | 110 |
109 if diff1 > 0: | 111 if diff1 > 0: |
110 info_msg += 'Eliminated %d duplicate/blank/comment/invalid lines from first query.' % diff1 | 112 info_msg += 'Eliminated %d duplicate/blank/comment/invalid lines from first query.' % diff1 |
111 | 113 |
112 print info_msg | 114 print(info_msg) |
115 | |
113 | 116 |
114 if __name__ == "__main__": | 117 if __name__ == "__main__": |
115 main() | 118 main() |