From 4ee36e67c1642750035665b0c205e8be7a93de69 Mon Sep 17 00:00:00 2001 From: Miguel C Date: Thu, 16 Jan 2020 13:54:11 +0000 Subject: [PATCH] feat: implement the last needed table to serve locus to gene data --- app/models/Backend.scala | 50 ++++++++++++++++++++++++++++++++++++++ app/models/Entities.scala | 30 +++++++++++++++++++++++ app/models/GQLSchema.scala | 21 +++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/app/models/Backend.scala b/app/models/Backend.scala index 4ea1437..56b0c86 100644 --- a/app/models/Backend.scala +++ b/app/models/Backend.scala @@ -496,6 +496,56 @@ class Backend @Inject()(@NamedDatabase("default") protected val dbConfigProvider } } + def getStudiesAndLeadVariantsForGeneByL2G(geneId: String, + pageIndex: Option[Int], + pageSize: Option[Int]): Future[Vector[V2DL2GRowByGene]] = { + val limitClause = parsePaginationTokens(pageIndex, pageSize) + + val topLociEnrich = + sql""" + |SELECT study_id, + | chrom, + | pos, + | ref, + | alt, + | y_proba_logi_distance, + | y_proba_logi_interaction, + | y_proba_logi_interlocus, + | y_proba_logi_molecularQTL, + | y_proba_logi_pathogenicity, + | y_proba_full_model, + | odds_ratio, + | oddsr_ci_lower, + | oddsr_ci_upper, + | direction, + | beta, + | beta_ci_lower, + | beta_ci_upper, + | pval, + | pval_exponent, + | pval_mantissa + |FROM ot.l2g_by_gsl l + |ANY INNER JOIN ( + | SELECT *, + | CAST(lead_chrom, 'String') as stringChrom + | FROM ot.v2d_by_stchr + | ) v on (v.study_id = l.study_id and + | v.stringChrom = l.chrom and + | v.lead_pos = l.pos and + | v.lead_ref = l.ref and + | v.lead_alt = l.alt) + |PREWHERE gene_id = $geneId + |#$limitClause + """.stripMargin.as[V2DL2GRowByGene] + + db.run(topLociEnrich.asTry).map { + case Success(v) => v + case Failure(ex) => + logger.error(ex.getMessage) + Vector.empty + } + } + def getGenesByRegion(chromosome: String, startPos: Long, endPos: Long): Future[Seq[Gene]] = { (parseChromosome(chromosome), parseRegion(startPos, endPos)) match { case (Right(chr), Right((start, end))) => diff --git a/app/models/Entities.scala b/app/models/Entities.scala index 3e86bc5..0c463c9 100644 --- a/app/models/Entities.scala +++ b/app/models/Entities.scala @@ -43,6 +43,11 @@ object Entities { case class V2DRow(tag: SimpleVariant, lead: SimpleVariant, study: Study, association: V2DAssociation, odds: V2DOdds, beta: V2DBeta) + case class V2DL2GRowByGene(studyId: String, variantId: String, odds: V2DOdds, beta: V2DBeta, pval: Double, + pvalExponent: Long, pvalMantissa: Double, yProbaDistance: Double, + yProbaInteraction: Double, yProbaInterlocus: Double, yProbaMolecularQTL: Double, + yProbaPathogenicity: Double, yProbaModel: Double) + case class OverlapRow(stid: String, numOverlapLoci: Int) case class OverlappedLociStudy(studyId: String, topOverlappedStudies: IndexedSeq[OverlapRow]) @@ -375,6 +380,31 @@ object Entities { GetResult(r => SLGRow(r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<)) } + implicit val getV2DL2GRowByGene: GetResult[V2DL2GRowByGene] = { + GetResult(r => { + val studyId: String = r.<< + val svID: String = SimpleVariant(r.<<, r.<<, r.<<, r.<<).id + + val yProbaLogiDistance: Double = r.<< + val yProbaLogiInteraction: Double = r.<< + val yProbaLogiInterlocus: Double = r.<< + val yProbaLogiMolecularQTL: Double = r.<< + val yProbaLogiPathogenicity: Double = r.<< + val yProbaFullModel: Double = r.<< + + val odds = V2DOdds(r.< studiesFetcher.defer(ctx.value.studyId)), + Field("variant", variant, + description = Some("Variant"), + resolve = ctx => variantsFetcher.defer(ctx.value.variantId)) + ), + ExcludeFields("studyId", "variantId") + ) + val query = ObjectType( "Query", fields[Backend, Unit]( Field("search", searchResult, @@ -1215,9 +1229,14 @@ object GQLSchema extends GQLGene with GQLVariant with GQLStudy with GQLIndexVari arguments = studyId :: variantId :: Nil, resolve = ctx => ctx.ctx.qtlColocalisation(ctx.arg(studyId), ctx.arg(variantId))), + // getStudiesAndLeadVariantsForGeneByL2G Field("studiesAndLeadVariantsForGene", ListType(studiesAndLeadVariantsForGene), arguments = geneId :: Nil, - resolve = ctx => ctx.ctx.getStudiesAndLeadVariantsForGene(ctx.arg(geneId))) + resolve = ctx => ctx.ctx.getStudiesAndLeadVariantsForGene(ctx.arg(geneId))), + Field("studiesAndLeadVariantsForGeneByL2G", ListType(V2DL2GRowByGeneImp), + arguments = geneId :: pageIndex :: pageSize :: Nil, + resolve = ctx => ctx.ctx.getStudiesAndLeadVariantsForGeneByL2G(ctx.arg(geneId), + ctx.arg(pageIndex), ctx.arg(pageSize))) )) val schema = Schema(query)