Scala  Domain  Modeling   and  Architecture  

Experience  Report   Hossam  Karim  

.

.

for {! ! locus ← Chromosome ⤞ Gene ⤞ Locus! if Locus ∈ range! ! ! path ← locus ⤞ Sequence ⤞ nucleotide! if nucleotide alignment (_ > 89)! } yield path! .

.

.

.

nucleotide.giNumber === _ } yield query      ! .nucleotide if meta.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.Sequence ⤞ meta.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.

giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.nucleotide.Sequence ⤞ meta.giNumber === _ } yield query      ! .nucleotide if meta.

inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.Sequence ⤞ meta.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.nucleotide.giNumber === _ } yield query      ! .nucleotide if meta.

Sequence ⤞ meta.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.giNumber === _ } yield query      ! .nucleotide.nucleotide if meta.

nucleotide if meta.nucleotide.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.giNumber === _ } yield query      ! .giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.Sequence ⤞ meta.

H]   }     . headers: H): Message[A. H] {   val body: Validation[H. H: Monoid](   body: Validation[H.trait Message[A. Option[A]]   val headers: H   }         trait MessageBuilder {   def build[A. Option[A]].

H] {   val body: Validation[H.trait Message[A. Option[A]]. H: Monoid](   body: Validation[H. H]   }     . Option[A]]   val headers: H   }         trait MessageBuilder {   def build[A. headers: H): Message[A.

. B]! (a: Message[A.!   def bind[A. ! monoid: Monoid[H]) =!   new Monad[({type λ[α] = Message[α. H]})#λ] {     def pure[A](a: => A): Message[A. H] = . H] = . H]. ! f: (A) => Message[B.implicit def m2m[H]! (implicit builder: MessageBuilder. H]): Message[B. . . .   }   .

build[A.def pure[A](a: => A) = ! builder. H](Success(Option(a)). ∅[H])     .

headers |+| mb.headers) . ! f: (A) => Message[B. H] = m. H](mb. H](! Success(Option.def bind[A.empty[B]).body match { case Success(Some(value)) case Success(None) builder. B](! m: Message[A. ∅[H]) case Failure(a) ⇒! builder. H](! Failure(a).build[B. m.body.build[B. H].build[B. ∅[H] |+| a)   ⇒ f(value) ⇒!     }   }!       builder. H] = {!   val mb: Message[B. H]): Message[B.

List. headers) }         ! implicit object DiagnosisMessageBuilder extends! MessageBuilder { def build[A.empty[Header])     . H: Monoid](! body: Validation[H. headers: H) = DiagnosisMessage(body. headers) }                 def body[A](value: A)(implicit builder: MessageBuilder) :! Message[A. Option[A]].implicit object BasicMessageBuilder extends MessageBuilder { def build[A. H: Monoid](! body: Validation[H. headers: H) = BasicMessage(body. HL] = builder. Option[A]].build(Success(Some(value)).

uuid! ) yield e } >>= search       .Gene._! //import Transactional._! //import Diagnosis._! ! gene map { for (! e ← meta.Gene ! if meta.import Basic.Chromosome ⤞ meta.uuid === _.

uuid   if meta. "application/vnd.0">.(genex <**> geney) (_ ++ _) >>=   header("media-type".uuid === _.uuid   } yield e   } >>= search     .Gene.x.gene+json") >>=   json           for {   m ← body(<gene xmlns="urn:model:gene:1.Gene.Gene ⤞ meta.</gene>)   gene ← xml(m)   } yield gene           gene map {   for {   e ← meta...

import scalaz._! import Scalaz._! // profit!! .

.

.

.

trait Resource {! val name: String! } !     trait Ontology extends Resource {! val nestingOntology: Option[Ontology]! val nestedOntology: List[Ontology]! val ownedType: List[Type]! val ownedRelation: List[Relation]! }!   .

trait GraphResource {   this: Resource =>   }     trait GraphVertex extends GraphResource {   this: Entity =>   val graphFeatures: List[PrimitiveFeature]   val master: Boolean   val rootToMasterEdge: GraphEdge with Relation   val masterToSelf: Option[GraphEdge with Relation] = None   }     trait GraphEdge extends GraphResource {   this: Relation =>   }     .

String]   }   .trait RelationalResource {   this: Resource =>   }     trait NamedRelationalResource this: Resource =>   val relationalName: String   }   extends RelationalResource {         trait RelationalEntity extends NamedRelationalResource {   this: Entity =>   }   trait RelationalCompositeFeature extends RelationalResource {   this: CompositeFeature =>   val mapping: Map[String.

object Chromosome extends   Entity   with RelationalEntity!    with GraphVertex   with XmlElement {   self =>     sealed trait ChromosomePart {   val ownerType = self   }     // Ontology Trait   val featuringType = self   val ownedFeature = chromatine :: Nil     // XML Trait   val namespace = "urn:domain:chromosome:1.   ownerType = Chromosome.   mapping = Map. String])   }     .empty[String.0"   val prefix = "chr"     // Features   val chromatine =   new Chromatine(   name = "chromatine".

empty[GraphEdge]   }       .metamodel match {   case Some(_: XmlElement) ⇒ body(XmlModel[A](model))   case _ ⇒ fail[XmlModel[A]]! ("No XmlElement meta-model definition could be found")   }   def ingoingEdges[A <: DomainModel] =   (model: A) ⇒ model.implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.edges.typeOf(model)   }   def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.filter(_.target == vertex)   case _ ⇒ List.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.

typeOf(model)   }   def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.target == vertex)   case _ ⇒ List.edges.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.filter(_.metamodel match {   case Some(_: XmlElement) ⇒ body(XmlModel[A](model))   case _ ⇒ fail[XmlModel[A]]! ("No XmlElement meta-model definition could be found")   }   def ingoingEdges[A <: DomainModel] =   (model: A) ⇒ model.empty[GraphEdge]   }       .implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.

