Skip to content

Commit

Permalink
rework ARCtrl.Spreadsheet according to datamodel changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 21, 2024
1 parent 2cb9db8 commit b568074
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 184 deletions.
7 changes: 4 additions & 3 deletions src/Spreadsheet/AnnotationTable/ArcTable.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ARCtrl.ISA.Spreadsheet.ArcTable
module ARCtrl.Spreadsheet.ArcTable

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open FsSpreadsheet

// I think we really should not add FSharpAux for exactly one function.
Expand Down Expand Up @@ -93,7 +94,7 @@ let tryFromFsWorksheet (sheet : FsWorksheet) =
|> Seq.map CompositeColumn.fixDeprecatedIOHeader
|> composeColumns
ArcTable.init sheet.Name
|> ArcTable.addColumns(compositeColumns,SkipFillMissing = true)
|> ArcTable.addColumns(compositeColumns,skipFillMissing = true)
|> Some
| None ->
None
Expand Down
11 changes: 6 additions & 5 deletions src/Spreadsheet/AnnotationTable/CompositeCell.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ARCtrl.ISA.Spreadsheet.CompositeCell
module ARCtrl.Spreadsheet.CompositeCell

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open FsSpreadsheet

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

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

| CompositeCell.Unitized (v,unit) -> [FsCell(v); FsCell(unit.NameText); FsCell(unit.TermSourceREFString); FsCell(unit.TermAccessionOntobeeUrl)]
| CompositeCell.Unitized (v,unit) -> [FsCell(v); FsCell(unit.NameText); FsCell(Option.defaultValue "" unit.TermSourceREF); FsCell(unit.TermAccessionOntobeeUrl)]
5 changes: 3 additions & 2 deletions src/Spreadsheet/AnnotationTable/CompositeColumn.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ARCtrl.ISA.Spreadsheet.CompositeColumn
module ARCtrl.Spreadsheet.CompositeColumn

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open FsSpreadsheet

/// Checks if the column header is a deprecated IO Header. If so, fixes it.
Expand Down
11 changes: 6 additions & 5 deletions src/Spreadsheet/AnnotationTable/CompositeHeader.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module ARCtrl.ISA.Spreadsheet.CompositeHeader
module ARCtrl.Spreadsheet.CompositeHeader

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open FsSpreadsheet

module ActivePattern =

open ARCtrl.ISA.Regex.ActivePatterns
open Regex.ActivePatterns

let mergeIDInfo idSpace1 localID1 idSpace2 localID2 =
if idSpace1 <> idSpace2 then failwithf "TermSourceRef %s and %s do not match" idSpace1 idSpace2
Expand All @@ -18,15 +19,15 @@ module ActivePattern =
let cellValues = cells |> List.map (fun c -> c.ValueAsString())
match cellValues with
| [AC name] ->
let ont = OntologyAnnotation.fromString(name)
let ont = OntologyAnnotation.create(name)
f ont
|> Some
| [AC name; TSRColumnHeader term1; TANColumnHeader term2]
//| [AC name; TermAccessionNumber term1; TermSourceREF term2]
//| [AC name; Unit; TermAccessionNumber term1; TermSourceREF term2]
| [AC name; UnitColumnHeader _; TSRColumnHeader term1; TANColumnHeader term2] ->
let term = mergeIDInfo term1.IDSpace term1.LocalID term2.IDSpace term2.LocalID
let ont = OntologyAnnotation.fromString(name, term.TermSourceRef, term.TermAccessionNumber)
let ont = OntologyAnnotation.create(name, term.TermSourceRef, term.TermAccessionNumber)
f ont
|> Some
| _ -> None
Expand Down
9 changes: 5 additions & 4 deletions src/Spreadsheet/ArcAssay.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ARCtrl.ISA.Spreadsheet.ArcAssay
module ARCtrl.Spreadsheet.ArcAssay

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open FsSpreadsheet

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

