diff --git a/app/models/Backend.scala b/app/models/Backend.scala index 9c064247..2dbf33d4 100644 --- a/app/models/Backend.scala +++ b/app/models/Backend.scala @@ -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") diff --git a/app/models/entities/CredibleSet.scala b/app/models/entities/CredibleSet.scala index df9a5dfc..e23d1e68 100644 --- a/app/models/entities/CredibleSet.scala +++ b/app/models/entities/CredibleSet.scala @@ -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.{ @@ -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), diff --git a/app/models/entities/L2GPredictions.scala b/app/models/entities/L2GPredictions.scala new file mode 100644 index 00000000..a7fb134e --- /dev/null +++ b/app/models/entities/L2GPredictions.scala @@ -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 l2GPredictionsF: OFormat[L2GPredictions] = Json.format[L2GPredictions] +} diff --git a/app/models/gql/Objects.scala b/app/models/gql/Objects.scala index da8a6e4a..6cd66991 100644 --- a/app/models/gql/Objects.scala +++ b/app/models/gql/Objects.scala @@ -1325,6 +1325,18 @@ 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]( + ReplaceField( + "geneId", + Field( + "target", + OptionType(targetImp), + Some("Target"), + resolve = r => targetsFetcher.deferOpt(r.value.geneId) + ) + ) + ) implicit val colocalisationImp: ObjectType[Backend, Colocalisation] = deriveObjectType[Backend, Colocalisation]( ReplaceField(