Skip to content

Commit

Permalink
new ro-crate export and context files
Browse files Browse the repository at this point in the history
  • Loading branch information
floWetzels authored and HLWeil committed Mar 21, 2024
1 parent 0fb24ee commit 9b0d7b7
Show file tree
Hide file tree
Showing 36 changed files with 349 additions and 331 deletions.
4 changes: 2 additions & 2 deletions src/ISA/ISA.Json/ArcTypes/ArcAssay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ module ArcAssay =

/// exports in json-ld format
let toJsonldString (a:ArcAssay) =
Assay.encoder (ConverterOptions(SetID=true,IncludeType=true)) None (a.ToAssay())
Assay.encoder (ConverterOptions(SetID=true,IsJsonLD=true)) None (a.ToAssay())
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:ArcAssay) =
Assay.encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) None (a.ToAssay())
Assay.encoder (ConverterOptions(SetID=true,IsJsonLD=true)) None (a.ToAssay())
|> GEncode.toJsonString 2

let fromJsonString (s:string) =
Expand Down
4 changes: 2 additions & 2 deletions src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ module ArcInvestigation =

/// exports in json-ld format
let toJsonldString (a:ArcInvestigation) =
Investigation.encoder (ConverterOptions(SetID=true,IncludeType=true)) (a.ToInvestigation())
Investigation.encoder (ConverterOptions(SetID=true,IsJsonLD=true)) (a.ToInvestigation())
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:ArcInvestigation) =
Investigation.encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) (a.ToInvestigation())
Investigation.encoder (ConverterOptions(SetID=true,IsJsonLD=true)) (a.ToInvestigation())
|> GEncode.toJsonString 2

let fromJsonString (s:string) =
Expand Down
4 changes: 2 additions & 2 deletions src/ISA/ISA.Json/ArcTypes/ArcStudy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ module ArcStudy =

/// exports in json-ld format
let toJsonldString (a:ArcStudy) (assays: ResizeArray<ArcAssay>) =
Study.encoder (ConverterOptions(SetID=true,IncludeType=true)) (a.ToStudy(assays))
Study.encoder (ConverterOptions(SetID=true,IsJsonLD=true)) (a.ToStudy(assays))
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:ArcStudy) (assays: ResizeArray<ArcAssay>) =
Study.encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) (a.ToStudy(assays))
Study.encoder (ConverterOptions(SetID=true,IsJsonLD=true)) (a.ToStudy(assays))
|> GEncode.toJsonString 2

let fromJsonString (s:string) =
Expand Down
25 changes: 9 additions & 16 deletions src/ISA/ISA.Json/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Assay =
match a.ID with
| Some id -> URI.toString id
| None -> match a.FileName with
| Some n -> n.Replace(" ","_").Remove(0,1 + (max (n.LastIndexOf('/')) (n.LastIndexOf('\\'))))
| Some n -> n.Replace(" ","_")//.Remove(0,1 + (max (n.LastIndexOf('/')) (n.LastIndexOf('\\'))))
| None -> "#EmptyAssay"

let encoder (options : ConverterOptions) (studyName:string Option) (oa : Assay) =
Expand All @@ -42,32 +42,25 @@ module Assay =
| None -> None
with
| Failure(msg) -> None
let a = ["Assay";"ArcAssay"]
[
if options.SetID then
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [ Encode.string "Assay"; Encode.string "ArcAssay"])
if options.IsJsonLD then
"@type", (Encode.list [ Encode.string "Assay"])
GEncode.tryInclude "filename" Encode.string (oa.FileName)
GEncode.tryInclude "measurementType" (OntologyAnnotation.encoder options) (oa.MeasurementType)
GEncode.tryInclude "technologyType" (OntologyAnnotation.encoder options) (oa.TechnologyType)
GEncode.tryInclude "technologyPlatform" Encode.string (oa.TechnologyPlatform)
GEncode.tryIncludeList "dataFiles" (Data.encoder options) (oa.DataFiles)
if options.IsRoCrate then
match oa.Materials with
| Some m ->
GEncode.tryIncludeList "samples" (Sample.encoder options) m.Samples
GEncode.tryIncludeList "materials" (Material.encoder options) m.OtherMaterials
| None -> ()
if not options.IsRoCrate then
if not options.IsJsonLD then
GEncode.tryInclude "materials" (AssayMaterials.encoder options) oa.Materials
GEncode.tryIncludeList "characteristicCategories" (MaterialAttribute.encoder options) (oa.CharacteristicCategories)
GEncode.tryIncludeList "unitCategories" (OntologyAnnotation.encoder options) (oa.UnitCategories)
GEncode.tryIncludeList "characteristicCategories" (MaterialAttribute.encoder options) (oa.CharacteristicCategories)
GEncode.tryIncludeList "unitCategories" (OntologyAnnotation.encoder options) (oa.UnitCategories)
GEncode.tryIncludeList "processSequence" (Process.encoder options studyName assayName) (oa.ProcessSequence)
GEncode.tryIncludeList "comments" (Comment.encoder options) (oa.Comments)
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.Assay.context_jsonvalue
]
|> GEncode.choose
Expand Down Expand Up @@ -101,11 +94,11 @@ module Assay =

