package jalview.datamodel.features;
+import jalview.datamodel.ContiguousI;
import jalview.datamodel.SequenceFeature;
import java.util.ArrayList;
{
if (nestedFeatures == null)
{
- nestedFeatures = new NCList<SequenceFeature>(feature);
+ nestedFeatures = new NCList<>(feature);
return true;
}
return nestedFeatures.add(feature, false);
*/
public List<SequenceFeature> findOverlappingFeatures(long start, long end)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
findNonNestedFeatures(start, end, result);
/*
* add non-nested features (may be all features for many cases)
*/
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
result.addAll(nonNestedFeatures);
/*
{
return Collections.emptyList();
}
- return new ArrayList<SequenceFeature>(contactFeatureStarts);
+ return new ArrayList<>(contactFeatureStarts);
}
/**
{
return Collections.emptyList();
}
- return new ArrayList<SequenceFeature>(nonPositionalFeatures);
+ return new ArrayList<>(nonPositionalFeatures);
}
/**
}
/**
- * Scans all positional features to check whether the given feature group is
- * found, and returns true if found, else false
- *
- * @param featureGroup
- * @return
- */
- protected boolean findFeatureGroup(String featureGroup)
- {
- for (SequenceFeature sf : getPositionalFeatures())
- {
- String group = sf.getFeatureGroup();
- if (group == featureGroup
- || (group != null && group.equals(featureGroup)))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
* Answers true if this store has no features, else false
*
* @return
public List<SequenceFeature> getFeaturesForGroup(boolean positional,
String group)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
/*
* if we know features don't include the target group, no need
}
return result;
}
+
+ /**
+ * Adds the shift value to the start and end of all positional features.
+ * Returns true if at least one feature was updated, else false.
+ *
+ * @param shift
+ * @return
+ */
+ public synchronized boolean shiftFeatures(int shift)
+ {
+ /*
+ * Because begin and end are final fields (to ensure the data store's
+ * integrity), we have to delete each feature and re-add it as amended.
+ * (Although a simple shift of all values would preserve data integrity!)
+ */
+ boolean modified = false;
+ for (SequenceFeature sf : getPositionalFeatures())
+ {
+ modified = true;
+ int newBegin = sf.getBegin() + shift;
+ int newEnd = sf.getEnd() + shift;
+
+ /*
+ * sanity check: don't shift left of the first residue
+ */
+ if (newEnd > 0)
+ {
+ newBegin = Math.max(1, newBegin);
+ SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd,
+ sf.getFeatureGroup(), sf.getScore());
+ addFeature(sf2);
+ }
+ delete(sf);
+ }
+ return modified;
+ }
}