Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename top-level ARC IO functions #480

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 85 additions & 42 deletions src/ARCtrl/ARC.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) =
with get() = _fs
and set(fs) = _fs <- fs

member this.WriteAsync(arcPath) =
member this.TryWriteAsync(arcPath) =
this.GetWriteContracts()
|> fullFillContractBatchAsync arcPath

member this.UpdateAsync(arcPath) =
member this.TryUpdateAsync(arcPath) =
this.GetUpdateContracts()
|> fullFillContractBatchAsync arcPath

static member loadAsync (arcPath : string) =
static member tryLoadAsync (arcPath : string) =
crossAsync {

let! paths = FileSystemHelper.getAllFilePathsAsync arcPath
Expand Down Expand Up @@ -138,7 +138,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) =
s.ToUpdateContract()
|]

member this.RemoveAssayAsync(arcPath : string, assayIdentifier: string) =
member this.TryRemoveAssayAsync(arcPath : string, assayIdentifier: string) =
this.GetAssayRemoveContracts(assayIdentifier)
|> fullFillContractBatchAsync arcPath

Expand All @@ -160,7 +160,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) =
yield! this.GetUpdateContracts()
|]

member this.RenameAssayAsync(arcPath : string, oldAssayIdentifier: string, newAssayIdentifier: string) =
member this.TryRenameAssayAsync(arcPath : string, oldAssayIdentifier: string, newAssayIdentifier: string) =
this.GetAssayRenameContracts(oldAssayIdentifier,newAssayIdentifier)
|> fullFillContractBatchAsync arcPath

Expand All @@ -179,7 +179,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) =
isa.ToUpdateContract()
|]

member this.RemoveStudyAsync(arcPath : string, studyIdentifier: string) =
member this.TryRemoveStudyAsync(arcPath : string, studyIdentifier: string) =
this.GetStudyRemoveContracts(studyIdentifier)
|> fullFillContractBatchAsync arcPath

Expand All @@ -201,60 +201,103 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) =
yield! this.GetUpdateContracts()
|]

member this.RenameStudyAsync(arcPath : string, oldStudyIdentifier: string, newStudyIdentifier: string) =
member this.TryRenameStudyAsync(arcPath : string, oldStudyIdentifier: string, newStudyIdentifier: string) =
this.GetStudyRenameContracts(oldStudyIdentifier,newStudyIdentifier)
|> fullFillContractBatchAsync arcPath


member this.WriteAsync(arcPath) =
crossAsync {
let! result = this.TryWriteAsync(arcPath)
match result with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not write ARC, failed with the following errors %s" appended
}

member this.UpdateAsync(arcPath) =
crossAsync {
let! result = this.TryUpdateAsync(arcPath)
match result with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not update ARC, failed with the following errors %s" appended
}

member this.RemoveAssayAsync(arcPath, assayIdentifier) =
crossAsync {
let! result = this.TryRemoveAssayAsync(arcPath, assayIdentifier)
match result with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not remove assay, failed with the following errors %s" appended
}

member this.RenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier) =
crossAsync {
let! result = this.TryRenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier)
match result with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not rename assay, failed with the following errors %s" appended
}

member this.RemoveStudyAsync(arcPath, studyIdentifier) =
crossAsync {
let! result = this.TryRemoveStudyAsync(arcPath, studyIdentifier)
match result with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not remove study, failed with the following errors %s" appended
}

member this.RenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier) =
crossAsync {
let! result = this.TryRenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier)
match result with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not rename study, failed with the following errors %s" appended
}

static member loadAsync (arcPath) =
crossAsync {
let! result = ARC.tryLoadAsync arcPath
match result with
| Ok arc -> return arc
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not load ARC, failed with the following errors %s" appended
return (ARC())
}

#if FABLE_COMPILER_PYTHON || !FABLE_COMPILER
member this.Write(arcPath) =
match Async.RunSynchronously (this.WriteAsync(arcPath)) with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not write ARC, failed with the following errors %s" appended
Async.RunSynchronously (this.WriteAsync(arcPath))

member this.Update(arcPath) =
match Async.RunSynchronously (this.UpdateAsync(arcPath)) with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not update ARC, failed with the following errors %s" appended
Async.RunSynchronously (this.UpdateAsync(arcPath))

member this.RemoveAssay(arcPath, assayIdentifier) =
match Async.RunSynchronously (this.RemoveAssayAsync(arcPath, assayIdentifier)) with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not remove assay, failed with the following errors %s" appended
Async.RunSynchronously (this.RemoveAssayAsync(arcPath, assayIdentifier))

member this.RenameAssay(arcPath, oldAssayIdentifier, newAssayIdentifier) =
match Async.RunSynchronously (this.RenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier)) with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not rename assay, failed with the following errors %s" appended
Async.RunSynchronously (this.RenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier))

member this.RemoveStudy(arcPath, studyIdentifier) =
match Async.RunSynchronously (this.RemoveStudyAsync(arcPath, studyIdentifier)) with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not remove study, failed with the following errors %s" appended
Async.RunSynchronously (this.RemoveStudyAsync(arcPath, studyIdentifier))

