Mercurial > repos > jpayne > quast_select
comparison quast_select.py @ 0:c36a89d3a351 tip
planemo upload
author | jpayne |
---|---|
date | Wed, 07 Feb 2018 16:37:42 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c36a89d3a351 |
---|---|
1 from __future__ import print_function | |
2 | |
3 import csv | |
4 from operator import lt, gt | |
5 import sys | |
6 | |
7 def pick(rows, key, reverse=False): | |
8 sorted_rows = sorted(rows, key=lambda r:r[key], reverse=reverse) | |
9 return sorted_rows[0]['Assembly'] | |
10 | |
11 def int_or_str(token): | |
12 try: | |
13 return int(token) | |
14 except ValueError: | |
15 return str(token) | |
16 | |
17 if __name__ == '__main__': | |
18 path, compared = sys.argv[1:] | |
19 #QUAST tables have sample info as columns, so we need to transpose the table | |
20 rows = list(zip(*csv.reader(open(path, "rU"), delimiter='\t', dialect='excel'))) | |
21 hed = rows.pop(0) | |
22 dict_rows = [{h : int_or_str(r[i]) for i, h in enumerate(hed)} for r in rows] | |
23 if "#" in compared: | |
24 reverse = False #if it's a count, we want the fewest | |
25 else: | |
26 reverse = True #otherwise it's a length and we want the longest | |
27 print(pick(dict_rows, compared, reverse)) |