From 59a84024b985f23c958661e7d9bb39b0e5425185 Mon Sep 17 00:00:00 2001 From: Bob MacCallum Date: Thu, 30 Mar 2023 16:08:50 -0400 Subject: [PATCH] sketched out a possible approach --- ISA/lib/perl/StudyAssayEntity.pm | 7 +++++ .../perl/StudyAssayEntity/Characteristic.pm | 3 +++ ISA/lib/perl/StudyAssayFileReader.pm | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/ISA/lib/perl/StudyAssayEntity.pm b/ISA/lib/perl/StudyAssayEntity.pm index e209ceb..ec4b69d 100644 --- a/ISA/lib/perl/StudyAssayEntity.pm +++ b/ISA/lib/perl/StudyAssayEntity.pm @@ -83,4 +83,11 @@ sub addFactorValue { } sub getFactorValues { $_[0]->{_factor_values} || [] } +# +# allow StudyAssayFileReader->readLineToObjects() to split this entity +# into multiple entities based on a delimiter +# +sub isSplittable { return 0 } +sub getSplitDelimiter { die "getSplitDelimiter() called on a non-splittable object" } + 1; diff --git a/ISA/lib/perl/StudyAssayEntity/Characteristic.pm b/ISA/lib/perl/StudyAssayEntity/Characteristic.pm index f35c037..d443841 100644 --- a/ISA/lib/perl/StudyAssayEntity/Characteristic.pm +++ b/ISA/lib/perl/StudyAssayEntity/Characteristic.pm @@ -52,4 +52,7 @@ sub qualifierContextMethod { return "addCharacteristic"; } +sub isSplittable { return 1; } +sub getSplitDelimiter { return qr/;\s*/ } + 1; diff --git a/ISA/lib/perl/StudyAssayFileReader.pm b/ISA/lib/perl/StudyAssayFileReader.pm index 0037708..f5dfd8d 100644 --- a/ISA/lib/perl/StudyAssayFileReader.pm +++ b/ISA/lib/perl/StudyAssayFileReader.pm @@ -157,7 +157,33 @@ sub readLineToObjects { } } + @rv = map { $_->isSplittable() ? splitObject($_) : $_ } @rv; + return \@rv; } +sub splitObject { + my ($obj) = @_; + my $delimiter = $obj->getDelimiter(); + my @rv = (); + + # Do something like this: + # + # check that $obj->getValue and the scalar return values of $obj->getXXX (wjere XXX in $obj->getAttributeNames) + # all split to the same number of values, N. + # + # there could be object attributes such as from $obj->getUnit + # if so, I guess check that that has the same number of splits as $obj->getValue + # + # that could also have sub-objects? so potentially do this recursively? + # + # if all is good, create N new objects, ideally by a deep copy of $obj, then + # go in to each copy and split and replace all the scalar values with the + # appropriate value (e.g. for the second of three objects, replace 'aaa;bbb;ccc' with 'bbb') + # + # otherwise warn about the split count mismatch and return the original object? + + return @rv; +} + 1;