diff --git a/src/Spreadsheet/AnnotationTable/ArcTable.fs b/src/Spreadsheet/AnnotationTable/ArcTable.fs index c1e5a26d..e7573d0a 100644 --- a/src/Spreadsheet/AnnotationTable/ArcTable.fs +++ b/src/Spreadsheet/AnnotationTable/ArcTable.fs @@ -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. @@ -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 diff --git a/src/Spreadsheet/AnnotationTable/CompositeCell.fs b/src/Spreadsheet/AnnotationTable/CompositeCell.fs index ff0f2902..da43f5b3 100644 --- a/src/Spreadsheet/AnnotationTable/CompositeCell.fs +++ b/src/Spreadsheet/AnnotationTable/CompositeCell.fs @@ -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) : CompositeCell = @@ -18,7 +19,7 @@ let toFsCells isTerm hasUnit (cell : CompositeCell) : list = | 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)] \ No newline at end of file + | CompositeCell.Unitized (v,unit) -> [FsCell(v); FsCell(unit.NameText); FsCell(Option.defaultValue "" unit.TermSourceREF); FsCell(unit.TermAccessionOntobeeUrl)] \ No newline at end of file diff --git a/src/Spreadsheet/AnnotationTable/CompositeColumn.fs b/src/Spreadsheet/AnnotationTable/CompositeColumn.fs index 24f4a14e..4cc5e7d9 100644 --- a/src/Spreadsheet/AnnotationTable/CompositeColumn.fs +++ b/src/Spreadsheet/AnnotationTable/CompositeColumn.fs @@ -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. diff --git a/src/Spreadsheet/AnnotationTable/CompositeHeader.fs b/src/Spreadsheet/AnnotationTable/CompositeHeader.fs index b8e9fe05..74e83ffa 100644 --- a/src/Spreadsheet/AnnotationTable/CompositeHeader.fs +++ b/src/Spreadsheet/AnnotationTable/CompositeHeader.fs @@ -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 @@ -18,7 +19,7 @@ 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] @@ -26,7 +27,7 @@ module ActivePattern = //| [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 diff --git a/src/Spreadsheet/ArcAssay.fs b/src/Spreadsheet/ArcAssay.fs index e0677363..bdc08731 100644 --- a/src/Spreadsheet/ArcAssay.fs +++ b/src/Spreadsheet/ArcAssay.fs @@ -1,6 +1,7 @@ -module ARCtrl.ISA.Spreadsheet.ArcAssay +module ARCtrl.Spreadsheet.ArcAssay -open ARCtrl.ISA +open ARCtrl +open ARCtrl.Helper open FsSpreadsheet let [] obsoleteAssaysLabel = "ASSAY METADATA" @@ -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 @@ -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 diff --git a/src/Spreadsheet/ArcInvestigation.fs b/src/Spreadsheet/ArcInvestigation.fs index c80fc3d4..f0208fee 100644 --- a/src/Spreadsheet/ArcInvestigation.fs +++ b/src/Spreadsheet/ArcInvestigation.fs @@ -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 @@ -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} @@ -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) = @@ -183,16 +183,16 @@ 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 @@ -200,7 +200,7 @@ module ArcInvestigation = yield SparseRow.fromValues [studyLabel] yield! Studies.toRows study None } - |> insertRemarks (List.ofArray investigation.Remarks) + |> insertRemarks (List.ofSeq investigation.Remarks) |> seq let fromFsWorkbook (doc:FsWorkbook) = diff --git a/src/Spreadsheet/ArcStudy.fs b/src/Spreadsheet/ArcStudy.fs index be2fcb70..bf6fb6ca 100644 --- a/src/Spreadsheet/ArcStudy.fs +++ b/src/Spreadsheet/ArcStudy.fs @@ -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 = diff --git a/src/Spreadsheet/CollectionAux.fs b/src/Spreadsheet/CollectionAux.fs index 7d324f2d..fa4985e7 100644 --- a/src/Spreadsheet/CollectionAux.fs +++ b/src/Spreadsheet/CollectionAux.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet module Seq = diff --git a/src/Spreadsheet/Metadata/Assays.fs b/src/Spreadsheet/Metadata/Assays.fs index 5b8ebd56..90466b17 100644 --- a/src/Spreadsheet/Metadata/Assays.fs +++ b/src/Spreadsheet/Metadata/Assays.fs @@ -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 = @@ -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= @@ -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)) @@ -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} diff --git a/src/Spreadsheet/Metadata/Comment.fs b/src/Spreadsheet/Metadata/Comment.fs index d731e25a..454dc236 100644 --- a/src/Spreadsheet/Metadata/Comment.fs +++ b/src/Spreadsheet/Metadata/Comment.fs @@ -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 = @@ -29,7 +29,6 @@ module Comment = let fromString k v = Comment.make - None (Option.fromValueWithDefault "" k) (Option.fromValueWithDefault "" v) diff --git a/src/Spreadsheet/Metadata/Contacts.fs b/src/Spreadsheet/Metadata/Contacts.fs index 1799dfbf..1c418c25 100644 --- a/src/Spreadsheet/Metadata/Contacts.fs +++ b/src/Spreadsheet/Metadata/Contacts.fs @@ -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 @@ -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 ) @@ -34,8 +35,8 @@ module Contacts = (fax ) (address ) (affiliation) - (Option.fromValueWithDefault [||] roles ) - (Option.fromValueWithDefault [||] comments ) + (roles ) + (comments ) |> Person.setOrcidFromComments let fromSparseTable (matrix : SparseTable) = @@ -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)) @@ -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 )) @@ -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} diff --git a/src/Spreadsheet/Metadata/Conversions.fs b/src/Spreadsheet/Metadata/Conversions.fs index 0a912dd8..446adb66 100644 --- a/src/Spreadsheet/Metadata/Conversions.fs +++ b/src/Spreadsheet/Metadata/Conversions.fs @@ -1,7 +1,8 @@ -namespace ARCtrl.ISA.Spreadsheet - -open ARCtrl.ISA +namespace ARCtrl.Spreadsheet +open ARCtrl +open ARCtrl.Helper +open ARCtrl.Process module internal Option = @@ -37,14 +38,15 @@ module OntologyAnnotation = ) 0 /// Returns a list of ISAJson OntologyAnnotation objects from ISATab aggregated strings - let fromAggregatedStrings (separator:char) (terms:string) (source:string) (accessions:string) : OntologyAnnotation []= + let fromAggregatedStrings (separator:char) (terms:string) (source:string) (accessions:string) : ResizeArray = let l = getLengthOfAggregatedStrings separator [|terms;source;accessions|] - if l = 0 then [||] + if l = 0 then ResizeArray() else let terms : string [] = if terms = "" then Array.create l "" else terms.Split(separator) let sources : string [] = if source = "" then Array.create l "" else source.Split(separator) let accessions : string [] = if accessions = "" then Array.create l "" else accessions.Split(separator) - Array.map3 (fun a b c -> OntologyAnnotation.fromString(a,b,c)) terms sources accessions + Array.map3 (fun a b c -> OntologyAnnotation.create(a,b,c)) terms sources accessions + |> ResizeArray /// Returns the aggregated ISATab OntologyAnnotation Name, ontology source and Accession number from a list of ISAJson OntologyAnnotation objects let toAggregatedStrings (separator:char) (oas : OntologyAnnotation []) = @@ -52,15 +54,15 @@ module OntologyAnnotation = if oas = [||] then {|TermNameAgg = ""; TermAccessionNumberAgg = ""; TermSourceREFAgg = ""|} else oas - |> Array.map OntologyAnnotation.toString |> Array.fold (fun (nameAgg,tsrAgg,tanAgg) term -> + let name,tsr,tan = Option.defaultValue "" term.Name, Option.defaultValue "" term.TermSourceREF, Option.defaultValue "" term.TermAccessionNumber if first then first <- false - term.TermName,term.TermSourceREF,term.TermAccessionNumber + name,tsr,tan else - sprintf "%s%c%s" nameAgg separator term.TermName, - sprintf "%s%c%s" tsrAgg separator term.TermSourceREF, - sprintf "%s%c%s" tanAgg separator term.TermAccessionNumber + sprintf "%s%c%s" nameAgg separator name, + sprintf "%s%c%s" tsrAgg separator tsr, + sprintf "%s%c%s" tanAgg separator tan ) ("","","") |> fun (nameAgg,tsrAgg,tanAgg) -> {|TermNameAgg = nameAgg; TermAccessionNumberAgg = tanAgg; TermSourceREFAgg = tsrAgg|} @@ -76,7 +78,7 @@ module Component = let sources : string [] = if source = "" then Array.create l "" else source.Split(separator) let accessions : string [] = if accessions = "" then Array.create l "" else accessions.Split(separator) Array.map4 (fun a b c d -> Component.fromString(a,b,c,d)) names terms sources accessions - |> Array.toList + |> List.ofArray /// Returns the aggregated ISATAb Component Name, Ontology Annotation value, Accession number and ontology source from a list of ISAJson Component objects let toAggregatedStrings (separator:char) (cs : Component list) = @@ -102,7 +104,7 @@ module ProtocolParameter = /// Returns a list of ISAJson ProtocolParameter objects from ISATab aggregated strings let fromAggregatedStrings (separator:char) (terms:string) (source:string) (accessions:string) = OntologyAnnotation.fromAggregatedStrings separator terms source accessions - |> Array.map (Some >> (ProtocolParameter.make None)) + |> ResizeArray.map (Some >> (ProtocolParameter.make None)) /// Returns the aggregated ISATAb Ontology Annotation value, Accession number and ontology source from a list of ISAJson ProtocolParameter objects let toAggregatedStrings (separator:char) (oas : ProtocolParameter list) = diff --git a/src/Spreadsheet/Metadata/DesignDescriptors.fs b/src/Spreadsheet/Metadata/DesignDescriptors.fs index f694379c..3a7ba089 100644 --- a/src/Spreadsheet/Metadata/DesignDescriptors.fs +++ b/src/Spreadsheet/Metadata/DesignDescriptors.fs @@ -1,6 +1,6 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet -open ARCtrl.ISA +open ARCtrl open Comment open Remark open System.Collections.Generic diff --git a/src/Spreadsheet/Metadata/Factors.fs b/src/Spreadsheet/Metadata/Factors.fs index 5ea7d090..92f41b97 100644 --- a/src/Spreadsheet/Metadata/Factors.fs +++ b/src/Spreadsheet/Metadata/Factors.fs @@ -1,6 +1,8 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet -open ARCtrl.ISA +open ARCtrl +open ARCtrl.Helper +open ARCtrl.Process open Comment open Remark open System.Collections.Generic @@ -15,12 +17,11 @@ module Factors = let labels = [nameLabel;factorTypeLabel;typeTermAccessionNumberLabel;typeTermSourceREFLabel] let fromString name designType typeTermSourceREF typeTermAccessionNumber comments = - let factorType = OntologyAnnotation.fromString(?termName = designType,?tan = typeTermAccessionNumber, ?tsr = typeTermSourceREF) + let factorType = OntologyAnnotation.create(?name = designType,?tan = typeTermAccessionNumber, ?tsr = typeTermSourceREF) Factor.make - None (name) - (Option.fromValueWithDefault OntologyAnnotation.empty factorType) - (Option.fromValueWithDefault [||] comments) + (Option.fromValueWithDefault (OntologyAnnotation()) factorType) + (Option.fromValueWithDefault (ResizeArray()) comments) let fromSparseTable (matrix : SparseTable) = if matrix.ColumnCount = 0 && matrix.CommentKeys.Length <> 0 then @@ -34,7 +35,7 @@ module Factors = matrix.CommentKeys |> List.map (fun k -> Comment.fromString k (matrix.TryGetValueDefault("",(k,i)))) - |> Array.ofList + |> ResizeArray fromString (matrix.TryGetValue(nameLabel,i)) @@ -50,7 +51,7 @@ module Factors = factors |> List.iteri (fun i f -> let i = i + 1 - let ft = f.FactorType |> Option.defaultValue OntologyAnnotation.empty |> fun f -> OntologyAnnotation.toString(f,true) + let ft = f.FactorType |> Option.defaultValue (OntologyAnnotation()) |> fun f -> OntologyAnnotation.toString(f,true) do matrix.Matrix.Add ((nameLabel,i), (Option.defaultValue "" f.Name)) do matrix.Matrix.Add ((factorTypeLabel,i), ft.TermName) do matrix.Matrix.Add ((typeTermAccessionNumberLabel,i), ft.TermAccessionNumber) @@ -60,7 +61,7 @@ module Factors = | None -> () | Some c -> c - |> Array.iter (fun comment -> + |> ResizeArray.iter (fun comment -> let n,v = comment |> Comment.toString commentKeys <- n :: commentKeys matrix.Matrix.Add((n,i),v) diff --git a/src/Spreadsheet/Metadata/OntologyAnnotation.fs b/src/Spreadsheet/Metadata/OntologyAnnotation.fs index 678645ea..b0a64c06 100644 --- a/src/Spreadsheet/Metadata/OntologyAnnotation.fs +++ b/src/Spreadsheet/Metadata/OntologyAnnotation.fs @@ -1,6 +1,7 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet -open ARCtrl.ISA +open ARCtrl +open ARCtrl.Helper open Comment open Remark open System.Collections.Generic @@ -20,14 +21,13 @@ module OntologyAnnotationSection = matrix.CommentKeys |> List.map (fun k -> Comment.fromString k (matrix.TryGetValueDefault("",(k,i)))) - |> Array.ofList - |> Option.fromValueWithDefault [||] + |> ResizeArray - OntologyAnnotation.fromString( - ?termName = matrix.TryGetValue(label,i), + OntologyAnnotation( + ?name = matrix.TryGetValue(label,i), ?tsr = matrix.TryGetValue(labelTSR,i), ?tan = matrix.TryGetValue(labelTAN,i), - ?comments = comments + comments = comments ) ) @@ -42,15 +42,12 @@ module OntologyAnnotationSection = do matrix.Matrix.Add ((labelTAN,i), oa.TermAccessionNumber) do matrix.Matrix.Add ((labelTSR,i), oa.TermSourceREF) - match d.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) - ) + d.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} diff --git a/src/Spreadsheet/Metadata/OntologySourceReference.fs b/src/Spreadsheet/Metadata/OntologySourceReference.fs index 63df6929..a41022d3 100644 --- a/src/Spreadsheet/Metadata/OntologySourceReference.fs +++ b/src/Spreadsheet/Metadata/OntologySourceReference.fs @@ -1,7 +1,8 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet open FsSpreadsheet -open ARCtrl.ISA +open ARCtrl +open ARCtrl.Helper open System.Collections.Generic @@ -21,7 +22,7 @@ module OntologySourceReference = (file) (name) (version) - (Option.fromValueWithDefault [||] comments) + comments let fromSparseTable (matrix : SparseTable) = if matrix.ColumnCount = 0 && matrix.CommentKeys.Length <> 0 then @@ -35,7 +36,7 @@ module OntologySourceReference = matrix.CommentKeys |> List.map (fun k -> Comment.fromString k (matrix.TryGetValueDefault("",(k,i)))) - |> Array.ofList + |> ResizeArray fromString (matrix.TryGetValue(descriptionLabel,i)) @@ -56,15 +57,13 @@ module OntologySourceReference = do matrix.Matrix.Add ((versionLabel,i), (Option.defaultValue "" o.Version)) do matrix.Matrix.Add ((descriptionLabel,i), (Option.defaultValue "" o.Description)) - match o.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) - ) + + o.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} diff --git a/src/Spreadsheet/Metadata/Protocols.fs b/src/Spreadsheet/Metadata/Protocols.fs index 4132198b..0c6180c2 100644 --- a/src/Spreadsheet/Metadata/Protocols.fs +++ b/src/Spreadsheet/Metadata/Protocols.fs @@ -1,6 +1,7 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet -open ARCtrl.ISA +open ARCtrl +open ARCtrl.Process open Comment open Remark open System.Collections.Generic @@ -30,14 +31,14 @@ module Protocols = ] let fromString name protocolType typeTermAccessionNumber typeTermSourceREF description uri version parametersName parametersTermAccessionNumber parametersTermSourceREF componentsName componentsType componentsTypeTermAccessionNumber componentsTypeTermSourceREF comments = - let protocolType = OntologyAnnotation.fromString(?termName = protocolType,?tan = typeTermAccessionNumber,?tsr = typeTermSourceREF) - let parameters = ProtocolParameter.fromAggregatedStrings ';' parametersName parametersTermSourceREF parametersTermAccessionNumber |> List.ofArray + let protocolType = OntologyAnnotation.create(?name = protocolType,?tan = typeTermAccessionNumber,?tsr = typeTermSourceREF) + let parameters = ProtocolParameter.fromAggregatedStrings ';' parametersName parametersTermSourceREF parametersTermAccessionNumber |> List.ofSeq let components = Component.fromAggregatedStrings ';' componentsName componentsType componentsTypeTermSourceREF componentsTypeTermAccessionNumber Protocol.make None (name |> Option.map URI.fromString) - (Option.fromValueWithDefault OntologyAnnotation.empty protocolType) + (Option.fromValueWithDefault (OntologyAnnotation()) protocolType) (description) (uri |> Option.map URI.fromString) (version) @@ -49,7 +50,7 @@ module Protocols = let fromSparseTable (matrix : SparseTable) = if matrix.ColumnCount = 0 && matrix.CommentKeys.Length <> 0 then let comments = SparseTable.GetEmptyComments matrix - Protocol.create(Comments = List.ofArray comments) + Protocol.create(Comments = List.ofSeq comments) |> List.singleton else List.init matrix.ColumnCount (fun i -> @@ -83,7 +84,7 @@ module Protocols = protocols |> List.iteri (fun i p -> let i = i + 1 - let pt = p.ProtocolType |> Option.defaultValue OntologyAnnotation.empty |> fun pt -> OntologyAnnotation.toString(pt,true) + let pt = p.ProtocolType |> Option.defaultValue (OntologyAnnotation()) |> fun pt -> OntologyAnnotation.toString(pt,true) let pAgg = p.Parameters |> Option.defaultValue [] |> ProtocolParameter.toAggregatedStrings ';' let cAgg = p.Components |> Option.defaultValue [] |> Component.toAggregatedStrings ';' diff --git a/src/Spreadsheet/Metadata/Publication.fs b/src/Spreadsheet/Metadata/Publication.fs index fb1a1b64..22bd73e6 100644 --- a/src/Spreadsheet/Metadata/Publication.fs +++ b/src/Spreadsheet/Metadata/Publication.fs @@ -1,6 +1,7 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet -open ARCtrl.ISA +open ARCtrl +open ARCtrl.Helper open Comment open Remark open System.Collections.Generic @@ -18,14 +19,14 @@ module Publications = let labels = [pubMedIDLabel;doiLabel;authorListLabel;titleLabel;statusLabel;statusTermAccessionNumberLabel;statusTermSourceREFLabel] let fromString pubMedID doi author title status statusTermSourceREF statusTermAccessionNumber comments = - let status = OntologyAnnotation.fromString(?termName = status,?tan = statusTermAccessionNumber,?tsr = statusTermSourceREF) + let status = OntologyAnnotation(?name = status,?tan = statusTermAccessionNumber,?tsr = statusTermSourceREF) Publication.make (pubMedID |> Option.map URI.fromString) (doi) (author) (title) - (Option.fromValueWithDefault OntologyAnnotation.empty status) - (Option.fromValueWithDefault [||] comments) + (Option.fromValueWithDefault (OntologyAnnotation()) status) + comments let fromSparseTable (matrix : SparseTable) = if matrix.ColumnCount = 0 && matrix.CommentKeys.Length <> 0 then @@ -39,7 +40,7 @@ module Publications = matrix.CommentKeys |> List.map (fun k -> Comment.fromString k (matrix.TryGetValueDefault("",(k,i)))) - |> Array.ofList + |> ResizeArray fromString (matrix.TryGetValue(pubMedIDLabel,i)) @@ -58,7 +59,7 @@ module Publications = publications |> List.iteri (fun i p -> let i = i + 1 - let s = Option.defaultValue OntologyAnnotation.empty p.Status |> fun s -> OntologyAnnotation.toString (s,true) + let s = Option.defaultValue (OntologyAnnotation()) p.Status |> fun s -> OntologyAnnotation.toString (s,true) do matrix.Matrix.Add ((pubMedIDLabel,i), (Option.defaultValue "" p.PubMedID)) do matrix.Matrix.Add ((doiLabel,i), (Option.defaultValue "" p.DOI)) do matrix.Matrix.Add ((authorListLabel,i), (Option.defaultValue "" p.Authors)) @@ -67,15 +68,12 @@ module Publications = do matrix.Matrix.Add ((statusTermAccessionNumberLabel,i), s.TermAccessionNumber) do matrix.Matrix.Add ((statusTermSourceREFLabel,i), s.TermSourceREF) - 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} diff --git a/src/Spreadsheet/Metadata/SparseTable.fs b/src/Spreadsheet/Metadata/SparseTable.fs index 1c68dd93..a8679a36 100644 --- a/src/Spreadsheet/Metadata/SparseTable.fs +++ b/src/Spreadsheet/Metadata/SparseTable.fs @@ -1,7 +1,6 @@ -namespace ARCtrl.ISA.Spreadsheet +namespace ARCtrl.Spreadsheet -open ARCtrl.ISA -open ARCtrl.ISA.Aux +open ARCtrl open System.Collections.Generic open FsSpreadsheet.DSL open FsSpreadsheet @@ -158,7 +157,7 @@ type SparseTable = (SparseRow.fromValues (Comment.wrapCommentKey key :: List.init (matrix.ColumnCount - 1) (fun i -> matrix.TryGetValueDefault("",(key,i + 1))))) } - static member GetEmptyComments(matrix) : Comment [] = + static member GetEmptyComments(matrix) : ResizeArray = matrix.CommentKeys - |> List.map (fun key -> Comment.create(Name = key)) - |> Array.ofList \ No newline at end of file + |> List.map (fun key -> Comment.create(name = key)) + |> ResizeArray \ No newline at end of file diff --git a/src/Spreadsheet/Metadata/Study.fs b/src/Spreadsheet/Metadata/Study.fs index 4fa8af2c..23c51e1e 100644 --- a/src/Spreadsheet/Metadata/Study.fs +++ b/src/Spreadsheet/Metadata/Study.fs @@ -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 +open ARCtrl.Process.Conversion module Studies = @@ -86,13 +89,12 @@ module Studies = do matrix.Matrix.Add ((publicReleaseDateLabel,i), (Option.defaultValue "" study.PublicReleaseDate)) do matrix.Matrix.Add ((fileNameLabel,i), processedFileName) - if Array.isEmpty study.Comments |> not then - study.Comments - |> Array.iter (fun comment -> - let n,v = comment |> Comment.toString - commentKeys <- n :: commentKeys - matrix.Matrix.Add((n,i),v) - ) + study.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} @@ -105,6 +107,8 @@ module Studies = |> StudyInfo.ToSparseTable |> SparseTable.ToRows + /// FACTORS AND PROTOCOLS ARE NOT USED ANYMORE, Lukas, 21.03.24 + // We made these changes as merging duplicated top level metadata with the underlying Table sequence is time consuming, complex and error prone let fromParts (studyInfo:StudyInfo) (designDescriptors:OntologyAnnotation list) (publications: Publication list) (factors: Factor list) (assays: ArcAssay list) (protocols : Protocol list) (contacts: Person list) = let assayIdentifiers = assays |> List.map (fun assay -> assay.Identifier) ArcStudy.make @@ -113,13 +117,12 @@ module Studies = (Option.fromValueWithDefault "" studyInfo.Description) (Option.fromValueWithDefault "" studyInfo.SubmissionDate) (Option.fromValueWithDefault "" studyInfo.PublicReleaseDate) - (Array.ofList publications) - (Array.ofList contacts) - (Array.ofList designDescriptors) - (protocols |> List.map ArcTable.fromProtocol |> ResizeArray) + (ResizeArray publications) + (ResizeArray contacts) + (ResizeArray designDescriptors) + (ResizeArray()) (ResizeArray(assayIdentifiers)) - (Array.ofList factors) - (Array.ofList studyInfo.Comments) + (ResizeArray studyInfo.Comments) |> fun arcstudy -> if arcstudy.isEmpty && arcstudy.Identifier = "" then None else Some (arcstudy,assays) @@ -163,18 +166,19 @@ module Studies = let toRows (study : ArcStudy) (assays : ArcAssay list option) = let protocols = study.Tables |> Seq.collect (fun p -> p.GetProtocols()) |> List.ofSeq + let factors = study.Tables |> Seq.collect (fun f -> f.GetProcesses() |> ProcessSequence.getFactors) |> List.ofSeq let assays = assays |> Option.defaultValue (study.GetRegisteredAssaysOrIdentifier() |> List.ofSeq) seq { yield! StudyInfo.toRows study yield SparseRow.fromValues [designDescriptorsLabel] - yield! DesignDescriptors.toRows (Some designDescriptorsLabelPrefix) (List.ofArray study.StudyDesignDescriptors) + yield! DesignDescriptors.toRows (Some designDescriptorsLabelPrefix) (List.ofSeq study.StudyDesignDescriptors) yield SparseRow.fromValues [publicationsLabel] - yield! Publications.toRows (Some publicationsLabelPrefix) (List.ofArray study.Publications) + yield! Publications.toRows (Some publicationsLabelPrefix) (List.ofSeq study.Publications) yield SparseRow.fromValues [factorsLabel] - yield! Factors.toRows (Some factorsLabelPrefix) (List.ofArray study.Factors) + yield! Factors.toRows (Some factorsLabelPrefix) factors yield SparseRow.fromValues [assaysLabel] yield! Assays.toRows (Some assaysLabelPrefix) assays @@ -183,5 +187,5 @@ module Studies = yield! Protocols.toRows (Some protocolsLabelPrefix) protocols yield SparseRow.fromValues [contactsLabel] - yield! Contacts.toRows (Some contactsLabelPrefix) (List.ofArray study.Contacts) + yield! Contacts.toRows (Some contactsLabelPrefix) (List.ofSeq study.Contacts) } \ No newline at end of file