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

add support for rat species #6

Merged
merged 2 commits into from
Oct 14, 2021
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
32 changes: 28 additions & 4 deletions ensembl_genes/species.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Union
from typing import Optional, Union

from ensembl_genes.models import GeneForMHC

Expand All @@ -10,15 +10,18 @@ class Species:
common_name: str
reference_genome: str
ensembl_gene_pattern: str
enable_mhc: bool
mhc_chromosome: str
mhc_lower: int
mhc_upper: int
xmhc_lower: int
xmhc_upper: int
chromosomes: list[str]

def get_mhc_category(self, gene: GeneForMHC) -> str:
def get_mhc_category(self, gene: GeneForMHC) -> Optional[str]:
"""Assign MHC status of MHC, xMHC, or no to an ensembl gene record."""
if not self.enable_mhc:
return None
import pandas as pd

chromosome: str = gene.chromosome
Expand Down Expand Up @@ -48,17 +51,38 @@ def get_mhc_category(self, gene: GeneForMHC) -> str:
ensembl_gene_pattern=r"^ENSG[0-9]{11}$",
# Refs MHC boundary discussion internal Related Sciences issue 127.
# https://bioinformatics.stackexchange.com/a/14719/9750
enable_mhc=True,
mhc_chromosome="6",
mhc_lower=28_510_120,
mhc_upper=33_480_577,
xmhc_lower=25_726_063,
xmhc_upper=33_410_226,
# Chromosome names applied to genes on the primary assembly rather than alternative sequences.
# Refs internal Related Sciences issue 241.
chromosomes=[*map(str, range(1, 23)), "X", "Y", "MT"],
chromosomes=[*map(str, range(1, 22 + 1)), "X", "Y", "MT"],
)
rat = Species(
name="rattus_norvegicus",
common_name="rat",
# Rnor_6.0
reference_genome="6",
# https://github.com/related-sciences/ensembl-genes/issues/4#issuecomment-941556912
ensembl_gene_pattern=r"^ENSRNOG[0-9]{11}$",
# FIXME: mhc coordinates
# https://github.com/related-sciences/ensembl-genes/pull/6#discussion_r729259953
enable_mhc=False,
mhc_chromosome="20",
mhc_lower=28_510_120,
mhc_upper=33_480_577,
xmhc_lower=25_726_063,
xmhc_upper=33_410_226,
# Chromosome names applied to genes on the primary assembly rather than alternative sequences.
# Refs internal Related Sciences issue 241.
chromosomes=[*map(str, range(1, 20 + 1)), "X", "Y", "MT"],
)


all_species = [human]
all_species = [human, rat]


def get_species(species: Union[str, Species]) -> Species:
Expand Down
8 changes: 7 additions & 1 deletion tests/species_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from ensembl_genes.models import GeneForMHC as Gene
from ensembl_genes.species import get_species, human
from ensembl_genes.species import get_species, human, rat


def test_get_species() -> None:
Expand Down Expand Up @@ -31,3 +31,9 @@ def test_get_species() -> None:
)
def test_get_mhc_category_human(gene: Gene, category: str) -> None:
assert human.get_mhc_category(gene) == category


def test_get_mhc_category_rat() -> None:
gene = Gene("20", 0, 0)
assert rat.enable_mhc is False
assert rat.get_mhc_category(gene) is None