Skip to content

Commit b568074

Browse files
committed
rework ARCtrl.Spreadsheet according to datamodel changes
1 parent 2cb9db8 commit b568074

20 files changed

+189
-184
lines changed

src/Spreadsheet/AnnotationTable/ArcTable.fs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
module ARCtrl.ISA.Spreadsheet.ArcTable
1+
module ARCtrl.Spreadsheet.ArcTable
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
45
open FsSpreadsheet
56

67
// I think we really should not add FSharpAux for exactly one function.
@@ -93,7 +94,7 @@ let tryFromFsWorksheet (sheet : FsWorksheet) =
9394
|> Seq.map CompositeColumn.fixDeprecatedIOHeader
9495
|> composeColumns
9596
ArcTable.init sheet.Name
96-
|> ArcTable.addColumns(compositeColumns,SkipFillMissing = true)
97+
|> ArcTable.addColumns(compositeColumns,skipFillMissing = true)
9798
|> Some
9899
| None ->
99100
None

src/Spreadsheet/AnnotationTable/CompositeCell.fs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
module ARCtrl.ISA.Spreadsheet.CompositeCell
1+
module ARCtrl.Spreadsheet.CompositeCell
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
45
open FsSpreadsheet
56

67
let fromFsCells (cells : list<FsCell>) : CompositeCell =
@@ -18,7 +19,7 @@ let toFsCells isTerm hasUnit (cell : CompositeCell) : list<FsCell> =
1819
| CompositeCell.FreeText v when isTerm -> [FsCell(v); FsCell(""); FsCell("")]
1920
| CompositeCell.FreeText v -> [FsCell(v)]
2021

21-
| CompositeCell.Term v when hasUnit -> [FsCell(v.NameText); FsCell(""); FsCell(v.TermSourceREFString); FsCell(v.TermAccessionOntobeeUrl)]
22-
| CompositeCell.Term v -> [FsCell(v.NameText); FsCell(v.TermSourceREFString); FsCell(v.TermAccessionOntobeeUrl)]
22+
| CompositeCell.Term v when hasUnit -> [FsCell(v.NameText); FsCell(""); FsCell(Option.defaultValue "" v.TermSourceREF); FsCell(v.TermAccessionOntobeeUrl)]
23+
| CompositeCell.Term v -> [FsCell(v.NameText); FsCell(Option.defaultValue "" v.TermSourceREF); FsCell(v.TermAccessionOntobeeUrl)]
2324

24-
| CompositeCell.Unitized (v,unit) -> [FsCell(v); FsCell(unit.NameText); FsCell(unit.TermSourceREFString); FsCell(unit.TermAccessionOntobeeUrl)]
25+
| CompositeCell.Unitized (v,unit) -> [FsCell(v); FsCell(unit.NameText); FsCell(Option.defaultValue "" unit.TermSourceREF); FsCell(unit.TermAccessionOntobeeUrl)]

src/Spreadsheet/AnnotationTable/CompositeColumn.fs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
module ARCtrl.ISA.Spreadsheet.CompositeColumn
1+
module ARCtrl.Spreadsheet.CompositeColumn
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
45
open FsSpreadsheet
56

67
/// Checks if the column header is a deprecated IO Header. If so, fixes it.

src/Spreadsheet/AnnotationTable/CompositeHeader.fs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
module ARCtrl.ISA.Spreadsheet.CompositeHeader
1+
module ARCtrl.Spreadsheet.CompositeHeader
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
45
open FsSpreadsheet
56

67
module ActivePattern =
78

8-
open ARCtrl.ISA.Regex.ActivePatterns
9+
open Regex.ActivePatterns
910

