Skip to content

Commit

Permalink
add l2g predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Oct 22, 2024
1 parent 3e9bba2 commit 282ac1d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ class Backend @Inject() (implicit
esRetriever.getByIds(targetIndexName, ids, fromJsValue[GeneOntologyTerm])
}

def getL2GPredictions(id: String,
pagination: Option[Pagination]
): Future[IndexedSeq[L2GPredictions]] = {
val indexName = getIndexOrDefault("l2g_predictions")
val pag = pagination.getOrElse(Pagination.mkDefault)

esRetriever
.getByIndexedTermsMust(indexName,
Map("studyLocusId.keyword" -> Seq(id)),
pag,
fromJsValue[L2GPredictions],
sortByField = ElasticRetriever.sortBy("score", SortOrder.Desc)
)
.map(_._1)
}

def getVariants(ids: Seq[String]): Future[IndexedSeq[VariantIndex]] = {
val indexName = getIndexOrDefault("variant_index")

Expand Down
12 changes: 11 additions & 1 deletion app/models/entities/CredibleSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import models.gql.StudyTypeEnum
import models.gql.Arguments.StudyType
import models.entities.GwasIndex.{gwasImp, gwasWithoutCredSetsImp}
import models.gql.Fetchers.{gwasFetcher, targetsFetcher, variantFetcher}
import models.gql.Objects.{logger, targetImp, variantIndexImp, colocalisationImp}
import models.gql.Objects.{logger, targetImp, variantIndexImp, colocalisationImp, l2gPredictionsImp}
import play.api.Logging
import play.api.libs.json.{JsValue, Json, OFormat, OWrites}
import sangria.schema.{
Expand Down Expand Up @@ -132,6 +132,16 @@ object CredibleSet extends Logging {
variantFetcher.deferOpt(id)
}
),
Field(
"l2Gpredictions",
OptionType(ListType(l2gPredictionsImp)),
description = None,
arguments = pageArg :: Nil,
resolve = js => {
val id = (js.value \ "studyLocusId").as[String]
js.ctx.getL2GPredictions(id, js.arg(pageArg))
}
),
Field(
"chromosome",
OptionType(StringType),
Expand Down
14 changes: 14 additions & 0 deletions app/models/entities/L2GPredictions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package models.entities

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

case class L2GPredictions(
studyLocusId: String,
geneId: String,
score: Double
)

object L2GPredictions extends Logging {
implicit val colocalisationF: OFormat[L2GPredictions] = Json.format[L2GPredictions]
}
2 changes: 2 additions & 0 deletions app/models/gql/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,8 @@ object Objects extends Logging {
implicit val alleleFrequencyImp: ObjectType[Backend, AlleleFrequency] =
deriveObjectType[Backend, AlleleFrequency]()
implicit val biosampleImp: ObjectType[Backend, Biosample] = deriveObjectType[Backend, Biosample]()
implicit val l2gPredictionsImp: ObjectType[Backend, L2GPredictions] =
deriveObjectType[Backend, L2GPredictions]()
implicit val colocalisationImp: ObjectType[Backend, Colocalisation] =
deriveObjectType[Backend, Colocalisation](
ReplaceField(
Expand Down

0 comments on commit 282ac1d

Please sign in to comment.