Skip to content

Commit

Permalink
adjust assay file header parsing
Browse files Browse the repository at this point in the history
-can now parse brackets inside brackets
-now ignores numbers
  • Loading branch information
HLWeil committed Apr 5, 2022
1 parent 74b5b0f commit 19cb0f6
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/ISADotNet.XLSX/AssayFile/AnnotationColumn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module AnnotationColumn =
/// Parses a string to a column header
static member fromStringHeader header =

let kindPattern = @".*(?= [\[\(])"
let namePattern = @"(?<= \[)[^#\]]*(?=[\]#])"
let kindPattern = @"[^\[(]*(?= [\[\(])"
let namePattern = @"(?<= \[).*(?=[\]])"
let ontologySourcePattern = @"(?<=\()\S+:[^;)#]*(?=[\)\#])"
let numberPattern = @"(?<=#)\d+(?=[\)\]])"

Expand Down
9 changes: 5 additions & 4 deletions src/ISADotNet.XLSX/AssayFile/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ module Assay =

// Reading the "Assay" metadata sheet. Here metadata
let assayMetaData,contacts =
Spreadsheet.tryGetSheetBySheetName "Assay" doc
|> Option.map (fun sheet ->
match Spreadsheet.tryGetSheetBySheetName "Assay" doc with
| Some sheet ->
sheet
|> SheetData.getRows
|> Seq.map (Row.mapCells (Cell.includeSharedStringValue sst.Value))
|> Seq.map (Row.getIndexedValues None >> Seq.map (fun (i,v) -> (int i) - 1, v))
|> MetaData.fromRows
|> fun (a,p) -> Option.defaultValue Assay.empty a, p
)
|> Option.defaultValue (Assay.empty,[])
| None ->
printfn "Cannot retrieve metadata: Assay file does not contain \"Assay\" sheet."
Assay.empty,[]

// All sheetnames in the spreadsheetDocument
let sheetNames =
Expand Down
9 changes: 5 additions & 4 deletions src/ISADotNet.XLSX/StudyFile/Study.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ module Study =

// Reading the "Study" metadata sheet. Here metadata
let studyMetaData =
Spreadsheet.tryGetSheetBySheetName "Study" doc
|> Option.map (fun sheet ->
match Spreadsheet.tryGetSheetBySheetName "Study" doc with
| Some sheet ->
sheet
|> SheetData.getRows
|> Seq.map (Row.mapCells (Cell.includeSharedStringValue sst.Value))
|> Seq.map (Row.getIndexedValues None >> Seq.map (fun (i,v) -> (int i) - 1, v))
|> MetaData.fromRows

)
|> Option.defaultValue (Study.empty)
| None ->
printfn "Cannot retrieve metadata: Study file does not contain \"Study\" sheet."
Study.empty

// All sheetnames in the spreadsheetDocument
let sheetNames =
Expand Down
45 changes: 32 additions & 13 deletions src/ISADotnet/DataModel/Factor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,40 @@ type Factor =
factor.FactorType |> Option.map OntologyAnnotation.toString |> Option.defaultValue ("","","")

/// Returns the name of the factor as string
[<System.Obsolete("This function is deprecated. Use the member \"GetName\" instead.")>]
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.NameAsString =
this.Name
|> Option.defaultValue ""

/// Returns the name of the factor with the number as string (e.g. "temperature #2")
[<System.Obsolete("This function is deprecated. Use the member \"GetNameWithNumber\" instead.")>]
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.NameAsStringWithNumber =
this.FactorType
|> Option.map (fun oa -> oa.GetNameWithNumber)
|> Option.defaultValue ""

/// Returns the name of the factor as string
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.GetName =
this.Name
|> Option.defaultValue ""

/// Returns the name of the factor with the number as string (e.g. "temperature #2")
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.GetNameWithNumber =
this.FactorType
|> Option.map (fun oa -> oa.GetName)
|> Option.map (fun oa -> oa.NameText)
|> Option.defaultValue ""

member this.NameText =
this.Name
|> Option.defaultValue ""

interface IISAPrintable with
member this.Print() =
this.ToString()
member this.PrintCompact() =
"OA " + this.GetNameWithNumber
"OA " + this.NameText

[<AnyOf>]
type Value =
Expand Down Expand Up @@ -115,7 +121,7 @@ type Value =

