private static boolean sortLengthAscending;
+ private static boolean sortEValueAscending;
+
+ private static boolean sortBitScoreAscending;
+
/**
* Sorts sequences in the alignment by Percentage Identity with the given
* reference sequence, sorting the highest identity to the top
true);
for (int i = 0; i < nSeq; i++)
{
- scores[i] = (float) PIDModel.computePID(align.getSequenceAt(i)
- .getSequenceAsString(), refSeq, pidParams);
+ scores[i] = (float) PIDModel.computePID(
+ align.getSequenceAt(i).getSequenceAsString(), refSeq,
+ pidParams);
seqs[i] = align.getSequenceAt(i);
}
List<SequenceI> algn;
synchronized (algn = align.getSequences())
{
- List<SequenceI> tmp = new ArrayList<SequenceI>();
+ List<SequenceI> tmp = new ArrayList<>();
for (int i = 0; i < seqs.length; i++)
{
}
/**
+ * Sorts by sequence evalue. Currently moves all sequences without an evalue to
+ * the top of the alignment.
+ *
+ * @param align
+ * The alignment object to sort
+ */
+ public static void sortByEValue(AlignmentI align)
+ {
+ int nSeq = align.getHeight();
+
+ double[] evalue = new double[nSeq];
+ SequenceI[] seqs = new SequenceI[nSeq];
+
+ for (int i = 0; i < nSeq; i++)
+ {
+ seqs[i] = align.getSequenceAt(i);
+ AlignmentAnnotation[] ann = seqs[i].getAnnotation("Search Scores");
+ if (ann != null)
+ {
+ evalue[i] = ann[0].getEValue();
+ }
+ else
+ {
+ evalue[i] = -1;
+ }
+ }
+
+ QuickSort.sort(evalue, seqs);
+
+ if (sortEValueAscending)
+ {
+ setReverseOrder(align, seqs);
+ }
+ else
+ {
+ setOrder(align, seqs);
+ }
+
+ sortEValueAscending = !sortEValueAscending;
+ }
+
+ /**
+ * Sorts by sequence bit score. Currently moves all sequences without a bit
+ * score to the top of the alignment
+ *
+ * @param align
+ * The alignment object to sort
+ */
+ public static void sortByBitScore(AlignmentI align)
+ {
+ int nSeq = align.getHeight();
+
+ double[] score = new double[nSeq];
+ SequenceI[] seqs = new SequenceI[nSeq];
+
+ for (int i = 0; i < nSeq; i++)
+ {
+ seqs[i] = align.getSequenceAt(i);
+ AlignmentAnnotation[] ann = seqs[i].getAnnotation("Search Scores");
+ if (ann != null)
+ {
+ score[i] = ann[0].getEValue();
+ }
+ else
+ {
+ score[i] = -1;
+ }
+ }
+
+ QuickSort.sort(score, seqs);
+
+ if (sortBitScoreAscending)
+ {
+ setReverseOrder(align, seqs);
+ }
+ else
+ {
+ setOrder(align, seqs);
+ }
+
+ sortBitScoreAscending = !sortBitScoreAscending;
+ }
+
+ /**
* Sorts the alignment by size of group. <br>
* Maintains the order of sequences in each group by order in given alignment
* object.
{
// MAINTAINS ORIGNAL SEQUENCE ORDER,
// ORDERS BY GROUP SIZE
- List<SequenceGroup> groups = new ArrayList<SequenceGroup>();
+ List<SequenceGroup> groups = new ArrayList<>();
if (groups.hashCode() != lastGroupHash)
{
// NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER
// /////////////////////////////////////////////
- List<SequenceI> seqs = new ArrayList<SequenceI>();
+ List<SequenceI> seqs = new ArrayList<>();
for (int i = 0; i < groups.size(); i++)
{
// tmp2 = tmp.retainAll(mask);
// return tmp2.addAll(mask.removeAll(tmp2))
- ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
+ ArrayList<SequenceI> seqs = new ArrayList<>();
int i, idx;
boolean[] tmask = new boolean[mask.size()];
}
else
{
- setReverseOrder(align, vectorSubsetToArray(tmp, align.getSequences()));
+ setReverseOrder(align,
+ vectorSubsetToArray(tmp, align.getSequences()));
}
}
{
int nSeq = align.getHeight();
- List<SequenceI> tmp = new ArrayList<SequenceI>();
+ List<SequenceI> tmp = new ArrayList<>();
tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences());
if (tmp.size() != nSeq)
{
- System.err
- .println("WARNING: tmp.size()="
- + tmp.size()
- + " != nseq="
- + nSeq
- + " in getOrderByTree - tree contains sequences not in alignment");
+ System.err.println("WARNING: tmp.size()=" + tmp.size() + " != nseq="
+ + nSeq
+ + " in getOrderByTree - tree contains sequences not in alignment");
}
}
}
else
{
- setReverseOrder(align, vectorSubsetToArray(tmp, align.getSequences()));
+ setReverseOrder(align,
+ vectorSubsetToArray(tmp, align.getSequences()));
}
}
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();
}
public static String FEATURE_DENSITY = "density";
- private static boolean containsIgnoreCase(final String lab,
- final List<String> labs)
- {
- if (labs == null)
- {
- return true;
- }
- if (lab == null)
- {
- return false;
- }
- for (String label : labs)
- {
- if (lab.equalsIgnoreCase(label))
- {
- return true;
- }
- }
- return false;
- }
-
/**
* Sort sequences by feature score or density, optionally restricted by
* feature types, feature groups, or alignment start/end positions.
* get sequence residues overlapping column region
* and features for residue positions and specified types
*/
- // TODO new method findPositions(startCol, endCol)? JAL-2544
- int startResidue = seqs[i].findPosition(startCol);
- int endResidue = seqs[i].findPosition(endCol);
String[] types = featureTypes == null ? null : featureTypes
.toArray(new String[featureTypes.size()]);
- List<SequenceFeature> sfs = seqs[i].getFeatures().findFeatures(
- startResidue, endResidue, types);
+ List<SequenceFeature> sfs = seqs[i].findFeatures(startCol + 1,
+ endCol + 1, types);
seqScores[i] = 0;
scores[i] = 0.0;
SequenceFeature sf = it.next();
/*
- * double-check feature overlaps columns (JAL-2544)
- * (could avoid this with a findPositions(fromCol, toCol) method)
- * findIndex returns base 1 column values, startCol/endCol are base 0
+ * accept all features with null or empty group, otherwise
+ * check group is one of the currently visible groups
*/
- if (seqs[i].findIndex(sf.getBegin()) > endCol + 1
- || seqs[i].findIndex(sf.getEnd()) < startCol + 1)
- {
- it.remove();
- continue;
- }
-
String featureGroup = sf.getFeatureGroup();
if (groups != null && featureGroup != null
+ && !"".equals(featureGroup)
&& !groups.contains(featureGroup))
{
it.remove();