Skip to content

Commit

Permalink
Finish term relation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Aug 18, 2023
1 parent acec96f commit 60a185e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/FsOboParser/OboOntology.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ type OboOntology =
OntologyAnnotation.fromAnnotationId termId
|> this.GetChildOntologyAnnotations

/// Takes an OboTerm and returns all related terms in this ontology as a triple of input term, relationship, and related term.
member this.GetRelatedTerms(term : OboTerm) =
term.Relationships
|> List.map (
OboTerm.deconstructRelationship
>> fun (r,tId) ->
term,
r,
this.Terms
|> List.tryFind (
fun t -> t.Id = tId
)
)

/// Takes an OboTerm and an OboOntology and returns all related terms in this ontology as a triple of input term, relationship, and related term.
static member getRelatedTerms term (ontology : OboOntology) =
ontology.GetRelatedTerms term



Expand Down
6 changes: 3 additions & 3 deletions src/FsOboParser/OboTerm.fs
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ type OboTerm =
regexMatch.Groups["relName"].Value, regexMatch.Groups["id"].Value

/// Returns the OboTerm's relationships as a triple consisting of the term's ID, the name of the relationship, and the related term's ID.
member this.GetRelatedTerms() =
member this.GetRelatedTermIds() =
this.Relationships
|> List.map (
OboTerm.deconstructRelationship
>> fun (r,tId) -> this.Id, r, tId
)

/// Takes an OboTerm and returns its relationships as a triple consisting of the input term's ID, the name of the relationship, and the related term's ID.
static member getRelatedTerms (term : OboTerm) =
term.GetRelatedTerms()
static member getRelatedTermIds (term : OboTerm) =
term.GetRelatedTermIds()
1 change: 1 addition & 0 deletions tests/FsOboParser.Tests/FsOboParser.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<Compile Include="OboTerm.Tests.fs" />
<Compile Include="OboOntology.Tests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion tests/FsOboParser.Tests/Main.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
open FsOboParser.Tests

open Expecto


[<EntryPoint>]
let main argv = Tests.runTestsWithCLIArgs [] argv FsOboParser.Tests.TestTests.testTest
let main argv = Tests.runTestsInAssemblyWithCLIArgs [] argv
22 changes: 22 additions & 0 deletions tests/FsOboParser.Tests/OboOntology.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace FsOboParser.Tests

open Expecto
open FsOboParser


module OboOntologyTests =

[<Tests>]
let oboOntologyTest =
testList "OboOntology" [
let testTerm1 = OboTerm.Create("id:1", Name = "testTerm1", Relationships = ["related_to id:2"; "unrelated_to id:3"; "antirelated_to id:4"])
let testTerm2 = OboTerm.Create("id:2", Name = "testTerm2", Relationships = ["related_to id:1"])
let testTerm3 = OboTerm.Create("id:3", Name = "testTerm3", Relationships = ["unrelated_to id:1"])
let testOntology = OboOntology.create [testTerm1; testTerm2; testTerm3] []
testList "GetRelatedTerms" [
testCase "returns correct related terms" <| fun _ ->
let actual = testOntology.GetRelatedTerms(testTerm1)
let expected = [testTerm1, "related_to", Some testTerm2; testTerm1, "unrelated_to", Some testTerm3; testTerm1, "antirelated_to", None]
Expect.sequenceEqual actual expected "is not equal"
]
]
9 changes: 8 additions & 1 deletion tests/FsOboParser.Tests/OboTerm.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ open FsOboParser
module OboTermTests =

[<Tests>]
let testTest =
let oboTermTest =
testList "OboTerm" [
testList "deconstructRelationship" [
testCase "is correctly deconstructed" <| fun _ ->
let actual = OboTerm.deconstructRelationship "part_of INVMSO:00000082"
let expected = "part_of", "INVMSO:00000082"
Expect.equal actual expected "is not equal"
]
testList "GetRelatedTermIds" [
testCase "returns correct related term IDs" <| fun _ ->
let testTerm = OboTerm.Create("id:1", Name = "testTerm1", Relationships = ["related_to id:2"; "unrelated_to id:3"])
let actual = testTerm.GetRelatedTermIds()
let expected = ["id:1", "related_to", "id:2"; "id:1", "unrelated_to", "id:3"]
Expect.sequenceEqual actual expected "is not equal"
]
]

0 comments on commit 60a185e

Please sign in to comment.