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;
* 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
QuickSort.sort(ids, seqs);
- AlignmentSorter as = getInstance();
- if (as.sortIdAscending)
+ if (sortIdAscending)
{
setReverseOrder(align, seqs);
}
setOrder(align, seqs);
}
- as.sortIdAscending = !as.sortIdAscending;
+ sortIdAscending = !sortIdAscending;
}
/**
QuickSort.sort(length, seqs);
- AlignmentSorter as = getInstance();
-
- if (as.sortLengthAscending)
+ if (sortLengthAscending)
{
setReverseOrder(align, seqs);
}
setOrder(align, seqs);
}
- as.sortLengthAscending = !as.sortLengthAscending;
+ sortLengthAscending = !sortLengthAscending;
}
/**
// ORDERS BY GROUP SIZE
List<SequenceGroup> 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
}
}
- if (as.sortGroupAscending)
+ if (sortGroupAscending)
{
setOrder(align, seqs);
}
// Get an ordered vector of sequences which may also be present in align
List<SequenceI> 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);
}
{
List<SequenceI> 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);
}
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();
}
}
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
}
/**
+ * 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.
* <p>
}
}
- boolean doSort = false;
-
if (FEATURE_SCORE.equals(method))
{
if (hasScores == 0)
}
}
}
- doSort = true;
+ QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending);
}
else if (FEATURE_DENSITY.equals(method))
{
// 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);
}
/*
* 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;
}
}