Skip to content

Commit e8a74ff

Browse files
committed
Implement run and workflow json methods
1 parent 70cdacf commit e8a74ff

15 files changed

Lines changed: 347 additions & 9 deletions

src/ARCtrl/ARCtrl.Javascript.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<Compile Include="JsonIO\Comment.fs" />
1717
<Compile Include="JsonIO\OntologyAnnotation.fs" />
1818
<Compile Include="JsonIO\OntologySourceReference.fs" />
19+
<Compile Include="JsonIO\Run.fs" />
20+
<Compile Include="JsonIO\Workflow.fs" />
1921
<Compile Include="JsonIO\DataFile.fs" />
2022
<Compile Include="JsonIO\Data.fs" />
2123
<Compile Include="JsonIO\Datamap.fs" />

src/ARCtrl/ARCtrl.Python.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<Compile Include="JsonIO\Comment.fs" />
1919
<Compile Include="JsonIO\OntologyAnnotation.fs" />
2020
<Compile Include="JsonIO\OntologySourceReference.fs" />
21+
<Compile Include="JsonIO\Run.fs" />
22+
<Compile Include="JsonIO\Workflow.fs" />
2123
<Compile Include="JsonIO\DataFile.fs" />
2224
<Compile Include="JsonIO\Data.fs" />
2325
<Compile Include="JsonIO\Datamap.fs" />

src/ARCtrl/ARCtrl.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
<Compile Include="JsonIO\Assay.fs" />
4848
<Compile Include="JsonIO\Study.fs" />
4949
<Compile Include="JsonIO\Investigation.fs" />
50+
<Compile Include="JsonIO\Run.fs" />
51+
<Compile Include="JsonIO\Workflow.fs" />
5052
<Compile Include="JsonIO\Datamap.fs" />
5153
<Compile Include="JsonIO\LDObject.fs" />
5254
<Compile Include="Conversion.fs" />

src/ARCtrl/JsonIO/Assay.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ open ARCtrl.Helper
66
[<AutoOpen>]
77
module AssayExtensions =
88

9-
open System.Collections.Generic
10-
119
type ArcAssay with
1210

1311
static member fromJsonString (s:string) =

src/ARCtrl/JsonIO/Run.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ARCtrl.Json
2+
3+
open ARCtrl
4+
open ARCtrl.Helper
5+
6+
[<AutoOpen>]
7+
module RunExtensions =
8+
9+
type ArcRun with
10+
11+
static member fromJsonString (s:string) =
12+
Decode.fromJsonString Run.decoder s
13+
14+
static member toJsonString(?spaces) =
15+
fun (obj:ArcRun) ->
16+
Run.encoder obj
17+
|> Encode.toJsonString (Encode.defaultSpaces spaces)
18+
19+
member this.ToJsonString(?spaces) =
20+
ArcRun.toJsonString(?spaces=spaces) this

src/ARCtrl/JsonIO/Workflow.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ARCtrl.Json
2+
3+
open ARCtrl
4+
open ARCtrl.Helper
5+
6+
[<AutoOpen>]
7+
module WorkflowExtensions =
8+
9+
type ArcWorkflow with
10+
11+
static member fromJsonString (s:string) =
12+
Decode.fromJsonString Workflow.decoder s
13+
14+
static member toJsonString(?spaces) =
15+
fun (obj:ArcWorkflow) ->
16+
Workflow.encoder obj
17+
|> Encode.toJsonString (Encode.defaultSpaces spaces)
18+
19+
member this.ToJsonString(?spaces) =
20+
ArcWorkflow.toJsonString(?spaces=spaces) this

src/Core/IdentifierSetters.fs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ARCtrl.IdentifierSetters
1+
module ARCtrl.IdentifierSetters
22

33
open ARCtrl.Helper
44
open Identifier
@@ -23,3 +23,13 @@ let setInvestigationIdentifier (newIdentifier: string) (investigation: ArcInvest
2323
checkValidCharacters newIdentifier
2424
investigation.Identifier <- newIdentifier
2525
investigation
26+
27+
let setRunIdentifier (newIdentifier: string) (run: ArcRun) =
28+
checkValidCharacters newIdentifier
29+
run.Identifier <- newIdentifier
30+
run
31+
32+
let setWorkflowIdentifier (newIdentifier: string) (workflow: ArcWorkflow) =
33+
checkValidCharacters newIdentifier
34+
workflow.Identifier <- newIdentifier
35+
workflow

src/Json/ARCtrl.Json.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
<Compile Include="Assay.fs" />
8181
<Compile Include="Study.fs" />
8282
<Compile Include="Investigation.fs" />
83+
<Compile Include="Run.fs" />
84+
<Compile Include="Workflow.fs" />
8385
</ItemGroup>
8486
<ItemGroup>
8587
<PackageReference Include="Thoth.Json.Core" />

src/Json/Assay.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ module Assay =
1919
Encode.tryInclude "TechnologyPlatform" OntologyAnnotation.encoder assay.TechnologyPlatform
2020
Encode.tryInclude "DataMap" DataMap.encoder assay.DataMap
2121
Encode.tryIncludeSeq "Tables" ArcTable.encoder assay.Tables
22-
Encode.tryIncludeSeq "Performers" Person.encoder assay.Performers
23-
Encode.tryIncludeSeq "Comments" Comment.encoder assay.Comments
22+
Encode.tryIncludeSeq "Performers" Person.encoder assay.Performers
23+
Encode.tryIncludeSeq "Comments" Comment.encoder assay.Comments
2424
]
2525
|> Encode.choose
2626
|> Encode.object
@@ -86,7 +86,7 @@ module Assay =
8686
let identifier = i.Replace(" ","_")
8787
$"assays/{identifier}/"
8888

