Spaces:
Running
Running
Download tests/test_annotated_sequence.py from Samad14/bio-nexus-api: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/Samad14/bio-nexus-api/resolve/main/tests/test_annotated_sequence.py
- Command line
-
hf download hf://spaces/Samad14/bio-nexus-api/tests/test_annotated_sequence.py
-
curl -L -o test_annotated_sequence.py https://huggingface.co/spaces/Samad14/bio-nexus-api/resolve/main/tests/test_annotated_sequence.py
2.06 kB
| from io import StringIO | |
| import pytest | |
| from Bio import SeqIO | |
| from app.tools.annotated_sequence import export_genbank | |
| from app.tools.sequence_utilities import SequenceUtilitiesError | |
| def annotation(start, end, strand=1): | |
| return {'label': 'origin', 'start': start, 'end': end, 'strand': strand, 'type': 'misc_feature'} | |
| def test_roundtrip(): | |
| result = export_genbank('GAATTCAAAA', 'plasmid', True, [annotation(8, 3)], ['EcoRI']) | |
| record = SeqIO.read(StringIO(result['genbank']), 'genbank') | |
| assert str(record.seq) == 'GAATTCAAAA' | |
| assert record.annotations['topology'] == 'circular' | |
| assert len(record.features) == 2 | |
| assert str(record.features[0].extract(record.seq)) == 'AAAGAA' | |
| assert record.features[1].qualifiers['label'] == ['EcoRI'] | |
| def test_reverse_origin(): | |
| result = export_genbank('GAATTCAAAA', 'plasmid', True, [annotation(8, 3, -1)], []) | |
| record = SeqIO.read(StringIO(result['genbank']), 'genbank') | |
| assert str(record.features[0].extract(record.seq)) == 'TTCTTT' | |
| assert result['features'][0]['sequence'] == 'TTCTTT' | |
| def test_invalid_coordinates(feature, circular): | |
| with pytest.raises(SequenceUtilitiesError): | |
| export_genbank('GAATTCAAAA', 'plasmid', circular, [feature], []) | |
| def test_label_and_determinism(): | |
| bad = annotation(1, 3); bad['label'] = 'bad\nORIGIN' | |
| with pytest.raises(SequenceUtilitiesError): | |
| export_genbank('GAATTC', 'plasmid', False, [bad], []) | |
| assert export_genbank('GAATTC', 'plasmid', False, [], []) == export_genbank('GAATTC', 'plasmid', False, [], []) | |
| async def test_endpoint(): | |
| from app.routers.seq_tools import AnnotatedSequenceRequest, annotated_genbank_endpoint | |
| result = await annotated_genbank_endpoint(AnnotatedSequenceRequest(sequence='GAATTC')) | |
| assert result['validation']['biological_annotations_validated'] is False | |
| assert result['results']['filename'] == 'BioNexus_DNA.gb' | |