Skip to content

Commit

Permalink
Rename ARCtrl.Path to ARCtrl.ArcPathHelper #398
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jul 8, 2024
1 parent 8b55020 commit 27d259a
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 79 deletions.
47 changes: 24 additions & 23 deletions src/ARCtrl/ARC.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ARCtrl
namespace ARCtrl

open ARCtrl.FileSystem
open ARCtrl.Contract
Expand All @@ -7,6 +7,7 @@ open ARCtrl.Helper
open ARCtrl.Spreadsheet
open FsSpreadsheet
open Fable.Core
open ARCtrl.ArcPathHelper

module ARCAux =

Expand Down Expand Up @@ -95,7 +96,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
let studies = assay.StudiesRegisteredIn
isa.RemoveAssay(assayIdentifier)
let paths = this.FileSystem.Tree.ToFilePaths()
let assayFolderPath = Path.getAssayFolderPath(assayIdentifier)
let assayFolderPath = getAssayFolderPath(assayIdentifier)
let filteredPaths = paths |> Array.filter (fun p -> p.StartsWith(assayFolderPath) |> not)
this.SetFilePaths(filteredPaths)
[
Expand All @@ -115,8 +116,8 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =

isa.RenameAssay(oldAssayIdentifier,newAssayIdentifier)
let paths = this.FileSystem.Tree.ToFilePaths()
let oldAssayFolderPath = Path.getAssayFolderPath(oldAssayIdentifier)
let newAssayFolderPath = Path.getAssayFolderPath(newAssayIdentifier)
let oldAssayFolderPath = getAssayFolderPath(oldAssayIdentifier)
let newAssayFolderPath = getAssayFolderPath(newAssayIdentifier)
let renamedPaths = paths |> Array.map (fun p -> p.Replace(oldAssayFolderPath,newAssayFolderPath))
this.SetFilePaths(renamedPaths)
[
Expand All @@ -132,7 +133,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
| None -> failwith "Cannot remove study from null ISA value."
isa.RemoveStudy(studyIdentifier)
let paths = this.FileSystem.Tree.ToFilePaths()
let studyFolderPath = Path.getStudyFolderPath(studyIdentifier)
let studyFolderPath = getStudyFolderPath(studyIdentifier)
let filteredPaths = paths |> Array.filter (fun p -> p.StartsWith(studyFolderPath) |> not)
this.SetFilePaths(filteredPaths)
[
Expand All @@ -150,8 +151,8 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =

isa.RenameStudy(oldStudyIdentifier,newStudyIdentifier)
let paths = this.FileSystem.Tree.ToFilePaths()
let oldStudyFolderPath = Path.getStudyFolderPath(oldStudyIdentifier)
let newStudyFolderPath = Path.getStudyFolderPath(newStudyIdentifier)
let oldStudyFolderPath = getStudyFolderPath(oldStudyIdentifier)
let newStudyFolderPath = getStudyFolderPath(newStudyIdentifier)
let renamedPaths = paths |> Array.map (fun p -> p.Replace(oldStudyFolderPath,newStudyFolderPath))
this.SetFilePaths(renamedPaths)
[
Expand Down Expand Up @@ -321,7 +322,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
match this.ISA with
| Some inv ->
let investigationConverter = Spreadsheet.ArcInvestigation.toFsWorkbook
workbooks.Add (Path.InvestigationFileName, (DTOType.ISA_Investigation, investigationConverter inv))
workbooks.Add (InvestigationFileName, (DTOType.ISA_Investigation, investigationConverter inv))
inv.StaticHash <- inv.GetLightHashCode()
inv.Studies
|> Seq.iter (fun s ->
Expand Down Expand Up @@ -356,7 +357,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =

| None ->
//printfn "ARC contains no ISA part."
workbooks.Add (Path.InvestigationFileName, (DTOType.ISA_Investigation, Spreadsheet.ArcInvestigation.toFsWorkbook (ArcInvestigation.create(Identifier.MISSING_IDENTIFIER))))
workbooks.Add (InvestigationFileName, (DTOType.ISA_Investigation, Spreadsheet.ArcInvestigation.toFsWorkbook (ArcInvestigation.create(Identifier.MISSING_IDENTIFIER))))

// Iterates over filesystem and creates a write contract for every file. If possible, include DTO.
_fs.Tree.ToFilePaths(true)
Expand Down Expand Up @@ -466,46 +467,46 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =

let includeRootFiles : Set<string> =
set [
Path.InvestigationFileName
Path.READMEFileName
InvestigationFileName
READMEFileName
]

let includeStudyFiles =
registeredStudies
|> Array.map (fun s ->
let studyFoldername = $"{Path.StudiesFolderName}/{s.Identifier}"
let studyFoldername = $"{StudiesFolderName}/{s.Identifier}"

set [
yield $"{studyFoldername}/{Path.StudyFileName}"
yield $"{studyFoldername}/{Path.READMEFileName}"
yield $"{studyFoldername}/{StudyFileName}"
yield $"{studyFoldername}/{READMEFileName}"

//just allow any constructed path from cell values. there may be occasions where this includes wrong files, but its good enough for now.
for table in s.Tables do
for kv in table.Values do
let textValue = kv.Value.ToFreeTextCell().AsFreeText
yield textValue // from arc root
yield $"{studyFoldername}/{Path.StudiesResourcesFolderName}/{textValue}" // from study root > resources
yield $"{studyFoldername}/{Path.StudiesProtocolsFolderName}/{textValue}" // from study root > protocols
yield $"{studyFoldername}/{StudiesResourcesFolderName}/{textValue}" // from study root > resources
yield $"{studyFoldername}/{StudiesProtocolsFolderName}/{textValue}" // from study root > protocols
]
)
|> Set.unionMany

let includeAssayFiles =
registeredAssays
|> Array.map (fun a ->
let assayFoldername = $"{Path.AssaysFolderName}/{a.Identifier}"
let assayFoldername = $"{AssaysFolderName}/{a.Identifier}"

set [
yield $"{assayFoldername}/{Path.AssayFileName}"
yield $"{assayFoldername}/{Path.READMEFileName}"
yield $"{assayFoldername}/{AssayFileName}"
yield $"{assayFoldername}/{READMEFileName}"

//just allow any constructed path from cell values. there may be occasions where this includes wrong files, but its good enough for now.
for table in a.Tables do
for kv in table.Values do
let textValue = kv.Value.ToFreeTextCell().AsFreeText
yield textValue // from arc root
yield $"{assayFoldername}/{Path.AssayDatasetFolderName}/{textValue}" // from assay root > dataset
yield $"{assayFoldername}/{Path.AssayProtocolsFolderName}/{textValue}" // from assay root > protocols
yield $"{assayFoldername}/{AssayDatasetFolderName}/{textValue}" // from assay root > dataset
yield $"{assayFoldername}/{AssayProtocolsFolderName}/{textValue}" // from assay root > protocols
]
)
|> Set.unionMany
Expand All @@ -519,8 +520,8 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
fsCopy.Tree
|> FileSystemTree.toFilePaths()
|> Array.filter (fun p ->
p.StartsWith(Path.WorkflowsFolderName)
|| p.StartsWith(Path.RunsFolderName)
p.StartsWith(WorkflowsFolderName)
|| p.StartsWith(RunsFolderName)
|| includeFiles.Contains(p)
)
|> FileSystemTree.fromFilePaths
Expand Down
6 changes: 3 additions & 3 deletions src/Contract/ARC.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ARCtrl.Contract.ARC
module ARCtrl.Contract.ARC

open ARCtrl.Path
open ARCtrl.ArcPathHelper

open ARCtrl.Contract

Expand All @@ -13,7 +13,7 @@ open ARCtrl.Contract
// 3. We ignore all other .xlsx files.
/// Tries to create READ contract with DTOType = ISA_Assay, ISA_Study or ISA_Investigation from given path relative to ARC root.
let tryISAReadContractFromPath (path: string) =
let split = ARCtrl.Path.split path
let split = split path
match split with
| InvestigationPath p ->
Some <| Contract.createRead(p, DTOType.ISA_Investigation)
Expand Down
8 changes: 4 additions & 4 deletions src/Contract/ArcAssay.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace ARCtrl.Contract
namespace ARCtrl.Contract

open ARCtrl
open ARCtrl.FileSystem
open ARCtrl.Path
open ARCtrl.Spreadsheet
open ARCtrl
open ARCtrl.ArcPathHelper
open ARCtrl.Helper
open FsSpreadsheet

Expand All @@ -14,7 +14,7 @@ module AssayContractExtensions =
let (|AssayPath|_|) (input) =
match input with
| [|AssaysFolderName; anyAssayName; AssayFileName|] ->
let path = ARCtrl.Path.combineMany input
let path = combineMany input
Some path
| _ -> None

Expand Down
6 changes: 3 additions & 3 deletions src/Contract/ArcInvestigation.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ARCtrl.Contract
namespace ARCtrl.Contract

open ARCtrl.FileSystem
open ARCtrl.Path
open ARCtrl.ArcPathHelper
open ARCtrl.Spreadsheet
open ARCtrl
open ARCtrl.Helper
Expand All @@ -14,7 +14,7 @@ module InvestigationContractExtensions =
let (|InvestigationPath|_|) (input) =
match input with
| [|InvestigationFileName|] ->
let path = ARCtrl.Path.combineMany input
let path = ARCtrl.ArcPathHelper.combineMany input
Some path
| _ -> None

Expand Down
6 changes: 3 additions & 3 deletions src/Contract/ArcStudy.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ARCtrl.Contract
namespace ARCtrl.Contract

open ARCtrl.FileSystem
open ARCtrl.Path
open ARCtrl.ArcPathHelper
open ARCtrl.Spreadsheet
open ARCtrl
open ARCtrl.Helper
Expand All @@ -14,7 +14,7 @@ module StudyContractExtensions =
let (|StudyPath|_|) (input) =
match input with
| [|StudiesFolderName; anyStudyName; StudyFileName|] ->
let path = ARCtrl.Path.combineMany input
let path = ARCtrl.ArcPathHelper.combineMany input
Some path
| _ -> None

Expand Down
8 changes: 4 additions & 4 deletions src/Contract/Datamap.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ARCtrl.Contract
namespace ARCtrl.Contract

open ARCtrl.FileSystem
open ARCtrl.Path
open ARCtrl.ArcPathHelper
open ARCtrl.Spreadsheet
open ARCtrl
open ARCtrl.Helper
Expand All @@ -13,10 +13,10 @@ module DatamapContractExtensions =
let (|DatamapPath|_|) (input) =
match input with
| [|AssaysFolderName; anyAssayName; DataMapFileName|] ->
let path = ARCtrl.Path.combineMany input
let path = ARCtrl.ArcPathHelper.combineMany input
Some path
| [|StudiesFolderName; anyStudyName; DataMapFileName|] ->
let path = ARCtrl.Path.combineMany input
let path = ARCtrl.ArcPathHelper.combineMany input
Some path
| _ -> None

Expand Down
8 changes: 4 additions & 4 deletions src/Contract/ValidationPackagesConfig.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ARCtrl.Contract
namespace ARCtrl.Contract

open ARCtrl.FileSystem
open ARCtrl.Path
open ARCtrl.ArcPathHelper
open ARCtrl
open ARCtrl.Yaml
open ARCtrl.Helper
Expand All @@ -13,11 +13,11 @@ module ValidationPackagesConfigExtensions =
let (|ValidationPackagesYamlPath|_|) (input) =
match input with
| [|ARCConfigFolderName; ValidationPackagesYamlFileName|] ->
let path = ARCtrl.Path.combineMany input
let path = ARCtrl.ArcPathHelper.combineMany input
Some path
| _ -> None

let internal config_file_path = [|ARCConfigFolderName; ValidationPackagesYamlFileName|] |> ARCtrl.Path.combineMany
let internal config_file_path = [|ARCConfigFolderName; ValidationPackagesYamlFileName|] |> ARCtrl.ArcPathHelper.combineMany

type ValidationPackagesConfig with

Expand Down
8 changes: 4 additions & 4 deletions src/Core/ArcTypes.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace rec ARCtrl
namespace rec ARCtrl

open Fable.Core
open ARCtrl.Helper
Expand Down Expand Up @@ -143,7 +143,7 @@ type ArcAssay(identifier: string, ?measurementType : OntologyAnnotation, ?techno
(comments : ResizeArray<Comment>) =
ArcAssay(identifier = identifier, ?measurementType = measurementType, ?technologyType = technologyType, ?technologyPlatform = technologyPlatform, tables =tables, ?datamap = datamap, performers = performers, comments = comments)

static member FileName = ARCtrl.Path.AssayFileName
static member FileName = ARCtrl.ArcPathHelper.AssayFileName
member this.StudiesRegisteredIn
with get () =
match this.Investigation with
Expand Down Expand Up @@ -585,7 +585,7 @@ type ArcStudy(identifier : string, ?title, ?description, ?submissionDate, ?publi
(this.Comments.Count = 0)

// Not sure how to handle this best case.
static member FileName = ARCtrl.Path.StudyFileName
static member FileName = ARCtrl.ArcPathHelper.StudyFileName
//member this.FileName = ArcStudy.FileName

/// Returns the count of registered assay *identifiers*. This is not necessarily the same as the count of registered assays, as not all identifiers correspond to an existing assay.
Expand Down Expand Up @@ -1147,7 +1147,7 @@ type ArcInvestigation(identifier : string, ?title : string, ?description : strin
member this.Remarks with get() = remarks and set(n) = remarks <- n
member this.StaticHash with get() = staticHash and set(h) = staticHash <- h

static member FileName = ARCtrl.Path.InvestigationFileName
static member FileName = ARCtrl.ArcPathHelper.InvestigationFileName

static member init(identifier: string) = ArcInvestigation identifier
static member create(identifier : string, ?title : string, ?description : string, ?submissionDate : string, ?publicReleaseDate : string, ?ontologySourceReferences, ?publications, ?contacts, ?assays : ResizeArray<ArcAssay>, ?studies : ResizeArray<ArcStudy>,?registeredStudyIdentifiers : ResizeArray<string>, ?comments : ResizeArray<Comment>, ?remarks) =
Expand Down
18 changes: 9 additions & 9 deletions src/Core/Helper/Identifier.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// This module contains helper functions to handle study/assay/investigation identifiers in an unsafe, forced way.
/// This module contains helper functions to handle study/assay/investigation identifiers in an unsafe, forced way.
module ARCtrl.Helper.Identifier

open Regex.ActivePatterns
Expand Down Expand Up @@ -75,15 +75,15 @@ module Assay =
/// <param name="identifier">Any correct assay identifier</param>
let fileNameFromIdentifier (identifier: string) : string =
checkValidCharacters (identifier)
ARCtrl.Path.combineMany [|ARCtrl.Path.AssaysFolderName; identifier; ARCtrl.Path.AssayFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.AssaysFolderName; identifier; ARCtrl.ArcPathHelper.AssayFileName|]

/// <summary>
/// On writing a xlsx file we unify our output to a relative path to ARC root. So: `assays/assayIdentifier/isa.assay.xlsx`.
/// </summary>
/// <param name="identifier">Any correct assay identifier</param>
let tryFileNameFromIdentifier (identifier: string) : string option =
if tryCheckValidCharacters (identifier) then
ARCtrl.Path.combineMany [|ARCtrl.Path.AssaysFolderName; identifier; ARCtrl.Path.AssayFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.AssaysFolderName; identifier; ARCtrl.ArcPathHelper.AssayFileName|]
|> Some
else None

Expand All @@ -94,15 +94,15 @@ module Assay =
/// <param name="identifier">Any correct assay identifier</param>
let datamapFileNameFromIdentifier (identifier: string) : string =
checkValidCharacters (identifier)
ARCtrl.Path.combineMany [|ARCtrl.Path.AssaysFolderName; identifier; ARCtrl.Path.DataMapFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.AssaysFolderName; identifier; ARCtrl.ArcPathHelper.DataMapFileName|]

/// <summary>
/// On writing a xlsx file we unify our output to a relative path to ARC root. So: `assays/assayIdentifier/isa.datamap.xlsx`.
/// </summary>
/// <param name="identifier">Any correct assay identifier</param>
let tryDatamapFileNameFromIdentifier (identifier: string) : string option =
if tryCheckValidCharacters (identifier) then
ARCtrl.Path.combineMany [|ARCtrl.Path.AssaysFolderName; identifier; ARCtrl.Path.DataMapFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.AssaysFolderName; identifier; ARCtrl.ArcPathHelper.DataMapFileName|]
|> Some
else None

Expand Down Expand Up @@ -143,15 +143,15 @@ module Study =
/// <param name="identifier">Any correct study identifier</param>
let fileNameFromIdentifier (identifier: string) : string =
checkValidCharacters (identifier)
ARCtrl.Path.combineMany [|ARCtrl.Path.StudiesFolderName; identifier; ARCtrl.Path.StudyFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.StudiesFolderName; identifier; ARCtrl.ArcPathHelper.StudyFileName|]

/// <summary>
/// On writing a xlsx file we unify our output to a relative path to ARC root. So: `studies/studyIdentifier/isa.study.xlsx`.
/// </summary>
/// <param name="identifier">Any correct study identifier</param>
let tryFileNameFromIdentifier (identifier: string) : string option =
if tryCheckValidCharacters (identifier) then
ARCtrl.Path.combineMany [|ARCtrl.Path.StudiesFolderName; identifier; ARCtrl.Path.StudyFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.StudiesFolderName; identifier; ARCtrl.ArcPathHelper.StudyFileName|]
|> Some
else None

Expand All @@ -161,14 +161,14 @@ module Study =
/// <param name="identifier">Any correct study identifier</param>
let datamapFileNameFromIdentifier (identifier: string) : string =
checkValidCharacters (identifier)
ARCtrl.Path.combineMany [|ARCtrl.Path.StudiesFolderName; identifier; ARCtrl.Path.DataMapFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.StudiesFolderName; identifier; ARCtrl.ArcPathHelper.DataMapFileName|]

/// <summary>
/// On writing a xlsx file we unify our output to a relative path to ARC root. So: `studies/studyIdentifier/isa.investigation.xlsx`.
/// </summary>
/// <param name="identifier">Any correct study identifier</param>
let tryDatamapFileNameFromIdentifier (identifier: string) : string option =
if tryCheckValidCharacters (identifier) then
ARCtrl.Path.combineMany [|ARCtrl.Path.StudiesFolderName; identifier; ARCtrl.Path.DataMapFileName|]
ARCtrl.ArcPathHelper.combineMany [|ARCtrl.ArcPathHelper.StudiesFolderName; identifier; ARCtrl.ArcPathHelper.DataMapFileName|]
|> Some
else None
Loading

0 comments on commit 27d259a

Please sign in to comment.