Skip to content

Commit

Permalink
add first experimental version of arc.getWriteContracts
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Aug 2, 2023
1 parent 560fadf commit 275323c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
69 changes: 68 additions & 1 deletion src/ARCtrl/ARCtrl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open FileSystem
open Contract
open ISA

open FsSpreadsheet
open Fable.Core

module ARCAux =
Expand Down Expand Up @@ -163,6 +163,73 @@ You could initialized your ARC with `ARC.fromFilePaths` or run `yourArc.addFSFro
)
{this with ISA = Some investigation}


static member updateFileSystemTree(arc) =
match arc.ISA,arc.FileSystem with
| Some inv,_ ->
let studyNames,assayNames =
inv.Studies
|> Seq.fold (fun (studyNames,assayNames) s ->
Array.append studyNames [|s.Identifier|],
Array.append assayNames (s.Assays |> Seq.map (fun a -> a.Identifier) |> Array.ofSeq)

) ([||],[||])
let workflows = FileSystemTree.createWorkflowsFolder [||]
let runs = FileSystemTree.createRunsFolder [||]
let assays = FileSystemTree.createAssaysFolder (assayNames |> Array.map FileSystemTree.initAssayFolder)
let studies = FileSystemTree.createStudiesFolder (studyNames |> Array.map FileSystemTree.initStudyFolder)
let investigation = FileSystemTree.createFile "isa.investigation.xlsx"
let tree = FileSystemTree.createFolder(inv.Identifier, [|investigation;assays;studies;workflows;runs|])
let fs = FileSystem.create(tree)
ARC.create(inv,fs = fs)
| _ ->
let workflows = FileSystemTree.createWorkflowsFolder [||]
let runs = FileSystemTree.createRunsFolder [||]
let assays = FileSystemTree.createAssaysFolder [||]
let studies = FileSystemTree.createStudiesFolder [||]
let tree = FileSystemTree.createFolder(Identifier.createMissingIdentifier(), [|assays;studies;workflows;runs|])
let fs = FileSystem.create(tree)
ARC.create(fs = fs)


/// <summary>
/// This function creates the ARC-model from fullfilled READ contracts. The necessary READ contracts can be created with `ARC.getReadContracts`.
/// </summary>
/// <param name="cArr">The fullfilled READ contracts.</param>
/// <param name="enableLogging">If this flag is set true, the function will print any missing/found assays/studies to the console. *Default* = false</param>
member this.getWriteContracts () =
let arc = ARC.updateFileSystemTree this
let workbooks = System.Collections.Generic.Dictionary<string, DTOType*FsWorkbook>()
match arc.ISA with
| Some inv ->
workbooks.Add ("isa.investigation.xlsx", (DTOType.ISA_Investigation, ISA.Spreadsheet.ArcInvestigation.toFsWorkbook inv))
inv.Studies
|> Seq.iter (fun s ->
workbooks.Add (
Path.combineMany[|"studies";s.Identifier;"isa.study.xlsx"|],
(DTOType.ISA_Study, ISA.Spreadsheet.ArcStudy.toFsWorkbook s))
s.Assays
|> Seq.iter (fun a ->
workbooks.Add (
Path.combineMany[|"assays";a.Identifier;"isa.assay.xlsx"|],
(DTOType.ISA_Assay, ISA.Spreadsheet.ArcAssay.toFsWorkbook a))
)
)
| None -> printfn "ARC contains no ISA part."
match arc.FileSystem with
| Some fs ->
fs.Tree.ToFilePaths(true)
|> Array.map (fun fp ->
match Dictionary.tryGet fp workbooks with
| Some (dto,wb) -> Contract.createCreate(fp,dto,DTO.Spreadsheet wb)
| None -> Contract.createCreate(fp, DTOType.PlainText, DTO.Text "")

)
| None ->
printfn "ARC contains no FileSystem part."
[||]


//-Pseudo code-//
//// Option 1
//let fs, readcontracts = ARC.FSFromFilePaths filepaths
Expand Down
35 changes: 34 additions & 1 deletion src/FileSystem/FileSystemTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,37 @@ type FileSystemTree =
loop this

static member filter (predicate: string -> bool) =
fun (tree: FileSystemTree) -> tree.Filter predicate
fun (tree: FileSystemTree) -> tree.Filter predicate



static member initAssayFolder(assayName : string) =
let dataset = FileSystemTree.createFolder("dataset", [|FileSystemTree.createFile ".gitkeep"|])
let protocols = FileSystemTree.createFolder("protocols", [|FileSystemTree.createFile ".gitkeep"|])
let readme = FileSystemTree.createFile "README.md"
let assayFile = FileSystemTree.createFile "isa.assay.xlsx"
FileSystemTree.createFolder(assayName, [|dataset; protocols; assayFile; readme|])

static member initStudyFolder(studyName : string) =
let resources = FileSystemTree.createFolder("resources", [|FileSystemTree.createFile ".gitkeep"|])
let protocols = FileSystemTree.createFolder("protocols", [|FileSystemTree.createFile ".gitkeep"|])
let readme = FileSystemTree.createFile "README.md"
let studyFile = FileSystemTree.createFile "isa.study.xlsx"
FileSystemTree.createFolder(studyName, [|resources; protocols; studyFile; readme|])

static member initInvestigationFile() =
FileSystemTree.createFile "isa.investigation.xlsx"


static member createAssaysFolder(assays : FileSystemTree array) =
FileSystemTree.createFolder("assays", Array.append [|FileSystemTree.createFile ".gitkeep"|] assays)

static member createStudiesFolder(studies : FileSystemTree array) =
FileSystemTree.createFolder("studies", Array.append [|FileSystemTree.createFile ".gitkeep"|] studies)

static member createWorkflowsFolder(workflows : FileSystemTree array) =
FileSystemTree.createFolder("assays", Array.append [|FileSystemTree.createFile ".gitkeep"|] workflows)

static member createRunsFolder(runs : FileSystemTree array) =
FileSystemTree.createFolder("runs", Array.append [|FileSystemTree.createFile ".gitkeep"|] runs)

0 comments on commit 275323c

Please sign in to comment.