1011
let mergeIDInfo idSpace1 localID1 idSpace2 localID2 =
1112
if idSpace1 <> idSpace2 then failwithf "TermSourceRef %s and %s do not match" idSpace1 idSpace2
@@ -18,15 +19,15 @@ module ActivePattern =
1819
let cellValues = cells |> List.map (fun c -> c.ValueAsString())
1920
match cellValues with
2021
| [AC name] ->
21-
let ont = OntologyAnnotation.fromString(name)
22+
let ont = OntologyAnnotation.create(name)
2223
f ont
2324
|> Some
2425
| [AC name; TSRColumnHeader term1; TANColumnHeader term2]
2526
//| [AC name; TermAccessionNumber term1; TermSourceREF term2]
2627
//| [AC name; Unit; TermAccessionNumber term1; TermSourceREF term2]
2728
| [AC name; UnitColumnHeader _; TSRColumnHeader term1; TANColumnHeader term2] ->
2829
let term = mergeIDInfo term1.IDSpace term1.LocalID term2.IDSpace term2.LocalID
29-
let ont = OntologyAnnotation.fromString(name, term.TermSourceRef, term.TermAccessionNumber)
30+
let ont = OntologyAnnotation.create(name, term.TermSourceRef, term.TermAccessionNumber)
3031
f ont
3132
|> Some
3233
| _ -> None

src/Spreadsheet/ArcAssay.fs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
module ARCtrl.ISA.Spreadsheet.ArcAssay
1+
module ARCtrl.Spreadsheet.ArcAssay
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
45
open FsSpreadsheet
56

67
let [<Literal>] obsoleteAssaysLabel = "ASSAY METADATA"
@@ -20,7 +21,7 @@ let toMetadataSheet (assay : ArcAssay) : FsWorksheet =
2021
yield! Assays.toRows (Some assaysPrefix) [assay]
2122

2223
yield SparseRow.fromValues [contactsLabel]
23-
yield! Contacts.toRows (Some contactsPrefix) (List.ofArray assay.Performers)
24+
yield! Contacts.toRows (Some contactsPrefix) (List.ofSeq assay.Performers)
2425
}
2526
let sheet = FsWorksheet(metaDataSheetName)
2627
assay
@@ -54,7 +55,7 @@ let fromMetadataSheet (sheet : FsWorksheet) : ArcAssay =
5455
assays
5556
|> Seq.tryHead
5657
|> Option.defaultValue (ArcAssay.create(Identifier.createMissingIdentifier()))
57-
|> ArcAssay.setPerformers (Array.ofList contacts)
58+
|> ArcAssay.setPerformers (ResizeArray contacts)
5859

5960
if en.MoveNext () then
6061
let currentLine = en.Current |> SparseRow.tryGetValueAt 0

src/Spreadsheet/ArcInvestigation.fs

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
namespace ARCtrl.ISA.Spreadsheet
1+
namespace ARCtrl.Spreadsheet
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
45
open FsSpreadsheet
56
open Comment
67
open Remark
@@ -78,13 +79,12 @@ module ArcInvestigation =
7879
do matrix.Matrix.Add ((submissionDateLabel,i), (Option.defaultValue "" investigation.SubmissionDate))
7980
do matrix.Matrix.Add ((publicReleaseDateLabel,i), (Option.defaultValue "" investigation.PublicReleaseDate))
8081

81-
if Array.isEmpty investigation.Comments |> not then
82-
investigation.Comments
83-
|> Array.iter (fun comment ->
84-
let n,v = comment |> Comment.toString
85-
commentKeys <- n :: commentKeys
86-
matrix.Matrix.Add((n,i),v)
87-
)
82+
investigation.Comments
83+
|> ResizeArray.iter (fun comment ->
84+
let n,v = comment |> Comment.toString
85+
commentKeys <- n :: commentKeys
86+
matrix.Matrix.Add((n,i),v)
87+
)
8888

8989
{matrix with CommentKeys = commentKeys |> List.distinct |> List.rev}
9090

@@ -106,14 +106,14 @@ module ArcInvestigation =
106106
(Option.fromValueWithDefault "" investigationInfo.Description)
107107
(Option.fromValueWithDefault "" investigationInfo.SubmissionDate)
108108
(Option.fromValueWithDefault "" investigationInfo.PublicReleaseDate)
109-
(Array.ofList ontologySourceReference)
110-
(Array.ofList publications)
111-
(Array.ofList contacts)
112-
(ResizeArray(assays))
113-
(ResizeArray(studies))
114-
(ResizeArray(studyIdentifiers))
115-
(Array.ofList investigationInfo.Comments)
116-
(Array.ofList remarks)
109+
(ResizeArray ontologySourceReference)
110+
(ResizeArray publications)
111+
(ResizeArray contacts)
112+
(ResizeArray assays)
113+
(ResizeArray studies)
114+
(ResizeArray studyIdentifiers)
115+
(ResizeArray investigationInfo.Comments)
116+
(ResizeArray remarks)
117117

