fmod DATUMOPS is
  inc ASSAYS .
  inc ANTIBODYOPS .
  inc STRESSOPS .
  inc GENEOPS .
  inc CONVERSION .
  inc NAT-LIST .

*** Two kinds of Datum: State-Datum Change-Datum 
***(
Dealing with optional `annotations'  -- in mutations, envts, extras ...
I've adopted the following strategy:  
  sorts Foo FooA . subsort Foo < FooA .
  op _!_ : Foo String -> FooA .

For computation we should probably normalize
and generate Foo ! "" if there is no annotation
)

  sorts Datum SDatum CDatum .
  subsort SDatum CDatum  < Datum .

*** the elements of a Datum
*** Firstline  Subject Assay Detectable/Change Stimulus
*** Environment Source Extras
*** Metadata:  DatumId RuleId

  sorts Subject Change Detectable Stimulus .
****  sort Assay ---- from ASSAYS
  sorts Environment Source Extras MetaData .

**** datum annotations -- id, rule, evidence category ...
  sorts MetaDataItem MetaDataItems .
  subsort MetaDataItem < MetaDataItems .

  op metaData : MetaDataItems -> MetaData [ctor format (nt d)] .
  op none : -> MetaDataItems [ctor] .
  op __ : MetaDataItems MetaDataItems 
            -> MetaDataItems [ctor assoc comm id: none] .

  op datumId : String -> MetaDataItem [ctor format (d ntt)] .
  op fileName : String -> MetaDataItem [ctor format (d ntt)] .
  op comment : String -> MetaDataItem [ctor format (d ntt)] .


***** Datum constructors
  op sdatum : Subject Assay Detectable 
             Environment Source Extras MetaData -> SDatum [ctor format (n d)] .
  op cdatum : Subject Assay Change Stimulus Times
              Environment Source Extras MetaData -> CDatum [ctor format (n d)] .

*** Adverb

  sort Adverb .
  ops partially slightly synergistically greatly bkg : -> Adverb [ctor] .

  op detectable-but : -> Adverb [ctor] .
  op undetectable-and : -> Adverb [ctor] .

************** subjects

  op subject : SProtein -> Subject [ctor format (nt d)] .
  op subject : Gene -> Subject [ctor format (nt d)] .
  op subject : Chemical Handle -> Subject [ctor format (nt d)] .

  op noSubject : -> Subject [ctor format (nt d)] .  ****format???

************** assays --- in ASSAYS

************** detectable / Change

  op detectable : Bool -> Detectable [ctor format (nt d)] .

*** Change--
  sort ChangeElt .
  ops increase decrease nochange : -> ChangeElt [ctor] .
  op change : ChangeElt -> Change [ctor format (nt d)] .
  op change : ChangeElt Adverb -> Change [ctor format (nt d)] .

************** Times
  sort TimeUnit .
  ops min hr sec : -> TimeUnit [ctor] .
  op days : -> TimeUnit [ctor] .
  op na : -> TimeUnit [ctor] .

*** TimePoints--
  op rat : Rat -> Rat .
  eq rat(r:Rat) = r:Rat .

  sorts TPoint TPoints  .
  subsort TPoint < TPoints .

  op nil : -> TPoints  [ctor] .
  op __ : TPoints TPoints -> TPoints [ctor assoc id: nil] .
****  op [__] : Rat Nat -> TPoint [ctor] .
  op (_`,_) : Rat Nat -> TPoint [ctor] .

  sorts Times .
  op times : TPoints TimeUnit -> Times [ctor format (nt d)]  .
  op times : TimeUnit -> Times [ctor format (nt d)]  .

  ops tnr tbg : -> Times [ctor] .

