return new String("Sequence" + i);\r
}\r
\r
+ /**\r
+ * Generates a hash of SeqCharacterHash properties for each sequence\r
+ * in a sequence set, and optionally renames the sequences to an\r
+ * unambiguous 'safe' name.\r
+ * @param sequences SequenceI[]\r
+ * @param write_names boolean set this to rename each of the sequences to its unique_name(index) name\r
+ * @return Hashtable to be passed to @see deuniquify to recover original names (and properties) for renamed sequences\r
+ */\r
public static Hashtable uniquify(SequenceI[] sequences, boolean write_names)\r
{\r
// Generate a safely named sequence set and a hash to recover the sequence names\r
\r
return map;\r
}\r
-\r
+ /**\r
+ * recover unsafe sequence names and original properties for a sequence\r
+ * set using a map generated by @see uniquify(sequences,true)\r
+ * @param map Hashtable\r
+ * @param sequences SequenceI[]\r
+ * @return boolean\r
+ */\r
public static boolean deuniquify(Hashtable map, SequenceI[] sequences)\r
{\r
- // recover unsafe sequence names for a sequence set\r
- boolean allfound = true;\r
-\r
- for (int i = 0; i < sequences.length; i++)\r
- {\r
- if (map.containsKey(sequences[i].getName()))\r
- {\r
- Hashtable sqinfo = (Hashtable) map.get(sequences[i].getName());\r
- SeqCharacterUnhash(sequences[i], sqinfo);\r
- }\r
- else\r
- {\r
- allfound = false;\r
+ jalview.analysis.SequenceIdMatcher matcher = new SequenceIdMatcher(sequences);\r
+ SequenceI msq = null;\r
+ Enumeration keys = map.keys();\r
+ Vector unmatched = new Vector();\r
+ for (int i=0, j=sequences.length; i<j; i++)\r
+ unmatched.add(sequences[i]);\r
+ while (keys.hasMoreElements()) {\r
+ Object key = keys.nextElement();\r
+ if (key instanceof String) {\r
+ if ((msq = matcher.findIdMatch((String) key))!=null) {\r
+ Hashtable sqinfo = (Hashtable) map.get(key);\r
+ unmatched.remove(msq);\r
+ SeqCharacterUnhash(msq, sqinfo);\r
+ }\r
+ else\r
+ {\r
+ System.err.println("Can't find '"+((String) key)+"' in uniquified alignment");\r
+ }\r
}\r
}\r
+ if (unmatched.size()>0) {\r
+ System.err.println("Did not find matches for :");\r
+ for (Enumeration i = unmatched.elements(); i.hasMoreElements(); System.out.println(((SequenceI) i.nextElement()).getName()))\r
+ ;\r
+ return false;\r
+ }\r
\r
- return allfound;\r
+ return true;\r
+ }\r
+ /**\r
+ * returns a subset of the sequenceI seuqences,\r
+ * including only those that contain at least one residue.\r
+ * @param sequences SequenceI[]\r
+ * @return SequenceI[]\r
+ */\r
+ public static SequenceI[] getNonEmptySequenceSet(SequenceI[] sequences) {\r
+ // Identify first row of alignment with residues for prediction\r
+ boolean ungapped[] = new boolean[sequences.length];\r
+ int msflen=0;\r
+ for (int i=0,j=sequences.length; i<j;i++) {\r
+ String tempseq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sequences[i].getSequence());\r
+ if (tempseq.length()==0)\r
+ ungapped[i]=false;\r
+ else {\r
+ ungapped[i]=true;\r
+ msflen++;\r
+ }\r
+ }\r
+ if (msflen==0)\r
+ return null; // no minimal set\r
+ // compose minimal set\r
+ SequenceI[] mset = new SequenceI[msflen];\r
+ for (int i=0,j=sequences.length,k=0; i<j;i++) {\r
+ if (ungapped[i])\r
+ mset[k++] = sequences[i];\r
+ }\r
+ ungapped = null;\r
+ return mset;\r
}\r
}\r
wsInfo = setWebService();\r
\r
SequenceI seq = msf[0];\r
+\r
altitle = "JNet prediction on " + seq.getName() +\r
" using alignment from " + title;\r
\r
AlignSeq.extractGaps("-. ", seq.getSequence()) +\r
"\n");\r
SequenceI aln[] = new SequenceI[msf.length];\r
- for (int i=0,j=msf.length; i<j;i++)\r
- aln[i] = new jalview.datamodel.Sequence(msf[i]);\r
+ for (int i=0,j=msf.length; i<j;i++) {\r
+ aln[i] = new jalview.datamodel.Sequence(msf[i]);\r
+ }\r
+\r
SequenceInfo = jalview.analysis.SeqsetUtils.uniquify(aln, true);\r
\r
if (!locateWebService())\r
{\r
al = new Alignment(new FormatAdapter().readFile(\r
result.getAligfile(), "Paste", format));\r
+ SequenceI sqs[] = new SequenceI[al.getHeight()];\r
for (int i=0, j=al.getHeight(); i<j; i++) {\r
- SequenceI sq = al.getSequenceAt(i);\r
- if (!jalview.analysis.SeqsetUtils.SeqCharacterUnhash(\r
- sq, (Hashtable) SequenceInfo.get(sq.getName())))\r
+ sqs[i] = al.getSequenceAt(i);\r
+ }\r
+ if (!jalview.analysis.SeqsetUtils.deuniquify(\r
+ (Hashtable) SequenceInfo,sqs))\r
{\r
throw (new Exception(\r
- "Couldn't recover sequence properties for JNet "\r
- +((i==0) ? "Query sequence" : "alignment sequence ("+i+")")));\r
+ "Couldn't recover sequence properties for alignment."));\r
}\r
- }\r
+\r
noMsa = false;\r
FirstSeq = 0;\r
}\r