Skip to content

Commit

Permalink
feat: Added GeneAlterationReference to allow modelling which gene is …
Browse files Browse the repository at this point in the history
…the relevant one in the referenced variant object; fix: Corrected linter errors in Tests
  • Loading branch information
lucienclin committed Dec 2, 2024
1 parent 64bbaaf commit a067fb3
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 22 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ lazy val compilerOptions = Seq(
"-language:experimental.macros",
"-language:higherKinds",
"-language:implicitConversions",
"-language:postfixOps",
"-Ymacro-annotations",

// Warnings as errors!
Expand Down Expand Up @@ -75,11 +76,11 @@ lazy val compilerOptions = Seq(
"-Wunused:locals",
"-Wunused:patvars",
"-Wunused:privates",
"-Wunused:implicits",
"-Wvalue-discard",

// Deactivated to avoid many false positives from 'evidence' parameters in context bounds
// "-Wunused:params",
// "-Wunused:implicits",
)


Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/de/dnpm/dip/coding/Coding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,10 @@ object Coding
coding => css.values.contains(coding.system)
)


implicit def codingToCoproductCoding[S, C <: Coproduct](coding: Coding[S])(
implicit sel: shapeless.ops.coproduct.Selector[C,S]
): Coding[C] =
coding.asInstanceOf[Coding[C]]

}
13 changes: 13 additions & 0 deletions src/main/scala/de/dnpm/dip/model/BaseCompleters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import de.dnpm.dip.coding.{
UnregisteredMedication
}
import de.dnpm.dip.coding.hgvs.HGVS
import de.dnpm.dip.coding.hgnc.HGNC



trait BaseCompleters
Expand Down Expand Up @@ -159,4 +161,15 @@ trait BaseCompleters
) // if not all CodeSystemProviders are in scope, so csps is sure to contain all systems
)


implicit def geneAlterationReferenceCompleter[T](
implicit hgnc: CodeSystemProvider[HGNC,Id,Applicative[Id]]
): Completer[GeneAlterationReference[T]] =
Completer.of(
ref => ref.copy(
gene = ref.gene.complete
)
)


}
54 changes: 54 additions & 0 deletions src/main/scala/de/dnpm/dip/model/GeneAlterationReference.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package de.dnpm.dip.model


import de.dnpm.dip.coding.Coding
import de.dnpm.dip.coding.hgnc.HGNC
import play.api.libs.json.{
Json,
Reads,
OWrites
}

/*
* Conceptually equivalent to FHIR "CodeableReference", to specify the
* (clinically) relevant gene in a variant supporting a recommendation
*
* Gene is kept optional because in SNVs it is already implicitly defined,
* and thus needn't be specified again, but for CNVs or Fusions, which can
* affect multiple or 2 genes, respectively,
* it should be specified to remove ambiguity
*
*/

final case class GeneAlterationReference[+Variant]
(
gene: Option[Coding[HGNC]],
variant: Reference[Variant],
display: Option[String]
)

object GeneAlterationReference
{

def apply[T <: { def id: Id[T] }](
gene: Option[Coding[HGNC]],
variant: T
): GeneAlterationReference[T] =
GeneAlterationReference(
gene,
Reference.to(variant),
None
)


implicit def reads[T]: Reads[GeneAlterationReference[T]] =
Json.reads[GeneAlterationReference[T]]
// For (temporary) backward compatibility, fall back to parsing as a normal reference
.orElse(
Reads.of[Reference[T]].map(GeneAlterationReference(None,_,None))
)

implicit def writes[T: Reference.TypeName]: OWrites[GeneAlterationReference[T]] =
Json.writes[GeneAlterationReference[T]]

}
4 changes: 2 additions & 2 deletions src/main/scala/de/dnpm/dip/model/Recommendation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ trait Recommendation
val id: Id[Recommendation]
val patient: Reference[Patient]
val issuedOn: LocalDate
val supportingVariants: Option[List[Reference[_]]]
// val supportingAlterations: Option[List[GeneAlterationReference[_]]]
// val supportingVariants: Option[List[Reference[_]]]
val supportingVariants: Option[List[GeneAlterationReference[_]]]
}


Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/de/dnpm/dip/model/json/BaseSchemas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import de.dnpm.dip.coding.{
Code,
Coding,
}
import de.dnpm.dip.coding.hgnc.HGNC
import de.dnpm.dip.model.{
Age,
ExternalId,
Expand All @@ -27,6 +28,7 @@ import de.dnpm.dip.model.{
PubMed,
OpenEndPeriod,
Reference,
GeneAlterationReference,
UnitOfTime
}
import shapeless.{
Expand Down Expand Up @@ -86,6 +88,14 @@ trait BaseSchemas
.toDefinition("Reference")


implicit def geneAlterationReferenceSchema[T]: Schema[GeneAlterationReference[T]] =
Schema.`object`[GeneAlterationReference[T]](
Field("gene",Json.schema[Coding[HGNC]],false),
Field("variant",Json.schema[Reference[T]],true)
)
.toDefinition("GeneAlterationReference")


implicit val publicationReferenceSchema: Schema[Reference[Publication]] =
Schema.`object`[Reference[Publication]](
Field(
Expand Down
2 changes: 0 additions & 2 deletions src/test/scala/de/dnpm/dip/coding/CodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package de.dnpm.dip.coding

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers._
import org.scalatest.Inspectors._
import de.dnpm.dip.coding.icd.ICD10GM


sealed trait Dummy
Expand Down
2 changes: 0 additions & 2 deletions src/test/scala/de/dnpm/dip/model/CompleterTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import org.scalatest.matchers.must.Matchers._
import de.dnpm.dip.util.Completer
import de.dnpm.dip.coding.Coding
import java.time.LocalDate
import java.util.UUID.randomUUID



class CompleterTests extends AnyFlatSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ package de.dnpm.dip.model
import scala.util.chaining._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers._
import play.api.libs.json.{
Json,
JsError,
JsSuccess
}
import play.api.libs.json.Json
import de.dnpm.dip.coding.Coding


Expand Down
10 changes: 0 additions & 10 deletions src/test/scala/de/dnpm/dip/model/ValueSetTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import java.net.URI
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers._
import de.dnpm.dip.coding.{
Coding,
CodeSystem,
CodeSystems,
ValueSet
}
Expand Down Expand Up @@ -39,14 +37,6 @@ class ValueSetTests extends AnyFlatSpec
CodeSystems[Systems].values.values.flatMap(_.concepts).size
)

/*
val valueSet =
composer.expand[(VitalStatus.Value,Gender.Value)]
valueSet.codings.size must equal (
CodeSystems[(VitalStatus.Value,Gender.Value)].values.flatMap(_.concepts).size
)
*/
}


Expand Down

0 comments on commit a067fb3

Please sign in to comment.