Skip to content

Commit

Permalink
Merge pull request #184 from opentargets/3361_remove_classic_aotf_agg…
Browse files Browse the repository at this point in the history
…regations

3361 remove classic aotf aggregations
  • Loading branch information
jdhayhurst authored Jul 23, 2024
2 parents 68a4191 + 66ae674 commit e5f0416
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 637 deletions.
385 changes: 47 additions & 338 deletions app/models/Backend.scala

Large diffs are not rendered by default.

58 changes: 0 additions & 58 deletions app/models/ElasticRetriever.scala
Original file line number Diff line number Diff line change
Expand Up @@ -740,64 +740,6 @@ class ElasticRetriever @Inject() (

object ElasticRetriever extends Logging {

/** aggregationFilterProducer returns a tuple where the first element is the overall list
* of filters and the second is a map with the cartesian product of each aggregation with
* the complementary list of filters
*/
def aggregationFilterProducer(
filters: Seq[AggregationFilter],
mappings: Map[String, AggregationMapping]
): (BoolQuery, Map[String, BoolQuery]) = {
val filtersByName = filters
.groupBy(_.name)
.view
.filterKeys(mappings.contains)
.toMap
.map { case (facet, filters) =>
val mappedFacet = mappings(facet)
val ff = filters.foldLeft(BoolQuery()) { (b, filter) =>
val termKey = filter.path.zipWithIndex.last
val termLevel = mappedFacet.pathKeys.lift
val termPrefix = if (mappedFacet.nested) s"${mappedFacet.key}." else ""
val keyName = termPrefix + s"${termLevel(termKey._2).getOrElse(mappedFacet.key)}.keyword"
b.withShould(TermQuery(keyName, termKey._1))
}

if (mappedFacet.nested) {
facet -> NestedQuery(mappedFacet.key, ff)
} else {
facet -> ff
}

}
.withDefaultValue(BoolQuery())

val overallFilters = filtersByName.foldLeft(BoolQuery()) { case (b, f) =>
b.withMust(f._2)
}

val namesR = mappings.keys.toList.reverse
if (namesR.size > 1) {
val mappedMappgings =
mappings.map(p => p._1 -> filtersByName(p._1)).toList.combinations(namesR.size - 1).toList

val cartesianProd = (namesR zip mappedMappgings).toMap.view
.mapValues(_.foldLeft(BoolQuery()) { (b, q) =>
b.withMust(q._2)
})
.toMap

logger.debug(s"overall filters $overallFilters")
cartesianProd foreach { el =>
logger.debug(s"cartesian product ${el._1} -> ${el._2.toString}")
}

(overallFilters, cartesianProd)
} else {
(overallFilters, Map.empty[String, BoolQuery].withDefaultValue(BoolQuery()))
}
}

/** *
* SortBy case class use the `fieldName` to sort by and asc if `desc` is false
* otherwise desc
Expand Down
33 changes: 0 additions & 33 deletions app/models/entities/Aggregations.scala

This file was deleted.

3 changes: 1 addition & 2 deletions app/models/entities/Associations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ case class Association(

case class Associations(
datasources: Seq[DatasourceSettings],
aggregations: Option[Aggregations],
count: Long,
rows: Vector[Association]
)

case class EvidenceSource(datasource: String, datatype: String)

object Associations {
val empty: Associations = Associations(Seq.empty, None, 0, Vector.empty)
val empty: Associations = Associations(Seq.empty, 0, Vector.empty)

implicit val getAssociationOTFRowFromDB: GetResult[Association] =
GetResult { r =>
Expand Down
13 changes: 1 addition & 12 deletions app/models/gql/Arguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ import sangria.util.tag

object Arguments {

import Aggregations._

val paginationGQLImp: InputObjectType[Pagination] = deriveInputObjectType[Pagination]()

val datasourceSettingsInputImp: InputObjectType[DatasourceSettings] =
deriveInputObjectType[DatasourceSettings](
InputObjectTypeName("DatasourceSettingsInput")
)

val aggregationFilterImp: InputObjectType[AggregationFilter] =
deriveInputObjectType[AggregationFilter]()

val entityNames: Argument[Option[Seq[String]]] = Argument(
"entityNames",
OptionInputType(ListInputType(StringType)),
Expand Down Expand Up @@ -144,15 +139,9 @@ object Arguments {
description = "List of datasource settings"
)

val aggregationFiltersListArg: Argument[Option[Seq[AggregationFilter]]] =
Argument("aggregationFilters",
OptionInputType(ListInputType(aggregationFilterImp)),
description = "List of the facets to aggregate by"
)

val facetFiltersListArg: Argument[Option[Seq[String]]] = Argument(
"facetFilters",
OptionInputType(ListInputType(StringType)),
description = "List of the facet IDs to filter by (using OR)"
description = "List of the facet IDs to filter by (using AND)"
)
}
13 changes: 2 additions & 11 deletions app/models/gql/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,13 @@ object Objects extends Logging {
associatedOTFDiseasesImp,
description = Some("associations on the fly"),
arguments =
BIds :: indirectTargetEvidences :: datasourceSettingsListArg :: facetFiltersListArg :: aggregationFiltersListArg :: BFilterString :: scoreSorting :: pageArg :: Nil,
BIds :: indirectTargetEvidences :: datasourceSettingsListArg :: facetFiltersListArg :: BFilterString :: scoreSorting :: pageArg :: Nil,
resolve = ctx =>
ctx.ctx.getAssociationsTargetFixed(
ctx.value,
ctx arg datasourceSettingsListArg,
ctx arg indirectTargetEvidences getOrElse false,
ctx arg facetFiltersListArg getOrElse (Seq.empty),
ctx arg aggregationFiltersListArg getOrElse Seq.empty,
ctx arg BIds map (_.toSet) getOrElse Set.empty,
ctx arg BFilterString,
(ctx arg scoreSorting) map (_.split(" ").take(2).toList match {
Expand Down Expand Up @@ -421,14 +420,13 @@ object Objects extends Logging {
associatedOTFTargetsImp,
description = Some("associations on the fly"),
arguments =
BIds :: indirectEvidences :: datasourceSettingsListArg :: facetFiltersListArg :: aggregationFiltersListArg :: BFilterString :: scoreSorting :: pageArg :: Nil,
BIds :: indirectEvidences :: datasourceSettingsListArg :: facetFiltersListArg :: BFilterString :: scoreSorting :: pageArg :: Nil,
resolve = ctx =>
ctx.ctx.getAssociationsDiseaseFixed(
ctx.value,
ctx arg datasourceSettingsListArg,
ctx arg indirectEvidences getOrElse (true),
ctx arg facetFiltersListArg getOrElse (Seq.empty),
ctx arg aggregationFiltersListArg getOrElse (Seq.empty),
ctx arg BIds map (_.toSet) getOrElse (Set.empty),
ctx arg BFilterString,
(ctx arg scoreSorting) map (_.split(" ").take(2).toList match {
Expand Down Expand Up @@ -1059,13 +1057,6 @@ object Objects extends Logging {
deriveObjectType[Backend, HarmonicSettings]()
implicit val clickhouseSettingsImp: ObjectType[Backend, ClickhouseSettings] =
deriveObjectType[Backend, ClickhouseSettings]()

implicit lazy val aggregationImp: ObjectType[Backend, Aggregation] =
deriveObjectType[Backend, Aggregation]()
implicit lazy val namedAggregationImp: ObjectType[Backend, NamedAggregation] =
deriveObjectType[Backend, NamedAggregation]()
implicit lazy val aggregationsImp: ObjectType[Backend, Aggregations] =
deriveObjectType[Backend, Aggregations]()
implicit val evidenceSourceImp: ObjectType[Backend, EvidenceSource] =
deriveObjectType[Backend, EvidenceSource]()

Expand Down
4 changes: 0 additions & 4 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ ot {
name = "interaction"
index = "interaction"
},
{
name = "evidences_aotf"
index = "evidences_aotf"
},
{
name = "known_drugs"
index = "known_drugs"
Expand Down
9 changes: 0 additions & 9 deletions test/controllers/GqlTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ class GqlTest
}

"Disease page queries" must {
"return a valid response for disease facets" taggedAs (IntegrationTestTag, ClickhouseTestTag) in {
testQueryAgainstGqlEndpoint(DiseaseAggregationfilter("DiseasePage_DiseaseFacets"))
}
"return a valid response for disease page" taggedAs IntegrationTestTag in {
testQueryAgainstGqlEndpoint(Disease("DiseasePage_DiseasePage"))
}
Expand Down Expand Up @@ -508,18 +505,12 @@ class GqlTest
}

"Target page" must {
"return valid associations visualisation" taggedAs (IntegrationTestTag, ClickhouseTestTag) in {
testQueryAgainstGqlEndpoint(TargetAggregationfilter("TargetPage_AssociationsViz"))
}
"return valid chemical probes" taggedAs (IntegrationTestTag) in {
testQueryAgainstGqlEndpoint(Target("ChemicalProbes_ChemicalProbes"))(ensgTransform)
}
"return valid gene ontology" taggedAs (IntegrationTestTag) in {
testQueryAgainstGqlEndpoint(Target("GeneOntology_GeneOntology"))(ensgTransform)
}
"return valid target facets" taggedAs (IntegrationTestTag, ClickhouseTestTag) in {
testQueryAgainstGqlEndpoint(TargetAggregationfilter("TargetPage_TargetFacets"))
}
"return valid target page" taggedAs (IntegrationTestTag) in {
testQueryAgainstGqlEndpoint(Target("TargetPage_TargetPage"))
}
Expand Down
Loading

0 comments on commit e5f0416

Please sign in to comment.