Skip to content

Commit

Permalink
Merge pull request #70 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
basic test of writing alignments
  • Loading branch information
GavinHuttley authored Feb 13, 2024
2 parents 6b9d73f + 28cf080 commit 953166e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 0 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def test(session):
"pytest",
"-s",
"-x",
"-m",
"not slow",
"--cov-report",
f"lcov:lcov-{session.python}.info",
"--cov",
Expand Down
7 changes: 5 additions & 2 deletions src/ensembl_lite/_aligndb.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,13 @@ def write_alignments(
outdir: os.PathLike,
ref_species: str,
stableids: list[str],
show_progress: bool = True,
):
# then the coordinates for the id's
ref_genome = genomes[ref_species]
locations = []
for stableid in stableids:
record = list(ref_genome.annotations.get_records_matching(name=stableid))
record = list(ref_genome.annotation_db.get_records_matching(name=stableid))
if not record:
continue
elif len(record) == 1:
Expand All @@ -478,7 +479,9 @@ def write_alignments(
if limit:
locations = locations[:limit]

for stableid, species, seqid, start, end in track(locations):
for stableid, species, seqid, start, end in track(
locations, disable=not show_progress
):
alignments = list(
get_alignment(
align_db,
Expand Down
20 changes: 19 additions & 1 deletion tests/test_aligndb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import numpy
import pytest

from cogent3 import make_seq
from cogent3 import load_aligned_seqs, make_seq
from cogent3.core.annotation_db import GffAnnotationDb

from ensembl_lite._aligndb import (
AlignDb,
AlignRecord,
GapPositions,
get_alignment,
write_alignments,
)
from ensembl_lite._genomedb import CompressedGenomeSeqsDb, Genome
from ensembl_lite.convert import seq_to_gap_coords
Expand Down Expand Up @@ -578,3 +579,20 @@ def test_align_db_get_records_no_matches(coord):
def test_get_species():
_, align_db = make_sample()
assert set(align_db.get_species_names()) == {"dog", "human", "mouse"}


def test_write_alignments(tmp_path):
genomes, align_db = make_sample(two_aligns=True)
write_alignments(
align_db=align_db,
genomes=genomes,
outdir=tmp_path,
limit=None,
mask_features=None,
stableids=["not-on-s2"],
ref_species="human",
show_progress=False,
)
aln_path = list(tmp_path.glob("*"))[0]
aln = load_aligned_seqs(aln_path, moltype="dna")
assert len(aln) == 3

0 comments on commit 953166e

Please sign in to comment.