Mercurial > repos > earlhaminst > hcluster_sg_parser
annotate hcluster_sg_parser.py @ 3:f9e418125021 draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit 66af14bc1642c1ca6ceb21f6018c8d665da890e8
author | earlhaminst |
---|---|
date | Fri, 28 Apr 2017 12:51:35 -0400 |
parents | 17aa68582a05 |
children | 02d73e6ca869 |
rev | line source |
---|---|
1
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
1 """ |
3
f9e418125021
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit 66af14bc1642c1ca6ceb21f6018c8d665da890e8
earlhaminst
parents:
1
diff
changeset
|
2 A simple parser to convert the hcluster_sg output into lists of IDs, one list for each cluster. |
1
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
3 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
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. |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
5 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
6 Usage: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
7 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
8 python hcluster_sg_parser.py [-m <N>] [-M <N>] <file> <discarded_out> |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
9 """ |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
10 import optparse |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
11 import sys |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
12 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
13 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
14 def main(): |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
15 parser = optparse.OptionParser() |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
16 parser.add_option('-m', '--min', type='int', default=0, help='Minimum number of cluster elements') |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
17 parser.add_option('-M', '--max', type='int', default=sys.maxsize, help='Maximum number of cluster elements') |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
18 options, args = parser.parse_args() |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
19 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
20 with open(args[1], 'w') as discarded_out: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
21 with open(args[0]) as fh: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
22 for line in fh: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
23 line = line.rstrip() |
3
f9e418125021
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit 66af14bc1642c1ca6ceb21f6018c8d665da890e8
earlhaminst
parents:
1
diff
changeset
|
24 line_cols = line.split('\t') |
f9e418125021
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit 66af14bc1642c1ca6ceb21f6018c8d665da890e8
earlhaminst
parents:
1
diff
changeset
|
25 cluster_id = line_cols[0] |
f9e418125021
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit 66af14bc1642c1ca6ceb21f6018c8d665da890e8
earlhaminst
parents:
1
diff
changeset
|
26 n_ids = int(line_cols[-2]) |
f9e418125021
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit 66af14bc1642c1ca6ceb21f6018c8d665da890e8
earlhaminst
parents:
1
diff
changeset
|
27 id_list = line_cols[-1].replace(',', '\n') |
1
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
28 if n_ids >= options.min and n_ids <= options.max: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
29 outfile = cluster_id + '_output.txt' |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
30 with open(outfile, 'w') as f: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
31 f.write(id_list) |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
32 else: |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
33 discarded_out.write(id_list) |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
34 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
35 |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
36 if __name__ == "__main__": |
17aa68582a05
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/hcluster_sg_parser commit a79c8f1799189754eae80aede6fbe5428570f36b
earlhaminst
parents:
diff
changeset
|
37 main() |