Skip to content

Commit

Permalink
add QProcessSequence type for QueryModel
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Apr 22, 2022
1 parent 2a9613d commit a6470f1
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 174 deletions.
15 changes: 15 additions & 0 deletions src/ISADotnet/DataModel/Data.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ type DataFile =
| DerivedDataFile -> "DerivedDataFileJson"
| ImageFile -> "ImageFileJson"

member this.IsDerivedData =
match this with
| DerivedDataFile -> true
| _ -> false

member this.IsRawData =
match this with
| RawDataFile -> true
| _ -> false

member this.IsImage =
match this with
| ImageFile -> true
| _ -> false

type Data =
{
[<JsonPropertyName(@"@id")>]
Expand Down
2 changes: 2 additions & 0 deletions src/ISADotnet/ISADotNet.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
<Compile Include="JsonIO\Study.fs" />
<Compile Include="JsonIO\Investigation.fs" />
<Compile Include="QueryModel\ValueIndex.fs" />
<Compile Include="QueryModel\Category.fs" />
<Compile Include="QueryModel\Value.fs" />
<Compile Include="QueryModel\Row.fs" />
<Compile Include="QueryModel\Column.fs" />
<Compile Include="QueryModel\ValueCollection.fs" />
<Compile Include="QueryModel\Sheet.fs" />
<Compile Include="QueryModel\ProcessSequence.fs" />
<Compile Include="QueryModel\Assay.fs" />
</ItemGroup>

Expand Down
185 changes: 23 additions & 162 deletions src/ISADotnet/QueryModel/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@ open System.Collections.Generic
open System.Collections


type QAssay =
{
[<JsonPropertyName(@"filename")>]
FileName : string option
[<JsonPropertyName(@"measurementType")>]
MeasurementType : OntologyAnnotation option
[<JsonPropertyName(@"technologyType")>]
TechnologyType : OntologyAnnotation option
[<JsonPropertyName(@"technologyPlatform")>]
TechnologyPlatform : string option
[<JsonPropertyName(@"sheets")>]
Sheets : QSheet list
}

static member create fileName measurementType technologyType technologyPlatform sheets : QAssay =
{
FileName = fileName
MeasurementType = measurementType
TechnologyType = technologyType
TechnologyPlatform = technologyPlatform
Sheets = sheets
}
type QAssay(FileName : string option,MeasurementType : OntologyAnnotation option,TechnologyType : OntologyAnnotation option,TechnologyPlatform : string option,Sheets : QSheet list) =

inherit QProcessSequence(Sheets)

member this.FileName = FileName
member this.MeasurementType = MeasurementType
member this.TechnologyType = TechnologyType
member this.TechnologyPlatform = TechnologyPlatform

static member fromAssay (assay : Assay) =
let sheets =
Expand All @@ -45,156 +31,31 @@ type QAssay =
x.Name.Value.Remove lastUnderScoreIndex
)
|> List.map (fun (name,processes) -> QSheet.fromProcesses name processes)
QAssay.create assay.FileName assay.MeasurementType assay.TechnologyType assay.TechnologyPlatform sheets

member this.Protocol (i : int) =
this.Sheets.[i]

member this.Protocol (sheetName) =
let sheet =
this.Sheets
|> List.tryFind (fun sheet -> sheet.SheetName = sheetName)
match sheet with
| Some s -> s
| None -> failwith $"Assay \"{this.FileName}\" does not contain sheet with name \"{sheetName}\""

member this.Protocols = this.Sheets

member this.ProtocolCount =
this.Sheets
|> List.length

member this.ProtocolNames =
this.Sheets
|> List.map (fun sheet -> sheet.SheetName)
QAssay(assay.FileName,assay.MeasurementType,assay.TechnologyType,assay.TechnologyPlatform,sheets)

member this.Protocol (sheetName : string) =
base.Protocol(sheetName, $"Assay \"{this.FileName}\"")

member this.Protocol (index : int) =
base.Protocol(index, $"Assay \"{this.FileName}\"")

interface IEnumerable<QSheet> with
member this.GetEnumerator() = (Seq.ofList this.Sheets).GetEnumerator()
//interface IEnumerable<QSheet> with
// member this.GetEnumerator() = (Seq.ofList this.Sheets).GetEnumerator()

interface IEnumerable with
member this.GetEnumerator() = (this :> IEnumerable<QSheet>).GetEnumerator() :> IEnumerator
//interface IEnumerable with
// member this.GetEnumerator() = (this :> IEnumerable<QSheet>).GetEnumerator() :> IEnumerator

/// Returns the initial inputs final outputs of the assay, to which no processPoints
static member getRootInputs (assay : QAssay) =
let inputs = assay.Protocols |> List.collect (fun p -> p.Rows |> List.map (fun r -> r.Input))
let outputs = assay.Protocols |> List.collect (fun p -> p.Rows |> List.map (fun r -> r.Output)) |> Set.ofList
inputs
|> List.filter (fun i -> outputs.Contains i |> not)
static member getRootInputs (assay : QAssay) = QProcessSequence.getRootInputs assay

/// Returns the final outputs of the assay, which point to no further nodes
static member getFinalOutputs (assay : QAssay) =
let inputs = assay.Protocols |> List.collect (fun p -> p.Rows |> List.map (fun r -> r.Input)) |> Set.ofList
let outputs = assay.Protocols |> List.collect (fun p -> p.Rows |> List.map (fun r -> r.Output))
outputs
|> List.filter (fun i -> inputs.Contains i |> not)
static member getFinalOutputs (assay : QAssay) = QProcessSequence.getFinalOutputs assay