118118

119119
let fromRows (rows:seq<SparseRow>) =
@@ -183,24 +183,24 @@ module ArcInvestigation =
183183
with | _ -> rows |> Seq.toList
184184
seq {
185185
yield SparseRow.fromValues [ontologySourceReferenceLabel]
186-
yield! OntologySourceReference.toRows (List.ofArray investigation.OntologySourceReferences)
186+
yield! OntologySourceReference.toRows (List.ofSeq investigation.OntologySourceReferences)
187187

188188
yield SparseRow.fromValues [investigationLabel]
189189
yield! InvestigationInfo.toRows investigation
190190

191191
yield SparseRow.fromValues [publicationsLabel]
192-
yield! Publications.toRows (Some publicationsLabelPrefix) (List.ofArray investigation.Publications)
192+
yield! Publications.toRows (Some publicationsLabelPrefix) (List.ofSeq investigation.Publications)
193193

194194
yield SparseRow.fromValues [contactsLabel]
195-
yield! Contacts.toRows (Some contactsLabelPrefix) (List.ofArray investigation.Contacts)
195+
yield! Contacts.toRows (Some contactsLabelPrefix) (List.ofSeq investigation.Contacts)
196196

197197
if not isLight then
198198
for studyIdentifier in investigation.RegisteredStudyIdentifiers do
199199
let study = investigation.TryGetStudy(studyIdentifier) |> Option.defaultValue (ArcStudy(studyIdentifier))
200200
yield SparseRow.fromValues [studyLabel]
201201
yield! Studies.toRows study None
202202
}
203-
|> insertRemarks (List.ofArray investigation.Remarks)
203+
|> insertRemarks (List.ofSeq investigation.Remarks)
204204
|> seq
205205

206206
let fromFsWorkbook (doc:FsWorkbook) =

src/Spreadsheet/ArcStudy.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace ARCtrl.ISA.Spreadsheet
1+
namespace ARCtrl.Spreadsheet
22

3-
open ARCtrl.ISA
3+
open ARCtrl
44
open FsSpreadsheet
55

6-
open Aux
6+
open ARCtrl.Helper
77

88
module ArcStudy =
99

src/Spreadsheet/CollectionAux.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ARCtrl.ISA.Spreadsheet
1+
namespace ARCtrl.Spreadsheet
22

33

44
module Seq =

src/Spreadsheet/Metadata/Assays.fs

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
namespace ARCtrl.ISA.Spreadsheet
1+
namespace ARCtrl.Spreadsheet
22

3-
open ARCtrl.ISA
3+
open ARCtrl
44
open Comment
55
open Remark
66
open System.Collections.Generic
7+
open ARCtrl.Helper
8+
open ARCtrl.Process.Conversion
9+
710

811
module Assays =
912

@@ -24,15 +27,15 @@ module Assays =
2427

2528

