-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: uniformize somatic-variant definition across bin scripts #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m-huertasp
wants to merge
19
commits into
dev
Choose a base branch
from
tests/418-uniformize-somatic-variants
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f199f73
feat: add somatic/germline mask to utils_filter
m-huertasp 30b8521
test: add unit test for all utils filter functions
m-huertasp 39e5bb7
refactor: use shared helper in filter_cohort
m-huertasp 8d1ce9a
refactor: use helper in check_contamination
m-huertasp 07f4e27
docs: add docstrings to check contamination
m-huertasp d39c828
docs: fix typo in docstring
m-huertasp 38bc0c1
refactor: use somatic threshold parameter in check contamination
m-huertasp f207ec4
style_ remove unused import and f-string prefixes
m-huertasp 7a448f6
fix: added loc for df division
m-huertasp 91100a8
remove: _plot_selectionfeatures.py (unused)
m-huertasp 5480178
chore: update reference datasets paths
m-huertasp 82b6999
tests: check contamination initial test
m-huertasp a68ad3f
refactor: move heatmap creation to parametrized function
m-huertasp 1f0c806
refactor: extract prepare datasets
m-huertasp b93e547
refactor: extract somatic vs germline
m-huertasp 88354a7
refactor: common code to single function
m-huertasp d2196a1
refactor: apply two_way_comparison to all possible
m-huertasp e91717b
refactor: exploration of contaminated samples
m-huertasp 19dee49
refactor: contamination detection snps
m-huertasp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
|
FerriolCalvet marked this conversation as resolved.
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Unit tests for check_contamination.py | ||
|
|
||
| Tests the functionality of checking contamination in genomic data. | ||
| """ | ||
|
|
||
| import sys | ||
| import unittest | ||
| from pathlib import Path | ||
| import pandas as pd | ||
| import numpy as np | ||
|
|
||
| # Add the bin directory to the path to import the module | ||
| sys.path.insert(0, str(Path(__file__).parent.parent)) | ||
| from check_contamination import compute_shared_variants | ||
|
|
||
| class TestComputeSharedVariants(unittest.TestCase): | ||
| """Test suite for compute_shared_variants function.""" | ||
|
|
||
| def _somatic_df(self): | ||
| """Return a minimal somatic variants DataFrame.""" | ||
| return pd.DataFrame({ | ||
| 'SAMPLE_ID': ['s1', 's1', 's2'], | ||
| 'MUT_ID': ['mut1', 'mut2', 'mut3'], | ||
| }) | ||
|
|
||
| def _germline_df(self): | ||
| """Return a minimal germline variants DataFrame.""" | ||
| return pd.DataFrame({ | ||
| 'SAMPLE_ID': ['s1', 's1', 's2'], | ||
| 'MUT_ID': ['mut1', 'mut4', 'mut5'], | ||
| }) | ||
|
|
||
| # ---- basic behaviour ------------------------------------------------ | ||
|
|
||
| def test_returns_dataframe(self): | ||
| result = compute_shared_variants(self._somatic_df(), self._germline_df()) | ||
| self.assertIsInstance(result, pd.DataFrame) | ||
|
|
||
| def test_dtype_is_int(self): | ||
| result = compute_shared_variants(self._somatic_df(), self._germline_df()) | ||
| self.assertEqual(result.dtypes['s1'], np.int64) | ||
|
|
||
| def test_shared_mutations_count(self): | ||
| """s1 shares mut1 with s1 → cell [s1, s1] == 1.""" | ||
| result = compute_shared_variants(self._somatic_df(), self._germline_df()) | ||
| self.assertEqual(result.loc['s1', 's1'], 1) | ||
|
|
||
| def test_no_shared_mutations(self): | ||
| """s2 has mut3 which s1/s2 don't have → cell [s2, s1] == 0.""" | ||
| result = compute_shared_variants(self._somatic_df(), self._germline_df()) | ||
| self.assertEqual(result.loc['s2', 's1'], 0) | ||
|
|
||
| def test_multiple_shared_mutations(self): | ||
| som = pd.DataFrame({'SAMPLE_ID': ['s1'], 'MUT_ID': ['mut1']}) | ||
| ger = pd.DataFrame({ | ||
| 'SAMPLE_ID': ['s1', 's1', 's1'], | ||
| 'MUT_ID': ['mut1', 'mut1', 'mut2'], # mut1 appears twice | ||
| }) | ||
| result = compute_shared_variants(som, ger) | ||
| # mut1 is in both sets → intersection size is 1 (set semantics) | ||
| self.assertEqual(result.loc['s1', 's1'], 1) | ||
|
|
||
| def test_empty_somatic(self): | ||
| result = compute_shared_variants( | ||
| pd.DataFrame({'SAMPLE_ID': [], 'MUT_ID': []}), | ||
| self._germline_df(), | ||
| ) | ||
| self.assertEqual(len(result), 0) | ||
|
|
||
| def test_empty_germline(self): | ||
| result = compute_shared_variants( | ||
| self._somatic_df(), | ||
| pd.DataFrame({'SAMPLE_ID': [], 'MUT_ID': []}), | ||
| ) | ||
| self.assertEqual(len(result.columns), 0) | ||
|
|
||
| def test_both_empty(self): | ||
| result = compute_shared_variants( | ||
| pd.DataFrame({'SAMPLE_ID': [], 'MUT_ID': []}), | ||
| pd.DataFrame({'SAMPLE_ID': [], 'MUT_ID': []}), | ||
| ) | ||
| self.assertIsInstance(result, pd.DataFrame) | ||
| self.assertEqual(result.shape, (0, 0)) | ||
|
|
||
| def test_samples_sorted(self): | ||
| """Sample IDs should appear in sorted order in index/columns.""" | ||
| som = pd.DataFrame({'SAMPLE_ID': ['z', 'a'], 'MUT_ID': ['m1', 'm2']}) | ||
| ger = pd.DataFrame({'SAMPLE_ID': ['y', 'b'], 'MUT_ID': ['m3', 'm4']}) | ||
| result = compute_shared_variants(som, ger) | ||
| self.assertEqual(list(result.index), ['a', 'z']) | ||
| self.assertEqual(list(result.columns), ['b', 'y']) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.