Skip to content

Commit f8ae105

Browse files
committed
some fixes against study idmap test case
1 parent 85a8e1b commit f8ae105

4 files changed

Lines changed: 40 additions & 18 deletions

File tree

src/Json/IDTable.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ module IDTable =
1212

1313
type IDTableRead = Dictionary<URI,obj>
1414

15+
let encodeID id =
16+
["@id",Encode.string id]
17+
|> Encode.object
18+
1519
let encode (genID: 'Value -> URI) (encoder : 'Value -> Json) (value : 'Value) (table:IDTableWrite) =
16-
match table.TryGetValue(genID value) with
17-
| true, v -> v
18-
| false, _ ->
20+
let id = genID value
21+
if table.ContainsKey id then
22+
encodeID id
23+
else
1924
let v = encoder value
2025
table.Add(genID value, v)
21-
v
26+
v

src/Json/OntologyAnnotation.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module AnnotationValue =
2222

2323
module OntologyAnnotation =
2424

25-
let encoder (oa : OntologyAnnotation) =
25+
let encoder (oa : OntologyAnnotation) =
2626
[
2727
Encode.tryInclude "annotationValue" Encode.string (oa.Name)
2828
Encode.tryInclude "termSource" Encode.string (oa.TermSourceREF)
@@ -127,12 +127,18 @@ module OntologyAnnotation =
127127

128128
let encoder (idMap : IDTable.IDTableWrite option) (oa : OntologyAnnotation) =
129129
let f = fun (oa : OntologyAnnotation) ->
130+
let comments =
131+
oa.Comments
132+
|> Seq.filter (fun c ->
133+
match c.Name with
134+
| Some n when n = Process.ColumnIndex.orderName -> false
135+
| _ -> true)
130136
[
131137
Encode.tryInclude "@id" Encode.string (ROCrate.genID oa |> Some)
132138
Encode.tryInclude "annotationValue" Encode.string (oa.Name)
133139
Encode.tryInclude "termSource" Encode.string (oa.TermSourceREF)
134140
Encode.tryInclude "termAccession" Encode.string (oa.TermAccessionNumber)
135-
Encode.tryIncludeSeq "comments" Comment.encoder (oa.Comments)
141+
Encode.tryIncludeSeq "comments" Comment.encoder comments
136142
]
137143
|> Encode.choose
138144
|> Encode.object

src/Json/Process/PropertyValue.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ module PropertyValue =
1212
module ROCrate =
1313

1414
let genID (p : IPropertyValue<'T>) =
15-
match p.GetCategory() with
16-
| Some t -> $"{p.GetAdditionalType()}/{OntologyAnnotation.ROCrate.genID t}{p.GetValue()}{p.GetUnit()}"
17-
| None -> $"#Empty{p.GetAdditionalType()}"
15+
match p.GetCategory(),p.GetValue(),p.GetUnit() with
16+
| Some t, Some v, Some u -> $"#{p.GetAdditionalType()}/{t.NameText}={v.Text}{u.NameText}"
17+
| Some t, Some v, None-> $"#{p.GetAdditionalType()}/{t.NameText}={v.Text}"
18+
| _ -> $"#Empty{p.GetAdditionalType()}"
1819

1920
let encoder<'T> (pv : IPropertyValue<'T>) =
2021
let categoryName, categoryURL =

src/Json/Study.fs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,20 @@ module Study =
186186
n.Add(assay)
187187
n
188188
let processes = study.GetProcesses()
189-
let protocols = ProcessSequence.getProtocols processes
190-
let factors = ProcessSequence.getFactors processes
191-
let characteristics = ProcessSequence.getCharacteristics processes
192-
let units = ProcessSequence.getUnits processes
189+
let encodedUnits =
190+
ProcessSequence.getUnits processes
191+
|> Encode.tryIncludeList "unitCategories" (OntologyAnnotation.ISAJson.encoder idMap)
192+
let encodedFactors =
193+
ProcessSequence.getFactors processes
194+
|> Encode.tryIncludeList "factors" (Factor.ISAJson.encoder idMap)
195+
let encodedCharacteristics =
196+
ProcessSequence.getCharacteristics processes
197+
|> Encode.tryIncludeList "characteristicCategories" (MaterialAttribute.ISAJson.encoder idMap)
198+
let encodedMaterials =
199+
Encode.tryInclude "materials" (StudyMaterials.ISAJson.encoder idMap) (Option.fromValueWithDefault [] processes)
200+
let encodedProtocols =
201+
ProcessSequence.getProtocols processes
202+
|> Encode.tryIncludeList "protocols" (Protocol.ISAJson.encoder (Some s.Identifier) None None idMap)
193203
[
194204
"@id", Encode.string (study |> ROCrate.genID)
195205
"filename", Encode.string fileName
@@ -201,13 +211,13 @@ module Study =
201211
Encode.tryIncludeSeq "publications" (Publication.ISAJson.encoder idMap) study.Publications
202212
Encode.tryIncludeSeq "people" (Person.ISAJson.encoder idMap) study.Contacts
203213
Encode.tryIncludeSeq "studyDesignDescriptors" (OntologyAnnotation.ISAJson.encoder idMap) study.StudyDesignDescriptors
204-
Encode.tryIncludeList "protocols" (Protocol.ISAJson.encoder (Some s.Identifier) None None idMap) protocols
205-
Encode.tryInclude "materials" (StudyMaterials.ISAJson.encoder idMap) (Option.fromValueWithDefault [] processes)
206-
Encode.tryIncludeList "factors" (Factor.ISAJson.encoder idMap) factors
207-
Encode.tryIncludeList "characteristicCategories" (MaterialAttribute.ISAJson.encoder idMap) characteristics
208-
Encode.tryIncludeList "unitCategories" (OntologyAnnotation.ISAJson.encoder idMap) units
214+
encodedProtocols
215+
encodedMaterials
209216
Encode.tryIncludeList "processSequence" (Process.ISAJson.encoder (Some s.Identifier) None idMap) processes
210217
Encode.tryIncludeSeq "assays" (Assay.ISAJson.encoder (Some s.Identifier) idMap) assays
218+
encodedFactors
219+
encodedCharacteristics
220+
encodedUnits
211221
Encode.tryIncludeSeq "comments" (Comment.ISAJson.encoder idMap) study.Comments
212222
]
213223
|> Encode.choose

0 commit comments

Comments
 (0)