2629
let fromString measurementType measurementTypeTermSourceREF measurementTypeTermAccessionNumber technologyType technologyTypeTermSourceREF technologyTypeTermAccessionNumber technologyPlatform fileName comments : ArcAssay =
27-
let measurementType = OntologyAnnotation.fromString(?termName = measurementType,?tan = measurementTypeTermAccessionNumber,?tsr = measurementTypeTermSourceREF)
28-
let technologyType = OntologyAnnotation.fromString(?termName = technologyType,?tan = technologyTypeTermAccessionNumber,?tsr = technologyTypeTermSourceREF)
30+
let measurementType = OntologyAnnotation.create(?name = measurementType,?tan = measurementTypeTermAccessionNumber,?tsr = measurementTypeTermSourceREF)
31+
let technologyType = OntologyAnnotation.create(?name = technologyType,?tan = technologyTypeTermAccessionNumber,?tsr = technologyTypeTermSourceREF)
2932
ArcAssay.make
3033
(fileName)
31-
(Option.fromValueWithDefault OntologyAnnotation.empty measurementType)
32-
(Option.fromValueWithDefault OntologyAnnotation.empty technologyType)
33-
(technologyPlatform |> Option.map ArcAssay.decomposeTechnologyPlatform)
34+
(Option.fromValueWithDefault (OntologyAnnotation()) measurementType)
35+
(Option.fromValueWithDefault (OntologyAnnotation()) technologyType)
36+
(technologyPlatform |> Option.map JsonTypes.decomposeTechnologyPlatform)
3437
(ResizeArray())
35-
[||]
38+
(ResizeArray())
3639
(comments)
3740

3841
let fromSparseTable (matrix : SparseTable) : ArcAssay list=
@@ -47,7 +50,7 @@ module Assays =
4750
matrix.CommentKeys
4851
|> List.map (fun k ->
4952
Comment.fromString k (matrix.TryGetValueDefault("",(k,i))))
50-
|> Array.ofList
53+
|> ResizeArray
5154

5255
fromString
5356
(matrix.TryGetValue(measurementTypeLabel,i))
@@ -69,24 +72,23 @@ module Assays =
6972
let processedFileName =
7073
if a.Identifier.StartsWith(Identifier.MISSING_IDENTIFIER) then Identifier.removeMissingIdentifier(a.Identifier) else Identifier.Assay.fileNameFromIdentifier(a.Identifier)
7174
let i = i + 1
72-
let mt = Option.defaultValue OntologyAnnotation.empty a.MeasurementType |> fun mt -> OntologyAnnotation.toString(mt,true)
73-
let tt = Option.defaultValue OntologyAnnotation.empty a.TechnologyType |> fun tt -> OntologyAnnotation.toString(tt,true)
75+
let mt = Option.defaultValue (OntologyAnnotation()) a.MeasurementType |> fun mt -> OntologyAnnotation.toString(mt,true)
76+
let tt = Option.defaultValue (OntologyAnnotation()) a.TechnologyType |> fun tt -> OntologyAnnotation.toString(tt,true)
7477
do matrix.Matrix.Add ((measurementTypeLabel,i), mt.TermName)
7578
do matrix.Matrix.Add ((measurementTypeTermAccessionNumberLabel,i), mt.TermAccessionNumber)
7679
do matrix.Matrix.Add ((measurementTypeTermSourceREFLabel,i), mt.TermSourceREF)
7780
do matrix.Matrix.Add ((technologyTypeLabel,i), tt.TermName)
7881
do matrix.Matrix.Add ((technologyTypeTermAccessionNumberLabel,i), tt.TermAccessionNumber)
7982
do matrix.Matrix.Add ((technologyTypeTermSourceREFLabel,i), tt.TermSourceREF)
80-
do matrix.Matrix.Add ((technologyPlatformLabel,i), (Option.defaultValue "" (a.TechnologyPlatform |> Option.map ArcAssay.composeTechnologyPlatform)))
83+
do matrix.Matrix.Add ((technologyPlatformLabel,i), (Option.defaultValue "" (a.TechnologyPlatform |> Option.map JsonTypes.composeTechnologyPlatform)))
8184
do matrix.Matrix.Add ((fileNameLabel,i), processedFileName)
8285

83-
if Array.isEmpty a.Comments |> not then
84-
a.Comments
85-
|> Array.iter (fun comment ->
86-
let n,v = comment |> Comment.toString
87-
commentKeys <- n :: commentKeys
88-
matrix.Matrix.Add((n,i),v)
89-
)
86+
a.Comments
87+
|> ResizeArray.iter (fun comment ->
88+
let n,v = comment |> Comment.toString
89+
commentKeys <- n :: commentKeys
90+
matrix.Matrix.Add((n,i),v)
91+
)
9092
)
9193
{matrix with CommentKeys = commentKeys |> List.distinct |> List.rev}
9294

