/*
 * Copyright 2009 Lari Natri <lari.natri@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU 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 General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package compid.data;

import compid.data.tuples.DatasetInfo;
import compid.data.tuples.Protein;
import compid.data.tuples.ProteinHit.GroupMemberStatus;
import compid.report.ReportPageModel;
import compid.report.protgroup.ProtGroupCollection;
import compid.report.protgroup.ProtGroupParams.ParagonScoreType;
import net.aavalla.utils.jobpool.parameters.SyncEnumSet;
import net.aavalla.utils.general.RetrievalHashSet;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.Vector;

/**
 *
 * @author Lari Natri
 */
public interface QueryHandler {

    public Vector<DatasetInfo> getDataSetInfos() throws DAOException;

    public int getDistinctPeptidesInDataSetsCount(Collection<DatasetInfo> dataSetInfos)
            throws DAOException;

    public int getDistinctPepsUsedInProtsByDataSetsCount(Collection<DatasetInfo> dataSetInfos)
            throws DAOException;

    public RetrievalHashSet<PeptideSequenceWithHits> getDistinctPepsInDataSets(Collection<DatasetInfo> dataSetInfos, boolean onlyPepsUsedInProteins)
            throws DAOException;


    public List<Integer> getQueryHitCountsPerProtein(Collection<DatasetInfo> dataSetInfos)
        throws DAOException;

    public List<Integer> getDistinctPeptideCountsPerProtein(Collection<DatasetInfo> dataSetInfos)
        throws DAOException;

    /**
     * Gets all proteins (including the one given as parameter) that have the
     * same exact amino acid sequence.
     * @param prot
     * @return list of proteins sharing a sequence
     * @throws compid.data.DAOException
     */
    public RetrievalHashSet<Protein> getProteinsHavingSameSequence(Protein prot)
            throws DAOException;

    /**
     * Gets all proteins that don't have a valid sequence reference; ie they
     * have PROTSEQ.PROTSEQ_ID = 1.
     * @return collection of proteins matching the query
     * @throws compid.data.DAOException
     */
    public RetrievalHashSet<Protein> getAllProteinsWithoutSequence()
            throws DAOException;

    /**
     * Gets all proteins in a collection of datasets that don't have a valid
     * sequence reference; ie they have PROTSEQ.PROTSEQ_ID = 1.
     * @param datasetInfos collection of datasets
     * @return collection of proteins matching the query
     * @throws compid.data.DAOException
     */
    public int getSequencelessProteinCount(Collection<DatasetInfo> datasetInfos)
            throws DAOException;

    /**
     * Gets all proteins that reference the same sequence by id
     * @param sequenceId primary key in table PROTSEQ
     * @return collection of proteins matching the query
     * @throws compid.data.DAOException
     */
    public RetrievalHashSet<Protein> getAllProteinsBySequenceId(int sequenceId)
            throws DAOException;

    public int getDistinctProteinCount(Collection<DatasetInfo> dataSetInfos)
            throws DAOException;

    public Set<Integer> getProteinHitIdsInDatasets(Collection<DatasetInfo> dataSetInfos, boolean winnersOnly)
            throws DAOException;

    public int getQueriesWhichFoundPeptidesInDatasetsCount(Collection<DatasetInfo> dataSetInfos)
            throws DAOException;

    public int getQueriesWhichFoundPeptidesInProteinsInDatasetsCount(Collection<DatasetInfo> dataSetInfos)
            throws DAOException;

    /**
     * Gets protein groups in datasets
     * @param datasetInfos datasets to include, must have primary key set
     * @param inclGroupMembers group member types to include
     * @param inclSequences true if sequences are to be retrieved
     * @param inclPeptides true if peptides are to be retrieved
     * @param splitExistingGroups split existing groups in database and return
     *        each protein as its own group with only one member
     * @return collection of protein groups
     * @throws DAOException Thrown on database errors
     */
    public ProtGroupCollection getProtGroupsInDatasets(
            Collection<DatasetInfo> datasetInfos,
            SyncEnumSet<GroupMemberStatus> inclGroupMembers,
            boolean inclSequences,
            boolean inclPeptides,
            boolean splitExistingGroups,
            ParagonScoreType paragonScoreType)
            throws DAOException;

    public void executeManualQuery(String sqlQuery, ReportPageModel model)
            throws DAOException;

}
