Skip to content

Commit

Permalink
add datamap contract handling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed May 14, 2024
1 parent db9fbf8 commit 890dfd6
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 14 deletions.
52 changes: 52 additions & 0 deletions tests/ARCtrl/ARCtrl.Contracts.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,58 @@ let tests_tryFromContract = testList "tryFromContract" [
|]
let investigation = contracts |> Array.choose ArcInvestigation.tryFromReadContract
Expect.hasLength investigation 1 ""
testCase "DataMap" <| fun _ ->
let fswb = TestObjects.Contract.ISA.SimpleISA.Assay.proteomeDatamapWB
let assayName = "myAssay"
let contracts = [|
Contract.create(
READ,
$"assays/{assayName}/isa.datamap.xlsx",
DTOType.ISA_Datamap,
DTO.Spreadsheet fswb
)
|]
let datamap = ARCAux.getAssayDataMapFromContracts assayName contracts
Expect.isSome datamap "Datamap should have been parsed"
testCase "DataMap_WrongIdentifier" <| fun _ ->
let fswb = TestObjects.Contract.ISA.SimpleISA.Assay.proteomeDatamapWB
let assayName = "myAssay"
let contracts = [|
Contract.create(
READ,
$"assays/{assayName}/isa.datamap.xlsx",
DTOType.ISA_Datamap,
DTO.Spreadsheet fswb
)
|]
let datamap = ARCAux.getAssayDataMapFromContracts "wrongAssay" contracts
Expect.isNone datamap "Datamap should not have been parsed"
testCase "DataMap_WrongType" <| fun _ ->
let fswb = TestObjects.Contract.ISA.SimpleISA.Assay.proteomeDatamapWB
let assayName = "myAssay"
let contracts = [|
Contract.create(
READ,
$"assays/{assayName}/isa.datamap.xlsx",
DTOType.ISA_Assay,
DTO.Spreadsheet fswb
)
|]
let datamap = ARCAux.getAssayDataMapFromContracts assayName contracts
Expect.isNone datamap "Datamap should not have been parsed"
testCase "DataMap_WrongPath" <| fun _ ->
let fswb = TestObjects.Contract.ISA.SimpleISA.Assay.proteomeDatamapWB
let assayName = "myAssay"
let contracts = [|
Contract.create(
READ,
$"studies/{assayName}/isa.datamap.xlsx",
DTOType.ISA_Datamap,
DTO.Spreadsheet fswb
)
|]
let datamap = ARCAux.getAssayDataMapFromContracts assayName contracts
Expect.isNone datamap "Datamap should not have been parsed"
]

let tests_gitContracts = testList "gitContracts" [
Expand Down
78 changes: 74 additions & 4 deletions tests/ARCtrl/ARCtrl.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let private simpleISAContracts =
|]

