Skip to content

Commit

Permalink
relation fetcher for l2g, pagingation max size for variant
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Oct 25, 2024
1 parent f7b0ef3 commit 66e2d64
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ch_tunnel: ## Create tunnel connection to Clickhouse eg. make ch_tunnel zone eur
@gcloud compute ssh ${instance} --zone="${zone}" --tunnel-through-iap -- -L 8123:localhost:8123

run_with_standalone: ## Runs API with standalone platform
@sbt "run 8090" -DELASTICSEARCH_HOST=elasticsearch -DSLICK_CLICKHOUSE_URL=jdbc:clickhouse://clickhouse:8123 -DPLATFORM_API_IGNORE_CACHE=true
@sbt "run 8090" -J-Xms2g -J-Xmx7g -DELASTICSEARCH_HOST=elasticsearch -DSLICK_CLICKHOUSE_URL=jdbc:clickhouse://clickhouse:8123 -DPLATFORM_API_IGNORE_CACHE=true

debug_with_standalone: ## Runs API with standalone platform
@sbt -jvm-debug 9999 run 8090 -DSLICK_CLICKHOUSE_URL=jdbc:clickhouse://clickhouse:8123 -DPLATFORM_API_IGNORE_CACHE=true
Expand Down
6 changes: 4 additions & 2 deletions app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ class Backend @Inject() (implicit

def getVariants(ids: Seq[String]): Future[IndexedSeq[VariantIndex]] = {
val indexName = getIndexOrDefault("variant_index")
esRetriever
val pag = Pagination(Pagination.indexDefault, Pagination.sizeMax)
val r = esRetriever
.getByIndexedTermsMust(indexName,
Map("variantId.keyword" -> ids),
Pagination.mkDefault,
pag,
fromJsValue[VariantIndex]
)
.map(_._1)
r
}

def getBiosamples(ids: Seq[String]): Future[IndexedSeq[Biosample]] = {
Expand Down
2 changes: 1 addition & 1 deletion app/models/entities/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._

object Configuration {
val batchSize = 100
val batchSize = 5000

case class Logging(otHeader: String, ignoredQueries: Seq[String])

Expand Down
14 changes: 7 additions & 7 deletions app/models/entities/CredibleSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import models.Backend
import models.gql.StudyTypeEnum
import models.gql.Arguments.StudyType
import models.entities.GwasIndex.{gwasImp, gwasWithoutCredSetsImp}
import models.gql.Fetchers.{gwasFetcher, l2gFetcher, targetsFetcher, variantFetcher}
import models.gql.Fetchers.{gwasFetcher, l2gFetcher, l2gByStudyLocusIdRel, targetsFetcher, variantFetcher}
import models.gql.Objects.{logger, targetImp, variantIndexImp, colocalisationImp, l2gPredictionsImp}
import play.api.Logging
import play.api.libs.json.{JsValue, Json, OFormat, OWrites}
Expand Down Expand Up @@ -106,7 +106,7 @@ object CredibleSet extends Logging {
resolve = r => {
val variantId = r.value.variantId.getOrElse("")
logger.debug(s"Finding variant index: $variantId")
DeferredValue(variantFetcher.deferOpt(variantId))
variantFetcher.deferOpt(variantId)
}
)
)
Expand All @@ -128,18 +128,18 @@ object CredibleSet extends Logging {
OptionType(variantIndexImp),
description = None,
resolve = js => {
val id = (js.value \ "variantId").asOpt[String]
val id = (js.value \ "variantId").as[String]
logger.debug(s"Finding variant for id: $id")
DeferredValue(variantFetcher.deferOpt(id))
variantFetcher.deferOpt(id)
}
),
Field(
"l2Gpredictions",
OptionType(l2gPredictionsImp),
OptionType(ListType(l2gPredictionsImp)),
description = None,
resolve = js => {
val id = (js.value \ "studyLocusId").as[String]
DeferredValue(l2gFetcher.deferOpt(id))
l2gFetcher.deferRelSeq(l2gByStudyLocusIdRel, id)
}
),
Field(
Expand Down Expand Up @@ -310,7 +310,7 @@ object CredibleSet extends Logging {
resolve = js => {
val studyId = (js.value \ "studyId").asOpt[String]
logger.debug(s"Finding gwas study: $studyId")
DeferredValue(gwasFetcher.deferOpt(studyId))
gwasFetcher.deferOpt(studyId)
}
)
val credibleSetImp: ObjectType[Backend, JsValue] = ObjectType(
Expand Down
2 changes: 1 addition & 1 deletion app/models/entities/GwasIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ object GwasIndex extends Logging {
description = Some("Credible sets"),
resolve = js => {
val studyId = (js.value \ "studyId").as[String]
DeferredValue(credibleSetFetcher.deferRelSeq(credibleSetByStudyRel, studyId))
credibleSetFetcher.deferRelSeq(credibleSetByStudyRel, studyId)
}
)
lazy val gwasImp: ObjectType[Backend, JsValue] = ObjectType(
Expand Down
11 changes: 8 additions & 3 deletions app/models/gql/Fetchers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,18 @@ object Fetchers extends Logging {
)
}

implicit val l2gFetcherId: HasId[L2GPredictions, String] =
HasId[L2GPredictions, String](_.studyLocusId)

val l2gFetcherCache = FetcherCache.simple
val l2gFetcher: Fetcher[Backend, L2GPredictions, L2GPredictions, String] = Fetcher(
implicit val l2gHasId: HasId[L2GPredictions, String] = HasId[L2GPredictions, String](_.studyLocusId)
val l2gByStudyLocusIdRel =
Relation[L2GPredictions, String]("byStudyLocus", l2g => Seq(l2g.studyLocusId))
val l2gFetcher: Fetcher[Backend, L2GPredictions, L2GPredictions, String] = Fetcher.rel(
config = FetcherConfig.maxBatchSize(entities.Configuration.batchSize).caching(l2gFetcherCache),
fetch = (ctx: Backend, ids: Seq[String]) => {
ctx.getL2GPredictions(ids)
},
fetchRel = (ctx: Backend, ids: RelationIds[L2GPredictions]) => {
ctx.getL2GPredictions(ids(l2gByStudyLocusIdRel))
}
)

Expand Down

0 comments on commit 66e2d64

Please sign in to comment.