/*
 * The Exomiser - A tool to annotate and prioritize genomic variants
 *
 * Copyright (c) 2016-2017 Queen Mary University of London.
 * Copyright (c) 2012-2016 Charité Universitätsmedizin Berlin and Genome Research Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.monarchinitiative.exomiser.core;

import org.junit.Test;
import org.monarchinitiative.exomiser.core.analysis.*;
import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisServiceProvider;
import org.monarchinitiative.exomiser.core.genome.GenomeAssembly;
import org.monarchinitiative.exomiser.core.genome.TestFactory;
import org.monarchinitiative.exomiser.core.prioritisers.PriorityFactory;
import org.monarchinitiative.exomiser.core.prioritisers.PriorityFactoryImpl;
import org.monarchinitiative.exomiser.core.prioritisers.service.TestPriorityServiceFactory;

import java.nio.file.Path;
import java.nio.file.Paths;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 *
 * @author Jules Jacobsen <jules.jacobsen@sanger.ac.uk>
 */
public class ExomiserTest {

    private static final Path VCF_PATH = Paths.get("src/test/resources/smallTest.vcf");

    private final GenomeAnalysisServiceProvider genomeAnalysisServiceProvider = new GenomeAnalysisServiceProvider(TestFactory
            .buildDefaultHg19GenomeAnalysisService());
    private final PriorityFactory priorityFactory = new PriorityFactoryImpl(TestPriorityServiceFactory.TEST_SERVICE, null, null);

    private final AnalysisFactory analysisFactory = new AnalysisFactory(genomeAnalysisServiceProvider, TestFactory
            .buildDefaultVariantFactory(), priorityFactory);
    //AnalysisFactory is only ever used here, but it provides a clean interface to the Analysis module
    private Exomiser instance = new Exomiser(analysisFactory);

    private Analysis makeAnalysisWithMode(AnalysisMode analysisMode) {
        return instance.getAnalysisBuilder()
                .vcfPath(VCF_PATH)
                .analysisMode(analysisMode)
                .build();
    }
    
    @Test
    public void canRunAnalysis_Full() {
        Analysis analysis = makeAnalysisWithMode(AnalysisMode.FULL);
        AnalysisResults analysisResults = instance.run(analysis);
        assertThat(analysisResults.getGenes().size(), equalTo(2));
    }
    
    @Test
    public void canRunAnalysis_Sparse() {
        Analysis analysis = makeAnalysisWithMode(AnalysisMode.SPARSE);
        AnalysisResults analysisResults = instance.run(analysis);
        assertThat(analysisResults.getGenes().size(), equalTo(2));
    }
    
    @Test
    public void canRunAnalysis_PassOnly() {
        Analysis analysis = makeAnalysisWithMode(AnalysisMode.PASS_ONLY);
        AnalysisResults analysisResults = instance.run(analysis);
        assertThat(analysisResults.getGenes().size(), equalTo(2));
    }

    @Test
    public void canRunAnalysisUsingAlternateGenomeAssemblyPassOnly() {
        Analysis analysis = instance.getAnalysisBuilder()
                .vcfPath(VCF_PATH)
                .genomeAssembly(GenomeAssembly.HG38)
                .analysisMode(AnalysisMode.PASS_ONLY)
                .build();
        AnalysisResults analysisResults = instance.run(analysis);
        assertThat(analysisResults.getGenes().size(), equalTo(2));
    }

    @Test
    public void canGetAnalysisBuilder() {
        AnalysisBuilder analysisBuilder = instance.getAnalysisBuilder();
        assertThat(analysisBuilder, instanceOf(AnalysisBuilder.class));
    }

 }

@@ -1121,16 +1121,55 @@
 .core;%0A%0A
+import com.google.common.collect.Sets;%0A
 import o
@@ -1238,16 +1238,89 @@
 ysis.*;%0A
+import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisService;%0A
 import o
@@ -3930,32 +3930,38 @@
 ) %7B%0A        
+Genome
 Analysis
  analysis = 
@@ -3952,28 +3952,1060 @@
 ysis
- analysis = instance
+Service grch37Service = TestFactory.buildStubGenomeAnalysisService(GenomeAssembly.HG19);%0A        GenomeAnalysisService grch38Service = TestFactory.buildStubGenomeAnalysisService(GenomeAssembly.HG38);%0A%0A        GenomeAnalysisServiceProvider twoAssemblyProvider = new GenomeAnalysisServiceProvider(grch37Service, Sets.newHashSet(grch38Service));%0A        AnalysisFactory analysisFactory = new AnalysisFactory(twoAssemblyProvider, TestFactory.buildDefaultVariantFactory(), priorityFactory);%0A%0A        Exomiser twoAssembliesSupportedExomiser = new Exomiser(analysisFactory);%0A%0A        Analysis hg37Analysis = twoAssembliesSupportedExomiser.getAnalysisBuilder()%0A                .vcfPath(VCF_PATH)%0A                .genomeAssembly(GenomeAssembly.HG19)%0A                .analysisMode(AnalysisMode.PASS_ONLY)%0A                .build();%0A        AnalysisResults hg37AnalysisResults = twoAssembliesSupportedExomiser.run(hg37Analysis);%0A        assertThat(hg37AnalysisResults.getGenes().size(), equalTo(2));%0A%0A%0A        Analysis hg38Analysis = twoAssembliesSupportedExomiser
 .get
@@ -5206,33 +5206,37 @@
 AnalysisResults 
-a
+hg38A
 nalysisResults =
@@ -5232,38 +5232,64 @@
 isResults = 
-instance.run(a
+twoAssembliesSupportedExomiser.run(hg38A
 nalysis);%0A  
@@ -5297,33 +5297,37 @@
      assertThat(
-a
+hg38A
 nalysisResults.g

Fix broken ExomiserTest