Skip to content

Commit

Permalink
fix assay file reader sample updating
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 23, 2021
1 parent 65d3081 commit 3536cd3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
37 changes: 26 additions & 11 deletions src/ISADotNet.XLSX/AssayFile/AnnotationTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ module AnnotationTable =
/// Updates the sample information in the given processes with the information of the samples in the given referenceProcesses.
///
/// If the processes contain a source with the same name as a sample in the referenceProcesses. Additionally transforms it to a sample
let updateSamplesByReference (referenceProcesses : Process seq) (processes : Process seq) =
let private updateSamplesBy (referenceProcesses : Process seq) (processes : Process seq) =
let samples =
referenceProcesses
|> Seq.append processes
|> Seq.collect (fun p ->
printfn "%O" p.Name
let inputs =
Expand All @@ -213,14 +212,16 @@ module AnnotationTable =
Seq.append inputs outputs
|> Seq.distinct
)
|> Seq.filter (fun (name,_,s) -> name <> None && name <> (Some ""))
|> Seq.groupBy (fun (name,_,s) -> name)
|> Seq.map (fun (name,s) ->
let x = s |> Seq.map (fun (name,_,s) -> s) |> Seq.reduce API.Update.UpdateByExisting.updateRecordType
if Seq.exists (fun (name,isSample,s) -> isSample) s then
name, ProcessInput.Sample x
else name, ProcessInput.Source (sourceOfSample x)

|> Seq.filter (fun (name,_,samples) -> name <> None && name <> (Some ""))
|> Seq.groupBy (fun (name,_,samples) -> name)
|> Seq.map (fun (name,samples) ->
let aggregatedSample =
samples
|> Seq.map (fun (name,_,s) -> s)
|> Seq.reduce (fun s1 s2 -> if s1 = s2 then s1 else API.Update.UpdateByExistingAppendLists.updateRecordType s1 s2)
if Seq.exists (fun (name,isSample,s) -> isSample) samples then
name, ProcessInput.Sample aggregatedSample
else name, ProcessInput.Source (sourceOfSample aggregatedSample)
)
|> Map.ofSeq

Expand All @@ -242,4 +243,18 @@ module AnnotationTable =
Outputs = p.Outputs |> Option.map (List.map updateOutput)
}
)


/// Updates the sample information in the given processes with the information of the samples in the given referenceProcesses.
///
/// If the processes contain a source with the same name as a sample in the referenceProcesses. Additionally transforms it to a sample
let updateSamplesByReference (referenceProcesses : Process seq) (processes : Process seq) =
referenceProcesses
|> Seq.append processes
|> updateSamplesBy processes

/// Updates the sample information in the given processes with the information of the samples in the given referenceProcesses.
///
/// If the processes contain a source with the same name as a sample in the referenceProcesses. Additionally transforms it to a sample
let updateSamplesByThemselves (processes : Process seq) =
processes
|> updateSamplesBy processes
2 changes: 1 addition & 1 deletion src/ISADotNet.XLSX/AssayFile/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module AssayFile =
Seq.append processes' processes
) (List.empty,List.empty,Seq.empty,Seq.empty)

let processes = AnnotationTable.updateSamplesByReference processes processes
let processes = AnnotationTable.updateSamplesByThemselves processes

let assay = assayMetaData |> Option.defaultValue Assay.empty

Expand Down
4 changes: 2 additions & 2 deletions tests/ISADotNet.Tests/ISADotNet.XLSX/AssayFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ let testProcessComparisonFunctions =
let process1 = Process.create None None None None None None None None (Some [Source source1]) (Some [Sample sample1]) None
let process2 = Process.create None None None None None None None None (Some [sourceWithSampleName]) (Some [Sample sample2]) None

let updatedProcesses = AnnotationTable.updateSamplesByReference [process1;process2] [process1;process2]
let updatedProcesses = AnnotationTable.updateSamplesByThemselves [process1;process2]

let expectedProcessSequence =
[
Expand Down Expand Up @@ -616,7 +616,7 @@ let testProcessComparisonFunctions =
let expectedSample = Sample.create None (Some "Sample1") (Some [characteristicValue]) (Some [factorValue]) None

Expect.equal inputSample outputSample "The information of the output of the first process and the input of the second process was not equalized"
Expect.equal expectedSample outputSample "Values were not correclty merged"
Expect.equal outputSample expectedSample "Values were not correctly merged"
)
]

Expand Down

0 comments on commit 3536cd3

Please sign in to comment.