import jalview.util.MessageManager;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Enumeration;
/**
* Data structure to hold and manipulate a multiple sequence alignment
- */
-/**
- * @author JimP
*
+ * @author JimP
*/
public class Alignment implements AlignmentI
{
+ private static final SequenceGroup[] NO_GROUPS = new SequenceGroup[0];
+
private Alignment dataset;
- protected List<SequenceI> sequences;
+ private List<SequenceI> sequences;
protected List<SequenceGroup> groups;
private boolean nucleotide = true;
+ private List<AlignedCodonFrame> codonFrameList;
+
+ /*
+ * persistent object to hold result of findAllGroups(SequenceI)
+ */
+ private List<SequenceGroup> groupsForSequence = new ArrayList<>();
+
public boolean hasRNAStructure = false;
public AlignmentAnnotation[] annotations;
public Hashtable alignmentProperties;
- private List<AlignedCodonFrame> codonFrameList;
-
private void initAlignment(SequenceI[] seqs)
{
groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
/**
* Make a new alignment from an array of SeqCigars
*
- * @param seqs
- * SeqCigar[]
+ * @param alseqs
*/
public Alignment(SeqCigar[] alseqs)
{
{
synchronized (sequences)
{
+
if (i > -1 && i < sequences.size())
{
return sequences.get(i);
}
}
+
return null;
}
@Override
public SequenceGroup[] findAllGroups(SequenceI s)
{
- ArrayList<SequenceGroup> temp = new ArrayList<>();
-
synchronized (groups)
{
int gSize = groups.size();
+ if (gSize == 0)
+ {
+ return NO_GROUPS;
+ }
+ groupsForSequence.clear();
for (int i = 0; i < gSize; i++)
{
SequenceGroup sg = groups.get(i);
if (sg.getSequences().contains(s))
{
- temp.add(sg);
+ groupsForSequence.add(sg);
}
}
}
- SequenceGroup[] ret = new SequenceGroup[temp.size()];
- return temp.toArray(ret);
+ SequenceGroup[] ret = new SequenceGroup[groupsForSequence.size()];
+ return groupsForSequence.toArray(ret);
}
/** */
int i = 0;
SequenceI sq = null;
String sqname = null;
+ int nseq = sequences.size();
if (startAfter != null)
{
// try to find the sequence in the alignment
boolean matched = false;
- while (i < sequences.size())
+ while (i < nseq)
{
if (getSequenceAt(i++) == startAfter)
{
i = 0;
}
}
- while (i < sequences.size())
+ while (i < nseq)
{
sq = getSequenceAt(i);
sqname = sq.getName();
public int getWidth()
{
int maxLength = -1;
-
+
for (int i = 0; i < sequences.size(); i++)
{
- if (getSequenceAt(i).getLength() > maxLength)
- {
- maxLength = getSequenceAt(i).getLength();
- }
+ maxLength = Math.max(maxLength, getSequenceAt(i).getLength());
}
-
return maxLength;
}
+ @Override
+ public int getVisibleWidth()
+ {
+ int w = getWidth();
+ if (hiddenCols != null)
+ {
+ w -= hiddenCols.getSize();
+ }
+ return w;
+ }
+
/**
* DOCUMENT ME!
*
int maxLength = -1;
SequenceI current;
- for (int i = 0; i < sequences.size(); i++)
+ int nseq = sequences.size();
+ for (int i = 0; i < nseq; i++)
{
current = getSequenceAt(i);
for (int j = current.getLength(); j > maxLength; j--)
maxLength++;
int cLength;
- for (int i = 0; i < sequences.size(); i++)
+ for (int i = 0; i < nseq; i++)
{
current = getSequenceAt(i);
cLength = current.getLength();
AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
annot.hasText = false;
- annot.setCalcId(new String(calcId));
+ if (calcId != null)
+ {
+ annot.setCalcId(new String(calcId));
+ }
annot.autoCalculated = autoCalc;
if (seqRef != null)
{
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- List<AlignmentAnnotation> aa = new ArrayList<>();
AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation();
if (alignmentAnnotation != null)
{
- for (AlignmentAnnotation a : alignmentAnnotation)
- {
- if (a.getCalcId() == calcId || (a.getCalcId() != null
- && calcId != null && a.getCalcId().equals(calcId)))
- {
- aa.add(a);
- }
- }
+ return AlignmentAnnotation.findAnnotation(
+ Arrays.asList(getAlignmentAnnotation()), calcId);
}
- return aa;
+ return Arrays.asList(new AlignmentAnnotation[] {});
}
@Override
public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
String calcId, String label)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
- for (AlignmentAnnotation ann : getAlignmentAnnotation())
- {
- if ((calcId == null || (ann.getCalcId() != null
- && ann.getCalcId().equals(calcId)))
- && (seq == null || (ann.sequenceRef != null
- && ann.sequenceRef == seq))
- && (label == null
- || (ann.label != null && ann.label.equals(label))))
- {
- aa.add(ann);
- }
- }
- return aa;
+ return AlignmentAnnotation.findAnnotations(
+ Arrays.asList(getAlignmentAnnotation()), seq, calcId, label);
}
@Override
}
@Override
- public void setHiddenColumns(HiddenColumns cols)
+ public boolean setHiddenColumns(HiddenColumns cols)
{
+ boolean changed = cols == null ? hiddenCols != null
+ : !cols.equals(hiddenCols);
hiddenCols = cols;
+ return changed;
}
@Override