member this.AsString =
match this with
| Value.Ontology oa -> oa.GetName
| Value.Ontology oa -> oa.NameText
| Value.Float f -> string f
| Value.Int i -> string i
| Value.Name s -> s
Expand All @@ -125,7 +131,7 @@ type Value =
this.ToString()
member this.PrintCompact() =
match this with
| Ontology oa -> oa.GetName
| Ontology oa -> oa.NameText
| Int i -> sprintf "%i" i
| Float f -> sprintf "%f" f
| Name n -> n
Expand Down Expand Up @@ -156,32 +162,45 @@ type FactorValue =
static member empty =
FactorValue.create()

member this.GetValue =
member this.ValueText =
this.Value
|> Option.map (fun oa ->
match oa with
| Value.Ontology oa -> oa.GetName
| Value.Ontology oa -> oa.NameText
| Value.Float f -> string f
| Value.Int i -> string i
| Value.Name s -> s
)
|> Option.defaultValue ""

member this.GetValueWithUnit =
[<System.Obsolete("This function is deprecated. Use the member \"ValueText\" instead.")>]
member this.GetValue = this.ValueText

member this.ValueWithUnitText =
let unit =
this.Unit |> Option.map (fun oa -> oa.GetName)
let v = this.GetValue
this.Unit |> Option.map (fun oa -> oa.NameText)
let v = this.ValueText
match unit with
| Some u -> sprintf "%s %s" v u
| None -> v

[<System.Obsolete("This function is deprecated. Use the member \"ValueWithUnitText\" instead.")>]
member this.GetValueWithUnit = this.ValueWithUnitText

member this.NameText =
this.Category
|> Option.map (fun factor -> factor.NameText)
|> Option.defaultValue ""

/// Returns the name of the category as string
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.GetName =
this.Category
|> Option.map (fun factor -> factor.GetName)
|> Option.defaultValue ""

