public void swap(int i1, int i2, int j1, int j2){

    int ilength = i2-i1+1;
    int jlength = j2-j1+1;
    int diff = jlength - ilength;

    Set<Pair<Integer,Integer>> newAlignments = new HashSet<Pair<Integer,Integer>>();

    for(Pair<Integer,Integer> alignment : sureAlignments){
      int pos = alignment.getFirst();

      if(pos < i1 || pos > j2){
        newAlignments.add(alignment);
      }
      else if (pos >= i1 && pos <= i2){
        newAlignments.add(new Pair<Integer,Integer>(pos+j2-i2, alignment.getSecond()));
      }
      else if (pos > i2 && pos < j1){
        newAlignments.add(new Pair<Integer,Integer>(pos+diff, alignment.getSecond()));
      }
      else if(pos >= j1 && pos <= j2){
        newAlignments.add(new Pair<Integer,Integer>(pos-j1+i1, alignment.getSecond()));
      }
      else{
        System.err.println("Error in Alignment.swap()");
        System.exit(1);
      }

    }

    sureAlignments = newAlignments;
  }