Skip to content

Commit

Permalink
Fix synonym obo writing #27 Add tests ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Oct 26, 2023
1 parent d4b6434 commit 73aa990
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/OBO.NET/OboTerm.fs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ type OboTerm =
if term.Definition = "" |> not then yield $"def: {term.Definition}"
if term.Comment = "" |> not then yield $"comment: {term.Comment}"
for subset in term.Subsets do yield $"subset: {subset}"
for synonym in term.Synonyms do yield $"synonym: {synonym}"
for synonym in term.Synonyms do yield $"synonym: {synonym.ToLine()}"
for xref in term.Xrefs do yield $"xref: {xref.Name}"
if term.BuiltIn then yield "builtin"
for property_value in term.PropertyValues do yield $"property_value: {property_value}"
Expand Down
33 changes: 24 additions & 9 deletions src/OBO.NET/TermSynonym.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
open DBXref


//The value consists of a quote enclosed synonym text, a scope identifier, an optional synonym type name, and an optional dbxref list, like this:
//synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021]

//The synonym scope may be one of four values: EXACT, BROAD, NARROW, RELATED. If the first form is used to specify a synonym, the scope is assumed to be RELATED.

//The synonym type must be the id of a synonym type defined by a synonymtypedef line in the header. If the synonym type has a default scope, that scope is used regardless of any scope declaration given by a synonym tag.

//The dbxref list is formatted as specified in dbxref formatting. A term may have any number of synonyms.
///The value consists of a quote enclosed synonym text, a scope identifier, an optional synonym type name, and an optional dbxref list, like this:
///synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021]
///
///The synonym scope may be one of four values: EXACT, BROAD, NARROW, RELATED. If the first form is used to specify a synonym, the scope is assumed to be RELATED.
///
///The synonym type must be the id of a synonym type defined by a synonymtypedef line in the header. If the synonym type has a default scope, that scope is used regardless of any scope declaration given by a synonym tag.
///
///The dbxref list is formatted as specified in dbxref formatting. A term may have any number of synonyms.
type TermSynonymScope =
| Exact
| Broad
Expand All @@ -27,13 +27,28 @@ type TermSynonymScope =
| _ -> printfn "[WARNING@L %i]unable to recognize %s as synonym scope" line s
Related

member this.ToOboString() =
match this with
| Exact -> "EXACT"
| Broad -> "BROAD"
| Narrow -> "NARROW"
| Related -> "RELATED"


type TermSynonym = {
Text : string
Scope : TermSynonymScope
TypeName : string
DBXrefs : DBXref list
}
} with
static member create(text: string, scope: TermSynonymScope, typeName: string, dbxrefs: DBXref list) = {
Text = text
Scope = scope
TypeName = typeName
DBXrefs = dbxrefs
}

member this.ToLine() = $"{this.Text} {this.Scope.ToOboString()} {this.TypeName} {this.DBXrefs}"


module TermSynonym =
Expand Down
5 changes: 5 additions & 0 deletions tests/OBO.NET.Tests/OBO.NET.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="TermSynonym.Tests.fs" />
<Compile Include="OboTerm.Tests.fs" />
<Compile Include="OboOntology.Tests.fs" />
<Compile Include="Main.fs" />
Expand All @@ -24,4 +25,8 @@
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.14.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="7.0.401" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions tests/OBO.NET.Tests/OboTerm.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ module OboTermTests =
let expected = ["id:1", "related_to", "id:2"; "id:1", "unrelated_to", "id:3"]
Expect.sequenceEqual actual expected "is not equal"
]
testList "ToLines" [
testCase "synonym" <| fun _ ->
let actual =
OboTerm.Create("NCBITaxon:562", Name="Escherichia coli", Synonyms=[TermSynonym.create("\"Bacillus coli\"", Related, "synonym", [])])
|> OboTerm.toLines
|> List.ofSeq
let expected = [
"id: NCBITaxon:562"
"name: Escherichia coli"
"synonym: \"Bacillus coli\" RELATED synonym []"
]
Expect.sequenceEqual actual expected ""
]
]
21 changes: 21 additions & 0 deletions tests/OBO.NET.Tests/TermSynonym.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace OBO.NET.Tests

open Expecto
open OBO.NET

module TermSynonymTests =

[<Tests>]
let main =
testList "TermSynonym" [
testCase "create" <| fun _ ->
let actual = TermSynonym.create("\"Bacillus coli\"", Related, "synonym", [])
Expect.equal actual.Text "\"Bacillus coli\"" "text"
Expect.equal actual.Scope Related "scope"
Expect.equal actual.TypeName "synonym" "typeName"
Expect.equal actual.DBXrefs [] "dbxrefs"
testCase "ToOboString" <| fun _ ->
let actual = TermSynonym.create("\"Bacillus coli\"", Related, "synonym", []).ToLine()
let expected = "\"Bacillus coli\" RELATED synonym []"
Expect.equal actual expected "is not equal"
]

0 comments on commit 73aa990

Please sign in to comment.