Skip to content

Commit

Permalink
drop protocol rowIndex when calculating rowRange
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Aug 5, 2022
1 parent 4c050d1 commit 94b6059
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
22 changes: 20 additions & 2 deletions src/ISADotNet.QueryModel/Sheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module ProtocolExtensions =
|> Option.bind (API.CommentList.tryItem Protocol.rowIndexKeyName)
|> Option.map (int)

static member setRowIndex i (p : Protocol) = p.SetRowIndex(i)

static member rowRangeKeyName = "RowRange"

static member composeRowRange (from : int) (to_ : int) =
Expand Down Expand Up @@ -69,12 +71,28 @@ module ProtocolExtensions =
|> Option.bind (API.CommentList.tryItem Protocol.rowRangeKeyName)
|> Option.map (Protocol.decomposeRowRange)

static member setRowRange (range : string) = fun (p : Protocol) -> p.SetRowRange(range)

static member setRowRange (from : int,to_ : int) = fun (p : Protocol) -> p.SetRowRange(from,to_)

static member dropRowIndex (p : Protocol) =
match p.Comments with
| None -> p
| Some cs ->
API.CommentList.dropByKey Protocol.rowIndexKeyName cs
|> Option.fromValueWithDefault []
|> fun cs -> {p with Comments = cs}

static member rangeOfIndices (i : int list) =
Protocol.composeRowRange (List.min i) (List.max i)

static member mergeIndicesToRange (ps : Protocol list) =
let r = ps |> List.choose (fun p -> p.TryGetRowIndex()) |> Protocol.rangeOfIndices
ps.[0].SetRowRange r
let indices = ps |> List.choose (fun p -> p.TryGetRowIndex())
if indices.IsEmpty then ps.[0]
else
let r = indices |> Protocol.rangeOfIndices
ps.[0].SetRowRange r
|> Protocol.dropRowIndex

member this.IsChildProtocolTypeOf(parentProtocolType : OntologyAnnotation) =
match this.ProtocolType with
Expand Down
22 changes: 18 additions & 4 deletions src/ISADotNet.XLSX/AssayFile/AnnotationTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,31 @@ module AnnotationTable =

/// Merges processes with the same parameter values, grouping the input and output files
let mergeIdenticalProcesses processNameRoot (processes : seq<Process>) =
let protocols =
processes
|> Seq.groupBy (fun p -> p.ExecutesProtocol.Value.Name.Value)
|> Seq.map (fun (n,ps) ->
let protocols = ps |> Seq.map (fun p -> p.ExecutesProtocol.Value)
protocols
|> Seq.map (fun p -> p.ProtocolType,p.Components)
|> Seq.reduce (fun (pt,c) (pt',c') ->
if pt <> pt' then failwithf "For the protocol with the name %s, two different protocol Types %O and %O were given, which is not allowed" n pt pt'
if c <> c' then failwithf "For the protocol with the name %s, two different component lists %O and %O were given, which is not allowed" n c c'
pt,c
) |> ignore
n,protocols |> Seq.toList |> Protocol.mergeIndicesToRange
)
|> Map.ofSeq
processes
|> Seq.groupBy (fun p -> p.ExecutesProtocol.Value.ProtocolType, p.ExecutesProtocol.Value.Name, p.ParameterValues, p.ExecutesProtocol.Value.Components)
|> Seq.mapi (fun i (_,processGroup) ->
let p = processGroup |> Seq.choose (fun pr -> pr.ExecutesProtocol) |> Seq.toList |> Protocol.mergeIndicesToRange
|> Seq.groupBy (fun p -> p.ExecutesProtocol.Value.Name.Value, p.ParameterValues)
|> Seq.mapi (fun i ((name,_),processGroup) ->
processGroup
|> Seq.reduce (fun p1 p2 ->
let mergedInputs = List.append (p1.Inputs |> Option.defaultValue []) (p2.Inputs |> Option.defaultValue []) |> Option.fromValueWithDefault []
let mergedOutputs = List.append (p1.Outputs |> Option.defaultValue []) (p2.Outputs |> Option.defaultValue []) |> Option.fromValueWithDefault []
{p1 with Inputs = mergedInputs; Outputs = mergedOutputs}
)
|> fun pr -> {pr with ExecutesProtocol = Some p; Name = Some (Process.composeName processNameRoot i)}
|> fun pr -> {pr with ExecutesProtocol = Some (protocols.[name]); Name = Some (Process.composeName processNameRoot i)}
)

/// Create a sample from a source
Expand Down
11 changes: 10 additions & 1 deletion src/ISADotnet/API/Comment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ module CommentList =
comments
|> List.map (fun c -> if c.Name = comment.Name then comment else c)
else
List.append comments [comment]
List.append comments [comment]

/// Returns a new comment list where comments with the given key are filtered out
let dropByKey (key: string) (comments : Comment list) =
comments
|> List.filter (fun c ->
match c.Name with
| Some n when n = key -> false
| _ -> true
)

0 comments on commit 94b6059

Please sign in to comment.