yield SparseRow.fromValues [contactsLabel]
yield! Contacts.toRows (Some contactsPrefix) (List.ofArray assay.Performers)
yield! Contacts.toRows (Some contactsPrefix) (List.ofSeq assay.Performers)
}
let sheet = FsWorksheet(metaDataSheetName)
assay
Expand Down Expand Up @@ -54,7 +55,7 @@ let fromMetadataSheet (sheet : FsWorksheet) : ArcAssay =
assays
|> Seq.tryHead
|> Option.defaultValue (ArcAssay.create(Identifier.createMissingIdentifier()))
|> ArcAssay.setPerformers (Array.ofList contacts)
|> ArcAssay.setPerformers (ResizeArray contacts)

if en.MoveNext () then
let currentLine = en.Current |> SparseRow.tryGetValueAt 0
Expand Down
42 changes: 21 additions & 21 deletions src/Spreadsheet/ArcInvestigation.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ARCtrl.ISA.Spreadsheet
namespace ARCtrl.Spreadsheet

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open FsSpreadsheet
open Comment
open Remark
Expand Down Expand Up @@ -78,13 +79,12 @@ module ArcInvestigation =
do matrix.Matrix.Add ((submissionDateLabel,i), (Option.defaultValue "" investigation.SubmissionDate))
do matrix.Matrix.Add ((publicReleaseDateLabel,i), (Option.defaultValue "" investigation.PublicReleaseDate))

if Array.isEmpty investigation.Comments |> not then
investigation.Comments
|> Array.iter (fun comment ->
let n,v = comment |> Comment.toString
commentKeys <- n :: commentKeys
matrix.Matrix.Add((n,i),v)
)
investigation.Comments
|> ResizeArray.iter (fun comment ->
let n,v = comment |> Comment.toString
commentKeys <- n :: commentKeys
matrix.Matrix.Add((n,i),v)
)

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

Expand All @@ -106,14 +106,14 @@ module ArcInvestigation =
(Option.fromValueWithDefault "" investigationInfo.Description)
(Option.fromValueWithDefault "" investigationInfo.SubmissionDate)
(Option.fromValueWithDefault "" investigationInfo.PublicReleaseDate)
(Array.ofList ontologySourceReference)
(Array.ofList publications)
(Array.ofList contacts)
(ResizeArray(assays))
(ResizeArray(studies))
(ResizeArray(studyIdentifiers))
(Array.ofList investigationInfo.Comments)
(Array.ofList remarks)
(ResizeArray ontologySourceReference)
(ResizeArray publications)
(ResizeArray contacts)
(ResizeArray assays)
(ResizeArray studies)
(ResizeArray studyIdentifiers)
(ResizeArray investigationInfo.Comments)
(ResizeArray remarks)


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

yield SparseRow.fromValues [investigationLabel]
yield! InvestigationInfo.toRows investigation

yield SparseRow.fromValues [publicationsLabel]
yield! Publications.toRows (Some publicationsLabelPrefix) (List.ofArray investigation.Publications)
yield! Publications.toRows (Some publicationsLabelPrefix) (List.ofSeq investigation.Publications)

yield SparseRow.fromValues [contactsLabel]
yield! Contacts.toRows (Some contactsLabelPrefix) (List.ofArray investigation.Contacts)
yield! Contacts.toRows (Some contactsLabelPrefix) (List.ofSeq investigation.Contacts)

if not isLight then
for studyIdentifier in investigation.RegisteredStudyIdentifiers do
let study = investigation.TryGetStudy(studyIdentifier) |> Option.defaultValue (ArcStudy(studyIdentifier))
yield SparseRow.fromValues [studyLabel]
yield! Studies.toRows study None
}
|> insertRemarks (List.ofArray investigation.Remarks)
|> insertRemarks (List.ofSeq investigation.Remarks)
|> seq

let fromFsWorkbook (doc:FsWorkbook) =
Expand Down
6 changes: 3 additions & 3 deletions src/Spreadsheet/ArcStudy.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace ARCtrl.ISA.Spreadsheet
namespace ARCtrl.Spreadsheet

open ARCtrl.ISA
open ARCtrl
open FsSpreadsheet

open Aux
open ARCtrl.Helper

module ArcStudy =

Expand Down
2 changes: 1 addition & 1 deletion src/Spreadsheet/CollectionAux.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ARCtrl.ISA.Spreadsheet
namespace ARCtrl.Spreadsheet


