Java tutorial
/* * Copyright 2016 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.jobs.steps.processor; import org.junit.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.test.MetaDataInstanceFactory; import uk.ac.ebi.eva.pipeline.io.readers.GeneReader; import uk.ac.ebi.eva.pipeline.jobs.steps.processors.GeneFilterProcessor; import uk.ac.ebi.eva.pipeline.model.FeatureCoordinates; import uk.ac.ebi.eva.test.data.GtfStaticTestData; import uk.ac.ebi.eva.test.utils.JobTestUtils; import java.io.File; import static junit.framework.TestCase.assertEquals; /** * {@link GeneFilterProcessor} * input: FeatureCoordinates * output: FeatureCoordinates that are "transcript" or "gene" */ public class GeneFilterProcessorTest { @Test public void shouldKeepGenesAndTranscripts() throws Exception { ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext(); GeneFilterProcessor geneFilterProcessor = new GeneFilterProcessor(); //simulate VEP output file File file = JobTestUtils.makeGzipFile(GtfStaticTestData.GTF_CONTENT); GeneReader geneReader = new GeneReader(file); geneReader.setSaveState(false); geneReader.open(executionContext); FeatureCoordinates gene; int count = 0; int keptGenes = 0; while ((gene = geneReader.read()) != null) { count++; FeatureCoordinates processedGene = geneFilterProcessor.process(gene); if (processedGene != null) { keptGenes++; } } assertEquals(7, count); assertEquals(4, keptGenes); } }