Skip to content

Commit

Permalink
updates to DB schema
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-combe committed Aug 15, 2024
1 parent dbdf5fb commit be492b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion models/dbsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class DBSequence(Base):
__tablename__ = "dbsequence"
id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
upload_id: Mapped[str] = mapped_column(Integer, ForeignKey("upload.id"), primary_key=True, nullable=False)
id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
accession: Mapped[str] = mapped_column(Text, nullable=False)
name: Mapped[str] = mapped_column(Text, nullable=True)
description: Mapped[str] = mapped_column(Text, nullable=True)
Expand Down
12 changes: 7 additions & 5 deletions models/match.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import ForeignKey, Text, FLOAT, JSON, BOOLEAN, Integer, ForeignKeyConstraint, CHAR
from sqlalchemy import ForeignKey, Text, FLOAT, JSON, BOOLEAN, Integer, ForeignKeyConstraint, CHAR, Index
from models.base import Base
from typing import Optional, Any

Expand All @@ -9,6 +9,7 @@ class Match(Base):
id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
upload_id: Mapped[int] = mapped_column(Integer, ForeignKey("upload.id"), index=True, primary_key=True,
nullable=False)
id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
spectrum_id: Mapped[str] = mapped_column(Text, nullable=True)
spectra_data_id: Mapped[int] = mapped_column(Integer, nullable=True) # nullable for csv data
multiple_spectra_identification_id: Mapped[str] = mapped_column(Integer, nullable=True)
Expand All @@ -29,16 +30,17 @@ class Match(Base):
"spectrumidentificationprotocol.upload_id"],
),
ForeignKeyConstraint(
["pep1_id", "upload_id"],
["modifiedpeptide.id", "modifiedpeptide.upload_id"],
[ "upload_id", "pep1_id",],
["modifiedpeptide.upload_id", "modifiedpeptide.id"],
),
ForeignKeyConstraint(
["pep2_id", "upload_id"],
["modifiedpeptide.id", "modifiedpeptide.upload_id"],
["upload_id", "pep2_id"],
["modifiedpeptide.upload_id", "modifiedpeptide.id", ],
),
# ForeignKeyConstraint(
# ["spectrum_id", "spectra_data_id", "upload_id"],
# ["spectrum.id", "spectrum.spectra_data_id", "spectrum.upload_id"],
# ),
Index("ix_match_id", "id"),
)

12 changes: 10 additions & 2 deletions models/modifiedpeptide.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import ForeignKey, Text, Integer, JSON, FLOAT
from sqlalchemy import ForeignKey, Text, Integer, JSON, FLOAT, Index
from models.base import Base
from typing import Optional, Any


class ModifiedPeptide(Base):
__tablename__ = "modifiedpeptide"
id: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False)
upload_id: Mapped[str] = mapped_column(Integer, ForeignKey("upload.id"), index=True, primary_key=True,
nullable=False)
id: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False)
base_sequence: Mapped[str] = mapped_column(Text, nullable=False)
mod_accessions: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False)
mod_avg_mass_deltas: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
Expand All @@ -21,3 +21,11 @@ class ModifiedPeptide(Base):
crosslinker_modmass: Mapped[float] = mapped_column(FLOAT, nullable=True)
crosslinker_pair_id: Mapped[str] = mapped_column(Text, nullable=True) # yes, it's a string
crosslinker_accession: Mapped[str] = mapped_column(Text, nullable=True)
# CREATE INDEX ix_modifiedpeptide_id ON public.modifiedpeptide USING btree (id);
# CREATE INDEX modifiedpeptide_upload_id__id_seq_idx ON public.modifiedpeptide (upload_id,id, base_sequence);
# CREATE INDEX modifiedpeptide_upload_id_linksite_idx ON public.modifiedpeptide (upload_id, link_site1);
__table_args__ = (
Index("ix_modifiedpeptide_id", "id"),
Index("modifiedpeptide_upload_id__id_seq_idx", "upload_id", "id", "base_sequence"),
Index("modifiedpeptide_upload_id_linksite_idx", "upload_id", "link_site1"),
)
8 changes: 4 additions & 4 deletions models/peptideevidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class PeptideEvidence(Base):
is_decoy: Mapped[bool] = mapped_column(BOOLEAN, nullable=True)
__table_args__ = (
ForeignKeyConstraint(
("dbsequence_id", "upload_id"),
("dbsequence.id", "dbsequence.upload_id"),
("upload_id", "dbsequence_id"),
("dbsequence.upload_id", "dbsequence.id"),
),
ForeignKeyConstraint(
("peptide_id", "upload_id"),
("modifiedpeptide.id", "modifiedpeptide.upload_id"),
("upload_id", "peptide_id"),
("modifiedpeptide.upload_id", "modifiedpeptide.id"),
),
# add index on upload_id, peptide_id
Index("peptideevidence_upload_id_peptide_id_idx", "upload_id", "peptide_id"),
Expand Down

0 comments on commit be492b5

Please sign in to comment.