*** StimTimes--  **** use NatList .
***(
  sort Nats .  subsort Nat < Nats .
  op nil : -> Nats .
  op _`,_ : Nats Nats -> Nats [ctor assoc id: nil] .
)

  sort StimTimes .  
  ops tnr tbg : -> StimTimes .
  op (_)_ : NatList TimeUnit  -> StimTimes [ctor] .

*** Environment--   
  op environment : String -> Environment [ctor format (nt d)] .
  op environment : EnvironmentName -> Environment [ctor format (nt d)] .
  op environment : CellEnvA -> Environment [ctor format (nt d)] .

**** Source
  sorts Figure Figures .
  subsort Figure < Figures .
  op none : -> Figures [ctor] .
  op __ : Figures Figures -> Figures [ctor assoc comm id: none] .

  op Fig _ : Nat -> Figure [ctor] .
  op Fig S : -> Figure [ctor] .
  op Fig S _ : Nat -> Figure [ctor] .
  op Fig __ : Nat String -> Figure [ctor] .
  op Fig S __ : Nat String -> Figure [ctor] .
  op Fig xxx : -> Figure [ctor] .  *** a place holder for info to be fetched
  op Table_ : Nat -> Figure [ctor] .
  op Table__ : Nat String -> Figure [ctor] .
  op Table ___ : Char Nat String -> Figure [ctor] .
  
   sort SourceType .
   op pmid_(_) : Nat Figures -> SourceType [ctor] .

  op source : SourceType -> Source [ctor format (nt d)] .

************** Stimulus 
---  Stuff you can add to the outside of a cell or a testtube
--- the []s are for injection into the sum sort to avoid non-regularity whines  
***!!! inject with t
  sort Treatment . 
***(
  op _[chem] : Chemical -> Treatment [ctor] .
  op _[op] : OProtein -> Treatment [ctor] .   
  op _[ab] : Antibody -> Treatment [ctor] .
  op _[peptide] : Peptide -> Treatment [ctor] .
  op _[stress] : Stress -> Treatment [ctor] .
  op _[sp] : SProtein -> Treatment [ctor] .  
) 
 *** inject with t
  op t : Chemical -> Treatment [ctor] .
  op t : OProtein -> Treatment [ctor] .   
  op t : Antibody -> Treatment [ctor] .
  op t : Peptide -> Treatment [ctor] .
  op t : Stress -> Treatment [ctor] .
  op t : SProtein -> Treatment [ctor] .  
 
  sort Treatments . subsort Treatment < Treatments .
  op none : -> Treatments [ctor] .
  op _+_ :  Treatments Treatments -> Treatments [ctor assoc comm id: none] .


**** {subject} {assay} is {changed} irt {streatments} opt({stimes}) 
****           the opt times go in the times: field
  op irt  : Treatments -> Stimulus [ctor format (nt d)] .

**** {subject} {assay} is {changed} itpo {xtreatments} 
  op itpo  : OProteins -> Stimulus [ctor format (nt d)] . **** only XProteins

**** {subject} {assay} is {changed} by {ttreatments}
  op by  : Treatments -> Stimulus [ctor format (nt d)] .

  sort BkgAdverb .
  op no-bkg-control : -> BkgAdverb .

  sorts KTreatment KTreatments KTreatmentsA .
  subsort KTreatments < KTreatmentsA .
  op _!_ : KTreatments BkgAdverb -> KTreatmentsA [ctor] .

  sort  Ktest  .
  ops KO DKO TKO RNAi DRNAi TRNAi AntiSense fmut null-mut AS-RNA AS-DNA : -> Ktest .
  ops blocking-Ab blocking-peptide altsort : -> Ktest .
  ops HRKnockdown : -> Ktest .
  ops method-not-reported : -> Ktest .
  op omission : -> Ktest .
  op altsort : -> Ktest .

  sort noK .  
  op none : -> noK [ctor] .
  sort KTreatmentsOr . 
  subsort noK < KTreatmentsOr .
  subsort KTreatment < KTreatmentsOr .
  subsort KTreatmentsOr < KTreatments .
  op _or_ : KTreatmentsOr KTreatmentsOr -> KTreatmentsOr
              [ctor assoc comm id: none] .
***  op _or_ : noK noK -> noK [ctor ditto] .
  sort KTreatmentsAndOr . 
  subsort noK < KTreatmentsAndOr .
  subsort KTreatment < KTreatmentsAndOr .
  subsort KTreatmentsAndOr < KTreatments .
  op _and/or_ : KTreatmentsAndOr KTreatmentsAndOr -> KTreatmentsAndOr
              [ctor assoc comm id: none] .

   op _[_] : Treatment Ktest -> KTreatment [ctor] .

***(
 red t(ADP) .
 red t(UV) .
 red t(ADP) + t(UV) .
 red t(ADP) [KO] .
 red (t(ADP) [KO]) and/or (t(UV) [RNAi]) .
 red (t(ADP) [KO]) or (t(UV) [RNAi]) .
 )
  sort XTreatment .
  op _(_)[stim] : Treatments StimTimes -> XTreatment [ctor] .
  op _(_)[costim] : Treatments StimTimes -> XTreatment [ctor] .
  op _(_)[stress] : Treatments StimTimes -> XTreatment [ctor] .
  op _[cotreatment] : Treatments -> XTreatment [ctor] .
  op _(_)[pretreatment] : Treatments StimTimes -> XTreatment [ctor] .
  op _(_)[preconditioning] : Treatments StimTimes -> XTreatment [ctor] .  *** added by amk
  op _(_)[posttreatment] : Treatments StimTimes -> XTreatment [ctor] .  *** added by amk
***  op _[addition]     : Treatments -> XTreatment  [ctor] .
  op _(_)[addition]     : Treatments StimTimes -> XTreatment  [ctor] .
  op _[substitution] : AProteins -> XTreatment [ctor] .  
  op _[knockin] : OProteins -> XTreatment  [ctor] .

  sort XTreatmentA .  subsort XTreatment < XTreatmentA .
  op _!_ : XTreatment BkgAdverb -> XTreatmentA [ctor] .
  
**** Extras
  sorts Extra ExtraSet .
  subsort Extra < ExtraSet  .    ***** ExtraSet < Extras  NO
  op none : -> ExtraSet [ctor] .
  op __ : ExtraSet ExtraSet -> ExtraSet [ctor assoc comm id: none] .
  op extras : ExtraSet -> Extras [ctor format (nt d)] .

  op reqs : KTreatmentsA   -> Extra [ctor format (ntt d)] .
  op reqs : KTreatmentsA Adverb  -> Extra [ctor format (ntt d)] .   --- and/or
  op notreq : KTreatmentsA   -> Extra [ctor format (ntt d)] .   --- or

***(
{noaffect description} = 
  {extratreat} 
  | {ktreatments}(and/or) 
)
  op unaffectedBy : KTreatmentsA -> Extra [ctor format (ntt d)] .   --- and/or
  op unaffectedBy : XTreatmentA -> Extra [ctor format (ntt d)] .

***(
{repress adj} := partially
{repress description} := {ktreatment}(and/or) opt({bkgadj})
)
  op repressedBy : KTreatmentsA -> Extra [ctor format (ntt d)] .
  op repressedBy  : KTreatmentsA Adverb -> Extra [ctor format (ntt d)] .

***(
{enhance adj} := slightly 
{enhance description} := {extratreat} opt({bkgadj})
)   
  op enhancedBy  : XTreatmentA -> Extra [ctor format (ntt d)] .
  op enhancedBy  : XTreatmentA Adverb -> Extra [ctor format (ntt d)] .

***(
{inhib adj} := partially, slightly, bkg
{inhibs description} = {extratreat}  opt({bkgadj})
)
  op inhibitedBy  : XTreatmentA -> Extra [ctor format (ntt d)] .
  op inhibitedBy  : XTreatmentA Adverb -> Extra [ctor format (ntt d)] .

***(
{reverse adj} := slightly, partially
{reverse description} :=  {extratreat} | {ktreatment}(and/or) opt({bkgadj})
)
  op reversedBy : XTreatmentA -> Extra [ctor format (ntt d)] .
  op reversedBy  : XTreatmentA Adverb -> Extra [ctor format (ntt d)] .
  op reversedBy  : KTreatmentsA -> Extra [ctor format (ntt d)] .
  op reversedBy : KTreatmentsA Adverb -> Extra [ctor format (ntt d)] .

***(
{repress adj} := partially
{repress description} := {ktreatment}(and/or) opt({bkgadj})
)
  op repressedBy : KTreatmentsA -> Extra [ctor format (ntt d)] .
  op repressedBy  : KTreatmentsA Adverb -> Extra [ctor format (ntt d)] .


endfm
