-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ALS-6467] Configurable VCF excerpt info column ordering
- Make column sorter that pulls from properties - Use it to sort and exclude columns
- Loading branch information
1 parent
c22595d
commit d3289ef
Showing
3 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/ColumnSorter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package edu.harvard.hms.dbmi.avillach.hpds.processing; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class ColumnSorter { | ||
private final Map<String, Integer> infoColumnsOrder; | ||
|
||
@Autowired | ||
public ColumnSorter(@Value("#{'${variant.info_column_order:}'.split(',')}") List<String> infoColumnOrder) { | ||
HashMap<String, Integer> order = new HashMap<>(); | ||
for (int i = 0; i < infoColumnOrder.size(); i++) { | ||
order.put(infoColumnOrder.get(i), i); | ||
} | ||
this.infoColumnsOrder = order; | ||
} | ||
|
||
public List<String> sortInfoColumns(List<String> columns) { | ||
// backwards compatibility check. | ||
if (infoColumnsOrder.isEmpty()) { | ||
return columns; | ||
} | ||
return columns.stream() | ||
.filter(infoColumnsOrder::containsKey) | ||
.sorted((a, b) -> Integer.compare( | ||
infoColumnsOrder.getOrDefault(a, Integer.MAX_VALUE), | ||
infoColumnsOrder.getOrDefault(b, Integer.MAX_VALUE) | ||
)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
processing/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/processing/ColumnSorterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package edu.harvard.hms.dbmi.avillach.hpds.processing; | ||
|
||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ColumnSorterTest { | ||
|
||
@Test | ||
public void shouldSortColumns() { | ||
ColumnSorter subject = new ColumnSorter(List.of("a", "b", "c")); | ||
List<String> actual = subject.sortInfoColumns(new ArrayList<>(List.of("b", "c", "a"))); | ||
List<String> expected = List.of("a", "b", "c"); | ||
|
||
Assert.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void shouldExcludeMissingColumns() { | ||
ColumnSorter subject = new ColumnSorter(List.of("a", "b", "c")); | ||
List<String> actual = subject.sortInfoColumns(new ArrayList<>(List.of("d", "b", "c", "a"))); | ||
List<String> expected = List.of("a", "b", "c"); | ||
|
||
Assert.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void shouldNotBreakForMissingColumns() { | ||
ColumnSorter subject = new ColumnSorter(List.of("a", "b", "c", "d")); | ||
List<String> actual = subject.sortInfoColumns(new ArrayList<>(List.of("d", "a"))); | ||
List<String> expected = List.of("a", "d"); | ||
|
||
Assert.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void shouldNoOpWithoutConfig() { | ||
ColumnSorter subject = new ColumnSorter(List.of()); | ||
List<String> actual = subject.sortInfoColumns(new ArrayList<>(List.of("b", "c", "a"))); | ||
List<String> expected = List.of("b", "c", "a"); | ||
|
||
Assert.assertEquals(expected, actual); | ||
} | ||
} |