Skip to content

Commit

Permalink
Refactor namespaces, add Globals namespace with default strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jan 10, 2024
1 parent ce71ac4 commit 4d84f7f
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 119 deletions.
2 changes: 1 addition & 1 deletion src/ARCTokenization/ARCTokenization.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<None Include="structural_ontologies/investigation_metadata_structural_ontology.yml" />
<None Include="structural_ontologies/study_metadata_structural_ontology.yml" />
<None Include="structural_ontologies/assay_metadata_structural_ontology.yml" />
<Compile Include="Globals.fs" />
<Compile Include="Address.fs" />
<Compile Include="Terms.fs" />
<Compile Include="Regex.fs" />
Expand All @@ -43,7 +44,6 @@
<Compile Include="Worksheet.fs" />
<Compile Include="FileSystem.fs" />
<Compile Include="TopLevelParsers.fs" />
<Compile Include="ParamBasedParsers.fs" />
<Compile Include="ARCMock.fs" />
</ItemGroup>

Expand Down
15 changes: 15 additions & 0 deletions src/ARCTokenization/Globals.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Globals

open ARCtrl
open ARCtrl.ISA

let [<Literal>] INVESTIGATION_FILE_NAME = Path.InvestigationFileName
let [<Literal>] INVESTIGATION_METADATA_SHEET_NAME = ARCtrl.ISA.Spreadsheet.ArcInvestigation.metaDataSheetName

let [<Literal>] STUDY_FILE_NAME = Path.StudyFileName
let [<Literal>] STUDY_METADATA_SHEET_NAME = ARCtrl.ISA.Spreadsheet.ArcStudy.metaDataSheetName
let [<Literal>] STUDY_OBSOLETE_METADATA_SHEET_NAME= ARCtrl.ISA.Spreadsheet.ArcStudy.obsoleteMetaDataSheetName

let [<Literal>] ASSAY_FILE_NAME = Path.AssayFileName
let [<Literal>] ASSAY_METADATA_SHEET_NAME = ARCtrl.ISA.Spreadsheet.ArcAssay.metaDataSheetName
let [<Literal>] ASSAY_OBSOLETE_METADATA_SHEET_NAME = ARCtrl.ISA.Spreadsheet.ArcAssay.obsoleteMetaDataSheetName
54 changes: 0 additions & 54 deletions src/ARCTokenization/ParamBasedParsers.fs

This file was deleted.

269 changes: 217 additions & 52 deletions src/ARCTokenization/TopLevelParsers.fs

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/ARCTokenization/Workbook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Workbook =

let getInvestigationMetadataSheet (useLastSheetOnIncorrectName: bool) investigation =
try
FsWorkbook.getWorksheetByName "isa_investigation" investigation
FsWorkbook.getWorksheetByName Globals.INVESTIGATION_METADATA_SHEET_NAME investigation
with _ ->
if useLastSheetOnIncorrectName then
FsWorkbook.getWorksheets investigation
Expand All @@ -19,22 +19,22 @@ module Workbook =

let getStudyMetadataSheet (useLastSheetOnIncorrectName: bool) study =
try
FsWorkbook.tryGetWorksheetByName "Study" study
|> Option.defaultValue (FsWorkbook.getWorksheetByName "isa_study" study)
FsWorkbook.tryGetWorksheetByName Globals.STUDY_OBSOLETE_METADATA_SHEET_NAME study
|> Option.defaultValue (FsWorkbook.getWorksheetByName Globals.STUDY_METADATA_SHEET_NAME study)
with _ ->
if useLastSheetOnIncorrectName then
FsWorkbook.getWorksheets study
|> Seq.last
else
failwith "No worksheet named 'Study' or 'isa_study' found in the workbook"
failwith $"No worksheet named {Globals.STUDY_OBSOLETE_METADATA_SHEET_NAME} or {Globals.STUDY_METADATA_SHEET_NAME} found in the workbook"

let getAssayMetadataSheet (useLastSheetOnIncorrectName: bool) assay =
try
FsWorkbook.tryGetWorksheetByName "Assay" assay
|> Option.defaultValue (FsWorkbook.getWorksheetByName "isa_assay" assay)
FsWorkbook.tryGetWorksheetByName Globals.ASSAY_OBSOLETE_METADATA_SHEET_NAME assay
|> Option.defaultValue (FsWorkbook.getWorksheetByName Globals.ASSAY_METADATA_SHEET_NAME assay)
with _ ->
if useLastSheetOnIncorrectName then
FsWorkbook.getWorksheets assay
|> Seq.last
else
failwith "No worksheet named 'Assay' or 'isa_assay' found in the workbook"
failwith $"No worksheet named {Globals.ASSAY_OBSOLETE_METADATA_SHEET_NAME} or {Globals.ASSAY_METADATA_SHEET_NAME} found in the workbook"
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ module AssayMetadata =
[<Fact>]
let ``Simple study is parsed from filepath CvParam with all structural ontology terms in order`` () =
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "Fixtures/correct/assay_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "assay_simple.xlsx" Assay.parseMetadataSheetFromFile [fakePath] |> Seq.head
let actual =
[fakePath]
|> Assay.parseMetadataSheetsFromTokens(
FileName = "assay_simple.xlsx"
)
|> Seq.head
Assert.All((List.zip allExpectedMetadataTermsFull actual), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module InvestigationMetadata =

open TestUtils

let parsedInvestigationMetadataEmpty = Investigation.parseMetadataSheetFromFile "Fixtures/incorrect/investigation_empty.xlsx"
let parsedInvestigationMetadataSimple = Investigation.parseMetadataSheetFromFile "Fixtures/correct/investigation_simple.xlsx"
let parsedInvestigationMetadataEmpty = Investigation.parseMetadataSheetFromFile() "Fixtures/incorrect/investigation_empty.xlsx"
let parsedInvestigationMetadataSimple = Investigation.parseMetadataSheetFromFile() "Fixtures/correct/investigation_simple.xlsx"

let allExpectedMetadataTermsEmpty =
Terms.InvestigationMetadata.nonObsoleteNonRootCvTerms
Expand Down Expand Up @@ -62,7 +62,13 @@ module InvestigationMetadata =
[<Fact>]
let ``Simple investigation is parsed from filepath CvParam with all structural ontology terms in order`` () =
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "Fixtures/correct/investigation_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "investigation_simple.xlsx" Investigation.parseMetadataSheetFromFile [fakePath] |> Seq.head
let actual =
[fakePath]
|> Investigation.parseMetadataSheetsFromTokens(
FileName = "investigation_simple.xlsx"
)
|> Seq.head

Assert.All((List.zip allExpectedMetadataTermsFull actual), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ module StudyMetadata =
[<Fact>]
let ``Simple study is parsed from filepath CvParam with all structural ontology terms in order`` () =
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = "Fixtures/correct/study_simple.xlsx")
let actual = ParamBasedParsers.parseIsaMetadataSheetFromCvp "study_simple.xlsx" Study.parseMetadataSheetfromFile [fakePath] |> Seq.head
let actual =
[fakePath]
|> Study.parseMetadataSheetsFromTokens(
FileName = "study_simple.xlsx"
)
|> Seq.head
Assert.All((List.zip allExpectedMetadataTermsFull actual), (fun (expected,actual) ->
CvParam.structuralEquality (expected) (actual :?> CvParam)
))

0 comments on commit 4d84f7f

Please sign in to comment.