Skip to content

Commit eaeb9cf

Browse files
committed
other models and db setup
1 parent 516b3f1 commit eaeb9cf

23 files changed

+287
-18
lines changed

db/__init__.py

Whitespace-only changes.

db/models.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Float
2+
from sqlalchemy.ext.declarative import declarative_base
3+
from sqlalchemy.orm import relationship
4+
from sqlalchemy.sql import func
5+
6+
Base = declarative_base()
7+
8+
class BioSample(Base):
9+
__tablename__ = 'biosample'
10+
id = Column(Integer, primary_key=True, index=True)
11+
name = Column(String)
12+
time_created = Column(DateTime(timezone=True), server_default=func.now())
13+
time_updated = Column(DateTime(timezone=True), onupdate=func.now())
14+
biosample_id = Column(Integer, ForeignKey('biosample.id'))
15+
16+
biosample = relationship('BioSample')
17+
18+
19+
class Participant(Base):
20+
__tablename__ = 'participant'
21+
id = Column(Integer, primary_key=True)
22+
name = Column(String)
23+
age = Column(Integer)
24+
time_created = Column(DateTime(timezone=True), server_default=func.now())
25+
time_updated = Column(DateTime(timezone=True), onupdate=func.now())

db/participant.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
id: https://bican.org/examples/participant
2+
name: participant
3+
prefixes:
4+
linkml: https://w3id.org/linkml/
5+
imports:
6+
- linkml:types
7+
default_range: string
8+
9+
classes:
10+
Participant:
11+
attributes:
12+
identifier:
13+
altName:
14+
strain:
15+
cellLine:
16+
vendor:
17+
age:
18+
sex:
19+
genotype:
20+
species:
21+
disorder:
22+
relatedParticipant:
23+
sameAs:

db/schema.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# build a schema using pydantic
2+
from pydantic import BaseModel
3+
4+
class BioSample(BaseModel):
5+
name: str
6+
biosample_id: int
7+
8+
class Config:
9+
orm_mode = True
10+
11+
class Participant(BaseModel):
12+
name:str
13+
age:int
14+
15+
class Config:
16+
orm_mode = True

main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
# from internal import admin
55
from routers import biosamples, participants
66

7+
import uvicorn
8+
from fastapi_sqlalchemy import DBSessionMiddleware, db
9+
import os
10+
from dotenv import load_dotenv
11+
12+
load_dotenv('.env')
13+
714
app = FastAPI(dependencies=[Depends(get_query_token)])
815

916

@@ -17,7 +24,14 @@
1724
# responses={418: {"description": "I'm a teapot"}},
1825
# )
1926

27+
# to avoid csrftokenError
28+
app.add_middleware(DBSessionMiddleware, db_url=os.environ['DATABASE_URL'])
2029

2130
@app.get("/")
2231
async def root():
2332
return {"message": "Knowledge Graph API"}
33+
34+
35+
# To run locally
36+
if __name__ == '__main__':
37+
uvicorn.run(app, host='0.0.0.0', port=8000)

models/__init__.py

Whitespace-only changes.

models/annotations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pydantic import BaseModel
2+
3+
4+
class Annotations(BaseModel):
5+
name: str

models/assay.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pydantic import BaseModel
2+
3+
4+
class Assay(BaseModel):
5+
name: str

models/atlas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pydantic import BaseModel
2+
3+
4+
class Atlas(BaseModel):
5+
type: Spatial, Dimensional

models/biosample.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from dandischema import DandiBaseModel
2+
3+
4+
class BioSample(DandiBaseModel):
5+
"""Description of the sample that was studied"""
6+
7+
identifier: Identifier = Field(nskey="schema")
8+
sampleType: SampleType = Field(
9+
description="Identifier for the sample characteristics (e.g., from OBI, Encode).",
10+
nskey="dandi",
11+
)
12+
assayType: Optional[List[AssayType]] = Field(
13+
None, description="Identifier for the assay(s) used (e.g., OBI).", nskey="dandi"
14+
)
15+
anatomy: Optional[List[Anatomy]] = Field(
16+
None,
17+
description="Identifier for what organ the sample belongs "
18+
"to. Use the most specific descriptor from sources such as UBERON.",
19+
nskey="dandi",
20+
)
21+
22+
wasDerivedFrom: Optional[List["BioSample"]] = Field(
23+
None,
24+
description="Describes the hierarchy of sample derivation or aggregation.",
25+
nskey="prov",
26+
)
27+
wasAttributedTo: Optional[List[Participant]] = Field(
28+
None,
29+
description="Participant(s) or Subject(s) associated with this sample.",
30+
nskey="prov",
31+
)
32+
sameAs: Optional[List[Identifier]] = Field(None, nskey="schema")
33+
hasMember: Optional[List[Identifier]] = Field(None, nskey="prov")
34+
35+
_ldmeta = {
36+
"rdfs:subClassOf": ["schema:Thing", "prov:Entity"],
37+
"rdfs:label": "Information about the biosample.",
38+
"nskey": "dandi",
39+
}

0 commit comments

Comments
 (0)