#include "PGOneII_PerProtein.h"
#include <string>
#include <vector>

PerProtein::PerProtein()
{
  RealProteinIndex = 0;
  NumberOfPositions = 0;
  LengthOfProtein = 0;
}

PerProtein::PerProtein(const PerProtein & rval)
{
  RealProteinIndex = rval.RealProteinIndex;
  NumberOfPositions = rval.NumberOfPositions;
  LengthOfProtein = rval.LengthOfProtein;
  CurrentPrefix = rval.CurrentPrefix;
}

void PerProtein::InitiatePerProtein(const string & OneProtein,
                                    const char & FirstPrefix,
                                    const int & ProteinIndexInput) {
  RealProteinIndex = ProteinIndexInput;
  LengthOfProtein = OneProtein.size();
  NumberOfPositions = 0;
  for (int ResidueIndex = 0; ResidueIndex < LengthOfProtein-1; ResidueIndex++) {
    if (OneProtein[ResidueIndex] == FirstPrefix) {
      CurrentPrefix.push_back(ResidueIndex);
      NumberOfPositions++;
    }
  }
}

void PerProtein::UpdateCurrentPrefix(const PerProtein & InputProtein,
                                     const string & OneProtein,
                                     const char & NewPrefix,
                                     const int & Lower,
                                     const int & Upper) {
    for (int PositionIndex = 0; PositionIndex < int(InputProtein.CurrentPrefix.size()); PositionIndex++) {
      int AALowerIndex = InputProtein.CurrentPrefix[PositionIndex] + Lower + 1;
      int AAUpperIndex = InputProtein.CurrentPrefix[PositionIndex] + Upper + 1;
      for (int ResidueIndex = AALowerIndex;
           ResidueIndex <= AAUpperIndex; ResidueIndex++) {
        if (OneProtein[ResidueIndex] == NewPrefix) {
          CurrentPrefix.push_back(ResidueIndex);
        }
      }
    }
    NumberOfPositions = CurrentPrefix.size();
}


void PerProtein::CopyPart(const PerProtein & rval) {
  RealProteinIndex = rval.RealProteinIndex;
  LengthOfProtein = rval.LengthOfProtein;
}

  int PerProtein::GetRealProteinIndex() {return RealProteinIndex;}
  int PerProtein::GetNumberOfPositions() {return NumberOfPositions;}
  int PerProtein::GetLengthOfProtein() {return LengthOfProtein;}

