import java.util.BitSet;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
/**
*
- * Implements the SequenceI interface for a char[] based sequence object.
- *
- * @author $author$
- * @version $Revision$
+ * Implements the SequenceI interface for a char[] based sequence object
*/
public class Sequence extends ASequence implements SequenceI
{
{
if (pdbIds == null)
{
- pdbIds = new Vector<PDBEntry>();
+ pdbIds = new Vector<>();
pdbIds.add(entry);
return true;
}
@Override
public Vector<PDBEntry> getAllPDBEntries()
{
- return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
+ return pdbIds == null ? new Vector<>() : pdbIds;
}
/**
}
/**
- * DOCUMENT ME!
+ * Sets the sequence description, and also parses out any special formats of
+ * interest
*
* @param desc
- * DOCUMENT ME!
*/
@Override
public void setDescription(String desc)
this.description = desc;
}
+ @Override
+ public void setGeneLoci(String speciesId, String assemblyId,
+ String chromosomeId, MapList map)
+ {
+ addDBRef(new GeneLocus(speciesId, assemblyId, chromosomeId,
+ new Mapping(map)));
+ }
+
/**
- * DOCUMENT ME!
+ * Returns the gene loci mapping for the sequence (may be null)
*
- * @return DOCUMENT ME!
+ * @return
+ */
+ @Override
+ public GeneLociI getGeneLoci()
+ {
+ DBRefEntry[] refs = getDBRefs();
+ if (refs != null)
+ {
+ for (final DBRefEntry ref : refs)
+ {
+ if (ref instanceof GeneLociI)
+ {
+ return (GeneLociI) ref;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Answers the description
+ *
+ * @return
*/
@Override
public String getDescription()
* preserve end residue column provided cursor was valid
*/
int endColumn = isValidCursor(cursor) ? cursor.lastColumnPosition : 0;
+
if (residuePos == this.end)
{
endColumn = column;
* @param curs
* @return
*/
- protected int findIndex(int pos, SequenceCursor curs)
+ protected int findIndex(final int pos, SequenceCursor curs)
{
if (!isValidCursor(curs))
{
/*
* move left or right to find pos from hint.position
*/
- int col = curs.columnPosition - 1; // convert from base 1 to 0-based array
- // index
+ int col = curs.columnPosition - 1; // convert from base 1 to base 0
int newPos = curs.residuePosition;
int delta = newPos > pos ? -1 : 1;
while (newPos != pos)
{
col += delta; // shift one column left or right
- if (col < 0 || col == sequence.length)
+ if (col < 0)
+ {
+ break;
+ }
+ if (col == sequence.length)
{
+ col--; // return last column if we failed to reach pos
break;
}
if (!Comparison.isGap(sequence[col]))
}
col++; // convert back to base 1
- updateCursor(pos, col, curs.firstColumnPosition);
+
+ /*
+ * only update cursor if we found the target position
+ */
+ if (newPos == pos)
+ {
+ updateCursor(pos, col, curs.firstColumnPosition);
+ }
return col;
}
* {@inheritDoc}
*/
@Override
- public Range findPositions(int fromColumn, int toColumn)
+ public ContiguousI findPositions(int fromColumn, int toColumn)
{
if (toColumn < fromColumn || fromColumn < 1)
{
return map;
}
+ /**
+ * Build a bitset corresponding to sequence gaps
+ *
+ * @return a BitSet where set values correspond to gaps in the sequence
+ */
+ @Override
+ public BitSet gapBitset()
+ {
+ BitSet gaps = new BitSet(sequence.length);
+ int j = 0;
+ while (j < sequence.length)
+ {
+ if (jalview.util.Comparison.isGap(sequence[j]))
+ {
+ gaps.set(j);
+ }
+ j++;
+ }
+ return gaps;
+ }
+
@Override
public int[] findPositionMap()
{
@Override
public List<int[]> getInsertions()
{
- ArrayList<int[]> map = new ArrayList<int[]>();
+ ArrayList<int[]> map = new ArrayList<>();
int lastj = -1, j = 0;
int pos = start;
int seqlen = sequence.length;
boolean createNewDs = false;
// TODO: take a (second look) at the dataset creation validation method for
// the very large sequence case
+
int startIndex = findIndex(start) - 1;
int endIndex = findIndex(end) - 1;
int startDeleteColumn = -1; // for dataset sequence deletions
int deleteCount = 0;
- for (int s = i; s < j; s++)
+ for (int s = i; s < j && s < sequence.length; s++)
{
if (Comparison.isGap(sequence[s]))
{
{
if (this.annotation == null)
{
- this.annotation = new Vector<AlignmentAnnotation>();
+ this.annotation = new Vector<>();
}
if (!this.annotation.contains(annotation))
{
return null;
}
- Vector<AlignmentAnnotation> subset = new Vector<AlignmentAnnotation>();
+ Vector<AlignmentAnnotation> subset = new Vector<>();
Enumeration<AlignmentAnnotation> e = annotation.elements();
while (e.hasMoreElements())
{
public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
String label)
{
- List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> result = new ArrayList<>();
if (this.annotation != null)
{
for (AlignmentAnnotation ann : annotation)
}
synchronized (dbrefs)
{
- List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
+ List<DBRefEntry> primaries = new ArrayList<>();
DBRefEntry[] tmp = new DBRefEntry[1];
for (DBRefEntry ref : dbrefs)
{
List<SequenceFeature> result = getFeatures().findFeatures(startPos,
endPos, types);
+ if (datasetSequence != null)
+ {
+ result = datasetSequence.getFeatures().findFeatures(startPos, endPos,
+ types);
+ }
+ else
+ {
+ result = sequenceFeatureStore.findFeatures(startPos, endPos, types);
+ }
/*
* if end column is gapped, endPos may be to the right,
return count;
}
+
+ @Override
+ public String getSequenceStringFromIterator(Iterator<int[]> it)
+ {
+ StringBuilder newSequence = new StringBuilder();
+ while (it.hasNext())
+ {
+ int[] block = it.next();
+ if (it.hasNext())
+ {
+ newSequence.append(getSequence(block[0], block[1] + 1));
+ }
+ else
+ {
+ newSequence.append(getSequence(block[0], block[1]));
+ }
+ }
+
+ return newSequence.toString();
+ }
+
+ @Override
+ public int firstResidueOutsideIterator(Iterator<int[]> regions)
+ {
+ int start = 0;
+
+ if (!regions.hasNext())
+ {
+ return findIndex(getStart()) - 1;
+ }
+
+ // Simply walk along the sequence whilst watching for region
+ // boundaries
+ int hideStart = getLength();
+ int hideEnd = -1;
+ boolean foundStart = false;
+
+ // step through the non-gapped positions of the sequence
+ for (int i = getStart(); i <= getEnd() && (!foundStart); i++)
+ {
+ // get alignment position of this residue in the sequence
+ int p = findIndex(i) - 1;
+
+ // update region start/end
+ while (hideEnd < p && regions.hasNext())
+ {
+ int[] region = regions.next();
+ hideStart = region[0];
+ hideEnd = region[1];
+ }
+ if (hideEnd < p)
+ {
+ hideStart = getLength();
+ }
+ // update boundary for sequence
+ if (p < hideStart)
+ {
+ start = p;
+ foundStart = true;
+ }
+ }
+
+ if (foundStart)
+ {
+ return start;
+ }
+ // otherwise, sequence was completely hidden
+ return 0;
+ }
}