/// exports in json-ld format
let toJsonldString (a:Assay) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) None a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) None a
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Assay) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) None a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) None a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand Down
8 changes: 4 additions & 4 deletions src/ISA/ISA.Json/Comment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ module Comment =
"@id", Encode.string (comment |> genID)
else
GEncode.tryInclude "@id" Encode.string (comment.ID)
if options.IncludeType then
if options.IsJsonLD then
"@type", Encode.string "Comment"
GEncode.tryInclude "name" Encode.string (comment.Name)
GEncode.tryInclude "value" Encode.string (comment.Value)
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.Comment.context_jsonvalue
]
|> GEncode.choose
Expand All @@ -53,11 +53,11 @@ module Comment =

/// exports in json-ld format
let toJsonldString (c:Comment) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) c
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) c
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Comment) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand Down
12 changes: 3 additions & 9 deletions src/ISA/ISA.Json/ConverterOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
type ConverterOptions() =

let mutable setID = false
let mutable includeType = false
let mutable includeContext = false
let mutable isRoCrate = false
let mutable isJsonLD = false

member this.SetID with get() = setID
and set(setId) = setID <- setId
member this.IncludeType with get() = includeType
and set(iT) = includeType <- iT
member this.IncludeContext with get() = includeContext
and set(iC) = includeContext <- iC
member this.IsRoCrate with get() = isRoCrate
and set(iR) = isRoCrate <- iR
member this.IsJsonLD with get() = isJsonLD
and set(iJ) = isJsonLD <- iJ
33 changes: 17 additions & 16 deletions src/ISA/ISA.Json/Data.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ module Data =
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [Encode.string "Data"; Encode.string "ArcData"])
if options.IsJsonLD then
"@type", (Encode.list [Encode.string "Data"])
GEncode.tryInclude "name" Encode.string (oa.Name)
GEncode.tryInclude "type" (DataFile.encoder options) (oa.DataType)
GEncode.tryIncludeList "comments" (Comment.encoder options) (oa.Comments)
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.Data.context_jsonvalue
]
|> GEncode.choose
Expand Down Expand Up @@ -78,10 +78,10 @@ module Data =

/// exports in json-ld format
let toJsonldString (d:Data) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) d
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) d
|> GEncode.toJsonString 2
let toJsonldStringWithContext (a:Data) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand All @@ -107,11 +107,11 @@ module Source =
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [ Encode.string "Source"; Encode.string "ArcSource"])
if options.IsJsonLD then
"@type", (Encode.list [ Encode.string "Source"])
GEncode.tryInclude "name" Encode.string (oa.Name)
GEncode.tryIncludeList "characteristics" (MaterialAttributeValue.encoder options) (oa.Characteristics)
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.Source.context_jsonvalue
]
|> GEncode.choose
Expand Down Expand Up @@ -139,11 +139,11 @@ module Source =

/// exports in json-ld format
let toJsonldString (s:Source) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) s
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) s
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Source) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand All @@ -168,13 +168,14 @@ module Sample =
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [ Encode.string "Sample"; Encode.string "ArcSample"])
if options.IsJsonLD then
"@type", (Encode.list [ Encode.string "Sample"])
GEncode.tryInclude "name" Encode.string (oa.Name)
GEncode.tryIncludeList "characteristics" (MaterialAttributeValue.encoder options) (oa.Characteristics)
GEncode.tryIncludeList "factorValues" (FactorValue.encoder options) (oa.FactorValues)
GEncode.tryIncludeList "derivesFrom" (Source.encoder options) (oa.DerivesFrom)
if options.IncludeContext then
if not options.IsJsonLD then
GEncode.tryIncludeList "derivesFrom" (Source.encoder options) (oa.DerivesFrom)
if options.IsJsonLD then
"@context", ROCrateContext.Sample.context_jsonvalue
]
|> GEncode.choose
Expand Down Expand Up @@ -203,11 +204,11 @@ module Sample =

/// exports in json-ld format
let toJsonldString (s:Sample) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) s
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) s
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Sample) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand Down
47 changes: 33 additions & 14 deletions src/ISA/ISA.Json/Factor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ module Factor =
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [Encode.string "Factor"; Encode.string "ArcFactor"])
if options.IsJsonLD then
"@type", (Encode.list [Encode.string "Factor"])
GEncode.tryInclude "factorName" Encode.string (oa.Name)
GEncode.tryInclude "factorType" (OntologyAnnotation.encoder options) (oa.FactorType)
if options.IsJsonLD then
if oa.FactorType.IsSome then
GEncode.tryInclude "annotationValue" Encode.string (oa.Name)
GEncode.tryInclude "termSource" Encode.string (oa.FactorType.Value.TermSourceREF)
GEncode.tryInclude "termAccession" Encode.string (oa.FactorType.Value.TermAccessionNumber)
else
GEncode.tryInclude "factorType" (OntologyAnnotation.encoder options) (oa.FactorType)
GEncode.tryIncludeArray "comments" (Comment.encoder options) (oa.Comments)
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.Factor.context_jsonvalue
]
|> GEncode.choose
Expand All @@ -98,11 +104,11 @@ module Factor =

