Skip to content

Commit f60edbd

Browse files
committed
adjust xlsx io to FSharpSpreadsheetML 0.0.7
1 parent 2147cb9 commit f60edbd

6 files changed

Lines changed: 68 additions & 58 deletions

File tree

src/ISADotNet.XLSX/AssayFile/AnnotationNode.fs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ module AnnotationNode =
135135
Seq.tryPick tryParseUnitHeader headers
136136
|> Option.map (fun h ->
137137
let unitNameGetter matrix i =
138-
Dictionary.tryGetValue (h.HeaderString,i) matrix
138+
Dictionary.tryGetValue (i,h.HeaderString) matrix
139139
let termAccessionGetter =
140140
match Seq.tryPick (tryParseTermAccessionNumberHeader h) headers with
141141
| Some h ->
142142
fun matrix i ->
143-
match Dictionary.tryGetValue (h.HeaderString,i) matrix with
143+
match Dictionary.tryGetValue (i,h.HeaderString) matrix with
144144
| Some "user-specific" -> None
145145
| Some v -> Some v
146146
| _ -> None
@@ -149,12 +149,12 @@ module AnnotationNode =
149149
match Seq.tryPick (tryParseTermSourceReferenceHeader h) headers with
150150
| Some h ->
151151
fun matrix i ->
152-
match Dictionary.tryGetValue (h.HeaderString,i) matrix with
152+
match Dictionary.tryGetValue (i,h.HeaderString) matrix with
153153
| Some "user-specific" -> None
154154
| Some v -> Some v
155155
| _ -> None
156156
| None -> fun _ _ -> None
157-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
157+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
158158
OntologyAnnotation.make
159159
None
160160
(unitNameGetter matrix i |> Option.map AnnotationValue.fromString)
@@ -169,8 +169,8 @@ module AnnotationNode =
169169
match Seq.tryPick (tryParseTermAccessionNumberHeader valueHeader) headers with
170170
| Some h ->
171171
h.Term,
172-
fun matrix i ->
173-
match Dictionary.tryGetValue (h.HeaderString,i) matrix with
172+
fun (matrix:System.Collections.Generic.Dictionary<int*string,string>) (i:int) ->
173+
match Dictionary.tryGetValue (i,h.HeaderString) matrix with
174174
| Some "user-specific" -> None
175175
| Some v -> Some v
176176
| _ -> None
@@ -180,7 +180,7 @@ module AnnotationNode =
180180
| Some h ->
181181
h.Term,
182182
fun matrix i ->
183-
match Dictionary.tryGetValue (h.HeaderString,i) matrix with
183+
match Dictionary.tryGetValue (i,h.HeaderString) matrix with
184184
| Some "user-specific" -> None
185185
| Some v -> Some v
186186
| _ -> None
@@ -199,7 +199,7 @@ module AnnotationNode =
199199
let valueGetter =
200200
fun matrix i ->
201201
let value =
202-
match Dictionary.tryGetValue (valueHeader.HeaderString,i) matrix with
202+
match Dictionary.tryGetValue (i,valueHeader.HeaderString) matrix with
203203
| Some "user-specific" -> None
204204
// Trim() should remove any accidental whitespaces at the beginning or end of a term
205205
| Some v -> Some v
@@ -235,7 +235,7 @@ module AnnotationNode =
235235
let parameter = category |> Option.map (Some >> ProtocolParameter.make None)
236236

237237
parameter,
238-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
238+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
239239
ProcessParameterValue.make
240240
parameter
241241
(valueGetter matrix i)
@@ -257,7 +257,7 @@ module AnnotationNode =
257257
)
258258

259259
factor,
260-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
260+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
261261
FactorValue.make
262262
None
263263
factor
@@ -276,7 +276,7 @@ module AnnotationNode =
276276
let characteristic = category |> Option.map (Some >> MaterialAttribute.make None)
277277

278278
characteristic,
279-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
279+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
280280
MaterialAttributeValue.make
281281
None
282282
characteristic
@@ -296,11 +296,11 @@ module AnnotationNode =
296296
else None
297297
let numberComment = h.Number |> Option.map (string >> (Comment.fromString "Number") >> List.singleton)
298298

299-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
299+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
300300

301301
Data.make
302302
None
303-
(Dictionary.tryGetValue (h.HeaderString,i) matrix)
303+
(Dictionary.tryGetValue (i,h.HeaderString) matrix)
304304
dataType
305305
numberComment
306306
)
@@ -309,16 +309,16 @@ module AnnotationNode =
309309
let tryGetSampleNameGetter (headers:string seq) =
310310
Seq.tryPick tryParseSampleName headers
311311
|> Option.map (fun h ->
312-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
313-
Dictionary.tryGetValue (h.HeaderString,i) matrix
312+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
313+
Dictionary.tryGetValue (i,h.HeaderString) matrix
314314
)
315315

316316
/// If the headers of a node depict a source name, returns a function for parsing the values of the matrix to the source names
317317
let tryGetSourceNameGetter (headers:string seq) =
318318
Seq.tryPick tryParseSourceName headers
319319
|> Option.map (fun h ->
320-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
321-
Dictionary.tryGetValue (h.HeaderString,i) matrix
320+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
321+
Dictionary.tryGetValue (i,h.HeaderString) matrix
322322
)
323323

324324
/// Returns true, if the headers contain a value node: characteristic, parameter or factor

src/ISADotNet.XLSX/AssayFile/AnnotationTable.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ module AnnotationTable =
118118
characteristics,
119119
factors,
120120
protocol,
121-
fun (matrix : System.Collections.Generic.Dictionary<(string * int),string>) i ->
121+
fun (matrix : System.Collections.Generic.Dictionary<(int * string),string>) i ->
122122
Process.make
123123
None
124124
None

