comparison hcluster_sg_parser.py @ 5:07f5b2c5ac10 draft default tip

"planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit e015ac3e0d8c1bc62b1301527241ee5e377b91db"
author earlhaminst
date Fri, 10 Sep 2021 15:08:06 +0000
parents 02d73e6ca869
children
comparison
equal deleted inserted replaced
4:02d73e6ca869 5:07f5b2c5ac10
3 3
4 When a minimum and/or maximum number of cluster elements are specified, the IDs contained in the filtered-out clusters are collected in the "discarded IDS" output dataset. 4 When a minimum and/or maximum number of cluster elements are specified, the IDs contained in the filtered-out clusters are collected in the "discarded IDS" output dataset.
5 5
6 Usage: 6 Usage:
7 7
8 python hcluster_sg_parser.py [-m <N>] [-M <N>] <file> <discarded_out> 8 python hcluster_sg_parser.py [-m <N>] [-M <N>] <file> <discarded_min_out> <discarded_max_out>
9 """ 9 """
10 import optparse 10 import optparse
11 import os
11 import sys 12 import sys
12 13
13 14
14 def main(): 15 def main():
15 parser = optparse.OptionParser() 16 parser = optparse.OptionParser()
16 parser.add_option('-m', '--min', type='int', default=0, help='Minimum number of cluster elements') 17 parser.add_option('-m', '--min', type='int', default=0, help='Minimum number of cluster elements')
17 parser.add_option('-M', '--max', type='int', default=sys.maxsize, help='Maximum number of cluster elements') 18 parser.add_option('-M', '--max', type='int', default=sys.maxsize, help='Maximum number of cluster elements')
19 parser.add_option('-d', '--dir', type='string', help="Absolute or relative path to output directory. If the directory does not exist, it will be created")
18 options, args = parser.parse_args() 20 options, args = parser.parse_args()
19 21
22 if options.dir and not os.path.exists(options.dir):
23 os.mkdir(options.dir)
20 with open(args[2], 'w') as discarded_max_out: 24 with open(args[2], 'w') as discarded_max_out:
21 with open(args[1], 'w') as discarded_min_out: 25 with open(args[1], 'w') as discarded_min_out:
22 with open(args[0]) as fh: 26 with open(args[0]) as fh:
23 for line in fh: 27 for line in fh:
24 line = line.rstrip() 28 line = line.rstrip()
30 discarded_min_out.write(id_list) 34 discarded_min_out.write(id_list)
31 elif n_ids > options.max: 35 elif n_ids > options.max:
32 discarded_max_out.write(id_list) 36 discarded_max_out.write(id_list)
33 else: 37 else:
34 outfile = cluster_id + '_output.txt' 38 outfile = cluster_id + '_output.txt'
39 if options.dir:
40 outfile = os.path.join(options.dir, outfile)
35 with open(outfile, 'w') as f: 41 with open(outfile, 'w') as f:
36 f.write(id_list) 42 f.write(id_list)
37 43
38 44
39 if __name__ == "__main__": 45 if __name__ == "__main__":