#include "PGTwoIII_PD.h"
#include "PGTwoIII_PerProtein.h"

#include <vector>

ProjectedDatabase::ProjectedDatabase()
{
  Support=0;
}


ProjectedDatabase::ProjectedDatabase(const ProjectedDatabase & rval) {
  Support = rval.Support;
  Prefix = rval.Prefix;
  ForEachProtein = rval.ForEachProtein;
}

void ProjectedDatabase::InitiateProData(const char & FirstPrefix, const vector <string> & SequencesDatabase, const int & Max_Pat_length) {
  Support = 0;
  for (int ProteinIndex = 0; ProteinIndex < (int)(SequencesDatabase.size()); ProteinIndex++) {
    PerProtein TempPerProtein;
    TempPerProtein.InitiatePerProtein(SequencesDatabase[ProteinIndex], FirstPrefix, ProteinIndex, Max_Pat_length);

    if (TempPerProtein.GetNumberOfPositions()>0) {
      ForEachProtein.push_back(TempPerProtein);
      Support++;
    }
  }
  Prefix.push_back(FirstPrefix);
}

void ProjectedDatabase::UpdateProData(const char & NewPrefix, const vector <string> & SequencesDatabase) {
  string TempStr;
  for (int PerProteinIndex = ForEachProtein.size() - 1; PerProteinIndex >= 0; PerProteinIndex--) {
    int RealProteinIndex = ForEachProtein[PerProteinIndex].GetRealProteinIndex();
    TempStr = SequencesDatabase[RealProteinIndex];
    ForEachProtein[PerProteinIndex].UpdateCurrentPrefix(TempStr, NewPrefix);
    if (ForEachProtein[PerProteinIndex].GetNumberOfPositions() == 0)
      ProjectedDatabase::DeleteOneProtein(PerProteinIndex);
  }
  Prefix.push_back(NewPrefix);
  //Support = ForEachProtein.size();
}

void ProjectedDatabase::DeleteOneProtein(const int & PerProteinIndex) {
  int LastProteinIndex = ForEachProtein.size() - 1;
  if (PerProteinIndex != LastProteinIndex)
    ForEachProtein[PerProteinIndex].Copy(ForEachProtein[LastProteinIndex]);
  ForEachProtein.pop_back();
  Support--;
}

void ProjectedDatabase::Copy(const ProjectedDatabase &rval) {
  Support = rval.Support;
  Prefix = rval.Prefix;
  ForEachProtein = rval.ForEachProtein;
}

int ProjectedDatabase::GetSupport() {return Support;}

int ProjectedDatabase::GetPrefixSize() {return Prefix.size();}

vector<char> ProjectedDatabase::GetPrefix(){return Prefix;}



