From 91895424646b7afd805886006a7eda78a6cbd3f9 Mon Sep 17 00:00:00 2001 From: Gisli Magnusson Date: Sun, 8 Feb 2026 00:50:09 +0000 Subject: [PATCH] fix(ENGKNOW-3014): Fix norif context, and allow single column -dh for norif. --- .../gorsat/Utilities/gorsatUtilities.scala | 18 +++++++++++++----- gortools/src/test/java/gorsat/UTestNorif.java | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gortools/src/main/scala/gorsat/Utilities/gorsatUtilities.scala b/gortools/src/main/scala/gorsat/Utilities/gorsatUtilities.scala index 404e68a8..ec557715 100644 --- a/gortools/src/main/scala/gorsat/Utilities/gorsatUtilities.scala +++ b/gortools/src/main/scala/gorsat/Utilities/gorsatUtilities.scala @@ -56,12 +56,20 @@ object Utilities { // return an iterator that only delivers the header defined with -dh. val header = stringValueOfOption(args, "-dh") val headerCols = header.split(",") - if (headerCols.length < 2 || headerCols(0).isEmpty || headerCols(1).isEmpty) { - throw new GorParsingException("-dh requires at least 2 non-empty comma-separated values") - } val inputSource = RowListIterator(List()) - if (isNor) inputSource.setHeader(HEADER_PREFIX + headerCols.mkString("\t")) else inputSource.setHeader(headerCols.mkString("\t")) - InputSourceParsingResult(inputSource, header, isNorContext = false) + if (isNor) { + if (headerCols.length < 1 || headerCols(0).isEmpty) { + throw new GorParsingException("For NOR -dh requires at least 1 non-empty value") + } + inputSource.setHeader(HEADER_PREFIX + headerCols.mkString("\t")) + } else { + if (headerCols.length < 2 || headerCols(0).isEmpty || headerCols(1).isEmpty) { + throw new GorParsingException("For GOR -dh requires at least 2 non-empty comma-separated values") + } + inputSource.setHeader(headerCols.mkString("\t")) + } + + InputSourceParsingResult(inputSource, header, isNorContext = isNor) } } diff --git a/gortools/src/test/java/gorsat/UTestNorif.java b/gortools/src/test/java/gorsat/UTestNorif.java index e08e2de6..b426fb4f 100644 --- a/gortools/src/test/java/gorsat/UTestNorif.java +++ b/gortools/src/test/java/gorsat/UTestNorif.java @@ -80,9 +80,10 @@ public static Collection data() throws IOException { {"Nested query started with norif", "norif <(nor " + testTsvFile1 + ")", expectedHeader + "chrN\t0\tA\t1\tA\n", null}, {"Invalid file path", "norif -dh col1,col2 not_exists.tsv", HEADER_PREFIX+ "col1\tcol2\n", null}, + {"Invalid file path, single col", "norif -dh col1 not_exists.tsv", HEADER_PREFIX+ "col1\n", null}, {"Invalid file path missing -dh", "norif not_exists.tsv", null, GorParsingException.class}, {"Empty file missing -dh", "norif " + testEmptyFile, null, GorParsingException.class}, - {"Invalid file path with invalid -dh value", "norif -dh col1 not_exists.tsv", null, GorParsingException.class}, + {"Invalid file path with invalid -dh value", "norif not_exists.tsv -dh ", null, GorParsingException.class}, {"Both invalid and valid file path", "norif " + testTsvFile1 + " not_exists.tsv", expectedHeader + "chrN\t0\tA\t1\tA\n", null}, });