////////////////////////////////////////////////////////////////////////
//
// ScoreMatrix.h - a collection of classes for scoreMatrices
//
// $Id: ScoreMatrix.h,v 1.6 2002/01/20 10:51:37 goetz Exp $
//
////////////////////////////////////////////////////////////////////////

#ifndef SCOREMATRIX_H
#define SCOREMATRIX_H

#include "Alignment.h"

//////////////////////////////////////////////////////////////////////
// abstract base class for all kinds of score matrices
class ScoreMatrix
{
public:
  /** this function gives the score of two chars */
  virtual int sc(const Alchar &a1, const Alchar &a2) const =0;
  
  ScoreMatrix(const string &name)
    : name(name)
  {};
  
  /** returns description of scoring matrix */
  operator const string() const
  { return name; }

  /** destructor */
  virtual ~ScoreMatrix() {};
private:
  string name;
};

//////////////////////////////////////////////////////////////////////
// simple score matrix: match=1, mismatch=-1, gap=-2
class EditDistMatrix : public ScoreMatrix
{
public:
  /** this function gives the score of two chars */
  virtual int sc(const Alchar &a1, const Alchar &a2) const;

  EditDistMatrix() 
    : ScoreMatrix("EditDistMatrix")
  {}
};

//////////////////////////////////////////////////////////////////////
// container class for predefined scorematrices (taken from the CLUSTAL-W 
// source code) such as PAM, BLOSUM, MT and GON
class PredefScore : public ScoreMatrix
{
public:
  /** this function gives the score of two chars
   *  gaps must be represented as '.'
   */
  virtual int sc(const Alchar &a1, const Alchar &a2) const;

  /** create with score matrix array from PredefScoreMatrix "matr"
   *  and gap penalty "gap" (no gap opening and extension penalties are
   *  supported!)
   *  optional a description "name" may be given
   *  eg. PredefScore blosum30( blosum30mt, 10 );
   */
  PredefScore( const short *matr, int gap, const string &name = "" );

  /** create with score matrix array from PredefScoreMatrix "matr"
   *  gap penalty is estimated as mean value of all mismatch values
   */
  PredefScore( const short *matr, const string &name = "" );

  /** empty constructor for convenience */
  PredefScore() 
    : ScoreMatrix("") {};
  
  // destructor for cleanup
  ~PredefScore() {};

  // value of gap penalty
  int gap;
private:
  // help function for constructor
  void init( const short *matr);
  // var for estimating the gap penalty
  int gapEst;
  // this matrix is indexed by characters in the alphabet, hence 26
  short scores[26][26];
};

#endif
