import jalview.analysis.AlignSeq;
import jalview.api.DBRefEntryI;
+import jalview.util.Comparison;
import jalview.util.DBRefUtils;
import jalview.util.MapList;
import jalview.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.BitSet;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
*/
int index = -1;
- /** array of sequence features - may not be null for a valid sequence object */
+ /**
+ * array of sequence features - may not be null for a valid sequence object
+ */
public SequenceFeature[] sequenceFeatures;
/**
{
if (name == null)
{
- System.err
- .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
+ System.err.println(
+ "POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
name = "";
}
// Does sequence have the /start-end signature?
{
char[] oseq = seq.getSequence();
initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
- seq.getStart(),
- seq.getEnd());
+ seq.getStart(), seq.getEnd());
}
description = seq.getDescription();
if (seq != datasetSequence)
}
}
-
@Override
public void setSequenceFeatures(SequenceFeature[] features)
{
{
new Exception(
"Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
- .printStackTrace();
+ .printStackTrace();
}
datasetSequence.setSequenceFeatures(features);
}
}
@Override
- public synchronized void addSequenceFeature(SequenceFeature sf)
+ public synchronized boolean addSequenceFeature(SequenceFeature sf)
{
- if (sequenceFeatures==null && datasetSequence != null)
+ if (sequenceFeatures == null && datasetSequence != null)
{
- datasetSequence.addSequenceFeature(sf);
- return;
+ return datasetSequence.addSequenceFeature(sf);
}
if (sequenceFeatures == null)
{
{
if (sequenceFeatures[i].equals(sf))
{
- return;
+ return false;
}
}
- SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
+ SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length
+ + 1];
System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
temp[sequenceFeatures.length] = sf;
sequenceFeatures = temp;
+ return true;
}
@Override
{
if (sequenceFeatures == null)
{
- if (datasetSequence!=null) {
- datasetSequence.deleteFeature(sf);
+ if (datasetSequence != null)
+ {
+ datasetSequence.deleteFeature(sf);
}
return;
}
}
@Override
+ public BitSet getInsertionsAsBits()
+ {
+ BitSet map = new BitSet();
+ int lastj = -1, j = 0;
+ int pos = start;
+ int seqlen = sequence.length;
+ while ((j < seqlen))
+ {
+ if (jalview.util.Comparison.isGap(sequence[j]))
+ {
+ if (lastj == -1)
+ {
+ lastj = j;
+ }
+ }
+ else
+ {
+ if (lastj != -1)
+ {
+ map.set(lastj, j);
+ lastj = -1;
+ }
+ }
+ j++;
+ }
+ if (lastj != -1)
+ {
+ map.set(lastj, j);
+ lastj = -1;
+ }
+ return map;
+ }
+
+ @Override
public void deleteChars(int i, int j)
{
int newstart = start, newend = end;
{
if (seq == this)
{
- throw new Error(
+ throw new IllegalArgumentException(
"Implementation Error: self reference passed to SequenceI.setDatasetSequence");
}
if (seq != null && seq.getDatasetSequence() != null)
{
- throw new Error(
+ throw new IllegalArgumentException(
"Implementation error: cascading dataset sequences are not allowed.");
}
datasetSequence = seq;
@Override
public AlignmentAnnotation[] getAnnotation()
{
- return annotation == null ? null : annotation
- .toArray(new AlignmentAnnotation[annotation.size()]);
+ return annotation == null ? null
+ : annotation
+ .toArray(new AlignmentAnnotation[annotation.size()]);
}
@Override
@Override
public SequenceI deriveSequence()
{
- Sequence seq=null;
+ Sequence seq = null;
if (datasetSequence == null)
{
if (isValidDatasetSequence())
else
{
// Create a new, valid dataset sequence
- createDatasetSequence();
+ createDatasetSequence();
}
}
return new Sequence(this);
private long _seqhash = 0;
+ /**
+ * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
+ * true
+ */
@Override
public boolean isProtein()
{
if (_seqhash != sequence.hashCode())
{
_seqhash = sequence.hashCode();
- _isNa=jalview.util.Comparison.isNucleotide(new SequenceI[] { this });
+ _isNa = Comparison.isNucleotide(this);
}
return !_isNa;
};
{
if (datasetSequence == null)
{
- Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
- jalview.util.Comparison.GapChars, getSequenceAsString()),
+ Sequence dsseq = new Sequence(getName(),
+ AlignSeq.extractGaps(jalview.util.Comparison.GapChars,
+ getSequenceAsString()),
getStart(), getEnd());
datasetSequence = dsseq;
dsseq.setDescription(description);
// move features and database references onto dataset sequence
dsseq.sequenceFeatures = sequenceFeatures;
- sequenceFeatures=null;
+ sequenceFeatures = null;
dsseq.dbrefs = dbrefs;
- dbrefs=null;
+ dbrefs = null;
// TODO: search and replace any references to this sequence with
// references to the dataset sequence in Mappings on dbref
dsseq.pdbIds = pdbIds;
for (int si = 0; si < sfs.length; si++)
{
SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
- : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
+ : new SequenceFeature[]
+ { new SequenceFeature(sfs[si]) };
if (sf != null && sf.length > 0)
{
for (int sfi = 0; sfi < sf.length; sfi++)
return null;
}
-
@Override
public List<DBRefEntry> getPrimaryDBRefs()
{
- if (datasetSequence!=null)
+ if (datasetSequence != null)
{
return datasetSequence.getPrimaryDBRefs();
}
- if (dbrefs==null || dbrefs.length==0)
+ if (dbrefs == null || dbrefs.length == 0)
{
return Collections.emptyList();
}
}
}
// whilst it looks like it is a primary ref, we also sanity check type
- if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
- DBRefUtils.getCanonicalName(ref.getSource())))
+ if (DBRefUtils.getCanonicalName(DBRefSource.PDB)
+ .equals(DBRefUtils.getCanonicalName(ref.getSource())))
{
// PDB dbrefs imply there should be a PDBEntry associated
// TODO: tighten PDB dbrefs