Skip to content

Commit

Permalink
Remove panels.yaml and use json
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Jul 24, 2024
1 parent 1de0444 commit a084bac
Show file tree
Hide file tree
Showing 29 changed files with 455 additions and 412 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.esotericsoftware.yamlbeans</groupId>
<artifactId>yamlbeans</artifactId>
<version>1.14</version>
</dependency>

<dependency>
<groupId>genepi</groupId>
<artifactId>genepi-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void setReport(String report) {
this.report = report;
}

public void setReference(String reference) {
this.reference = reference;
}

public void setPhasing(String phasing) {
this.phasing = phasing;
}
Expand All @@ -82,10 +86,6 @@ public void setPopulation(String population) {
this.population = population;
}

public void setRefPanel(RefPanel panel) {
this.panel = panel;
}

public void setBuild(String build) {
this.build = build;
}
Expand Down Expand Up @@ -131,13 +131,11 @@ public Integer call() throws Exception {
output = new OutputWriter();
}

if (panel == null) {
try {
panel = RefPanel.loadFromJson(reference);
} catch (Exception e) {
output.error("Unable to parse reference panel:" ,e);
return -1;
}
try {
panel = RefPanel.loadFromJson(reference);
} catch (Exception e) {
output.error("Unable to parse reference panel:" ,e);
return -1;
}

if (!checkParameters()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public void setFiles(List<String> files) {
this.files = files;
}

public void setRefPanel(RefPanel panel) {
this.panel = panel;
}

public void setChainFile(String chainFile) {
this.chainFile = chainFile;
}

public void setReference(String reference) {
this.reference = reference;
}

public void setPopulation(String population) {
this.population = population;
}
Expand Down Expand Up @@ -125,13 +125,11 @@ public Integer call() throws Exception {
output = new OutputWriter();
}

if (panel == null) {
try {
panel = RefPanel.loadFromJson(reference);
} catch (Exception e) {
output.error("Unable to parse reference panel:", e);
return -1;
}
try {
panel = RefPanel.loadFromJson(reference);
} catch (Exception e) {
output.error("Unable to parse reference panel:", e);
return -1;
}

if (!analyzeFiles()) {
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/genepi/imputationserver/util/RefPanel.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package genepi.imputationserver.util;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.esotericsoftware.yamlbeans.YamlReader;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
Expand Down Expand Up @@ -289,35 +287,10 @@ public static RefPanel fromProperties(Object properties) throws IOException {

}

public static void resolveEnvVariable(Map<String, Object> properties, String folder) {
for (String key : properties.keySet()) {
Object value = properties.get(key);
if (value instanceof String) {
String valueString = value.toString().replaceAll("\\$\\{app_local_folder\\}", folder);
properties.put(key, valueString);
}
}
}

public static RefPanel loadFromJson(String filename) throws JsonSyntaxException, JsonIOException, IOException {
Gson gson = (new GsonBuilder()).create();
Map<String, Object> panel = gson.fromJson(new FileReader(filename), Map.class);
return fromProperties(panel);
}

public static RefPanel loadFromYamlFile(String filename, String id) throws IOException {

YamlReader reader = new YamlReader(new FileReader(filename));
List<Map<String, Object>> panels = reader.read(List.class);
for (Map<String, Object> panel : panels) {
if (panel.get("id").equals(id)) {
resolveEnvVariable(panel, (new File(filename).getParent()));
return fromProperties(panel);
}
}

throw new IOException("Reference panel '" + id + "' not found in file '" + filename + "'.");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ public class InputValidationCommandTest extends AbstractTestcase {
@Test
public void testHg19DataWithBuild38() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/three";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setBuild("hg38");

assertEquals(-1, (int) command.call());
Expand All @@ -44,24 +41,13 @@ public void testHg19DataWithBuild38() throws Exception {

}

@Test(expected = IOException.class)
public void testWithWrongReferencePanel() throws IOException {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
RefPanel.loadFromYamlFile(panels, "missing-reference-panel");

}

@Test
public void testHg38DataWithBuild19() throws Exception {

String panels = "test-data/configs/hapmap-chr20/panels.txt";
String inputFolder = "test-data/data/chr20-unphased-hg38";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr20/hapmap2.json");
command.setBuild("hg19");
command.setPopulation("eur");

Expand All @@ -76,13 +62,10 @@ public void testHg38DataWithBuild19() throws Exception {
@Test
public void testWrongVcfFile() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/wrong_vcf";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(-1, (int) command.call());
Expand All @@ -96,13 +79,10 @@ public void testWrongVcfFile() throws Exception {
@Test
public void testMixedPopulation() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/single";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("mixed");

assertEquals(0, (int) command.call());
Expand All @@ -112,13 +92,10 @@ public void testMixedPopulation() throws Exception {
@Test
public void testCorrectHrcPopulation() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/single";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hrc-fake");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hrc-fake.json");
command.setPopulation("mixed");

assertEquals(0, (int) command.call());
Expand All @@ -128,13 +105,10 @@ public void testCorrectHrcPopulation() throws Exception {
@Test
public void testWrongHrcPopulation() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/single";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hrc-fake");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hrc-fake.json");
command.setPopulation("aas");

assertEquals(-1, (int) command.call());
Expand All @@ -149,13 +123,10 @@ public void testWrongHrcPopulation() throws Exception {
@Test
public void testWrong1KP3Population() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/single";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "phase3-fake");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/phase3-fake.json");
command.setPopulation("asn");

assertEquals(-1, (int) command.call());
Expand All @@ -170,34 +141,27 @@ public void testWrong1KP3Population() throws Exception {
@Test
public void testWrongTopmedPopulation() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/single";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "TOPMedfreeze6-fake");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/TOPMedfreeze6-fake.json");
command.setPopulation("asn");

assertEquals(-1, (int) command.call());

OutputReader log = new OutputReader(CLOUDGENE_LOG);
log.view();
assertTrue(log.hasInMemory("::group type=error::"));
assertTrue(log.hasInMemory("Population 'asn' is not supported by reference panel 'TOPMedfreeze6-fake'"));
}

@Test
public void testUnorderedVcfFile() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
// input folder contains no vcf or vcf.gz files
String inputFolder = "test-data/data/unorderd";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(-1, (int) command.call());
Expand All @@ -211,13 +175,10 @@ public void testUnorderedVcfFile() throws Exception {
@Test
public void testWrongChromosomes() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/wrong_chrs";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(-1, (int) command.call());
Expand All @@ -230,19 +191,15 @@ public void testWrongChromosomes() throws Exception {
@Test
public void testSingleUnphasedVcfWithEagle() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/single";

RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(0, (int) command.call());

OutputReader log = new OutputReader(CLOUDGENE_LOG);
log.view();
assertTrue(log.hasInMemory("1 valid VCF file(s) found."));
assertTrue(log.hasInMemory("Samples: 41"));
assertTrue(log.hasInMemory("Chromosomes: 1"));
Expand All @@ -257,13 +214,10 @@ public void testSingleUnphasedVcfWithEagle() throws Exception {
@Test
public void testThreeUnphasedVcfWithEagle() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
String inputFolder = "test-data/data/three";
// create workflow context
RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(0, (int) command.call());
Expand All @@ -283,15 +237,10 @@ public void testThreeUnphasedVcfWithEagle() throws Exception {
@Test
public void testTabixIndexCreationChr20() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
// input folder contains no vcf or vcf.gz files
String inputFolder = "test-data/data/chr20-phased";

// create workflow context
RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(0, (int) command.call());
Expand Down Expand Up @@ -321,15 +270,10 @@ public void testTabixIndexCreationChr20() throws Exception {
@Test
public void testTabixIndexCreationChr1() throws Exception {

String panels = "test-data/configs/hapmap-chr1/panels.txt";
// input folder contains no vcf or vcf.gz files
String inputFolder = "test-data/data/single";

// create workflow context
RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2");

InputValidationCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
command.setReference("test-data/configs/hapmap-chr1/hapmap2.json");
command.setPopulation("eur");

assertEquals(0, (int) command.call());
Expand Down
Loading

0 comments on commit a084bac

Please sign in to comment.