From 6eb5c44328d9106f0ccb1065dd3423856cc35f81 Mon Sep 17 00:00:00 2001 From: Heinrich Lukas Weil Date: Wed, 20 Jul 2022 10:06:19 +0200 Subject: [PATCH] add additional ontology helper functions to querymodel --- .../OntologyAnnotation.fs | 51 +++++++++++++++++++ src/ISADotNet.QueryModel/Value.fs | 14 ++++- src/ISADotNet.QueryModel/ValueCollection.fs | 24 ++++++++- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/ISADotNet.QueryModel/OntologyAnnotation.fs b/src/ISADotNet.QueryModel/OntologyAnnotation.fs index 3a6a5da6..5d82179f 100644 --- a/src/ISADotNet.QueryModel/OntologyAnnotation.fs +++ b/src/ISADotNet.QueryModel/OntologyAnnotation.fs @@ -74,3 +74,54 @@ module OntologyAnnotation = member this.GetAs(targetOntology : string, ont : Obo.OboOntology) = OntologyAnnotation.getAs(this,targetOntology,ont) + + static member tryGetAs (term : OntologyAnnotation, targetOntology : string, ont : Obo.OboOntology) = + ont.GetEquivalentOntologyAnnotations(term) + |> List.tryFind (fun t -> t.TermSourceREFString = targetOntology) + + member this.TryGetAs(targetOntology : string, ont : Obo.OboOntology) = + OntologyAnnotation.tryGetAs(this,targetOntology,ont) + + type Value with + + member this.GetAs(targetOntology : string, ont : Obo.OboOntology) = + match this with + | Ontology oa -> Ontology (oa.GetAs(targetOntology, ont)) + | _ -> this + + member this.TryGetAs(targetOntology : string, ont : Obo.OboOntology) = + match this with + | Ontology oa -> + oa.TryGetAs(targetOntology, ont) + |> Option.map Ontology + | _ -> None + + type ProcessParameterValue with + + member this.GetAs(targetOntology : string, ont : Obo.OboOntology) = + {this with Value = this.Value |> Option.map (fun v -> v.GetAs(targetOntology,ont))} + + member this.TryGetAs(targetOntology : string, ont : Obo.OboOntology) = + this.Value + |> Option.bind (fun v -> v.TryGetAs(targetOntology,ont)) + |> Option.map (fun v -> {this with Value = Some v}) + + type MaterialAttributeValue with + + member this.GetAs(targetOntology : string, ont : Obo.OboOntology) = + {this with Value = this.Value |> Option.map (fun v -> v.GetAs(targetOntology,ont))} + + member this.TryGetAs(targetOntology : string, ont : Obo.OboOntology) = + this.Value + |> Option.bind (fun v -> v.TryGetAs(targetOntology,ont)) + |> Option.map (fun v -> {this with Value = Some v}) + + type FactorValue with + + member this.GetAs(targetOntology : string, ont : Obo.OboOntology) = + {this with Value = this.Value |> Option.map (fun v -> v.GetAs(targetOntology,ont))} + + member this.TryGetAs(targetOntology : string, ont : Obo.OboOntology) = + this.Value + |> Option.bind (fun v -> v.TryGetAs(targetOntology,ont)) + |> Option.map (fun v -> {this with Value = Some v}) \ No newline at end of file diff --git a/src/ISADotNet.QueryModel/Value.fs b/src/ISADotNet.QueryModel/Value.fs index 8328b20e..67da1b2b 100644 --- a/src/ISADotNet.QueryModel/Value.fs +++ b/src/ISADotNet.QueryModel/Value.fs @@ -108,4 +108,16 @@ type ISAValue = match this with | Parameter p -> p.TryGetValueIndex() | Characteristic c -> c.TryGetValueIndex() - | Factor f -> f.TryGetValueIndex() \ No newline at end of file + | Factor f -> f.TryGetValueIndex() + + member this.GetAs(targetOntology : string, ont : Obo.OboOntology) = + match this with + | Parameter p -> p.GetAs(targetOntology,ont) |> Parameter + | Characteristic c -> c.GetAs(targetOntology,ont) |> Characteristic + | Factor f -> f.GetAs(targetOntology,ont) |> Factor + + member this.TryGetAs(targetOntology : string, ont : Obo.OboOntology) = + match this with + | Parameter p -> p.TryGetAs(targetOntology,ont) |> Option.map Parameter + | Characteristic c -> c.TryGetAs(targetOntology,ont) |> Option.map Characteristic + | Factor f -> f.TryGetAs(targetOntology,ont) |> Option.map Factor \ No newline at end of file diff --git a/src/ISADotNet.QueryModel/ValueCollection.fs b/src/ISADotNet.QueryModel/ValueCollection.fs index f7f45d93..0d99b5e5 100644 --- a/src/ISADotNet.QueryModel/ValueCollection.fs +++ b/src/ISADotNet.QueryModel/ValueCollection.fs @@ -86,19 +86,39 @@ type ValueCollection(values : ISAValue list) = ) |> ValueCollection + member this.WithName(name : string) = + values + |> List.filter (fun v -> v.Category.NameText = name) + |> ValueCollection + member this.WithCategory(category : OntologyAnnotation) = values |> List.filter (fun v -> v.Category = category) |> ValueCollection + member this.WithEquivalentCategory(equivalentCategory : OntologyAnnotation, ont : Obo.OboOntology) = + values + |> List.filter (fun v -> v.Category.IsEquivalentTo(equivalentCategory, ont)) + |> ValueCollection + + member this.WithChildCategory(childCategory : OntologyAnnotation) = + values + |> List.filter (fun v -> childCategory.IsChildTermOf(v.Category)) + |> ValueCollection + + member this.WithChildCategory(childCategory : OntologyAnnotation, ont : Obo.OboOntology) = + values + |> List.filter (fun v -> childCategory.IsChildTermOf(v.Category, ont)) + |> ValueCollection + member this.WithParentCategory(parentCategory : OntologyAnnotation) = values |> List.filter (fun v -> v.Category.IsChildTermOf(parentCategory)) |> ValueCollection - member this.WithName(name : string) = + member this.WithParentCategory(parentCategory : OntologyAnnotation, ont : Obo.OboOntology) = values - |> List.filter (fun v -> v.Category.NameText = name) + |> List.filter (fun v -> v.Category.IsChildTermOf(parentCategory,ont)) |> ValueCollection member this.Distinct() =