src/ISADotNet.XLSX/AssayFile/Assay.fs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ module Process =
1414
/// matrixHeaders are the column headers of the table
1515
///
1616
/// sparseMatrix is a sparse representation of the sheet table, with the first part of the key being the column header and the second part being a zero based row index
17-
let fromSparseMatrix (processNameRoot:string) matrixHeaders (sparseMatrix : Dictionary<string*int,string>) =
17+
let fromSparseMatrix (processNameRoot:string) matrixHeaders (sparseMatrix : Dictionary<int*string,string>) =
1818
let len =
1919
let mutable i = 0
2020
for kv in sparseMatrix do
21-
let j = kv.Key |> snd
21+
let j = kv.Key |> fst
2222
if j > i then i <- j
2323
i + 1
2424
let characteristic,factors,protocol,processGetter =
@@ -46,14 +46,14 @@ module Assay =
4646
/// matrixHeaders are the column headers of the table
4747
///
4848
/// sparseMatrix is a sparse representation of the sheet table, with the first part of the key being the column header and the second part being a zero based row index
49-
let fromSparseMatrix (processNameRoot:string) matrixHeaders (sparseMatrix : Dictionary<string*int,string>) =
49+
let fromSparseMatrix (processNameRoot:string) matrixHeaders (sparseMatrix : Dictionary<int*string,string>) =
5050
let characteristics,factors,protocols,processes = Process.fromSparseMatrix processNameRoot matrixHeaders sparseMatrix
5151
factors,protocols,Assay.create(CharacteristicCategories = characteristics,ProcessSequence = Seq.toList processes)
5252

5353
/// Returns an assay from a sequence of sparseMatrix representations of assay.xlsx sheets
5454
///
5555
/// See "fromSparseMatrix" function for parameter documentation
56-
let fromSparseMatrices (sheets : (string*(string seq)*Dictionary<string*int,string>) seq) =
56+
let fromSparseMatrices (sheets : (string*(string seq)*Dictionary<int*string,string>) seq) =
5757
let characteristics,factors,protocols,processes =
5858
sheets
5959
|> Seq.map (fun (name,matrixHeaders,matrix) -> Process.fromSparseMatrix name matrixHeaders matrix)
@@ -72,16 +72,20 @@ module Assay =
7272
7373
/// Create a new ISADotNet.XLSX assay file constisting of two sheets. The first has the name of the assayIdentifier and is meant to store parameters used in the assay. The second stores additional assay metadata
7474
let init metadataSheetName assayIdentifier path =
75-
Spreadsheet.initWithSST assayIdentifier path
75+
Spreadsheet.initWithSst assayIdentifier path
7676
|> MetaData.init metadataSheetName
7777
|> Spreadsheet.close
7878

79-
/// Parses the assay file
79+
/// Reads an assay from an xlsx spreadsheetdocument
80+
///
81+
/// As factors and protocols are used for the investigation file, they are returned individually
82+
///
83+
/// The persons from the metadata sheet are returned independently as they are not a part of the assay object
8084
let fromSpreadsheet (doc:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument) =
8185

8286
let sst = Spreadsheet.tryGetSharedStringTable doc
8387

84-
// Get the metadata from the metadata sheet
88+
// Reading the "Investigation" metadata sheet. Here metadata
8589
let assayMetaData,contacts =
8690
Spreadsheet.tryGetSheetBySheetName "Investigation" doc
8791
|> Option.map (fun sheet ->
@@ -93,7 +97,8 @@ module Assay =
9397
|> fun (a,p) -> Option.defaultValue Assay.empty a, p
9498
)
9599
|> Option.defaultValue (Assay.empty,[])
96-
100+
101+
// All sheetnames in the spreadsheetDocument
97102
let sheetNames =
98103
Spreadsheet.getWorkbookPart doc
99104
|> Workbook.get
@@ -108,19 +113,20 @@ module Assay =
108113
| Some wsp ->
109114
match Table.tryGetByNameBy (fun s -> s.StartsWith "annotationTable") wsp with
110115
| Some table ->
116+
// Extract the sheetdata as a sparse matrix
111117
let sheet = Worksheet.getSheetData wsp.Worksheet
112118
let headers = Table.getColumnHeaders table
113119
let m = Table.toSparseValueMatrix sst sheet table
114120
Seq.singleton (sheetName,headers,m)
115121
| None -> Seq.empty
116122
| None -> Seq.empty
117123
)
118-
|> fromSparseMatrices
124+
|> fromSparseMatrices // Feed the sheets (represented as sparse matrices) into the assay parser function
119125

120126
factors,
121127
protocols |> Seq.toList,
122128
contacts,
123-
API.Update.UpdateByExisting.updateRecordType assayMetaData assay
129+
API.Update.UpdateByExisting.updateRecordType assayMetaData assay // Merges the assay containing the assay meta data and the assay containing the processes retrieved from the sheets
124130

125131
/// Parses the assay file
126132
let fromFile (path:string) =

src/ISADotNet.XLSX/ISADotNet.XLSX.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="FSharpSpreadsheetML" Version="0.0.6" />
32+
<PackageReference Include="FSharpSpreadsheetML" Version="0.0.7" />
3333
</ItemGroup>
3434

3535
<ItemGroup>

src/ISADotNet.XLSX/InvestigationFile/Investigation.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ module Investigation =
232232
|> ignore
233233

234234
let toFile (path : string) (investigation:Investigation) =
235-
let doc = Spreadsheet.initWithSST "isa_investigation" path
235+
let doc = Spreadsheet.initWithSst "isa_investigation" path
236236
try
237237
toSpreadsheet doc investigation
238238
finally

0 commit comments

Comments
 (0)