|
| 1 | +namespace ARCtrl.WorkflowGraph |
| 2 | + |
| 3 | +open ARCtrl |
| 4 | +open ARCtrl.Helper |
| 5 | +open ARCtrl.CWL |
| 6 | + |
| 7 | +[<RequireQualifiedAccess>] |
| 8 | +module Adapters = |
| 9 | + |
| 10 | + let private createCwlLookupFromInvestigation (investigation: ArcInvestigation option) = |
| 11 | + match investigation with |
| 12 | + | None -> |
| 13 | + Map.empty |
| 14 | + | Some inv -> |
| 15 | + seq { |
| 16 | + for workflow in inv.Workflows do |
| 17 | + match workflow.CWLDescription with |
| 18 | + | Some cwl -> |
| 19 | + yield Identifier.Workflow.cwlFileNameFromIdentifier workflow.Identifier, cwl |
| 20 | + | None -> |
| 21 | + () |
| 22 | + for run in inv.Runs do |
| 23 | + match run.CWLDescription with |
| 24 | + | Some cwl -> |
| 25 | + yield Identifier.Run.cwlFileNameFromIdentifier run.Identifier, cwl |
| 26 | + | None -> |
| 27 | + () |
| 28 | + } |
| 29 | + |> Seq.map (fun (path, cwl) -> ArcPathHelper.normalizePathKey path, cwl) |
| 30 | + |> Map.ofSeq |
| 31 | + |
| 32 | + let private createResolver (lookup: Map<string, CWLProcessingUnit>) = |
| 33 | + if Map.isEmpty lookup then |
| 34 | + None |
| 35 | + else |
| 36 | + Some (fun (path: string) -> lookup |> Map.tryFind (ArcPathHelper.normalizePathKey path)) |
| 37 | + |
| 38 | + let private createMissingDescriptionError identifier scopeType = |
| 39 | + { |
| 40 | + Kind = GraphIssueKind.MissingCwlDescription |
| 41 | + Message = $"No CWLDescription available for {scopeType} '{identifier}'." |
| 42 | + Scope = Some identifier |
| 43 | + Reference = None |
| 44 | + } |
| 45 | + |
| 46 | + let ofWorkflow (workflow: ArcWorkflow) : Result<WorkflowGraph, GraphBuildIssue> = |
| 47 | + match workflow.CWLDescription with |
| 48 | + | None -> |
| 49 | + Error (createMissingDescriptionError workflow.Identifier "workflow") |
| 50 | + | Some processingUnit -> |
| 51 | + let cwlLookup = createCwlLookupFromInvestigation workflow.Investigation |
| 52 | + let options = |
| 53 | + WorkflowGraphBuildOptions.defaultOptions |
| 54 | + |> WorkflowGraphBuildOptions.withRootScope workflow.Identifier |
| 55 | + |> WorkflowGraphBuildOptions.withRootWorkflowFilePath (Some (Identifier.Workflow.cwlFileNameFromIdentifier workflow.Identifier)) |
| 56 | + |> WorkflowGraphBuildOptions.withTryResolveRunPath (createResolver cwlLookup) |
| 57 | + Builder.buildWith options processingUnit |
| 58 | + |> Ok |
| 59 | + |
| 60 | + let ofRun (run: ArcRun) : Result<WorkflowGraph, GraphBuildIssue> = |
| 61 | + match run.CWLDescription with |
| 62 | + | None -> |
| 63 | + Error (createMissingDescriptionError run.Identifier "run") |
| 64 | + | Some processingUnit -> |
| 65 | + let cwlLookup = createCwlLookupFromInvestigation run.Investigation |
| 66 | + let options = |
| 67 | + WorkflowGraphBuildOptions.defaultOptions |
| 68 | + |> WorkflowGraphBuildOptions.withRootScope run.Identifier |
| 69 | + |> WorkflowGraphBuildOptions.withRootWorkflowFilePath (Some (Identifier.Run.cwlFileNameFromIdentifier run.Identifier)) |
| 70 | + |> WorkflowGraphBuildOptions.withTryResolveRunPath (createResolver cwlLookup) |
| 71 | + Builder.buildWith options processingUnit |
| 72 | + |> Ok |
| 73 | + |
| 74 | + let ofInvestigation (investigation: ArcInvestigation) : WorkflowGraphIndex = |
| 75 | + let workflowGraphs = ResizeArray() |
| 76 | + let runGraphs = ResizeArray() |
| 77 | + |
| 78 | + for workflow in investigation.Workflows do |
| 79 | + workflowGraphs.Add(workflow.Identifier, ofWorkflow workflow) |
| 80 | + for run in investigation.Runs do |
| 81 | + runGraphs.Add(run.Identifier, ofRun run) |
| 82 | + |
| 83 | + { |
| 84 | + WorkflowGraphs = workflowGraphs |
| 85 | + RunGraphs = runGraphs |
| 86 | + } |
0 commit comments