Skip to content
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

basic test of writing alignments #70

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading