Skip to content

Commit

Permalink
add biosample to the gwas api
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Sep 25, 2024
1 parent cb96bc3 commit 0f776bd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
17 changes: 17 additions & 0 deletions app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import models.Helpers._
import models.db.{QAOTF, QLITAGG, QW2V, SentenceQuery}
import models.entities.Publication._
import models.entities.Associations._
import models.entities.Biosample._
import models.entities.Configuration._
import models.entities.DiseaseHPOs._
import models.entities.Drug._
Expand Down Expand Up @@ -142,6 +143,22 @@ class Backend @Inject() (implicit
esRetriever.getByIds(indexName, ids, fromJsValue[VariantIndex])
}

def getBiosample(id: String): Future[Option[Biosample]] = {
val indexName = getIndexOrDefault("biosample", Some("biosample"))
esRetriever
.getByIndexedTermsMust(
indexName,
Map("biosampleId.keyword" -> Seq(id)),
Pagination.mkDefault,
fromJsValue[Biosample]
)
.map {
case (Seq(), _) => None
case (hits, aggs) =>
Some(hits.head)
}
}

def getStudies(queryArgs: StudyQueryArgs,
pagination: Option[Pagination]
): Future[IndexedSeq[JsValue]] = {
Expand Down
20 changes: 20 additions & 0 deletions app/models/entities/Biosample.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package models.entities

import play.api.Logging
import play.api.libs.json._

case class Biosample(
biosampleId: String,
biosampleName: String,
description: Option[String],
xrefs: Option[Seq[String]],
synonyms: Option[Seq[String]],
parents: Option[Seq[String]],
ancestors: Option[Seq[String]],
children: Option[Seq[String]],
descendants: Option[Seq[String]]
)

object Biosample extends Logging {
implicit val biosampleF: OFormat[Biosample] = Json.format[Biosample]
}
14 changes: 9 additions & 5 deletions app/models/entities/GwasIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import models.gql.Fetchers.{diseasesFetcher, targetsFetcher}
import play.api.Logging
import play.api.libs.json.{JsValue, Json, OFormat}
import models.entities.CredibleSet.credibleSetImp
import models.gql.Objects.{diseaseImp, targetImp}
import models.gql.Objects.{diseaseImp, targetImp, biosampleImp}
import sangria.schema.{
BooleanType,
Field,
Expand Down Expand Up @@ -76,10 +76,14 @@ object GwasIndex extends Logging {
}
),
Field(
"biosampleFromSourceId",
OptionType(StringType),
description = Some(""),
resolve = js => (js.value \ "biosampleFromSourceId").asOpt[String]
"biosample",
OptionType(biosampleImp),
Some("Biosample"),
resolve = js => {
val biosampleId = (js.value \ "biosampleFromSourceId").asOpt[String].getOrElse("")
logger.info(s"Finding biosample: $biosampleId")
js.ctx.getBiosample(biosampleId)
}
),
Field(
"nSamples",
Expand Down
1 change: 1 addition & 0 deletions app/models/gql/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ object Objects extends Logging {
)
implicit val alleleFrequencyImp: ObjectType[Backend, AlleleFrequency] =
deriveObjectType[Backend, AlleleFrequency]()
implicit val biosampleImp: ObjectType[Backend, Biosample] = deriveObjectType[Backend, Biosample]()
implicit val colocalisationImp: ObjectType[Backend, Colocalisation] =
deriveObjectType[Backend, Colocalisation](
ReplaceField(
Expand Down

0 comments on commit 0f776bd

Please sign in to comment.