/*
* Jalview - A Sequence Alignment Editor and Viewer
-* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
import java.util.*;
+import jalview.analysis.*;
/**
* DOCUMENT ME!
* @author $author$
* @version $Revision$
*/
-public class Sequence implements SequenceI
+public class Sequence
+ implements SequenceI
{
SequenceI datasetSequence;
String name;
}
/**
- * Creates a new Sequence object.
- *
+ * Creates a new Sequence object with new features, DBRefEntries, AlignmentAnnotations, and PDBIds
+ * but inherits any existing dataset sequence reference.
* @param seq DOCUMENT ME!
*/
public Sequence(SequenceI seq)
seq.getStart(),
seq.getEnd());
description = seq.getDescription();
+ if (seq.getSequenceFeatures()!=null) {
+ SequenceFeature[] sf = seq.getSequenceFeatures();
+ for (int i=0; i<sf.length; i++) {
+ addSequenceFeature(new SequenceFeature(sf[i]));
+ }
+ }
+ if (seq.getDBRef()!=null) {
+ DBRefEntry[] dbr = seq.getDBRef();
+ for (int i=0; i<dbr.length; i++) {
+ addDBRef(new DBRefEntry(dbr[i]));
+ }
+ }
+ setDatasetSequence(seq.getDatasetSequence());
+ if (seq.getAnnotation()!=null) {
+ AlignmentAnnotation[] sqann = seq.getAnnotation();
+ for (int i=0;i<sqann.length; i++)
+ {
+ AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
+ addAlignmentAnnotation(newann);
+ }
+ }
+ if (seq.getPDBId()!=null) {
+ Vector ids = seq.getPDBId();
+ Enumeration e = ids.elements();
+ while (e.hasMoreElements()) {
+ this.addPDBId(new PDBEntry((PDBEntry) e.nextElement()));
+ }
+ }
}
public void deleteFeature(SequenceFeature sf)
{
if(sequenceFeatures==null)
+ {
return;
+ }
int index=0;
for (index = 0; index < sequenceFeatures.length; index++)
if(index==sequenceFeatures.length)
+ {
return;
+ }
int sfLength = sequenceFeatures.length;
if(sfLength<2)
System.arraycopy(sequenceFeatures, 0, temp, 0, index);
if(index<sfLength)
+ {
System.arraycopy(sequenceFeatures,
index + 1,
temp,
index, sequenceFeatures.length - index -1);
+ }
sequenceFeatures = temp;
}
public void addPDBId(PDBEntry entry)
{
if (pdbIds == null)
+ {
pdbIds = new Vector();
+ }
pdbIds.addElement(entry);
}
public SequenceI getSubSequence(int start, int end)
{
if (start < 0)
+ {
start = 0;
+ }
char [] seq = getSequence(start, end);
if (seq.length == 0)
+ {
return null;
+ }
int nstart = findPosition(start);
int nend = findPosition(end) - 1;
// JBPNote - this is an incomplete copy.
SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
nseq.setDescription(description);
if (datasetSequence!=null)
+ {
nseq.setDatasetSequence(datasetSequence);
+ }
else
+ {
nseq.setDatasetSequence(this);
+ }
return nseq;
}
}
/**
- * DOCUMENT ME!
+ * Return the alignment position for a sequence position
*
- * @param pos DOCUMENT ME!
+ * @param pos lying from start to end
*
- * @return DOCUMENT ME!
+ * @return aligned position of residue pos
*/
public int findIndex(int pos)
{
System.arraycopy(sequence,j,tmp,i,sequence.length-j);
}
+ if (this.datasetSequence != null)
+ {
+ for (int s = i; s < j; s++)
+ {
+ if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
+ {
+
+ Sequence ds = new Sequence(name,
+ AlignSeq.extractGaps(
+ jalview.util.Comparison.GapChars,
+ this.getSequenceAsString()
+ ),
+ start,
+ end);
+ ds.setDescription(description);
+ }
+ break;
+ }
+ }
+
sequence = tmp;
+
}
+
/**
* DOCUMENT ME!
*
public void addDBRef(DBRefEntry entry)
{
if (dbrefs == null)
+ {
dbrefs = new DBRefEntry[0];
+ }
int i, iSize = dbrefs.length;
for(i=0; i<iSize; i++)
- if(dbrefs[i].getAccessionId().equals(entry.getAccessionId())
- && dbrefs[i].getSource().equals(entry.getSource())
- && dbrefs[i].getVersion().equals(entry.getVersion()))
+ {
+ if(dbrefs[i].equals(entry))
{
return;
}
+ }
DBRefEntry[] temp = new DBRefEntry[iSize + 1];
System.arraycopy(dbrefs, 0, temp, 0, iSize);
public AlignmentAnnotation[] getAnnotation()
{
if (annotation == null)
+ {
return null;
+ }
AlignmentAnnotation[] ret = new AlignmentAnnotation[annotation.size()];
for (int r = 0; r < ret.length; r++)
+ {
ret[r] = (AlignmentAnnotation) annotation.elementAt(r);
+ }
return ret;
}
public void addAlignmentAnnotation(AlignmentAnnotation annotation)
{
if (this.annotation == null)
+ {
this.annotation = new Vector();
+ }
this.annotation.addElement(annotation);
+ annotation.setSequenceRef(this);
}
* sequence's dataset sequence.
*
*/
- private boolean isValidDatasetSequence() {
- if (datasetSequence!=null)
+ private boolean isValidDatasetSequence()
+ {
+ if (datasetSequence!=null)
+ {
return false;
+ }
for (int i=0;i<sequence.length; i++)
+ {
if (jalview.util.Comparison.isGap(sequence[i]))
+ {
return false;
+ }
+ }
return true;
}
/* (non-Javadoc)
* @see jalview.datamodel.SequenceI#deriveSequence()
*/
- public SequenceI deriveSequence() {
- SequenceI seq = new Sequence(name, sequence, start, end);
- seq.setDescription(description);
- if (datasetSequence!=null) {
- seq.setDatasetSequence(datasetSequence);
+ public SequenceI deriveSequence()
+ {
+ SequenceI seq=new Sequence(this);
+ if (datasetSequence != null)
+ {
+ // duplicate current sequence with same dataset
+ seq.setDatasetSequence(datasetSequence);
+ }
+ else
+ {
+ if (isValidDatasetSequence())
+ {
+ // Use this as dataset sequence
+ seq.setDatasetSequence(this);
} else {
- if (isValidDatasetSequence())
- seq.setDatasetSequence(this);
+ // Create a new, valid dataset sequence
+ SequenceI ds = seq;
+ ds.setSequence(AlignSeq.extractGaps(jalview.util.Comparison.GapChars, new String(sequence)));
+ setDatasetSequence(ds);
+ seq = this; // and return this sequence as the derived sequence.
}
- return seq;
+ }
+ return seq;
+ }
+ /* (non-Javadoc)
+ * @see jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[] annotations)
+ */
+ public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
+ {
+ if (annotation!=null) {
+ annotation.clear();
+ }
+ if (annotations!=null) {
+ for (int i=0; i<annotations.length; i++)
+ {
+ if (annotations[i]!=null)
+ addAlignmentAnnotation(annotations[i]);
+ }
+ }
}
}