diff --git a/src/main/java/genepi/imputationserver/steps/InputValidationCommand.java b/src/main/java/genepi/imputationserver/steps/InputValidationCommand.java index a4aa529..f39b661 100644 --- a/src/main/java/genepi/imputationserver/steps/InputValidationCommand.java +++ b/src/main/java/genepi/imputationserver/steps/InputValidationCommand.java @@ -168,18 +168,19 @@ private boolean checkVcfFiles() throws Exception { try { VcfFile vcfFile = VcfFileUtil.load(filename, chunksize, !noIndex); + String chromosome = vcfFile.getChromosome(); - if (VcfFileUtil.isChrMT(vcfFile.getChromosome())) { + if (VcfFileUtil.isChrMT(chromosome)) { vcfFile.setPhased(true); } - if (!VcfFileUtil.isValidChromosome(vcfFile.getChromosome())) { - output.error("No valid chromosomes found!"); + if (!VcfFileUtil.isValidChromosome(chromosome)) { + output.error("Invalid chromosome found: " + chromosome); return false; } validVcfFiles.add(vcfFile); - chromosomes.add(vcfFile.getChromosome()); + chromosomes.add(chromosome); // check if all files have same amount of samples if (noSamples != 0 && noSamples != vcfFile.getNoSamples()) { @@ -210,14 +211,14 @@ private boolean checkVcfFiles() throws Exception { if (build.equals("hg19") && vcfFile.hasChrPrefix()) { output.error("Your upload data contains chromosome '" + vcfFile.getRawChromosome() + "'. This is not a valid hg19 encoding. Please ensure that your input data is build hg19 and chromosome is encoded as '" - + vcfFile.getChromosome() + "'."); + + chromosome + "'."); return false; } if (build.equals("hg38") && !vcfFile.hasChrPrefix()) { output.error("Your upload data contains chromosome '" + vcfFile.getRawChromosome() + "'. This is not a valid hg38 encoding. Please ensure that your input data is build hg38 and chromosome is encoded as 'chr" - + vcfFile.getChromosome() + "'."); + + chromosome + "'."); return false; } diff --git a/src/test/java/genepi/imputationserver/steps/InputValidationCommandTest.java b/src/test/java/genepi/imputationserver/steps/InputValidationCommandTest.java index 19ee7cf..dc340df 100644 --- a/src/test/java/genepi/imputationserver/steps/InputValidationCommandTest.java +++ b/src/test/java/genepi/imputationserver/steps/InputValidationCommandTest.java @@ -20,6 +20,38 @@ public class InputValidationCommandTest extends AbstractTestcase { private static final String CLOUDGENE_LOG = "cloudgene.report"; + @Test + public void testMissingReferencePanel() throws Exception { + String inputFolder = "test-data/data/chr20-phased"; + + InputValidationCommand command = buildCommand(inputFolder); + command.setReference("this-path/does-not-exist.json"); + command.setBuild("hg38"); + + assertEquals(1, (int)command.call()); + + OutputReader log = new OutputReader(CLOUDGENE_LOG); + log.view(); + assertTrue(log.hasInMemory("::error:: Unable to parse reference panel: this-path/does-not-exist.json (No such file or directory)")); + } + + @Test + public void testInvalidChromosome() throws Exception { + + String inputFolder = "test-data/data/chrY-fake"; + + InputValidationCommand command = buildCommand(inputFolder); + command.setReference("test-data/configs/hapmap-chr1/hapmap2.json"); + command.setPopulation("mixed"); + + assertEquals(1, (int)command.call()); + + OutputReader log = new OutputReader(CLOUDGENE_LOG); + log.view(); + assertTrue(log.hasInMemory("::error:: Invalid chromosome found: Y")); + + } + @Test public void testVcfWithHeaderOnly() throws Exception { diff --git a/test-data/data/chrY-fake/fake.chrY.vcf.gz b/test-data/data/chrY-fake/fake.chrY.vcf.gz new file mode 100644 index 0000000..983772c Binary files /dev/null and b/test-data/data/chrY-fake/fake.chrY.vcf.gz differ diff --git a/test-data/data/chrY-fake/fake.chrY.vcf.gz.tbi b/test-data/data/chrY-fake/fake.chrY.vcf.gz.tbi new file mode 100644 index 0000000..958fb05 Binary files /dev/null and b/test-data/data/chrY-fake/fake.chrY.vcf.gz.tbi differ