src/Spreadsheet/Metadata/Comment.fs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace ARCtrl.ISA.Spreadsheet
1+
namespace ARCtrl.Spreadsheet
22

3-
open ARCtrl.ISA
3+
open ARCtrl
44
open System.Text.RegularExpressions
5-
open ARCtrl.ISA.Regex.ActivePatterns
5+
open ARCtrl.Helper.Regex.ActivePatterns
66

77
module Comment =
88

@@ -29,7 +29,6 @@ module Comment =
2929

3030
let fromString k v =
3131
Comment.make
32-
None
3332
(Option.fromValueWithDefault "" k)
3433
(Option.fromValueWithDefault "" v)
3534

src/Spreadsheet/Metadata/Contacts.fs

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
namespace ARCtrl.ISA.Spreadsheet
1+
namespace ARCtrl.Spreadsheet
22

3-
open ARCtrl.ISA
3+
open ARCtrl
4+
open ARCtrl.Helper
5+
open ARCtrl.Process.Conversion
46
open Comment
57
open Remark
68
open System.Collections.Generic
@@ -24,7 +26,6 @@ module Contacts =
2426
let fromString lastName firstName midInitials email phone fax address affiliation role rolesTermAccessionNumber rolesTermSourceREF comments =
2527
let roles = OntologyAnnotation.fromAggregatedStrings ';' role rolesTermSourceREF rolesTermAccessionNumber
2628
Person.make
27-
None
2829
None
2930
(lastName )
3031
(firstName )
@@ -34,8 +35,8 @@ module Contacts =
3435
(fax )
3536
(address )
3637
(affiliation)
37-
(Option.fromValueWithDefault [||] roles )
38-
(Option.fromValueWithDefault [||] comments )
38+
(roles )
39+
(comments )
3940
|> Person.setOrcidFromComments
4041

4142
let fromSparseTable (matrix : SparseTable) =
@@ -49,7 +50,7 @@ module Contacts =
4950
matrix.CommentKeys
5051
|> List.map (fun k ->
5152
Comment.fromString k (matrix.TryGetValueDefault("",(k,i))))
52-
|> Array.ofList
53+
|> ResizeArray
5354
fromString
5455
(matrix.TryGetValue(lastNameLabel,i))
5556
(matrix.TryGetValue(firstNameLabel,i))
@@ -72,7 +73,7 @@ module Contacts =
7273
|> List.map Person.setCommentFromORCID
7374
|> List.iteri (fun i p ->
7475
let i = i + 1
75-
let rAgg = Option.defaultValue [||] p.Roles |> OntologyAnnotation.toAggregatedStrings ';'
76+
let rAgg = p.Roles |> Array.ofSeq |> OntologyAnnotation.toAggregatedStrings ';'
7677
do matrix.Matrix.Add ((lastNameLabel,i), (Option.defaultValue "" p.LastName ))
7778
do matrix.Matrix.Add ((firstNameLabel,i), (Option.defaultValue "" p.FirstName ))
7879
do matrix.Matrix.Add ((midInitialsLabel,i), (Option.defaultValue "" p.MidInitials ))
@@ -85,15 +86,12 @@ module Contacts =
8586
do matrix.Matrix.Add ((rolesTermAccessionNumberLabel,i), rAgg.TermAccessionNumberAgg)
8687
do matrix.Matrix.Add ((rolesTermSourceREFLabel,i), rAgg.TermSourceREFAgg)
8788

88-
match p.Comments with
89-
| None -> ()
90-
| Some c ->
91-
c
92-
|> Array.iter (fun comment ->
93-
let n,v = comment |> Comment.toString
94-
commentKeys <- n :: commentKeys
95-
matrix.Matrix.Add((n,i),v)
96-
)
89+
p.Comments
90+
|> ResizeArray.iter (fun comment ->
91+
let n,v = comment |> Comment.toString
92+
commentKeys <- n :: commentKeys
93+
matrix.Matrix.Add((n,i),v)
94+
)
9795
)
9896
{matrix with CommentKeys = commentKeys |> List.distinct |> List.rev}
9997

0 commit comments

Comments
 (0)