From 32084443f59b052b28cb372d3ae0840abf48dc9d Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Thu, 17 Nov 2005 16:50:50 +0000 Subject: [PATCH] implement match flipping on contig reverse complement git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3826 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- uk/ac/sanger/artemis/AlignMatch.java | 37 ++++++- .../sanger/artemis/SimpleComparisonData.java | 5 +- .../artemis/components/AlignmentViewer.java | 100 +++++++++++++++++- .../artemis/components/ComparatorGlue.java | 50 ++++++--- .../components/DisplayAdjustmentEvent.java | 12 ++- .../artemis/components/FeatureDisplay.java | 17 ++- uk/ac/sanger/artemis/sequence/Bases.java | 7 +- 7 files changed, 201 insertions(+), 27 deletions(-) diff --git a/uk/ac/sanger/artemis/AlignMatch.java b/uk/ac/sanger/artemis/AlignMatch.java index b09a9cbca..a3c1d484a 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 194d7429f..48d617b5f 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 021f87447..1d62e5539 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 8da6a0ab9..556999ba4 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 fa70a88ba..4be835f85 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 6de6173da..051a45f57 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 57c2b6c1a..6c7fff720 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); -- GitLab