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