Skip to content

Commit

Permalink
add additional ontology helper functions to querymodel
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Jul 20, 2022
1 parent 11ef6b8 commit 6eb5c44
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/ISADotNet.QueryModel/OntologyAnnotation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
14 changes: 13 additions & 1 deletion src/ISADotNet.QueryModel/Value.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,16 @@ type ISAValue =
match this with
| Parameter p -> p.TryGetValueIndex()
| Characteristic c -> c.TryGetValueIndex()
| Factor f -> f.TryGetValueIndex()
| 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
24 changes: 22 additions & 2 deletions src/ISADotNet.QueryModel/ValueCollection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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() =
Expand Down

0 comments on commit 6eb5c44

Please sign in to comment.