diff --git a/app/models/Backend.scala b/app/models/Backend.scala index 57df6557..d56e986e 100644 --- a/app/models/Backend.scala +++ b/app/models/Backend.scala @@ -13,7 +13,6 @@ import gql.validators.QueryTermsValidator._ import models.Helpers._ import models.db.{QAOTF, QLITAGG, QW2V, SentenceQuery} import models.entities.Publication._ -import models.entities.Aggregations._ import models.entities.Associations._ import models.entities.Configuration._ import models.entities.DiseaseHPOs._ @@ -463,25 +462,23 @@ class Backend @Inject() (implicit defaultOTSettings.clickhouse.disease.associations.name ) - def getAssociationsDiseaseFixed( - disease: Disease, + def getAssociationsEntityFixed( + tableName: String, datasources: Option[Seq[DatasourceSettings]], - indirect: Boolean, - facetFilters: Seq[String], - aggregationFilters: Seq[AggregationFilter], - targetSet: Set[String], + fixedEntityId: String, + indirectIds: Set[String], + bIds: Set[String], filter: Option[String], orderBy: Option[(String, String)], pagination: Option[Pagination] ): Future[Associations] = { val page = pagination.getOrElse(Pagination.mkDefault) val dss = datasources.getOrElse(defaultOTSettings.clickhouse.harmonic.datasources) - val weights = dss.map(s => (s.id, s.weight)) val dontPropagate = dss.withFilter(!_.propagate).map(_.id).toSet val aotfQ = QAOTF( - defaultOTSettings.clickhouse.disease.associations.name, - disease.id, + tableName, + fixedEntityId, _, _, filter, @@ -491,230 +488,57 @@ class Backend @Inject() (implicit page.offset, page.size ) + val simpleQ = aotfQ(indirectIds, bIds).simpleQuery(0, 100000) - logger.debug(s"get disease id ${disease.name}") - val indirectIDs = if (indirect) disease.descendants.toSet + disease.id else Set.empty[String] - val targetIds = applyFacetFiltersToBIDs("facet_search_target", targetSet, facetFilters) - val simpleQ = aotfQ(indirectIDs, targetIds).simpleQuery(0, 100000) - - val evidencesIndexName = defaultESSettings.entities - .find(_.name == "evidences_aotf") - .map(_.index) - .getOrElse("evidences_aotf") - - val tractabilityMappings = - List("SmallMolecule", "Antibody", "Protac", "OtherModalities").map { t => - s"tractability$t" -> AggregationMapping( - s"facet_tractability_${t.toLowerCase}", - IndexedSeq.empty, - nested = false - ) - }.toMap - val mappings = Map( - "dataTypes" -> AggregationMapping( - "datatype_id", - IndexedSeq("datatype_id", "datasource_id"), - false - ), - "pathwayTypes" -> AggregationMapping("facet_reactome", IndexedSeq("l1", "l2"), true), - "targetClasses" -> AggregationMapping("facet_classes", IndexedSeq("l1", "l2"), true) - ) ++ tractabilityMappings - - val queries = ElasticRetriever.aggregationFilterProducer(aggregationFilters, mappings) - val filtersMap = queries._2 - - val uniqueTargetsAgg = - CardinalityAggregation("uniques", Some("target_id.keyword"), precisionThreshold = Some(40000)) - val reverseTargetsAgg = ReverseNestedAggregation("uniques", None, Seq(uniqueTargetsAgg)) - - val queryAggs = Seq( - FilterAggregation( - "uniques", - queries._1, - subaggs = Seq( - uniqueTargetsAgg, - TermsAggregation("ids", field = Some("target_id.keyword"), size = Some(40000)) - ) - ), - FilterAggregation( - "dataTypes", - filtersMap("dataTypes"), - subaggs = Seq( - uniqueTargetsAgg, - TermsAggregation( - "aggs", - Some("datatype_id.keyword"), - size = Some(100), - subaggs = Seq( - uniqueTargetsAgg, - TermsAggregation( - "aggs", - Some("datasource_id.keyword"), - size = Some(100), - subaggs = Seq( - uniqueTargetsAgg - ) - ) - ) - ) - ) - ), - FilterAggregation( - "pathwayTypes", - filtersMap("pathwayTypes"), - subaggs = Seq( - uniqueTargetsAgg, - NestedAggregation( - "aggs", - path = "facet_reactome", - subaggs = Seq( - TermsAggregation( - "aggs", - Some("facet_reactome.l1.keyword"), - size = Some(100), - subaggs = Seq( - TermsAggregation( - "aggs", - Some("facet_reactome.l2.keyword"), - size = Some(100), - subaggs = Seq(reverseTargetsAgg) - ), - reverseTargetsAgg - ) - ), - reverseTargetsAgg - ) - ) - ) - ), - FilterAggregation( - "targetClasses", - filtersMap("targetClasses"), - subaggs = Seq( - uniqueTargetsAgg, - NestedAggregation( - "aggs", - path = "facet_classes", - subaggs = Seq( - TermsAggregation( - "aggs", - Some("facet_classes.l1.keyword"), - size = Some(100), - subaggs = Seq( - TermsAggregation( - "aggs", - Some("facet_classes.l2.keyword"), - size = Some(100), - subaggs = Seq(reverseTargetsAgg) - ), - reverseTargetsAgg - ) - ), - reverseTargetsAgg - ) - ) - ) - ) - ) ++ tractabilityMappings.map { kv => - FilterAggregation( - kv._1, - ElasticRetriever.aggregationFilterProducer(aggregationFilters, Map(kv))._1, - subaggs = Seq( - uniqueTargetsAgg, - TermsAggregation( - "aggs", - Some(s"${kv._2.key}.keyword"), - size = Some(100), - subaggs = Seq( - uniqueTargetsAgg - ) - ) - ) - ) - } - - val esQ = esRetriever.getAggregationsByQuery( - evidencesIndexName, - boolQuery() - .withShould( - boolQuery() - .withMust(termsQuery("disease_id.keyword", indirectIDs)) - .withMust(not(termsQuery("datasource_id.keyword", dontPropagate))) - ) - .withShould( - boolQuery() - .withMust(termQuery("disease_id.keyword", disease.id)) - ), - queryAggs - ) map { - case obj: JsObject => - logger.trace(Json.prettyPrint(obj)) - - val ids = (obj \ "uniques" \ "ids" \ "buckets" \\ "key").map(_.as[String]).toSet - val uniques = (obj \ "uniques" \\ "value").head.as[Long] - val restAggs: Seq[NamedAggregation] = ((obj - "uniques").fields map { pair => - NamedAggregation( - pair._1, - (pair._2 \ "uniques" \\ "value").headOption.map(jv => jv.as[Long]), - ArraySeq.unsafeWrapArray((pair._2 \\ "buckets").head.as[Array[entities.Aggregation]]) - ) - }).to(Seq) - - Some((Aggregations(uniques, restAggs), ids)) - - case _ => None - } - - // TODO use option to enable or disable the computation of each of the sides - (dbRetriever.executeQuery[String, Query](simpleQ) zip esQ) flatMap { case (tIDs, esR) => - val tids = esR.map(_._2 intersect tIDs.toSet).getOrElse(tIDs.toSet) - val fullQ = aotfQ(indirectIDs, tids).query - - logger.debug( - s"disease fixed get simpleQ n ${tIDs.size} " + - s"agg n ${esR.map(_._2.size).getOrElse(-1)} " + - s"inter n ${tids.size}" - ) + (dbRetriever.executeQuery[String, Query](simpleQ)) flatMap { case assocIds => + val assocIdSet = assocIds.toSet + val fullQ = aotfQ(indirectIds, assocIdSet).query - if (tids.nonEmpty) { + if (assocIdSet.nonEmpty) { dbRetriever.executeQuery[Association, Query](fullQ) map { case assocs => - Associations(dss, esR.map(_._1), tids.size, assocs) + Associations(dss, assocIdSet.size, assocs) } } else { - Future.successful(Associations(dss, esR.map(_._1), tids.size, Vector.empty)) + Future.successful(Associations(dss, assocIdSet.size, Vector.empty)) } } } - def getAssociationsTargetFixed( - target: Target, + def getAssociationsDiseaseFixed( + disease: Disease, datasources: Option[Seq[DatasourceSettings]], indirect: Boolean, facetFilters: Seq[String], - aggregationFilters: Seq[AggregationFilter], - diseaseSet: Set[String], + targetSet: Set[String], filter: Option[String], orderBy: Option[(String, String)], pagination: Option[Pagination] ): Future[Associations] = { - val page = pagination.getOrElse(Pagination.mkDefault) - val dss = datasources.getOrElse(defaultOTSettings.clickhouse.harmonic.datasources) - - val weights = dss.map(s => (s.id, s.weight)) - val dontPropagate = dss.withFilter(!_.propagate).map(_.id).toSet - val aotfQ = QAOTF( - defaultOTSettings.clickhouse.target.associations.name, - target.id, - _, - _, + logger.debug(s"get disease id ${disease.name}") + val indirectIDs = if (indirect) disease.descendants.toSet + disease.id else Set.empty[String] + val targetIds = applyFacetFiltersToBIDs("facet_search_target", targetSet, facetFilters) + getAssociationsEntityFixed( + defaultOTSettings.clickhouse.disease.associations.name, + datasources, + disease.id, + indirectIDs, + targetIds, filter, orderBy, - weights, - dontPropagate, - page.offset, - page.size + pagination ) + } + def getAssociationsTargetFixed( + target: Target, + datasources: Option[Seq[DatasourceSettings]], + indirect: Boolean, + facetFilters: Seq[String], + diseaseSet: Set[String], + filter: Option[String], + orderBy: Option[(String, String)], + pagination: Option[Pagination] + ): Future[Associations] = { logger.debug(s"get target id ${target.approvedSymbol} ACTUALLY DISABLED!") val indirectIDs = if (indirect) { val interactions = @@ -725,137 +549,22 @@ class Backend @Inject() (implicit .toSet + target.id case None => Set.empty + target.id } - interactions.await - } else Set.empty[String] val diseaseIds = applyFacetFiltersToBIDs("facet_search_disease", diseaseSet, facetFilters) - val simpleQ = aotfQ(indirectIDs, diseaseIds).simpleQuery(0, 100000) - - val evidencesIndexName = defaultESSettings.entities - .find(_.name == "evidences_aotf") - .map(_.index) - .getOrElse("evidences_aotf") - - val mappings = Map( - "dataTypes" -> AggregationMapping( - "datatype_id", - IndexedSeq("datatype_id", "datasource_id"), - false - ), - "therapeuticAreas" -> AggregationMapping("facet_therapeuticAreas", IndexedSeq.empty, false) - ) - - val queries = ElasticRetriever.aggregationFilterProducer(aggregationFilters, mappings) - val filtersMap = queries._2 - - val uniqueDiseasesAgg = CardinalityAggregation( - "uniques", - Some("disease_id.keyword"), - precisionThreshold = Some(40000) - ) - val queryAggs = Seq( - FilterAggregation( - "uniques", - queries._1, - subaggs = Seq( - uniqueDiseasesAgg, - TermsAggregation("ids", field = Some("disease_id.keyword"), size = Some(40000)) - ) - ), - FilterAggregation( - "dataTypes", - filtersMap("dataTypes"), - subaggs = Seq( - uniqueDiseasesAgg, - TermsAggregation( - "aggs", - Some("datatype_id.keyword"), - size = Some(100), - subaggs = Seq( - uniqueDiseasesAgg, - TermsAggregation( - "aggs", - Some("datasource_id.keyword"), - size = Some(100), - subaggs = Seq( - uniqueDiseasesAgg - ) - ) - ) - ) - ) - ), - FilterAggregation( - "therapeuticAreas", - filtersMap("therapeuticAreas"), - subaggs = Seq( - uniqueDiseasesAgg, - TermsAggregation( - "aggs", - Some("facet_therapeuticAreas.keyword"), - size = Some(100), - subaggs = Seq( - uniqueDiseasesAgg - ) - ) - ) - ) + getAssociationsEntityFixed( + defaultOTSettings.clickhouse.target.associations.name, + datasources, + target.id, + indirectIDs, + diseaseIds, + filter, + orderBy, + pagination ) - - val esQ = esRetriever.getAggregationsByQuery( - evidencesIndexName, - boolQuery() - .withShould( - boolQuery() - .withMust(termsQuery("target_id.keyword", indirectIDs)) - .withMust(not(termsQuery("datasource_id.keyword", dontPropagate))) - ) - .withShould( - boolQuery() - .withMust(termQuery("target_id.keyword", target.id)) - ), - queryAggs - ) map { - case obj: JsObject => - logger.trace(Json.prettyPrint(obj)) - - val ids = (obj \ "uniques" \ "ids" \ "buckets" \\ "key").map(_.as[String]).toSet - val uniques = (obj \ "uniques" \\ "value").head.as[Long] - val restAggs = (obj - "uniques").fields map { pair => - NamedAggregation( - pair._1, - (pair._2 \ "uniques" \\ "value").headOption.map(jv => jv.as[Long]), - ArraySeq.unsafeWrapArray((pair._2 \\ "buckets").head.as[Array[entities.Aggregation]]) - ) - } - - Some((Aggregations(uniques, restAggs.to(Seq)), ids)) - - case _ => None - } - - (dbRetriever.executeQuery[String, Query](simpleQ) zip esQ) flatMap { case (dIDs, esR) => - val dids = esR.map(_._2 intersect dIDs.toSet).getOrElse(dIDs.toSet) - val fullQ = aotfQ(indirectIDs, dids).query - - logger.debug( - s"target fixed get simpleQ n ${dIDs.size} " + - s"agg n ${esR.map(_._2.size).getOrElse(-1)} " + - s"inter n ${dids.size}" - ) - - if (dids.nonEmpty) { - dbRetriever.executeQuery[Association, Query](fullQ) map { case assocs => - Associations(dss, esR.map(_._1), dids.size, assocs) - } - } else { - Future.successful(Associations(dss, esR.map(_._1), dids.size, Vector.empty)) - } - } } def getSimilarW2VEntities( diff --git a/app/models/ElasticRetriever.scala b/app/models/ElasticRetriever.scala index 4e951940..6a11eea6 100644 --- a/app/models/ElasticRetriever.scala +++ b/app/models/ElasticRetriever.scala @@ -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 diff --git a/app/models/entities/Aggregations.scala b/app/models/entities/Aggregations.scala deleted file mode 100644 index 87155101..00000000 --- a/app/models/entities/Aggregations.scala +++ /dev/null @@ -1,33 +0,0 @@ -package models.entities - -import play.api.Logging -import play.api.libs.json._ -import play.api.libs.json.Reads._ -import play.api.libs.functional.syntax._ - -case class AggregationFilter(name: String, path: Seq[String]) - -case class AggregationMapping(key: String, pathKeys: IndexedSeq[String], nested: Boolean) - -case class Aggregation(key: String, uniques: Long, aggs: Option[Seq[Aggregation]]) - -case class NamedAggregation(name: String, uniques: Option[Long], rows: Seq[Aggregation]) - -case class Aggregations(uniques: Long, aggs: Seq[NamedAggregation]) - -object Aggregations extends Logging { - val empty: Aggregations = Aggregations(0, Seq.empty) - - implicit val aggregationImpWrites: OWrites[Aggregation] = Json.writes[Aggregation] - implicit val aggregationImpReads: Reads[Aggregation] = - ((__ \ "key").read[String] and - (__ \ "uniques" \\ "value").readWithDefault[Long](0) and - (__ \ "aggs" \\ "buckets") - .lazyReadNullable(Reads.seq[Aggregation](aggregationImpReads)))(Aggregation.apply _) - - implicit val namedAggregationImpFormat: OFormat[NamedAggregation] = Json.format[NamedAggregation] - implicit val aggregationsImpFormat: OWrites[Aggregations] = Json.writes[Aggregations] - - implicit val aggregationFilterImpFormat: OFormat[AggregationFilter] = - Json.format[AggregationFilter] -} diff --git a/app/models/entities/Associations.scala b/app/models/entities/Associations.scala index 43146a83..77447c5b 100644 --- a/app/models/entities/Associations.scala +++ b/app/models/entities/Associations.scala @@ -22,7 +22,6 @@ case class Association( case class Associations( datasources: Seq[DatasourceSettings], - aggregations: Option[Aggregations], count: Long, rows: Vector[Association] ) @@ -30,7 +29,7 @@ case class Associations( 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 => diff --git a/app/models/gql/Arguments.scala b/app/models/gql/Arguments.scala index 26b559fc..5bbef251 100644 --- a/app/models/gql/Arguments.scala +++ b/app/models/gql/Arguments.scala @@ -11,8 +11,6 @@ import sangria.util.tag object Arguments { - import Aggregations._ - val paginationGQLImp: InputObjectType[Pagination] = deriveInputObjectType[Pagination]() val datasourceSettingsInputImp: InputObjectType[DatasourceSettings] = @@ -20,9 +18,6 @@ object Arguments { InputObjectTypeName("DatasourceSettingsInput") ) - val aggregationFilterImp: InputObjectType[AggregationFilter] = - deriveInputObjectType[AggregationFilter]() - val entityNames: Argument[Option[Seq[String]]] = Argument( "entityNames", OptionInputType(ListInputType(StringType)), @@ -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)" ) } diff --git a/app/models/gql/Objects.scala b/app/models/gql/Objects.scala index 1c81912f..c5ab3822 100644 --- a/app/models/gql/Objects.scala +++ b/app/models/gql/Objects.scala @@ -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 { @@ -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 { @@ -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]() diff --git a/conf/application.conf b/conf/application.conf index 27d862a6..07320801 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -87,10 +87,6 @@ ot { name = "interaction" index = "interaction" }, - { - name = "evidences_aotf" - index = "evidences_aotf" - }, { name = "known_drugs" index = "known_drugs" diff --git a/test/controllers/GqlTest.scala b/test/controllers/GqlTest.scala index 3fcca40e..d33b0017 100644 --- a/test/controllers/GqlTest.scala +++ b/test/controllers/GqlTest.scala @@ -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")) } @@ -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")) } diff --git a/test/inputs/GqlCase.scala b/test/inputs/GqlCase.scala index 670d6779..683450b2 100644 --- a/test/inputs/GqlCase.scala +++ b/test/inputs/GqlCase.scala @@ -1,7 +1,6 @@ package inputs import controllers.GqlTest -import models.entities.AggregationFilter import org.scalacheck.Gen import play.api.Logging @@ -27,92 +26,60 @@ sealed trait GqlFragment[T] extends GqlCase[T] { def generateFragmentQuery: String } -case class AssociationDisease(file: String) extends GqlCase[(String, AggregationFilter)] { - val inputGenerator = for { - disease <- diseaseGenerator - agg <- aggregationfilterGenerator - } yield (disease, agg) +case class AssociationDisease(file: String) extends GqlCase[String] { + val inputGenerator = diseaseGenerator - def generateVariables(inputs: (String, AggregationFilter)) = + def generateVariables(disease: String) = s""" "variables": { - "efoId": "${inputs._1}", + "efoId": "$disease", "index": 0, "size": 10, - "sortBy": "", - "aggregationFilters": [ - { - "name": "${inputs._2.name}", - "path": ${inputs._2.path.mkString("[\"", "\", \"", "\"]")} - }] + "sortBy": "" } """ } -case class AssociationDiseaseIndirect(file: String) extends GqlCase[(String, AggregationFilter)] { - val inputGenerator = for { - disease <- diseaseGenerator - agg <- aggregationfilterGenerator - } yield (disease, agg) +case class AssociationDiseaseIndirect(file: String) extends GqlCase[String] { + val inputGenerator = diseaseGenerator - def generateVariables(inputs: (String, AggregationFilter)) = + def generateVariables(disease: String) = s""" "variables": { - "efoId": "${inputs._1}", + "efoId": "$disease", "index": 0, "size": 10, "sortBy": "", - "enableIndirect": false, - "aggregationFilters": [ - { - "name": "${inputs._2.name}", - "path": ${inputs._2.path.mkString("[\"", "\", \"", "\"]")} - }] + "enableIndirect": false } """ } -case class AssociationTarget(file: String) extends GqlCase[(String, AggregationFilter)] { - val inputGenerator = for { - target <- geneGenerator - agg <- aggregationfilterGenerator - } yield (target, agg) +case class AssociationTarget(file: String) extends GqlCase[String] { + val inputGenerator = geneGenerator - def generateVariables(inputs: (String, AggregationFilter)) = + def generateVariables(target: String) = s""" "variables": { - "ensemblId": "${inputs._1}", + "ensemblId": "$target", "index": 0, "size": 10, - "sortBy": "", - "aggregationFilters": [ - { - "name": "${inputs._2.name}", - "path": ${inputs._2.path.mkString("[\"", "\", \"", "\"]")} - }] + "sortBy": "" } """ } -case class AssociationTargetIndirect(file: String) extends GqlCase[(String, AggregationFilter)] { - val inputGenerator = for { - target <- geneGenerator - agg <- aggregationfilterGenerator - } yield (target, agg) +case class AssociationTargetIndirect(file: String) extends GqlCase[String] { + val inputGenerator = geneGenerator - def generateVariables(inputs: (String, AggregationFilter)) = + def generateVariables(target: String) = s""" "variables": { - "ensemblId": "${inputs._1}", + "ensemblId": "$target", "index": 0, "enableIndirect": false, "size": 10, - "sortBy": "", - "aggregationFilters": [ - { - "name": "${inputs._2.name}", - "path": ${inputs._2.path.mkString("[\"", "\", \"", "\"]")} - }] + "sortBy": "" } """ } @@ -130,25 +97,6 @@ case class Disease(file: String) extends GqlCase[String] { """ } -case class DiseaseAggregationfilter(file: String) extends GqlCase[(String, AggregationFilter)] { - val inputGenerator = for { - disease <- diseaseGenerator - agg <- aggregationfilterGenerator - } yield (disease, agg) - - def generateVariables(inputs: (String, AggregationFilter)): String = - s""" - "variables": { - "efoId": "${inputs._1}", - "aggregationFilters": [ - { - "name": "${inputs._2.name}", - "path": ${inputs._2.path.mkString("[\"", "\", \"", "\"]")} - }] - } - """ -} - abstract class AbstractDrug extends GqlCase[String] { val inputGenerator = drugGenerator @@ -320,28 +268,6 @@ case class TargetDisease(file: String) extends GqlCase[(String, String)] { } } -case class TargetAggregationfilter(file: String) extends GqlCase[(String, AggregationFilter)] { - val inputGenerator = for { - gene <- geneGenerator - aggregationFilter <- aggregationfilterGenerator - } yield (gene, aggregationFilter) - - def generateVariables(inputs: (String, AggregationFilter)): String = - s""" - "variables": { - "ensemblId": "${inputs._1}", - "size": 10, - "index": 0, - "aggregationFilters": [ - { - "name": "${inputs._2.name}", - "path": ${inputs._2.path.mkString("[\"", "\", \"", "\"]")} - }] - } - """ - -} - case class TargetDiseaseSize(file: String) extends GqlCase[(String, String, Int)] { val inputGenerator = targetDiseaseSizeGenerator diff --git a/test/inputs/GqlItTestInputs.scala b/test/inputs/GqlItTestInputs.scala index 0a7b1eb0..4b601f69 100644 --- a/test/inputs/GqlItTestInputs.scala +++ b/test/inputs/GqlItTestInputs.scala @@ -1,6 +1,5 @@ package inputs -import models.entities.AggregationFilter import org.scalacheck.Gen import scala.reflect.io.File @@ -16,82 +15,7 @@ trait GqlItTestInputs { lazy val goInputs = File(this.getClass.getResource(s"/gqlInputs/goIds.txt").getPath).lines().toList - val aggregationFilterMap: Map[String, Seq[String]] = Map( - "pathwayTypes" -> Seq( - "Autophagy", - "Cell Cycle", - "Cell-Cell communication", - "Cellular responses to external stimuli", - "Chromatin organization", - "Circadian Clock", - "Developmental Biology", - "Digestion and absorption", - "Disease", - "DNA Repair", - "DNA Replication", - "Extracellular matrix organization", - "Gene expression (Transcription)", - "Hemostasis", - "Immune System", - "Metabolism", - "Metabolism of proteins", - "Metabolism of RNA", - "Muscle contraction", - "Neuronal System", - "Organelle biogenesis and maintenance", - "Programmed Cell Death", - "Protein localization", - "Reproduction", - "Sensory Perception", - "Signal Transduction", - "Transport of small molecules", - "Vesicle-mediated transport" - ), - "targetClasses" -> Seq( - "Adhesion", - "Auxiliary transport protein", - "Enzyme", - "Epigenetic regulator", - "Ion channel", - "Membrane receptor", - "Other cytosolic protein", - "Other membrane protein", - "Other nuclear protein", - "Secreted protein", - "Surface antigen", - "Transcription factor", - "Transporter", - "Unclassified protein", - "Structural protein" - ), - "dataTypes" -> Seq( - "Genetic associations", - "Drugs", - "Text mining", - "RNA expression", - "Animal models", - "Somatic mutations" - ), - "tractabilityAntibody" -> Seq( - "Clinical precedence", - "Predicted tractable high confidence", - "Predicted tractable med low confidence" - ), - "tractabilitySmallMolecule" -> Seq( - "Clinical precedence", - "Discovery precedence", - "Predicted tractable" - ) - ) - // Generators - val aggregationfilterGenerator: Gen[AggregationFilter] = { - for { - name <- Gen.oneOf(aggregationFilterMap.keySet) - paths <- Gen.someOf(aggregationFilterMap(name)) - } yield AggregationFilter(name, paths.to(Seq)) - } - val geneGenerator: Gen[String] = Gen.oneOf(geneInputs) val diseaseGenerator: Gen[String] = Gen.oneOf(diseaseInputs) val drugGenerator: Gen[String] = Gen.oneOf(drugInputs)