diff --git a/uk/ac/sanger/artemis/AlignMatch.java b/uk/ac/sanger/artemis/AlignMatch.java
index b09a9cbcab2e80d846c883d791e70de2b55ebacb..a3c1d484a0df395d4d79d13487d6300eb207616b 100644
--- a/uk/ac/sanger/artemis/AlignMatch.java
+++ b/uk/ac/sanger/artemis/AlignMatch.java
@@ -20,18 +20,19 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/AlignMatch.java,v 1.5 2005-07-12 10:39:45 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/AlignMatch.java,v 1.6 2005-11-17 16:50:50 tjc Exp $
  */
 
 package uk.ac.sanger.artemis;
 
 import uk.ac.sanger.artemis.io.Range;
+import uk.ac.sanger.artemis.util.OutOfRangeException;
 
 /**
  *  Each object of this class represents a single match from an alignment.
  *
  *  @author Kim Rutherford
- *  @version $Id: AlignMatch.java,v 1.5 2005-07-12 10:39:45 tjc Exp $
+ *  @version $Id: AlignMatch.java,v 1.6 2005-11-17 16:50:50 tjc Exp $
  **/
 
 public class AlignMatch 
@@ -148,6 +149,38 @@ public class AlignMatch
     return query_sequence_range;
   }
 
+  /**
+   * Set the range for either the query or the subject match. This
+   * is used when flipping contigs round.
+   * @param start
+   * @param end
+   * @param subject
+   */
+  public void setRange(final int start, final int end, boolean subject)
+  {
+	try
+	{
+	  if(subject)
+	  {
+		if(start < end)
+		  this.subject_sequence_range = new Range(start, end);
+		else
+	      this.subject_sequence_range = new Range(end, start);
+	  }
+	  else
+	  {
+	    if(start < end)
+	      this.query_sequence_range = new Range(start, end);
+	    else
+	      this.query_sequence_range = new Range(end, start);
+	  }
+	}
+	catch(OutOfRangeException ex)
+	{
+	  ex.printStackTrace();
+	}
+	this.rev_match = !this.rev_match;
+  }
   /**
    *  Returns true if and only if the query hits the reverse complement of the
    *  subject.
diff --git a/uk/ac/sanger/artemis/SimpleComparisonData.java b/uk/ac/sanger/artemis/SimpleComparisonData.java
index 194d7429ffdbe0707bb965727b46cff154ae5ab4..48d617b5fe96f2762fdb5d532656b57a93e99236 100644
--- a/uk/ac/sanger/artemis/SimpleComparisonData.java
+++ b/uk/ac/sanger/artemis/SimpleComparisonData.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/SimpleComparisonData.java,v 1.2 2004-12-14 10:41:42 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/SimpleComparisonData.java,v 1.3 2005-11-17 16:50:50 tjc Exp $
  */
 
 package uk.ac.sanger.artemis;
@@ -41,7 +41,7 @@ import java.util.Hashtable;
  *  objects.  In particular it has methods for managing AlignMatch objects.
  *
  *  @author Kim Rutherford <kmr@sanger.ac.uk>
- *  @version $Id: SimpleComparisonData.java,v 1.2 2004-12-14 10:41:42 tjc Exp $
+ *  @version $Id: SimpleComparisonData.java,v 1.3 2005-11-17 16:50:50 tjc Exp $
  **/
 
 abstract class SimpleComparisonData implements ComparisonData 
@@ -111,6 +111,7 @@ abstract class SimpleComparisonData implements ComparisonData
     return matches;
   }
 
+  
   /**
    *  If this object contains only valid matches for a comparison between
    *  subject_sequence and query_sequence return null (subject_sequence is the
diff --git a/uk/ac/sanger/artemis/components/AlignmentViewer.java b/uk/ac/sanger/artemis/components/AlignmentViewer.java
index 021f874471618db0a124b6e19dfaec3f5761f056..1d62e5539a4c24875db12114ed66b5660dc59909 100644
--- a/uk/ac/sanger/artemis/components/AlignmentViewer.java
+++ b/uk/ac/sanger/artemis/components/AlignmentViewer.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/AlignmentViewer.java,v 1.30 2005-11-01 12:01:04 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/AlignmentViewer.java,v 1.31 2005-11-17 16:50:50 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.components;
@@ -47,7 +47,7 @@ import javax.swing.*;
  *  ComparisonData object.
  *
  *  @author Kim Rutherford
- *  @version $Id: AlignmentViewer.java,v 1.30 2005-11-01 12:01:04 tjc Exp $
+ *  @version $Id: AlignmentViewer.java,v 1.31 2005-11-17 16:50:50 tjc Exp $
  **/
 
 public class AlignmentViewer extends CanvasPanel
