}
/**
- * DOCUMENT ME!
+ * Returns the given sequence with all of the given gap characters removed.
*
- * @param gapChar
- * DOCUMENT ME!
+ * @param gapChars
+ * a string of characters to be treated as gaps
* @param seq
- * DOCUMENT ME!
+ * the input sequence
*
- * @return DOCUMENT ME!
+ * @return
*/
- public static String extractGaps(String gapChar, String seq)
+ public static String extractGaps(String gapChars, String seq)
{
- StringTokenizer str = new StringTokenizer(seq, gapChar);
- StringBuffer newString = new StringBuffer();
+ if (gapChars == null || seq == null)
+ {
+ return null;
+ }
+ StringTokenizer str = new StringTokenizer(seq, gapChars);
+ StringBuilder newString = new StringBuilder(seq.length());
while (str.hasMoreTokens())
{
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* grab bag of useful alignment manipulation operations Expect these to be
* Answers true if the mappings include one between the given (dataset)
* sequences.
*/
- public static boolean mappingExists(AlignedCodonFrame[] codonFrames,
+ public static boolean mappingExists(Set<AlignedCodonFrame> set,
SequenceI aaSeq, SequenceI cdnaSeq)
{
- if (codonFrames != null)
+ if (set != null)
{
- for (AlignedCodonFrame acf : codonFrames)
+ for (AlignedCodonFrame acf : set)
{
if (cdnaSeq == acf.getDnaForAaSeq(aaSeq))
{
*/
// TODO there may be one AlignedCodonFrame per dataset sequence, or one with
// all mappings. Would it help to constrain this?
- AlignedCodonFrame[] mappings = al.getCodonFrame(seq);
+ List<AlignedCodonFrame> mappings = al.getCodonFrame(seq);
if (mappings == null)
{
return false;
boolean selectedOnly);
/**
- * Returns a viewport which is a 'slave of' this one i.e. updated in
- * tandem in some sense, or null if none is set.
+ * Returns a viewport which holds the cDna for this (protein), or vice versa,
+ * or null if none is set.
*
* @return
*/
- AlignViewportI getSlave();
-
- void setSlave(AlignViewportI sl);
+ AlignViewportI getCodingComplement();
+
+ void setCodingComplement(AlignViewportI sl);
+
+ /**
+ * Answers true if viewport hosts DNA/RAN, false if peptide.
+ *
+ * @return
+ */
+ boolean isNucleotide();
}
for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
.size(); i++)
{
- int[] region = (int[]) viewport.getColumnSelection()
- .getHiddenColumns().elementAt(i);
+ int[] region = viewport.getColumnSelection()
+ .getHiddenColumns().get(i);
copiedHiddenColumns.addElement(new int[]
{ region[0] - hiddenOffset, region[1] - hiddenOffset });
*/
package jalview.appletgui;
-import java.util.*;
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
import jalview.util.ParseHtmlBodyAndLinks;
+import java.awt.Checkbox;
+import java.awt.CheckboxMenuItem;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.FontMetrics;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.MenuItem;
+import java.awt.Panel;
+import java.awt.PopupMenu;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.util.Arrays;
+import java.util.Vector;
+
public class AnnotationLabels extends Panel implements ActionListener,
MouseListener, MouseMotionListener
{
return true;
}
else
+ {
return false;
+ }
}
jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
{
- int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
- .elementAt(i);
+ int[] region = av.getColumnSelection().getHiddenColumns().get(i);
jalview.appletgui.AlignFrame.copiedHiddenColumns
.addElement(new int[]
*/
package jalview.appletgui;
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SequenceGroup;
import jalview.util.MessageManager;
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.MenuItem;
+import java.awt.Panel;
+import java.awt.PopupMenu;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
public class ScalePanel extends Panel implements MouseMotionListener,
MouseListener
{
reveal = null;
for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
{
- int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
- .elementAt(i);
+ int[] region = av.getColumnSelection().getHiddenColumns().get(i);
if (res + 1 == region[0] || res - 1 == region[1])
{
reveal = region;
}
gg.drawLine(
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + 2,
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + (fm.getDescent() * 2));
}
else
{
gg.drawLine(
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + fm.getDescent(),
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + (fm.getDescent() * 2));
}
}
*/
package jalview.appletgui;
-import java.awt.*;
-
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Panel;
+import java.util.List;
public class SeqCanvas extends Panel
{
}
else
{
- java.util.Vector regions = av.getColumnSelection().getHiddenColumns();
+ List<int[]> regions = av.getColumnSelection().getHiddenColumns();
int screenY = 0;
int blockStart = startRes;
int blockEnd = endRes;
- for (int i = 0; i < regions.size(); i++)
+ for (int[] region : regions)
{
- int[] region = (int[]) regions.elementAt(i);
int hideStart = region[0];
int hideEnd = region[1];
if ((group == null) && (av.getAlignment().getGroups().size() > 0))
{
- group = (SequenceGroup) av.getAlignment().getGroups().get(0);
+ group = av.getAlignment().getGroups().get(0);
groupIndex = 0;
}
break;
}
- group = (SequenceGroup) av.getAlignment().getGroups()
+ group = av.getAlignment().getGroups()
.get(groupIndex);
} while (groupIndex < av.getAlignment().getGroups().size());
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Hashtable;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
end = rs.findIndex(end);
if (csel != null)
{
- Vector cs = csel.getSelected();
+ List<Integer> cs = csel.getSelected();
csel.clear();
- for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
+ for (Integer selectedCol : cs)
{
- csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
- .intValue()));
+ csel.addElement(rs.findIndex(selectedCol));
}
}
}
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Override
public void setSequenceAt(int i, SequenceI snew)
{
- SequenceI oldseq = getSequenceAt(i);
- deleteSequence(i);
synchronized (sequences)
{
+ deleteSequence(i);
sequences.set(i, snew);
}
}
synchronized (sequences)
{
sequences.remove(i);
+ hiddenSequences.adjustHeightSequenceDeleted(i);
}
- hiddenSequences.adjustHeightSequenceDeleted(i);
}
}
return alignmentProperties;
}
- AlignedCodonFrame[] codonFrameList = null;
+ // AlignedCodonFrame[] codonFrameList = null;
+
+ LinkedHashSet<AlignedCodonFrame> codonFrameList = new LinkedHashSet<AlignedCodonFrame>();
/*
* (non-Javadoc)
@Override
public void addCodonFrame(AlignedCodonFrame codons)
{
- if (codons == null)
- {
- return;
- }
- if (codonFrameList == null)
+ if (codons != null)
{
- codonFrameList = new AlignedCodonFrame[]
- { codons };
- return;
+ codonFrameList.add(codons);
}
- AlignedCodonFrame[] t = new AlignedCodonFrame[codonFrameList.length + 1];
- System.arraycopy(codonFrameList, 0, t, 0, codonFrameList.length);
- t[codonFrameList.length] = codons;
- codonFrameList = t;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see jalview.datamodel.AlignmentI#getCodonFrame(int)
- */
- @Override
- public AlignedCodonFrame getCodonFrame(int index)
- {
- return codonFrameList[index];
}
/*
* jalview.datamodel.AlignmentI#getCodonFrame(jalview.datamodel.SequenceI)
*/
@Override
- public AlignedCodonFrame[] getCodonFrame(SequenceI seq)
+ public List<AlignedCodonFrame> getCodonFrame(SequenceI seq)
{
- if (seq == null || codonFrameList == null)
+ if (seq == null)
{
return null;
}
- Vector cframes = new Vector();
- for (int f = 0; f < codonFrameList.length; f++)
+ List<AlignedCodonFrame> cframes = new ArrayList<AlignedCodonFrame>();
+ for (AlignedCodonFrame acf : codonFrameList)
{
- if (codonFrameList[f].involvesSequence(seq))
+ if (acf.involvesSequence(seq))
{
- cframes.addElement(codonFrameList[f]);
+ cframes.add(acf);
}
}
- if (cframes.size() == 0)
- {
- return null;
- }
- AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()];
- cframes.copyInto(cfr);
- return cfr;
+ return cframes;
}
/*
* @see jalview.datamodel.AlignmentI#getCodonFrames()
*/
@Override
- public AlignedCodonFrame[] getCodonFrames()
+ public Set<AlignedCodonFrame> getCodonFrames()
{
return codonFrameList;
}
{
return false;
}
- boolean removed = false;
- int i = 0, iSize = codonFrameList.length;
- while (i < iSize)
- {
- if (codonFrameList[i] == codons)
- {
- removed = true;
- if (i + 1 < iSize)
- {
- System.arraycopy(codonFrameList, i + 1, codonFrameList, i, iSize
- - i - 1);
- }
- iSize--;
- }
- else
- {
- i++;
- }
- }
- return removed;
+ return codonFrameList.remove(codons);
}
@Override
{
addAnnotation(alan[a]);
}
- AlignedCodonFrame[] acod = toappend.getCodonFrames();
- for (int a = 0; acod != null && a < acod.length; a++)
- {
- this.addCodonFrame(acod[a]);
- }
+
+ this.codonFrameList.addAll(toappend.getCodonFrames());
+
List<SequenceGroup> sg = toappend.getGroups();
if (sg != null)
{
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
+ * modify it under the terms of the GNU General License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
+ * PURPOSE. See the GNU General License for more details.
*
- * You should have received a copy of the GNU General Public License
+ * You should have received a copy of the GNU General License
* along with Jalview. If not, see <http://www.gnu.org/licenses/>.
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
*
* @return Number of sequences in alignment
*/
- public int getHeight();
+ int getHeight();
/**
*
* @return Greatest sequence length within alignment.
*/
@Override
- public int getWidth();
+ int getWidth();
/**
* Calculates if this set of sequences (visible and invisible) are all the
*
* @return true if all sequences in alignment are the same length
*/
- public boolean isAligned();
+ boolean isAligned();
/**
* Calculates if this set of sequences is all the same length
* optionally exclude hidden sequences from test
* @return true if all (or just visible) sequences are the same length
*/
- public boolean isAligned(boolean includeHidden);
+ boolean isAligned(boolean includeHidden);
/**
* Gets sequences as a Synchronized collection
* @return All sequences in alignment.
*/
@Override
- public List<SequenceI> getSequences();
+ List<SequenceI> getSequences();
/**
* Gets sequences as a SequenceI[]
*
* @return All sequences in alignment.
*/
- public SequenceI[] getSequencesArray();
+ SequenceI[] getSequencesArray();
/**
* Find a specific sequence in this alignment.
*
* @return SequenceI at given index.
*/
- public SequenceI getSequenceAt(int i);
+ SequenceI getSequenceAt(int i);
/**
* Returns a map of lists of sequences keyed by sequence name.
*
* @return
*/
- public Map<String, List<SequenceI>> getSequencesByName();
+ Map<String, List<SequenceI>> getSequencesByName();
/**
* Add a new sequence to this alignment.
* @param seq
* New sequence will be added at end of alignment.
*/
- public void addSequence(SequenceI seq);
+ void addSequence(SequenceI seq);
/**
* Used to set a particular index of the alignment with the given sequence.
* @param seq
* New sequence to be inserted.
*/
- public void setSequenceAt(int i, SequenceI seq);
+ void setSequenceAt(int i, SequenceI seq);
/**
* Deletes a sequence from the alignment
* @param s
* Sequence to be deleted.
*/
- public void deleteSequence(SequenceI s);
+ void deleteSequence(SequenceI s);
/**
* Deletes a sequence from the alignment.
* @param i
* Index of sequence to be deleted.
*/
- public void deleteSequence(int i);
+ void deleteSequence(int i);
/**
* Finds sequence in alignment using sequence name as query.
*
* @return Sequence matching query, if found. If not found returns null.
*/
- public SequenceI findName(String name);
+ SequenceI findName(String name);
- public SequenceI[] findSequenceMatch(String name);
+ SequenceI[] findSequenceMatch(String name);
/**
* Finds index of a given sequence in the alignment.
*
* @return Index of sequence within the alignment or -1 if not found
*/
- public int findIndex(SequenceI s);
+ int findIndex(SequenceI s);
/**
* Finds group that given sequence is part of.
* @return First group found for sequence. WARNING : Sequences may be members
* of several groups. This method is incomplete.
*/
- public SequenceGroup findGroup(SequenceI s);
+ SequenceGroup findGroup(SequenceI s);
/**
* Finds all groups that a given sequence is part of.
*
* @return All groups containing given sequence.
*/
- public SequenceGroup[] findAllGroups(SequenceI s);
+ SequenceGroup[] findAllGroups(SequenceI s);
/**
* Adds a new SequenceGroup to this alignment.
* @param sg
* New group to be added.
*/
- public void addGroup(SequenceGroup sg);
+ void addGroup(SequenceGroup sg);
/**
* Deletes a specific SequenceGroup
* @param g
* Group will be deleted from alignment.
*/
- public void deleteGroup(SequenceGroup g);
+ void deleteGroup(SequenceGroup g);
/**
* Get all the groups associated with this alignment.
*
* @return All groups as a list.
*/
- public List<SequenceGroup> getGroups();
+ List<SequenceGroup> getGroups();
/**
* Deletes all groups from this alignment.
*/
- public void deleteAllGroups();
+ void deleteAllGroups();
/**
* Adds a new AlignmentAnnotation to this alignment
* @note Care should be taken to ensure that annotation is at least as wide as
* the longest sequence in the alignment for rendering purposes.
*/
- public void addAnnotation(AlignmentAnnotation aa);
+ void addAnnotation(AlignmentAnnotation aa);
/**
* moves annotation to a specified index in alignment annotation display stack
* @param index
* the destination position
*/
- public void setAnnotationIndex(AlignmentAnnotation aa, int index);
+ void setAnnotationIndex(AlignmentAnnotation aa, int index);
/**
* Deletes a specific AlignmentAnnotation from the alignment, and removes its
* the annotation to delete
* @return true if annotation was deleted from this alignment.
*/
- public boolean deleteAnnotation(AlignmentAnnotation aa);
+ boolean deleteAnnotation(AlignmentAnnotation aa);
/**
* Deletes a specific AlignmentAnnotation from the alignment, and optionally
* into the alignment
* @return true if annotation was deleted from this alignment.
*/
- public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
+ boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook);
/**
* Get the annotation associated with this alignment (this can be null if no
* @return array of AlignmentAnnotation objects
*/
@Override
- public AlignmentAnnotation[] getAlignmentAnnotation();
+ AlignmentAnnotation[] getAlignmentAnnotation();
/**
* Change the gap character used in this alignment to 'gc'
* @param gc
* the new gap character.
*/
- public void setGapCharacter(char gc);
+ void setGapCharacter(char gc);
/**
* Get the gap character used in this alignment
*
* @return gap character
*/
- public char getGapCharacter();
+ char getGapCharacter();
/**
* Test for all nucleotide alignment
*
* @return true if alignment is nucleotide sequence
*/
- public boolean isNucleotide();
+ boolean isNucleotide();
/**
* Test if alignment contains RNA structure
*
* @return true if RNA structure AligmnentAnnotation was added to alignment
*/
- public boolean hasRNAStructure();
+ boolean hasRNAStructure();
/**
* Set alignment to be a nucleotide sequence
*
*/
- public void setNucleotide(boolean b);
+ void setNucleotide(boolean b);
/**
* Get the associated dataset for the alignment.
* @return Alignment containing dataset sequences or null of this is a
* dataset.
*/
- public Alignment getDataset();
+ Alignment getDataset();
/**
* Set the associated dataset for the alignment, or create one.
* @param dataset
* The dataset alignment or null to construct one.
*/
- public void setDataset(Alignment dataset);
+ void setDataset(Alignment dataset);
/**
* pads sequences with gaps (to ensure the set looks like an alignment)
*
* @return boolean true if alignment was modified
*/
- public boolean padGaps();
+ boolean padGaps();
- public HiddenSequences getHiddenSequences();
+ HiddenSequences getHiddenSequences();
/**
* Compact representation of alignment
*
* @return CigarArray
*/
- public CigarArray getCompactAlignment();
+ CigarArray getCompactAlignment();
/**
* Set an arbitrary key value pair for an alignment. Note: both key and value
* @param key
* @param value
*/
- public void setProperty(Object key, Object value);
+ void setProperty(Object key, Object value);
/**
* Get a named property from the alignment.
* @param key
* @return value of property
*/
- public Object getProperty(Object key);
+ Object getProperty(Object key);
/**
* Get the property hashtable.
*
* @return hashtable of alignment properties (or null if none are defined)
*/
- public Hashtable getProperties();
+ Hashtable getProperties();
/**
* add a reference to a frame of aligned codons for this alignment
*
* @param codons
*/
- public void addCodonFrame(AlignedCodonFrame codons);
+ void addCodonFrame(AlignedCodonFrame codons);
/**
* remove a particular codon frame reference from this alignment
* @param codons
* @return true if codon frame was removed.
*/
- public boolean removeCodonFrame(AlignedCodonFrame codons);
+ boolean removeCodonFrame(AlignedCodonFrame codons);
/**
* get all codon frames associated with this alignment
*
* @return
*/
- public AlignedCodonFrame[] getCodonFrames();
-
- /**
- * get a particular codon frame
- *
- * @param index
- * @return
- */
- public AlignedCodonFrame getCodonFrame(int index);
+ Set<AlignedCodonFrame> getCodonFrames();
/**
* get codon frames involving sequenceI
*/
- public AlignedCodonFrame[] getCodonFrame(SequenceI seq);
+ List<AlignedCodonFrame> getCodonFrame(SequenceI seq);
/**
* find sequence with given name in alignment
* tried
* @return matched sequence or null
*/
- public SequenceI findName(String token, boolean b);
+ SequenceI findName(String token, boolean b);
/**
* find next sequence with given name in alignment starting after a given
* tried
* @return matched sequence or null
*/
- public SequenceI findName(SequenceI startAfter, String token, boolean b);
+ SequenceI findName(SequenceI startAfter, String token, boolean b);
/**
* find first sequence in alignment which is involved in the given search
* @param results
* @return -1 or index of sequence in alignment
*/
- public int findIndex(SearchResults results);
+ int findIndex(SearchResults results);
/**
* append sequences and annotation from another alignment object to this one.
* @param toappend
* - the alignment to be appended.
*/
- public void append(AlignmentI toappend);
+ void append(AlignmentI toappend);
/**
* Justify the sequences to the left or right by deleting and inserting gaps
* true if alignment padded to right, false to justify to left
* @return true if alignment was changed TODO: return undo object
*/
- public boolean justify(boolean right);
+ boolean justify(boolean right);
/**
* add given annotation row at given position (0 is start, -1 is end)
* @param consensus
* @param i
*/
- public void addAnnotation(AlignmentAnnotation consensus, int i);
+ void addAnnotation(AlignmentAnnotation consensus, int i);
/**
* search for or create a specific annotation row on the alignment
*
* @return existing annotation matching the given attributes
*/
- public AlignmentAnnotation findOrCreateAnnotation(String name,
+ AlignmentAnnotation findOrCreateAnnotation(String name,
String calcId, boolean autoCalc, SequenceI seqRef,
SequenceGroup groupRef);
* @param up
* @param i
*/
- public void moveSelectedSequencesByOne(SequenceGroup sg,
+ void moveSelectedSequencesByOne(SequenceGroup sg,
Map<SequenceI, SequenceCollectionI> map, boolean up);
/**
*
* @param alignmentAnnotation
*/
- public void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
+ void validateAnnotation(AlignmentAnnotation alignmentAnnotation);
/**
* Align this alignment the same as the given one. If both of the same type
* @param al
* @return
*/
- public int alignAs(AlignmentI al);
+ int alignAs(AlignmentI al);
/**
* Returns the set of distinct sequence names in the alignment.
*
* @return
*/
- public Set<String> getSequenceNames();
+ Set<String> getSequenceNames();
}
*/
package jalview.datamodel;
-import java.util.Vector;
+import java.util.List;
public class CigarArray extends CigarBase
{
* internal constructor function - called by CigarArray(AlignmentI, ...);
*
* @param alignment
- * @param columnSelection
+ * @param list
* - vector of visible regions as returned from
* columnSelection.getHiddenColumns()
* @param selectionGroup
*/
private void constructFromAlignment(AlignmentI alignment,
- Vector columnSelection, SequenceGroup selectionGroup)
+ List<int[]> list, SequenceGroup selectionGroup)
{
int[] _startend = _calcStartEndBounds(alignment, selectionGroup);
int start = _startend[1], end = _startend[2];
// now construct the CigarArray operations
- if (columnSelection != null)
+ if (list != null)
{
int[] region;
int hideStart, hideEnd;
int last = start;
- for (int j = 0; last < end & j < columnSelection.size(); j++)
+ for (int j = 0; last < end & j < list.size(); j++)
{
- region = (int[]) columnSelection.elementAt(j);
+ region = list.get(j);
hideStart = region[0];
hideEnd = region[1];
// edit hidden regions to selection range
import jalview.util.ShiftList;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.List;
-import java.util.Vector;
/**
* NOTE: Columns are zero based.
*/
public class ColumnSelection
{
- Vector selected = new Vector();
+ /*
+ * Because autoboxing can convert int to Integer, have to be very careful
+ * using methods remove(int), remove(Integer) and set(int, Integer).
+ * Verification is in unit tests.
+ */
+ List<Integer> selected = new ArrayList<Integer>();
- // Vector of int [] {startCol, endCol}
- Vector hiddenColumns;
+ /*
+ * List of {startCol, endCol} hidden column ranges
+ */
+ List<int[]> hiddenColumns;
/**
* Add a column to the selection
Integer column = new Integer(col);
if (!selected.contains(column))
{
- selected.addElement(column);
+ selected.add(column);
}
}
*/
public void clear()
{
- selected.removeAllElements();
+ selected.clear();
}
/**
- * removes col from selection
+ * Removes column 'col' from selection (NOT the col'th item).
*
* @param col
* index of column to be removed
*/
public void removeElement(int col)
{
- Integer colInt = new Integer(col);
-
- if (selected.contains(colInt))
- {
- selected.removeElement(colInt);
- }
+ selected.remove(new Integer(col));
}
/**
colInt = new Integer(i);
if (selected.contains(colInt))
{
- selected.removeElement(colInt);
+ selected.remove(colInt);
}
}
}
/**
*
- * @return Vector containing selected columns as Integers
+ * @return list containing selected columns as Integers
*/
- public Vector getSelected()
+ public List<Integer> getSelected()
{
return selected;
}
*/
public int columnAt(int i)
{
- return ((Integer) selected.elementAt(i)).intValue();
+ // autoboxing Integer -> int
+ return selected.get(i);
}
/**
*/
public int getMin()
{
- int min = 1000000000;
+ int min = Integer.MAX_VALUE;
for (int i = 0; i < selected.size(); i++)
{
if (temp >= start)
{
- selected.setElementAt(new Integer(temp - change), i);
+ // i = index here!
+ selected.set(i, new Integer(temp - change));
}
}
int hSize = hiddenColumns.size();
for (int i = 0; i < hSize; i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
if (region[0] > start && start + change > region[1])
{
deletedHiddenColumns.add(region);
- hiddenColumns.removeElementAt(i);
+ hiddenColumns.remove(i);
i--;
hSize--;
continue;
if (temp >= start)
{
- selected.setElementAt(new Integer(temp - change), i);
+ // i is index position in list here!
+ selected.set(i, new Integer(temp - change));
}
}
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
if (region[0] >= start)
{
region[0] -= change;
}
if (region[1] < region[0])
{
- hiddenColumns.removeElementAt(i--);
+ hiddenColumns.remove(i--);
}
if (region[0] < 0)
{
if (shiftrecord != null)
{
- Vector shifts = shiftrecord.shifts;
+ List<int[]> shifts = shiftrecord.getShifts();
if (shifts != null && shifts.size() > 0)
{
int shifted = 0;
for (int i = 0, j = shifts.size(); i < j; i++)
{
- int[] sh = (int[]) shifts.elementAt(i);
+ int[] sh = shifts.get(i);
// compensateForEdit(shifted+sh[0], sh[1]);
compensateForDelEdits(shifted + sh[0], sh[1]);
shifted -= sh[1];
* removes intersection of position,length ranges in deletions from the
* start,end regions marked in intervals.
*
- * @param deletions
- * @param intervals
+ * @param shifts
+ * @param hiddenColumns2
* @return
*/
- private boolean pruneIntervalVector(Vector deletions, Vector intervals)
+ private boolean pruneIntervalVector(List<int[]> shifts,
+ List<int[]> hiddenColumns2)
{
boolean pruned = false;
- int i = 0, j = intervals.size() - 1, s = 0, t = deletions.size() - 1;
- int hr[] = (int[]) intervals.elementAt(i);
- int sr[] = (int[]) deletions.elementAt(s);
+ int i = 0, j = hiddenColumns2.size() - 1, s = 0, t = shifts.size() - 1;
+ int hr[] = hiddenColumns2.get(i);
+ int sr[] = shifts.get(s);
while (i <= j && s <= t)
{
boolean trailinghn = hr[1] >= sr[0];
{
if (i < j)
{
- hr = (int[]) intervals.elementAt(++i);
+ hr = hiddenColumns2.get(++i);
}
else
{
{ // leadinghc disjoint or not a deletion
if (s < t)
{
- sr = (int[]) deletions.elementAt(++s);
+ sr = shifts.get(++s);
}
else
{
{
if (trailinghc)
{ // deleted hidden region.
- intervals.removeElementAt(i);
+ hiddenColumns2.remove(i);
pruned = true;
j--;
if (i <= j)
{
- hr = (int[]) intervals.elementAt(i);
+ hr = hiddenColumns2.remove(i);
}
continue;
}
// sr contained in hr
if (s < t)
{
- sr = (int[]) deletions.elementAt(++s);
+ sr = shifts.get(++s);
}
else
{
// operations.
}
- private boolean pruneColumnList(Vector deletion, Vector list)
+ private boolean pruneColumnList(List<int[]> shifts, List<Integer> list)
{
- int s = 0, t = deletion.size();
- int[] sr = (int[]) list.elementAt(s++);
+ int s = 0, t = shifts.size();
+ int[] sr = shifts.get(s++);
boolean pruned = false;
int i = 0, j = list.size();
while (i < j && s <= t)
{
- int c = ((Integer) list.elementAt(i++)).intValue();
+ int c = list.get(i++);
if (sr[0] <= c)
{
if (sr[1] + sr[0] >= c)
- { // sr[1] -ve means inseriton.
- list.removeElementAt(--i);
+ { // sr[1] -ve means insertion.
+ // remove the (i-1)'th element
+ list.remove(--i);
j--;
}
else
{
if (s < t)
{
- sr = (int[]) deletion.elementAt(s);
+ sr = shifts.get(s);
}
s++;
}
{
if (deletions != null)
{
- Vector shifts = deletions.shifts;
+ List<int[]> shifts = deletions.getShifts();
if (shifts != null && shifts.size() > 0)
{
// delete any intervals intersecting.
}
/**
- * This Method is used to return all the HiddenColumn regions less than the
+ * This method is used to return all the HiddenColumn regions less than the
* given index.
*
* @param end
* int
* @return Vector
*/
- public Vector getHiddenColumns()
+ public List<int[]> getHiddenColumns()
{
return hiddenColumns;
}
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
if (result >= region[0])
{
result += region[1] - region[0] + 1;
int[] region;
do
{
- region = (int[]) hiddenColumns.elementAt(index++);
+ region = hiddenColumns.get(index++);
if (hiddenColumn > region[1])
{
result -= region[1] + 1 - region[0];
int gaps = 0;
do
{
- int[] region = (int[]) hiddenColumns.elementAt(index);
+ int[] region = hiddenColumns.get(index);
if (hiddenRegion == 0)
{
return region[0];
int index = 0;
do
{
- int[] region = (int[]) hiddenColumns.elementAt(index);
+ int[] region = hiddenColumns.get(index);
if (alPos < region[0])
{
return region[0];
int index = hiddenColumns.size() - 1;
do
{
- int[] region = (int[]) hiddenColumns.elementAt(index);
+ int[] region = hiddenColumns.get(index);
if (alPos > region[1])
{
return region[1];
{
while (size() > 0)
{
- int column = ((Integer) getSelected().firstElement()).intValue();
+ int column = getSelected().get(0).intValue();
hideColumns(column);
}
{
if (hiddenColumns == null)
{
- hiddenColumns = new Vector();
+ hiddenColumns = new ArrayList<int[]>();
}
boolean added = false;
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
if (start <= region[1] && end >= region[0])
{
- hiddenColumns.removeElementAt(i);
+ hiddenColumns.remove(i);
overlap = true;
break;
}
else if (end < region[0] && start < region[0])
{
- hiddenColumns.insertElementAt(new int[]
- { start, end }, i);
+ hiddenColumns.add(i, new int[]
+ { start, end });
added = true;
break;
}
}
else if (!added)
{
- hiddenColumns.addElement(new int[]
+ hiddenColumns.add(new int[]
{ start, end });
}
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
for (int j = region[0]; j < region[1] + 1; j++)
{
addElement(j);
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
if (res == region[0])
{
for (int j = region[0]; j < region[1] + 1; j++)
addElement(j);
}
- hiddenColumns.removeElement(region);
+ hiddenColumns.remove(region);
break;
}
}
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.get(i);
if (column >= region[0] && column <= region[1])
{
return false;
{
if (copy.selected != null)
{
- selected = new Vector();
+ selected = new ArrayList<Integer>();
for (int i = 0, j = copy.selected.size(); i < j; i++)
{
- selected.addElement(copy.selected.elementAt(i));
+ selected.add(copy.selected.get(i));
}
}
if (copy.hiddenColumns != null)
{
- hiddenColumns = new Vector(copy.hiddenColumns.size());
+ hiddenColumns = new ArrayList<int[]>(copy.hiddenColumns.size());
for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)
{
int[] rh, cp;
- rh = (int[]) copy.hiddenColumns.elementAt(i);
+ rh = copy.hiddenColumns.get(i);
if (rh != null)
{
cp = new int[rh.length];
System.arraycopy(rh, 0, cp, 0, rh.length);
- hiddenColumns.addElement(cp);
+ hiddenColumns.add(cp);
}
}
}
for (i = 0; i < iSize; i++)
{
StringBuffer visibleSeq = new StringBuffer();
- Vector regions = getHiddenColumns();
+ List<int[]> regions = getHiddenColumns();
int blockStart = start, blockEnd = end;
- int[] region;
int hideStart, hideEnd;
- for (int j = 0; j < regions.size(); j++)
+ for (int[] region : regions)
{
- region = (int[]) regions.elementAt(j);
hideStart = region[0];
hideEnd = region[1];
{
if (hiddenColumns != null && hiddenColumns.size() > 0)
{
- Vector visiblecontigs = new Vector();
- Vector regions = getHiddenColumns();
+ List<int[]> visiblecontigs = new ArrayList<int[]>();
+ List<int[]> regions = getHiddenColumns();
int vstart = start;
int[] region;
for (int j = 0; vstart < end && j < regions.size(); j++)
{
- region = (int[]) regions.elementAt(j);
+ region = regions.get(j);
hideStart = region[0];
hideEnd = region[1];
}
if (hideStart > vstart)
{
- visiblecontigs.addElement(new int[]
+ visiblecontigs.add(new int[]
{ vstart, hideStart - 1 });
}
vstart = hideEnd + 1;
if (vstart < end)
{
- visiblecontigs.addElement(new int[]
+ visiblecontigs.add(new int[]
{ vstart, end - 1 });
}
int[] vcontigs = new int[visiblecontigs.size() * 2];
for (int i = 0, j = visiblecontigs.size(); i < j; i++)
{
- int[] vc = (int[]) visiblecontigs.elementAt(i);
- visiblecontigs.setElementAt(null, i);
+ int[] vc = visiblecontigs.get(i);
+ visiblecontigs.set(i, null);
vcontigs[i * 2] = vc[0];
vcontigs[i * 2 + 1] = vc[1];
}
- visiblecontigs.removeAllElements();
+ visiblecontigs.clear();
return vcontigs;
}
else
if (hiddenColumns != null && hiddenColumns.size() > 0)
{
// then mangle the alignmentAnnotation annotation array
- Vector annels = new Vector();
+ List<Annotation[]> annels = new ArrayList<Annotation[]>();
Annotation[] els = null;
- Vector regions = getHiddenColumns();
+ List<int[]> regions = getHiddenColumns();
int blockStart = start, blockEnd = end;
- int[] region;
int hideStart, hideEnd, w = 0;
- for (int j = 0; j < regions.size(); j++)
+ for (int[] region : regions)
{
- region = (int[]) regions.elementAt(j);
hideStart = region[0];
hideEnd = region[1];
break;
}
- annels.addElement(els = new Annotation[blockEnd - blockStart]);
+ annels.add(els = new Annotation[blockEnd - blockStart]);
System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
0, els.length);
w += els.length;
if (end > blockStart)
{
- annels.addElement(els = new Annotation[end - blockStart + 1]);
+ annels.add(els = new Annotation[end - blockStart + 1]);
if ((els.length + blockStart) <= alignmentAnnotation.annotations.length)
{
// copy just the visible segment of the annotation row
{
return;
}
- Enumeration e = annels.elements();
- alignmentAnnotation.annotations = new Annotation[w];
- w = 0;
- while (e.hasMoreElements())
+ for (Annotation[] chnk : annels)
{
- Annotation[] chnk = (Annotation[]) e.nextElement();
System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
chnk.length);
w += chnk.length;
{
if (colsel != null && colsel.size() > 0)
{
- Enumeration e = colsel.getSelected().elements();
- while (e.hasMoreElements())
+ for (Integer eo : colsel.getSelected())
{
- Object eo = e.nextElement();
- if (hiddenColumns != null && isVisible(((Integer) eo).intValue()))
+ if (hiddenColumns != null && isVisible(eo))
{
if (!selected.contains(eo))
{
- selected.addElement(eo);
+ selected.add(eo);
}
}
}
*/
public void setElementsFrom(ColumnSelection colsel)
{
- selected = new Vector();
+ selected = new ArrayList<Integer>();
if (colsel.selected != null && colsel.selected.size() > 0)
{
if (hiddenColumns != null && hiddenColumns.size() > 0)
{
// only select visible columns in this columns selection
- selected = new Vector();
+ selected = new ArrayList<Integer>();
addElementsFrom(colsel);
}
else
{
// add everything regardless
- Enumeration en = colsel.selected.elements();
- while (en.hasMoreElements())
+ for (Integer e : colsel.getSelected())
{
- selected.addElement(en.nextElement());
+ selected.add(e);
}
}
}
{
if (viscontigs[v] > spos)
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder(64);
for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
{
sb.append(gc);
import java.util.ArrayList;
import java.util.List;
+/**
+ * Holds a list of search result matches, where each match is a contiguous
+ * stretch of a single sequence.
+ *
+ * @author gmcarstairs
+ *
+ */
public class SearchResults
{
private List<Match> matches = new ArrayList<Match>();
+ public class Match
+ {
+ SequenceI sequence;
+
+ int start;
+
+ int end;
+
+ public Match(SequenceI seq, int start, int end)
+ {
+ sequence = seq;
+ this.start = start;
+ this.end = end;
+ }
+
+ public SequenceI getSequence()
+ {
+ return sequence;
+ }
+
+ public int getStart()
+ {
+ return start;
+ }
+
+ public int getEnd()
+ {
+ return end;
+ }
+ }
+
/**
* This method replaces the old search results which merely held an alignment
* index of search matches. This broke when sequences were moved around the
return matches.get(index).sequence;
}
- public int getResultStart(int index)
- {
- return matches.get(index).start;
- }
-
- public int getResultEnd(int index)
+ /**
+ * Returns the start position of the i'th match in the search results.
+ *
+ * @param i
+ * @return
+ */
+ public int getResultStart(int i)
{
- return matches.get(index).end;
+ return matches.get(i).start;
}
- class Match
+ /**
+ * Returns the end position of the i'th match in the search results.
+ *
+ * @param i
+ * @return
+ */
+ public int getResultEnd(int i)
{
- SequenceI sequence;
-
- int start;
-
- int end;
-
- public Match(SequenceI seq, int start, int end)
- {
- sequence = seq;
- this.start = start;
- this.end = end;
- }
+ return matches.get(i).end;
}
/**
{
return matches.isEmpty();
}
+
+ /**
+ * Returns the list of matches.
+ *
+ * @return
+ */
+ public List<Match> getResults()
+ {
+ return matches;
+ }
}
*/
public int[] gapMap()
{
- String seq = jalview.analysis.AlignSeq.extractGaps(
- jalview.util.Comparison.GapChars, new String(sequence));
- int[] map = new int[seq.length()];
+ int[] map = new int[sequence.length];
int j = 0;
int p = 0;
j++;
}
- return map;
+ int[] compact = new int[p];
+ System.arraycopy(map, 0, compact, 0, p);
+ return compact;
}
/*
public String getDescription();
/**
- * Return the alignment column for a sequence position * Return the alignment
- * position for a sequence position
+ * Return the alignment column for a sequence position
*
* @param pos
* lying from start to end
import jalview.schemes.ZappoColourScheme;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.jabaws2.Jws2Instance;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
+import java.util.Set;
import java.util.Vector;
import javax.swing.JButton;
reload.setEnabled(true);
}
+ /**
+ * Add a KeyListener with handlers for various KeyPressed and KeyReleased
+ * events
+ */
void addKeyListener()
{
addKeyListener(new KeyAdapter()
// TODO: execute command before adding to redo list / broadcasting?
command.undoCommand(getViewAlignments());
- AlignViewport originalSource = getOriginatingSource(command);
+ AlignmentViewport originalSource = getOriginatingSource(command);
updateEditMenuBar();
if (originalSource != null)
viewport.addToHistoryList(command);
command.doCommand(getViewAlignments());
- AlignViewport originalSource = getOriginatingSource(command);
+ AlignmentViewport originalSource = getOriginatingSource(command);
updateEditMenuBar();
if (originalSource != null)
}
}
- AlignViewport getOriginatingSource(CommandI command)
+ AlignmentViewport getOriginatingSource(CommandI command)
{
- AlignViewport originalSource = null;
+ AlignmentViewport originalSource = null;
// For sequence removal and addition, we need to fire
// the property change event FROM the viewport where the
// original alignment was altered
viewport.getHiddenRepSequences(), up);
alignPanel.paintAlignment(true);
- final AlignViewportI slave = viewport.getSlave();
- if (slave != null)
+ final AlignViewportI peer = viewport.getCodingComplement();
+ if (peer != null)
{
- final SequenceGroup selectionGroup = viewport.getSlave()
- .getSelectionGroup();
+ final SequenceGroup selectionGroup = peer.getSelectionGroup();
if (selectionGroup != null)
{
- viewport.getSlave()
- .getAlignment()
- .moveSelectedSequencesByOne(
- viewport.getSlave().getSelectionGroup(),
- viewport.getSlave().getHiddenRepSequences(), up);
+ peer.getAlignment().moveSelectedSequencesByOne(
+ peer.getSelectionGroup(), peer.getHiddenRepSequences(), up);
+ ((AlignViewport) peer).getAlignPanel().paintAlignment(true);
}
}
}
synchronized void slideSequences(boolean right, int size)
{
- List<SequenceI> sg = new Vector();
+ List<SequenceI> sg = new ArrayList<SequenceI>();
if (viewport.cursorMode)
{
sg.add(viewport.getAlignment().getSequenceAt(
return;
}
- Vector invertGroup = new Vector();
+ List<SequenceI> invertGroup = new ArrayList<SequenceI>();
- for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
+ for (SequenceI seq : viewport.getAlignment().getSequences())
{
- if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
+ if (!sg.contains(seq))
{
- invertGroup.add(viewport.getAlignment().getSequenceAt(i));
+ invertGroup.add(seq);
}
}
SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
for (int i = 0; i < invertGroup.size(); i++)
{
- seqs2[i] = (SequenceI) invertGroup.elementAt(i);
+ seqs2[i] = invertGroup.get(i);
}
SlideSequencesCommand ssc;
for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
.size(); i++)
{
- int[] region = (int[]) viewport.getColumnSelection()
- .getHiddenColumns().elementAt(i);
+ int[] region = viewport.getColumnSelection()
+ .getHiddenColumns().get(i);
if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
{
hiddenColumns.addElement(new int[]
Desktop.jalviewClipboard = new Object[]
{ seqs, viewport.getAlignment().getDataset(), hiddenColumns };
statusBar.setText(MessageManager.formatMessage(
- "label.copied_sequences_to_clipboard", new String[]
+ "label.copied_sequences_to_clipboard", new Object[]
{ Integer.valueOf(seqs.length).toString() }));
}
.getSequences());
}
- // else
- {
- // if (justifySeqs>0)
- {
- // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
- }
- }
-
- // }
-
/**
* DOCUMENT ME!
*
sprods[s].updatePDBIds();
}
Alignment al = new Alignment(sprods);
- AlignedCodonFrame[] cf = prods.getCodonFrames();
+ Set<AlignedCodonFrame> cf = prods.getCodonFrames();
al.setDataset(ds);
- for (int s = 0; cf != null && s < cf.length; s++)
+ for (AlignedCodonFrame acf : cf)
{
- al.addCodonFrame(cf[s]);
- cf[s] = null;
+ al.addCodonFrame(acf);
}
AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
DEFAULT_HEIGHT);
*
* @param av
*/
- public boolean closeView(AlignViewport av)
+ public boolean closeView(AlignmentViewport av)
{
if (viewport == av)
{
protected void viewAsCdna_actionPerformed()
{
final AlignmentI alignment = getViewport().getAlignment();
- AlignedCodonFrame[] mappings = alignment.getCodonFrames();
+ Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
if (mappings == null)
{
return;
StructureSelectionManager ssm, VamsasSource source)
{
/*
- * ...work in progress... do nothing unless we are a 'slave' of the source
- * May replace this with direct calls not via SSM.
+ * ...work in progress... do nothing unless we are a 'complement' of the
+ * source May replace this with direct calls not via SSM.
*/
if (source instanceof AlignViewportI
- && ((AlignViewportI) source).getSlave() == this)
+ && ((AlignViewportI) source).getCodingComplement() == this)
{
// ok to continue;
}
AlignFrame.DEFAULT_HEIGHT);
/*
- * Set the cDNA to list for edits on the protein.
+ * Set the frames to list for each other's edit and sort commands.
*/
ssm.addCommandListener(cdnaFrame.getViewport());
+ ssm.addCommandListener(proteinFrame.getViewport());
/*
- * cDNA is 'slaved' to edits, selection, sorting, show/hide on protein
+ * cDNA view will mirror edits, selection, sorting, show/hide on protein
*/
- proteinFrame.getViewport().setSlave(cdnaFrame.getViewport());
+ proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
}
return true;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.ColourSchemeI;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import java.awt.BorderLayout;
import java.awt.Color;
{
JInternalFrame frame;
- AlignViewport av;
+ AlignmentViewport av;
AlignmentPanel ap;
*/
boolean sliderDragging = false;
- public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
+ public AnnotationColourChooser(AlignmentViewport av, final AlignmentPanel ap)
{
oldcs = av.getGlobalColourScheme();
if (av.getAlignment().getGroups() != null)
hiddenColumns = new Vector();
for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
{
- int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
- .elementAt(i);
+ int[] region = av.getColumnSelection().getHiddenColumns().get(i);
hiddenColumns.addElement(new int[]
{ region[0], region[1] });
import jalview.io.*;
import jalview.jbgui.*;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
/**
* Cut'n'paste files into the desktop See JAL-1105
public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
{
- AlignViewport viewport;
+ AlignmentViewport viewport;
public CutAndPasteHtmlTransfer()
{
/**
* DOCUMENT ME!
*/
- public void setForInput(AlignViewport viewport)
+ public void setForInput(AlignmentViewport viewport)
{
this.viewport = viewport;
if (viewport != null)
import jalview.structure.StructureSelectionManager;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.ParamManager;
import java.awt.BorderLayout;
return;
}
- AlignViewport source = null, target = null;
+ AlignmentViewport source = null, target = null;
if (frames[0] instanceof AlignFrame)
{
source = ((AlignFrame) frames[0]).getCurrentView();
public static int getViewCount(String alignmentId)
{
- AlignViewport[] aps = getViewports(alignmentId);
+ AlignmentViewport[] aps = getViewports(alignmentId);
return (aps == null) ? 0 : aps.length;
}
* unique alignment id
* @return all viewports on the alignment bound to sequenceSetId
*/
- public static AlignViewport[] getViewports(String sequenceSetId)
+ public static AlignmentViewport[] getViewports(String sequenceSetId)
{
Vector viewp = new Vector();
if (desktop != null)
}
if (viewp.size() > 0)
{
- AlignViewport[] vp = new AlignViewport[viewp.size()];
+ AlignmentViewport[] vp = new AlignmentViewport[viewp.size()];
viewp.copyInto(vp);
return vp;
}
* @param av
* @return alignFrame for av
*/
- public static AlignFrame getAlignFrameFor(AlignViewport av)
+ public static AlignFrame getAlignFrameFor(AlignmentViewport av)
{
if (desktop != null)
{
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.GraduatedColor;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import jalview.ws.dbsources.das.api.jalviewSourceI;
import java.awt.BorderLayout;
{
SequenceI[] dataset, seqs;
int iSize;
- AlignViewport vp = af.getViewport();
+ AlignmentViewport vp = af.getViewport();
if (vp.getSelectionGroup() != null
&& vp.getSelectionGroup().getSize() > 0)
{
{
selectSeq(seq);
}
+ // TODO is this addition ok here?
+ av.isSelectionGroupChanged(true);
+
alignPanel.paintAlignment(true);
}
jal = av.getAlignment();
}
// SAVE MAPPINGS
- if (jal.getCodonFrames() != null && jal.getCodonFrames().length > 0)
+ Set<AlignedCodonFrame> jac = jal.getCodonFrames();
+ if (jac != null)
{
- jalview.datamodel.AlignedCodonFrame[] jac = jal.getCodonFrames();
- for (int i = 0; i < jac.length; i++)
+ for (AlignedCodonFrame acf : jac)
{
AlcodonFrame alc = new AlcodonFrame();
vamsasSet.addAlcodonFrame(alc);
- if (jac[i].getProtMappings() != null
- && jac[i].getProtMappings().length > 0)
+ if (acf.getProtMappings() != null
+ && acf.getProtMappings().length > 0)
{
- SequenceI[] dnas = jac[i].getdnaSeqs();
- jalview.datamodel.Mapping[] pmaps = jac[i].getProtMappings();
+ SequenceI[] dnas = acf.getdnaSeqs();
+ jalview.datamodel.Mapping[] pmaps = acf.getProtMappings();
for (int m = 0; m < pmaps.length; m++)
{
AlcodMap alcmap = new AlcodMap();
for (int c = 0; c < av.getColumnSelection().getHiddenColumns()
.size(); c++)
{
- int[] region = (int[]) av.getColumnSelection()
- .getHiddenColumns().elementAt(c);
+ int[] region = av.getColumnSelection().getHiddenColumns()
+ .get(c);
HiddenColumns hc = new HiddenColumns();
hc.setStart(region[0]);
hc.setEnd(region[1]);
import jalview.jbgui.GPCAPanel;
import jalview.schemes.ResidueProperties;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.PCAModel;
import java.awt.BorderLayout;
AlignmentPanel ap;
- AlignViewport av;
+ AlignmentViewport av;
PCAModel pcaModel;
import jalview.datamodel.SequenceI;
import jalview.jbgui.GPairwiseAlignPanel;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import java.awt.event.ActionEvent;
import java.util.Vector;
public class PairwiseAlignPanel extends GPairwiseAlignPanel
{
- AlignViewport av;
+ AlignmentViewport av;
Vector sequences;
* @param av
* DOCUMENT ME!
*/
- public PairwiseAlignPanel(AlignViewport av)
+ public PairwiseAlignPanel(AlignmentViewport av)
{
super();
this.av = av;
import jalview.datamodel.*;
import jalview.math.*;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
/**
* DOCUMENT ME!
float scalefactor = 1;
- AlignViewport av;
+ AlignmentViewport av;
AlignmentPanel ap;
*/
package jalview.gui;
-import java.awt.*;
-import java.awt.event.*;
-
-import javax.swing.*;
-
-import jalview.datamodel.*;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.SwingUtilities;
+import javax.swing.ToolTipManager;
+
/**
* DOCUMENT ME!
*
reveal = null;
for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
{
- int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
- .elementAt(i);
+ int[] region = av.getColumnSelection().getHiddenColumns().get(i);
if (res + 1 == region[0] || res - 1 == region[1])
{
reveal = region;
}
gg.drawLine(
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + 2,
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + (fm.getDescent() * 2));
}
else
{
gg.drawLine(
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + fm.getDescent(),
- (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+ ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
y + (fm.getDescent() * 2));
}
}
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.image.BufferedImage;
+import java.util.List;
import javax.swing.JComponent;
}
else
{
- java.util.Vector regions = av.getColumnSelection().getHiddenColumns();
+ List<int[]> regions = av.getColumnSelection().getHiddenColumns();
int screenY = 0;
int blockStart = startRes;
int blockEnd = endRes;
- for (int i = 0; regions != null && i < regions.size(); i++)
+ for (int[] region : regions)
{
- int[] region = (int[]) regions.elementAt(i);
int hideStart = region[0];
int hideEnd = region[1];
import jalview.commands.EditCommand;
import jalview.commands.EditCommand.Action;
import jalview.commands.EditCommand.Edit;
-import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SearchResults;
import jalview.datamodel.Sequence;
import jalview.structure.StructureSelectionManager;
import jalview.structure.VamsasSource;
import jalview.util.Comparison;
+import jalview.util.MappingUtils;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import java.awt.BorderLayout;
import java.awt.Color;
// TODO: extend config options to allow user to control if selections may be
// shared between viewports.
boolean iSentTheSelection = (av == source
- || (source instanceof AlignViewport && ((AlignViewport) source)
+ || (source instanceof AlignViewport && ((AlignmentViewport) source)
.getSequenceSetId().equals(av.getSequenceSetId())));
if (iSentTheSelection || !av.followSelection)
{
}
/*
- * Check for selection in a view of which this one is a 'slave'.
+ * Check for selection in a view of which this one is a dna/protein
+ * complement.
*/
- if (selectionAsSlave(seqsel, colsel, source))
+ if (selectionFromTranslation(seqsel, colsel, source))
{
return;
}
}
/**
- * If this panel is a 'slave' of the selection source, tries to map the source
- * selection to a local one, and returns true. Else returns false.
+ * If this panel is a cdna/protein translation view of the selection source,
+ * tries to map the source selection to a local one, and returns true. Else
+ * returns false.
*
* @param seqsel
* @param colsel
* @param source
*/
- protected boolean selectionAsSlave(SequenceGroup seqsel,
+ protected boolean selectionFromTranslation(SequenceGroup seqsel,
ColumnSelection colsel, SelectionSource source)
{
if (!(source instanceof AlignViewportI)) {
return false;
}
final AlignViewportI sourceAv = (AlignViewportI) source;
- if (sourceAv.getSlave() != av)
+ if (sourceAv.getCodingComplement() != av && av.getCodingComplement() != sourceAv)
{
return false;
}
/*
- * Map sequence selection. Note the SequenceGroup holds aligned sequences,
- * the mappings hold dataset sequences.
+ * Map sequence selection
*/
- AlignedCodonFrame[] codonFrames = sourceAv.getAlignment()
- .getCodonFrames();
- SequenceGroup sg = new SequenceGroup();
- for (SequenceI selected : seqsel.getSequences())
- {
- for (AlignedCodonFrame acf : codonFrames)
- {
- SequenceI dnaSeq = acf.getDnaForAaSeq(selected);
- if (dnaSeq != null)
- {
- for (SequenceI seq : av.getAlignment().getSequences())
- {
- if (seq.getDatasetSequence() == dnaSeq)
- {
- sg.addSequence(seq, false);
- break;
- }
- }
- }
- }
- }
+ SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
av.setSelectionGroup(sg);
av.isSelectionGroupChanged(true);
- // ((AlignmentViewport) slave).firePropertyChange("alignment", null, slave
- // .getAlignment()
- // .getSequences());
/*
* Map column selection
*/
- // TODO
+ ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
+ av);
+ av.setColumnSelection(cs);
+ av.isColSelChanged(true);
- AlignmentPanel ap = av.getAlignPanel();
PaintRefresher.Refresh(this, av.getSequenceSetId());
return true;
import jalview.jbgui.GSplitFrame;
+import java.awt.Component;
+import java.awt.MouseInfo;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.util.Map.Entry;
+
+import javax.swing.AbstractAction;
import javax.swing.JComponent;
+import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
*/
protected void init()
{
- setSize(AlignFrame.DEFAULT_WIDTH, Desktop.instance.getHeight() - 10);
+ setSize(AlignFrame.DEFAULT_WIDTH, Desktop.instance.getHeight() - 20);
- /*
- * Add a listener to tidy up when the frame is closed.
- */
+ addCloseFrameListener();
+
+ addKeyListener();
+
+ addKeyBindings();
+
+ }
+
+ /**
+ * Add a listener to tidy up when the frame is closed.
+ */
+ protected void addCloseFrameListener()
+ {
addInternalFrameListener(new InternalFrameAdapter()
{
@Override
}
};
});
+ }
+
+ /**
+ * Add a key listener that delegates to whichever split component the mouse is
+ * in (or does nothing if neither).
+ */
+ protected void addKeyListener()
+ {
+ // TODO Key Bindings rather than KeyListener are recommended for Swing
+ addKeyListener(new KeyAdapter() {
+
+ @Override
+ public void keyPressed(KeyEvent e)
+ {
+ Component c = getComponentAtMouse();
+ if (c != null)
+ {
+ for (KeyListener kl : c.getKeyListeners())
+ {
+ kl.keyPressed(e);
+ }
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e)
+ {
+ Component c = getComponentAtMouse();
+ if (c != null)
+ {
+ for (KeyListener kl : c.getKeyListeners())
+ {
+ kl.keyReleased(e);
+ }
+ }
+ }
+
+ });
+ }
+ /**
+ * Returns the split pane component the mouse is in, or null if neither.
+ *
+ * @return
+ */
+ protected Component getComponentAtMouse()
+ {
+ Point loc = MouseInfo.getPointerInfo().getLocation();
+
+ if (isIn(loc, getTopComponent())) {
+ return getTopComponent();
+ }
+ else if (isIn(loc, getBottomComponent()))
+ {
+ return getBottomComponent();
+ }
+ return null;
}
+ private boolean isIn(Point loc, JComponent comp)
+ {
+ Point p = comp.getLocationOnScreen();
+ Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(), comp.getHeight());
+ return r.contains(loc);
+ }
+
+ /**
+ * Set key bindings (recommended for Swing over key accelerators).
+ */
+ private void addKeyBindings()
+ {
+ /*
+ * Bind Cmd-Alt/I (invert column selection)
+ */
+ // If AlignFrame exposed a Map of Action objects by key,
+ // we could delegate all key bindings with a single lookup
+ this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+ KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, Toolkit
+ .getDefaultToolkit().getMenuShortcutKeyMask()
+ | java.awt.event.KeyEvent.ALT_MASK, false),
+ "INV_SEQ_SEL");
+ this.getActionMap().put("INV_SEQ_SEL", new AbstractAction()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ Component c = getComponentAtMouse();
+ if (c instanceof AlignFrame)
+ {
+ ((AlignFrame) c).invertColSel_actionPerformed(null);
+ }
+ }
+ });
+ if (getTopComponent() instanceof AlignFrame)
+ {
+ for (Entry<KeyStroke, JMenuItem> acc : ((AlignFrame) getTopComponent())
+ .getAccelerators().entrySet())
+ {
+
+ final KeyStroke ks = acc.getKey();
+ this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, ks);
+ this.getActionMap().put(ks, new AbstractAction()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ Component c = getComponentAtMouse();
+ if (c instanceof AlignFrame)
+ {
+ ((AlignFrame) c).getAccelerators().get(ks)
+ .getActionListeners()[0].actionPerformed(null);
+ }
+ }
+ });
+ }
+ }
+ }
}
import jalview.analysis.Conservation;
import jalview.analysis.NJTree;
+import jalview.api.AlignViewportI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
aps[a].av.getAlignment().deleteAllGroups();
aps[a].av.clearSequenceColours();
}
- if (av.getSlave() != null)
+ if (av.getCodingComplement() != null)
{
- av.getSlave().setSelectionGroup(null);
- av.getSlave().getAlignment().deleteAllGroups();
- av.getSlave().clearSequenceColours();
+ av.getCodingComplement().setSelectionGroup(null);
+ av.getCodingComplement().getAlignment().deleteAllGroups();
+ av.getCodingComplement().clearSequenceColours();
}
colourGroups();
}
// TODO can we push all of the below into AlignViewportI?
av.getAlignment().addGroup(sg);
- if (av.getSlave() != null)
+ final AlignViewportI codingComplement = av.getCodingComplement();
+ if (codingComplement != null)
{
SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, av,
- av.getSlave());
+ codingComplement);
if (mappedGroup.getSequences().size() > 0)
{
- av.getSlave().getAlignment().addGroup(mappedGroup);
+ codingComplement.getAlignment().addGroup(mappedGroup);
for (SequenceI seq : mappedGroup.getSequences())
{
- av.getSlave().setSequenceColour(seq,
+ codingComplement.setSequenceColour(seq,
mappedGroup.getIdColour().brighter());
}
}
}
-
}
// notify the panel to redo any group specific stuff.
// to any Jmols listening in
}
- if (av.getSlave() != null)
+ if (av.getCodingComplement() != null)
{
- ((AlignViewport) av.getSlave()).getAlignPanel().updateAnnotation();
+ ((AlignViewport) av.getCodingComplement()).getAlignPanel().updateAnnotation();
/*
* idPanel. repaint ()
*/
import jalview.io.NewickFile;
import jalview.jbgui.GTreePanel;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import java.awt.Font;
import java.awt.Graphics;
return treeCanvas.av.getAlignment();
}
- public AlignViewport getViewPort()
+ public AlignmentViewport getViewPort()
{
return treeCanvas.av;
}
public CommandI sortAlignmentIn(AlignmentPanel ap)
{
- AlignViewport av = ap.av;
+ AlignmentViewport av = ap.av;
SequenceI[] oldOrder = av.getAlignment().getSequencesArray();
AlignmentSorter.sortByTree(av.getAlignment(), tree);
CommandI undo;
import jalview.structure.VamsasListener;
import jalview.structure.VamsasSource;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
-import java.util.Enumeration;
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.Iterator;
AlignmentI visal = null;
if (source instanceof AlignViewport)
{
- visal = ((AlignViewport) source).getAlignment();
+ visal = ((AlignmentViewport) source).getAlignment();
}
SelectionMessage sm = null;
if ((seqsel == null || seqsel.getSize() == 0)
{
// the empty selection.
sm = new SelectionMessage("jalview", new String[]
- { ((AlignViewport) source).getSequenceSetId() }, null,
+ { ((AlignmentViewport) source).getSequenceSetId() }, null,
true);
}
else
{
// gather selected columns outwith the sequence positions
// too
- Enumeration cols = colsel.getSelected().elements();
- while (cols.hasMoreElements())
+ for (int ival : colsel.getSelected())
{
- int ival = ((Integer) cols.nextElement()).intValue();
Pos p = new Pos();
p.setI(ival + 1);
range.addPos(p);
import jalview.io.vamsas.DatastoreRegistry;
import jalview.io.vamsas.Rangetype;
import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
import java.io.IOException;
import java.util.Enumeration;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.Vector;
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
-import uk.ac.vamsas.client.*;
-import uk.ac.vamsas.objects.core.*;
+import uk.ac.vamsas.client.IClientAppdata;
+import uk.ac.vamsas.client.IClientDocument;
+import uk.ac.vamsas.client.Vobject;
+import uk.ac.vamsas.client.VorbaId;
+import uk.ac.vamsas.objects.core.Alignment;
+import uk.ac.vamsas.objects.core.AlignmentSequence;
+import uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation;
+import uk.ac.vamsas.objects.core.AnnotationElement;
+import uk.ac.vamsas.objects.core.DataSet;
+import uk.ac.vamsas.objects.core.DataSetAnnotations;
+import uk.ac.vamsas.objects.core.DbRef;
+import uk.ac.vamsas.objects.core.Entry;
+import uk.ac.vamsas.objects.core.Glyph;
+import uk.ac.vamsas.objects.core.Local;
+import uk.ac.vamsas.objects.core.MapType;
+import uk.ac.vamsas.objects.core.Mapped;
+import uk.ac.vamsas.objects.core.Property;
+import uk.ac.vamsas.objects.core.Provenance;
+import uk.ac.vamsas.objects.core.RangeAnnotation;
+import uk.ac.vamsas.objects.core.RangeType;
+import uk.ac.vamsas.objects.core.Seg;
+import uk.ac.vamsas.objects.core.Sequence;
+import uk.ac.vamsas.objects.core.SequenceType;
+import uk.ac.vamsas.objects.core.VAMSAS;
import uk.ac.vamsas.objects.utils.Properties;
/*
* @return true if alignment associated with this view will be stored in
* document.
*/
- public boolean alignmentWillBeSkipped(AlignViewport av)
+ public boolean alignmentWillBeSkipped(AlignmentViewport av)
{
return (!av.getAlignment().isAligned());
}
- private void addToSkipList(AlignViewport av)
+ private void addToSkipList(AlignmentViewport av)
{
if (skipList == null)
{
an.addProperty(Properties.newProperty(THRESHOLD,
Properties.FLOATTYPE, "" + alan.getThreshold().value));
if (alan.getThreshold().label != null)
+ {
an.addProperty(Properties.newProperty(THRESHOLD + "Name",
Properties.STRINGTYPE, "" + alan.getThreshold().label));
+ }
}
((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
bindjvvobj(alan, an);
// sync,
// and if any contain more than one view, then remove the one generated by
// document update.
- AlignViewport views[], av = null;
+ AlignmentViewport views[], av = null;
AlignFrame af = null;
Iterator newviews = newAlignmentViews.iterator();
while (newviews.hasNext())
{
- av = (AlignViewport) newviews.next();
+ av = (AlignmentViewport) newviews.next();
af = Desktop.getAlignFrameFor(av);
// TODO implement this : af.getNumberOfViews
String seqsetidobj = av.getSequenceSetId();
// to the align frames.
boolean gathered = false;
String newviewid = null;
- AlignedCodonFrame[] mappings = av.getAlignment().getCodonFrames();
+ Set<AlignedCodonFrame> mappings = av.getAlignment()
+ .getCodonFrames();
for (int i = 0; i < views.length; i++)
{
if (views[i] != av)
{
// ensure sequence mappings from vamsas document view still
// active
- if (mappings != null && mappings.length > 0)
+ if (mappings != null)
{
jalview.structure.StructureSelectionManager
.getStructureSelectionManager(Desktop.instance)
uk.ac.vamsas.objects.core.Alignment alignment = dataset
.getAlignment(al);
// TODO check this handles multiple views properly
- AlignViewport av = findViewport(alignment);
+ AlignmentViewport av = findViewport(alignment);
jalview.datamodel.AlignmentI jal = null;
if (av != null)
return newAlignmentViews.size();
}
- public AlignViewport findViewport(Alignment alignment)
+ public AlignmentViewport findViewport(Alignment alignment)
{
- AlignViewport av = null;
- AlignViewport[] avs = Desktop
+ AlignmentViewport av = null;
+ AlignmentViewport[] avs = Desktop
.getViewports((String) getvObj2jv(alignment));
if (avs != null)
{
Cache.log.warn("Failed to parse threshold property");
}
if (val != null)
+ {
if (gl == null)
{
gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
{
gl.value = val.floatValue();
}
+ }
}
else if (props[p].getName().equalsIgnoreCase(THRESHOLD + "Name"))
{
if (gl == null)
+ {
gl = new GraphLine(0, "", java.awt.Color.black);
+ }
gl.label = props[p].getContent();
}
}
return vobj2jv;
}
- public void storeSequenceMappings(AlignViewport viewport, String title)
+ public void storeSequenceMappings(AlignmentViewport viewport, String title)
throws Exception
{
- AlignViewport av = viewport;
+ AlignmentViewport av = viewport;
try
{
jalview.datamodel.AlignmentI jal = av.getAlignment();
}
// Store any sequence mappings.
- if (av.getAlignment().getCodonFrames() != null
- && av.getAlignment().getCodonFrames().length > 0)
+ Set<AlignedCodonFrame> cframes = av.getAlignment().getCodonFrames();
+ if (cframes != null)
{
- jalview.datamodel.AlignedCodonFrame[] cframes = av.getAlignment()
- .getCodonFrames();
- for (int cf = 0; cf < cframes.length; cf++)
+ for (AlignedCodonFrame acf : cframes)
{
- if (cframes[cf].getdnaSeqs() != null
- && cframes[cf].getdnaSeqs().length > 0)
+ if (acf.getdnaSeqs() != null && acf.getdnaSeqs().length > 0)
{
- jalview.datamodel.SequenceI[] dmps = cframes[cf].getdnaSeqs();
- jalview.datamodel.Mapping[] mps = cframes[cf].getProtMappings();
+ jalview.datamodel.SequenceI[] dmps = acf.getdnaSeqs();
+ jalview.datamodel.Mapping[] mps = acf.getProtMappings();
for (int smp = 0; smp < mps.length; smp++)
{
uk.ac.vamsas.objects.core.SequenceType mfrom = (SequenceType) getjv2vObj(dmps[smp]);
package jalview.io.vamsas;
import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceI;
import jalview.gui.Desktop;
}
// create mapping storage object and make each dataset alignment reference
// it.
- jalview.datamodel.AlignmentI dsLoc = (jalview.datamodel.AlignmentI) getvObj2jv(sdloc
- .getV_parent());
- jalview.datamodel.AlignmentI dsMap = (jalview.datamodel.AlignmentI) getvObj2jv(sdmap
- .getV_parent());
- AlignedCodonFrame afc = new AlignedCodonFrame();
+ AlignmentI dsLoc = (AlignmentI) getvObj2jv(sdloc.getV_parent());
+ AlignmentI dsMap = (AlignmentI) getvObj2jv(sdmap.getV_parent());
+ AlignedCodonFrame acf = new AlignedCodonFrame();
if (dsLoc != null && dsLoc != dsMap)
{
- dsLoc.addCodonFrame(afc);
+ dsLoc.addCodonFrame(acf);
}
if (dsMap != null)
{
- dsMap.addCodonFrame(afc);
+ dsMap.addCodonFrame(acf);
}
// create and add the new mapping to (each) dataset's codonFrame
mapping = new jalview.util.MapList(mapping.getToRanges(),
mapping.getFromRanges(), mapping.getToRatio(),
mapping.getFromRatio());
- afc.addMap(to, from, mapping);
+ acf.addMap(to, from, mapping);
}
else
{
mapping = this.parsemapType(sequenceMapping, 3, 1); // correct sense
- afc.addMap(from, to, mapping);
+ acf.addMap(from, to, mapping);
}
}
else
{
mapping = this.parsemapType(sequenceMapping, 1, 1); // correct sense
- afc.addMap(from, to, mapping);
+ acf.addMap(from, to, mapping);
}
bindjvvobj(mapping, sequenceMapping);
jalview.structure.StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance).addMappings(
- new AlignedCodonFrame[]
- { afc });
+ .getStructureSelectionManager(Desktop.instance).addMapping(acf);
// Try to link up any conjugate database references in the two sequences
// matchConjugateDBRefs(from, to, mapping);
// Try to propagate any dbrefs across this mapping.
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.datamodel.SequenceNode;
-import jalview.gui.AlignViewport;
import jalview.gui.TreePanel;
import jalview.io.NewickFile;
import jalview.io.VamsasAppDatastore;
+import jalview.viewmodel.AlignmentViewport;
import uk.ac.vamsas.client.Vobject;
import uk.ac.vamsas.objects.core.AlignmentSequence;
import uk.ac.vamsas.objects.core.Entry;
*/
public Object[] recoverInputData(Provenance tp)
{
- AlignViewport javport = null;
+ AlignmentViewport javport = null;
jalview.datamodel.AlignmentI jal = null;
jalview.datamodel.CigarArray view = null;
for (int pe = 0; pe < tp.getEntryCount(); pe++)
return null;
}
- private AlignViewport getViewport(Vobject v_parent)
+ private AlignmentViewport getViewport(Vobject v_parent)
{
if (v_parent instanceof uk.ac.vamsas.objects.core.Alignment)
{
int d = 0, r = -1;
for (int i = 0; i < cols.length; i++)
{
- cols[i] = ""
- + (1 + ((Integer) colsel.getSelected().elementAt(i))
- .intValue());
+ cols[i] = "" + (1 + colsel.getSelected().get(i).intValue());
}
}
else
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.util.HashMap;
+import java.util.Map;
+import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTabbedPane;
+import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.MenuEvent;
private boolean showAutoCalculatedAbove = false;
+ private Map<KeyStroke, JMenuItem> accelerators = new HashMap<KeyStroke, JMenuItem>();
+
public GAlignFrame()
{
try
reload.setMnemonic('R');
}
+ // setKeyBindings();
+
if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
{
java.util.Enumeration userColours = jalview.gui.UserDefinedColours
}
+ /**
+ * Set key bindings (recommended for Swing over key accelerators).
+ */
+ private void setKeyBindings()
+ {
+ /*
+ * Experiment using Cmd-Alt/K (unmapped) as a synonym for Cmd-Alt/I (invert
+ * column selection)
+ */
+ this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
+ KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, Toolkit
+ .getDefaultToolkit().getMenuShortcutKeyMask()
+ | java.awt.event.KeyEvent.ALT_MASK, false),
+ "INV_SEQ_SEL");
+ this.getActionMap().put("INV_SEQ_SEL", new AbstractAction()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ invertColSel_actionPerformed(null);
+ }
+ });
+ }
+
public void setColourSelected(String defaultColour)
{
{
fileMenu.setText(MessageManager.getString("action.file"));
saveAs.setText(MessageManager.getString("action.save_as") + "...");
- saveAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
+ KeyStroke keyStroke = javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_S, Toolkit.getDefaultToolkit()
.getMenuShortcutKeyMask()
- | java.awt.event.KeyEvent.SHIFT_MASK, false));
+ | java.awt.event.KeyEvent.SHIFT_MASK, false);
+ saveAs.setAccelerator(keyStroke);
+ accelerators.put(keyStroke, saveAs);
saveAs.addActionListener(new ActionListener()
{
@Override
});
invertSequenceMenuItem.setText(MessageManager
.getString("action.invert_sequence_selection"));
- invertSequenceMenuItem.setAccelerator(javax.swing.KeyStroke
+ keyStroke = javax.swing.KeyStroke
.getKeyStroke(java.awt.event.KeyEvent.VK_I, Toolkit
- .getDefaultToolkit().getMenuShortcutKeyMask(), false));
+ .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+ invertSequenceMenuItem.setAccelerator(keyStroke);
+ accelerators.put(keyStroke, invertSequenceMenuItem);
invertSequenceMenuItem
.addActionListener(new java.awt.event.ActionListener()
{
{
this.annotationSortOrder = annotationSortOrder;
}
+
+ public Map<KeyStroke, JMenuItem> getAccelerators()
+ {
+ return this.accelerators;
+ }
}
/**
* Remove each of the given codonFrames from the stored set (if present).
*
- * @param codonFrames
+ * @param set
*/
- public void removeMappings(AlignedCodonFrame[] codonFrames)
+ public void removeMappings(Set<AlignedCodonFrame> set)
{
- if (codonFrames != null)
+ if (set != null)
{
- for (AlignedCodonFrame acf : codonFrames)
- {
- seqmappings.remove(acf);
- }
+ seqmappings.removeAll(set);
}
}
* Add each of the given codonFrames to the stored set (if not aready
* present).
*
- * @param codonFrames
+ * @param set
*/
- public void addMappings(AlignedCodonFrame[] codonFrames)
+ public void addMappings(Set<AlignedCodonFrame> set)
{
- if (codonFrames != null)
+ if (set != null)
{
- for (AlignedCodonFrame acf : codonFrames)
- {
- seqmappings.add(acf);
- }
+ seqmappings.addAll(set);
+ }
+ }
+
+ public void addMapping(AlignedCodonFrame acf)
+ {
+ if (acf != null)
+ {
+ seqmappings.add(acf);
}
}
*
* @param command
* @param undo
- * @param alignmentI
+ * @param mapTo
* @param gapChar
* @return
*/
- public CommandI mapCommand(CommandI command,
- boolean undo,
- final AlignmentI alignmentI, char gapChar)
+ public CommandI mapCommand(CommandI command, boolean undo,
+ final AlignmentI mapTo, char gapChar)
{
if (command instanceof EditCommand)
{
return MappingUtils.mapEditCommand((EditCommand) command, undo,
- alignmentI, gapChar,
- seqmappings);
+ mapTo, gapChar, seqmappings);
}
else if (command instanceof OrderCommand)
{
return MappingUtils.mapOrderCommand((OrderCommand) command, undo,
- alignmentI, seqmappings);
+ mapTo, seqmappings);
}
return null;
}
private static final int TO_UPPER_CASE = 'a' - 'A';
- public static final String GapChars = " .-";
+ private static final char GAP_SPACE = ' ';
+
+ private static final char GAP_DOT = '.';
+
+ private static final char GAP_DASH = '-';
+
+ public static final String GapChars = new String(new char[]
+ { GAP_SPACE, GAP_DOT, GAP_DASH });
/**
* DOCUMENT ME!
*/
public static final boolean isGap(char c)
{
- return (c == '-' || c == '.' || c == ' ') ? true : false;
+ return (c == GAP_DASH || c == GAP_DOT || c == GAP_SPACE) ? true : false;
}
/**
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentOrder;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResults.Match;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.gui.AlignViewport;
import java.util.ArrayList;
import java.util.HashMap;
*
* @param command
* @param undo
- * @param alignment
+ * @param mapTo
* @param gapChar
* @param mappings
* @return
*/
public static EditCommand mapEditCommand(EditCommand command,
- boolean undo, final AlignmentI alignment, char gapChar,
+ boolean undo, final AlignmentI mapTo, char gapChar,
Set<AlignedCodonFrame> mappings)
{
/*
+ * For now, only support mapping from protein edits to cDna
+ */
+ if (!mapTo.isNucleotide())
+ {
+ return null;
+ }
+
+ /*
* Cache a copy of the target sequences so we can mimic successive edits on
* them. This lets us compute mappings for all edits in the set.
*/
Map<SequenceI, SequenceI> targetCopies = new HashMap<SequenceI, SequenceI>();
- for (SequenceI seq : alignment.getSequences())
+ for (SequenceI seq : mapTo.getSequences())
{
SequenceI ds = seq.getDatasetSequence();
if (ds != null)
targetCopies.put(ds, copy);
}
}
-
+
/*
* Compute 'source' sequences as they were before applying edits:
*/
Map<SequenceI, SequenceI> originalSequences = command.priorState(undo);
-
+
EditCommand result = new EditCommand();
Iterator<Edit> edits = command.getEditIterator(!undo);
while (edits.hasNext())
if (edit.getAction() == Action.CUT
|| edit.getAction() == Action.PASTE)
{
- mapCutOrPaste(edit, undo, alignment.getSequences(), result,
- mappings);
+ mapCutOrPaste(edit, undo, mapTo.getSequences(), result, mappings);
}
else if (edit.getAction() == Action.INSERT_GAP
|| edit.getAction() == Action.DELETE_GAP)
{
mapInsertOrDelete(edit, undo, originalSequences,
- alignment.getSequences(),
- targetCopies, gapChar, result, mappings);
+ mapTo.getSequences(), targetCopies, gapChar, result,
+ mappings);
}
}
return result.getSize() > 0 ? result : null;
EditCommand result, Set<AlignedCodonFrame> mappings)
{
Action action = edit.getAction();
-
+
/*
* Invert sense of action if an Undo.
*/
}
final SequenceI actedOn = originalSequences.get(ds);
final int seqpos = actedOn.findPosition(editPos);
-
+
/*
* Determine all mappings from this position to mapped sequences.
*/
SearchResults sr = buildSearchResults(seq, seqpos, mappings);
-
+
if (!sr.isEmpty())
{
for (SequenceI targetSeq : targetSeqs)
{
final int ratio = 3; // TODO: compute this - how?
final int mappedCount = count * ratio;
-
+
/*
* Shift Delete start position left, as it acts on positions to its
* right.
Edit e = result.new Edit(action, new SequenceI[]
{ targetSeq }, mappedEditPos, mappedCount, gapChar);
result.addEdit(e);
-
+
/*
* and 'apply' the edit to our copy of its target sequence
*/
}
/**
- * Returns a (possibly empty) SequenceGroup containing any sequences the
+ * Returns a (possibly empty) SequenceGroup containing any sequences in the
* mapped viewport corresponding to the given group in the source viewport.
*
* @param sg
- * @param av
- * @param mapped
+ * @param mapFrom
+ * @param mapTo
* @return
*/
public static SequenceGroup mapSequenceGroup(SequenceGroup sg,
- AlignViewportI av, AlignViewportI mapped)
+ AlignViewportI mapFrom, AlignViewportI mapTo)
{
/*
- * Map sequence selection. Note the SequenceGroup holds aligned sequences,
- * the mappings hold dataset sequences.
+ * Note the SequenceGroup holds aligned sequences, the mappings hold dataset
+ * sequences.
*/
- AlignedCodonFrame[] codonFrames = av.getAlignment()
+ boolean targetIsNucleotide = mapTo.isNucleotide();
+ AlignViewportI protein = targetIsNucleotide ? mapFrom : mapTo;
+ Set<AlignedCodonFrame> codonFrames = protein.getAlignment()
.getCodonFrames();
/*
{
for (AlignedCodonFrame acf : codonFrames)
{
- SequenceI dnaSeq = acf.getDnaForAaSeq(selected);
- if (dnaSeq != null)
+ SequenceI mappedSequence = targetIsNucleotide ? acf
+ .getDnaForAaSeq(selected) : acf.getAaForDnaSeq(selected);
+ if (mappedSequence != null)
{
- for (SequenceI seq : mapped.getAlignment().getSequences())
+ for (SequenceI seq : mapTo.getAlignment().getSequences())
{
- if (seq.getDatasetSequence() == dnaSeq)
+ if (seq.getDatasetSequence() == mappedSequence)
{
mappedGroup.addSequence(seq, false);
break;
* @return
*/
public static CommandI mapOrderCommand(OrderCommand command,
- boolean undo, AlignmentI mapTo,
- Set<AlignedCodonFrame> mappings)
+ boolean undo, AlignmentI mapTo, Set<AlignedCodonFrame> mappings)
{
SequenceI[] sortOrder = command.getSequenceOrder(undo);
List<SequenceI> mappedOrder = new ArrayList<SequenceI>();
{
for (AlignedCodonFrame acf : mappings)
{
- SequenceI dnaSeq = acf.getDnaForAaSeq(seq);
- if (dnaSeq != null)
+ /*
+ * Try protein-to-Dna, failing that try dna-to-protein
+ */
+ SequenceI mappedSeq = acf.getDnaForAaSeq(seq);
+ if (mappedSeq == null)
+ {
+ mappedSeq = acf.getAaForDnaSeq(seq);
+ }
+ if (mappedSeq != null)
{
for (SequenceI seq2 : mapTo.getSequences())
{
- if (seq2.getDatasetSequence() == dnaSeq)
+ if (seq2.getDatasetSequence() == mappedSeq)
{
mappedOrder.add(seq2);
j++;
return result;
}
+ /**
+ * Returns a ColumnSelection in the 'mapTo' view which corresponds to the
+ * given selection in the 'mapFrom' view. We assume one is nucleotide, the
+ * other is protein (and holds the mappings from codons to protein residues).
+ *
+ * @param colsel
+ * @param mapFrom
+ * @param mapTo
+ * @return
+ */
+ public static ColumnSelection mapColumnSelection(ColumnSelection colsel,
+ AlignViewportI mapFrom, AlignViewport mapTo)
+ {
+ boolean targetIsNucleotide = mapTo.isNucleotide();
+ AlignViewportI protein = targetIsNucleotide ? mapFrom : mapTo;
+ Set<AlignedCodonFrame> codonFrames = protein.getAlignment()
+ .getCodonFrames();
+ ColumnSelection mappedColumns = new ColumnSelection();
+ char fromGapChar = mapFrom.getAlignment().getGapCharacter();
+
+ for (int col : colsel.getSelected())
+ {
+ int mappedToMin = Integer.MAX_VALUE;
+ int mappedToMax = Integer.MIN_VALUE;
+
+ /*
+ * For each sequence in the 'from' alignment
+ */
+ for (SequenceI fromSeq : mapFrom.getAlignment().getSequences())
+ {
+ /*
+ * Ignore gaps (unmapped anyway)
+ */
+ if (fromSeq.getCharAt(col) == fromGapChar)
+ {
+ continue;
+ }
+
+ /*
+ * Get the residue position and find the mapped position.
+ */
+ int residuePos = fromSeq.findPosition(col);
+ SearchResults sr = buildSearchResults(fromSeq, residuePos,
+ codonFrames);
+ for (Match m : sr.getResults())
+ {
+ int mappedStartResidue = m.getStart();
+ int mappedEndResidue = m.getEnd();
+ SequenceI mappedSeq = m.getSequence();
+
+ /*
+ * Locate the aligned sequence whose dataset is mappedSeq.
+ */
+ for (SequenceI toSeq : mapTo.getAlignment().getSequences())
+ {
+ if (toSeq.getDatasetSequence() == mappedSeq)
+ {
+ int mappedStartCol = toSeq.findIndex(mappedStartResidue);
+ int mappedEndCol = toSeq.findIndex(mappedEndResidue);
+ mappedToMin = Math.min(mappedToMin, mappedStartCol);
+ mappedToMax = Math.max(mappedToMax, mappedEndCol);
+ // System.out.println(fromSeq.getName() + " mapped to cols "
+ // + mappedStartCol + ":" + mappedEndCol);
+ }
+ }
+ }
+ }
+ /*
+ * Add mapped columns to mapped selection (converting base 1 to base 0)
+ */
+ for (int i = mappedToMin; i <= mappedToMax; i++)
+ {
+ mappedColumns.addElement(i - 1);
+ }
+ }
+ return mappedColumns;
+ }
+
}
*/
package jalview.util;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
/**
* ShiftList Simple way of mapping a linear series to a new linear range with
*/
public class ShiftList
{
- public Vector shifts;
+ private List<int[]> shifts;
public ShiftList()
{
- shifts = new Vector();
+ shifts = new ArrayList<int[]>();
}
/**
{
int sidx = 0;
int[] rshift = null;
- while (sidx < shifts.size()
- && (rshift = (int[]) shifts.elementAt(sidx))[0] < pos)
+ while (sidx < shifts.size() && (rshift = shifts.get(sidx))[0] < pos)
{
sidx++;
}
if (sidx == shifts.size())
{
- shifts.insertElementAt(new int[]
- { pos, shift }, sidx);
+ shifts.add(sidx, new int[]
+ { pos, shift });
}
else
{
int sidx = 0;
int rshift[];
while (sidx < shifts.size()
- && (rshift = ((int[]) shifts.elementAt(sidx++)))[0] <= pos)
+ && (rshift = (shifts.get(sidx++)))[0] <= pos)
{
shifted += rshift[1];
}
*/
public void clear()
{
- shifts.removeAllElements();
+ shifts.clear();
}
/**
{
for (int i = 0, j = shifts.size(); i < j; i++)
{
- int[] sh = (int[]) shifts.elementAt(i);
+ int[] sh = shifts.get(i);
if (sh != null)
{
- inverse.shifts.addElement(new int[]
+ inverse.shifts.add(new int[]
{ sh[0], -sh[1] });
}
}
}
/**
- * parse a 1d map of position 1<i<n to L<pos[i]<N such as that returned from
- * SequenceI.gapMap()
+ * parse a 1d map of position 1<i<n to L<pos[i]<N such as that
+ * returned from SequenceI.gapMap()
*
* @param gapMap
* @return shifts from map index to mapped position
}
return shiftList;
}
+
+ public List<int[]> getShifts()
+ {
+ return shifts;
+ }
}
import jalview.schemes.ColourSchemeI;
import jalview.schemes.PIDColourScheme;
import jalview.schemes.ResidueProperties;
+import jalview.util.MappingUtils;
import jalview.workers.AlignCalcManager;
import jalview.workers.ConsensusThread;
import jalview.workers.StrucConsensusThread;
public abstract class AlignmentViewport implements AlignViewportI
{
/*
- * A viewport that is a slave of (driven by) this one in some sense.
+ * A viewport that hosts the cDna view of this (protein), or vice versa (if
+ * set).
*/
- AlignViewportI slave = null;
+ AlignViewportI codingComplement = null;
/**
* alignment displayed in the viewport. Please use get/setter
hideSequence(seqs);
+ AlignViewportI peer = getCodingComplement();
+ if (peer != null)
+ {
+ SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(
+ selectionGroup, this, peer);
+ ((AlignmentViewport) peer).hideSequence(mappedGroup
+ .getSequencesInOrder(peer.getAlignment()));
+ peer.setSelectionGroup(null);
+
+ }
+
setSelectionGroup(null);
}
};
@Override
- public AlignViewportI getSlave()
+ public AlignViewportI getCodingComplement()
{
- return this.slave;
+ return this.codingComplement;
}
+ /**
+ * Set this as the (cDna/protein) complement of the given viewport. Also
+ * ensures the reverse relationship is set on the given viewport.
+ */
@Override
- public void setSlave(AlignViewportI sl)
+ public void setCodingComplement(AlignViewportI av)
{
- if (this == sl.getSlave())
+ if (this == av)
{
- System.err.println("Ignoring recursive setSlave request");
+ System.err.println("Ignoring recursive setCodingComplement request");
}
else
{
- this.slave = sl;
+ this.codingComplement = av;
+ // avoid infinite recursion!
+ if (av.getCodingComplement() != this)
+ {
+ av.setCodingComplement(this);
+ }
}
}
+
+ @Override
+ public boolean isNucleotide()
+ {
+ return getAlignment() == null ? false : getAlignment().isNucleotide();
+ }
}
import jalview.gui.WebserviceInfo;
import jalview.util.MessageManager;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
public abstract class AWSThread extends Thread
{
/**
* dataset sequence relationships to be propagated onto new results
*/
- protected AlignedCodonFrame[] codonframe = null;
+ protected Set<AlignedCodonFrame> codonframe = null;
/**
* are there jobs still running in this thread.
SequenceI[] alignment = al.getSequencesArray();
for (int sq = 0; sq < alignment.length; sq++)
{
- for (int i = 0; i < codonframe.length; i++)
+ for (AlignedCodonFrame acf : codonframe)
{
- AlignedCodonFrame acf = codonframe[i];
final SequenceI seq = alignment[sq];
if (acf != null && acf.involvesSequence(seq))
{
al.addCodonFrame(acf);
- codonframe[i] = null;
break;
}
}
WsUrl = wsurl2;
if (alframe != null)
{
- AlignedCodonFrame[] cf = alframe.getViewport().getAlignment()
+ Set<AlignedCodonFrame> cf = alframe.getViewport().getAlignment()
.getCodonFrames();
if (cf != null)
{
- codonframe = new AlignedCodonFrame[cf.length];
- System.arraycopy(cf, 0, codonframe, 0, cf.length);
+ codonframe = new LinkedHashSet<AlignedCodonFrame>();
+ codonframe.addAll(cf);
}
}
}
/*
* Check two mappings (one for Mouse, one for Human)
*/
- assertEquals(2, protein.getCodonFrames().length);
- assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).length);
- assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).length);
+ assertEquals(2, protein.getCodonFrames().size());
+ assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).size());
+ assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).size());
/*
* Inspect mapping for Human protein
*/
- AlignedCodonFrame humanMapping = protein.getCodonFrame(protein
- .getSequenceAt(0))[0];
+ AlignedCodonFrame humanMapping = protein.getCodonFrame(
+ protein.getSequenceAt(0)).get(0);
assertEquals(1, humanMapping.getdnaSeqs().length);
assertEquals(cdna1.getSequenceAt(1).getDatasetSequence(),
humanMapping.getdnaSeqs()[0]);
/*
* Inspect mappings for Mouse protein
*/
- AlignedCodonFrame mouseMapping1 = protein.getCodonFrame(protein
- .getSequenceAt(1))[0];
+ AlignedCodonFrame mouseMapping1 = protein.getCodonFrame(
+ protein.getSequenceAt(1)).get(0);
assertEquals(2, mouseMapping1.getdnaSeqs().length);
assertEquals(cdna1.getSequenceAt(0).getDatasetSequence(),
mouseMapping1.getdnaSeqs()[0]);
/*
* Check two mappings (one for Mouse, one for Human)
*/
- assertEquals(2, protein.getCodonFrames().length);
- assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).length);
- assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).length);
+ assertEquals(2, protein.getCodonFrames().size());
+ assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).size());
+ assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).size());
/*
* Inspect mapping for Human protein - should map to 2nd and 4th cDNA seqs
*/
- AlignedCodonFrame humanMapping = protein.getCodonFrame(protein
- .getSequenceAt(0))[0];
+ AlignedCodonFrame humanMapping = protein.getCodonFrame(
+ protein.getSequenceAt(0)).get(0);
assertEquals(2, humanMapping.getdnaSeqs().length);
assertEquals(cdna1.getSequenceAt(1).getDatasetSequence(),
humanMapping.getdnaSeqs()[0]);
/*
* Inspect mapping for Mouse protein - should map to 1st/3rd/5th cDNA seqs
*/
- AlignedCodonFrame mouseMapping = protein.getCodonFrame(protein
- .getSequenceAt(1))[0];
+ AlignedCodonFrame mouseMapping = protein.getCodonFrame(
+ protein.getSequenceAt(1)).get(0);
assertEquals(3, mouseMapping.getdnaSeqs().length);
assertEquals(cdna1.getSequenceAt(0).getDatasetSequence(),
mouseMapping.getdnaSeqs()[0]);
*/
package jalview.analysis;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import jalview.datamodel.Mapping;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
}
}
+ @Test
+ public void testExtractGaps()
+ {
+ assertNull(AlignSeq.extractGaps(null, null));
+ assertNull(AlignSeq.extractGaps(". -", null));
+ assertNull(AlignSeq.extractGaps(null, "AB-C"));
+
+ assertEquals("ABCD", AlignSeq.extractGaps(" .-", ". -A-B.C D."));
+ }
}
--- /dev/null
+package jalview.datamodel;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class ColumnSelectionTest
+{
+
+ @Test
+ public void testAddElement()
+ {
+ ColumnSelection cs = new ColumnSelection();
+ cs.addElement(2);
+ cs.addElement(5);
+ List<Integer> sel = cs.getSelected();
+ assertEquals(2, sel.size());
+ assertEquals(new Integer(2), sel.get(0));
+ assertEquals(new Integer(5), sel.get(1));
+ }
+
+ /**
+ * Test the remove method - in particular to verify that remove(int i) removes
+ * the element whose value is i, _NOT_ the i'th element.
+ */
+ @Test
+ public void testRemoveElement()
+ {
+ ColumnSelection cs = new ColumnSelection();
+ cs.addElement(2);
+ cs.addElement(5);
+
+ // removing elements not in the list has no effect
+ cs.removeElement(0);
+ cs.removeElement(1);
+ List<Integer> sel = cs.getSelected();
+ assertEquals(2, sel.size());
+ assertEquals(new Integer(2), sel.get(0));
+ assertEquals(new Integer(5), sel.get(1));
+
+ // removing an element in the list removes it
+ cs.removeElement(2);
+ assertEquals(1, sel.size());
+ assertEquals(new Integer(5), sel.get(0));
+ }
+}
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
import java.util.List;
import org.junit.Before;
assertEquals(0, seq.getEnd()); // ??
}
+ /**
+ * Tests for the method that returns an alignment column position (base 1) for
+ * a given sequence position (base 1).
+ */
+ @Test
+ public void testFindIndex()
+ {
+ SequenceI seq = new Sequence("test", "ABCDEF");
+ assertEquals(0, seq.findIndex(0));
+ assertEquals(1, seq.findIndex(1));
+ assertEquals(5, seq.findIndex(5));
+ assertEquals(6, seq.findIndex(6));
+ assertEquals(6, seq.findIndex(9));
+
+ seq = new Sequence("test", "-A--B-C-D-E-F--");
+ assertEquals(2, seq.findIndex(1));
+ assertEquals(5, seq.findIndex(2));
+ assertEquals(7, seq.findIndex(3));
+
+ // before start returns 0
+ assertEquals(0, seq.findIndex(0));
+ assertEquals(0, seq.findIndex(-1));
+
+ // beyond end returns last residue column
+ assertEquals(13, seq.findIndex(99));
+
+ }
+
+ /**
+ * Tests for the method that returns a dataset sequence position (base 1) for
+ * an aligned column position (base 0).
+ */
@Test
public void testFindPosition()
{
// for static method see StringUtilsTest
}
+
+ /**
+ * Test the method that returns an array of aligned sequence positions where
+ * the array index is the data sequence position (both base 0).
+ */
+ @Test
+ public void testGapMap()
+ {
+ SequenceI seq = new Sequence("test", "-A--B-CD-E--F-");
+ seq.createDatasetSequence();
+ assertEquals("[1, 4, 6, 7, 9, 12]", Arrays.toString(seq.gapMap()));
+ }
}
--- /dev/null
+package jalview.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+public class ShiftListTest
+{
+
+ @Test
+ public void testParseMap()
+ {
+ assertNull(ShiftList.parseMap(null));
+ assertNull(ShiftList.parseMap(new int[]
+ {}));
+
+ /*
+ * Gap map showing residues in aligned positions 2,3,6,8,9,10,12
+ */
+ int[] gm = new int[]
+ { 2, 3, 6, 8, 9, 10, 12 };
+ List<int[]> shifts = ShiftList.parseMap(gm).getShifts();
+ assertEquals(4, shifts.size());
+
+ // TODO are these results (which pass) correct??
+ assertEquals("[0, 2]", Arrays.toString(shifts.get(0)));
+ assertEquals("[4, 2]", Arrays.toString(shifts.get(1)));
+ assertEquals("[7, 1]", Arrays.toString(shifts.get(2)));
+ assertEquals("[11, 1]", Arrays.toString(shifts.get(3)));
+ }
+}