Skip to content

Commit

Permalink
apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Nov 15, 2023
1 parent 996b465 commit f8a4ceb
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 49 deletions.
5 changes: 2 additions & 3 deletions src/ISA/ISA/ARCtrl.ISA.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="ArcTypes\ArcTables.fs" />
<Compile Include="ArcTypes\ArcTypes.fs" />
<Compile Include="ArcTypes\IdentifierSetters.fs" />
<Compile Include="UIHelper.fs" />
<Compile Include="Builder\Types.fs" />
<Compile Include="Builder\ProcessBuilder.fs" />
<Compile Include="Builder\AssayBuilder.fs" />
Expand All @@ -63,9 +64,7 @@
<ItemGroup>
<ProjectReference Include="..\..\FileSystem\ARCtrl.FileSystem.fsproj" />
</ItemGroup>
<ItemGroup>
<Content Include="*.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" />
</ItemGroup>
<ItemGroup />
<PropertyGroup>
<Authors>nfdi4plants, Lukas Weil, Kevin Frey, Kevin Schneider, Oliver Muas</Authors>
<Description>ARC and ISA compliant experimental metadata toolkit in F#. This project is meant as an easy means to open, manipulate and save ISA (Investigation,Study,Assay) metadata files in the dotnet environment.</Description>
Expand Down
20 changes: 16 additions & 4 deletions src/ISA/ISA/ArcTypes/ArcTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,27 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, values: Syste
fun (table:ArcTable) ->
table.TryGetCellAt(column, row)

member this.IterColumns(mapping: CompositeColumn -> unit) =
member this.IterColumns(action: CompositeColumn -> unit) =
for columnIndex in 0 .. (this.ColumnCount-1) do
let column = this.GetColumn columnIndex
mapping column
action column

member this.IteriColumns(mapping: int -> CompositeColumn -> unit) =
static member iterColumns(action: CompositeColumn -> unit) =
fun (table:ArcTable) ->
let copy = table.Copy()
copy.IterColumns(action)
copy

member this.IteriColumns(action: int -> CompositeColumn -> unit) =
for columnIndex in 0 .. (this.ColumnCount-1) do
let column = this.GetColumn columnIndex
mapping columnIndex column
action columnIndex column

static member iteriColumns(action: int -> CompositeColumn -> unit) =
fun (table:ArcTable) ->
let copy = table.Copy()
copy.IteriColumns(action)
copy

// - Cell API - //
// TODO: And then directly a design question. Is a column with rows containing both CompositeCell.Term and CompositeCell.Unitized allowed?
Expand Down
13 changes: 0 additions & 13 deletions src/ISA/ISA/ArcTypes/CompositeCell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ type CompositeCell =
member this.isTerm = match this with | Term _ -> true | _ -> false
member this.isFreeText = match this with | FreeText _ -> true | _ -> false

/// <summary>
/// Updates current CompositeCell with information from OntologyAnnotation.
///
/// For `Term`, OntologyAnnotation (oa) is fully set. For `Unitized`, oa is set as unit while value is untouched.
/// For `FreeText` oa.NameText is set.
/// </summary>
/// <param name="oa"></param>
member this.UpdateWithOA(oa:OntologyAnnotation) =
match this with
| CompositeCell.Term _ -> CompositeCell.createTerm oa
| CompositeCell.Unitized (v,_) -> CompositeCell.createUnitized (v,oa)
| CompositeCell.FreeText _ -> CompositeCell.createFreeText oa.NameText

/// <summary>
/// This returns the default empty cell from an existing CompositeCell.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/ISA/ISA/ArcTypes/CompositeColumn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ type CompositeColumn = {

/// <summary>
/// Simple predictor for empty default cells.
///
/// Currently uses majority vote for the column to decide cell type.
/// </summary>
member this.PredictNewColumnCell() =
member this.GetDefaultEmptyCell() =
if not this.Header.IsTermColumn then
CompositeCell.emptyFreeText
else
Expand Down
20 changes: 10 additions & 10 deletions src/ISA/ISA/ArcTypes/CompositeHeader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ type CompositeHeader =
| Characteristic oa -> oa
| Component oa -> oa
| ProtocolType -> OntologyAnnotation.fromString(this.ToString(), tan=this.GetFeaturedColumnAccession)
| ProtocolREF
| ProtocolDescription
| ProtocolUri
| ProtocolVersion
| Performer
| Date
| Input _
| Output _
| FreeText _ ->
OntologyAnnotation.fromString (this.ToString())
| ProtocolREF -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| ProtocolDescription -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| ProtocolUri -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| ProtocolVersion -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| Performer -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| Date -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| Input _ -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| Output _ -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
| FreeText _ -> OntologyAnnotation.fromString (this.ToString()) // use owl ontology in the future
// owl ontology: https://github.com/nfdi4plants/ARC_ontology/blob/main/ARC_v2.0.owl

