<commit_before>/*
 * The Exomiser - A tool to annotate and prioritize genomic variants
 *
 * Copyright (c) 2016-2020 Queen Mary University of London.
 * Copyright (c) 2012-2016 Char<NAME> 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/>.
 */

package org.monarchinitiative.exomiser.core.analysis;

import com.google.common.collect.Sets;
import de.charite.compbio.jannovar.annotation.VariantEffect;
import org.monarchinitiative.exomiser.core.analysis.util.InheritanceModeOptions;
import org.monarchinitiative.exomiser.core.filters.*;
import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisService;
import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisServiceProvider;
import org.monarchinitiative.exomiser.core.model.ChromosomalRegion;
import org.monarchinitiative.exomiser.core.model.GeneticInterval;
import org.monarchinitiative.exomiser.core.model.frequency.FrequencySource;
import org.monarchinitiative.exomiser.core.model.pathogenicity.PathogenicitySource;
import org.monarchinitiative.exomiser.core.phenotype.service.OntologyService;
import org.monarchinitiative.exomiser.core.prioritisers.HiPhiveOptions;
import org.monarchinitiative.exomiser.core.prioritisers.PriorityFactory;
import org.monarchinitiative.exomiser.core.prioritisers.PriorityType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Class for correctly building an {@link Analysis} object ready to be run by an {@link AnalysisRunner}.
 *
 * @author <NAME> <<EMAIL>>
 */
public class AnalysisBuilder implements FluentAnalysisBuilder<Analysis> {

    private static final Logger logger = LoggerFactory.getLogger(AnalysisBuilder.class);

    // Perhaps combine these into an ueber AnalysisService?
    private final OntologyService ontologyService;
    private final PriorityFactory priorityFactory;
    private final GenomeAnalysisServiceProvider genomeAnalysisServiceProvider;

    private final Analysis.Builder builder;

    private InheritanceModeOptions inheritanceModeOptions = InheritanceModeOptions.empty();

    //Source-data-related variables
    private GenomeAnalysisService genomeAnalysisService;
    private Set<FrequencySource> frequencySources = EnumSet.noneOf(FrequencySource.class);
    private Set<PathogenicitySource> pathogenicitySources = EnumSet.noneOf(PathogenicitySource.class);

    private List<AnalysisStep> analysisSteps = new ArrayList<>();

    AnalysisBuilder(GenomeAnalysisServiceProvider genomeAnalysisServiceProvider, PriorityFactory priorityFactory, OntologyService ontologyService) {
        this.ontologyService = ontologyService;
        this.priorityFactory = priorityFactory;
        this.genomeAnalysisServiceProvider = genomeAnalysisServiceProvider;
        this.builder = Analysis.builder();
    }

    // TODO: Should this be building an AnalysisProto (rename to Analysis), then the AnalysisProto is wrapped in an AnalysisRunnerSupport?
    //  alternatively the AnalysisParser could be used for creating a RunnableAnalysis which has all the decorated filters and so on ready to roll
    //  i.e. rename the current Analysis to Job and split into Sample and Analysis
    public Analysis build() {
        new AnalysisStepChecker().check(analysisSteps);
        builder.steps(analysisSteps);
        return builder.build();<commit_msg>Update AnalysisBuilder to use final analysisSteps variable<commit_after>/*
 * The Exomiser - A tool to annotate and prioritize genomic variants
 *
 * Copyright (c) 2016-2020 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/>.
 */

package org.monarchinitiative.exomiser.core.analysis;

import com.google.common.collect.Sets;
import de.charite.compbio.jannovar.annotation.VariantEffect;
import org.monarchinitiative.exomiser.core.analysis.util.InheritanceModeOptions;
import org.monarchinitiative.exomiser.core.filters.*;
import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisService;
import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisServiceProvider;
import org.monarchinitiative.exomiser.core.model.ChromosomalRegion;
import org.monarchinitiative.exomiser.core.model.GeneticInterval;
import org.monarchinitiative.exomiser.core.model.frequency.FrequencySource;
import org.monarchinitiative.exomiser.core.model.pathogenicity.PathogenicitySource;
import org.monarchinitiative.exomiser.core.phenotype.service.OntologyService;
import org.monarchinitiative.exomiser.core.prioritisers.HiPhiveOptions;
import org.monarchinitiative.exomiser.core.prioritisers.PriorityFactory;
import org.monarchinitiative.exomiser.core.prioritisers.PriorityType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Class for correctly building an {@link Analysis} object ready to be run by an {@link AnalysisRunner}.
 *
 * @author <NAME> <<EMAIL>>
 */
public class AnalysisBuilder implements FluentAnalysisBuilder<Analysis> {

    private static final Logger logger = LoggerFactory.getLogger(AnalysisBuilder.class);

    // Perhaps combine these into an ueber AnalysisService?
    private final OntologyService ontologyService;
    private final PriorityFactory priorityFactory;
    private final GenomeAnalysisServiceProvider genomeAnalysisServiceProvider;

    private final Analysis.Builder builder;

    private InheritanceModeOptions inheritanceModeOptions = InheritanceModeOptions.empty();

    //Source-data-related variables
    private GenomeAnalysisService genomeAnalysisService;
    private Set<FrequencySource> frequencySources = EnumSet.noneOf(FrequencySource.class);
    private Set<PathogenicitySource> pathogenicitySources = EnumSet.noneOf(PathogenicitySource.class);

    private final List<AnalysisStep> analysisSteps = new ArrayList<>();

    AnalysisBuilder(GenomeAnalysisServiceProvider genomeAnalysisServiceProvider, PriorityFactory priorityFactory, OntologyService ontologyService) {
        this.ontologyService = ontologyService;
        this.priorityFactory = priorityFactory;
        this.genomeAnalysisServiceProvider = genomeAnalysisServiceProvider;
        this.builder = Analysis.builder();
    }

    // TODO: Should this be building an AnalysisProto (rename to Analysis), then the AnalysisProto is wrapped in an AnalysisRunnerSupport?
    //  alternatively the AnalysisParser could be used for creating a RunnableAnalysis which has all the decorated filters and so on ready to roll
    //  i.e. rename the current Analysis to Job and split into Sample and Analysis
    public Analysis build() {
        new AnalysisStepChecker().check(analysisSteps);
        builder.steps(analysisSteps);
        return builder.build();
{'fraction_non_alphanumeric': 0.0712404364730967, 'fraction_numerical': 0.004766085538693089, 'mean_word_length': 5.031770045385779, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3638668', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2001, 'n_words': 638}