let private tests_read_contracts = testList "read_contracts" [
ptestCase "simpleISA" (fun () -> // set to pending, until performance issues in Study.fromFsWorkbook is resolved.
testCase "simpleISA" (fun () ->
let arc = ARC()
arc.SetISAFromContracts simpleISAContracts
Expect.isSome arc.ISA "isa should be filled out"
Expand All @@ -70,15 +70,17 @@ let private tests_read_contracts = testList "read_contracts" [
Expect.equal inv.Studies.Count 2 "should have read two studies"
let study1 = inv.Studies.[0]
Expect.equal study1.Identifier Study.BII_S_1.studyIdentifier "study 1 identifier should have been read from study contract"
Expect.equal study1.TableCount 8 "study 1 should have the 7 tables from investigation plus one extra. One table should be overwritten."

Expect.equal study1.TableCount 2 "study 1 should have the 2 tables. Top level Metadata tables are ignored."
//Expect.equal study1.TableCount 8 "study 1 should have the 7 tables from investigation plus one extra. One table should be overwritten."

Expect.equal study1.RegisteredAssays.Count 3 "study 1 should have read three assays"
let assay1 = study1.RegisteredAssays.[0]
Expect.equal assay1.Identifier Assay.Proteome.assayIdentifier "assay 1 identifier should have been read from assay contract"
Expect.equal assay1.TableCount 1 "assay 1 should have read one table"

)
ptestCase "StudyAssayOnlyRegistered" (fun () -> // set to pending, until performance issues in Study.fromFsWorkbook is resolved.
testCase "StudyAssayOnlyRegistered" (fun () -> // set to pending, until performance issues in Study.fromFsWorkbook is resolved.
let arc = ARC()
arc.SetISAFromContracts([|
SimpleISA.Investigation.investigationReadContract
Expand All @@ -94,7 +96,8 @@ let private tests_read_contracts = testList "read_contracts" [
Expect.equal inv.VacantStudyIdentifiers.Count 1 "should have one vacant study identifier"
let study1 = inv.Studies.[0]
Expect.equal study1.Identifier Study.BII_S_1.studyIdentifier "study 1 identifier should have been read from study contract"
Expect.equal study1.TableCount 8 "study 1 should have the 7 tables from investigation plus one extra. One table should be overwritten."
Expect.equal study1.TableCount 2 "study 1 should have the 2 tables. Top level Metadata tables are ignored."
//Expect.equal study1.TableCount 8 "study 1 should have the 7 tables from investigation plus one extra. One table should be overwritten."

Expect.equal study1.RegisteredAssays.Count 1 "study 1 should have read one assay"
Expect.equal study1.RegisteredAssayIdentifierCount 3 "study 1 should have read three registered assay identifiers"
Expand Down Expand Up @@ -148,6 +151,23 @@ let private tests_read_contracts = testList "read_contracts" [
(Array.create 2 (CompositeCell.createFreeText UpdateAssayWithStudyProtocol.description))
"Description value was not taken correctly"
)
testCase "SimpleISA_WithDataset" (fun _ ->
let contracts = Array.append simpleISAContracts [|SimpleISA.Assay.proteomeDatamapContract|]

let arc = ARC()
arc.SetISAFromContracts contracts

let inv = Expect.wantSome arc.ISA "Arc should have investigation"
let a1 = inv.GetAssay(SimpleISA.Assay.proteomeIdentifer)
let datamap = Expect.wantSome a1.DataMap "Proteome Assay was supposed to have datamap"

Expect.equal 2 datamap.Table.RowCount "Datamap was not read correctly"

let a2 = inv.GetAssay(SimpleISA.Assay.metabolomeIdentifer)
Expect.isNone a2.DataMap "Metabolome Assay was not supposed to have datamap"

)

]

let private tests_writeContracts = testList "write_contracts" [
Expand Down Expand Up @@ -194,6 +214,33 @@ let private tests_writeContracts = testList "write_contracts" [
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/isa.assay.xlsx" && c.DTOType.IsSome && c.DTOType.Value = Contract.DTOType.ISA_Assay) "assay file exisiting but has wrong DTO type"

)
testCase "assayWithDatamap" (fun _ ->
let inv = ArcInvestigation("MyInvestigation", "BestTitle")
let a = inv.InitAssay("MyAssay")
let dm = DataMap.init()
a.DataMap <- Some dm
let arc = ARC(isa = inv)
let contracts = arc.GetWriteContracts()
let contractPathsString = contracts |> Array.map (fun c -> c.Path) |> String.concat ", "
Expect.equal contracts.Length 10 $"Should contain more contracts as base folders but contained: {contractPathsString}"

// Base
Expect.exists contracts (fun c -> c.Path = "workflows/.gitkeep") "Contract for workflows folder missing"
Expect.exists contracts (fun c -> c.Path = "runs/.gitkeep") "Contract for runs folder missing"
Expect.exists contracts (fun c -> c.Path = "assays/.gitkeep") "Contract for assays folder missing"
Expect.exists contracts (fun c -> c.Path = "studies/.gitkeep") "Contract for studies folder missing"
Expect.exists contracts (fun c -> c.Path = "isa.investigation.xlsx") "Contract for investigation folder missing"
Expect.exists contracts (fun c -> c.Path = "isa.investigation.xlsx" && c.DTOType.IsSome && c.DTOType.Value = Contract.DTOType.ISA_Investigation) "Contract for investigation existing but has wrong DTO type"

// Assay folder
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/README.md") "assay readme missing"
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/protocols/.gitkeep") "assay protocols folder missing"
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/dataset/.gitkeep") "assay dataset folder missing"
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/isa.assay.xlsx") "assay file missing"
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/isa.assay.xlsx" && c.DTOType.IsSome && c.DTOType.Value = Contract.DTOType.ISA_Assay) "assay file existing but has wrong DTO type"
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/isa.datamap.xlsx") "assay datamap file missing"
Expect.exists contracts (fun c -> c.Path = "assays/MyAssay/isa.datamap.xlsx" && c.DTOType.IsSome && c.DTOType.Value = Contract.DTOType.ISA_Datamap) "assay datamap file existing but has wrong DTO type"
)
testCase "sameAssayAndStudyName" (fun _ ->
let inv = ArcInvestigation("MyInvestigation", "BestTitle")
inv.InitStudy("MyAssay").InitRegisteredAssay("MyAssay") |> ignore
Expand Down Expand Up @@ -315,6 +362,29 @@ let private tests_updateContracts = testList "update_contracts" [
let nextContracts = arc.GetUpdateContracts()
Expect.equal nextContracts.Length 0 "Should contain no contracts as there are no changes"
)
testCase "simpleISA_Datamap_NoChanges" (fun _ ->
let arc = ARC()
let readContracts = Array.append simpleISAContracts [|SimpleISA.Assay.proteomeDatamapContract|]
arc.SetISAFromContracts readContracts
let contracts = arc.GetUpdateContracts()
Expect.equal contracts.Length 0 "Should contain no contracts as there are no changes"
)
testCase "simpleISA_Datamap_Changed" (fun _ ->
let arc = ARC()
let readContracts = Array.append simpleISAContracts [|SimpleISA.Assay.proteomeDatamapContract|]
arc.SetISAFromContracts readContracts
let isa = arc.ISA.Value

let dm = Expect.wantSome (isa.GetAssay(SimpleISA.Assay.proteomeIdentifer).DataMap) "Assay should have datamap"
dm.Values.[(0,1)] <- CompositeCell.createDataFromString("Hello")

let contracts = arc.GetUpdateContracts()
Expect.equal contracts.Length 1 $"Should contain only assay datamap change contract"
let expectedPath = Identifier.Assay.datamapFileNameFromIdentifier SimpleISA.Assay.proteomeIdentifer
Expect.equal contracts.[0].Path expectedPath "Should be the assay datamap file"
let nextContracts = arc.GetUpdateContracts()
Expect.equal nextContracts.Length 0 "Should contain no contracts as there are no changes"
)
testCase "simpleISA_StudyChange" (fun _ ->
let arc = ARC()
arc.SetISAFromContracts simpleISAContracts
Expand Down
12 changes: 7 additions & 5 deletions tests/Core/ArcAssay.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let private test_create =
let tables = ResizeArray([ArcTable.init("MyTable1")])
let performers = ResizeArray [|Person(firstName = "Kevin", lastName = "Frey")|]
let comments = ResizeArray [|Comment.create("Comment Name")|]
let actual = ArcAssay(identifier, oa_mt, oa_tt, technologyPlatform, tables, performers, comments)
let actual = ArcAssay(identifier, oa_mt, oa_tt, technologyPlatform, tables, performers = performers, comments = comments)
Expect.equal actual.Identifier identifier "identifier"
Expect.equal actual.MeasurementType (Some oa_mt) "MeasurementType"
Expect.equal actual.TechnologyType (Some oa_tt) "TechnologyType"
Expand All @@ -92,7 +92,7 @@ let private test_create =
let tables = ResizeArray([ArcTable.init("MyTable1")])
let performers = ResizeArray [|Person.create(firstName = "Kevin", lastName = "Frey")|]
let comments = ResizeArray [|Comment.create("Comment Name")|]
let actual = ArcAssay(identifier, oa_mt, oa_tt, technologyPlatform, tables, performers, comments)
let actual = ArcAssay(identifier, oa_mt, oa_tt, technologyPlatform, tables, performers = performers, comments = comments)
Expect.equal actual.Identifier identifier "identifier"
Expect.equal actual.MeasurementType (Some oa_mt) "MeasurementType"
Expect.equal actual.TechnologyType (Some oa_tt) "TechnologyType"
Expand All @@ -108,7 +108,7 @@ let private test_create =
let tables = ResizeArray([ArcTable.init("MyTable1")])
let performers = ResizeArray[|Person.create(firstName = "Kevin", lastName = "Frey")|]
let comments = ResizeArray[|Comment.create("Comment Name")|]
let actual = ArcAssay.create(identifier, oa_mt, oa_tt, technologyPlatform, tables, performers, comments)
let actual = ArcAssay.create(identifier, oa_mt, oa_tt, technologyPlatform, tables, performers = performers, comments = comments)
Expect.equal actual.Identifier identifier "identifier"
Expect.equal actual.MeasurementType (Some oa_mt) "MeasurementType"
Expect.equal actual.TechnologyType (Some oa_tt) "TechnologyType"
Expand Down Expand Up @@ -142,6 +142,7 @@ let private test_create =
technologyType
technologyPlatform
tables
None
performers
comments

Expand Down Expand Up @@ -507,8 +508,8 @@ let private tests_UpdateBy = testList "UpdateBy" [
OntologyAnnotation("MyTechnologyType"),
OntologyAnnotation("MyTechnologyPlatform"),
ResizeArray([ArcTable.init("MyTable")]),
ResizeArray [|Person(firstName="Kevin", lastName="Frey")|],
ResizeArray [|Comment(name="CommentName", value="CommentValue")|]
performers = ResizeArray [|Person(firstName="Kevin", lastName="Frey")|],
comments = ResizeArray [|Comment(name="CommentName", value="CommentValue")|]
)
testCase "UpdateBy, full replace" <| fun _ ->
let actual = create_testAssay()
Expand Down Expand Up @@ -611,6 +612,7 @@ let private tests_GetHashCode = testList "GetHashCode" [
(OntologyAnnotation "tt" |> Some)
(OntologyAnnotation "tp" |> Some)
(ResizeArray([ArcTable.init("My Table"); ArcTable.Tests.create_testTable()]))
None
(ResizeArray [|Person(firstName="John",lastName="Doe"); Person(firstName="Jane",lastName="Doe")|])
(ResizeArray [|Comment("Hello", "World"); Comment("ByeBye", "World") |])
testCase "passing" <| fun _ ->
Expand Down
2 changes: 2 additions & 0 deletions tests/Core/ArcStudy.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ let private test_create =
contacts
studyDesignDescriptors
tables
None
assay_identifiers
comments

Expand Down Expand Up @@ -452,6 +453,7 @@ let private tests_GetHashCode = testList "GetHashCode" [
(ResizeArray [|Person(firstName="John",lastName="Doe"); Person(firstName="Jane",lastName="Doe")|])
(ResizeArray [|OntologyAnnotation(); OntologyAnnotation(); OntologyAnnotation("Name", "tsr", "Tan")|])
(ResizeArray([ArcTable.init("My Table"); ArcTable.Tests.create_testTable()]))
None
(ResizeArray(["Registered Assay1"; "Registered Assay2"]))
(ResizeArray [|Comment("Hello", "World"); Comment("ByeBye", "World") |])
testCase "passing" <| fun _ ->
Expand Down
4 changes: 2 additions & 2 deletions tests/Json/Assay.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module Helper =
OntologyAnnotation("TT", "MS", "MS:696969"),
OntologyAnnotation("TP", "MS", "MS:123456", ResizeArray [Comment.create("Hello","Space")]),
ResizeArray([Tests.ArcTable.Helper.create_filled(); ArcTable.init("My Second Table")]),
ResizeArray [|Person.create(firstName="Kevin", lastName="Frey")|],
ResizeArray [|Comment.create("Hello", "World")|]
performers = ResizeArray [|Person.create(firstName="Kevin", lastName="Frey")|],
comments = ResizeArray [|Comment.create("Hello", "World")|]
)

let compare =
Expand Down
4 changes: 2 additions & 2 deletions tests/Json/Study.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module Helper =
ResizeArray [|Person.create(firstName="Kevin", lastName="Frey", phone="023382093810")|],
ResizeArray [|OntologyAnnotation(); OntologyAnnotation()|],
ResizeArray [ArcTable.Helper.create_filled(); ArcTable.init("Table 2")],
ResizeArray ["Assay 1"; "Assay 2"],
ResizeArray [|Comment.create("Hello", "World")|]
registeredAssayIdentifiers = ResizeArray ["Assay 1"; "Assay 2"],
comments = ResizeArray [|Comment.create("Hello", "World")|]
)

let compareFields =
Expand Down
27 changes: 26 additions & 1 deletion tests/TestingUtils/TestObjects.Contract/ISA.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module SimpleISA =

module Assay =

let proteomeIdentifer = Assay.Proteome.assayIdentifier
let proteomeMetadataWorksheet = Assay.Proteome.assayMetadata
let proteomeWsName = "Measurement"
let proteomeTable =
Expand All @@ -37,6 +38,31 @@ module SimpleISA =
dtoType = DTOType.ISA_Assay,
dto = DTO.Spreadsheet proteomeWB)

let proteomeDatamapTable =
DataMap.initWorksheet "Proteome"
[
DataMap.Data.appendDataColumn 2
DataMap.Explication.appendMeanColumn 2
DataMap.Unit.appendPPMColumn 2
DataMap.ObjectType.appendFloatColumn 2
DataMap.Description.appendDescriptionColumn 2
DataMap.GeneratedBy.appendGeneratedByColumn 2
]

let proteomeDatamapWB =
let wb = new FsWorkbook()
wb.AddWorksheet(proteomeDatamapTable)
wb

let proteomeDatamapContract =
Contract.create(
Operation.READ,
path = Identifier.Assay.datamapFileNameFromIdentifier Assay.Proteome.assayIdentifier,
dtoType = DTOType.ISA_Datamap,
dto = DTO.Spreadsheet proteomeDatamapWB)


let metabolomeIdentifer = Assay.Metabolome.assayIdentifier
let metabolomeMetadataWorksheet = Assay.Metabolome.assayMetadata

let metabolomeWB =
Expand Down Expand Up @@ -125,7 +151,6 @@ module SimpleISA =
dtoType = DTOType.ISA_Investigation,
dto = DTO.Spreadsheet Investigation.BII_I_1.fullInvestigation)


module UpdateAssayWithStudyProtocol =

let assayIdentifier = "MyAssay"
Expand Down

0 comments on commit 890dfd6

Please sign in to comment.