Skip to content

Commit

Permalink
feat: add subsampling of phenotype values
Browse files Browse the repository at this point in the history
  • Loading branch information
zietzm committed Aug 28, 2024
1 parent 1745f23 commit 6ba339a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/webgwas_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def validate_phenotype(
def get_phenotype_summary(
cohort: Annotated[Cohort, Depends(validate_cohort)],
phenotype_definition: Annotated[ValidPhenotype, Depends(validate_phenotype)],
n_samples: int = 1000,
) -> PhenotypeSummary:
return get_phenotype_summary_impl(cohort, phenotype_definition)
return get_phenotype_summary_impl(cohort, phenotype_definition).subsample(n_samples)


@app.post(
Expand Down
16 changes: 16 additions & 0 deletions src/webgwas_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,19 @@ class PhenotypeSummary(SQLModel):
),
)
rsquared: float = Field(..., description="R-squared of the phenotype definition")

def subsample(self, n_samples: int) -> "PhenotypeSummary":
phenotypes = [
ApproximatePhenotypeValues(
t=p.t,
a=p.a,
n=p.n,
)
for p in self.phenotypes[:n_samples]
]
return PhenotypeSummary(
phenotype_definition=self.phenotype_definition,
cohort_name=self.cohort_name,
phenotypes=phenotypes,
rsquared=self.rsquared,
)

0 comments on commit 6ba339a

Please sign in to comment.