From 770a6a7d91b1f46a7d0372b987f859b35f286ad8 Mon Sep 17 00:00:00 2001 From: "j.procter@dundee.ac.uk" Date: Fri, 8 Aug 2014 17:46:52 +0100 Subject: [PATCH] JAL-1483 sort by feature score/density made first class alignment view controller operation --- src/jalview/api/AlignViewControllerI.java | 12 ++++ src/jalview/controller/AlignViewController.java | 74 +++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/src/jalview/api/AlignViewControllerI.java b/src/jalview/api/AlignViewControllerI.java index fadc09e..090a8b5 100644 --- a/src/jalview/api/AlignViewControllerI.java +++ b/src/jalview/api/AlignViewControllerI.java @@ -61,4 +61,16 @@ public interface AlignViewControllerI boolean markColumnsContainingFeatures(boolean invert, boolean extendCurrent, boolean clearColumns, String featureType); + /** + * sort the alignment or current selection by average score over the given set of features + * @param typ list of feature names or null to use currently displayed features + */ + void sortAlignmentByFeatureScore(String[] typ); + + /** + * sort the alignment or current selection by distribution of the given set of features + * @param typ list of feature names or null to use currently displayed features + */ + void sortAlignmentByFeatureDensity(String[] typ); + } diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index 077f9cd..3cf8000 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -21,13 +21,17 @@ package jalview.controller; import java.awt.Color; +import java.util.ArrayList; import java.util.BitSet; import java.util.List; +import jalview.analysis.AlignmentSorter; import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureRenderer; +import jalview.commands.OrderCommand; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.ColumnSelection; @@ -294,4 +298,74 @@ public class AlignViewController implements AlignViewControllerI return false; } } + + @Override + public void sortAlignmentByFeatureDensity(String[] typ) + { + sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY); + } + + protected void sortBy(String[] typ, String methodText, final String method) + { + FeatureRenderer fr = alignPanel.getFeatureRenderer(); + if (typ == null) + { + typ = fr==null ? null : fr.getDisplayedFeatureTypes(); + } + String gps[] = null; + gps = fr==null ? null : fr.getDisplayedFeatureGroups(); + if (typ != null) + { + ArrayList types = new ArrayList(); + for (int i = 0; i < typ.length; i++) + { + if (typ[i] != null) + { + types.add(typ[i]); + } + typ = new String[types.size()]; + types.toArray(typ); + } + } + if (gps != null) + { + ArrayList grps = new ArrayList(); + + for (int i = 0; i < gps.length; i++) + { + if (gps[i] != null) + { + grps.add(gps[i]); + } + } + gps = new String[grps.size()]; + grps.toArray(gps); + } + AlignmentI al = viewport.getAlignment(); + + int start, stop; + SequenceGroup sg = viewport.getSelectionGroup(); + if (sg != null) + { + start = sg.getStartRes(); + stop = sg.getEndRes(); + } + else + { + start = 0; + stop = al.getWidth(); + } + SequenceI[] oldOrder = al.getSequencesArray(); + AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method); + avcg.addHistoryItem(new OrderCommand(methodText, oldOrder, viewport + .getAlignment())); + alignPanel.paintAlignment(true); + + } + + @Override + public void sortAlignmentByFeatureScore(String[] typ) + { + sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE); + } } -- 1.7.10.2