jpayne@0: from __future__ import print_function jpayne@0: jpayne@0: import csv jpayne@0: from operator import lt, gt jpayne@0: import sys jpayne@0: jpayne@0: def pick(rows, key, reverse=False): jpayne@0: sorted_rows = sorted(rows, key=lambda r:r[key], reverse=reverse) jpayne@0: return sorted_rows[0]['Assembly'] jpayne@0: jpayne@0: def int_or_str(token): jpayne@0: try: jpayne@0: return int(token) jpayne@0: except ValueError: jpayne@0: return str(token) jpayne@0: jpayne@0: if __name__ == '__main__': jpayne@0: path, compared = sys.argv[1:] jpayne@0: #QUAST tables have sample info as columns, so we need to transpose the table jpayne@0: rows = list(zip(*csv.reader(open(path, "rU"), delimiter='\t', dialect='excel'))) jpayne@0: hed = rows.pop(0) jpayne@0: dict_rows = [{h : int_or_str(r[i]) for i, h in enumerate(hed)} for r in rows] jpayne@0: if "#" in compared: jpayne@0: reverse = False #if it's a count, we want the fewest jpayne@0: else: jpayne@0: reverse = True #otherwise it's a length and we want the longest jpayne@0: print(pick(dict_rows, compared, reverse))