Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gortools/src/main/scala/gorsat/Commands/CalcIfMissing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class CalcIfMissing extends CommandInfo("CALCIFMISSING",
val columnNames = Calc.getColumnsFromArgs(args)
val exprSrc = Calc.getExpressionsFromArgs(args, columnNames)

val existingColumns = forcedInputHeader.split('\t')
val existingColumns = forcedInputHeader.toLowerCase.split('\t')
val newColumns = ArrayBuffer[String]()
val expressions = ArrayBuffer[String]()
for (i <- columnNames.indices) {
if (!existingColumns.contains(columnNames(i))) {
if (!existingColumns.contains(columnNames(i).toLowerCase)) {
newColumns += columnNames(i)
expressions += exprSrc(i)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ object IteratorUtilities {
if (ALLOW_DUPLICATE_COLUMNS || allowDuplicates) {
column = column + "x"
colToUp = column.toUpperCase
if (!allowDuplicates) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !allowDuplicates - just logs warning? Am I misinterpreting ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we allowDuplicates is false but we are overwriting at a global level with ALLOW_DUPLICATE_COLUMNS we print out a warning about the duplicate labels.
This is basically the case when we are switching over, we have many commands with allowDublicates = false but we overwrite for backward compatibiltity with ALLOW_DUPLICATE_COLUMNS=true, we print out the warning for those columns that have allowDublicates = false. When all the queries are fixed we will set ALLOW_DUPLICATE_COLUMNS=false.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I see this is with the prior that ALLOW_DUPLICATE_COLUMNS is set to TRUE

logger.warn(s"Duplicate column name '$col' detected in header: $header. Renaming to '$column'")
}
} else {
throw new GorDataException(f"Error: Duplicate column name '$column%s' detected in header: $header%s")
throw new GorDataException(f"Error: Duplicate column name '$column' detected in header: $header")
}
}
usedCols.add(colToUp)
Expand Down
24 changes: 24 additions & 0 deletions gortools/src/test/java/gorsat/UTestHeaderFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import gorsat.Utilities.IteratorUtilities;
import org.gorpipe.exceptions.GorDataException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.slf4j.LoggerFactory;

import java.io.File;
Expand All @@ -35,6 +39,13 @@
public class UTestHeaderFlags {

private static final org.slf4j.Logger log = LoggerFactory.getLogger(UTestHeaderFlags.class);

@Rule
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();

@Rule
public final SystemErrRule systemErrRule = new SystemErrRule().enableLog();

/**
* If an excluded char becomes included after the initial state in gorsat.Utilities.IteratorUtilities#validHeader
* this test will throw an exception.
Expand Down Expand Up @@ -68,6 +79,8 @@ public void testValidHeaderUsedKeywordsWithDupAllowingDup() {
String testHeader = "#abc\tstart\tfrom\tselect\tmax\tmin\tfrom\tgroup\trange\torder\trank\torder";
String resultingHeader = IteratorUtilities.validHeader(testHeader, true);
Assert.assertEquals("#abc\tstart\tfrom\tselect\tmax\tmin\tfromx\tgroup\trange\torder\trank\torderx", resultingHeader);
Assert.assertFalse(systemErrRule.getLog().contains("Duplicate column name 'from'"));
Assert.assertFalse(systemErrRule.getLog().contains("Duplicate column name 'order'"));
}

@Test
Expand All @@ -76,6 +89,17 @@ public void testValidHeaderUsedKeywordsWithDupNotAllowingDup() {
Assert.assertThrows(GorDataException.class, () -> IteratorUtilities.validHeader(testHeader, false));
}

@Ignore("Only works if run alone, as the property is read only on class load")
@Test
public void testValidHeaderUsedKeywordsWithDupAllowingDupOnlyGlobal() {
System.setProperty("gor.iterators.allowDuplicateColumns", "true");
String testHeader = "#abc\tstart\tfrom\tselect\tmax\tmin\tfrom\tgroup\trange\torder\trank\torder";
String resultingHeader = IteratorUtilities.validHeader(testHeader, false);
Assert.assertEquals("#abc\tstart\tfrom\tselect\tmax\tmin\tfromx\tgroup\trange\torder\trank\torderx", resultingHeader);
Assert.assertTrue(systemErrRule.getLog().contains("Duplicate column name 'from'"));
Assert.assertTrue(systemErrRule.getLog().contains("Duplicate column name 'order'"));
}

@Test
public void testHeaderParsing() {
String testStr = "test$He*aDer";
Expand Down
8 changes: 8 additions & 0 deletions gortools/src/test/java/gorsat/parser/UTestCalcIfMissing.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ public void addsOnlyMissingColumns() {
"chr1\t1\t64\t3.14\tbingo\n";
Assert.assertEquals(expected, result);
}

@Test
public void ignoresColumnWhenItExistsWithCaseDiff() {
final String result = TestUtils.runGorPipe("gorrow 1,1 | calc data1 64 | calcifmissing DATA1,data2,data3 42,3.14,'bingo'");
final String expected = "chrom\tpos\tdata1\tdata2\tdata3\n" +
"chr1\t1\t64\t3.14\tbingo\n";
Assert.assertEquals(expected, result);
}
}
Loading