Skip to content

Commit 475b136

Browse files
authored
Merge pull request #500 from VariantEffect/modify/estelle/495/renameTaxIdToCode
Rename tax_id to code in Taxonomy
2 parents 9f0e5d7 + 566e613 commit 475b136

File tree

9 files changed

+57
-28
lines changed

9 files changed

+57
-28
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""rename_tax_id_to_code
2+
3+
Revision ID: 019eb75ad9ae
4+
Revises: b29bbfb2a13a
5+
Create Date: 2025-08-20 16:21:15.872816
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '019eb75ad9ae'
14+
down_revision = 'a8e345cca190'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.alter_column('taxonomies', 'tax_id', new_column_name='code', existing_type=sa.Integer(), existing_nullable=False)
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade():
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.alter_column('taxonomies', 'code', new_column_name='tax_id', existing_type=sa.Integer(), existing_nullable=False)
28+
# ### end Alembic commands ###

src/mavedb/lib/score_sets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def search_score_sets(db: Session, owner_or_contributor: Optional[User], search:
114114
ScoreSet.target_genes.any(
115115
TargetGene.target_accession.has(func.lower(TargetAccession.assembly).icontains(lower_search_text))
116116
),
117-
# TODO(#94): add LICENSE, plus TAX_ID if numeric
117+
# TODO(#94): add LICENSE, plus TAXONOMY CODE if numeric
118118
ScoreSet.publication_identifiers.any(
119119
func.lower(PublicationIdentifier.identifier).icontains(lower_search_text)
120120
),

src/mavedb/lib/taxonomies.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
async def find_or_create_taxonomy(db: Session, taxonomy: TaxonomyCreate):
1212
"""
13-
Find an existing taxonomy ID record with the specified tax_id int, or create a new one.
13+
Find an existing taxonomy ID record with the specified code, or create a new one.
1414
1515
:param db: An active database session
1616
:param taxonomy: A TaxonomyCreate object containing the taxonomy details to search for or create.
1717
:return: An existing Taxonomy containing the specified taxonomy ID, or a new, unsaved Taxonomy
18-
tax_id: A valid taxonomy ID from NCBI
18+
code: A valid taxonomy ID from NCBI
1919
"""
20-
taxonomy_record = db.query(Taxonomy).filter(Taxonomy.tax_id == taxonomy.tax_id).one_or_none()
20+
taxonomy_record = db.query(Taxonomy).filter(Taxonomy.code == taxonomy.code).one_or_none()
2121
if not taxonomy_record:
22-
taxonomy_record = await search_NCBI_taxonomy(db, str(taxonomy.tax_id))
22+
taxonomy_record = await search_NCBI_taxonomy(db, str(taxonomy.code))
2323
return taxonomy_record
2424

2525

@@ -51,14 +51,14 @@ async def search_NCBI_taxonomy(db: Session, search: str) -> Any:
5151
ncbi_taxonomy.setdefault("rank", "NULL")
5252
ncbi_taxonomy.setdefault("has_described_species_name", False)
5353
taxonomy_record = Taxonomy(
54-
tax_id=ncbi_taxonomy["tax_id"],
54+
code=ncbi_taxonomy["code"],
5555
organism_name=ncbi_taxonomy["organism_name"],
5656
common_name=ncbi_taxonomy["common_name"],
5757
rank=ncbi_taxonomy["rank"],
5858
has_described_species_name=ncbi_taxonomy["has_described_species_name"],
5959
url="https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=info&id="
60-
+ str(ncbi_taxonomy["tax_id"]),
61-
article_reference="NCBI:txid" + str(ncbi_taxonomy["tax_id"]),
60+
+ str(ncbi_taxonomy["code"]),
61+
article_reference="NCBI:txid" + str(ncbi_taxonomy["code"]),
6262
)
6363
db.add(taxonomy_record)
6464
db.commit()

src/mavedb/models/taxonomy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Taxonomy(Base):
1212
__tablename__ = "taxonomies"
1313

1414
id = Column(Integer, primary_key=True)
15-
tax_id = Column(Integer, nullable=False)
15+
code = Column(Integer, nullable=False)
1616
organism_name = Column(String, nullable=True)
1717
common_name = Column(String, nullable=True)
1818
rank = Column(String, nullable=True)

src/mavedb/routers/score_sets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ async def create_score_set(
820820
"MaveDB does not support score-sets with both sequence and accession based targets. Please re-submit this scoreset using only one type of target."
821821
)
822822
upload_taxonomy = gene.target_sequence.taxonomy
823-
save_to_logging_context({"requested_taxonomy": gene.target_sequence.taxonomy.tax_id})
823+
save_to_logging_context({"requested_taxonomy": gene.target_sequence.taxonomy.code})
824824
taxonomy = await find_or_create_taxonomy(db, upload_taxonomy)
825825

826826
if not taxonomy:
@@ -1155,7 +1155,7 @@ async def update_score_set(
11551155
)
11561156

11571157
upload_taxonomy = gene.target_sequence.taxonomy
1158-
save_to_logging_context({"requested_taxonomy": gene.target_sequence.taxonomy.tax_id})
1158+
save_to_logging_context({"requested_taxonomy": gene.target_sequence.taxonomy.code})
11591159
taxonomy = await find_or_create_taxonomy(db, upload_taxonomy)
11601160

11611161
if not taxonomy:
@@ -1165,7 +1165,7 @@ async def update_score_set(
11651165
)
11661166
raise HTTPException(
11671167
status_code=status.HTTP_400_BAD_REQUEST,
1168-
detail=f"Unknown taxonomy {gene.target_sequence.taxonomy.tax_id}",
1168+
detail=f"Unknown taxonomy {gene.target_sequence.taxonomy.code}",
11691169
)
11701170

11711171
# If the target sequence has a label, use it. Otherwise, use the name from the target gene as the label.

src/mavedb/routers/taxonomies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ def fetch_taxonomy(
6868
return item
6969

7070

71-
@router.get("/tax-id/{item_id}", status_code=200, response_model=taxonomy.Taxonomy, responses={404: {}})
72-
def fetch_taxonomy_by_tax_id(
71+
@router.get("/code/{item_id}", status_code=200, response_model=taxonomy.Taxonomy, responses={404: {}})
72+
def fetch_taxonomy_by_code(
7373
*,
7474
item_id: int,
7575
db: Session = Depends(deps.get_db),
7676
) -> Any:
7777
"""
78-
Fetch a single taxonomy by tax_id.
78+
Fetch a single taxonomy by code.
7979
"""
80-
item = db.query(Taxonomy).filter(Taxonomy.tax_id == item_id).first()
80+
item = db.query(Taxonomy).filter(Taxonomy.code == item_id).first()
8181
if not item:
82-
raise HTTPException(status_code=404, detail=f"Taxonomy with tax_ID {item_id} not found")
82+
raise HTTPException(status_code=404, detail=f"Taxonomy with code {item_id} not found")
8383
return item
8484

8585

@@ -101,7 +101,7 @@ async def search_taxonomies(search: TextSearch, db: Session = Depends(deps.get_d
101101
)
102102
)
103103
else:
104-
query = query.filter(Taxonomy.tax_id == int(search.text))
104+
query = query.filter(Taxonomy.code == int(search.text))
105105
items = query.order_by(Taxonomy.organism_name).all()
106106

107107
if not items and search.text:

src/mavedb/view_models/taxonomy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class TaxonomyBase(BaseModel):
9-
tax_id: int
9+
code: int
1010
organism_name: Optional[str] = None
1111
common_name: Optional[str] = None
1212
rank: Optional[str] = None

tests/helpers/constants.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,9 @@
598598
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
599599
}
600600

601+
601602
TEST_MINIMAL_TAXONOMY = {
602-
"tax_id": 9606,
603+
"code": 9606,
603604
}
604605

605606
TEST_POPULATED_TAXONOMY = {
@@ -692,7 +693,7 @@
692693
"sequence_type": "dna",
693694
"sequence": "ACGTTT",
694695
"taxonomy": {
695-
"tax_id": TEST_SAVED_TAXONOMY["tax_id"],
696+
"code": TEST_SAVED_TAXONOMY["code"],
696697
"organism_name": TEST_SAVED_TAXONOMY["organism_name"],
697698
"common_name": TEST_SAVED_TAXONOMY["common_name"],
698699
"rank": TEST_SAVED_TAXONOMY["rank"],
@@ -719,7 +720,7 @@
719720
"sequenceType": "dna",
720721
"sequence": "ACGTTT",
721722
"taxonomy": {
722-
"taxId": TEST_SAVED_TAXONOMY["tax_id"],
723+
"code": TEST_SAVED_TAXONOMY["code"],
723724
"organismName": TEST_SAVED_TAXONOMY["organism_name"],
724725
"commonName": TEST_SAVED_TAXONOMY["common_name"],
725726
"rank": TEST_SAVED_TAXONOMY["rank"],
@@ -772,7 +773,7 @@
772773
"label": "TEST1",
773774
"taxonomy": {
774775
"recordType": "Taxonomy",
775-
"taxId": TEST_SAVED_TAXONOMY["tax_id"],
776+
"code": TEST_SAVED_TAXONOMY["code"],
776777
"organismName": TEST_SAVED_TAXONOMY["organism_name"],
777778
"commonName": TEST_SAVED_TAXONOMY["common_name"],
778779
"rank": TEST_SAVED_TAXONOMY["rank"],
@@ -930,7 +931,7 @@
930931
"sequence": "ACGTTT",
931932
"label": "TEST3",
932933
"taxonomy": {
933-
"taxId": TEST_SAVED_TAXONOMY["tax_id"],
934+
"code": TEST_SAVED_TAXONOMY["code"],
934935
"organismName": TEST_SAVED_TAXONOMY["organism_name"],
935936
"commonName": TEST_SAVED_TAXONOMY["common_name"],
936937
"rank": TEST_SAVED_TAXONOMY["rank"],
@@ -950,7 +951,7 @@
950951
"sequence": "TAATGCC",
951952
"label": "TEST4",
952953
"taxonomy": {
953-
"taxId": TEST_SAVED_TAXONOMY["tax_id"],
954+
"code": TEST_SAVED_TAXONOMY["code"],
954955
"organismName": TEST_SAVED_TAXONOMY["organism_name"],
955956
"commonName": TEST_SAVED_TAXONOMY["common_name"],
956957
"rank": TEST_SAVED_TAXONOMY["rank"],
@@ -1003,7 +1004,7 @@
10031004
"label": "TEST3",
10041005
"taxonomy": {
10051006
"recordType": "Taxonomy",
1006-
"taxId": TEST_SAVED_TAXONOMY["tax_id"],
1007+
"code": TEST_SAVED_TAXONOMY["code"],
10071008
"organismName": TEST_SAVED_TAXONOMY["organism_name"],
10081009
"commonName": TEST_SAVED_TAXONOMY["common_name"],
10091010
"rank": TEST_SAVED_TAXONOMY["rank"],
@@ -1027,7 +1028,7 @@
10271028
"label": "TEST4",
10281029
"taxonomy": {
10291030
"recordType": "Taxonomy",
1030-
"taxId": TEST_SAVED_TAXONOMY["tax_id"],
1031+
"code": TEST_SAVED_TAXONOMY["code"],
10311032
"organismName": TEST_SAVED_TAXONOMY["organism_name"],
10321033
"commonName": TEST_SAVED_TAXONOMY["common_name"],
10331034
"rank": TEST_SAVED_TAXONOMY["rank"],

tests/view_models/test_wild_type_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
taxonomy = TaxonomyCreate(
99
id=1,
10-
tax_id=1,
10+
code=1,
1111
organism_name="Organism",
1212
common_name="Common name",
1313
rank="Rank",

0 commit comments

Comments
 (0)