Skip to content

Commit

Permalink
Add fromOboEntries function to OboOntology type
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Jul 28, 2023
1 parent eb6dca1 commit 28b8da1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#r "FsOboParser.dll"

#r "nuget: IsaDotNet"
//#r "nuget: FsOboParser"

open FsOboParser

Expand All @@ -10,7 +11,7 @@ open System.IO

let testPath = Path.Combine(__SOURCE_DIRECTORY__, "./../../nfdi4plants/arc-validate/ErrorClassOntology.obo")

OboEntries.fromFile true testPath
//OboEntries.fromFile true testPath
let testOntology = OboOntology.fromFile true testPath

let testTerms = [
Expand All @@ -26,6 +27,13 @@ testOntology.GetChildOntologyAnnotations(testTerms.Head.Id)
testOntology.GetChildOntologyAnnotations(testTerms.Head.Id, Depth = 1)
testOntology.GetChildOntologyAnnotations(testTerms.Head.Id, Depth = 2)

let performanceTerms = List.init 7000000 (fun i -> OboTerm.Create($"lol:{i}"))
let performanceOboOntology = OboOntology.create performanceTerms []
OboOntology.toFile @"C:\Repos\CSBiology\FsOboParser\performanceOntology.obo" performanceOboOntology

let x = OboOntology.fromFile false @"C:\Repos\CSBiology\FsOboParser\performanceOntology.obo"


//let fileLines = File.ReadAllLines testPath

//OboTerm.fromLines true ((fileLines |> Seq.ofArray).GetEnumerator()) 0
Expand Down
3 changes: 2 additions & 1 deletion src/FsOboParser/FastOboGraph.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace FsOboParser

//open OboTerm

//open type OboTerm


////########################################
Expand Down
15 changes: 15 additions & 0 deletions src/FsOboParser/OboOntology.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ type OboOntology =
System.IO.File.ReadAllLines path
|> OboOntology.fromLines verbose

/// Takes a list of OboEntries and returns the OboOntology based on it.
static member fromOboEntries entries =

let rec loop terms typedefs entries =
match entries with
| h :: t ->
match h with
| Term term -> loop (term :: terms) typedefs t
| TypeDef typedef -> loop terms (typedef :: typedefs) t
| [] -> terms, typedefs

let terms, typedefs = loop [] [] entries

OboOntology.create terms typedefs

/// Writes an OBO Ontology to term and type def stanzas in line form.
static member toLines (oboOntology : OboOntology) =
seq {
Expand Down

0 comments on commit 28b8da1

Please sign in to comment.