#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "Array.h"
#include "Sequence.h"
#include "GeneticCode.h"
#include "ScoringMatrix.h"
#include "DicodonScores.h"
#include "Statistics.h"
#include "Scores.h"
#include "Regions.h"
#include "Features.h"
#include "frameshifts.h"

void
frameshiftScan (Array regions, int frameshiftThreshold)
{
  int i, dist, curStart, curEnd;
  int prevStart[3] = {-1,-1,-1};
  int prevEnd[3] = {-1,-1,-1};
  Region *current;

  sortArray (regions, sortRegionsByStart);
  for (i = 0; i < regions->elements; i++) {
    current = regions->array[i];
    curStart = realStart (current);
    curEnd = realEnd (current);
    if (prevStart[1+current->dir] > -1) {
      dist = abs (curStart - prevEnd[1+current->dir]);
      if (dist < frameshiftThreshold) {
        fprintf(stderr, 
    "Possible frameshift near %d in %s (would join %s %d %d and %s %d %d)\n",
        prevEnd[1+current->dir], current->name, current->name, 
        prevStart[1+current->dir], prevEnd[1+current->dir], 
        current->name, curStart, curEnd);
      }
    }
    prevStart[1+current->dir] = curStart;
    prevEnd[1+current->dir] = curEnd;
  }
}
