import jalview.util.ShiftList;
import java.io.PrintStream;
-import java.util.Enumeration;
+import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
* one or more ScGroup objects, which are referenced by each seqCigar's group
* membership
*/
- private Vector scGroups;
+ private List<ScGroup> scGroups=null;
private boolean isNa = false;
selseqs = alignment.getSequencesArray();
}
+ List<List<SequenceI>> seqsets=new ArrayList<List<SequenceI>>();
// get the alignment's group list and make a copy
- Vector grps = new Vector();
+ List<SequenceGroup> grps = new ArrayList<SequenceGroup>();
List<SequenceGroup> gg = alignment.getGroups();
grps.addAll(gg);
ScGroup[] sgrps = null;
boolean addedgps[] = null;
if (grps != null)
{
- SequenceGroup sg;
if (selection != null && selectedRegionOnly)
{
// trim annotation to the region being stored.
// strip out any groups that do not actually intersect with the
// visible and selected region
int ssel = selection.getStartRes(), esel = selection.getEndRes();
- Vector isg = new Vector();
- Enumeration en = grps.elements();
- while (en.hasMoreElements())
+ List<SequenceGroup> isg = new ArrayList<SequenceGroup>();
+ for (SequenceGroup sg : grps)
{
- sg = (SequenceGroup) en.nextElement();
-
if (!(sg.getStartRes() > esel || sg.getEndRes() < ssel))
{
// adjust bounds of new group, if necessary.
sg.setStartRes(sg.getStartRes() - ssel + 1);
sg.setEndRes(sg.getEndRes() - ssel + 1);
- isg.addElement(sg);
+ isg.add(sg);
}
}
grps = isg;
addedgps = new boolean[grps.size()];
for (int g = 0; g < sgrps.length; g++)
{
- sg = (SequenceGroup) grps.elementAt(g);
+ SequenceGroup sg = grps.get(g);
sgrps[g] = new ScGroup();
sgrps[g].sg = new SequenceGroup(sg);
addedgps[g] = false;
- grps.setElementAt(sg.getSequences(null), g);
+ seqsets.set(g, sg.getSequences(null));
}
- // grps now contains vectors (should be sets) for each group, so we can
+ // seqsets now contains vectors (should be sets) for each group, so we can
// track when we've done with the group
}
int csi = 0;
sequences[csi].setGroupMembership(selected);
selected.addElement(sequences[csi]);
}
- if (grps != null)
+ if (seqsets != null)
{
for (int sg = 0; sg < sgrps.length; sg++)
{
- if (((Vector) grps.elementAt(sg)).contains(selseqs[i]))
+ if ((seqsets.get(sg)).contains(selseqs[i]))
{
sequences[csi].setGroupMembership(sgrps[sg]);
sgrps[sg].sg.deleteSequence(selseqs[i], false);
{
if (scGroups == null)
{
- scGroups = new Vector();
+ scGroups = new ArrayList<ScGroup>();
}
addedgps[sg] = true;
- scGroups.addElement(sgrps[sg]);
+ scGroups.add(sgrps[sg]);
}
}
}
SequenceGroup[] nsg = new SequenceGroup[nvg];
for (int g = 0; g < nvg; g++)
{
- SequenceGroup sg = ((ScGroup) scGroups.elementAt(g)).sg;
+ SequenceGroup sg = scGroups.get(g).sg;
if (r)
{
if (sg.getStartRes() > gend || sg.getEndRes() < gstart)
for (int g = 0; g < nvg; g++)
{
if (nsg[g] != null
- && sequences[nsq].isMemberOf(scGroups.elementAt(g)))
+ && sequences[nsq].isMemberOf(scGroups.get(g)))
{
nsg[g].addSequence(aln[nsq], false);
}
+ " groups defined on the view.");
for (int g = 0; g < view.scGroups.size(); g++)
{
- ScGroup sgr = (ScGroup) view.scGroups.elementAt(g);
+ ScGroup sgr = view.scGroups.get(g);
os.println("Group " + g + ": Name = " + sgr.sg.getName()
+ " Contains " + sgr.seqs.size() + " Seqs.");
os.println("This group runs from " + sgr.sg.getStartRes() + " to "
import java.awt.Color;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
/**
* group members
*/
- private Vector<SequenceI> sequences = new Vector<SequenceI>();
+ private List<SequenceI> sequences = new ArrayList<SequenceI>();
/**
* representative sequence for this group (if any)
* @param end
* last column of group
*/
- public SequenceGroup(Vector sequences, String groupName,
+ public SequenceGroup(List<SequenceI> sequences, String groupName,
ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
boolean colourText, int start, int end)
{
{
if (seqsel != null)
{
- sequences = new Vector();
- Enumeration<SequenceI> sq = seqsel.sequences.elements();
- while (sq.hasMoreElements())
- {
- sequences.addElement(sq.nextElement());
- }
- ;
+ sequences = new ArrayList<SequenceI>();
+ sequences.addAll(seqsel.sequences);
if (seqsel.groupName != null)
{
groupName = new String(seqsel.groupName);
{
if (hiddenReps == null)
{
+ // TODO: need a synchronizedCollection here ?
return sequences;
}
else
{
- Vector allSequences = new Vector();
- SequenceI seq;
- for (int i = 0; i < sequences.size(); i++)
+ List<SequenceI> allSequences = new ArrayList<SequenceI>();
+ for (SequenceI seq : sequences)
{
- seq = sequences.elementAt(i);
- allSequences.addElement(seq);
+ allSequences.add(seq);
if (hiddenReps.containsKey(seq))
{
SequenceCollectionI hsg = hiddenReps.get(seq);
{
if (seq2 != seq && !allSequences.contains(seq2))
{
- allSequences.addElement(seq2);
+ allSequences.add(seq2);
}
}
}
*/
public void addSequence(SequenceI s, boolean recalc)
{
- if (s != null && !sequences.contains(s))
+ synchronized (sequences)
{
- sequences.addElement(s);
- }
+ if (s != null && !sequences.contains(s))
+ {
+ sequences.add(s);
+ }
- if (recalc)
- {
- recalcConservation();
+ if (recalc)
+ {
+ recalcConservation();
+ }
}
}
*/
public void addOrRemove(SequenceI s, boolean recalc)
{
+ synchronized (sequences)
+ {
if (sequences.contains(s))
{
deleteSequence(s, recalc);
else
{
addSequence(s, recalc);
+ }
}
}
/**
- * DOCUMENT ME!
+ * remove
*
* @param s
- * DOCUMENT ME!
+ * to be removed
* @param recalc
- * DOCUMENT ME!
+ * true means recalculate conservation
*/
public void deleteSequence(SequenceI s, boolean recalc)
{
- sequences.removeElement(s);
-
- if (recalc)
+ synchronized (sequences)
{
- recalcConservation();
+ sequences.remove(s);
+
+ if (recalc)
+ {
+ recalcConservation();
+ }
}
}
}
/**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * @return number of sequences in group
*/
public int getSize()
{
}
/**
- * DOCUMENT ME!
- *
* @param i
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * @return the ith sequence
*/
public SequenceI getSequenceAt(int i)
{
- return sequences.elementAt(i);
+ return sequences.get(i);
}
/**
- * DOCUMENT ME!
- *
* @param state
- * DOCUMENT ME!
+ * colourText
*/
public void setColourText(boolean state)
{
}
/**
- * DOCUMENT ME!
+ * computes the width of current set of sequences and returns it
*
* @return DOCUMENT ME!
*/
@Override
public int getWidth()
{
- // MC This needs to get reset when characters are inserted and deleted
- if (sequences.size() > 0)
+ synchronized (sequences)
{
- width = sequences.elementAt(0).getLength();
- }
-
- for (int i = 1; i < sequences.size(); i++)
- {
- SequenceI seq = sequences.elementAt(i);
-
- if (seq.getLength() > width)
- {
- width = seq.getLength();
+ // MC This needs to get reset when characters are inserted and deleted
+ boolean first=true;
+ for (SequenceI seq:sequences) {
+ if (first || seq.getLength() > width)
+ {
+ width = seq.getLength();
+ first = false;
+ }
}
+ return width;
}
-
- return width;
}
/**
*/
public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
{
- int sSize = sequences.size();
- int alHeight = al.getHeight();
+ synchronized (sequences)
+ {
+ int sSize = sequences.size();
+ int alHeight = al.getHeight();
- SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
+ SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
- int index = 0;
- for (int i = 0; i < alHeight && index < sSize; i++)
- {
- if (sequences.contains(al.getSequenceAt(i)))
+ int index = 0;
+ for (int i = 0; i < alHeight && index < sSize; i++)
{
- seqs[(trim) ? index : i] = al.getSequenceAt(i);
- index++;
+ if (sequences.contains(al.getSequenceAt(i)))
+ {
+ seqs[(trim) ? index : i] = al.getSequenceAt(i);
+ index++;
+ }
}
- }
- if (index == 0)
- {
- return null;
- }
- if (!trim)
- {
- return seqs;
- }
- if (index < seqs.length)
- {
- SequenceI[] dummy = seqs;
- seqs = new SequenceI[index];
- while (--index >= 0)
+ if (index == 0)
+ {
+ return null;
+ }
+ if (!trim)
+ {
+ return seqs;
+ }
+ if (index < seqs.length)
{
- seqs[index] = dummy[index];
- dummy[index] = null;
+ SequenceI[] dummy = seqs;
+ seqs = new SequenceI[index];
+ while (--index >= 0)
+ {
+ seqs[index] = dummy[index];
+ dummy[index] = null;
+ }
}
+ return seqs;
}
- return seqs;
}
/**
{
SequenceGroup sgroup = new SequenceGroup(this);
SequenceI[] insect = getSequencesInOrder(alignment);
- sgroup.sequences = new Vector();
+ sgroup.sequences = new ArrayList<SequenceI>();
for (int s = 0; insect != null && s < insect.length; s++)
{
if (map == null || map.containsKey(insect[s]))
{
- sgroup.sequences.addElement(insect[s]);
+ sgroup.sequences.add(insect[s]);
}
}
- // Enumeration en =getSequences(hashtable).elements();
- // while (en.hasMoreElements())
- // {
- // SequenceI elem = (SequenceI) en.nextElement();
- // if (alignment.getSequences().contains(elem))
- // {
- // sgroup.addSequence(elem, false);
- // }
- // }
return sgroup;
}
// TODO add in other methods like 'getAlignmentAnnotation(String label),
// etc'
ArrayList<AlignmentAnnotation> annot = new ArrayList<AlignmentAnnotation>();
- for (SequenceI seq : sequences)
+ synchronized (sequences)
{
- AlignmentAnnotation[] aa = seq.getAnnotation();
- if (aa != null)
+ for (SequenceI seq : sequences)
{
- for (AlignmentAnnotation al : aa)
+ AlignmentAnnotation[] aa = seq.getAnnotation();
+ if (aa != null)
{
- if (al.groupRef == this)
+ for (AlignmentAnnotation al : aa)
{
- annot.add(al);
+ if (al.groupRef == this)
+ {
+ annot.add(al);
+ }
}
}
}
- }
- if (consensus != null)
- {
- annot.add(consensus);
- }
- if (conservation != null)
- {
- annot.add(conservation);
+ if (consensus != null)
+ {
+ annot.add(consensus);
+ }
+ if (conservation != null)
+ {
+ annot.add(conservation);
+ }
}
return annot.toArray(new AlignmentAnnotation[0]);
}
public void clear()
{
- sequences.clear();
+ synchronized (sequences)
+ {
+ sequences.clear();
+ }
}
private AnnotatedCollectionI context;