89-
let encoder (studyName:string Option) (a : ArcAssay) =
89+
let encoder (assayName:string Option) (a : ArcAssay) =
9090
let fileName = Identifier.Assay.fileNameFromIdentifier a.Identifier
9191
let processes = a.GetProcesses()
9292
let dataFiles = ProcessSequence.getData processes
@@ -104,7 +104,7 @@ module Assay =
104104
Encode.tryInclude "technologyPlatform" OntologyAnnotation.ROCrate.encoderDefinedTerm a.TechnologyPlatform
105105
Encode.tryIncludeSeq "performers" Person.ROCrate.encoder a.Performers
106106
Encode.tryIncludeList "dataFiles" Data.ROCrate.encoder dataFiles
107-
Encode.tryIncludeList "processSequence" (Process.ROCrate.encoder studyName (Some a.Identifier)) processes
107+
Encode.tryIncludeList "processSequence" (Process.ROCrate.encoder assayName (Some a.Identifier)) processes
108108
Encode.tryIncludeSeq "comments" Comment.ROCrate.encoder a.Comments
109109
"@context", ROCrateContext.Assay.context_jsonvalue |> Some
110110
]

src/Json/Run.fs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace ARCtrl.Json
2+
3+
open Thoth.Json.Core
4+
5+
open ARCtrl
6+
open ARCtrl.Process
7+
open ARCtrl.Helper
8+
open Conversion
9+
10+
module Run =
11+
12+
let rec encoder (run: ArcRun) =
13+
[
14+
"Identifier", Encode.string run.Identifier |> Some
15+
Encode.tryInclude "Title" Encode.string run.Title
16+
Encode.tryInclude "Description" Encode.string run.Description
17+
Encode.tryInclude "MeasurementType" OntologyAnnotation.encoder run.MeasurementType
18+
Encode.tryInclude "TechnologyType" OntologyAnnotation.encoder run.TechnologyType
19+
Encode.tryInclude "TechnologyPlatform" OntologyAnnotation.encoder run.TechnologyPlatform
20+
Encode.tryInclude "DataMap" DataMap.encoder run.DataMap
21+
Encode.tryIncludeSeq "WorkflowIdentifiers" Encode.string run.WorkflowIdentifiers
22+
Encode.tryIncludeSeq "Tables" ArcTable.encoder run.Tables
23+
Encode.tryIncludeSeq "Performers" Person.encoder run.Performers
24+
Encode.tryIncludeSeq "Comments" Comment.encoder run.Comments
25+
]
26+
|> Encode.choose
27+
|> Encode.object
28+
29+
let decoder: Decoder<ArcRun> =
30+
Decode.object (fun get ->
31+
ArcRun.create(
32+
get.Required.Field("Identifier") Decode.string,
33+
?title = get.Optional.Field "Title" Decode.string,
34+
?description = get.Optional.Field "Description" Decode.string,
35+
?measurementType = get.Optional.Field "MeasurementType" OntologyAnnotation.decoder,
36+
?technologyType = get.Optional.Field "TechnologyType" OntologyAnnotation.decoder,
37+
?technologyPlatform = get.Optional.Field "TechnologyPlatform" OntologyAnnotation.decoder,
38+
?workflowIdentifiers = get.Optional.Field "WorkflowIdentifiers" (Decode.resizeArray Decode.string),
39+
?tables = get.Optional.Field "Tables" (Decode.resizeArray ArcTable.decoder),
40+
?datamap = get.Optional.Field "DataMap" DataMap.decoder,
41+
?performers = get.Optional.Field "Performers" (Decode.resizeArray Person.decoder),
42+
?comments = get.Optional.Field "Comments" (Decode.resizeArray Comment.decoder)
43+
)
44+
)

0 commit comments

Comments
 (0)