Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Update TRAPI model to 1.3 (#559)
Browse files Browse the repository at this point in the history
This PR updates the TRAPI model to TRAPI 1.3. This includes:
- Removed the TRAPISubAttribute type and allow attributes to have TRAPIAttributes of their own. See [TRAPI model change](NCATSTranslator/ReasonerAPI@6ec8ea2) and [TRAPI ChangeLog](https://github.com/NCATSTranslator/ReasonerAPI/blob/7520ac564e63289dffe092d4c7affd6db4ba22f1/ChangeLog.md).
  - This requires making some usages `lazy` so that they can recursively refer to themselves.
- Updated TRAPINodeBinding to the model described in https://github.com/NCATSTranslator/ReasonerAPI/blob/1e0795a1c4ff5bcac3ccd5f188fdc09ec6bd27c3/TranslatorReasonerAPI.yaml#L468-L505, which includes changes from:
  - NCATSTranslator/ReasonerAPI#304
  - NCATSTranslator/ReasonerAPI#312
  • Loading branch information
gaurav authored Aug 25, 2022
2 parents 6e5a813 + fa8fc9c commit 82ca402
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object ExampleQueriesEndpointTest extends DefaultRunnableSpec {
implicit val decoderBiolinkClass: Decoder[BiolinkClass] = Implicits.biolinkClassDecoder(biolinkData.classes)
implicit val decoderBiolinkPredicate: Decoder[BiolinkPredicate] =
Implicits.biolinkPredicateDecoder(biolinkData.predicates)
implicit val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]
implicit lazy val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]

exampleJson.as[ExampleJsonFile]
}
Expand Down Expand Up @@ -120,7 +120,7 @@ object ExampleQueriesEndpointTest extends DefaultRunnableSpec {
implicit val decoderBiolinkClass: Decoder[BiolinkClass] = Implicits.biolinkClassDecoder(biolinkData.classes)
implicit val decoderBiolinkPredicate: Decoder[BiolinkPredicate] =
Implicits.biolinkPredicateDecoder(biolinkData.predicates)
implicit val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]
implicit lazy val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]

response.as[TRAPIResponse]
}
Expand Down
4 changes: 2 additions & 2 deletions src/it/scala/org/renci/cam/it/ProdQueryServiceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object ProdQueryServiceTest extends DefaultRunnableSpec {
implicit val decoderIRI: Decoder[IRI] = Implicits.iriDecoder(biolinkData.prefixes)
implicit val keyDecoderIRI: KeyDecoder[IRI] = Implicits.iriKeyDecoder(biolinkData.prefixes)
implicit val decoderTRAPINode: Decoder[BiolinkClass] = Implicits.biolinkClassDecoder(biolinkData.classes)
implicit val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]
implicit lazy val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]
knowledgeGraphNodesJson.as[Map[IRI, TRAPINode]]
}

Expand All @@ -76,7 +76,7 @@ object ProdQueryServiceTest extends DefaultRunnableSpec {
implicit val keyDecoderIRI: KeyDecoder[IRI] = Implicits.iriKeyDecoder(biolinkData.prefixes)
implicit val decoderBiolinkClass: Decoder[BiolinkClass] = Implicits.biolinkClassDecoder(biolinkData.classes)
implicit val decoderBiolinkPredicate: Decoder[BiolinkPredicate] = Implicits.biolinkPredicateDecoder(biolinkData.predicates)
implicit val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]
implicit lazy val decoderTRAPIAttribute: Decoder[TRAPIAttribute] = deriveDecoder[TRAPIAttribute]
knowledgeGraphEdgesJson.as[Map[String, TRAPIEdge]]
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
host = 0.0.0.0
port = 8080
port = ${?PORT}
trapi-version = "1.2.0"
trapi-version = "1.3.0"
trapi-version = ${?TRAPI_VERSION}
location = "http://localhost:8080"
location = ${?LOCATION}
Expand Down
54 changes: 32 additions & 22 deletions src/main/scala/org/renci/cam/domain/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,43 +126,52 @@ package object domain {

}

final case class TRAPIQueryNode(ids: Option[List[IRI]], categories: Option[List[BiolinkClass]], is_set: Option[Boolean])
final case class TRAPIQueryNode(ids: Option[List[IRI]],
categories: Option[List[BiolinkClass]],
is_set: Option[Boolean] = Some(false),
constraints: Option[List[TRAPIAttributeConstraint]] = None)

