Mercurial > repos > earlhaminst > hcluster_sg_parser
comparison hcluster_sg_parser.py @ 4:02d73e6ca869 draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit e35f2ea026b79daaced9a2a50da02b4881d6154b
author | earlhaminst |
---|---|
date | Fri, 19 Jul 2019 11:44:07 -0400 |
parents | f9e418125021 |
children | 07f5b2c5ac10 |
comparison
equal
deleted
inserted
replaced
3:f9e418125021 | 4:02d73e6ca869 |
---|---|
15 parser = optparse.OptionParser() | 15 parser = optparse.OptionParser() |
16 parser.add_option('-m', '--min', type='int', default=0, help='Minimum number of cluster elements') | 16 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') | 17 parser.add_option('-M', '--max', type='int', default=sys.maxsize, help='Maximum number of cluster elements') |
18 options, args = parser.parse_args() | 18 options, args = parser.parse_args() |
19 | 19 |
20 with open(args[1], 'w') as discarded_out: | 20 with open(args[2], 'w') as discarded_max_out: |
21 with open(args[0]) as fh: | 21 with open(args[1], 'w') as discarded_min_out: |
22 for line in fh: | 22 with open(args[0]) as fh: |
23 line = line.rstrip() | 23 for line in fh: |
24 line_cols = line.split('\t') | 24 line = line.rstrip() |
25 cluster_id = line_cols[0] | 25 line_cols = line.split('\t') |
26 n_ids = int(line_cols[-2]) | 26 cluster_id = line_cols[0] |
27 id_list = line_cols[-1].replace(',', '\n') | 27 n_ids = int(line_cols[-2]) |
28 if n_ids >= options.min and n_ids <= options.max: | 28 id_list = line_cols[-1].replace(',', '\n') |
29 outfile = cluster_id + '_output.txt' | 29 if n_ids < options.min: |
30 with open(outfile, 'w') as f: | 30 discarded_min_out.write(id_list) |
31 f.write(id_list) | 31 elif n_ids > options.max: |
32 else: | 32 discarded_max_out.write(id_list) |
33 discarded_out.write(id_list) | 33 else: |
34 outfile = cluster_id + '_output.txt' | |
35 with open(outfile, 'w') as f: | |
36 f.write(id_list) | |
34 | 37 |
35 | 38 |
36 if __name__ == "__main__": | 39 if __name__ == "__main__": |
37 main() | 40 main() |