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