*/
package jalview.datamodel;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
/**
* Data structure to hold and manipulate a multiple sequence alignment
{
return dataset;
}
+
+ /**
+ * Returns an iterable collection of annotations on this alignment which match
+ * the given criteria.
+ */
+ @Override
+ public Iterable<AlignmentAnnotation> findAnnotation(SequenceI datasequence,
+ String calcId, String label)
+ {
+ List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
+ for (AlignmentAnnotation ann : annotations)
+ {
+ // only sequence-linked annotations can qualify (have a datasequence)
+ if (ann.sequenceRef == null)
+ {
+ continue;
+ }
+ boolean matchDatasequence = (ann.sequenceRef.getDatasetSequence() == datasequence);
+ final String annCalcId = ann.getCalcId();
+ boolean matchCalcId = (annCalcId != null && annCalcId.equals(calcId));
+ boolean matchLabel = (ann.label != null && ann.label.equals(label));
+ if (matchDatasequence && matchCalcId && matchLabel)
+ {
+ result.add(ann);
+ }
+ }
+ return result;
+ }
}
JMenu hideAnnotationsMenu = new JMenu();
+ JMenuItem addDatasequenceAnnotations = new JMenuItem();
+
JMenuItem sequenceFeature = new JMenuItem();
JMenuItem textColour = new JMenuItem();
showAnnotationsMenu.removeAll();
hideAnnotationsMenu.removeAll();
final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
- addAnnotationTypeToShowHide(showAnnotationsMenu,
- all, true,
- true);
- addAnnotationTypeToShowHide(hideAnnotationsMenu, all, true,
- false);
+ addAnnotationTypeToShowHide(showAnnotationsMenu, all, true, true);
+ addAnnotationTypeToShowHide(hideAnnotationsMenu, all, true, false);
showAnnotationsMenu.addSeparator();
hideAnnotationsMenu.addSeparator();
*/
public static void getAnnotationTypesForShowHide(
List<List<String>> shownTypes, List<List<String>> hiddenTypes,
- BitSet visibleGraphGroups,
- AlignmentAnnotation[] annotations, SequenceGroup sequenceGroup)
+ BitSet visibleGraphGroups, AlignmentAnnotation[] annotations,
+ SequenceGroup sequenceGroup)
{
// lookup table, key = graph group, value = list of types in the group
Map<Integer, List<String>> groupLabels = new LinkedHashMap<Integer, List<String>>();
* @param doShow
*/
protected void showHideAnnotation_actionPerformed(
- Collection<String> types,
- boolean anyType, boolean doShow)
+ Collection<String> types, boolean anyType, boolean doShow)
{
for (AlignmentAnnotation aa : ap.getAlignment()
.getAlignmentAnnotation())
.getString("label.show_annotations"));
hideAnnotationsMenu.setText(MessageManager
.getString("label.hide_annotations"));
+ final List<AlignmentAnnotation> referenceAnns = getDatasequenceAnnotationsNotOnAlignment(ap.av
+ .getSelectionGroup());
+ addDatasequenceAnnotations.setText(MessageManager
+ .getString("label.add_reference_annotations"));
+ addDatasequenceAnnotations.setEnabled(!referenceAnns.isEmpty());
+ addDatasequenceAnnotations.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ addReferenceAnnotations_actionPerformed(referenceAnns);
+ }
+ });
sequenceFeature.setText(MessageManager
.getString("label.create_sequence_feature"));
sequenceFeature.addActionListener(new ActionListener()
// groupMenu.add(chooseAnnotations);
groupMenu.add(showAnnotationsMenu);
groupMenu.add(hideAnnotationsMenu);
+ groupMenu.add(addDatasequenceAnnotations);
groupMenu.add(editMenu);
groupMenu.add(outputMenu);
groupMenu.add(sequenceFeature);
});
}
+ /**
+ * Get a list of any annotations on the dataset sequences in the current
+ * selection group that are not also on the alignment.
+ * <p/>
+ * The criteria for 'on the alignment' is finding an annotation that matches
+ * on sequenceRef.datasetSequence, calcId and label.
+ *
+ * @return
+ */
+ protected List<AlignmentAnnotation> getDatasequenceAnnotationsNotOnAlignment(
+ SequenceGroup sg)
+ {
+ List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
+
+ for (SequenceI seq : sg.getSequences())
+ {
+ SequenceI dataset = seq.getDatasetSequence();
+ AlignmentAnnotation[] datasetAnnotations = dataset.getAnnotation();
+ if (datasetAnnotations != null)
+ {
+ for (AlignmentAnnotation dsann : datasetAnnotations)
+ {
+ /*
+ * If the alignment has no annotation that matches this one...
+ */
+ if (!ap.getAlignment()
+ .findAnnotation(dataset, dsann.getCalcId(), dsann.label)
+ .iterator().hasNext())
+ {
+ /*
+ * ...then add it to the result list
+ */
+ result.add(dsann);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Add any annotations on the sequence dataset to the alignment (that are not
+ * already copied to it).
+ */
+ protected void addReferenceAnnotations_actionPerformed(
+ List<AlignmentAnnotation> anns)
+ {
+ for (AlignmentAnnotation ann : anns)
+ {
+ // todo: copy, add, adjust...
+ }
+ }
+
protected void sequenceSelectionDetails_actionPerformed()
{
createSequenceDetailsReport(ap.av.getSequenceSelection());