Skip to content

Commit

Permalink
start working on assay query model
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 21, 2022
1 parent e8e0175 commit 372d5d9
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/ISADotNet.XLSX/StudyFile/Study.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Study =

Study.create(CharacteristicCategories = characteristics,Factors = factors, Protocols = protocols, ProcessSequence = processes)

/// Diesen Block durch JS ersetzen ---->
// Diesen Block durch JS ersetzen ---->

/// Create a new ISADotNet.XLSX study file constisting of two sheets. The first has the name of the studyIdentifier and is meant to store parameters used in the study. The second stores additional study metadata
let init study studyIdentifier path =
Expand Down
6 changes: 6 additions & 0 deletions src/ISADotnet/DataModel/Material.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ type MaterialAttribute =
|> Option.map (fun oa -> oa.GetName)
|> Option.defaultValue ""

/// Returns number of Material attribute
member this.Number =
this.CharacteristicType
|> Option.bind (fun oa -> oa.Number)
|> Option.defaultValue ""

/// Returns the name of the characteristic with the number as string (e.g. "temperature #2")
member this.GetNameWithNumber =
this.CharacteristicType
Expand Down
7 changes: 5 additions & 2 deletions src/ISADotnet/DataModel/Ontology.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ type OntologyAnnotation =
)
|> Option.defaultValue ""

/// Returns number of Ontology annotation
member this.Number =
this.Comments |> Option.bind (List.tryPick (fun c -> if c.Name = Some "Number" then c.Value else None))

/// Returns the name of the ontology with the number as string (e.g. "temperature #2")
member this.GetNameWithNumber =
let number = this.Comments |> Option.bind (List.tryPick (fun c -> if c.Name = Some "Number" then c.Value else None))
let name = this.GetName
match number with
match this.Number with
| Some n -> name + " #" + n
| None -> name

Expand Down
183 changes: 147 additions & 36 deletions src/ISADotnet/JsonIO/AssayCommonAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,69 @@ open System.Text.Json.Serialization
open System.Text.Json
open System.IO

open System.Collections.Generic
open System.Collections



module AssayCommonAPI =

//[<AnyOf>]
//type NamedValue =
// | [<SerializationOrder(0)>] Parameter of ProcessParameterValue
// | [<SerializationOrder(1)>] Characteristic of MaterialAttributeValue
// | [<SerializationOrder(2)>] Factor of FactorValue
[<AnyOf>]
type ISAValue =
| [<SerializationOrder(0)>] Parameter of ProcessParameterValue
| [<SerializationOrder(1)>] Characteristic of MaterialAttributeValue
| [<SerializationOrder(2)>] Factor of FactorValue

/// Returns the ontology of the category of the Value as string
member this.Category =
match this with
| Parameter p -> p.Category.Value.ParameterName.Value
| Characteristic c -> c.Category.Value.CharacteristicType.Value
| Factor f -> f.Category.Value.FactorType.Value

///// Returns the name of the Value as string
//member this.GetTableHeader =
// match this with
// | Parameter p -> p.GetName
// | Characteristic c -> c.GetName
// | Factor f -> f.GetName

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

/// Returns the name of the Value with the number as string (e.g. "temperature #2")
member this.NameWithNumber = this.Category.GetNameWithNumber

/// Returns the name of the Value with the number as string (e.g. "temperature #2")
member this.Number = this.Category.Number

//member this.Value =
// match this with
// | Parameter p -> p.GetValue
// | Characteristic c -> c.GetValue
// | Factor f -> f.GetValue

member this.ValueString =
match this with
| Parameter p -> p.GetValue
| Characteristic c -> c.GetValue
| Factor f -> f.GetValue

member this.ValueWithUnit =
match this with
| Parameter p -> p.GetValueWithUnit
| Characteristic c -> c.GetValueWithUnit
| Factor f -> f.GetValueWithUnit

let combineValues (characteristics : MaterialAttributeValue list) (parameters : ProcessParameterValue list) (factors : FactorValue list) : ISAValue list =
let l =
(characteristics |> List.map Characteristic)
@ (parameters |> List.map Parameter)
@ (factors |> List.map Factor)
l

type IPrintable =
abstract member Print : unit -> unit

type Row =
{
Expand All @@ -23,23 +79,27 @@ module AssayCommonAPI =
InputType : string option
[<JsonPropertyName(@"outputType")>]
OutputType : string option
[<JsonPropertyName(@"parameterValues")>]
ParameterValues : ProcessParameterValue list
[<JsonPropertyName(@"characteristicValues")>]
CharacteristicValues : MaterialAttributeValue list
[<JsonPropertyName(@"factorValues")>]
FactorValues : FactorValue list
[<JsonPropertyName(@"values")>]
Values : ISAValue list
}

