-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcf_dimensions.py
More file actions
101 lines (72 loc) · 3.6 KB
/
Copy pathvcf_dimensions.py
File metadata and controls
101 lines (72 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
VCF dimensions (= technical metadata) DB Model.
"""
from typing import TYPE_CHECKING
from sqlalchemy import BigInteger, ForeignKey, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from divbase_api.models.base import BaseDBModel
if TYPE_CHECKING:
from divbase_api.models.projects import ProjectDB
class VCFMetadataDB(BaseDBModel):
"""
DB model for the technical metadata ("dimensions") for the VCF files in the S3 buckets.
One entry per VCF file. This table is updated by workers and read by the API.
id (primary key), created_at and updated_at are inherited from BaseDBModel.
To allow multiple projects to have VCF files with the same S3 key (filename),
this model uses a UniqueConstraint (vcf_file_s3_key, project_id).
"""
__tablename__ = "vcf_metadata"
vcf_file_s3_key: Mapped[str] = mapped_column(String, index=True)
project_id: Mapped[int] = mapped_column(
ForeignKey("project.id", ondelete="CASCADE"),
index=True,
)
s3_version_id: Mapped[str] = mapped_column(String, nullable=False, index=True)
file_size_bytes: Mapped[int] = mapped_column(BigInteger)
variant_count: Mapped[int] = mapped_column(BigInteger)
sample_count: Mapped[int] = mapped_column(Integer)
__table_args__ = (UniqueConstraint("vcf_file_s3_key", "project_id", name="unique_vcf_per_project"),)
project: Mapped["ProjectDB"] = relationship("ProjectDB", back_populates="vcf_metadata")
samples: Mapped[list["VCFMetadataSamplesDB"]] = relationship(
"VCFMetadataSamplesDB", back_populates="vcf_metadata", cascade="all, delete-orphan"
)
scaffolds: Mapped[list["VCFMetadataScaffoldsDB"]] = relationship(
"VCFMetadataScaffoldsDB", back_populates="vcf_metadata", cascade="all, delete-orphan"
)
class SkippedVCFDB(BaseDBModel):
"""
DB model to track DivBase-generated result VCFs.
These should ignored by queries since they contain duplicated data compared to the source VCFs.
"""
__tablename__ = "skipped_vcf_files"
vcf_file_s3_key: Mapped[str] = mapped_column(String, index=True)
project_id: Mapped[int] = mapped_column(
ForeignKey("project.id", ondelete="CASCADE"),
index=True,
)
s3_version_id: Mapped[str] = mapped_column(String, nullable=False, index=True)
skip_reason: Mapped[str | None] = mapped_column(String, nullable=True)
__table_args__ = (UniqueConstraint("vcf_file_s3_key", "project_id", name="unique_skipped_vcf_per_project"),)
project: Mapped["ProjectDB"] = relationship("ProjectDB", back_populates="skipped_vcf_files")
class VCFMetadataSamplesDB(BaseDBModel):
"""
DB model for one-to-many relationship between VCF file metadata and the sample names in the VCF files.
"""
__tablename__ = "vcf_metadata_samples"
vcf_metadata_id: Mapped[int] = mapped_column(
ForeignKey("vcf_metadata.id", ondelete="CASCADE"),
index=True,
)
sample_name: Mapped[str] = mapped_column(String, index=True)
vcf_metadata: Mapped["VCFMetadataDB"] = relationship("VCFMetadataDB", back_populates="samples")
class VCFMetadataScaffoldsDB(BaseDBModel):
"""
DB model for one-to-many relationship between VCF file metadata and the scaffold names in the VCF files.
"""
__tablename__ = "vcf_metadata_scaffolds"
vcf_metadata_id: Mapped[int] = mapped_column(
ForeignKey("vcf_metadata.id", ondelete="CASCADE"),
index=True,
)
scaffold_name: Mapped[str] = mapped_column(String, index=True)
vcf_metadata: Mapped["VCFMetadataDB"] = relationship("VCFMetadataDB", back_populates="scaffolds")