trait Type extends Resource   trait SimpleType extends Type   trait Entity extends Type! !   trait Relation extends Type   trait trait trait trait trait   trait trait trait     Feature[+T <: Type] extends Resource   SimpleFeature[+T <: SimpleType] extends Feature[T]   PrimitiveFeature extends SimpleFeature[Primitive]   EnumerationFeature extends SimpleFeature[Enumeration]   CompositeFeature extends SimpleFeature[Composite]   Primitive extends SimpleType   Enumeration extends SimpleType   Composite extends SimpleType   .

_   dao list (Locus.trait PrimitiveLogic {   val resource: Primitive         def ===[A](value: Primitive[A]): Operator = .locusUUID in list)       dao find (Locus. .   }         def find(operator: Operator): Option[T]   def list(operator: Operator): List[T]!         import PrimitiveLogic.              def in[A](values: PrimitiveList[A]): Operator = . . . .locusUUID === uuid)       .

nucleotide ⤞   Sequence.accession.typeOfGene where (_ !== y)     ._   val path =   Sequence.accessionNumber !== x     import GraphOps._   val validation =   Sequence.import Logic.protein ⤞   Locus.nucleotide.

for {! ! locus ← Chromosome ⤞ Gene ⤞ Locus! if Locus ∈ range! ! ! path ← locus ⤞ Sequence ⤞ nucleotide! if nucleotide alignment (_ > 89)! } yield path! .

.

PSM] {         def query(pim: PIM): List[Query]   def view(query: Query): View   def transform(view: View): PSM   }     .trait Qvt[PIM. Query. View.

  }   .   filter(graphProfile.   }   .graphPredicate)   }   def transform(view: Package) = graph(view)   def graph(element: Package): GraphOntology = {   .getNestedPackages).   .. Package..class GraphSimpleQvt(   ontologyProfile: OntologyProfile. GraphOntology] {         def query(pim: Model) = {   walk[Package](pim)(_.   graphProfile: GraphProfile)   extends SimpleQvt[Model.   .

toList   children ++ ! (children.flatMap(walk(_. f)))   }   .def walk[A]   (element: A)   (f: A => Iterable[A]): List[A] = {   val children = f(element).

map(_.reverse   .iterate(element)(_.takeWhile(!_.getNestingPackage)   .mkString(".scala rocks !!   .getName)   .def packageName(element: Package): String =   Stream! .isInstanceOf[Model])   .") //.

.

Thank  You   .