Skip to content

Commit

Permalink
fix querymodel node updating
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Jun 15, 2022
1 parent 36831dc commit af3dc20
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 44 deletions.
25 changes: 13 additions & 12 deletions src/ISADotnet/QueryModel/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ type QAssay(FileName : string option,MeasurementType : OntologyAnnotation option
member this.TechnologyType = TechnologyType
member this.TechnologyPlatform = TechnologyPlatform

static member fromAssay (assay : Assay) =
static member fromAssay (assay : Assay, ?ReferenceSheets : QSheet list) =
let sheets =
assay.ProcessSequence |> Option.defaultValue []
|> List.groupBy (fun x ->
if x.ExecutesProtocol.IsSome && x.ExecutesProtocol.Value.Name.IsSome then
x.ExecutesProtocol.Value.Name.Value
else
// Data Stewards use '_' as seperator to distinguish between protocol template types.
// Exmp. 1SPL01_plants, in these cases we need to find the last '_' char and remove from that index.
let lastUnderScoreIndex = x.Name.Value.LastIndexOf '_'
x.Name.Value.Remove lastUnderScoreIndex
)
|> List.map (fun (name,processes) -> QSheet.fromProcesses name processes)
match ReferenceSheets with
| Some ref ->
assay.ProcessSequence
|> Option.defaultValue []
|> fun sheets -> QProcessSequence(sheets,ref)
| None ->
assay.ProcessSequence
|> Option.defaultValue []
|> QProcessSequence
|> Seq.toList

QAssay(assay.FileName,assay.MeasurementType,assay.TechnologyType,assay.TechnologyPlatform,sheets)


member this.Protocol (sheetName : string) =
base.Protocol(sheetName, $"Assay \"{this.FileName}\"")

Expand Down
45 changes: 26 additions & 19 deletions src/ISADotnet/QueryModel/ProcessSequence.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@ type QProcessSequence (sheets : QSheet list) =

member this.Sheets = sheets

new (processSequence : Process list) =
let updateNodes (sheets : QSheet list) =
let mapping =
sheets
|> List.collect (fun s ->
s.Rows
|> List.collect (fun r -> [r.Input, r.InputType.Value; r.Output, r.OutputType.Value])
)
|> List.groupBy fst
|> List.map (fun (name,vs) -> name, vs |> List.map snd |> IOType.reduce)
|> Map.ofList
let updateRow row =
{row with
InputType = Some mapping.[row.Input]
OutputType = Some mapping.[row.Output]
}
sheets
|> List.map (fun sheet ->
{sheet with Rows = sheet.Rows |> List.map updateRow}
static member internal updateNodesAgainst (reference : QSheet list) (sheets : QSheet list) =
let mapping =
reference
|> List.collect (fun s ->
s.Rows
|> List.collect (fun r -> [r.Input, r.InputType.Value; r.Output, r.OutputType.Value])
)
|> List.groupBy fst
|> List.map (fun (name,vs) -> name, vs |> List.map snd |> IOType.reduce)
|> Map.ofList
let updateRow row =
{row with
InputType = Some mapping.[row.Input]
OutputType = Some mapping.[row.Output]
}
sheets
|> List.map (fun sheet ->
{sheet with Rows = sheet.Rows |> List.map updateRow}
)

new (processSequence : Process list, ?ReferenceSheets : QSheet list) =
let updateNodes (sheets : QSheet list) =
match ReferenceSheets with
| Some ref ->
QProcessSequence.updateNodesAgainst (ref @ sheets) sheets
| None ->
QProcessSequence.updateNodesAgainst sheets sheets
let sheets =
processSequence
|> List.groupBy (fun x ->
Expand Down
26 changes: 13 additions & 13 deletions src/ISADotnet/QueryModel/Study.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ type QStudy(FileName : string option,Identifier : string option,Title : string o
member this.Assays = Assays

static member fromStudy (study : Study) =
let assays = study.Assays |> Option.map (List.map QAssay.fromAssay) |> Option.defaultValue []
let sheets =
study.ProcessSequence |> Option.defaultValue []
|> List.groupBy (fun x ->
if x.ExecutesProtocol.IsSome && x.ExecutesProtocol.Value.Name.IsSome then
x.ExecutesProtocol.Value.Name.Value
else
// Data Stewards use '_' as seperator to distinguish between protocol template types.
// Exmp. 1SPL01_plants, in these cases we need to find the last '_' char and remove from that index.
let lastUnderScoreIndex = x.Name.Value.LastIndexOf '_'
x.Name.Value.Remove lastUnderScoreIndex
)
|> List.map (fun (name,processes) -> QSheet.fromProcesses name processes)
|> List.append (assays |> List.collect (fun a -> a.Protocols))
study.Assays
|> Option.map (List.collect (fun a -> a.ProcessSequence |> Option.defaultValue []) )
|> Option.defaultValue []
|> List.append (study.ProcessSequence |> Option.defaultValue [])
|> QProcessSequence
|> Seq.toList

let assays =
study.Assays
|> Option.map (List.map (fun a -> QAssay.fromAssay(a,sheets)))
|> Option.defaultValue []

QStudy(study.FileName,study.Identifier,study.Title,study.Description,study.SubmissionDate,study.PublicReleaseDate,study.Publications,study.Contacts,study.StudyDesignDescriptors,assays,sheets)

member this.Protocol (sheetName : string) =
Expand Down

0 comments on commit af3dc20

Please sign in to comment.