Skip to content

Commit

Permalink
added test for calculate_allele frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Mück committed May 8, 2024
1 parent 7891417 commit 7e7ff8f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
9 changes: 8 additions & 1 deletion deeprvat/annotations/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,14 @@ def process_vep(
)
if "#Uploaded_variation" in vep_file.columns:
vep_file = vep_file.merge(vcf_df, on="#Uploaded_variation", how = 'left')
vep_file.loc[vep_file.chrom.isna(),['chrom','pos','ref','alt']]=vep_file[vep_file['chrom'].isna()]['#Uploaded_variation'].str.replace("_", ":").str.replace("/", ":").str.split(':', expand=True).values
if vep_file.chrom.isna().sum()>0:
vep_file.loc[vep_file.chrom.isna(),['chrom','pos','ref','alt']]=vep_file[vep_file['chrom'].isna()]['#Uploaded_variation'].str.replace("_", ":").str.replace("/", ":").str.split(':', expand=True).values
assert vep_file.chrom.isna().sum() == 0
assert vep_file.pos.isna().sum() == 0
assert vep_file.ref.isna().sum() == 0
assert vep_file.alt.isna().sum() == 0


if "pos" in vep_file.columns:
vep_file["pos"] = vep_file["pos"].astype(int)

Expand Down
68 changes: 68 additions & 0 deletions tests/annotations/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,74 @@ def test_merge_absplice_scores(
assert written_results.shape == expected_results.shape
assert_frame_equal(written_results, expected_results, check_exact = False)

@pytest.mark.parametrize(
"test_data_name_dir, genotype_file, variant_file, expected",
[
( "calculate_allele_frequency_small",
"genotypes.h5",
"variants.parquet",
"af_df.parquet",
),
]
)
def test_calculate_allele_frequencies(
test_data_name_dir, genotype_file, variant_file, expected, tmp_path
):
current_test_data_dir = tests_data_dir / 'calculate_allele_frequency' / test_data_name_dir
genotype_filepath = current_test_data_dir / 'input' / genotype_file
variant_filepath = current_test_data_dir / 'input' /variant_file
expected_path = current_test_data_dir / 'expected' / expected
output_path = tmp_path / 'out.parquet'
cli_runner = CliRunner()
cli_parameters = [
'get-af-from-gt',
genotype_filepath.as_posix(),
variant_filepath.as_posix(),
output_path.as_posix(),
]
result = cli_runner.invoke(annotations_cli, cli_parameters, catch_exceptions=False)
assert result.exit_code == 0
written_results = pd.read_parquet(output_path)
expected_results = pd.read_parquet(expected_path)
assert written_results.shape == expected_results.shape
assert_frame_equal(written_results, expected_results[written_results.columns], check_exact = False)




# @pytest.mark.parametrize(
# "test_data_name_dir, input_file_1, input_file_2, parameter1, expected",
# [
# ( "test_name_dir",
# "input_file1.parquet",
# "input_file2.parquet",
# "8",
# "expected.parquet",
# ),
# ]
# )
# def template(
# test_data_name_dir, input_file_1, input_file_2, parameter1, expected, tmp_path
# ):
# current_test_data_dir = tests_data_dir / 'test_name' / test_data_name_dir
# input_path1 = current_test_data_dir / 'input' / input_file_1
# input_path2 = current_test_data_dir / 'input' /input_file_2
# expected_path = current_test_data_dir / 'expected' / expected
# output_path = tmp_path / 'out.parquet'
# cli_runner = CliRunner()
# cli_parameters = [
# 'function-name',
# input_path1.as_posix(),
# input_path2.as_posix(),
# output_path.as_posix(),
# parameter1,
# ]
# result = cli_runner.invoke(annotations_cli, cli_parameters, catch_exceptions=False)
# assert result.exit_code == 0
# written_results = pd.read_parquet(output_path)
# expected_results = pd.read_parquet(expected_path)
# assert written_results.shape == expected_results.shape
# assert_frame_equal(written_results, expected_results[written_results.columns], check_exact = False)

# @pytest.mark.parametrize(
# "test_name_dir, input_file_1, input_file_2, parameter1, expected",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7e7ff8f

Please sign in to comment.