@@ -1524,6 +1524,102 @@ public class AlignmentViewer extends CanvasPanel
       return match.getQuerySequenceEnd();
   }
 
+  /**
+   * Remove an AlignMatch from the all_matches array
+   * @param index for the array
+   */
+  public void removeMatch(final int index)
+  {
+	AlignMatch tmp_matches[] = new AlignMatch[all_matches.length - 1];
+	System.arraycopy(all_matches,0,tmp_matches,0,index);
+	
+	if(index < tmp_matches.length -1)
+	{
+	  System.out.println("removeMatch() ");
+		
+      System.arraycopy(all_matches,index+1,tmp_matches,
+    		              index,all_matches.length-index);
+	}
+	this.all_matches = new AlignMatch[tmp_matches.length];
+	this.all_matches = tmp_matches;
+  }
+  
+  /**
+   * Flip the matches within a contig and deleted those that overlap
+   * with other contigs
+   * @param subject true if flipping the subject
+   * @param start of the contig
+   * @param end of the contig
+   */
+  protected void flippingContig(boolean subject, int start, int end)
+  {
+	  int match_start;
+	  int match_end;
+	  int delete_overlaps = -1;
+	  
+	  for(int i = 0; i < all_matches.length; ++i)
+	  {
+		  if(subject)
+		  {
+			match_start = all_matches[i].getSubjectSequenceStart();
+			match_end   = all_matches[i].getSubjectSequenceEnd();
+			
+		    if(match_start >= start &&
+		       match_end <= end)
+	        {
+		      match_start = end - (match_start - start);
+	          match_end   = end - (match_end -start);
+	          all_matches[i].setRange(match_start, match_end, subject);
+	        }
+		    else if( (match_start >= start && match_start <= end) ||
+		             (match_end <= end && match_end >= start) )
+		    {
+		    	  // this match extends past end of contig
+		    	  if(delete_overlaps == -1)
+				delete_overlaps = JOptionPane.showConfirmDialog(null,
+				                 "Found a match extending past the boundary of the contig:\n"+
+				                 match_start+".."+match_end+
+				                 "\nDelete all such matches?",
+				                 "Delete Overlapping Matches",
+				                 JOptionPane.YES_NO_OPTION);
+		      
+		      
+		      if(delete_overlaps == JOptionPane.YES_OPTION)
+  		    	    removeMatch(i);
+		    }
+		  }
+		  else
+		  {
+			match_start = all_matches[i].getQuerySequenceStart();
+			match_end   = all_matches[i].getQuerySequenceEnd();
+			
+		    if(match_start >= start &&
+		       match_end <= end)
+		    {
+	           match_start = end - (match_start - start);
+	           match_end   = end - (match_end -start);
+	           all_matches[i].setRange(match_start, match_end, subject);
+		    }
+		    else if( (match_start >= start && match_start <= end) ||
+		             (match_end <= end && match_end >= start) )
+		    {
+               // this match extends past end of contig
+		    	  if(delete_overlaps == -1)
+				delete_overlaps = JOptionPane.showConfirmDialog(null,
+				                 "Found a match extending past the boundary of the contig:\n"+
+				                 match_start+".."+match_end+
+				                 "\nDelete all such matches?",
+				                 "Delete Overlapping Matches",
+				                 JOptionPane.YES_NO_OPTION);
+		      
+		      
+		      if(delete_overlaps == JOptionPane.YES_OPTION)
+		    	    removeMatch(i);
+		    }
+		  }
+	  }
+  }
+  
   /**
   *
   * Find regions where there are no matches.
diff --git a/uk/ac/sanger/artemis/components/ComparatorGlue.java b/uk/ac/sanger/artemis/components/ComparatorGlue.java
index 8da6a0ab901a4bfcb67b9e96913d60edd163e551..556999ba481c6c2039bb90de80c19b9d7fba433a 100644
--- a/uk/ac/sanger/artemis/components/ComparatorGlue.java
+++ b/uk/ac/sanger/artemis/components/ComparatorGlue.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/ComparatorGlue.java,v 1.1 2004-06-09 09:46:10 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/ComparatorGlue.java,v 1.2 2005-11-17 16:50:50 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.components;
@@ -41,7 +41,7 @@ import javax.swing.*;
  *  and an AlignmentViewer.
  *
  *  @author Kim Rutherford <kmr@sanger.ac.uk>
- *  @version $Id: ComparatorGlue.java,v 1.1 2004-06-09 09:46:10 tjc Exp $
+ *  @version $Id: ComparatorGlue.java,v 1.2 2005-11-17 16:50:50 tjc Exp $
  **/
 
 public class ComparatorGlue {
@@ -75,11 +75,21 @@ public class ComparatorGlue {
    *  Wire-up the two FeatureDisplay objects with DisplayAdjustmentListeners.
    **/
   private void addDisplayListeners (final FeatureDisplay subject_display,
-                                    final FeatureDisplay query_display) {
-
-    subject_listener = new DisplayAdjustmentListener () {
-      public void displayAdjustmentValueChanged (DisplayAdjustmentEvent e) {
-        if (e.getType () == DisplayAdjustmentEvent.REV_COMP_EVENT) {
+                                    final FeatureDisplay query_display) 
+  {
+
+    subject_listener = new DisplayAdjustmentListener () 
+    {
+      public void displayAdjustmentValueChanged (DisplayAdjustmentEvent e) 
+      {
+        if (e.getType () == DisplayAdjustmentEvent.REV_COMP_EVENT) 
+        {
+          getAlignmentViewer ().unlockDisplays ();
+          return;
+        }
+        else if (e.getType () == DisplayAdjustmentEvent.CONTIG_REV_COMP_EVENT) 
+        {
+          getAlignmentViewer().flippingContig(true, e.getStart(), e.getEnd());
           getAlignmentViewer ().unlockDisplays ();
           return;
         }
@@ -107,10 +117,19 @@ public class ComparatorGlue {
       }
     };
 
-    query_listener = new DisplayAdjustmentListener () {
-      public void displayAdjustmentValueChanged (DisplayAdjustmentEvent e) {
-        if (e.getType () == DisplayAdjustmentEvent.REV_COMP_EVENT) {
-          getAlignmentViewer ().unlockDisplays ();
+    query_listener = new DisplayAdjustmentListener () 
+    {
+      public void displayAdjustmentValueChanged (DisplayAdjustmentEvent e) 
+      {
+        if (e.getType () == DisplayAdjustmentEvent.REV_COMP_EVENT) 
+        {
+          getAlignmentViewer().unlockDisplays();
+          return;
+        }
+        else if (e.getType () == DisplayAdjustmentEvent.CONTIG_REV_COMP_EVENT) 
+        {
+        	  getAlignmentViewer().flippingContig(false, e.getStart(), e.getEnd());
+        	  getAlignmentViewer().unlockDisplays();
           return;
         }
 
@@ -121,7 +140,8 @@ public class ComparatorGlue {
 
         if (getAlignmentViewer ().displaysAreLocked () &&
             (e.getType () == DisplayAdjustmentEvent.SCROLL_ADJUST_EVENT ||
-             e.getType () == DisplayAdjustmentEvent.ALL_CHANGE_ADJUST_EVENT)) {
+             e.getType () == DisplayAdjustmentEvent.ALL_CHANGE_ADJUST_EVENT)) 
+        {
           final int difference = e.getStart () - query_first_base_position;
 
           subject_first_base_position =
@@ -141,8 +161,10 @@ public class ComparatorGlue {
     query_display.addDisplayAdjustmentListener (query_listener);
 
     final DisplayAdjustmentListener subject_align_listener =
-      new DisplayAdjustmentListener () {
-        public void displayAdjustmentValueChanged (DisplayAdjustmentEvent e) {
+      new DisplayAdjustmentListener () 
+      {
+        public void displayAdjustmentValueChanged (DisplayAdjustmentEvent e) 
+        {
           getAlignmentViewer ().setSubjectSequencePosition (e);
         }
       };
diff --git a/uk/ac/sanger/artemis/components/DisplayAdjustmentEvent.java b/uk/ac/sanger/artemis/components/DisplayAdjustmentEvent.java
index fa70a88ba002ee51cb5be54ee8d40cbf3da59f70..4be835f85e291499c38982699e6ac23ccc25e6d4 100644
--- a/uk/ac/sanger/artemis/components/DisplayAdjustmentEvent.java
+++ b/uk/ac/sanger/artemis/components/DisplayAdjustmentEvent.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/DisplayAdjustmentEvent.java,v 1.1 2004-06-09 09:46:13 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/DisplayAdjustmentEvent.java,v 1.2 2005-11-17 16:50:50 tjc Exp $
  **/
 
 package uk.ac.sanger.artemis.components;
@@ -31,7 +31,7 @@ import uk.ac.sanger.artemis.ChangeEvent;
  *  This event is sent when a FeatureDisplay is scrolled.
  *
  *  @author Kim Rutherford
- *  @version $Id: DisplayAdjustmentEvent.java,v 1.1 2004-06-09 09:46:13 tjc Exp $
+ *  @version $Id: DisplayAdjustmentEvent.java,v 1.2 2005-11-17 16:50:50 tjc Exp $
  **/
 
 public class DisplayAdjustmentEvent extends ChangeEvent 
@@ -90,6 +90,14 @@ public class DisplayAdjustmentEvent extends ChangeEvent
    *  the the scale has changed.
    **/
   final static public int ALL_CHANGE_ADJUST_EVENT = 3;
+  
+  /**
+   *  The type of DisplayAdjustmentEvent where the display has been reverse
+   *  complemented.
+   **/
+  final static public int CONTIG_REV_COMP_EVENT = 4;
+
+  
 
   /**
    *  Create a new DisplayAdjustmentEvent.
diff --git a/uk/ac/sanger/artemis/components/FeatureDisplay.java b/uk/ac/sanger/artemis/components/FeatureDisplay.java
index 6de6173da99f0ac407733f4548aeef530a9cda01..051a45f57f2964a1fdf8dc9d70fc238758bc4732 100644
--- a/uk/ac/sanger/artemis/components/FeatureDisplay.java
+++ b/uk/ac/sanger/artemis/components/FeatureDisplay.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.31 2005-11-15 12:21:18 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.32 2005-11-17 16:50:50 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.components;
@@ -47,7 +47,7 @@ import javax.swing.UIManager;
  *  This component is used for displaying an Entry.
  *
  *  @author Kim Rutherford
- *  @version $Id: FeatureDisplay.java,v 1.31 2005-11-15 12:21:18 tjc Exp $
+ *  @version $Id: FeatureDisplay.java,v 1.32 2005-11-17 16:50:50 tjc Exp $
  **/
 
 public class FeatureDisplay extends EntryGroupPanel
@@ -967,6 +967,19 @@ public class FeatureDisplay extends EntryGroupPanel
 
     if(event.getType() == SequenceChangeEvent.REVERSE_COMPLEMENT ) 
       fireAdjustmentEvent(DisplayAdjustmentEvent.REV_COMP_EVENT);
+    else if(event.getType() == SequenceChangeEvent.CONTIG_REVERSE_COMPLEMENT ) 
+    {
+    	   final Range range = event.getRange();
+      
+    	   fireAction(adjustment_listener_list, 
+    			   new DisplayAdjustmentEvent(FeatureDisplay.this,
+                           range.getStart(),
+                           range.getEnd(),
+                           getMaxVisibleBases(),
+                           getScaleValue(), getScaleFactor(),
+                           isRevCompDisplay(), 
+                           DisplayAdjustmentEvent.CONTIG_REV_COMP_EVENT));
+    }
     else 
       fireAdjustmentEvent(DisplayAdjustmentEvent.SCROLL_ADJUST_EVENT);
   }
diff --git a/uk/ac/sanger/artemis/sequence/Bases.java b/uk/ac/sanger/artemis/sequence/Bases.java
index 57c2b6c1ab6fc044eb333ee2a2be24a42ebca640..6c7fff720a6ad93fcb027d309c43bcc0108b33f5 100644
--- a/uk/ac/sanger/artemis/sequence/Bases.java
+++ b/uk/ac/sanger/artemis/sequence/Bases.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.17 2005-11-15 12:21:18 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.18 2005-11-17 16:50:50 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.sequence;
@@ -47,7 +47,7 @@ import java.util.Iterator;
  *  non-base letter returns '@'.
  *
  *  @author Kim Rutherford
- *  @version $Id: Bases.java,v 1.17 2005-11-15 12:21:18 tjc Exp $ */
+ *  @version $Id: Bases.java,v 1.18 2005-11-17 16:50:50 tjc Exp $ */
 
 public class Bases 
 {
@@ -1224,7 +1224,8 @@ public class Bases
       if (this_hash_map != null) {
         final Iterator iter = this_hash_map.keySet ().iterator ();
 
-        while (iter.hasNext()) {
+        while (iter.hasNext()) 
+        {
           final SequenceChangeListener this_listener =
             (SequenceChangeListener) iter.next();
           this_listener.sequenceChanged (event);