Skip to content

Commit

Permalink
Merge pull request #72 from jmmut/feature/genotyped-validator
Browse files Browse the repository at this point in the history
EVA-519 add GenotypedVcfJobParametersValidator and test
  • Loading branch information
jorizci authored Jan 27, 2017
2 parents b47069d + 72866b1 commit f6ad70d
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 6 deletions.
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* {@link PopulationStatisticsLoaderStep}
*/
public class PopulationStatisticsLoaderStepParametersValidator extends DefaultJobParametersValidator {

public PopulationStatisticsLoaderStepParametersValidator() {
super(new String[]{JobParametersNames.INPUT_STUDY_ID,
JobParametersNames.INPUT_VCF_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void setUp() throws Exception {
requiredParameters.put(JobParametersNames.INPUT_STUDY_TYPE, new JobParameter("COLLECTION"));

// annotation
requiredParameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("true"));
requiredParameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("false"));

annotationParameters = new TreeMap<>();
annotationParameters.put(JobParametersNames.OUTPUT_DIR_ANNOTATION, new JobParameter(dir));
Expand Down Expand Up @@ -98,13 +98,21 @@ public void allJobParametersAreValid() throws JobParametersInvalidException {
parameters.putAll(optionalParameters);
validator.validate(new JobParameters(parameters));
}
@Test
public void allRequiredJobParametersAreValid() throws JobParametersInvalidException {
Map<String, JobParameter> parameters = new TreeMap<>();
parameters.putAll(requiredParameters);
parameters.putAll(annotationParameters);
validator.validate(new JobParameters(parameters));
}

@Test(expected = JobParametersInvalidException.class)
public void dbNameIsRequiredSkippingAnnotation() 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"));
validator.validate(new JobParameters(parameters));
}

Expand All @@ -114,7 +122,6 @@ public void dbNameIsRequiredWithoutSkippingAnnotation() throws JobParametersInva
parameters.putAll(requiredParameters);
parameters.putAll(optionalParameters);
parameters.putAll(annotationParameters);
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("false"));
parameters.remove(JobParametersNames.DB_NAME);
validator.validate(new JobParameters(parameters));
}
Expand All @@ -126,6 +133,7 @@ public void annotationParametersAreNotRequiredIfAnnotationIsSkipped() throws Job
Map<String, JobParameter> parameters = new TreeMap<>();
parameters.putAll(requiredParameters);
parameters.putAll(optionalParameters);
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("true"));
validator.validate(new JobParameters(parameters));
}

Expand All @@ -134,12 +142,11 @@ public void annotationParametersAreRequiredIfAnnotationIsNotSkipped() throws Job
Map<String, JobParameter> parameters = new TreeMap<>();
parameters.putAll(requiredParameters);
parameters.putAll(optionalParameters);
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("false"));
validator.validate(new JobParameters(parameters));
}

/**
* The parameters APP_VEP_CACHE_SPECIES is chosen as one belonging to the annotation parameters. We don't check
* 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.
Expand All @@ -151,7 +158,6 @@ public void appVepCacheSpeciesIsRequiredIfAnnotationIsNotSkipped() throws JobPar
parameters.putAll(annotationParameters);
parameters.putAll(optionalParameters);
parameters.remove(JobParametersNames.APP_VEP_CACHE_SPECIES);
parameters.put(JobParametersNames.ANNOTATION_SKIP, new JobParameter("false"));
validator.validate(new JobParameters(parameters));
}
}
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));
}
}

0 comments on commit f6ad70d

Please sign in to comment.