/// Returns the initial inputs final outputs of the assay, to which no processPoints
static member getRootInputOf (assay : QAssay) (sample : string) =
let mappings =
assay.Protocols
|> List.collect (fun p ->
p.Rows
|> List.map (fun r -> r.Output,r.Input)
|> List.distinct
)
|> List.groupBy fst
|> List.map (fun (out,ins) -> out, ins |> List.map snd)
|> Map.ofList
let rec loop lastState state =
if lastState = state then state
else
let newState =
state
|> List.collect (fun s ->
mappings.TryFind s
|> Option.defaultValue [s]
)
loop state newState
loop [] [sample]
static member getRootInputOf (assay : QAssay) (sample : string) = QProcessSequence.getRootInputOf assay sample

/// Returns the final outputs of the assay, which point to no further nodes
static member getFinalOutputsOf (assay : QAssay) (sample : string) =
let mappings =
assay.Protocols
|> List.collect (fun p ->
p.Rows
|> List.map (fun r -> r.Input,r.Output)
|> List.distinct
)
|> List.groupBy fst
|> List.map (fun (inp,outs) -> inp, outs |> List.map snd)
|> Map.ofList
let rec loop lastState state =
if lastState = state then state
else
let newState =
state
|> List.collect (fun s ->
mappings.TryFind s
|> Option.defaultValue [s]
)
loop state newState
loop [] [sample]

member this.Nearest =
this.Sheets
|> List.collect (fun sheet -> sheet.Values |> Seq.toList)
|> IOValueCollection

member this.SinkNearest =
this.Sheets
|> List.collect (fun sheet ->
sheet.Rows
|> List.collect (fun r ->
r.Input
|> QAssay.getRootInputOf this |> List.distinct
|> List.collect (fun inp ->
r.Values
|> List.map (fun v ->
KeyValuePair((inp,r.Output),v)
)
)
)
)
|> IOValueCollection

member this.SourceNearest =
this.Sheets
|> List.collect (fun sheet ->
sheet.Rows
|> List.collect (fun r ->
r.Output
|> QAssay.getFinalOutputsOf this |> List.distinct
|> List.collect (fun out ->
r.Values
|> List.map (fun v ->
KeyValuePair((r.Input,out),v)
)
)
)
)
|> IOValueCollection

member this.Global =
this.Sheets
|> List.collect (fun sheet ->
sheet.Rows
|> List.collect (fun r ->
let outs = r.Output |> QAssay.getFinalOutputsOf this |> List.distinct
let inps = r.Input |> QAssay.getRootInputOf this |> List.distinct
outs
|> List.collect (fun out ->
inps
|> List.collect (fun inp ->
r.Values
|> List.map (fun v ->
KeyValuePair((inp,out),v)
)
)
)
)
)
|> IOValueCollection
static member getFinalOutputsOf (assay : QAssay) (sample : string) = QProcessSequence.getFinalOutputsOf assay sample

static member toString (rwa : QAssay) = JsonSerializer.Serialize<QAssay>(rwa,JsonExtensions.options)

Expand Down
42 changes: 42 additions & 0 deletions src/ISADotnet/QueryModel/Category.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace ISADotNet.QueryModel

open ISADotNet
open System.Text.Json.Serialization

[<AnyOf>]
type ISACategory =
| [<SerializationOrder(0)>] Parameter of ProtocolParameter
| [<SerializationOrder(1)>] Characteristic of MaterialAttribute
| [<SerializationOrder(2)>] Factor of Factor

member this.IsCharacteristicCategory =
match this with
| Characteristic _ -> true
| _ -> false

member this.IsParameterCategory =
match this with
| Parameter _ -> true
| _ -> false

member this.IsFactorCategory =
match this with
| Factor _ -> true
| _ -> false

/// Returns the name of the Category
member this.Name =
match this with
| Parameter p -> try p.ParameterName.Value with | _ -> failwith $"Parameter does not contain header"
| Characteristic c -> try c.CharacteristicType.Value with | _ -> failwith $"Characteristic does not contain header"
| Factor f -> try f.FactorType.Value with | _ -> failwith $"Factor does not contain header"

/// Returns the name of the Category as string
member this.NameText = this.Name.NameText

/// Returns the header text of the Category as string
member this.HeaderText =
match this with
| Parameter p -> try $"Parameter [{p.NameText}]" with | _ -> failwith $"Parameter does not contain header"
| Characteristic c -> try $"Characteristics [{c.NameText}]" with | _ -> failwith $"Characteristic does not contain header"
| Factor f -> try $"Factor [{f.NameText}]" with | _ -> failwith $"Factor does not contain header"
16 changes: 15 additions & 1 deletion src/ISADotnet/QueryModel/Column.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
module Column
namespace ISADotNet.QueryModel

open ISADotNet
open System.Text.Json.Serialization

open System.Collections.Generic
open System.Collections

type QColumn =
{
[<JsonPropertyName(@"category")>]
Header : ISACategory
[<JsonPropertyName(@"values")>]
Values : KeyValuePair<string*string,ISAValue> list
}

Loading

0 comments on commit a6470f1

Please sign in to comment.