Mercurial > repos > dcouvin > resfinder4
comparison resfinder/cge/out/test.py @ 0:55051a9bc58d draft default tip
Uploaded
| author | dcouvin |
|---|---|
| date | Mon, 10 Jan 2022 20:06:07 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:55051a9bc58d |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import json | |
| 4 import os.path | |
| 5 | |
| 6 from result import Result | |
| 7 from exceptions import CGECoreOutTypeError, CGECoreOutInputError | |
| 8 from template import CGEOutTemplate | |
| 9 from translate import Translate | |
| 10 | |
| 11 | |
| 12 try: | |
| 13 CGEOutTemplate("nonsense") | |
| 14 except CGECoreOutTypeError: | |
| 15 print("Caught expected template error.") | |
| 16 | |
| 17 soft_dict = CGEOutTemplate("software_result") | |
| 18 soft_dict["software_name"] = "ResFinder" | |
| 19 soft_dict["key"] = "soft_dict key" | |
| 20 soft_dict["version"] = "3.2.0" | |
| 21 | |
| 22 soft_result = Result(**soft_dict) | |
| 23 | |
| 24 test_gene = { | |
| 25 "type": "gene", | |
| 26 "key": "some_gene_key", | |
| 27 "name": "gen_name", | |
| 28 "identity": "187", | |
| 29 "alignment_length": "800", | |
| 30 "ref_gene_lenght": "800", | |
| 31 "coverage": "89", | |
| 32 "ref_id": "some_ref_id" | |
| 33 } | |
| 34 | |
| 35 soft_result.add_class(cl="genes", **test_gene) | |
| 36 | |
| 37 test_dict = { | |
| 38 "type": "software_result", | |
| 39 "software_name": "ResFinder", | |
| 40 "software_version": "4.0", | |
| 41 "run_date": "20200214", | |
| 42 "key": "software_key" | |
| 43 } | |
| 44 | |
| 45 result = Result(result_type="software_result", **test_dict) | |
| 46 result.add_class(cl="genes", **test_gene) | |
| 47 | |
| 48 test_trans_table = { | |
| 49 "primary": "key", | |
| 50 "gene": "name", | |
| 51 "id": "identity", | |
| 52 "alignment": "alignment_length", | |
| 53 "gene_lenght": "ref_gene_lenght", | |
| 54 "cov": "coverage" | |
| 55 } | |
| 56 | |
| 57 translator = Translate("gene", test_trans_table) | |
| 58 | |
| 59 test_gene2 = { | |
| 60 "primary": "some_gene_key2", | |
| 61 "gene": "gen_name2", | |
| 62 "id": "97", | |
| 63 "alignment": "800", | |
| 64 "gene_lenght": "800", | |
| 65 "cov": "99" | |
| 66 } | |
| 67 | |
| 68 result.add_class(cl="genes", result_type="gene", | |
| 69 **translator.translate(test_gene2)) | |
| 70 | |
| 71 try: | |
| 72 result.check_results() | |
| 73 soft_result.check_results() | |
| 74 except CGECoreOutInputError as e: | |
| 75 print("Error dict:\n{}".format(e.errors)) | |
| 76 | |
| 77 print(json.dumps(result)) | |
| 78 print(json.dumps(soft_result)) |
