X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FGrouping.java;h=066814e626b390897a812565b1262958f61aadc8;hb=a7169b1c72607f3c9357195b4999869650a2a891;hp=4eee9c06cf517dbe8122bb2be0edce769f77d916;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/analysis/Grouping.java b/src/jalview/analysis/Grouping.java
index 4eee9c0..066814e 100644
--- a/src/jalview/analysis/Grouping.java
+++ b/src/jalview/analysis/Grouping.java
@@ -1,30 +1,33 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.analysis;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
/**
@@ -50,9 +53,9 @@ public class Grouping
String[] selectedChars, List list)
{
// TODO: determine how to get/recover input data for group generation
- Hashtable gps = new Hashtable();
+ Map> gps = new HashMap>();
int width = 0, i;
- Hashtable pgroup = new Hashtable();
+ Map pgroup = new HashMap();
if (list != null)
{
for (SequenceGroup sg : list)
@@ -66,32 +69,116 @@ public class Grouping
for (i = 0; i < sequences.length; i++)
{
String schar = selectedChars[i];
- SequenceGroup pgp = (SequenceGroup) pgroup
- .get(((Object) sequences[i]).toString());
+ SequenceGroup pgp = pgroup.get(((Object) sequences[i]).toString());
if (pgp != null)
{
schar = pgp.getName() + ":" + schar;
}
- Vector svec = (Vector) gps.get(schar);
+ List svec = gps.get(schar);
if (svec == null)
{
- svec = new Vector();
+ svec = new ArrayList();
gps.put(schar, svec);
}
if (width < sequences[i].getLength())
{
width = sequences[i].getLength();
}
- svec.addElement(sequences[i]);
+ svec.add(sequences[i]);
}
// make some groups
- java.util.Enumeration sge = gps.keys();
SequenceGroup[] groups = new SequenceGroup[gps.size()];
i = 0;
- while (sge.hasMoreElements())
+ for (String key : gps.keySet())
{
- String key = (String) sge.nextElement();
- SequenceGroup group = new SequenceGroup((Vector) gps.get(key),
+ SequenceGroup group = new SequenceGroup(gps.get(key),
+ "Subseq: " + key, null, true, true, false, 0, width - 1);
+
+ groups[i++] = group;
+ }
+ gps.clear();
+ pgroup.clear();
+ return groups;
+ }
+
+ /**
+ * Divide the given sequences based on the equivalence of characters at
+ * selected columns If exgroups is provided, existing groups will be
+ * subdivided.
+ *
+ * @param sequences
+ * @param columnSelection
+ * @param list
+ * @return
+ */
+ public static SequenceGroup[] makeGroupsFromCols(SequenceI[] sequences,
+ ColumnSelection cs, List list)
+ {
+ // TODO: determine how to get/recover input data for group generation
+ Map> gps = new HashMap>();
+ Map pgroup = new HashMap();
+ if (list != null)
+ {
+ for (SequenceGroup sg : list)
+ {
+ for (SequenceI sq : sg.getSequences(null))
+ {
+ pgroup.put(sq.toString(), sg);
+ }
+ }
+ }
+
+ /*
+ * get selected columns (in the order they were selected);
+ * note this could include right-to-left ranges
+ */
+ int[] spos = new int[cs.getSelected().size()];
+ int width = -1;
+ int i = 0;
+ for (Integer pos : cs.getSelected())
+ {
+ spos[i++] = pos.intValue();
+ }
+
+ for (i = 0; i < sequences.length; i++)
+ {
+ int slen = sequences[i].getLength();
+ if (width < slen)
+ {
+ width = slen;
+ }
+
+ SequenceGroup pgp = pgroup.get(((Object) sequences[i]).toString());
+ StringBuilder schar = new StringBuilder();
+ if (pgp != null)
+ {
+ schar.append(pgp.getName() + ":");
+ }
+ for (int p : spos)
+ {
+ if (p >= slen)
+ {
+ schar.append("~");
+ }
+ else
+ {
+ schar.append(sequences[i].getCharAt(p));
+ }
+ }
+ List svec = gps.get(schar.toString());
+ if (svec == null)
+ {
+ svec = new ArrayList();
+ gps.put(schar.toString(), svec);
+ }
+ svec.add(sequences[i]);
+ }
+ // make some groups
+ SequenceGroup[] groups = new SequenceGroup[gps.size()];
+ i = 0;
+ for (String key : gps.keySet())
+ {
+ SequenceGroup group = new SequenceGroup(gps.get(key),
"Subseq: " + key, null, true, true, false, 0, width - 1);
groups[i++] = group;