Skip to content

Commit

Permalink
Add FromString, FromStringWithNumber for OntologyAnnotation, Factor, …
Browse files Browse the repository at this point in the history
…MaterialAttribute (Issue #24)
  • Loading branch information
Freymaurer committed Sep 6, 2021
1 parent 6f883e6 commit 035ed55
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/ISADotnet/DataModel/Factor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ type Factor =
FactorType = oa
)

/// Create a ISAJson Ontology Annotation value from ISATab string entries
static member fromStringWithNumber (name:string) (term:string) (accession:string) (source:string) =
let oa =
OntologyAnnotation.fromStringWithNumber term accession source
Factor.create(
Name = name,
FactorType = oa
)

/// Get ISATab string entries from an ISAJson Factor object
static member toString (factor : Factor) =
factor.FactorType |> Option.map OntologyAnnotation.toString |> Option.defaultValue ("","","")
Expand Down
6 changes: 5 additions & 1 deletion src/ISADotnet/DataModel/Material.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ type MaterialAttribute =
static member empty =
MaterialAttribute.create()


/// Create a ISAJson MaterialAttribute from ISATab string entries
static member fromString (term:string) (accession:string) (source:string) =
let oa = OntologyAnnotation.fromString term accession source
MaterialAttribute.create (CharacteristicType = oa)

/// Create a ISAJson MaterialAttribute from ISATab string entries
static member fromStringWithNumber (term:string) (accession:string) (source:string) =
let oa = OntologyAnnotation.fromStringWithNumber term accession source
MaterialAttribute.create (CharacteristicType = oa)

/// Get ISATab string entries from an ISAJson MaterialAttribute object
static member toString (ma : MaterialAttribute) =
ma.CharacteristicType |> Option.map OntologyAnnotation.toString |> Option.defaultValue ("","","")
Expand Down
12 changes: 12 additions & 0 deletions src/ISADotnet/DataModel/Ontology.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ type OntologyAnnotation =
TermAccessionNumber = (source |> URI.fromString)
)

/// Create a ISAJson Ontology Annotation value from ISATab string entries
static member fromStringWithNumber (term:string) (accession:string) (source:string) =
let t,number =
let lastIndex = term.LastIndexOf '#'
term.Remove(lastIndex).Trim(), term.Substring(lastIndex+1).Trim()
OntologyAnnotation.create (
Name = AnnotationValue.fromString t,
TermSourceREF = accession,
TermAccessionNumber = (source |> URI.fromString),
Comments = [ Comment.create(Name = "Number", Value = number) ]
)

/// Get a ISATab string entries from an ISAJson Ontology Annotation object (name,accession,source)
static member toString (oa : OntologyAnnotation) =
oa.Name |> Option.map AnnotationValue.toString |> Option.defaultValue "",
Expand Down

0 comments on commit 035ed55

Please sign in to comment.