/// <summary>
/// Tries to create a `CompositeHeader` from a given string.
Expand Down
16 changes: 16 additions & 0 deletions src/ISA/ISA/UIHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module ARCtrl.ISA.UIHelper

module CompositeCell =
/// <summary>
/// Updates current CompositeCell with information from OntologyAnnotation.
///
/// For `Term`, OntologyAnnotation (oa) is fully set. For `Unitized`, oa is set as unit while value is untouched.
/// For `FreeText` oa.NameText is set.
/// </summary>
/// <param name="oa"></param>
/// <param name="cell"></param>
let updateWithOA (oa:OntologyAnnotation) (cell: CompositeCell) =
match cell with
| CompositeCell.Term _ -> CompositeCell.createTerm oa
| CompositeCell.Unitized (v,_) -> CompositeCell.createUnitized (v,oa)
| CompositeCell.FreeText _ -> CompositeCell.createFreeText oa.NameText
38 changes: 20 additions & 18 deletions tests/ISA/ISA.Tests/CompositeCell.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,25 @@ let private tests_GetContent = testList "GetContent" [

]

let private tests_UpdateWithOA = testList "UpdateWithOA" [
let testOntologyAnnotation = OntologyAnnotation.fromString("New OA", "NEW", "NEW:00001")
testCase "Term" <| fun _ ->
let cc = CompositeCell.createTermFromString("TestTerm", "TEST", "TEST:00001")
let actual = cc.UpdateWithOA testOntologyAnnotation
let expected = CompositeCell.createTermFromString(testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort)
Expect.equal actual expected ""
testCase "Unitized" <| fun _ ->
let cc = CompositeCell.createUnitizedFromString("12", "TestTerm", "TEST", "TEST:00001")
let actual = cc.UpdateWithOA testOntologyAnnotation
let expected = CompositeCell.createUnitizedFromString("12", testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort)
Expect.equal actual expected ""
testCase "FreeText" <| fun _ ->
let cc = CompositeCell.createFreeText("TestTerm")
let actual = cc.UpdateWithOA testOntologyAnnotation
let expected = CompositeCell.createFreeText(testOntologyAnnotation.NameText)
Expect.equal actual expected ""
let private tests_UIHelper = testList "UIHelper" [
testList "UpdateWithOA" [
let testOntologyAnnotation = OntologyAnnotation.fromString("New OA", "NEW", "NEW:00001")
testCase "Term" <| fun _ ->
let cc = CompositeCell.createTermFromString("TestTerm", "TEST", "TEST:00001")
let actual = cc |> UIHelper.CompositeCell.updateWithOA testOntologyAnnotation
let expected = CompositeCell.createTermFromString(testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort)
Expect.equal actual expected ""
testCase "Unitized" <| fun _ ->
let cc = CompositeCell.createUnitizedFromString("12", "TestTerm", "TEST", "TEST:00001")
let actual = cc |> UIHelper.CompositeCell.updateWithOA testOntologyAnnotation
let expected = CompositeCell.createUnitizedFromString("12", testOntologyAnnotation.NameText, testOntologyAnnotation.TermSourceREFString, testOntologyAnnotation.TermAccessionShort)
Expect.equal actual expected ""
testCase "FreeText" <| fun _ ->
let cc = CompositeCell.createFreeText("TestTerm")
let actual = cc |> UIHelper.CompositeCell.updateWithOA testOntologyAnnotation
let expected = CompositeCell.createFreeText(testOntologyAnnotation.NameText)
Expect.equal actual expected ""
]
]

let main =
Expand All @@ -179,5 +181,5 @@ let main =
tests_create
tests_ToString
tests_GetContent
tests_UpdateWithOA
tests_UIHelper
]

0 comments on commit f8a4ceb

Please sign in to comment.