Mercurial > repos > greg > cfsan_snp_pipeline_quast_select
comparison cfsan_snp_pipeline_quast_select.py @ 0:fedc60909fbe draft default tip
Uploaded
| author | greg |
|---|---|
| date | Tue, 17 Oct 2023 14:13:45 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:fedc60909fbe |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import csv | |
| 4 import sys | |
| 5 | |
| 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 | |
| 12 def int_or_str(token): | |
| 13 try: | |
| 14 return int(token) | |
| 15 except ValueError: | |
| 16 return str(token) | |
| 17 | |
| 18 | |
| 19 if __name__ == '__main__': | |
| 20 path, criterion = sys.argv[1:] | |
| 21 # QUAST tables have sample info as columns, so we need to transpose the table. | |
| 22 rows = list(zip(*csv.reader(open(path, "r"), delimiter='\t', dialect='excel'))) | |
| 23 hed = rows.pop(0) | |
| 24 dict_rows = [{h: int_or_str(r[i]) for i, h in enumerate(hed)} for r in rows] | |
| 25 if "fewest" in criterion: | |
| 26 # If it's a count, we want the fewest. | |
| 27 reverse = False | |
| 28 else: | |
| 29 # Otherwise it's a length and we want the longest. | |
| 30 reverse = True | |
| 31 print(pick(dict_rows, criterion, reverse)) |
