-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from alliance-genome/KANBAN-504_seq-retrieval
KANBAN-504 seq retrieval - added unit testing
- Loading branch information
Showing
13 changed files
with
179 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,5 @@ | ||
[tool.pytest.ini_options] | ||
addopts = [ | ||
"--import-mode=importlib", | ||
] | ||
pythonpath = "src" |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
flake8==7.0.* | ||
mypy==1.9.* | ||
pytest==8.0.* |
Binary file added
BIN
+5.69 MB
pipeline/seq_retrieval/tests/resources/GCF_000002985.6_WBcel235_genomic_X.fna.gz
Binary file not shown.
1 change: 1 addition & 0 deletions
1
pipeline/seq_retrieval/tests/resources/GCF_000002985.6_WBcel235_genomic_X.fna.gz.fai
This file contains 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 @@ | ||
X 17718942 3 80 81 |
Binary file added
BIN
+4.3 KB
pipeline/seq_retrieval/tests/resources/GCF_000002985.6_WBcel235_genomic_X.fna.gz.gzi
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
pipeline/seq_retrieval/tests/unit/data_mover/test_data_file_mover.py
This file contains 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,40 @@ | ||
""" | ||
Unit testing for data_file_mover module | ||
""" | ||
|
||
from pathlib import Path | ||
import os.path | ||
|
||
from data_mover.data_file_mover import is_accessible_url, download_from_url, find_local_file, fetch_file | ||
|
||
|
||
FASTA_URL = 'https://s3.amazonaws.com/agrjbrowse/fasta/GCF_000146045.2_R64_genomic.fna.gz' | ||
DOWNLOAD_DIR = 'tests/tmp/' | ||
|
||
|
||
def test_is_accessible_url(): | ||
response = is_accessible_url(FASTA_URL) | ||
|
||
assert isinstance(response, bool) | ||
assert response is True | ||
|
||
|
||
def test_download_from_url(): | ||
downloaded_file_path = download_from_url(url=FASTA_URL, dest_dir=DOWNLOAD_DIR, reuse_local_cache=False) | ||
|
||
expected_rel_file_path = os.path.join(DOWNLOAD_DIR, 'GCF_000146045.2_R64_genomic.fna.gz') | ||
expected_abs_file_path = str(Path(expected_rel_file_path).resolve()) | ||
|
||
assert isinstance(downloaded_file_path, str) | ||
assert downloaded_file_path == expected_abs_file_path | ||
|
||
assert find_local_file(expected_rel_file_path) == expected_abs_file_path | ||
|
||
# Test cached retrieval | ||
download_last_modified = os.path.getmtime(filename=downloaded_file_path) | ||
|
||
fetched_file_path = fetch_file(url=FASTA_URL, dest_dir=DOWNLOAD_DIR, reuse_local_cache=True) | ||
fetch_last_modified = os.path.getmtime(filename=fetched_file_path) | ||
|
||
# Assert fetched file has not been redownloaded but is the previously downloaded file | ||
assert download_last_modified == fetch_last_modified |
51 changes: 51 additions & 0 deletions
51
pipeline/seq_retrieval/tests/unit/seq_region/test_seq_region.py
This file contains 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,51 @@ | ||
""" | ||
Unit testing for SeqRegion class and related functions | ||
""" | ||
|
||
from seq_region import SeqRegion, chain_seq_region_seqs | ||
|
||
|
||
FASTA_FILE_URL = 'file://tests/resources/GCF_000002985.6_WBcel235_genomic_X.fna.gz' | ||
|
||
|
||
def test_seq_region_class(): | ||
|
||
# WBGene00000149 Transcript:C42D8.8b.1 Exon 1 (mRNA start) | ||
exon_1: SeqRegion = SeqRegion(seq_id='X', start=5116799, end=5116864, strand='-', | ||
fasta_file_url=FASTA_FILE_URL) | ||
|
||
assert isinstance(exon_1, SeqRegion) | ||
|
||
exon_1.fetch_seq() | ||
exon_1_seq: str = exon_1.get_sequence() | ||
|
||
assert isinstance(exon_1_seq, str) | ||
assert exon_1_seq == 'atgACGGTGGGTAAACTAATGATTGGCTTACTTATACCGATTCTTGTCGCCACAGTTTACGCAGAG' | ||
|
||
|
||
def test_seq_region_chaining(): | ||
|
||
# WBGene00000149 Transcript:C42D8.8b.1 Exon 1 (mRNA start) | ||
exon_1: SeqRegion = SeqRegion(seq_id='X', start=5116799, end=5116864, strand='-', | ||
fasta_file_url=FASTA_FILE_URL) | ||
EXON_1_SEQ = 'atgACGGTGGGTAAACTAATGATTGGCTTACTTATACCGATTCTTGTCGCCACAGTTTACGCAGAG' | ||
|
||
# WBGene00000149 Transcript:C42D8.8b.1 Exon 2 | ||
exon_2: SeqRegion = SeqRegion(seq_id='X', start=5116171, end=5116338, strand='-', | ||
fasta_file_url=FASTA_FILE_URL) | ||
EXON_2_SEQ = 'ggTTCCCCAGCAGGCAGCAAGCGACATGAGAAGTTCATTCCAATGGTCGCATTTTCATGTGGATACCGCAACCAGTATATGACCGAAGAGGGATCATGGAAGACTGATGATGAACGATATGCCACCTGCTTCTCTGGCAAACTTGACATCCTCAAGTACTGCCGCAAG' | ||
|
||
# WBGene00000149 Transcript:C42D8.8b.1 Exon 3 | ||
exon_3: SeqRegion = SeqRegion(seq_id='X', start=5115556, end=5115682, strand='-', | ||
fasta_file_url=FASTA_FILE_URL) | ||
EXON_3_SEQ = 'GCTTATCCATCCATGAACATCACCAACATCGTCGAATACTCGCACGAAGTGAGCATCTCCGACTGGTGCCGCGAGGAAGGATCGCCATGCAAGTGGACTCACAGTGTCAGACCGTACCATTGCATTG' | ||
|
||
seq_region_list = [exon_1, exon_2, exon_3] | ||
|
||
for exon in seq_region_list: | ||
exon.fetch_seq() | ||
|
||
chained_seq = chain_seq_region_seqs(seq_region_list, '-') | ||
|
||
assert isinstance(chained_seq, str) | ||
assert chained_seq == EXON_1_SEQ + EXON_2_SEQ + EXON_3_SEQ |