Skip to content

Commit

Permalink
feat: implement the last needed table to serve locus to gene data
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarmona committed Jan 16, 2020
1 parent d68176e commit 4ee36e6
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
50 changes: 50 additions & 0 deletions app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))) =>
Expand Down
30 changes: 30 additions & 0 deletions app/models/Entities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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.<<?, r.<<?, r.<<?)
val beta = V2DBeta(r.<<?, r.<<?, r.<<?, r.<<?)
val pval: Double = r.<<
val pvalExponent: Long = r.<<
val pvalMantissa: Double = r.<<

V2DL2GRowByGene(studyId, svID, odds, beta, pval, pvalExponent, pvalMantissa,
yProbaLogiDistance, yProbaLogiInteraction, yProbaLogiInterlocus, yProbaLogiMolecularQTL,
yProbaLogiPathogenicity, yProbaFullModel)

})
}

implicit val getV2DByStudy: GetResult[V2DByStudy] = {
def toGeneScoreTupleWithDuplicates(geneIds: Seq[String], geneScores: Seq[Double]): Seq[(String, Double)] = {
val ordScored = geneIds zip geneScores
Expand Down
21 changes: 20 additions & 1 deletion app/models/GQLSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,20 @@ object GQLSchema extends GQLGene with GQLVariant with GQLStudy with GQLIndexVari
ExcludeFields("studyId", "variantId")
)

implicit val V2DOddsImp = deriveObjectType[Backend, V2DOdds]()
implicit val V2DBetaImp = deriveObjectType[Backend, V2DBeta]()
implicit val V2DL2GRowByGeneImp = deriveObjectType[Backend, V2DL2GRowByGene](
AddFields(
Field("study", study,
description = Some("Study"),
resolve = ctx => 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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4ee36e6

Please sign in to comment.