Skip to content

Commit

Permalink
finalize first DAG visualization draft ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Oct 22, 2021
1 parent e08e29e commit 2a9311b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 65 deletions.
63 changes: 16 additions & 47 deletions docs/VisualizeAssayGraph.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,33 @@
// #r "nuget: DynamicObj"
// #r @"C:\Users\Lukas\Downloads\Cyjs.NET-main\bin\Cyjs.NET\netstandard2.1\Cyjs.NET.dll"
#r "nuget: Cyjs.NET"
#r "nuget: ISADotNet.XLSX"
#r "nuget: System.Text.Json"
#r "nuget: FSharpSpreadsheetML"

#r "nuget: FSharp.SystemTextJson"


#r @"D:\Repos\ISADotNet\bin\ISADotNet.XLSX\netstandard2.0\ISADotNet.dll"
#r @"D:\Repos\ISADotNet\bin\ISADotNet.XLSX\netstandard2.0\ISADotNet.XLSX.dll"
#r @"D:\Repos\ISADotNet\bin\ISADotNet.Viz\netstandard2.0\ISADotNet.Viz.dll"

open ISADotNet
open ISADotNet.API
open ISADotNet.XLSX
open ISADotNet.Viz

open Cyjs.NET
open Elements

let source = __SOURCE_DIRECTORY__

let _,_,_,assay = AssayFile.AssayFile.fromFile (source + @"\content\files\AssayFile.xlsx")



let myFirstGraph =
CyGraph.initEmpty ()

open Cyjs.NET
open Elements

let edges =
assay.ProcessSequence.Value
|> List.collect (fun p ->
p.Outputs.Value
|> List.zip p.Inputs.Value
|> List.map (fun (i,o) -> ProcessInput.getName i |> Option.get,ProcessOutput.getName o |> Option.get,p.Name.Value)
)




let cyNodes =
edges
|> List.collect (fun (i,o,e) -> [i;o])
|> List.distinct
|> List.map (fun n -> node n [CyParam.label n])

let cyEgdes =
edges
|> List.mapi (fun index (i,o,e) -> edge (string index) i o [CyParam.label e])
let source = __SOURCE_DIRECTORY__

let myGraph =
CyGraph.initEmpty ()
|> CyGraph.withElements cyNodes
|> CyGraph.withElements cyEgdes
|> CyGraph.withStyle "node"
[
CyParam.content =. CyParam.label
CyParam.color "#A00975"
]
|> CyGraph.withStyle "edge"
[
CyParam.content =. CyParam.label
CyParam.color "#FF0000"
]
|> CyGraph.withLayout (Layout.initBreadthfirst id)
|> CyGraph.withSize(800, 400)
let _,_,_,assay = AssayFile.Assay.fromFile (source + @"\content\files\AssayFile.xlsx")

Layout.initBreadthfirst

myGraph
|> CyGraph.show
DAG.fromProcessSequence (assay.ProcessSequence.Value,Schema = Schema.SwateGreen)
|> DAG.show
6 changes: 5 additions & 1 deletion src/ISADotNet.Viz/DAG.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open ISADotNet
open ISADotNet.API
open Cyjs.NET
open Cyjs.NET.Elements

type DAG =

Expand All @@ -16,13 +17,16 @@ type DAG =

let schema = Option.defaultValue ISADotNet.Viz.Schema.DefaultGrey Schema

let rootNodes = API.ProcessSequence.getRootInputs ps |> List.map ProcessInput.getName

let edges =
ps
|> List.collect (fun p ->
p.Outputs.Value
|> List.zip p.Inputs.Value
|> List.map (fun (i,o) -> ProcessInput.getName i |> Option.get,ProcessOutput.getName o |> Option.get,p.Name.Value)
|> List.map (fun (i,o) -> ProcessInput.getName i ,ProcessOutput.getName o ,p.Name.Value)
)
|> List.append (rootNodes |> List.map (fun i -> "Root",i,""))

let cyNodes =
edges
Expand Down
4 changes: 2 additions & 2 deletions src/ISADotNet.Viz/ISADotNet.Viz.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<WarnOn>3390;$(WarnOn)</WarnOn>
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cyjs.NET" Version="0.0.3" />
<PackageReference Include="Cyjs.NET" Version="0.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 4 additions & 13 deletions src/ISADotNet.Viz/Schema.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ type Schema =
static member NFDIBlue =

{
VertexColor = "#2D3E50"
VertexLabelColor = "#2D3E50"
EdgeColor = "#4FB3D9"
EdgeLabelColor = "#425162"
}

static member SwateGreen =

{
VertexColor = "#252423"
VertexLabelColor = "#252423"
EdgeColor = "#1FC2A7"
EdgeLabelColor = "#2f6b82"
VertexColor = "#2D3E50" //Dark blue
VertexLabelColor = "#2D3E50" //Dark blue
EdgeColor = "#4FB3D9" //light blue
EdgeLabelColor = "#425162" //grey
}
26 changes: 24 additions & 2 deletions src/ISADotnet/API/Process.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ module ProcessParameterValue =
module ProcessInput =

/// Returns name of processInput
let getName (pi : ProcessInput) =
let tryGetName (pi : ProcessInput) =
match pi with
| ProcessInput.Sample s -> s.Name
| ProcessInput.Source s -> s.Name
| ProcessInput.Material m -> m.Name
| ProcessInput.Data d -> d.Name

/// Returns name of processInput
let getName (pi : ProcessInput) =
tryGetName pi |> Option.defaultValue ""

/// Returns true, if given name equals name of processInput
let nameEquals (name : string) (pi : ProcessInput) =
match pi with
Expand Down Expand Up @@ -115,12 +119,16 @@ module ProcessInput =
module ProcessOutput =

/// Returns name of processOutput
let getName (po : ProcessOutput) =
let tryGetName (po : ProcessOutput) =
match po with
| ProcessOutput.Sample s -> s.Name
| ProcessOutput.Material m -> m.Name
| ProcessOutput.Data d -> d.Name

/// Returns name of processInput
let getName (po : ProcessOutput) =
tryGetName po |> Option.defaultValue ""

/// Returns true, if given name equals name of processOutput
let nameEquals (name : string) (po : ProcessOutput) =
match po with
Expand Down Expand Up @@ -368,3 +376,17 @@ module ProcessSequence =
processSequence
|> List.collect Process.getFactors
|> List.distinct

/// Returns the final outputs of the processSequence, which point to no further nodes
let getRootInputs (processSequence : Process list) =
let inputs = processSequence |> List.collect (fun p -> p.Inputs |> Option.defaultValue [])
let outputs = processSequence |> List.collect (fun p -> p.Outputs |> Option.defaultValue [] |> List.map ProcessOutput.getName) |> Set.ofList
inputs
|> List.filter (fun i -> ProcessInput.getName i |> outputs.Contains |> not)

/// Returns the initial inputs of the processSequence, to which no processPoints
let getFinalInputs (processSequence : Process list) =
let inputs = processSequence |> List.collect (fun p -> p.Inputs |> Option.defaultValue [] |> List.map ProcessInput.getName) |> Set.ofList
let outputs = processSequence |> List.collect (fun p -> p.Outputs |> Option.defaultValue [])
outputs
|> List.filter (fun o -> ProcessOutput.getName o |> inputs.Contains |> not)

0 comments on commit 2a9311b

Please sign in to comment.