From b40490cf94e600ed172accfa597d726438d8093b Mon Sep 17 00:00:00 2001 From: HLWeil Date: Wed, 21 Feb 2024 12:44:40 +0100 Subject: [PATCH] fix querymodel value getting --- src/ARCtrl.QueryModel/ArcTables.fs | 110 +++++++++++++---------- tests/ARCtrl.Querymodel.Tests/TestARC.fs | 24 ++++- 2 files changed, 82 insertions(+), 52 deletions(-) diff --git a/src/ARCtrl.QueryModel/ArcTables.fs b/src/ARCtrl.QueryModel/ArcTables.fs index a4e8ca8..bfad169 100644 --- a/src/ARCtrl.QueryModel/ArcTables.fs +++ b/src/ARCtrl.QueryModel/ArcTables.fs @@ -142,7 +142,6 @@ module ArcTables = ) |> ResizeArray.distinctBy (fun n -> n.Name) - /// Returns the names of all nodes for which the predicate reutrns true static member getNodesBy (predicate : IOType -> bool) (ps : #ArcTables) = ps.Tables @@ -211,6 +210,40 @@ module ArcTables = loop (ArcTables.getFinalOutputs ps |> List.ofSeq) [] + static member getPreviousNodesBy (node : string) (ps : #ArcTables) = + + let rec collectBackwardNodes nodes = + let newNodes = + ps.Tables + |> Seq.collect (fun sheet -> + sheet.Rows + |> Seq.choose (fun r -> if List.contains r.Output nodes then Some r.Input else None) + ) + |> Seq.toList + |> List.append nodes + |> List.distinct + + if newNodes = nodes then nodes + else collectBackwardNodes newNodes + + collectBackwardNodes [node] + + static member getSucceedingNodesBy (node : string) (ps : #ArcTables) = + let rec collectForwardNodes nodes = + let newNodes = + ps.Tables + |> Seq.collect (fun sheet -> + sheet.Rows + |> Seq.choose (fun r -> if List.contains r.InputName nodes then Some r.OutputName else None) + ) + |> Seq.toList + |> List.append nodes + |> List.distinct + + if newNodes = nodes then nodes + else collectForwardNodes newNodes + collectForwardNodes [node] + /// Returns the names of all nodes processSequence, which are connected to the given node and for which the predicate returns true static member getNodesOfBy (predicate : IOType -> bool) (node : string) (ps : #ArcTables) = ArcTables.getSubTreeOf node ps @@ -487,77 +520,58 @@ module ArcTables = let ps = if ProtocolName.IsSome then ArcTables.onlyValuesOfProtocol this ProtocolName.Value else this ps.Values().Components() - /// Returns all values in the process sequence, that are connected to the given node - /// - /// If a protocol name is given, returns only the values of the processes that implement this protocol - member this.ValuesOf(node : string, ?ProtocolName : string) = - match ProtocolName with - | Some ps -> - let connectedNodes = this.NodesOf node - let ps = ArcTables.onlyValuesOfProtocol this ps - connectedNodes - |> ResizeArray.collect (fun n -> - ps.ValuesOf(n) - ) - |> ResizeArray.distinct - |> ValueCollection - | None -> - (ArcTables.getPreviousValuesOf this node).Values @ (ArcTables.getSucceedingValuesOf this node).Values - |> ValueCollection - - /// Returns all values in the process sequence, that are connected to the given node - /// - /// If a protocol name is given, returns only the values of the processes that implement this protocol - member this.ValuesOf(node : QNode, ?ProtocolName : string) = - this.ValuesOf(node.Name, ?ProtocolName = ProtocolName) - /// Returns all values in the process sequence, that are connected to the given node and come before it in the sequence - /// - /// If a protocol name is given, returns only the values of the processes that implement this protocol member this.PreviousValuesOf(node : string, ?ProtocolName) = match ProtocolName with | Some ps -> - let connectedNodes = this.NodesOf node + let previousNodes = ArcTables.getPreviousNodesBy node this let ps = ArcTables.onlyValuesOfProtocol this ps - connectedNodes - |> ResizeArray.collect (fun n -> + previousNodes + |> Seq.collect (fun n -> ps.PreviousValuesOf(n) - ) - |> ResizeArray.distinct + ) |> ValueCollection - | None -> + | None -> ArcTables.getPreviousValuesOf this node - - /// Returns all values in the process sequence, that are connected to the given node and come before it in the sequence - /// - /// If a protocol name is given, returns only the values of the processes that implement this protocol - member this.PreviousValuesOf(node : QNode, ?ProtocolName) = - this.PreviousValuesOf(node.Name, ?ProtocolName = ProtocolName) - - /// Returns all values in the process sequence, that are connected to the given node and come after it in the sequence - /// - /// If a protocol name is given, returns only the values of the processes that implement this protocol member this.SucceedingValuesOf(node : string, ?ProtocolName) = match ProtocolName with | Some ps -> - let connectedNodes = this.NodesOf node + let succeedingNodes = ArcTables.getSucceedingNodesBy node this let ps = ArcTables.onlyValuesOfProtocol this ps - connectedNodes - |> ResizeArray.collect (fun n -> + succeedingNodes + |> Seq.collect (fun n -> ps.SucceedingValuesOf(n) ) - |> ResizeArray.distinct |> ValueCollection - | None -> + | None -> ArcTables.getSucceedingValuesOf this node + /// Returns all values in the process sequence, that are connected to the given node and come before it in the sequence + /// + /// If a protocol name is given, returns only the values of the processes that implement this protocol + member this.PreviousValuesOf(node : QNode, ?ProtocolName) = + this.PreviousValuesOf(node.Name, ?ProtocolName = ProtocolName) + /// Returns all values in the process sequence, that are connected to the given node and come after it in the sequence /// /// If a protocol name is given, returns only the values of the processes that implement this protocol member this.SucceedingValuesOf(node : QNode, ?ProtocolName) = this.SucceedingValuesOf(node.Name, ?ProtocolName = ProtocolName) + /// Returns all values in the process sequence, that are connected to the given node + /// + /// If a protocol name is given, returns only the values of the processes that implement this protocol + member this.ValuesOf(node : string, ?ProtocolName : string) = + this.PreviousValuesOf(node,?ProtocolName = ProtocolName).Values @ this.SucceedingValuesOf(node,?ProtocolName = ProtocolName).Values + |> ValueCollection + + /// Returns all values in the process sequence, that are connected to the given node + /// + /// If a protocol name is given, returns only the values of the processes that implement this protocol + member this.ValuesOf(node : QNode, ?ProtocolName : string) = + this.ValuesOf(node.Name, ?ProtocolName = ProtocolName) + /// Returns all characteristic values in the process sequence, that are connected to the given node /// /// If a protocol name is given, returns only the values of the processes that implement this protocol diff --git a/tests/ARCtrl.Querymodel.Tests/TestARC.fs b/tests/ARCtrl.Querymodel.Tests/TestARC.fs index 8773428..3b49ff9 100644 --- a/tests/ARCtrl.Querymodel.Tests/TestARC.fs +++ b/tests/ARCtrl.Querymodel.Tests/TestARC.fs @@ -100,21 +100,29 @@ let ArcTables_ValueOf = let nodeName = "sampleOutHeat.txt" let protocolName = "MS" let values = isa.ArcTables.ValuesOf(nodeName,protocolName) - let expected = - [ - ISAValue.Parameter ( + let expectedTechRep = + ISAValue.Parameter ( ProcessParameterValue.create( ProtocolParameter.fromString("technical replicate","MS","MS:1001808"), Value.Ontology (OntologyAnnotation.fromString("1")) ) ) - ISAValue.Parameter ( + let expectedInjVol = + ISAValue.Parameter ( ProcessParameterValue.create( ProtocolParameter.fromString("injection volume setting","AFR","AFR:0001577"), Value.Int 20, OntologyAnnotation.fromString("microliter","UO","http://purl.obolibrary.org/obo/UO_0000101") ) ) + let expected = + [ + expectedTechRep;expectedInjVol + expectedTechRep;expectedInjVol + expectedTechRep;expectedInjVol + expectedTechRep;expectedInjVol + expectedTechRep;expectedInjVol + expectedTechRep;expectedInjVol ] Expect.sequenceEqual values expected "Did not return correct values for specific table" ) @@ -134,6 +142,14 @@ let ArcTables_ValueOf = let rep2 = isa.ArcTables.ValuesOf("C2_measured").WithName("biological replicate").First.ValueText Expect.equal rep2 "2" "Did not return correct value for specific table" ) + testCase "ValuesOf_SpecificTable_PooledOutput" (fun () -> + let vals = isa.ArcTables.ValuesOf("sampleOutHeat.txt","Growth").WithName("biological replicate").Values |> List.map (fun v -> v.ValueText) + Expect.sequenceEqual vals ["1";"2";"3";"1";"2";"3"] "Did not return correct values" + ) + testCase "SpecificValue_SpecificTable_PooledOutput" (fun () -> + let vals = isa.ArcTables.ValuesOf("C2_prep","Growth").WithName("biological replicate").First.ValueText + Expect.equal vals "2" "Did not return correct value" + ) ]