/// Returns the name of the category with the number as string (e.g. "temperature #2")
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.GetNameWithNumber =
this.Category
|> Option.map (fun oa -> oa.GetNameWithNumber)
Expand All @@ -191,8 +210,8 @@ type FactorValue =
member this.Print() =
this.ToString()
member this.PrintCompact() =
let category = this.Category |> Option.map (fun f -> f.GetName)
let unit = this.Unit |> Option.map (fun oa -> oa.GetName)
let category = this.Category |> Option.map (fun f -> f.NameText)
let unit = this.Unit |> Option.map (fun oa -> oa.NameText)
let value =
this.Value
|> Option.map (fun v ->
Expand Down
52 changes: 38 additions & 14 deletions src/ISADotnet/DataModel/Material.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type MaterialAttribute =
MaterialAttribute.make None (Option.fromValueWithDefault OntologyAnnotation.empty oa)

/// Create a ISAJson MaterialAttribute from string entries, where the term name can contain a # separated number. e.g: "temperature unit #2"
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
static member fromStringWithNumber (term:string) (source:string) (accession:string) =
let oa = OntologyAnnotation.fromStringWithNumber term source accession
MaterialAttribute.make None (Option.fromValueWithDefault OntologyAnnotation.empty oa)
Expand All @@ -39,6 +40,7 @@ type MaterialAttribute =
MaterialAttribute.make None (Option.fromValueWithDefault OntologyAnnotation.empty oa)

/// Create a ISAJson MaterialAttribute from string entries, where the term name can contain a # separated number. e.g: "temperature unit #2"
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
static member fromStringWithNumberAndComments (term:string) (source:string) (accession:string) (comments : Comment list) =
let oa = OntologyAnnotation.fromStringWithNumberAndComments term source accession comments
MaterialAttribute.make None (Option.fromValueWithDefault OntologyAnnotation.empty oa)
Expand All @@ -48,42 +50,51 @@ type MaterialAttribute =
ma.CharacteristicType |> Option.map OntologyAnnotation.toString |> Option.defaultValue ("","","")

/// Returns the name of the characteristic as string
[<System.Obsolete("This function is deprecated. Use the member \"GetName\" instead.")>]
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.NameAsString =
this.CharacteristicType
|> Option.map (fun oa -> oa.NameAsString)
|> Option.defaultValue ""

/// Returns the name of the characteristic with the number as string (e.g. "temperature #2")
[<System.Obsolete("This function is deprecated. Use the member \"GetNameWithNumber\" instead.")>]
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.NameAsStringWithNumber =
this.CharacteristicType
|> Option.map (fun oa -> oa.NameAsStringWithNumber)
|> Option.defaultValue ""

/// Returns the name of the characteristic as string
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.GetName =
this.CharacteristicType
|> Option.map (fun oa -> oa.GetName)
|> Option.defaultValue ""

/// Returns number of Material attribute
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.Number =
this.CharacteristicType
|> Option.bind (fun oa -> oa.Number)
|> Option.defaultValue ""

/// Returns the name of the characteristic with the number as string (e.g. "temperature #2")
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.GetNameWithNumber =
this.CharacteristicType
|> Option.map (fun oa -> oa.GetNameWithNumber)
|> Option.defaultValue ""

/// Returns the name of the characteristic as string
member this.NameText =
this.CharacteristicType
|> Option.map (fun oa -> oa.NameText)
|> Option.defaultValue ""

interface IISAPrintable with
member this.Print() =
this.ToString()
member this.PrintCompact() =
"OA " + this.GetNameWithNumber
"OA " + this.NameText

type MaterialAttributeValue =
{
Expand Down Expand Up @@ -114,42 +125,50 @@ type MaterialAttributeValue =
MaterialAttributeValue.create()

/// Returns the name of the category as string
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.GetName =
this.Category
|> Option.map (fun oa -> oa.GetName)
|> Option.defaultValue ""

/// Returns the name of the category with the number as string (e.g. "temperature #2")
[<System.Obsolete("This function is deprecated. Numbering support will soon be dropped")>]
member this.GetNameWithNumber =
this.Category
|> Option.map (fun oa -> oa.GetNameWithNumber)
|> Option.defaultValue ""

member this.GetValue =
member this.ValueText =
this.Value
|> Option.map (fun oa ->
match oa with
| Value.Ontology oa -> oa.GetName
| Value.Ontology oa -> oa.NameText
| Value.Float f -> string f
| Value.Int i -> string i
| Value.Name s -> s
)
|> Option.defaultValue ""

member this.GetValueWithUnit =
[<System.Obsolete("This function is deprecated. Use the member \"ValueText\" instead.")>]
member this.GetValue = this.ValueText

member this.ValueWithUnitText =
let unit =
this.Unit |> Option.map (fun oa -> oa.GetName)
let v = this.GetValue
this.Unit |> Option.map (fun oa -> oa.NameText)
let v = this.ValueText
match unit with
| Some u -> sprintf "%s %s" v u
| None -> v

[<System.Obsolete("This function is deprecated. Use the member \"ValueWithUnitText\" instead.")>]
member this.GetValueWithUnit = this.ValueWithUnitText

interface IISAPrintable with
member this.Print() =
this.ToString()
member this.PrintCompact() =
let category = this.Category |> Option.map (fun f -> f.GetName)
let unit = this.Unit |> Option.map (fun oa -> oa.GetName)
let category = this.Category |> Option.map (fun f -> f.NameText)
let unit = this.Unit |> Option.map (fun oa -> oa.NameText)
let value =
this.Value
|> Option.map (fun v ->
Expand Down Expand Up @@ -209,21 +228,26 @@ type Material =
static member empty =
Material.create()

[<System.Obsolete("This function is deprecated. Use the member \"GetNameWithNumber\" instead.")>]
[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.NameAsString =
this.Name
|> Option.defaultValue ""


[<System.Obsolete("This function is deprecated. Use the member \"NameText\" instead.")>]
member this.GetName =
this.Name
|> Option.defaultValue ""

member this.NameText =
this.Name
|> Option.defaultValue ""

interface IISAPrintable with
member this.Print() =
this.ToString()
member this.PrintCompact() =
let chars = this.Characteristics |> Option.defaultValue [] |> List.length
match this.MaterialType with
| Some t ->
sprintf "%s [%s; %i characteristics]" this.GetName t.AsString chars
| None -> sprintf "%s [%i characteristics]" this.GetName chars
sprintf "%s [%s; %i characteristics]" this.NameText t.AsString chars
| None -> sprintf "%s [%i characteristics]" this.NameText chars
Loading

0 comments on commit 19cb0f6

Please sign in to comment.