Skip to content

Commit 3536cd3

Browse files
committed
fix assay file reader sample updating
1 parent 65d3081 commit 3536cd3

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/ISADotNet.XLSX/AssayFile/AnnotationTable.fs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,9 @@ module AnnotationTable =
196196
/// Updates the sample information in the given processes with the information of the samples in the given referenceProcesses.
197197
///
198198
/// If the processes contain a source with the same name as a sample in the referenceProcesses. Additionally transforms it to a sample
199-
let updateSamplesByReference (referenceProcesses : Process seq) (processes : Process seq) =
199+
let private updateSamplesBy (referenceProcesses : Process seq) (processes : Process seq) =
200200
let samples =
201201
referenceProcesses
202-
|> Seq.append processes
203202
|> Seq.collect (fun p ->
204203
printfn "%O" p.Name
205204
let inputs =
@@ -213,14 +212,16 @@ module AnnotationTable =
213212
Seq.append inputs outputs
214213
|> Seq.distinct
215214
)
216-
|> Seq.filter (fun (name,_,s) -> name <> None && name <> (Some ""))
217-
|> Seq.groupBy (fun (name,_,s) -> name)
218-
|> Seq.map (fun (name,s) ->
219-
let x = s |> Seq.map (fun (name,_,s) -> s) |> Seq.reduce API.Update.UpdateByExisting.updateRecordType
220-
if Seq.exists (fun (name,isSample,s) -> isSample) s then
221-
name, ProcessInput.Sample x
222-
else name, ProcessInput.Source (sourceOfSample x)
223-
215+
|> Seq.filter (fun (name,_,samples) -> name <> None && name <> (Some ""))
216+
|> Seq.groupBy (fun (name,_,samples) -> name)
217+
|> Seq.map (fun (name,samples) ->
218+
let aggregatedSample =
219+
samples
220+
|> Seq.map (fun (name,_,s) -> s)
221+
|> Seq.reduce (fun s1 s2 -> if s1 = s2 then s1 else API.Update.UpdateByExistingAppendLists.updateRecordType s1 s2)
222+
if Seq.exists (fun (name,isSample,s) -> isSample) samples then
223+
name, ProcessInput.Sample aggregatedSample
224+
else name, ProcessInput.Source (sourceOfSample aggregatedSample)
224225
)
225226
|> Map.ofSeq
226227

@@ -242,4 +243,18 @@ module AnnotationTable =
242243
Outputs = p.Outputs |> Option.map (List.map updateOutput)
243244
}
244245
)
245-
246+
247+
/// Updates the sample information in the given processes with the information of the samples in the given referenceProcesses.
248+
///
249+
/// If the processes contain a source with the same name as a sample in the referenceProcesses. Additionally transforms it to a sample
250+
let updateSamplesByReference (referenceProcesses : Process seq) (processes : Process seq) =
251+
referenceProcesses
252+
|> Seq.append processes
253+
|> updateSamplesBy processes
254+
255+
/// Updates the sample information in the given processes with the information of the samples in the given referenceProcesses.
256+
///
257+
/// If the processes contain a source with the same name as a sample in the referenceProcesses. Additionally transforms it to a sample
258+
let updateSamplesByThemselves (processes : Process seq) =
259+
processes
260+
|> updateSamplesBy processes

src/ISADotNet.XLSX/AssayFile/Assay.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module AssayFile =
106106
Seq.append processes' processes
107107
) (List.empty,List.empty,Seq.empty,Seq.empty)
108108

109-
let processes = AnnotationTable.updateSamplesByReference processes processes
109+
let processes = AnnotationTable.updateSamplesByThemselves processes
110110

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

tests/ISADotNet.Tests/ISADotNet.XLSX/AssayFileTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ let testProcessComparisonFunctions =
576576
let process1 = Process.create None None None None None None None None (Some [Source source1]) (Some [Sample sample1]) None
577577
let process2 = Process.create None None None None None None None None (Some [sourceWithSampleName]) (Some [Sample sample2]) None
578578

579-
let updatedProcesses = AnnotationTable.updateSamplesByReference [process1;process2] [process1;process2]
579+
let updatedProcesses = AnnotationTable.updateSamplesByThemselves [process1;process2]
580580

581581
let expectedProcessSequence =
582582
[
@@ -616,7 +616,7 @@ let testProcessComparisonFunctions =
616616
let expectedSample = Sample.create None (Some "Sample1") (Some [characteristicValue]) (Some [factorValue]) None
617617

618618
Expect.equal inputSample outputSample "The information of the output of the first process and the input of the second process was not equalized"
619-
Expect.equal expectedSample outputSample "Values were not correclty merged"
619+
Expect.equal outputSample expectedSample "Values were not correctly merged"
620620
)
621621
]
622622

0 commit comments

Comments
 (0)