X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAlignmentSorter.java;fp=src%2Fjalview%2Fanalysis%2FAlignmentSorter.java;h=b88ef3a128f19e955e593e5a0a23a0e4bfdf8a1c;hb=4f77328104498504339216829abf5ea87e2791ec;hp=8634db68d2bedf572eaa2d94c3ffeece92a33e9e;hpb=2b8c0785318a3528e1876e8e2dd48b7d831eae69;p=jalview.git diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index 8634db6..b88ef3a 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -22,8 +22,6 @@ package jalview.analysis; import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.SimilarityParams; -import jalview.bin.ApplicationSingletonProvider; -import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; @@ -53,65 +51,40 @@ import java.util.List; * from the first tobesorted position in the alignment. e.g. (a,tb2,b,tb1,c,tb3 * becomes a,tb1,tb2,tb3,b,c) */ -public class AlignmentSorter implements ApplicationSingletonI +public class AlignmentSorter { - - private AlignmentSorter() - { - // private singleton - } - - private static AlignmentSorter getInstance() - { - return (AlignmentSorter) ApplicationSingletonProvider - .getInstance(AlignmentSorter.class); - } - - /** - * types of feature ordering: Sort by score : average score - or total score - - * over all features in region Sort by feature label text: (or if null - - * feature type text) - numerical or alphabetical Sort by feature density: - * based on counts - ignoring individual text or scores for each feature - */ - public static final String FEATURE_SCORE = "average_score"; - - public static final String FEATURE_LABEL = "text"; - - public static final String FEATURE_DENSITY = "density"; - /* * todo: refactor searches to follow a basic pattern: (search property, last * search state, current sort direction) */ - boolean sortIdAscending = true; - - int lastGroupHash = 0; + static boolean sortIdAscending = true; - boolean sortGroupAscending = true; + static int lastGroupHash = 0; - AlignmentOrder lastOrder = null; + static boolean sortGroupAscending = true; - boolean sortOrderAscending = true; + static AlignmentOrder lastOrder = null; - TreeModel lastTree = null; + static boolean sortOrderAscending = true; - boolean sortTreeAscending = true; + static TreeModel lastTree = null; + static boolean sortTreeAscending = true; - /** + /* * last Annotation Label used for sort by Annotation score */ - private String lastSortByAnnotation; + private static String lastSortByAnnotation; - /** - * string hash of last arguments to sortByFeature (sort order toggles if this - * is unchanged between sorts) + /* + * string hash of last arguments to sortByFeature + * (sort order toggles if this is unchanged between sorts) */ - private String sortByFeatureCriteria; + private static String sortByFeatureCriteria; - private boolean sortByFeatureAscending = true; + private static boolean sortByFeatureAscending = true; - private boolean sortLengthAscending; + private static boolean sortLengthAscending; /** * Sorts sequences in the alignment by Percentage Identity with the given @@ -249,8 +222,7 @@ public class AlignmentSorter implements ApplicationSingletonI QuickSort.sort(ids, seqs); - AlignmentSorter as = getInstance(); - if (as.sortIdAscending) + if (sortIdAscending) { setReverseOrder(align, seqs); } @@ -259,7 +231,7 @@ public class AlignmentSorter implements ApplicationSingletonI setOrder(align, seqs); } - as.sortIdAscending = !as.sortIdAscending; + sortIdAscending = !sortIdAscending; } /** @@ -283,9 +255,7 @@ public class AlignmentSorter implements ApplicationSingletonI QuickSort.sort(length, seqs); - AlignmentSorter as = getInstance(); - - if (as.sortLengthAscending) + if (sortLengthAscending) { setReverseOrder(align, seqs); } @@ -294,7 +264,7 @@ public class AlignmentSorter implements ApplicationSingletonI setOrder(align, seqs); } - as.sortLengthAscending = !as.sortLengthAscending; + sortLengthAscending = !sortLengthAscending; } /** @@ -311,16 +281,14 @@ public class AlignmentSorter implements ApplicationSingletonI // ORDERS BY GROUP SIZE List groups = new ArrayList<>(); - AlignmentSorter as = getInstance(); - - if (groups.hashCode() != as.lastGroupHash) + if (groups.hashCode() != lastGroupHash) { - as.sortGroupAscending = true; - as.lastGroupHash = groups.hashCode(); + sortGroupAscending = true; + lastGroupHash = groups.hashCode(); } else { - as.sortGroupAscending = !as.sortGroupAscending; + sortGroupAscending = !sortGroupAscending; } // SORTS GROUPS BY SIZE @@ -360,7 +328,7 @@ public class AlignmentSorter implements ApplicationSingletonI } } - if (as.sortGroupAscending) + if (sortGroupAscending) { setOrder(align, seqs); } @@ -433,18 +401,16 @@ public class AlignmentSorter implements ApplicationSingletonI // Get an ordered vector of sequences which may also be present in align List tmp = order.getOrder(); - AlignmentSorter as = getInstance(); - - if (as.lastOrder == order) + if (lastOrder == order) { - as.sortOrderAscending = !as.sortOrderAscending; + sortOrderAscending = !sortOrderAscending; } else { - as.sortOrderAscending = true; + sortOrderAscending = true; } - if (as.sortOrderAscending) + if (sortOrderAscending) { setOrder(align, tmp); } @@ -507,20 +473,18 @@ public class AlignmentSorter implements ApplicationSingletonI { List tmp = getOrderByTree(align, tree); - AlignmentSorter as = getInstance(); - // tmp should properly permute align with tree. - if (as.lastTree != tree) + if (lastTree != tree) { - as.sortTreeAscending = true; - as.lastTree = tree; + sortTreeAscending = true; + lastTree = tree; } else { - as.sortTreeAscending = !as.sortTreeAscending; + sortTreeAscending = !sortTreeAscending; } - if (as.sortTreeAscending) + if (sortTreeAscending) { setOrder(align, tmp); } @@ -622,7 +586,7 @@ public class AlignmentSorter implements ApplicationSingletonI for (int i = 0; i < alignment.length; i++) { - ids[i] = (new Float(alignment[i].getName().substring(8))) + ids[i] = (Float.valueOf(alignment[i].getName().substring(8))) .floatValue(); } @@ -694,12 +658,9 @@ public class AlignmentSorter implements ApplicationSingletonI } jalview.util.QuickSort.sort(scores, seqs); - - AlignmentSorter as = getInstance(); - - if (as.lastSortByAnnotation != scoreLabel) + if (lastSortByAnnotation != scoreLabel) { - as.lastSortByAnnotation = scoreLabel; + lastSortByAnnotation = scoreLabel; setOrder(alignment, seqs); } else @@ -709,6 +670,18 @@ public class AlignmentSorter implements ApplicationSingletonI } /** + * types of feature ordering: Sort by score : average score - or total score - + * over all features in region Sort by feature label text: (or if null - + * feature type text) - numerical or alphabetical Sort by feature density: + * based on counts - ignoring individual text or scores for each feature + */ + public static String FEATURE_SCORE = "average_score"; + + public static String FEATURE_LABEL = "text"; + + public static String FEATURE_DENSITY = "density"; + + /** * Sort sequences by feature score or density, optionally restricted by * feature types, feature groups, or alignment start/end positions. *

@@ -836,8 +809,6 @@ public class AlignmentSorter implements ApplicationSingletonI } } - boolean doSort = false; - if (FEATURE_SCORE.equals(method)) { if (hasScores == 0) @@ -863,7 +834,7 @@ public class AlignmentSorter implements ApplicationSingletonI } } } - doSort = true; + QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); } else if (FEATURE_DENSITY.equals(method)) { @@ -875,12 +846,9 @@ public class AlignmentSorter implements ApplicationSingletonI // System.err.println("Sorting on Density: seq "+seqs[i].getName()+ // " Feats: "+featureCount+" Score : "+scores[i]); } - doSort = true; - } - if (doSort) - { - QuickSort.sortByDouble(scores, seqs, getInstance().sortByFeatureAscending); + QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); } + setOrder(alignment, seqs); } @@ -915,17 +883,16 @@ public class AlignmentSorter implements ApplicationSingletonI /* * if resorting on the same criteria, toggle sort order */ - AlignmentSorter as = getInstance(); - if (as.sortByFeatureCriteria == null - || !scoreCriteria.equals(as.sortByFeatureCriteria)) + if (sortByFeatureCriteria == null + || !scoreCriteria.equals(sortByFeatureCriteria)) { - as.sortByFeatureAscending = true; + sortByFeatureAscending = true; } else { - as.sortByFeatureAscending = !as.sortByFeatureAscending; + sortByFeatureAscending = !sortByFeatureAscending; } - as.sortByFeatureCriteria = scoreCriteria; + sortByFeatureCriteria = scoreCriteria; } }