module Seq =
Expand Down
40 changes: 21 additions & 19 deletions src/Spreadsheet/Metadata/Assays.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace ARCtrl.ISA.Spreadsheet
namespace ARCtrl.Spreadsheet

open ARCtrl.ISA
open ARCtrl
open Comment
open Remark
open System.Collections.Generic
open ARCtrl.Helper
open ARCtrl.Process.Conversion


module Assays =

Expand All @@ -24,15 +27,15 @@ module Assays =


let fromString measurementType measurementTypeTermSourceREF measurementTypeTermAccessionNumber technologyType technologyTypeTermSourceREF technologyTypeTermAccessionNumber technologyPlatform fileName comments : ArcAssay =
let measurementType = OntologyAnnotation.fromString(?termName = measurementType,?tan = measurementTypeTermAccessionNumber,?tsr = measurementTypeTermSourceREF)
let technologyType = OntologyAnnotation.fromString(?termName = technologyType,?tan = technologyTypeTermAccessionNumber,?tsr = technologyTypeTermSourceREF)
let measurementType = OntologyAnnotation.create(?name = measurementType,?tan = measurementTypeTermAccessionNumber,?tsr = measurementTypeTermSourceREF)
let technologyType = OntologyAnnotation.create(?name = technologyType,?tan = technologyTypeTermAccessionNumber,?tsr = technologyTypeTermSourceREF)
ArcAssay.make
(fileName)
(Option.fromValueWithDefault OntologyAnnotation.empty measurementType)
(Option.fromValueWithDefault OntologyAnnotation.empty technologyType)
(technologyPlatform |> Option.map ArcAssay.decomposeTechnologyPlatform)
(Option.fromValueWithDefault (OntologyAnnotation()) measurementType)
(Option.fromValueWithDefault (OntologyAnnotation()) technologyType)
(technologyPlatform |> Option.map JsonTypes.decomposeTechnologyPlatform)
(ResizeArray())
[||]
(ResizeArray())
(comments)

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

fromString
(matrix.TryGetValue(measurementTypeLabel,i))
Expand All @@ -69,24 +72,23 @@ module Assays =
let processedFileName =
if a.Identifier.StartsWith(Identifier.MISSING_IDENTIFIER) then Identifier.removeMissingIdentifier(a.Identifier) else Identifier.Assay.fileNameFromIdentifier(a.Identifier)
let i = i + 1
let mt = Option.defaultValue OntologyAnnotation.empty a.MeasurementType |> fun mt -> OntologyAnnotation.toString(mt,true)
let tt = Option.defaultValue OntologyAnnotation.empty a.TechnologyType |> fun tt -> OntologyAnnotation.toString(tt,true)
let mt = Option.defaultValue (OntologyAnnotation()) a.MeasurementType |> fun mt -> OntologyAnnotation.toString(mt,true)
let tt = Option.defaultValue (OntologyAnnotation()) a.TechnologyType |> fun tt -> OntologyAnnotation.toString(tt,true)
do matrix.Matrix.Add ((measurementTypeLabel,i), mt.TermName)
do matrix.Matrix.Add ((measurementTypeTermAccessionNumberLabel,i), mt.TermAccessionNumber)
do matrix.Matrix.Add ((measurementTypeTermSourceREFLabel,i), mt.TermSourceREF)
do matrix.Matrix.Add ((technologyTypeLabel,i), tt.TermName)
do matrix.Matrix.Add ((technologyTypeTermAccessionNumberLabel,i), tt.TermAccessionNumber)
do matrix.Matrix.Add ((technologyTypeTermSourceREFLabel,i), tt.TermSourceREF)
do matrix.Matrix.Add ((technologyPlatformLabel,i), (Option.defaultValue "" (a.TechnologyPlatform |> Option.map ArcAssay.composeTechnologyPlatform)))
do matrix.Matrix.Add ((technologyPlatformLabel,i), (Option.defaultValue "" (a.TechnologyPlatform |> Option.map JsonTypes.composeTechnologyPlatform)))
do matrix.Matrix.Add ((fileNameLabel,i), processedFileName)

