-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from jmmut/feature/genotyped-validator
EVA-519 add GenotypedVcfJobParametersValidator and test
- Loading branch information
Showing
4 changed files
with
316 additions
and
6 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../uk/ac/ebi/eva/pipeline/parameters/validation/job/GenotypedVcfJobParametersValidator.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,70 @@ | ||
/* | ||
* Copyright 2017 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package uk.ac.ebi.eva.pipeline.parameters.validation.job; | ||
|
||
import org.springframework.batch.core.JobParameters; | ||
import org.springframework.batch.core.JobParametersInvalidException; | ||
import org.springframework.batch.core.JobParametersValidator; | ||
import org.springframework.batch.core.job.CompositeJobParametersValidator; | ||
import org.springframework.batch.core.job.DefaultJobParametersValidator; | ||
|
||
import uk.ac.ebi.eva.pipeline.parameters.JobParametersNames; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.AnnotationLoaderStepParametersValidator; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.FileLoaderStepParametersValidator; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.PopulationStatisticsGeneratorStepParametersValidator; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.PopulationStatisticsLoaderStepParametersValidator; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.VariantLoaderStepParametersValidator; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.VepAnnotationGeneratorStepParametersValidator; | ||
import uk.ac.ebi.eva.pipeline.parameters.validation.step.VepInputGeneratorStepParametersValidator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Validates the job parameters necessary to execute an {@link uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJob} | ||
*/ | ||
public class GenotypedVcfJobParametersValidator extends DefaultJobParametersValidator { | ||
|
||
@Override | ||
public void validate(JobParameters parameters) throws JobParametersInvalidException { | ||
compositeJobParametersValidator(parameters).validate(parameters); | ||
} | ||
|
||
private CompositeJobParametersValidator compositeJobParametersValidator(JobParameters jobParameters) { | ||
List<JobParametersValidator> jobParametersValidators = new ArrayList<>(); | ||
|
||
jobParametersValidators.add(new VariantLoaderStepParametersValidator()); | ||
jobParametersValidators.add(new FileLoaderStepParametersValidator()); | ||
|
||
Boolean skipAnnotation = Boolean.valueOf(jobParameters.getString(JobParametersNames.ANNOTATION_SKIP)); | ||
if (!skipAnnotation) { | ||
jobParametersValidators.add(new VepInputGeneratorStepParametersValidator()); | ||
jobParametersValidators.add(new VepAnnotationGeneratorStepParametersValidator()); | ||
jobParametersValidators.add(new AnnotationLoaderStepParametersValidator()); | ||
} | ||
|
||
Boolean skipStats = Boolean.valueOf(jobParameters.getString(JobParametersNames.STATISTICS_SKIP)); | ||
if (!skipStats) { | ||
jobParametersValidators.add(new PopulationStatisticsGeneratorStepParametersValidator()); | ||
jobParametersValidators.add(new PopulationStatisticsLoaderStepParametersValidator()); | ||
} | ||
|
||
CompositeJobParametersValidator compositeJobParametersValidator = new CompositeJobParametersValidator(); | ||
compositeJobParametersValidator.setValidators(jobParametersValidators); | ||
return compositeJobParametersValidator; | ||
} | ||
|
||
} |
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
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
234 changes: 234 additions & 0 deletions
234
...ac/ebi/eva/pipeline/parameters/validation/job/GenotypedVcfJobParametersValidatorTest.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,234 @@ | ||
/* | ||
* Copyright 2017 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package uk.ac.ebi.eva.pipeline.parameters.validation.job; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.springframework.batch.core.JobParameter; | ||
import org.springframework.batch.core.JobParameters; | ||
import org.springframework.batch.core.JobParametersInvalidException; | ||
|
||
import uk.ac.ebi.eva.pipeline.parameters.JobParametersNames; | ||
import uk.ac.ebi.eva.test.rules.PipelineTemporaryFolderRule; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* Tests that the arguments necessary to run a {@link uk.ac.ebi.eva.pipeline.jobs.AggregatedVcfJob} are | ||
* correctly validated | ||
*/ | ||
public class GenotypedVcfJobParametersValidatorTest { | ||
|
||
private GenotypedVcfJobParametersValidator validator; | ||
|
||
@Rule | ||
public PipelineTemporaryFolderRule temporaryFolder = new PipelineTemporaryFolderRule(); | ||
|
||
private Map<String, JobParameter> requiredParameters; | ||
|
||
private Map<String, JobParameter> annotationParameters; | ||
|
||
private Map<String, JobParameter> statsParameters; | ||
|
||
private Map<String, JobParameter> optionalParameters; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
validator = new GenotypedVcfJobParametersValidator(); | ||
final String dir = temporaryFolder.getRoot().getCanonicalPath(); | ||
|
||
requiredParameters = new TreeMap<>(); | ||
|
||
// variant load step | ||
requiredParameters.put(JobParametersNames.DB_NAME, new JobParameter("database")); | ||
requiredParameters.put(JobParametersNames.DB_COLLECTIONS_VARIANTS_NAME, new JobParameter("variants")); | ||
requiredParameters.put(JobParametersNames.INPUT_STUDY_ID, new JobParameter("inputStudyId")); | ||
requiredParameters.put(JobParametersNames.INPUT_VCF_ID, new JobParameter("inputVcfId")); | ||
requiredParameters.put(JobParametersNames.INPUT_VCF_AGGREGATION, new JobParameter("NONE")); | ||
requiredParameters.put(JobParametersNames.INPUT_VCF, | ||
new JobParameter(temporaryFolder.newFile().getCanonicalPath())); | ||
|
||
// file load step | ||
requiredParameters.put(JobParametersNames.DB_COLLECTIONS_FILES_NAME, new JobParameter("collectionsFilesName")); | ||
requiredParameters.put(JobParametersNames.INPUT_STUDY_NAME, new JobParameter("inputStudyName")); | ||
requiredParameters.put(JobParametersNames.INPUT_STUDY_TYPE, new JobParameter("COLLECTION")); | ||
|
||
// skips | ||
requiredParameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("false")); | ||
requiredParameters.put(JobParametersNames.STATISTICS_SKIP, new JobParameter("false")); | ||
|
||
// annotation | ||
annotationParameters = new TreeMap<>(); | ||
annotationParameters.put(JobParametersNames.OUTPUT_DIR_ANNOTATION, new JobParameter(dir)); | ||
annotationParameters.put(JobParametersNames.APP_VEP_CACHE_SPECIES, new JobParameter("Human")); | ||
annotationParameters.put(JobParametersNames.APP_VEP_CACHE_VERSION, new JobParameter("100_A")); | ||
annotationParameters.put(JobParametersNames.APP_VEP_NUMFORKS, new JobParameter("6")); | ||
annotationParameters.put(JobParametersNames.APP_VEP_CACHE_PATH, | ||
new JobParameter(temporaryFolder.getRoot().getCanonicalPath())); | ||
annotationParameters.put(JobParametersNames.APP_VEP_PATH, | ||
new JobParameter(temporaryFolder.newFile().getCanonicalPath())); | ||
annotationParameters.put(JobParametersNames.INPUT_FASTA, | ||
new JobParameter(temporaryFolder.newFile().getCanonicalPath())); | ||
|
||
// statistics | ||
statsParameters = new TreeMap<>(); | ||
statsParameters.put(JobParametersNames.OUTPUT_DIR_STATISTICS, new JobParameter(dir)); | ||
|
||
|
||
// optionals | ||
optionalParameters = new TreeMap<>(); | ||
optionalParameters.put(JobParametersNames.CONFIG_CHUNK_SIZE, new JobParameter("100")); | ||
optionalParameters.put(JobParametersNames.CONFIG_RESTARTABILITY_ALLOW, new JobParameter("true")); | ||
optionalParameters.put(JobParametersNames.STATISTICS_OVERWRITE, new JobParameter("true")); | ||
} | ||
|
||
// The next tests show behaviour about the required parameters | ||
|
||
@Test | ||
public void allJobParametersAreValid() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.putAll(statsParameters); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test | ||
public void allRequiredJobParametersAreValid() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.putAll(statsParameters); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void dbNameIsRequiredSkippingAnnotationAndStats() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.remove(JobParametersNames.DB_NAME); | ||
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("true")); | ||
parameters.put(JobParametersNames.STATISTICS_SKIP, new JobParameter("true")); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void dbNameIsRequiredWithoutSkippingAnnotation() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.remove(JobParametersNames.DB_NAME); | ||
parameters.put(JobParametersNames.STATISTICS_SKIP, new JobParameter("true")); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void dbNameIsRequiredWithoutSkippingStats() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(statsParameters); | ||
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("true")); | ||
parameters.remove(JobParametersNames.DB_NAME); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void dbNameIsRequiredWithoutSkippingAnnotationAndStats() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.putAll(statsParameters); | ||
parameters.remove(JobParametersNames.DB_NAME); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
// The next tests show what happens when not all the annotation parameters are present | ||
|
||
@Test | ||
public void annotationParametersAreNotRequiredIfAnnotationIsSkipped() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(statsParameters); | ||
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("true")); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void annotationParametersAreRequiredIfAnnotationIsNotSkipped() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(statsParameters); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
/** | ||
* The parameter APP_VEP_CACHE_SPECIES is chosen as one belonging to the annotation parameters. We don't check | ||
* for every annotation parameter, because in AnnotationLoaderStepParametersValidatorTest, | ||
* VepAnnotationGeneratorStepParametersValidatorTest and VepInputGeneratorStepParametersValidatorTest, it is already | ||
* checked that every missing required parameter makes the validation fail. | ||
*/ | ||
@Test(expected = JobParametersInvalidException.class) | ||
public void appVepCacheSpeciesIsRequiredIfAnnotationIsNotSkipped() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.putAll(statsParameters); | ||
parameters.remove(JobParametersNames.APP_VEP_CACHE_SPECIES); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
// The next tests show what happens when not all the stats parameters are present | ||
|
||
@Test | ||
public void statsParametersAreNotRequiredIfStatsIsSkipped() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.put(JobParametersNames.STATISTICS_SKIP, new JobParameter("true")); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void statsParametersAreRequiredIfStatsIsNotSkipped() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
|
||
@Test(expected = JobParametersInvalidException.class) | ||
public void outputDirStatistitcsIsRequiredIfStatsIsNotSkipped() throws JobParametersInvalidException { | ||
Map<String, JobParameter> parameters = new TreeMap<>(); | ||
parameters.putAll(requiredParameters); | ||
parameters.putAll(optionalParameters); | ||
parameters.putAll(annotationParameters); | ||
parameters.putAll(statsParameters); | ||
parameters.remove(JobParametersNames.OUTPUT_DIR_STATISTICS); | ||
validator.validate(new JobParameters(parameters)); | ||
} | ||
} |