member this.RenameStudy(arcPath, oldStudyIdentifier, newStudyIdentifier) =
match Async.RunSynchronously (this.RenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier)) with
| Ok _ -> ()
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not rename study, failed with the following errors %s" appended
Async.RunSynchronously (this.RenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier))

static member load (arcPath) =
match Async.RunSynchronously (ARC.loadAsync arcPath) with
| Ok arc -> arc
| Error errors ->
let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n"
failwithf "Could not load ARC, failed with the following errors %s" appended
Async.RunSynchronously (ARC.loadAsync arcPath)
#endif


Expand Down
30 changes: 15 additions & 15 deletions tests/ARCtrl/ARCtrl.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ let tests_load =
testList "Load" [
testCaseCrossAsync "simpleARC" (crossAsync {
let p = TestObjects.IO.testSimpleARC
let! result = ARC.loadAsync(p)
let! result = ARC.tryLoadAsync(p)
let result = Expect.wantOk result "ARC should load successfully"

Expect.isSome result.ISA "Should contain an ISA part"
Expand Down Expand Up @@ -979,7 +979,7 @@ let tests_write =
let p = ArcPathHelper.combine TestObjects.IO.testResultsFolder "ARC_Write_Empty"
let a = ARC()

let! result = a.WriteAsync(p)
let! result = a.TryWriteAsync(p)

Expect.wantOk result "ARC should write successfully" |> ignore

Expand Down Expand Up @@ -1014,7 +1014,7 @@ let tests_write =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! result = arc.WriteAsync(p)
let! result = arc.TryWriteAsync(p)
Expect.wantOk result "ARC should write successfully" |> ignore

let expectedPaths =
Expand Down Expand Up @@ -1046,7 +1046,7 @@ let tests_write =
testCaseCrossAsync "LoadSimpleARCAndAddAssay" (crossAsync {
let p = ArcPathHelper.combine TestObjects.IO.testResultsFolder "ARC_Write_SimpleARCWithAssay"

let! readResult = ARC.loadAsync(TestObjects.IO.testSimpleARC)
let! readResult = ARC.tryLoadAsync(TestObjects.IO.testSimpleARC)
let arc = Expect.wantOk readResult "ARC should load correctly"

let i = arc.ISA.Value
Expand All @@ -1060,7 +1060,7 @@ let tests_write =

arc.UpdateFileSystem()

let! writeResult = arc.WriteAsync(p)
let! writeResult = arc.TryWriteAsync(p)

Expect.wantOk writeResult "ARC should write successfully" |> ignore

Expand Down Expand Up @@ -1131,7 +1131,7 @@ let tests_Update =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! writeResult = arc.WriteAsync(p)
let! writeResult = arc.TryWriteAsync(p)

Expect.wantOk writeResult "ARC should write successfully" |> ignore

Expand All @@ -1141,7 +1141,7 @@ let tests_Update =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! updateResult = arc.UpdateAsync(p)
let! updateResult = arc.TryUpdateAsync(p)

Expect.wantOk updateResult "ARC should update successfully" |> ignore

Expand Down Expand Up @@ -1194,14 +1194,14 @@ let tests_renameAssay =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! updateResult = arc.WriteAsync(p)
let! updateResult = arc.TryWriteAsync(p)

Expect.wantOk updateResult "ARC should write successfully" |> ignore

// rename assay
let newAssayName = "MyNewAssay"

let! renameResult = arc.RenameAssayAsync(p,assayName, newAssayName)
let! renameResult = arc.TryRenameAssayAsync(p,assayName, newAssayName)
Expect.wantOk renameResult "Assay should be renamed successfully" |> ignore

let expectedPaths =
Expand Down Expand Up @@ -1247,14 +1247,14 @@ let tests_RenameStudy =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! writeResult = arc.WriteAsync(p)
let! writeResult = arc.TryWriteAsync(p)

Expect.wantOk writeResult "ARC should write successfully" |> ignore

// rename study
let newStudyName = "MyNewStudy"

let! renameResult = arc.RenameStudyAsync(p,studyName, newStudyName)
let! renameResult = arc.TryRenameStudyAsync(p,studyName, newStudyName)
Expect.wantOk renameResult "Study should be renamed successfully" |> ignore

let expectedPaths =
Expand Down Expand Up @@ -1301,13 +1301,13 @@ let tests_RemoveAssay =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! writeResult = arc.WriteAsync(p)
let! writeResult = arc.TryWriteAsync(p)

Expect.wantOk writeResult "ARC should write successfully" |> ignore

// remove assay

let! removeResult = arc.RemoveAssayAsync(p,assayName)
let! removeResult = arc.TryRemoveAssayAsync(p,assayName)
Expect.wantOk removeResult "Assay should be removed successfully" |> ignore

let expectedPaths =
Expand Down Expand Up @@ -1349,13 +1349,13 @@ let tests_RemoveStudy =
arc.ISA <- Some i
arc.UpdateFileSystem()

let! writeResult = arc.WriteAsync(p)
let! writeResult = arc.TryWriteAsync(p)

Expect.wantOk writeResult "ARC should write successfully" |> ignore

// remove study

let! removeResult = arc.RemoveStudyAsync(p,studyName)
let! removeResult = arc.TryRemoveStudyAsync(p,studyName)
Expect.wantOk removeResult "Study should be removed successfully" |> ignore

let expectedPaths =
Expand Down
Loading