if Array.isEmpty a.Comments |> not then
a.Comments
|> Array.iter (fun comment ->
let n,v = comment |> Comment.toString
commentKeys <- n :: commentKeys
matrix.Matrix.Add((n,i),v)
)
a.Comments
|> ResizeArray.iter (fun comment ->
let n,v = comment |> Comment.toString
commentKeys <- n :: commentKeys
matrix.Matrix.Add((n,i),v)
)
)
{matrix with CommentKeys = commentKeys |> List.distinct |> List.rev}

Expand Down
7 changes: 3 additions & 4 deletions src/Spreadsheet/Metadata/Comment.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace ARCtrl.ISA.Spreadsheet
namespace ARCtrl.Spreadsheet

open ARCtrl.ISA
open ARCtrl
open System.Text.RegularExpressions
open ARCtrl.ISA.Regex.ActivePatterns
open ARCtrl.Helper.Regex.ActivePatterns

module Comment =

Expand All @@ -29,7 +29,6 @@ module Comment =

let fromString k v =
Comment.make
None
(Option.fromValueWithDefault "" k)
(Option.fromValueWithDefault "" v)

Expand Down
30 changes: 14 additions & 16 deletions src/Spreadsheet/Metadata/Contacts.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace ARCtrl.ISA.Spreadsheet
namespace ARCtrl.Spreadsheet

open ARCtrl.ISA
open ARCtrl
open ARCtrl.Helper
open ARCtrl.Process.Conversion
open Comment
open Remark
open System.Collections.Generic
Expand All @@ -24,7 +26,6 @@ module Contacts =
let fromString lastName firstName midInitials email phone fax address affiliation role rolesTermAccessionNumber rolesTermSourceREF comments =
let roles = OntologyAnnotation.fromAggregatedStrings ';' role rolesTermSourceREF rolesTermAccessionNumber
Person.make
None
None
(lastName )
(firstName )
Expand All @@ -34,8 +35,8 @@ module Contacts =
(fax )
(address )
(affiliation)
(Option.fromValueWithDefault [||] roles )
(Option.fromValueWithDefault [||] comments )
(roles )
(comments )
|> Person.setOrcidFromComments

let fromSparseTable (matrix : SparseTable) =
Expand All @@ -49,7 +50,7 @@ module Contacts =
matrix.CommentKeys
|> List.map (fun k ->
Comment.fromString k (matrix.TryGetValueDefault("",(k,i))))
|> Array.ofList
|> ResizeArray
fromString
(matrix.TryGetValue(lastNameLabel,i))
(matrix.TryGetValue(firstNameLabel,i))
Expand All @@ -72,7 +73,7 @@ module Contacts =
|> List.map Person.setCommentFromORCID
|> List.iteri (fun i p ->
let i = i + 1
let rAgg = Option.defaultValue [||] p.Roles |> OntologyAnnotation.toAggregatedStrings ';'
let rAgg = p.Roles |> Array.ofSeq |> OntologyAnnotation.toAggregatedStrings ';'
do matrix.Matrix.Add ((lastNameLabel,i), (Option.defaultValue "" p.LastName ))
do matrix.Matrix.Add ((firstNameLabel,i), (Option.defaultValue "" p.FirstName ))
do matrix.Matrix.Add ((midInitialsLabel,i), (Option.defaultValue "" p.MidInitials ))
Expand All @@ -85,15 +86,12 @@ module Contacts =
do matrix.Matrix.Add ((rolesTermAccessionNumberLabel,i), rAgg.TermAccessionNumberAgg)
do matrix.Matrix.Add ((rolesTermSourceREFLabel,i), rAgg.TermSourceREFAgg)

match p.Comments with
| None -> ()
| Some c ->
c
|> Array.iter (fun comment ->
let n,v = comment |> Comment.toString
commentKeys <- n :: commentKeys
matrix.Matrix.Add((n,i),v)
)
p.Comments
|> ResizeArray.iter (fun comment ->
let n,v = comment |> Comment.toString
commentKeys <- n :: commentKeys
matrix.Matrix.Add((n,i),v)
)
)
{matrix with CommentKeys = commentKeys |> List.distinct |> List.rev}

Expand Down
Loading

0 comments on commit b568074

Please sign in to comment.