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.HiddenColumns;
11 import jalview.datamodel.PDBEntry;
12 import jalview.datamodel.Sequence;
13 import jalview.datamodel.SequenceGroup;
14 import jalview.datamodel.SequenceI;
15 import jalview.gui.AlignFrame;
16 import jalview.gui.AlignViewport;
17 import jalview.gui.Desktop;
18 import jalview.io.AnnotationFile;
19 import jalview.io.AppletFormatAdapter;
20 import jalview.io.DataSourceType;
21 import jalview.io.FeaturesFile;
22 import jalview.io.FileFormat;
23 import jalview.io.FileFormatI;
24 import jalview.io.FileFormats;
25 import jalview.io.IdentifyFile;
26 import jalview.io.JPredFile;
27 import jalview.io.JnetAnnotationMaker;
28 import jalview.io.NewickFile;
29 import jalview.structure.SelectionSource;
30 import jalview.structure.StructureSelectionManager;
31 import jalview.util.HttpUtils;
32 import jalview.util.MessageManager;
34 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.StringTokenizer;
39 import java.util.Vector;
42 * A class to load parameters for either JalviewLite or Jalview
47 public class JalviewAppLoader
50 private JalviewApp app; // Jalview or JalviewJS or JalviewLite
52 private boolean debug;
54 String separator = "\u00AC"; // JalviewLite note: the default used to
55 // be '|', but many sequence IDS include
58 public String getSeparator()
63 public void setSeparator(String separator)
65 this.separator = separator;
68 public JalviewAppLoader(boolean debug)
73 public void load(JalviewApp app)
78 String sep = app.getParameter("separator");
87 throw new Error(MessageManager
88 .getString("error.invalid_separator_parameter"));
102 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
108 protected boolean loadPdbFiles()
110 boolean result = false;
112 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
116 boolean doAlign = app.getDefaultParameter("alignpdbfiles", false);
117 app.setAlignPdbStructures(doAlign);
119 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
122 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
124 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
127 // Accumulate pdbs here if they are heading for the same view (if
128 // alignPdbStructures is true)
129 Vector<Object[]> pdbs = new Vector<>();
130 // create a lazy matcher if we're asked to
131 jalview.analysis.SequenceIdMatcher matcher = (app
132 .getDefaultParameter("relaxedidmatch", false))
133 ? new jalview.analysis.SequenceIdMatcher(
134 app.getViewport().getAlignment()
135 .getSequencesArray())
138 int pdbFileCount = 0;
142 if (pdbFileCount > 0)
144 param = app.getParameter("PDBFILE" + pdbFileCount);
148 param = app.getParameter("PDBFILE");
153 PDBEntry pdb = new PDBEntry();
156 SequenceI[] seqs = null;
157 String[] chains = null;
159 StringTokenizer st = new StringTokenizer(param, " ");
161 if (st.countTokens() < 2)
163 String sequence = app.getParameter("PDBSEQ");
164 if (sequence != null)
166 seqs = new SequenceI[] { matcher == null
167 ? (Sequence) app.getViewport().getAlignment()
169 : matcher.findIdMatch(sequence) };
175 param = st.nextToken();
176 List<SequenceI> tmp = new ArrayList<>();
177 List<String> tmp2 = new ArrayList<>();
179 while (st.hasMoreTokens())
181 seqstring = st.nextToken();
182 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
183 if (st2.countTokens() > 1)
186 tmp2.add(st2.nextToken());
187 seqstring = st2.nextToken();
189 tmp.add(matcher == null
190 ? (Sequence) app.getViewport().getAlignment()
192 : matcher.findIdMatch(seqstring));
195 seqs = tmp.toArray(new SequenceI[tmp.size()]);
196 if (tmp2.size() == tmp.size())
198 chains = tmp2.toArray(new String[tmp2.size()]);
203 DataSourceType protocol = resolveFileProtocol(app, ret);
204 // TODO check JAL-357 for files in a jar (CLASSLOADER)
209 for (int i = 0; i < seqs.length; i++)
213 ((Sequence) seqs[i]).addPDBId(pdb);
214 StructureSelectionManager
215 .getStructureSelectionManager(
216 (StructureSelectionManagerProvider) app)
217 .registerPDBEntry(pdb);
223 // this may not really be a problem but we give a warning
226 "Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
234 pdbs.addElement(new Object[] { pdb, seqs, chains, protocol });
238 app.newStructureView(pdb, seqs, chains, protocol);
244 } while (param != null || pdbFileCount < 10);
247 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
248 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
249 String[][] chains = new String[pdbs.size()][];
250 String[] protocols = new String[pdbs.size()];
251 for (int pdbsi = 0, pdbsiSize = pdbs
252 .size(); pdbsi < pdbsiSize; pdbsi++)
254 Object[] o = pdbs.elementAt(pdbsi);
255 pdb[pdbsi] = (PDBEntry) o[0];
256 seqs[pdbsi] = (SequenceI[]) o[1];
257 chains[pdbsi] = (String[]) o[2];
258 protocols[pdbsi] = (String) o[3];
260 app.alignedStructureView(pdb, seqs, chains, protocols);
267 * Load in a Jnetfile if specified by parameter. Returns true if loaded, else
273 protected boolean loadJnetFile()
275 boolean result = false;
276 String param = app.getParameter("jnetfile");
279 // jnet became jpred around 2016
280 param = app.getParameter("jpredfile");
287 DataSourceType protocol = resolveFileProtocol(app, ret);
288 JPredFile predictions = new JPredFile(ret[0], protocol);
289 JnetAnnotationMaker.add_annotation(predictions,
290 app.getViewport().getAlignment(), 0, false);
291 // false == do not add sequence profile from concise output
292 app.getViewport().getAlignment().setupJPredAlignment();
293 app.updateForAnnotations();
295 } catch (Exception ex)
297 ex.printStackTrace();
304 * Load annotations if specified by parameter. Returns true if loaded, else
310 protected boolean loadAnnotations()
312 boolean result = false;
313 String param = app.getParameter("annotations");
317 DataSourceType protocol = resolveFileProtocol(app, ret);
319 if (new AnnotationFile().annotateAlignmentView(app.getViewport(),
322 app.updateForAnnotations();
328 .println("Annotations were not added from annotation file '"
336 * Load features file and view settings as specified by parameters. Returns
337 * true if features were loaded, else false.
342 protected boolean loadFeatures()
344 boolean result = false;
345 // ///////////////////////////
346 // modify display of features
347 // we do this before any features have been loaded, ensuring any hidden
348 // groups are hidden when features first displayed
350 // hide specific groups
352 String param = app.getParameter("hidefeaturegroups");
355 app.setFeatureGroupState(separatorListToArray(param, separator),
357 // app.setFeatureGroupStateOn(newAlignFrame, param, false);
359 // show specific groups
360 param = app.getParameter("showfeaturegroups");
363 app.setFeatureGroupState(separatorListToArray(param, separator),
365 // app.setFeatureGroupStateOn(newAlignFrame, param, true);
367 // and now load features
368 param = app.getParameter("features");
372 DataSourceType protocol = resolveFileProtocol(app, ret);
374 result = app.parseFeaturesFile(ret[0], protocol);
377 param = app.getParameter("showFeatureSettings");
378 if (param != null && param.equalsIgnoreCase("true"))
380 app.newFeatureSettings();
386 * Load a score file if specified by parameter. Returns true if file was
387 * loaded, else false.
391 protected boolean loadScoreFile()
393 boolean result = false;
394 String sScoreFile = app.getParameter("scoreFile");
395 if (sScoreFile != null && !"".equals(sScoreFile))
402 "Attempting to load T-COFFEE score file from the scoreFile parameter");
404 result = app.loadScoreFile(sScoreFile);
408 "Failed to parse T-COFFEE parameter as a valid score file ('"
409 + sScoreFile + "')");
411 } catch (Exception e)
413 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
414 sScoreFile, e.getMessage());
420 String[] ret = new String[1];
423 * Load a tree for the alignment if specified by parameter. Returns true if a
424 * tree was loaded, else false.
429 protected boolean loadTree()
431 boolean result = false;
432 String treeFile = app.getParameter("tree");
433 if (treeFile == null)
435 treeFile = app.getParameter("treeFile");
438 if (treeFile != null)
443 NewickFile fin = new NewickFile(treeFile,
444 resolveFileProtocol(app, ret));
447 if (fin.getTree() != null)
449 app.loadTree(fin, ret[0]);
453 System.out.println("Successfully imported tree.");
461 "Tree parameter did not resolve to a valid tree.");
464 } catch (Exception ex)
466 ex.printStackTrace();
473 * form a complete URL given a path to a resource and a reference location on
477 * - an absolute path on the same server as localref or a document
478 * located relative to localref
480 * - a URL on the same server as url
481 * @return a complete URL for the resource located by url
483 public static String resolveUrlForLocalOrAbsolute(String targetPath,
486 String resolvedPath = "";
487 if (targetPath.startsWith("/"))
489 String codebase = localref.toString();
490 String localfile = localref.getFile();
491 resolvedPath = codebase.substring(0,
492 codebase.length() - localfile.length()) + targetPath;
497 * get URL path and strip off any trailing file e.g.
498 * www.jalview.org/examples/index.html#applets?a=b is trimmed to
499 * www.jalview.org/examples/
501 String urlPath = localref.toString();
502 String directoryPath = urlPath;
503 int lastSeparator = directoryPath.lastIndexOf("/");
504 if (lastSeparator > 0)
506 directoryPath = directoryPath.substring(0, lastSeparator + 1);
509 if (targetPath.startsWith("/"))
512 * construct absolute URL to a file on the server - this is not allowed?
514 // String localfile = localref.getFile();
515 // resolvedPath = urlPath.substring(0,
516 // urlPath.length() - localfile.length())
518 resolvedPath = directoryPath + targetPath.substring(1);
522 resolvedPath = directoryPath + targetPath;
526 // System.err.println(
527 // "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
533 * parse the string into a list
537 * @return elements separated by separator
539 public static String[] separatorListToArray(String list, String separator)
541 // TODO use StringUtils version (slightly different...)
542 int seplen = separator.length();
543 if (list == null || list.equals("") || list.equals(separator))
547 Vector<String> jv = new Vector<>();
549 while ((pos = list.indexOf(separator, cp)) > cp)
551 jv.addElement(list.substring(cp, pos));
554 if (cp < list.length())
556 String c = list.substring(cp);
557 if (!c.equals(separator))
564 String[] v = new String[jv.size()];
565 for (int i = 0; i < v.length; i++)
567 v[i] = jv.elementAt(i);
569 jv.removeAllElements();
572 // System.err.println("Array from '" + separator
573 // + "' separated List:\n" + v.length);
574 // for (int i = 0; i < v.length; i++)
576 // System.err.println("item " + i + " '" + v[i] + "'");
583 // System.err.println(
584 // "Empty Array from '" + separator + "' separated List");
589 public static DataSourceType resolveFileProtocol(JalviewApp app,
592 String path = retPath[0];
596 if (path.startsWith("PASTE"))
598 retPath[0] = path.substring(5);
599 return DataSourceType.PASTE;
605 if (path.indexOf("://") >= 0)
607 return DataSourceType.URL;
611 * try relative to document root
613 URL documentBase = app.getDocumentBase();
614 String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
615 if (HttpUtils.isValidUrl(withDocBase))
619 // System.err.println("Prepended document base '" + documentBase
620 // + "' to make: '" + withDocBase + "'");
622 retPath[0] = withDocBase;
623 return DataSourceType.URL;
627 * try relative to codebase (if different to document base)
629 URL codeBase = app.getCodeBase();
630 String withCodeBase = resolveUrlForLocalOrAbsolute(path, codeBase);
631 if (!withCodeBase.equals(withDocBase)
632 && HttpUtils.isValidUrl(withCodeBase))
636 // System.err.println("Prepended codebase '" + codeBase
637 // + "' to make: '" + withCodeBase + "'");
639 retPath[0] = withCodeBase;
640 return DataSourceType.URL;
644 * try locating by classloader; try this last so files in the directory
645 * are resolved using document base
647 if (inArchive(app.getClass(), path))
649 return DataSourceType.CLASSLOADER;
655 * Discovers whether the given file is in the Applet Archive
661 private static boolean inArchive(Class<?> c, String f)
663 // This might throw a security exception in certain browsers
664 // Netscape Communicator for instance.
667 boolean rtn = (c.getResourceAsStream("/" + f) != null);
670 // System.err.println("Resource '" + f + "' was "
671 // + (rtn ? "" : "not ") + "located by classloader.");
674 } catch (Exception ex)
676 System.out.println("Exception checking resources: " + f + " " + ex);
681 public void callInitCallback()
683 String initjscallback = app.getParameter("oninit");
684 if (initjscallback == null)
688 initjscallback = initjscallback.trim();
689 if (initjscallback.length() > 0)
696 * read sequence1...sequenceN as a raw alignment
701 public String getPastedSequence(JalviewApp jalviewApp)
703 StringBuffer data = new StringBuffer("PASTE");
706 while ((file = app.getParameter("sequence" + i)) != null)
708 data.append(file.toString() + "\n");
711 if (data.length() > 5)
713 file = data.toString();
719 * concatenate the list with separator
723 * @return concatenated string
725 public static String arrayToSeparatorList(String[] list, String separator)
727 // TODO use StringUtils version
728 StringBuffer v = new StringBuffer();
729 if (list != null && list.length > 0)
731 for (int i = 0, iSize = list.length; i < iSize; i++)
745 // .println("Returning '" + separator + "' separated List:\n");
746 // System.err.println(v);
752 // System.err.println(
753 // "Returning empty '" + separator + "' separated List\n");
755 return "" + separator;
758 public String arrayToSeparatorList(String[] array)
760 return arrayToSeparatorList(array, separator);
763 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
765 StringBuffer result = new StringBuffer("");
766 if (sep == null || sep.length() == 0)
768 sep = separator; // "+0x00AC;
770 AlignViewport v = ((AlignFrame) alf).getViewport();
771 if (v.getSelectionGroup() != null)
773 SequenceI[] seqs = v.getSelectionGroup()
774 .getSequencesInOrder(v.getAlignment());
776 for (int i = 0; i < seqs.length; i++)
778 result.append(seqs[i].getName());
783 return result.toString();
786 public void setFeatureGroupStateOn(final AlignFrameI alf,
787 final String groups, boolean state)
789 Jalview.execRunnable(new Runnable()
794 ((AlignFrame) alf).setFeatureGroupState(
795 separatorListToArray(groups, separator), state);
800 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
802 return arrayToSeparatorList(
803 ((AlignFrame) alf).getFeatureGroupsOfState(visible));
806 public void scrollViewToIn(final AlignFrameI alf, final String topRow,
807 final String leftHandColumn)
809 Jalview.execRunnable(new Runnable()
816 ((AlignFrame) alf).scrollTo(new Integer(topRow).intValue(),
817 new Integer(leftHandColumn).intValue());
819 } catch (Exception ex)
821 System.err.println("Couldn't parse integer arguments (topRow='"
822 + topRow + "' and leftHandColumn='" + leftHandColumn
824 ex.printStackTrace();
830 public void scrollViewToRowIn(final AlignFrameI alf, final String topRow)
833 Jalview.execRunnable(new Runnable()
840 ((AlignFrame) alf).scrollToRow(new Integer(topRow).intValue());
842 } catch (Exception ex)
844 System.err.println("Couldn't parse integer arguments (topRow='"
846 ex.printStackTrace();
853 public void scrollViewToColumnIn(final AlignFrameI alf,
854 final String leftHandColumn)
856 Jalview.execRunnable(new Runnable()
865 .scrollToColumn(new Integer(leftHandColumn).intValue());
867 } catch (Exception ex)
870 "Couldn't parse integer arguments (leftHandColumn='"
871 + leftHandColumn + "')");
872 ex.printStackTrace();
879 public boolean addPdbFile(AlignFrameI alf, String sequenceId,
880 String pdbEntryString, String pdbFile)
882 AlignFrame alFrame = (AlignFrame) alf;
883 SequenceI toaddpdb = alFrame.getViewport().getAlignment()
884 .findName(sequenceId);
885 boolean needtoadd = false;
886 if (toaddpdb != null)
888 Vector<PDBEntry> pdbe = toaddpdb.getAllPDBEntries();
889 PDBEntry pdbentry = null;
890 if (pdbe != null && pdbe.size() > 0)
892 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
894 pdbentry = pdbe.elementAt(pe);
895 if (!pdbentry.getId().equals(pdbEntryString)
896 && !pdbentry.getFile().equals(pdbFile))
906 if (pdbentry == null)
908 pdbentry = new PDBEntry();
909 pdbentry.setId(pdbEntryString);
910 pdbentry.setFile(pdbFile);
911 needtoadd = true; // add this new entry to sequence.
913 // resolve data source
914 // TODO: this code should be a refactored to an io package
915 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
917 if (protocol == null)
923 pdbentry.setProperty("protocol", protocol);
924 toaddpdb.addPDBId(pdbentry);
925 alFrame.alignPanel.getStructureSelectionManager()
926 .registerPDBEntry(pdbentry);
932 public AlignFrameI loadAlignment(String text, int width, int height,
935 AlignmentI al = null;
939 FileFormatI format = new IdentifyFile().identify(text,
940 DataSourceType.PASTE);
941 al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE,
943 if (al.getHeight() > 0)
945 return new AlignFrame(al, width, height, title);
947 } catch (IOException ex)
949 ex.printStackTrace();
954 public String getFeatureGroupsOn(AlignFrameI alf)
956 return arrayToSeparatorList(
957 ((AlignFrame) alf).getFeatureGroups());
960 public void highlightIn(final AlignFrameI alf, final String sequenceId,
961 final String position, final String alignedPosition)
963 // TODO: could try to highlight in all alignments if alf==null
964 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
965 ((AlignFrame) alf).getViewport().getAlignment()
966 .getSequencesArray());
967 final SequenceI sq = matcher.findIdMatch(sequenceId);
973 apos = new Integer(position).intValue();
975 } catch (NumberFormatException ex)
979 final int pos = apos;
980 // use vamsas listener to broadcast to all listeners in scope
981 if (alignedPosition != null && (alignedPosition.trim().length() == 0
982 || alignedPosition.toLowerCase().indexOf("false") > -1))
984 Jalview.execRunnable(new Runnable()
989 StructureSelectionManager
990 .getStructureSelectionManager(Desktop.getInstance())
991 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
997 Jalview.execRunnable(new Runnable()
1002 StructureSelectionManager
1003 .getStructureSelectionManager(Desktop.getInstance())
1004 .mouseOverVamsasSequence(sq, pos, null);
1011 public void selectIn(final AlignFrameI alf, String sequenceIds,
1012 String columns, String sep)
1014 if (sep == null || sep.length() == 0)
1022 System.err.println("Selecting region using separator string '"
1027 String[] ids = JalviewAppLoader.separatorListToArray(sequenceIds, sep);
1028 String[] cols = JalviewAppLoader.separatorListToArray(columns, sep);
1029 final SequenceGroup sel = new SequenceGroup();
1030 final ColumnSelection csel = new ColumnSelection();
1031 AlignmentI al = ((AlignFrame) alf).getViewport().getAlignment();
1032 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
1033 ((AlignFrame) alf).getViewport().getAlignment()
1034 .getSequencesArray());
1035 int start = 0, end = al.getWidth(), alw = al.getWidth();
1036 boolean seqsfound = true;
1037 if (ids != null && ids.length > 0)
1040 for (int i = 0; i < ids.length; i++)
1042 if (ids[i].trim().length() == 0)
1046 SequenceI sq = matcher.findIdMatch(ids[i]);
1050 sel.addSequence(sq, false);
1054 boolean inseqpos = false;
1055 if (cols != null && cols.length > 0)
1057 boolean seset = false;
1058 for (int i = 0; i < cols.length; i++)
1060 String cl = cols[i].trim();
1061 if (cl.length() == 0)
1066 if ((p = cl.indexOf("-")) > -1)
1068 int from = -1, to = -1;
1071 from = new Integer(cl.substring(0, p)).intValue();
1073 } catch (NumberFormatException ex)
1076 "ERROR: Couldn't parse first integer in range element column selection string '"
1077 + cl + "' - format is 'from-to'");
1082 to = new Integer(cl.substring(p + 1)).intValue();
1084 } catch (NumberFormatException ex)
1087 "ERROR: Couldn't parse second integer in range element column selection string '"
1088 + cl + "' - format is 'from-to'");
1091 if (from >= 0 && to >= 0)
1108 // comment to prevent range extension
1118 for (int r = from; r <= to; r++)
1120 if (r >= 0 && r < alw)
1127 System.err.println("Range '" + cl + "' deparsed as [" + from
1133 System.err.println("ERROR: Invalid Range '" + cl
1134 + "' deparsed as [" + from + "," + to + "]");
1142 r = new Integer(cl).intValue();
1144 } catch (NumberFormatException ex)
1146 if (cl.toLowerCase().equals("sequence"))
1148 // we are in the dataset sequence's coordinate frame.
1154 "ERROR: Couldn't parse integer from point selection element of column selection string '"
1159 if (r >= 0 && r <= alw)
1169 // comment to prevent range extension
1182 System.err.println("Point selection '" + cl
1183 + "' deparsed as [" + r + "]");
1188 System.err.println("ERROR: Invalid Point selection '" + cl
1189 + "' deparsed as [" + r + "]");
1196 // we only propagate the selection when it was the null selection, or the
1197 // given sequences were found in the alignment.
1198 if (inseqpos && sel.getSize() > 0)
1200 // assume first sequence provides reference frame ?
1201 SequenceI rs = sel.getSequenceAt(0);
1202 start = rs.findIndex(start);
1203 end = rs.findIndex(end);
1204 List<Integer> cs = new ArrayList<>(csel.getSelected());
1206 for (Integer selectedCol : cs)
1208 csel.addElement(rs.findIndex(selectedCol));
1211 sel.setStartRes(start);
1213 Jalview.execRunnable(new Runnable()
1218 ((AlignFrame) alf).select(sel, csel, ((AlignFrame) alf)
1219 .getCurrentView().getAlignment().getHiddenColumns());
1225 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1227 AlignmentI alorder = ((AlignFrame) alf).getViewport().getAlignment();
1228 String[] order = new String[alorder.getHeight()];
1229 for (int i = 0; i < order.length; i++)
1231 order[i] = alorder.getSequenceAt(i).getName();
1233 return arrayToSeparatorList(order, sep);
1236 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1237 String format, String suffix)
1241 AlignViewport vp = ((AlignFrame) alf).getViewport();
1242 FileFormatI theFormat = FileFormats.getInstance().forName(format);
1243 boolean seqlimits = (suffix == null
1244 || suffix.equalsIgnoreCase("true"));
1245 if (vp.getSelectionGroup() != null)
1247 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
1248 // method now returns a full copy of sequence data
1249 // TODO consider using getSequenceSelection instead here
1250 String reply = new AppletFormatAdapter().formatSequences(theFormat,
1251 new Alignment(vp.getSelectionAsNewSequence()),
1255 } catch (IllegalArgumentException ex)
1257 ex.printStackTrace();
1258 return "Error retrieving alignment, possibly invalid format specifier: "
1264 public String orderAlignmentBy(AlignFrameI alf, String order,
1265 String undoName, String sep)
1267 if (sep == null || sep.length() == 0)
1271 String[] ids = JalviewAppLoader.separatorListToArray(order, sep);
1272 SequenceI[] sqs = null;
1273 if (ids != null && ids.length > 0)
1275 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
1276 ((AlignFrame) alf).getViewport().getAlignment()
1277 .getSequencesArray());
1279 sqs = new SequenceI[ids.length];
1280 for (int i = 0; i < ids.length; i++)
1282 if (ids[i].trim().length() == 0)
1286 SequenceI sq = matcher.findIdMatch(ids[i]);
1294 SequenceI[] sqq = new SequenceI[s];
1295 System.arraycopy(sqs, 0, sqq, 0, s);
1307 final AlignmentOrder aorder = new AlignmentOrder(sqs);
1309 if (undoName != null && undoName.trim().length() == 0)
1313 final String _undoName = undoName;
1314 // TODO: deal with synchronization here: cannot raise any events until after
1315 // this has returned.
1316 return ((AlignFrame) alf).sortBy(aorder, _undoName) ? "true" : "";
1319 public String getAlignmentFrom(AlignFrameI alf, String format,
1324 boolean seqlimits = (suffix == null
1325 || suffix.equalsIgnoreCase("true"));
1327 FileFormatI theFormat = FileFormats.getInstance().forName(format);
1328 String reply = new AppletFormatAdapter().formatSequences(theFormat,
1329 ((AlignFrame) alf).getViewport().getAlignment(), seqlimits);
1331 } catch (IllegalArgumentException ex)
1333 ex.printStackTrace();
1334 return "Error retrieving alignment, possibly invalid format specifier: "
1339 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1341 if (new AnnotationFile().annotateAlignmentView(
1342 ((AlignFrame) alf).getViewport(), annotation,
1343 DataSourceType.PASTE))
1345 ((AlignFrame) alf).alignPanel.fontChanged();
1346 ((AlignFrame) alf).alignPanel.setScrollValues(0, 0);
1350 ((AlignFrame) alf).parseFeaturesFile(annotation,
1351 DataSourceType.PASTE);
1355 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1356 boolean autoenabledisplay)
1358 boolean ret = ((AlignFrame) alf).parseFeaturesFile(features,
1359 DataSourceType.PASTE);
1364 if (autoenabledisplay)
1366 ((AlignFrame) alf).getViewport().setShowSequenceFeatures(true);
1367 // this next was for a checkbox in JalviewLite
1368 // ((AlignFrame) alf).getViewport().sequenceFeatures.setState(true);
1373 public String getFeaturesFrom(AlignFrameI alf, String format)
1375 AlignFrame f = ((AlignFrame) alf);
1378 FeaturesFile formatter = new FeaturesFile();
1379 if (format.equalsIgnoreCase("Jalview"))
1381 features = formatter.printJalviewFormat(
1382 f.getViewport().getAlignment().getSequencesArray(),
1383 f.alignPanel.getFeatureRenderer(), true);
1387 features = formatter.printGffFormat(
1388 f.getViewport().getAlignment().getSequencesArray(),
1389 f.alignPanel.getFeatureRenderer(), true);
1392 if (features == null)
1400 public String getAnnotationFrom(AlignFrameI alf)
1402 AlignFrame f = (AlignFrame) alf;
1403 String annotation = new AnnotationFile()
1404 .printAnnotationsForView(f.getViewport());
1408 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1410 return (AlignFrameI) ((AlignFrame) alf).newView(name, true);
1413 public String[] separatorListToArray(String list)
1415 return separatorListToArray(list, separator);
1418 public Object[] getSelectionForListener(AlignFrameI currentFrame,
1419 SequenceGroup seqsel, ColumnSelection colsel,
1420 HiddenColumns hidden, SelectionSource source, Object alignFrame)
1422 // System.err.println("Testing selection event relay to
1423 // jsfunction:"+_listener);
1425 AlignFrame src = (AlignFrame) alignFrame;
1428 if (source instanceof AlignViewport
1429 && ((AlignFrame) currentFrame).getViewport() == source)
1431 // should be valid if it just generated an event!
1432 src = (AlignFrame) currentFrame;
1436 String[] seqs = new String[] {};
1437 String[] cols = new String[] {};
1438 int strt = 0, end = (src == null) ? -1
1439 : src.alignPanel.av.getAlignment().getWidth();
1440 if (seqsel != null && seqsel.getSize() > 0)
1442 seqs = new String[seqsel.getSize()];
1443 for (int i = 0; i < seqs.length; i++)
1445 seqs[i] = seqsel.getSequenceAt(i).getName();
1447 if (strt < seqsel.getStartRes())
1449 strt = seqsel.getStartRes();
1451 if (end == -1 || end > seqsel.getEndRes())
1453 end = seqsel.getEndRes();
1456 if (colsel != null && !colsel.isEmpty())
1460 end = colsel.getMax() + 1;
1462 cols = new String[colsel.getSelected().size()];
1463 for (int i = 0; i < cols.length; i++)
1465 cols[i] = "" + (1 + colsel.getSelected().get(i).intValue());
1470 if (seqsel != null && seqsel.getSize() > 0)
1472 // send a valid range, otherwise we send the empty selection
1473 cols = new String[2];
1474 cols[0] = "" + (1 + strt) + "-" + (1 + end);
1477 return new Object[] { src, setid, arrayToSeparatorList(seqs),
1478 arrayToSeparatorList(cols) };