public SequenceI[] getSequencesArray()
{
+ if (sequences==null)
+ return null;
SequenceI[] reply = new SequenceI[sequences.size()];
for (int i = 0; i < sequences.size(); i++)
{
public void finalize()
{
if(getDataset()!=null)
- getDataset().finalize();
+ getDataset().removeAlignmentRef();
dataset = null;
sequences = null;
hiddenSequences = null;
}
+ /**
+ * decrement the alignmentRefs counter by one and call finalize if it goes to zero.
+ */
+ private void removeAlignmentRef()
+ {
+ if (--alignmentRefs==0)
+ {
+ finalize();
+ }
+ }
/**
* DOCUMENT ME!
/** */
public SequenceI findName(String name)
{
- int i = 0;
+ return findName(name,false);
+ }
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#findName(java.lang.String, boolean)
+ */
+ public SequenceI findName(String token, boolean b)
+ {
+
+ int i = 0;
+ SequenceI sq=null;
+ String sqname=null;
while (i < sequences.size())
{
- if (getSequenceAt(i).getName().equals(name))
+ sq = getSequenceAt(i);
+ sqname = sq.getName();
+ if (sqname.equals(token) // exact match
+ || (b && // allow imperfect matches - case varies
+ (sqname.equalsIgnoreCase(token))))
{
return getSequenceAt(i);
}
return null;
}
-
public SequenceI[] findSequenceMatch(String name)
{
Vector matches = new Vector();
return true;
}
-
- /**
- * DOCUMENT ME!
- *
- * @param aa DOCUMENT ME!
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#deleteAnnotation(jalview.datamodel.AlignmentAnnotation)
*/
- public void deleteAnnotation(AlignmentAnnotation aa)
+ public boolean deleteAnnotation(AlignmentAnnotation aa)
{
- if(aa.sequenceRef!=null)
- aa.sequenceRef.removeAlignmentAnnotation(aa);
-
int aSize = 1;
if (annotations != null)
if (aSize < 1)
{
- return;
+ return false;
}
AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
+ boolean swap=false;
int tIndex = 0;
for (int i = 0; i < aSize; i++)
{
if (annotations[i] == aa)
{
+ swap=true;
continue;
}
-
- temp[tIndex] = annotations[i];
- tIndex++;
+ if (tIndex<temp.length)
+ temp[tIndex++] = annotations[i];
}
- annotations = temp;
+ if (swap)
+ {
+ annotations = temp;
+ if(aa.sequenceRef!=null)
+ aa.sequenceRef.removeAlignmentAnnotation(aa);
+ }
+ return swap;
}
/**
// Create a new dataset for this alignment.
// Can only be done once, if dataset is not null
// This will not be performed
- Sequence[] seqs = new Sequence[getHeight()];
+ SequenceI[] seqs = new SequenceI[getHeight()];
SequenceI currentSeq;
for (int i = 0; i < getHeight(); i++)
{
}
else
{
- seqs[i] = new Sequence(currentSeq.getName(),
- AlignSeq.extractGaps(
- jalview.util.Comparison.GapChars,
- currentSeq.getSequenceAsString()
- ),
- currentSeq.getStart(),
- currentSeq.getEnd());
- seqs[i].sequenceFeatures = currentSeq.getSequenceFeatures();
- seqs[i].setDescription(currentSeq.getDescription());
- getSequenceAt(i).setSequenceFeatures(null);
- getSequenceAt(i).setDatasetSequence(seqs[i]);
+ seqs[i] = currentSeq.createDatasetSequence();
}
}
{
dataset = data;
}
+ dataset.addAlignmentRef();
+ }
+ /**
+ * reference count for number of alignments referencing this one.
+ */
+ int alignmentRefs=0;
+ /**
+ * increase reference count to this alignment.
+ */
+ private void addAlignmentRef()
+ {
+ alignmentRefs++;
}
public Alignment getDataset()
{
return alignmentProperties;
}
+ AlignedCodonFrame[] codonFrameList=null;
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#addCodonFrame(jalview.datamodel.AlignedCodonFrame)
+ */
+ public void addCodonFrame(AlignedCodonFrame codons)
+ {
+ if (codons==null)
+ return;
+ if (codonFrameList==null)
+ {
+ codonFrameList = new AlignedCodonFrame[] { codons };
+ return;
+ }
+ 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)
+ */
+ public AlignedCodonFrame getCodonFrame(int index)
+ {
+ return codonFrameList[index];
+ }
+
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#getCodonFrame(jalview.datamodel.SequenceI)
+ */
+ public AlignedCodonFrame[] getCodonFrame(SequenceI seq)
+ {
+ if (seq==null || codonFrameList==null)
+ return null;
+ Vector cframes=new Vector();
+ for (int f=0;f<codonFrameList.length; f++)
+ {
+ if (codonFrameList[f].involvesSequence(seq))
+ cframes.addElement(codonFrameList[f]);
+ }
+ if (cframes.size()==0)
+ return null;
+ AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()];
+ cframes.copyInto(cfr);
+ return cfr;
+ }
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#getCodonFrames()
+ */
+ public AlignedCodonFrame[] getCodonFrames()
+ {
+ return codonFrameList;
+ }
+
+ /* (non-Javadoc)
+ * @see jalview.datamodel.AlignmentI#removeCodonFrame(jalview.datamodel.AlignedCodonFrame)
+ */
+ public boolean removeCodonFrame(AlignedCodonFrame codons)
+ {
+ if (codons==null || codonFrameList==null)
+ 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;
+ }
}