3 import jalview.api.AlignFrameI;
4 import jalview.api.JalviewApp;
5 import jalview.api.StructureSelectionManagerProvider;
6 import jalview.datamodel.Alignment;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.AlignmentOrder;
9 import jalview.datamodel.ColumnSelection;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.Sequence;
12 import jalview.datamodel.SequenceGroup;
13 import jalview.datamodel.SequenceI;
14 import jalview.gui.AlignFrame;
15 import jalview.gui.AlignViewport;
16 import jalview.gui.Desktop;
17 import jalview.io.AnnotationFile;
18 import jalview.io.AppletFormatAdapter;
19 import jalview.io.DataSourceType;
20 import jalview.io.FileFormat;
21 import jalview.io.FileFormatI;
22 import jalview.io.FileFormats;
23 import jalview.io.IdentifyFile;
24 import jalview.io.JPredFile;
25 import jalview.io.JnetAnnotationMaker;
26 import jalview.io.NewickFile;
27 import jalview.structure.StructureSelectionManager;
28 import jalview.util.HttpUtils;
29 import jalview.util.MessageManager;
31 import java.awt.EventQueue;
32 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.StringTokenizer;
37 import java.util.Vector;
40 * A class to load parameters for either JalviewLite or Jalview
45 public class JalviewAppLoader
48 private JalviewApp app; // Jalview or JalviewJS or JalviewLite
50 private boolean debug;
52 String separator = "\u00AC"; // JalviewLite note: the default used to
53 // be '|', but many sequence IDS include
56 public String getSeparator()
61 public void setSeparator(String separator)
63 this.separator = separator;
66 public JalviewAppLoader(boolean debug)
71 public void load(JalviewApp app)
76 String sep = app.getParameter("separator");
85 throw new Error(MessageManager
86 .getString("error.invalid_separator_parameter"));
100 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
106 protected boolean loadPdbFiles()
108 boolean result = false;
110 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
114 boolean doAlign = app.getDefaultParameter("alignpdbfiles", false);
115 app.setAlignPdbStructures(doAlign);
117 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
120 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
122 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
125 // Accumulate pdbs here if they are heading for the same view (if
126 // alignPdbStructures is true)
127 Vector<Object[]> pdbs = new Vector<>();
128 // create a lazy matcher if we're asked to
129 jalview.analysis.SequenceIdMatcher matcher = (app
130 .getDefaultParameter("relaxedidmatch", false))
131 ? new jalview.analysis.SequenceIdMatcher(
132 app.getViewport().getAlignment()
133 .getSequencesArray())
136 int pdbFileCount = 0;
140 if (pdbFileCount > 0)
142 param = app.getParameter("PDBFILE" + pdbFileCount);
146 param = app.getParameter("PDBFILE");
151 PDBEntry pdb = new PDBEntry();
154 SequenceI[] seqs = null;
155 String[] chains = null;
157 StringTokenizer st = new StringTokenizer(param, " ");
159 if (st.countTokens() < 2)
161 String sequence = app.getParameter("PDBSEQ");
162 if (sequence != null)
164 seqs = new SequenceI[] { matcher == null
165 ? (Sequence) app.getViewport().getAlignment()
167 : matcher.findIdMatch(sequence) };
173 param = st.nextToken();
174 List<SequenceI> tmp = new ArrayList<>();
175 List<String> tmp2 = new ArrayList<>();
177 while (st.hasMoreTokens())
179 seqstring = st.nextToken();
180 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
181 if (st2.countTokens() > 1)
184 tmp2.add(st2.nextToken());
185 seqstring = st2.nextToken();
187 tmp.add(matcher == null
188 ? (Sequence) app.getViewport().getAlignment()
190 : matcher.findIdMatch(seqstring));
193 seqs = tmp.toArray(new SequenceI[tmp.size()]);
194 if (tmp2.size() == tmp.size())
196 chains = tmp2.toArray(new String[tmp2.size()]);
201 DataSourceType protocol = resolveFileProtocol(app, ret);
202 // TODO check JAL-357 for files in a jar (CLASSLOADER)
207 for (int i = 0; i < seqs.length; i++)
211 ((Sequence) seqs[i]).addPDBId(pdb);
212 StructureSelectionManager
213 .getStructureSelectionManager(
214 (StructureSelectionManagerProvider) app)
215 .registerPDBEntry(pdb);
221 // this may not really be a problem but we give a warning
224 "Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
232 pdbs.addElement(new Object[] { pdb, seqs, chains, protocol });
236 app.newStructureView(pdb, seqs, chains, protocol);
242 } while (param != null || pdbFileCount < 10);
245 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
246 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
247 String[][] chains = new String[pdbs.size()][];
248 String[] protocols = new String[pdbs.size()];
249 for (int pdbsi = 0, pdbsiSize = pdbs
250 .size(); pdbsi < pdbsiSize; pdbsi++)
252 Object[] o = pdbs.elementAt(pdbsi);
253 pdb[pdbsi] = (PDBEntry) o[0];
254 seqs[pdbsi] = (SequenceI[]) o[1];
255 chains[pdbsi] = (String[]) o[2];
256 protocols[pdbsi] = (String) o[3];
258 app.alignedStructureView(pdb, seqs, chains, protocols);
265 * Load in a Jnetfile if specified by parameter. Returns true if loaded, else
271 protected boolean loadJnetFile()
273 boolean result = false;
274 String param = app.getParameter("jnetfile");
277 // jnet became jpred around 2016
278 param = app.getParameter("jpredfile");
285 DataSourceType protocol = resolveFileProtocol(app, ret);
286 JPredFile predictions = new JPredFile(ret[0], protocol);
287 JnetAnnotationMaker.add_annotation(predictions,
288 app.getViewport().getAlignment(), 0, false);
289 // false == do not add sequence profile from concise output
290 app.getViewport().getAlignment().setupJPredAlignment();
291 app.updateForAnnotations();
293 } catch (Exception ex)
295 ex.printStackTrace();
302 * Load annotations if specified by parameter. Returns true if loaded, else
308 protected boolean loadAnnotations()
310 boolean result = false;
311 String param = app.getParameter("annotations");
315 DataSourceType protocol = resolveFileProtocol(app, ret);
317 if (new AnnotationFile().annotateAlignmentView(app.getViewport(),
320 app.updateForAnnotations();
326 .println("Annotations were not added from annotation file '"
334 * Load features file and view settings as specified by parameters. Returns
335 * true if features were loaded, else false.
340 protected boolean loadFeatures()
342 boolean result = false;
343 // ///////////////////////////
344 // modify display of features
345 // we do this before any features have been loaded, ensuring any hidden
346 // groups are hidden when features first displayed
348 // hide specific groups
350 String param = app.getParameter("hidefeaturegroups");
353 app.setFeatureGroupState(separatorListToArray(param, separator),
355 // app.setFeatureGroupStateOn(newAlignFrame, param, false);
357 // show specific groups
358 param = app.getParameter("showfeaturegroups");
361 app.setFeatureGroupState(separatorListToArray(param, separator),
363 // app.setFeatureGroupStateOn(newAlignFrame, param, true);
365 // and now load features
366 param = app.getParameter("features");
370 DataSourceType protocol = resolveFileProtocol(app, ret);
372 result = app.parseFeaturesFile(ret[0], protocol);
375 param = app.getParameter("showFeatureSettings");
376 if (param != null && param.equalsIgnoreCase("true"))
378 app.newFeatureSettings();
384 * Load a score file if specified by parameter. Returns true if file was
385 * loaded, else false.
389 protected boolean loadScoreFile()
391 boolean result = false;
392 String sScoreFile = app.getParameter("scoreFile");
393 if (sScoreFile != null && !"".equals(sScoreFile))
400 "Attempting to load T-COFFEE score file from the scoreFile parameter");
402 result = app.loadScoreFile(sScoreFile);
406 "Failed to parse T-COFFEE parameter as a valid score file ('"
407 + sScoreFile + "')");
409 } catch (Exception e)
411 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
412 sScoreFile, e.getMessage());
418 String[] ret = new String[1];
421 * Load a tree for the alignment if specified by parameter. Returns true if a
422 * tree was loaded, else false.
427 protected boolean loadTree()
429 boolean result = false;
430 String treeFile = app.getParameter("tree");
431 if (treeFile == null)
433 treeFile = app.getParameter("treeFile");
436 if (treeFile != null)
441 NewickFile fin = new NewickFile(treeFile,
442 resolveFileProtocol(app, ret));
445 if (fin.getTree() != null)
447 app.loadTree(fin, ret[0]);
451 System.out.println("Successfully imported tree.");
459 "Tree parameter did not resolve to a valid tree.");
462 } catch (Exception ex)
464 ex.printStackTrace();
471 * form a complete URL given a path to a resource and a reference location on
475 * - an absolute path on the same server as localref or a document
476 * located relative to localref
478 * - a URL on the same server as url
479 * @return a complete URL for the resource located by url
481 public static String resolveUrlForLocalOrAbsolute(String targetPath,
484 String resolvedPath = "";
485 if (targetPath.startsWith("/"))
487 String codebase = localref.toString();
488 String localfile = localref.getFile();
489 resolvedPath = codebase.substring(0,
490 codebase.length() - localfile.length()) + targetPath;
495 * get URL path and strip off any trailing file e.g.
496 * www.jalview.org/examples/index.html#applets?a=b is trimmed to
497 * www.jalview.org/examples/
499 String urlPath = localref.toString();
500 String directoryPath = urlPath;
501 int lastSeparator = directoryPath.lastIndexOf("/");
502 if (lastSeparator > 0)
504 directoryPath = directoryPath.substring(0, lastSeparator + 1);
507 if (targetPath.startsWith("/"))
510 * construct absolute URL to a file on the server - this is not allowed?
512 // String localfile = localref.getFile();
513 // resolvedPath = urlPath.substring(0,
514 // urlPath.length() - localfile.length())
516 resolvedPath = directoryPath + targetPath.substring(1);
520 resolvedPath = directoryPath + targetPath;
524 // System.err.println(
525 // "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
531 * parse the string into a list
535 * @return elements separated by separator
537 public static String[] separatorListToArray(String list, String separator)
539 // TODO use StringUtils version (slightly different...)
540 int seplen = separator.length();
541 if (list == null || list.equals("") || list.equals(separator))
545 Vector<String> jv = new Vector<>();
547 while ((pos = list.indexOf(separator, cp)) > cp)
549 jv.addElement(list.substring(cp, pos));
552 if (cp < list.length())
554 String c = list.substring(cp);
555 if (!c.equals(separator))
562 String[] v = new String[jv.size()];
563 for (int i = 0; i < v.length; i++)
565 v[i] = jv.elementAt(i);
567 jv.removeAllElements();
570 // System.err.println("Array from '" + separator
571 // + "' separated List:\n" + v.length);
572 // for (int i = 0; i < v.length; i++)
574 // System.err.println("item " + i + " '" + v[i] + "'");
581 // System.err.println(
582 // "Empty Array from '" + separator + "' separated List");
587 public static DataSourceType resolveFileProtocol(JalviewApp app,
590 String path = retPath[0];
594 if (path.startsWith("PASTE"))
596 retPath[0] = path.substring(5);
597 return DataSourceType.PASTE;
603 if (path.indexOf("://") >= 0)
605 return DataSourceType.URL;
609 * try relative to document root
611 URL documentBase = app.getDocumentBase();
612 String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
613 if (HttpUtils.isValidUrl(withDocBase))
617 // System.err.println("Prepended document base '" + documentBase
618 // + "' to make: '" + withDocBase + "'");
620 retPath[0] = withDocBase;
621 return DataSourceType.URL;
625 * try relative to codebase (if different to document base)
627 URL codeBase = app.getCodeBase();
628 String withCodeBase = resolveUrlForLocalOrAbsolute(path, codeBase);
629 if (!withCodeBase.equals(withDocBase)
630 && HttpUtils.isValidUrl(withCodeBase))
634 // System.err.println("Prepended codebase '" + codeBase
635 // + "' to make: '" + withCodeBase + "'");
637 retPath[0] = withCodeBase;
638 return DataSourceType.URL;
642 * try locating by classloader; try this last so files in the directory
643 * are resolved using document base
645 if (inArchive(app.getClass(), path))
647 return DataSourceType.CLASSLOADER;
653 * Discovers whether the given file is in the Applet Archive
659 private static boolean inArchive(Class<?> c, String f)
661 // This might throw a security exception in certain browsers
662 // Netscape Communicator for instance.
665 boolean rtn = (c.getResourceAsStream("/" + f) != null);
668 // System.err.println("Resource '" + f + "' was "
669 // + (rtn ? "" : "not ") + "located by classloader.");
672 } catch (Exception ex)
674 System.out.println("Exception checking resources: " + f + " " + ex);
679 public void callInitCallback()
681 String initjscallback = app.getParameter("oninit");
682 if (initjscallback == null)
686 initjscallback = initjscallback.trim();
687 if (initjscallback.length() > 0)
694 * read sequence1...sequenceN as a raw alignment
699 public String getPastedSequence(JalviewApp jalviewApp)
701 StringBuffer data = new StringBuffer("PASTE");
704 while ((file = app.getParameter("sequence" + i)) != null)
706 data.append(file.toString() + "\n");
709 if (data.length() > 5)
711 file = data.toString();
717 * concatenate the list with separator
721 * @return concatenated string
723 public static String arrayToSeparatorList(String[] list, String separator)
725 // TODO use StringUtils version
726 StringBuffer v = new StringBuffer();
727 if (list != null && list.length > 0)
729 for (int i = 0, iSize = list.length; i < iSize; i++)
743 // .println("Returning '" + separator + "' separated List:\n");
744 // System.err.println(v);
750 // System.err.println(
751 // "Returning empty '" + separator + "' separated List\n");
753 return "" + separator;
756 public String arrayToSeparatorList(String[] array)
758 return arrayToSeparatorList(array, separator);
761 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
763 StringBuffer result = new StringBuffer("");
764 if (sep == null || sep.length() == 0)
766 sep = separator; // "+0x00AC;
768 AlignViewport v = ((AlignFrame) alf).getViewport();
769 if (v.getSelectionGroup() != null)
771 SequenceI[] seqs = v.getSelectionGroup()
772 .getSequencesInOrder(v.getAlignment());
774 for (int i = 0; i < seqs.length; i++)
776 result.append(seqs[i].getName());
781 return result.toString();
784 public void setFeatureGroupStateOn(final AlignFrameI alf,
785 final String groups, boolean state)
787 java.awt.EventQueue.invokeLater(new Runnable()
792 ((AlignFrame) alf).setFeatureGroupState(
793 separatorListToArray(groups, separator), state);
798 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
800 return arrayToSeparatorList(
801 ((AlignFrame) alf).getFeatureGroupsOfState(visible));
804 public void scrollViewToIn(final AlignFrameI alf, final String topRow,
805 final String leftHandColumn)
807 java.awt.EventQueue.invokeLater(new Runnable()
814 ((AlignFrame) alf).scrollTo(new Integer(topRow).intValue(),
815 new Integer(leftHandColumn).intValue());
817 } catch (Exception ex)
819 System.err.println("Couldn't parse integer arguments (topRow='"
820 + topRow + "' and leftHandColumn='" + leftHandColumn
822 ex.printStackTrace();
828 public void scrollViewToRowIn(final AlignFrameI alf, final String topRow)
831 java.awt.EventQueue.invokeLater(new Runnable()
838 ((AlignFrame) alf).scrollToRow(new Integer(topRow).intValue());
840 } catch (Exception ex)
842 System.err.println("Couldn't parse integer arguments (topRow='"
844 ex.printStackTrace();
851 public void scrollViewToColumnIn(final AlignFrameI alf,
852 final String leftHandColumn)
854 java.awt.EventQueue.invokeLater(new Runnable()
863 .scrollToColumn(new Integer(leftHandColumn).intValue());
865 } catch (Exception ex)
868 "Couldn't parse integer arguments (leftHandColumn='"
869 + leftHandColumn + "')");
870 ex.printStackTrace();
877 public boolean addPdbFile(AlignFrameI alf, String sequenceId,
878 String pdbEntryString, String pdbFile)
880 AlignFrame alFrame = (AlignFrame) alf;
881 SequenceI toaddpdb = alFrame.getViewport().getAlignment()
882 .findName(sequenceId);
883 boolean needtoadd = false;
884 if (toaddpdb != null)
886 Vector<PDBEntry> pdbe = toaddpdb.getAllPDBEntries();
887 PDBEntry pdbentry = null;
888 if (pdbe != null && pdbe.size() > 0)
890 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
892 pdbentry = pdbe.elementAt(pe);
893 if (!pdbentry.getId().equals(pdbEntryString)
894 && !pdbentry.getFile().equals(pdbFile))
904 if (pdbentry == null)
906 pdbentry = new PDBEntry();
907 pdbentry.setId(pdbEntryString);
908 pdbentry.setFile(pdbFile);
909 needtoadd = true; // add this new entry to sequence.
911 // resolve data source
912 // TODO: this code should be a refactored to an io package
913 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
915 if (protocol == null)
921 pdbentry.setProperty("protocol", protocol);
922 toaddpdb.addPDBId(pdbentry);
923 alFrame.alignPanel.getStructureSelectionManager()
924 .registerPDBEntry(pdbentry);
930 public AlignFrameI loadAlignment(String text, int width, int height,
933 AlignmentI al = null;
937 FileFormatI format = new IdentifyFile().identify(text,
938 DataSourceType.PASTE);
939 al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE,
941 if (al.getHeight() > 0)
943 return new AlignFrame(al, width, height, title);
945 } catch (IOException ex)
947 ex.printStackTrace();
952 public String getFeatureGroupsOn(AlignFrameI alf)
954 return arrayToSeparatorList(
955 ((AlignFrame) alf).getFeatureGroups());
958 public void highlightIn(final AlignFrameI alf, final String sequenceId,
959 final String position, final String alignedPosition)
961 // TODO: could try to highlight in all alignments if alf==null
962 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
963 ((AlignFrame) alf).getViewport().getAlignment()
964 .getSequencesArray());
965 final SequenceI sq = matcher.findIdMatch(sequenceId);
971 apos = new Integer(position).intValue();
973 } catch (NumberFormatException ex)
977 final int pos = apos;
978 // use vamsas listener to broadcast to all listeners in scope
979 if (alignedPosition != null && (alignedPosition.trim().length() == 0
980 || alignedPosition.toLowerCase().indexOf("false") > -1))
982 java.awt.EventQueue.invokeLater(new Runnable()
987 StructureSelectionManager
988 .getStructureSelectionManager(Desktop.getInstance())
989 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
995 java.awt.EventQueue.invokeLater(new Runnable()
1000 StructureSelectionManager
1001 .getStructureSelectionManager(Desktop.getInstance())
1002 .mouseOverVamsasSequence(sq, pos, null);
1009 public void selectIn(final AlignFrameI alf, String sequenceIds,
1010 String columns, String sep)
1012 if (sep == null || sep.length() == 0)
1020 System.err.println("Selecting region using separator string '"
1025 String[] ids = JalviewAppLoader.separatorListToArray(sequenceIds, sep);
1026 String[] cols = JalviewAppLoader.separatorListToArray(columns, sep);
1027 final SequenceGroup sel = new SequenceGroup();
1028 final ColumnSelection csel = new ColumnSelection();
1029 AlignmentI al = ((AlignFrame) alf).getViewport().getAlignment();
1030 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
1031 ((AlignFrame) alf).getViewport().getAlignment()
1032 .getSequencesArray());
1033 int start = 0, end = al.getWidth(), alw = al.getWidth();
1034 boolean seqsfound = true;
1035 if (ids != null && ids.length > 0)
1038 for (int i = 0; i < ids.length; i++)
1040 if (ids[i].trim().length() == 0)
1044 SequenceI sq = matcher.findIdMatch(ids[i]);
1048 sel.addSequence(sq, false);
1052 boolean inseqpos = false;
1053 if (cols != null && cols.length > 0)
1055 boolean seset = false;
1056 for (int i = 0; i < cols.length; i++)
1058 String cl = cols[i].trim();
1059 if (cl.length() == 0)
1064 if ((p = cl.indexOf("-")) > -1)
1066 int from = -1, to = -1;
1069 from = new Integer(cl.substring(0, p)).intValue();
1071 } catch (NumberFormatException ex)
1074 "ERROR: Couldn't parse first integer in range element column selection string '"
1075 + cl + "' - format is 'from-to'");
1080 to = new Integer(cl.substring(p + 1)).intValue();
1082 } catch (NumberFormatException ex)
1085 "ERROR: Couldn't parse second integer in range element column selection string '"
1086 + cl + "' - format is 'from-to'");
1089 if (from >= 0 && to >= 0)
1106 // comment to prevent range extension
1116 for (int r = from; r <= to; r++)
1118 if (r >= 0 && r < alw)
1125 System.err.println("Range '" + cl + "' deparsed as [" + from
1131 System.err.println("ERROR: Invalid Range '" + cl
1132 + "' deparsed as [" + from + "," + to + "]");
1140 r = new Integer(cl).intValue();
1142 } catch (NumberFormatException ex)
1144 if (cl.toLowerCase().equals("sequence"))
1146 // we are in the dataset sequence's coordinate frame.
1152 "ERROR: Couldn't parse integer from point selection element of column selection string '"
1157 if (r >= 0 && r <= alw)
1167 // comment to prevent range extension
1180 System.err.println("Point selection '" + cl
1181 + "' deparsed as [" + r + "]");
1186 System.err.println("ERROR: Invalid Point selection '" + cl
1187 + "' deparsed as [" + r + "]");
1194 // we only propagate the selection when it was the null selection, or the
1195 // given sequences were found in the alignment.
1196 if (inseqpos && sel.getSize() > 0)
1198 // assume first sequence provides reference frame ?
1199 SequenceI rs = sel.getSequenceAt(0);
1200 start = rs.findIndex(start);
1201 end = rs.findIndex(end);
1202 List<Integer> cs = new ArrayList<>(csel.getSelected());
1204 for (Integer selectedCol : cs)
1206 csel.addElement(rs.findIndex(selectedCol));
1209 sel.setStartRes(start);
1211 EventQueue.invokeLater(new Runnable()
1216 ((AlignFrame) alf).select(sel, csel, ((AlignFrame) alf)
1217 .getCurrentView().getAlignment().getHiddenColumns());
1223 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1225 AlignmentI alorder = ((AlignFrame) alf).getViewport().getAlignment();
1226 String[] order = new String[alorder.getHeight()];
1227 for (int i = 0; i < order.length; i++)
1229 order[i] = alorder.getSequenceAt(i).getName();
1231 return arrayToSeparatorList(order);
1234 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1235 String format, String suffix)
1239 AlignViewport vp = ((AlignFrame) alf).getViewport();
1240 FileFormatI theFormat = FileFormats.getInstance().forName(format);
1241 boolean seqlimits = (suffix == null
1242 || suffix.equalsIgnoreCase("true"));
1243 if (vp.getSelectionGroup() != null)
1245 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
1246 // method now returns a full copy of sequence data
1247 // TODO consider using getSequenceSelection instead here
1248 String reply = new AppletFormatAdapter().formatSequences(theFormat,
1249 new Alignment(vp.getSelectionAsNewSequence()),
1253 } catch (IllegalArgumentException ex)
1255 ex.printStackTrace();
1256 return "Error retrieving alignment, possibly invalid format specifier: "
1262 public String orderAlignmentBy(AlignFrameI alf, String order,
1263 String undoName, String sep)
1265 if (sep == null || sep.length() == 0)
1269 String[] ids = JalviewAppLoader.separatorListToArray(order, sep);
1270 SequenceI[] sqs = null;
1271 if (ids != null && ids.length > 0)
1273 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
1274 ((AlignFrame) alf).getViewport().getAlignment()
1275 .getSequencesArray());
1277 sqs = new SequenceI[ids.length];
1278 for (int i = 0; i < ids.length; i++)
1280 if (ids[i].trim().length() == 0)
1284 SequenceI sq = matcher.findIdMatch(ids[i]);
1292 SequenceI[] sqq = new SequenceI[s];
1293 System.arraycopy(sqs, 0, sqq, 0, s);
1306 final AlignmentOrder aorder = new AlignmentOrder(sqs);
1308 if (undoName != null && undoName.trim().length() == 0)
1312 final String _undoName = undoName;
1313 // TODO: deal with synchronization here: cannot raise any events until after
1314 // this has returned.
1315 return ((AlignFrame) alf).sortBy(aorder, _undoName) ? "true" : "";
1318 public String getAlignmentFrom(AlignFrameI alf, String format,
1323 boolean seqlimits = (suffix == null
1324 || suffix.equalsIgnoreCase("true"));
1326 FileFormatI theFormat = FileFormats.getInstance().forName(format);
1327 String reply = new AppletFormatAdapter().formatSequences(theFormat,
1328 ((AlignFrame) alf).getViewport().getAlignment(), seqlimits);
1330 } catch (IllegalArgumentException ex)
1332 ex.printStackTrace();
1333 return "Error retrieving alignment, possibly invalid format specifier: "