Skip to content

Commit

Permalink
fix #35 and #36
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jan 10, 2024
1 parent 49bbb27 commit 560d46b
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/ARCTokenization/Workbook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,44 @@ open ARCTokenization.Terms
module Workbook =

let getInvestigationMetadataSheet (useLastSheetOnIncorrectName: bool) investigation =
try
FsWorkbook.getWorksheetByName Globals.INVESTIGATION_METADATA_SHEET_NAME investigation
with _ ->

match FsWorkbook.tryGetWorksheetByName Globals.INVESTIGATION_METADATA_SHEET_NAME investigation with
| Some ws -> ws
| None ->
if useLastSheetOnIncorrectName then
FsWorkbook.getWorksheets investigation
|> Seq.last
match FsWorkbook.getWorksheets investigation |> Seq.tryLast with
| Some ws -> ws
| None -> failwith "No worksheets found in the workbook."
else
failwith "No worksheet named 'isa_investigation' found in the workbook"
failwith $"No worksheet named {Globals.INVESTIGATION_METADATA_SHEET_NAME} found in the workbook."


let getStudyMetadataSheet (useLastSheetOnIncorrectName: bool) study =
try
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 {Globals.STUDY_OBSOLETE_METADATA_SHEET_NAME} or {Globals.STUDY_METADATA_SHEET_NAME} found in the workbook"

match FsWorkbook.tryGetWorksheetByName Globals.STUDY_OBSOLETE_METADATA_SHEET_NAME study with
| Some ws -> ws
| None ->
match FsWorkbook.tryGetWorksheetByName Globals.STUDY_METADATA_SHEET_NAME study with
| Some ws -> ws
| None ->
if useLastSheetOnIncorrectName then
match FsWorkbook.getWorksheets study |> Seq.tryLast with
| Some ws -> ws
| None -> failwith "No worksheets found in the workbook."
else
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 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 {Globals.ASSAY_OBSOLETE_METADATA_SHEET_NAME} or {Globals.ASSAY_METADATA_SHEET_NAME} found in the workbook"

match FsWorkbook.tryGetWorksheetByName Globals.ASSAY_OBSOLETE_METADATA_SHEET_NAME assay with
| Some ws -> ws
| None ->
match FsWorkbook.tryGetWorksheetByName Globals.ASSAY_METADATA_SHEET_NAME assay with
| Some ws -> ws
| None ->
if useLastSheetOnIncorrectName then
match FsWorkbook.getWorksheets assay |> Seq.tryLast with
| Some ws -> ws
| None -> failwith "No worksheets found in the workbook."
else
failwith $"No worksheet named {Globals.ASSAY_OBSOLETE_METADATA_SHEET_NAME} or {Globals.ASSAY_METADATA_SHEET_NAME} found in the workbook"

0 comments on commit 560d46b

Please sign in to comment.