/// exports in json-ld format
let toJsonldString (f:Factor) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) f
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) f
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Factor) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand All @@ -126,12 +132,25 @@ module FactorValue =
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [Encode.string "FactorValue"; Encode.string "ArcFactorValue"])
GEncode.tryInclude "category" (Factor.encoder options) (oa.Category)
GEncode.tryInclude "value" (Value.encoder options) (oa.Value)
GEncode.tryInclude "unit" (OntologyAnnotation.encoder options) (oa.Unit)
if options.IncludeContext then
if options.IsJsonLD then
"@type", (Encode.list [Encode.string "FactorValue"])
if options.IsJsonLD then
if oa.Category.IsSome then
GEncode.tryInclude "categoryName" Encode.string (oa.Category.Value.Name)
if oa.Category.IsSome && oa.Category.Value.FactorType.IsSome then
GEncode.tryInclude "category" Encode.string (oa.Category.Value.FactorType.Value.Name)
if oa.Category.IsSome && oa.Category.Value.FactorType.IsSome then
GEncode.tryInclude "categoryCode" Encode.string (oa.Category.Value.FactorType.Value.TermAccessionNumber)
if oa.Value.IsSome then "value", Encode.string (oa.ValueText)
if oa.Value.IsSome && oa.Value.Value.IsAnOntology then
GEncode.tryInclude "valueCode" Encode.string (oa.Value.Value.AsOntology()).TermAccessionNumber
if oa.Unit.IsSome then GEncode.tryInclude "unit" Encode.string (oa.Unit.Value.Name)
if oa.Unit.IsSome then GEncode.tryInclude "unitCode" Encode.string (oa.Unit.Value.TermAccessionNumber)
else
GEncode.tryInclude "category" (Factor.encoder options) (oa.Category)
GEncode.tryInclude "value" (Value.encoder options) (oa.Value)
GEncode.tryInclude "unit" (OntologyAnnotation.encoder options) (oa.Unit)
if options.IsJsonLD then
"@context", ROCrateContext.FactorValue.context_jsonvalue
]
|> GEncode.choose
Expand All @@ -156,11 +175,11 @@ module FactorValue =

/// exports in json-ld format
let toJsonldString (f:FactorValue) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) f
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) f
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:FactorValue) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
Expand Down
15 changes: 8 additions & 7 deletions src/ISA/ISA.Json/Investigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ module Investigation =
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
if options.IsJsonLD then
"@type", Encode.string "Investigation"
GEncode.tryInclude "filename" Encode.string (oa.FileName)
GEncode.tryInclude "identifier" Encode.string (oa.Identifier)
GEncode.tryInclude "title" Encode.string (oa.Title)
GEncode.tryInclude "description" Encode.string (oa.Description)
GEncode.tryInclude "submissionDate" Encode.string (oa.SubmissionDate)
GEncode.tryInclude "publicReleaseDate" Encode.string (oa.PublicReleaseDate)
GEncode.tryIncludeList "ontologySourceReferences" (OntologySourceReference.encoder options) (oa.OntologySourceReferences)
if not options.IsJsonLD then
GEncode.tryIncludeList "ontologySourceReferences" (OntologySourceReference.encoder options) (oa.OntologySourceReferences)
GEncode.tryIncludeList "publications" (Publication.encoder options) (oa.Publications)
GEncode.tryIncludeList "people" (Person.encoder options) (oa.Contacts)
GEncode.tryIncludeList "studies" (Study.encoder options) (oa.Studies)
GEncode.tryIncludeList "comments" (Comment.encoder options) (oa.Comments)
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.Investigation.context_jsonvalue
]
|> GEncode.choose
Expand All @@ -50,7 +51,7 @@ module Investigation =
GEncode.tryInclude "@id" Encode.string (Some "ro-crate-metadata.json")
GEncode.tryInclude "about" (encoder options) (Some oa)
"conformsTo", ROCrateContext.ROCrate.conformsTo_jsonvalue
if options.IncludeContext then
if options.IsJsonLD then
"@context", ROCrateContext.ROCrate.context_jsonvalue
]
|> GEncode.choose
Expand Down Expand Up @@ -87,13 +88,13 @@ module Investigation =

/// exports in json-ld format
let toJsonldString (i:Investigation) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) i
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) i
|> GEncode.toJsonString 2

let toJsonldStringWithContext (i:Investigation) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) i
encoder (ConverterOptions(SetID=true,IsJsonLD=true)) i
|> GEncode.toJsonString 2

let toRoCrateString (i:Investigation) =
encodeRoCrate (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true,IsRoCrate=true)) i
encodeRoCrate (ConverterOptions(SetID=true,IsJsonLD=true)) i
|> GEncode.toJsonString 2
Loading

0 comments on commit 9b0d7b7

Please sign in to comment.