* Build a lookup, by calcId (annotation source), of all annotation types in
* each graph group.
*/
- Map<String, Map<Integer, List<String>>> groupLabels = new HashMap<String, Map<Integer, List<String>>>();
+ Map<String, Map<Integer, List<String>>> groupLabels = new HashMap<>();
// trackers for which calcId!label combinations we have dealt with
- List<String> addedToShown = new ArrayList<String>();
- List<String> addedToHidden = new ArrayList<String>();
+ List<String> addedToShown = new ArrayList<>();
+ List<String> addedToHidden = new ArrayList<>();
for (AlignmentAnnotation aa : annotations)
{
/*
* Build a 'composite label' for types in line graph groups.
*/
- final List<String> labelAsList = new ArrayList<String>();
+ final List<String> labelAsList = new ArrayList<>();
final String displayLabel = aa.label;
labelAsList.add(displayLabel);
if (aa.graph == AlignmentAnnotation.LINE_GRAPH
return (anns == null ? Collections.<AlignmentAnnotation> emptyList()
: Arrays.asList(anns));
}
+
+ /**
+ * replace an existing sequence associated annotation with another, creating
+ * association as necessary.
+ *
+ * @param newAnnot
+ * - annotation row associated with a sequence to be propagated to
+ * its reference annotation
+ * @param typeName
+ * - label used to match existing row
+ * @param calcId
+ * - calcId for existing row
+ */
+ public static void replaceAnnotationOnAlignmentWith(
+ AlignmentAnnotation newAnnot, String typeName, String calcId)
+ {
+ if (newAnnot.sequenceRef != null)
+ {
+ SequenceI dsseq = newAnnot.sequenceRef;
+ while (dsseq.getDatasetSequence() != null)
+ {
+ dsseq = dsseq.getDatasetSequence();
+ }
+ // look for same annotation on dataset and lift this one over
+ List<AlignmentAnnotation> dsan = dsseq.getAlignmentAnnotations(calcId,
+ typeName);
+ if (dsan != null && dsan.size() > 0)
+ {
+ for (AlignmentAnnotation dssan : dsan)
+ {
+ dsseq.removeAlignmentAnnotation(dssan);
+ }
+ }
+ AlignmentAnnotation dssan = new AlignmentAnnotation(newAnnot);
+ dsseq.addAlignmentAnnotation(dssan);
+ dssan.adjustForAlignment();
+ }
+ }
}
*/
package jalview.api;
+import jalview.datamodel.features.FeatureMatcherSetI;
+
import java.util.Comparator;
/**
FeatureColourI getFeatureColour(String type);
/**
+ * Returns any filters defined for the feature type, or null if not known
+ *
+ * @param type
+ * @return
+ */
+
+ FeatureMatcherSetI getFeatureFilters(String type);
+
+ /**
* Returns the transparency value, from 0 (fully transparent) to 1 (fully
* opaque)
*
String calcId, boolean autoCalc, SequenceI seqRef,
SequenceGroup groupRef)
{
- if (annotations != null)
+ AlignmentAnnotation annot = annotations == null ? null
+ : AlignmentAnnotation.findFirstAnnotation(
+ Arrays.asList(getAlignmentAnnotation()), name, calcId,
+ autoCalc, seqRef, groupRef);
+
+ if (annot == null)
{
- for (AlignmentAnnotation annot : getAlignmentAnnotation())
+
+ annot = new AlignmentAnnotation(name, name, new Annotation[1], 0f, 0f,
+ AlignmentAnnotation.BAR_GRAPH);
+ annot.hasText = false;
+ if (calcId != null)
{
- if (annot.autoCalculated == autoCalc && (name.equals(annot.label))
- && (calcId == null || annot.getCalcId().equals(calcId))
- && annot.sequenceRef == seqRef
- && annot.groupRef == groupRef)
- {
- return annot;
- }
+ annot.setCalcId(calcId);
+ }
+ annot.autoCalculated = autoCalc;
+ if (seqRef != null)
+ {
+ annot.setSequenceRef(seqRef);
}
+ annot.groupRef = groupRef;
+ addAnnotation(annot);
}
- AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
- new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
- annot.hasText = false;
- if (calcId != null)
+ return annot;
+ }
+
+
+ @Override
+ public AlignmentAnnotation updateFromOrCopyAnnotation(
+ AlignmentAnnotation ala)
+ {
+ AlignmentAnnotation annot = AlignmentAnnotation.findFirstAnnotation(
+ Arrays.asList(getAlignmentAnnotation()), ala.label, ala.calcId,
+ ala.autoCalculated, ala.sequenceRef, ala.groupRef);
+ if (annot == null)
{
- annot.setCalcId(calcId);
+ annot = new AlignmentAnnotation(ala);
+ addAnnotation(annot);
}
- annot.autoCalculated = autoCalc;
- if (seqRef != null)
+ else
{
- annot.setSequenceRef(seqRef);
+ annot.updateAlignmentAnnotationFrom(ala);
}
- annot.groupRef = groupRef;
- addAnnotation(annot);
-
+ validateAnnotation(annot);
return annot;
}
public AlignmentAnnotation(AlignmentAnnotation annotation)
{
setAnnotationId();
+ updateAlignmentAnnotationFrom(annotation);
+ }
+
+ /**
+ * copy attributes and annotation from an existing annotation (used by copy
+ * constructor). This method does not update the unique annotationId
+ *
+ * @param annotation
+ */
+ public void updateAlignmentAnnotationFrom(AlignmentAnnotation annotation)
+ {
this.label = new String(annotation.label);
if (annotation.description != null)
{
this.eValue = eValue;
}
+ public static AlignmentAnnotation findFirstAnnotation(
+ Iterable<AlignmentAnnotation> alignmentAnnotation, String name,
+ String calcId, boolean autoCalc, SequenceI seqRef,
+ SequenceGroup groupRef)
+ {
+
+ for (AlignmentAnnotation annot : alignmentAnnotation)
+ {
+ if (annot.autoCalculated == autoCalc && (name.equals(annot.label))
+ && (calcId == null || annot.getCalcId().equals(calcId))
+ && annot.sequenceRef == seqRef && annot.groupRef == groupRef)
+ {
+ return annot;
+ }
+ }
+ return null;
+ }
+
}
boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef);
/**
+ * like findOrCreateAnnotation - looks for an existing alignment annotation
+ * row with matching name, calcId, sequenceRef, groupRef and autoCalculated
+ * flag and updates it from the annotation. If none is found the annotation is
+ * added directly.
+ *
+ * @param ala
+ * @return ala or the annotation row that was updated.
+ */
+ AlignmentAnnotation updateFromOrCopyAnnotation(AlignmentAnnotation ala);
+
+ /**
* move the given group up or down in the alignment by the given number of
* rows. Implementor assumes given group is already present on alignment - no
* recalculations are triggered.
@Override
public ContiguousI findPositions(int fromColumn, int toColumn)
{
- if (toColumn < fromColumn || fromColumn < 1)
+ fromColumn = Math.max(fromColumn, 1);
+ if (toColumn < fromColumn)
{
return null;
}
* from 1), or null if no residues are included in the range
*
* @param fromColum
- * - first column base 1
+ * - first column base 1. (0 and negative positions are rounded up)
* @param toColumn
* - last column, base 1
- * @return
+ * @return null if fromColum>toColumn
*/
public ContiguousI findPositions(int fromColum, int toColumn);
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.renderer.ResidueShader;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
{
FeatureColourI preferredColour = featureSettings
.getFeatureColour(type);
+ FeatureMatcherSetI preferredFilters = featureSettings
+ .getFeatureFilters(type);
+
FeatureColourI origColour = fr.getFeatureStyle(type);
if (!mergeOnly || (!origRenderOrder.contains(type)
|| origColour == null
{
fr.setColour(type, preferredColour);
}
+ if (preferredFilters != null
+ && (!mergeOnly || fr.getFeatureFilter(type) != null))
+ {
+ fr.setFeatureFilter(type, preferredFilters);
+ }
if (featureSettings.isFeatureDisplayed(type))
{
displayed.setVisible(type);
import jalview.api.FeatureColourI;
import jalview.api.FeatureSettingsModelI;
+import jalview.datamodel.features.FeatureMatcherSetI;
/**
* An adapter class that may be extended to instantiate feature colour schemes
return false;
}
+ @Override
+ public FeatureMatcherSetI getFeatureFilters(String type)
+ {
+ return null;
+ }
+
}
package jalview.ws.api;
+import jalview.api.FeatureColourI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceI;
-import jalview.ws.gui.AnnotationWsJob;
-import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.WsParamSetI;
import java.util.List;
+import java.util.Map;
public interface SequenceAnnotationServiceI extends JalviewWebServiceI
{
List<ArgumentI> paramset) throws Throwable;
/**
- * todo: move to SequenceAnnotationResult
+ * materialise annotation and features for sequences input to the service
*
- * @param running
- * @param abstractJabaCalcWorker
- * @return
+ * @param job
+ * @param seqs
+ * - features and alignment annotation added to these will be
+ * imported to the dataset for the alignment
+ * @param featureColours
+ * - container for feature colours - any defined will be merged with
+ * viewport
+ * @param featureFilters
+ * - container for filters - any defined will be merged with viewport
+ * @return sequence and alignment annotation rows that should be made
+ * visible/updated on alignment
+ * @throws Throwable
*/
- List<AlignmentAnnotation> getAlignmentAnnotation(AnnotationWsJob running,
- SeqAnnotationServiceCalcWorker abstractJabaCalcWorker) throws Throwable;
-
+ List<AlignmentAnnotation> getAnnotationResult(JobId job,
+ List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters) throws Throwable;
+
}
package jalview.ws.jws2;
import jalview.analysis.AlignSeq;
+import jalview.analysis.AlignmentAnnotationUtils;
import jalview.analysis.SeqsetUtils;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureColourI;
import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.ContiguousI;
+import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
import jalview.gui.IProgressIndicator;
import jalview.gui.IProgressIndicatorHandler;
import jalview.gui.JvOptionPane;
+import jalview.schemes.FeatureSettingsAdapter;
import jalview.schemes.ResidueProperties;
+import jalview.util.MapList;
import jalview.util.MessageManager;
import jalview.workers.AlignCalcWorker;
import jalview.ws.api.CancellableI;
bySequence = !service.isAlignmentAnalysis();
filterNonStandardResidues = service.isFilterSymbols();
min_valid_seqs = service.getMinimumInputSequences();
+ submitGaps = service.isAlignmentAnalysis();
if (service.isInteractiveUpdate())
{
return;
}
- AlignmentAnnotation[] aa = alignViewport.getAlignment()
- .getAlignmentAnnotation();
if (guiProgress != null)
{
guiProgress.setProgressBar(service.getActionText(),
// and poll for updates until job finishes, fails or becomes stale
boolean finished = false;
- long rpos = 0;
do
{
Cache.log.debug("Updating status for annotation service.");
if (cancellable
&& ((CancellableI) annotService).cancel(running))
{
- System.err.println("Cancelled AACon job: " + rslt);
+ System.err.println("Cancelled job: " + rslt);
}
else
{
- System.err.println("FAILED TO CANCEL AACon job: " + rslt);
+ System.err.println("FAILED TO CANCEL job: " + rslt);
}
} catch (Exception x)
running.setFeatureRenderer(
((jalview.gui.AlignmentPanel) ap).cloneFeatureRenderer());
Cache.log.debug("retrieving job results.");
+ final Map<String, FeatureColourI> featureColours = new HashMap<>();
+ final Map<String, FeatureMatcherSetI> featureFilters = new HashMap<>();
List<AlignmentAnnotation> returnedAnnot = annotService
- .getAlignmentAnnotation(running, this);
+ .getAnnotationResult(running.getJobHandle(), seqs,
+ featureColours, featureFilters);
+
Cache.log.debug("Obtained " + (returnedAnnot == null ? "no rows"
: ("" + returnedAnnot.size())));
+ Cache.log.debug("There were " + featureColours.size()
+ + " feature colours and " + featureFilters.size()
+ + " filters defined.");
+
+ // TODO
+ // copy over each annotation row reurned and also defined on each
+ // sequence, excluding regions not annotated due to gapMap/column
+ // visibility
+
running.setAnnotation(returnedAnnot);
if (running.hasResults())
updateResultAnnotation(true);
if (running.isTransferSequenceFeatures())
{
+ // TODO
+ // look at each sequence and lift over any features, excluding regions
+ // not annotated due to gapMap/column visibility
+
jalview.bin.Cache.log.debug(
"Updating feature display settings and transferring features from Job "
+ rslt + " at " + service.getUri());
- ((jalview.gui.AlignmentPanel) ap)
- .updateFeatureRendererFrom(running.getFeatureRenderer());
+ // TODO: consider merge rather than apply here
+ alignViewport.applyFeaturesStyle(new FeatureSettingsAdapter()
+ {
+ @Override
+ public FeatureColourI getFeatureColour(String type)
+ {
+ return featureColours.get(type);
+ }
+
+ @Override
+ public FeatureMatcherSetI getFeatureFilters(String type)
+ {
+ return featureFilters.get(type);
+ }
+
+ @Override
+ public boolean isFeatureDisplayed(String type)
+ {
+ return featureColours.containsKey(type);
+ }
+
+ });
// TODO: JAL-1150 - create sequence feature settings API for defining
// styles and enabling/disabling feature overlay on alignment panel
if (alignFrame.alignPanel == ap)
{
- // only do this if the alignFrame is currently showing this view.
- Desktop.getAlignFrameFor(alignViewport)
- .setShowSeqFeatures(true);
+ alignViewport.setShowSequenceFeatures(true);
+ alignFrame.setMenusForViewport();
}
}
ap.adjustAnnotationHeight();
if ((immediate || !calcMan.isWorking(this)) && running != null
&& running.hasResults())
{
- List<AlignmentAnnotation> ourAnnot = running.getAnnotation();
- updateOurAnnots(ourAnnot);
+ List<AlignmentAnnotation> ourAnnot = running.getAnnotation(),
+ newAnnots = new ArrayList<>();
+ //
+ // update graphGroup for all annotation
+ //
+ /**
+ * find a graphGroup greater than any existing ones this could be a method
+ * provided by alignment Alignment.getNewGraphGroup() - returns next
+ * unused graph group
+ */
+ int graphGroup = 1;
+ if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
+ {
+ for (AlignmentAnnotation ala : alignViewport.getAlignment()
+ .getAlignmentAnnotation())
+ {
+ if (ala.graphGroup > graphGroup)
+ {
+ graphGroup = ala.graphGroup;
+ }
+ }
+ }
+ /**
+ * update graphGroup in the annotation rows returned from service
+ */
+ // TODO: look at sequence annotation rows and update graph groups in the
+ // case of reference annotation.
+ for (AlignmentAnnotation ala : ourAnnot)
+ {
+ if (ala.graphGroup > 0)
+ {
+ ala.graphGroup += graphGroup;
+ }
+ SequenceI aseq = null;
+
+ /**
+ * transfer sequence refs and adjust gapmap
+ */
+ if (ala.sequenceRef != null)
+ {
+ SequenceI seq = running.getSeqNames()
+ .get(ala.sequenceRef.getName());
+ aseq = seq;
+ while (seq.getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ }
+ Annotation[] resAnnot = ala.annotations,
+ gappedAnnot = new Annotation[Math.max(
+ alignViewport.getAlignment().getWidth(),
+ gapMap.length)];
+ for (int p = 0, ap = start; ap < gappedAnnot.length; ap++)
+ {
+ if (gapMap != null && gapMap.length > ap && !gapMap[ap])
+ {
+ gappedAnnot[ap] = new Annotation("", "", ' ', Float.NaN);
+ }
+ else if (p < resAnnot.length)
+ {
+ gappedAnnot[ap] = resAnnot[p++];
+ }
+ }
+ ala.sequenceRef = aseq;
+ ala.annotations = gappedAnnot;
+ AlignmentAnnotation newAnnot = getAlignViewport().getAlignment()
+ .updateFromOrCopyAnnotation(ala);
+ if (aseq != null)
+ {
+
+ aseq.addAlignmentAnnotation(newAnnot);
+ newAnnot.adjustForAlignment();
+
+ AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(
+ newAnnot, newAnnot.label, newAnnot.getCalcId());
+ }
+ newAnnots.add(newAnnot);
+
+ }
+ for (SequenceI sq : running.getSeqs())
+ {
+ if (!sq.getFeatures().hasFeatures()
+ && (sq.getDBRefs() == null || sq.getDBRefs().length == 0))
+ {
+ continue;
+ }
+ running.setTransferSequenceFeatures(true);
+ SequenceI seq = running.getSeqNames().get(sq.getName());
+ SequenceI dseq;
+ ContiguousI seqRange = seq.findPositions(start, end);
+
+ while ((dseq = seq).getDatasetSequence() != null)
+ {
+ seq = seq.getDatasetSequence();
+ }
+ List<ContiguousI> sourceRange = new ArrayList();
+ if (gapMap != null && gapMap.length >= end)
+ {
+ int lastcol = start, col = start;
+ do
+ {
+ if (col == end || !gapMap[col])
+ {
+ if (lastcol <= (col - 1))
+ {
+ seqRange = seq.findPositions(lastcol, col);
+ sourceRange.add(seqRange);
+ }
+ lastcol = col + 1;
+ }
+ } while (++col <= end);
+ }
+ else
+ {
+ sourceRange.add(seq.findPositions(start, end));
+ }
+ int i = 0;
+ int source_startend[] = new int[sourceRange.size() * 2];
+
+ for (ContiguousI range : sourceRange)
+ {
+ source_startend[i++] = range.getBegin();
+ source_startend[i++] = range.getEnd();
+ }
+ Mapping mp = new Mapping(
+ new MapList(source_startend, new int[]
+ { seq.getStart(), seq.getEnd() }, 1, 1));
+ dseq.transferAnnotation(sq, mp);
+
+ }
+ updateOurAnnots(newAnnots);
}
}
}
}
our.clear();
- // validate rows and update Alignmment state
- for (AlignmentAnnotation an : ourAnnots)
- {
- alignViewport.getAlignment().validateAnnotation(an);
- }
- // TODO: may need a menu refresh after this
- // af.setMenusForViewport();
- ap.adjustAnnotationHeight();
}
+
+ // validate rows and update Alignmment state
+ for (AlignmentAnnotation an : ourAnnots)
+ {
+ alignViewport.getAlignment().validateAnnotation(an);
+ }
+ // TODO: may need a menu refresh after this
+ // af.setMenusForViewport();
+ ap.adjustAnnotationHeight();
+
}
public SequenceAnnotationServiceI getService()
*/
package jalview.ws.jws2.jabaws2;
-import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.util.MessageManager;
-import jalview.ws.gui.AnnotationWsJob;
import jalview.ws.uimodel.AlignAnalysisUIText;
import java.util.ArrayList;
}
@Override
- List<AlignmentAnnotation> annotationFromScoreManager(
- AnnotationWsJob running, AlignViewportI alignViewport,
- boolean[] gapMap)
+ List<AlignmentAnnotation> annotationFromScoreManager(AlignmentI seqs,
+ Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters)
{
+ return aacons_annotation(seqs.getWidth(), seqs, null);
+ }
+ private List<AlignmentAnnotation> aacons_annotation(int alWidth,
+ AlignmentI alignViewport, boolean[] gapMap)
+ {
Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
- int alWidth = alignViewport.getAlignment().getWidth();
ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<>();
for (String score : scoremap.keySet())
{
}
else
{
- createAnnotationRowsForScores(alignViewport, gapMap, ourAnnot,
- getCalcId(), alWidth, scr);
+ createAnnotationRowsForScores(alignViewport, null, ourAnnot,
+ getCalcId(),
+ scr.getScores().size(), scr);
}
}
}
*/
package jalview.ws.jws2.jabaws2;
-import jalview.api.AlignViewportI;
+import jalview.analysis.AlignmentAnnotationUtils;
import jalview.api.FeatureColourI;
import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.GraphLine;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.schemes.FeatureColour;
import jalview.util.ColorUtils;
-import jalview.ws.gui.AnnotationWsJob;
import java.awt.Color;
import java.util.ArrayList;
}
@Override
- List<AlignmentAnnotation> annotationFromScoreManager(
- AnnotationWsJob running, AlignViewportI alignViewport,
- boolean[] gapMap)
+ List<AlignmentAnnotation> annotationFromScoreManager(AlignmentI seqs,
+ Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters)
{
Map<String, String[]> featureTypeMap = featureMap.get(our.getName());
Map<String, Map<String, Object>> annotTypeMap = annotMap
.get(our.getName());
boolean dispFeatures = false;
- Map<String, Object> fc = new Hashtable<>();
+ Map<String, SequenceFeature> fc = new Hashtable<>(),
+ fex = new Hashtable();
List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
- /**
- * grouping for any annotation rows created
- */
- int graphGroup = 1;
- if (alignViewport.getAlignment().getAlignmentAnnotation() != null)
- {
- for (AlignmentAnnotation ala : alignViewport.getAlignment()
- .getAlignmentAnnotation())
- {
- if (ala.graphGroup > graphGroup)
- {
- graphGroup = ala.graphGroup;
- }
- }
- }
+ int graphGroup = 1, lastAnnot = 0;
- // TODO: downgrade code below so we don't annotate sequences directly
- Map<String, SequenceI> seqNames = running.getSeqNames();
- int start = running.getStartPos();
- for (String seqId : seqNames.keySet())
+ for (SequenceI seq : seqs.getSequences())
{
+ String seqId = seq.getName();
boolean sameGroup = false;
- SequenceI dseq, aseq, seq = seqNames.get(seqId);
- int base = seq.findPosition(start) - 1;
+ SequenceI dseq, aseq;
+ int base = seq.findPosition(0) - 1;
aseq = seq;
while ((dseq = seq).getDatasetSequence() != null)
{
{
Cache.log.info("Couldn't recover disorder prediction for sequence "
+ seq.getName() + "(Prediction name was " + seqId + ")"
- + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.");
+ + "\nSee http://issues.jalview.org/browse/JAL-1319 for one possible reason why disorder predictions might fail.",
+ q);
}
float last = Float.NaN, val = Float.NaN;
- int lastAnnot = ourAnnot.size();
if (scores != null && scores.scores != null)
{
for (Score scr : scores.scores)
// make features on sequence
for (Range rn : scr.getRanges())
{
-
+ // TODO: Create virtual feature settings
SequenceFeature sf;
String[] type = featureTypeMap.get(scr.getMethod());
if (type == null)
base + rn.to, methodName);
}
dseq.addSequenceFeature(sf);
- if (last != val && !Float.isNaN(last))
+ // mark feature as requiring a graduated colourscheme if has
+ // variable scores
+ if (!Float.isNaN(last) && !Float.isNaN(val) && last != val)
{
fc.put(sf.getType(), sf);
+ } else
+ {
+ fex.put(sf.getType(), sf);
}
last = val;
- running.setTransferSequenceFeatures(true);
dispFeatures = true;
}
}
}
String typename, calcName;
AlignmentAnnotation annot = createAnnotationRowsForScores(
- alignViewport, gapMap, ourAnnot,
+ seqs, null, ourAnnot,
typename = our.getName() + " (" + scr.getMethod() + ")",
calcName = our.getNameURI() + "/" + scr.getMethod(),
aseq, base + 1, scr);
}
annot._linecolour = col;
// finally, update any dataset annotation
- replaceAnnotationOnAlignmentWith(annot, typename, calcName,
- aseq);
+ AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(annot,
+ typename, calcName);
}
}
}
{
if (dispFeatures)
{
- jalview.api.FeatureRenderer fr = running.getFeatureRenderer();
- for (String ft : fc.keySet())
+ // TODO: virtual feature settings
+ // feature colours need to merged with current viewport's colours
+ // simple feature colours promoted to colour-by-score ranges using
+ // currently assigned or created feature colour
+ for (String ft : fex.keySet())
{
- FeatureColourI gc = fr.getFeatureStyle(ft);
- if (gc.isSimpleColour())
+ Color col = ColorUtils.createColourFromName(ft);
+ // set graduated color as fading to white for minimum, and
+ // autoscaling to values on alignment
+
+ FeatureColourI ggc;
+ if (fc.get(ft) != null)
{
- // set graduated color as fading to white for minimum, and
- // autoscaling to values on alignment
- FeatureColourI ggc = new FeatureColour(gc.getColour(),
- Color.white, gc.getColour(), Color.white,
- Float.MIN_VALUE, Float.MAX_VALUE);
+ ggc = new FeatureColour(col, Color.white, col,
+
+ Color.white, Float.MIN_VALUE, Float.MAX_VALUE);
ggc.setAutoScaled(true);
- fr.setColour(ft, ggc);
}
+ else
+ {
+ ggc = new FeatureColour(col);
+ }
+ featureColours.put(ft, ggc);
}
}
package jalview.ws.jws2.jabaws2;
-import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
+import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.util.MessageManager;
import jalview.ws.api.JobId;
import jalview.ws.api.SequenceAnnotationServiceI;
-import jalview.ws.gui.AnnotationWsJob;
import jalview.ws.jws2.JabaParamStore;
import jalview.ws.jws2.JabaPreset;
-import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.WsParamSetI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import compbio.data.msa.SequenceAnnotation;
import compbio.data.sequence.FastaSequence;
return new JobId(our.getServiceType(), our.getName(), rslt);
}
+
@Override
- public List<AlignmentAnnotation> getAlignmentAnnotation(
- AnnotationWsJob running,
- SeqAnnotationServiceCalcWorker abstractJabaCalcWorker) throws Throwable
+ public
+ List<AlignmentAnnotation> getAnnotationResult(JobId job,
+ List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters) throws Throwable
{
if (scoremanager == null)
{
// TODO: raise annotation unavailable exception ?
- scoremanager = service.getAnnotation(running.getJobId());
+ scoremanager = service.getAnnotation(job.getJobId());
}
if (scoremanager == null)
{
return List.of();
}
-
- return annotationFromScoreManager(running,
- abstractJabaCalcWorker.getAlignViewport(),
- abstractJabaCalcWorker.getGapMap());
+ /**
+ * dummy alignment to perform annotation on
+ */
+ AlignmentI newal = new Alignment(seqs.toArray(new SequenceI[0]));
+ List<AlignmentAnnotation> ourAnnot = annotationFromScoreManager(newal,
+ featureColours, featureFilters);
+ return ourAnnot;
}
/**
* service specific annotation creation method
*
- * @param running
- * @param alignViewport
- * @param gapMap
+ * @param seqs
+ * - sequences to be annotated with results
+ * @param featureColours
+ * - - updated with any colours imported during result processing
+ * @param featureFilters
+ * - updated with any filters imported during result processing
+ *
* @return
*/
abstract List<AlignmentAnnotation> annotationFromScoreManager(
- AnnotationWsJob running,
- AlignViewportI alignViewport, boolean[] gapMap);
+ AlignmentI seqs, Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters);
+
/**
* create and complete an annotation row from a JABAWS score object
* @param scr
*/
- protected void createAnnotationRowsForScores(AlignViewportI alignViewport,
+ protected void createAnnotationRowsForScores(AlignmentI al_result,
boolean[] gapMap, List<AlignmentAnnotation> ourAnnot,
String calcId,
int alWidth, Score scr)
{
// simple annotation row
- AlignmentAnnotation annotation = alignViewport.getAlignment()
+ AlignmentAnnotation annotation = al_result
.findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
null);
- if (alWidth == gapMap.length) // scr.getScores().size())
+ if (gapMap == null || alWidth == gapMap.length) // scr.getScores().size())
{
constructAnnotationFromScore(gapMap, annotation, 0,
alWidth, scr);
* @return
*/
protected AlignmentAnnotation createAnnotationRowsForScores(
- AlignViewportI alignViewport, boolean[] gapMap,
+ AlignmentI alignment, boolean[] gapMap,
List<AlignmentAnnotation> ourAnnot, String typeName,
String calcId, SequenceI dseq, int base, Score scr)
{
// scr.getMethod(), typeName, new Annotation[]
// {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
// annotation.setCalcId(calcId);
- AlignmentAnnotation annotation = alignViewport.getAlignment()
+ AlignmentAnnotation annotation = alignment
.findOrCreateAnnotation(typeName, calcId, false, dseq, null);
constructAnnotationFromScore(gapMap, annotation, 0, dseq.getLength(),
scr);
}
/**
- * replace an existing sequence associated annotation with another, creating
- * association as necessary
- *
- * @param newAnnot
- * - annotation row used to create an instance on the dataset
- * sequence.
- * @param typeName
- * - label used to match existing row
- * @param calcId
- * - calcId for existing row
- * @param aSeq
- * - alignment sequence with reference to destination dataet sequence
- */
- protected void replaceAnnotationOnAlignmentWith(
- AlignmentAnnotation newAnnot, String typeName, String calcId,
- SequenceI aSeq)
- {
- SequenceI dsseq = aSeq.getDatasetSequence();
- while (dsseq.getDatasetSequence() != null)
- {
- dsseq = dsseq.getDatasetSequence();
- }
- // look for same annotation on dataset and lift this one over
- List<AlignmentAnnotation> dsan = dsseq.getAlignmentAnnotations(calcId,
- typeName);
- if (dsan != null && dsan.size() > 0)
- {
- for (AlignmentAnnotation dssan : dsan)
- {
- dsseq.removeAlignmentAnnotation(dssan);
- }
- }
- AlignmentAnnotation dssan = new AlignmentAnnotation(newAnnot);
- dsseq.addAlignmentAnnotation(dssan);
- dssan.adjustForAlignment();
- }
-
- /**
* create column annotation elements from Jabaws score object
*
* @param gapMap
*/
package jalview.ws.jws2.jabaws2;
-import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.util.MessageManager;
-import jalview.ws.gui.AnnotationWsJob;
import jalview.ws.uimodel.AlignAnalysisUIText;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.TreeSet;
import java.util.regex.Pattern;
}
@Override
- List<AlignmentAnnotation> annotationFromScoreManager(
- AnnotationWsJob running, AlignViewportI alignViewport,
- boolean[] gapMap)
+ List<AlignmentAnnotation> annotationFromScoreManager(AlignmentI seqs,
+ Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters)
{
List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
.equals(AlifoldResult.contactProbabilities.toString()));
// add annotation for the consensus sequence alignment
- createAnnotationRowforScoreHolder(alignViewport, gapMap, ourAnnot,
+ createAnnotationRowforScoreHolder(seqs, null,
+ ourAnnot,
getCalcId(), structs.get(0), null, null);
// Add annotations for the mfe Structure
- createAnnotationRowforScoreHolder(alignViewport, gapMap, ourAnnot,
+ createAnnotationRowforScoreHolder(seqs, null,
+ ourAnnot,
getCalcId(), structs.get(1), data.get(1), null);
// decide whether to add base pair contact probability histogram
int count = 2;
if (bpScores)
{
- createAnnotationRowforScoreHolder(alignViewport, gapMap, ourAnnot,
+ createAnnotationRowforScoreHolder(seqs, null,
+ ourAnnot,
getCalcId(), structs.get(2), data.get(0), data.get(2));
count++;
}
.equals(AlifoldResult.ensembleValues.toString()))
{
- createAnnotationRowforScoreHolder(alignViewport, gapMap, ourAnnot,
+ createAnnotationRowforScoreHolder(seqs, null, ourAnnot,
getCalcId(), structs.get(i), data.get(i), null);
}
}
}
private static void createAnnotationRowforScoreHolder(
- AlignViewportI alignViewport, boolean[] gapMap,
+ AlignmentI alignment, boolean[] gapMap,
List<AlignmentAnnotation> ourAnnot, String calcId, String struct,
TreeSet<Score> data, TreeSet<Score> descriptionData)
{
String typename = typenameAndDescription[0];
String description = typenameAndDescription[1];
- AlignmentAnnotation annotation = alignViewport.getAlignment()
+ AlignmentAnnotation annotation = alignment
.findOrCreateAnnotation(typename, calcId, false, null, null);
constructAnnotationFromScoreHolder(gapMap, annotation, struct, data);
package jalview.ws.slivkaws;
+import jalview.api.FeatureColourI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.ws.api.JobId;
import jalview.ws.api.SequenceAnnotationServiceI;
-import jalview.ws.gui.AnnotationWsJob;
-import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.WsParamSetI;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import uk.ac.dundee.compbio.slivkaclient.FormField;
import uk.ac.dundee.compbio.slivkaclient.RemoteFile;
}
@Override
- public List<AlignmentAnnotation> getAlignmentAnnotation(AnnotationWsJob running,
- SeqAnnotationServiceCalcWorker abstractJabaCalcWorker) throws Throwable
+ public List<AlignmentAnnotation> getAnnotationResult(JobId job,
+ List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
+ Map<String, FeatureMatcherSetI> featureFilters) throws Throwable
{
// TODO Auto-generated method stub
return null;
createAnnotation(sq);
AlignmentAnnotation alc, alo = sq.getAnnotation()[0];
alc = new AlignmentAnnotation(alo);
+
+ // TODO: this only tests string equals (which is unreliable), should use
+ // refactored tests from StockholmFileTest
+ Assert.assertEquals(alc.toString(), alo.toString());
+
for (String key : alo.getProperties())
{
assertEquals("Property mismatch", alo.getProperty(key),
assertEquals("", ala.getCalcId());
}
+ @Test(groups = {"Functional"})
+ public void testUpdateFromOrAddAnnotation()
+ {
+ SequenceI seq = new Sequence("seq1", "FRMLPSRT-A--L-");
+ AlignmentI alignment = new Alignment(new SequenceI[] { seq });
+
+ AlignmentAnnotation ala = alignment.findOrCreateAnnotation(
+ "Temperature Factor", null, false, seq, null);
+
+ assertNotNull(ala);
+ assertEquals(seq, ala.sequenceRef);
+ assertEquals("", ala.getCalcId());
+
+ // Assuming findOrCreateForNullCalcId passed then this should work
+
+ assertTrue(ala == alignment.updateFromOrCopyAnnotation(ala));
+ AlignmentAnnotation updatedAla = new AlignmentAnnotation(ala);
+ updatedAla.description = "updated Description";
+ Assert.assertTrue(
+ ala == alignment.updateFromOrCopyAnnotation(updatedAla));
+ Assert.assertEquals(ala.toString(), updatedAla.toString());
+ updatedAla.calcId = "newCalcId";
+ AlignmentAnnotation newUpdatedAla = alignment
+ .updateFromOrCopyAnnotation(updatedAla);
+ Assert.assertTrue(updatedAla != newUpdatedAla);
+ Assert.assertEquals(updatedAla.toString(), newUpdatedAla.toString());
+ }
+
@Test(groups = "Functional")
public void testPropagateInsertions()
{
* invalid inputs
*/
assertNull(sq.findPositions(6, 5));
- assertNull(sq.findPositions(0, 5));
- assertNull(sq.findPositions(-1, 5));
/*
* all gapped ranges
assertEquals(new Range(11, 12), sq.findPositions(5, 10)); // DE
assertEquals(new Range(8, 13), sq.findPositions(1, 13)); // the lot
assertEquals(new Range(8, 13), sq.findPositions(1, 99));
+
+ /**
+ * now try on a sequence with no gaps
+ */
+ sq.createDatasetSequence();
+ assertEquals(new Range(8, 13),
+ sq.getDatasetSequence().findPositions(1, 99));
+ assertEquals(new Range(8, 13),
+ sq.getDatasetSequence().findPositions(0, 99));
+
}
/**