final case class TRAPIQueryEdge(predicates: Option[List[BiolinkPredicate]],
subject: String,
`object`: String,
constraints: Option[List[TRAPIQueryConstraint]])

final case class TRAPIQueryConstraint(id: IRI,
name: String,
not: Option[Boolean],
operator: String,
value: String,
unit_id: Option[IRI],
unit_name: Option[String])
knowledge_type: Option[String] = None,
attribute_constraints: Option[List[TRAPIAttributeConstraint]] = None,
qualifier_constraints: Option[List[TRAPIQualifierConstraint]] = None)

final case class TRAPIAttributeConstraint(id: IRI,
name: String,
not: Option[Boolean],
operator: String,
value: String,
unit_id: Option[IRI],
unit_name: Option[String])

final case class TRAPIQueryGraph(nodes: Map[String, TRAPIQueryNode], edges: Map[String, TRAPIQueryEdge])

final case class TRAPINode(name: Option[String], categories: Option[List[BiolinkClass]], attributes: Option[List[TRAPIAttribute]])

final case class TRAPIEdge(predicate: Option[BiolinkPredicate], subject: IRI, `object`: IRI, attributes: Option[List[TRAPIAttribute]])
final case class TRAPIEdge(predicate: Option[BiolinkPredicate],
subject: IRI,
`object`: IRI,
attributes: Option[List[TRAPIAttribute]] = None,
qualifiers: Option[List[TRAPIQualifier]] = None)

final case class TRAPIAttribute(attribute_source: Option[String],
attribute_type_id: IRI,
original_attribute_name: Option[String],
// Note that `value` is actually supposed to be able to support
// any data type, including lists.
// https://github.com/NCATSTranslator/ReasonerAPI/blob/7520ac564e63289dffe092d4c7affd6db4ba22f1/TranslatorReasonerAPI.yaml#L761-L764
// Not sure if a List[String] is close enough to read attributes here.
value: List[String],
value_type_id: Option[IRI],
value_url: Option[String],
description: Option[String],
attributes: Option[List[TRAPISubAttribute]])
attributes: Option[List[TRAPIAttribute]])

final case class TRAPIQualifier(qualifier_type_id: String, qualifier_value: String)

final case class TRAPISubAttribute(attribute_source: Option[String],
attribute_type_id: IRI,
original_attribute_name: Option[String],
value: List[String],
value_type_id: Option[IRI],
value_url: Option[String],
description: Option[String])
final case class TRAPIQualifierConstraint(qualifier_set: List[TRAPIQualifier])

final case class TRAPIKnowledgeGraph(nodes: Map[IRI, TRAPINode], edges: Map[String, TRAPIEdge])

Expand All @@ -175,7 +184,7 @@ package object domain {

}

final case class TRAPINodeBinding(id: IRI)
final case class TRAPINodeBinding(id: IRI, query_id: Option[IRI] = None, attributes: Option[List[TRAPIAttribute]] = None)

final case class TRAPIEdgeBinding(id: String)

Expand All @@ -185,7 +194,7 @@ package object domain {
knowledge_graph: Option[TRAPIKnowledgeGraph],
results: Option[List[TRAPIResult]])

final case class TRAPIQuery(message: TRAPIMessage, log_level: Option[String])
final case class TRAPIQuery(message: TRAPIMessage, log_level: Option[String], submitter: Option[String] = None)

final case class TRAPIResponse(message: TRAPIMessage, status: Option[String], description: Option[String], logs: Option[List[LogEntry]])

Expand All @@ -196,7 +205,8 @@ package object domain {
final case class MetaEdge(subject: BiolinkClass,
predicate: BiolinkPredicate,
`object`: BiolinkClass,
attributes: Option[List[MetaAttribute]])
attributes: Option[List[MetaAttribute]],
knowledge_types: Option[List[String]] = Some(List("lookup")))

final case class MetaAttribute(attribute_type_id: IRI,
attribute_source: Option[String],
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/renci/cam/test/QueryServiceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ object QueryServiceTest extends DefaultRunnableSpec with LazyLogging {
predicates = Some(List(BiolinkPredicate("related_to", IRI("https://w3id.org/biolink/vocab/related_to")))),
subject = "n0",
`object` = "n1",
constraints = None
attribute_constraints = None
)
)
)
Expand Down

0 comments on commit 82ca402

Please sign in to comment.