Skip to content

Commit

Permalink
fix querymodel value getting
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Feb 21, 2024
1 parent e4a7c14 commit b40490c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 52 deletions.
110 changes: 62 additions & 48 deletions src/ARCtrl.QueryModel/ArcTables.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions tests/ARCtrl.Querymodel.Tests/TestARC.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
)
]


Expand Down

0 comments on commit b40490c

Please sign in to comment.