static member create(?Input,?Output,?InputType,?OutputType,?ParamValues,?CharValues,?FactorValues) : Row=
static member create (?Input,?Output,?InputType,?OutputType,?Values) : Row =

{
Input = Input |> Option.defaultValue ""
Output = Output |> Option.defaultValue ""
InputType = InputType
OutputType = OutputType
Values = Values |> Option.defaultValue []
}

static member create(?Input,?Output,?InputType,?OutputType,?CharValues,?ParamValues,?FactorValues) : Row =
{
Input = Input |> Option.defaultValue ""
Output = Output |> Option.defaultValue ""
InputType = InputType
OutputType = OutputType
ParameterValues = ParamValues |> Option.defaultValue []
CharacteristicValues = CharValues |> Option.defaultValue []
FactorValues = FactorValues |> Option.defaultValue []
Values = combineValues (CharValues |> Option.defaultValue []) (ParamValues |> Option.defaultValue []) (FactorValues |> Option.defaultValue [])
}

static member fromProcess (proc : Process) : Row list =
Expand All @@ -55,6 +115,28 @@ module AssayCommonAPI =
Row.create(inputName,outputName,ParamValues = parameterValues, CharValues = characteristics,FactorValues = factors)
)

member this.Item (i : int) =
this.Values
|> Seq.item i

member this.Item (s : string) =
this.Values
|> List.find (fun v ->
s = v.NameWithNumber || v.Name = s
)

member this.Item (oa : OntologyAnnotation) =
this.Values
|> List.pick (fun v ->
if v.Category = oa then Some v
else None
)

interface IEnumerable<ISAValue> with
member this.GetEnumerator() : System.Collections.Generic.IEnumerator<ISAValue> = (seq this.Values).GetEnumerator()

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

type RowWiseSheet =
{
Expand All @@ -75,6 +157,19 @@ module AssayCommonAPI =
|> List.collect (Row.fromProcess)
|> RowWiseSheet.create name

member this.Item (input : string) =
this.Rows
|> List.pick (fun r ->
if r.Input = input then Some r
else None
)

interface IEnumerable<Row> with
member this.GetEnumerator() = (seq this.Rows).GetEnumerator()

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

type RowWiseAssay =
{
//[<JsonPropertyName(@"assayName")>]
Expand All @@ -83,6 +178,12 @@ module AssayCommonAPI =
Sheets : RowWiseSheet list
}

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

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

static member create (*assayName*) sheets : RowWiseAssay =
{
//AssayName = assayName
Expand All @@ -102,6 +203,16 @@ module AssayCommonAPI =
)
|> List.map (fun (name,processes) -> RowWiseSheet.fromProcesses name processes)
|> RowWiseAssay.create (*(assay.FileName |> Option.defaultValue "")*)

member this.Item (sheetName) =
this.Sheets
|> List.pick (fun sheet ->
if sheet.SheetName = sheetName then
Some sheet
else None
)



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

Expand Down Expand Up @@ -219,23 +330,23 @@ module AssayCommonAPI =
FactorColumns = factorColumns
}

static member fromRowWiseSheet (rws : RowWiseSheet) =
let parameters =
rws.Rows
|> List.map (fun row -> row.ParameterValues)
|> List.transpose
|> List.map ParameterColumn.fromParams
let characteristics =
rws.Rows
|> List.map (fun row -> row.CharacteristicValues)
|> List.transpose
|> List.map CharacteristicColumn.fromCharacteristics
let factors =
rws.Rows
|> List.map (fun row -> row.FactorValues)
|> List.transpose
|> List.map FactorColumn.fromFactors
ColumnWiseSheet.create rws.SheetName parameters characteristics factors
//static member fromRowWiseSheet (rws : RowWiseSheet) =
// let parameters =
// rws.Rows
// |> List.map (fun row -> row.ParameterValues)
// |> List.transpose
// |> List.map ParameterColumn.fromParams
// let characteristics =
// rws.Rows
// |> List.map (fun row -> row.CharacteristicValues)
// |> List.transpose
// |> List.map CharacteristicColumn.fromCharacteristics
// let factors =
// rws.Rows
// |> List.map (fun row -> row.FactorValues)
// |> List.transpose
// |> List.map FactorColumn.fromFactors
// ColumnWiseSheet.create rws.SheetName parameters characteristics factors

type ColumnWiseAssay =
{
Expand All @@ -250,7 +361,7 @@ module AssayCommonAPI =
Sheets = sheets
}

static member fromRowWiseAssay (rwa : RowWiseAssay) =
rwa.Sheets
|> List.map ColumnWiseSheet.fromRowWiseSheet
|> ColumnWiseAssay.create
//static member fromRowWiseAssay (rwa : RowWiseAssay) =
// rwa.Sheets
// |> List.map ColumnWiseSheet.fromRowWiseSheet
// |> ColumnWiseAssay.create

0 comments on commit 372d5d9

Please sign in to comment.