|
| 1 | +import os |
| 2 | +import pandas as pd |
| 3 | +import pytest |
| 4 | + |
| 5 | +from pelc.batch_eplet_comp import compute_epletic_load |
| 6 | +from pelc.output_type import OutputType |
| 7 | +from tests.base_loading_for_tests import base_loading |
| 8 | + |
| 9 | +def test_one_chromosome() -> None: |
| 10 | + """ |
| 11 | + Test the epletic load calculation with only one chromosome. If only one chromosome is present, it has to be |
| 12 | + the first one, and it will mean it's a homozygote. Otherwise, _equal_amount_of_unknown_alleles will return False |
| 13 | + and compute_epletic_load will return None. No file will then be created. |
| 14 | + :return: None |
| 15 | + """ |
| 16 | + |
| 17 | + # OK |
| 18 | + donordf, recipientdf, output_path = base_loading("pytest_only_one_chromosome_ok.xlsx", "Sheet 1") |
| 19 | + |
| 20 | + for class_1 in False, True: |
| 21 | + compute_epletic_load( |
| 22 | + donordf, |
| 23 | + recipientdf, |
| 24 | + output_path, |
| 25 | + OutputType.DETAILS_AND_COUNT, |
| 26 | + class_1, # class_i |
| 27 | + True, # class_ii |
| 28 | + False, # abv_only |
| 29 | + ) |
| 30 | + |
| 31 | + output_df: pd.DataFrame = pd.read_csv(f"{output_path}.csv", index_col="Index") |
| 32 | + |
| 33 | + assert output_df.at[8, "EpMismatches"] == "160S_DQ" |
| 34 | + assert output_df.at[8, "Eplet Load"] == 1 |
| 35 | + |
| 36 | + os.remove(f"{output_path}.csv") |
| 37 | + |
| 38 | + # NOT OK |
| 39 | + donordf, recipientdf, output_path = base_loading("pytest_only_one_chromosome_not_ok.xlsx", "Sheet 1") |
| 40 | + |
| 41 | + for class_1 in False, True: |
| 42 | + # Make sure this raises a ValueError |
| 43 | + with pytest.raises(ValueError): |
| 44 | + compute_epletic_load( |
| 45 | + donordf, |
| 46 | + recipientdf, |
| 47 | + output_path, |
| 48 | + OutputType.DETAILS_AND_COUNT, |
| 49 | + class_1, # class_i |
| 50 | + True, # class_ii |
| 51 | + False, # abv_only |
| 52 | + ) |
| 53 | + |
| 54 | + # NOT OK2 |
| 55 | + donordf, recipientdf, output_path = base_loading("pytest_only_one_chromosome_not_ok_2.xlsx", "Sheet 1") |
| 56 | + |
| 57 | + for class_1 in False, True: |
| 58 | + # Make sure this raises a ValueError |
| 59 | + with pytest.raises(ValueError): |
| 60 | + compute_epletic_load( |
| 61 | + donordf, |
| 62 | + recipientdf, |
| 63 | + output_path, |
| 64 | + OutputType.DETAILS_AND_COUNT, |
| 65 | + class_1, # class_i |
| 66 | + True, # class_ii |
| 67 | + False, # abv_only |
| 68 | + ) |
0 commit comments