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.awt.EventQueue;
35 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.StringTokenizer;
40 import java.util.Vector;
43 * A class to load parameters for either JalviewLite or Jalview
48 public class JalviewAppLoader
51 private JalviewApp app; // Jalview or JalviewJS or JalviewLite
53 private boolean debug;
55 String separator = "\u00AC"; // JalviewLite note: the default used to
56 // be '|', but many sequence IDS include
59 public String getSeparator()
64 public void setSeparator(String separator)
66 this.separator = separator;
69 public JalviewAppLoader(boolean debug)
74 public void load(JalviewApp app)
79 String sep = app.getParameter("separator");
88 throw new Error(MessageManager
89 .getString("error.invalid_separator_parameter"));
103 * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
109 protected boolean loadPdbFiles()
111 boolean result = false;
113 * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
117 boolean doAlign = app.getDefaultParameter("alignpdbfiles", false);
118 app.setAlignPdbStructures(doAlign);
120 * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
123 * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
125 * <param name="PDBfile3" value="1q0o Q45135_9MICO">
128 // Accumulate pdbs here if they are heading for the same view (if
129 // alignPdbStructures is true)
130 Vector<Object[]> pdbs = new Vector<>();
131 // create a lazy matcher if we're asked to
132 jalview.analysis.SequenceIdMatcher matcher = (app
133 .getDefaultParameter("relaxedidmatch", false))
134 ? new jalview.analysis.SequenceIdMatcher(
135 app.getViewport().getAlignment()
136 .getSequencesArray())
139 int pdbFileCount = 0;
143 if (pdbFileCount > 0)
145 param = app.getParameter("PDBFILE" + pdbFileCount);
149 param = app.getParameter("PDBFILE");
154 PDBEntry pdb = new PDBEntry();
157 SequenceI[] seqs = null;
158 String[] chains = null;
160 StringTokenizer st = new StringTokenizer(param, " ");
162 if (st.countTokens() < 2)
164 String sequence = app.getParameter("PDBSEQ");
165 if (sequence != null)
167 seqs = new SequenceI[] { matcher == null
168 ? (Sequence) app.getViewport().getAlignment()
170 : matcher.findIdMatch(sequence) };
176 param = st.nextToken();
177 List<SequenceI> tmp = new ArrayList<>();
178 List<String> tmp2 = new ArrayList<>();
180 while (st.hasMoreTokens())
182 seqstring = st.nextToken();
183 StringTokenizer st2 = new StringTokenizer(seqstring, "=");
184 if (st2.countTokens() > 1)
187 tmp2.add(st2.nextToken());
188 seqstring = st2.nextToken();
190 tmp.add(matcher == null
191 ? (Sequence) app.getViewport().getAlignment()
193 : matcher.findIdMatch(seqstring));
196 seqs = tmp.toArray(new SequenceI[tmp.size()]);
197 if (tmp2.size() == tmp.size())
199 chains = tmp2.toArray(new String[tmp2.size()]);
204 DataSourceType protocol = resolveFileProtocol(app, ret);
205 // TODO check JAL-357 for files in a jar (CLASSLOADER)
210 for (int i = 0; i < seqs.length; i++)
214 ((Sequence) seqs[i]).addPDBId(pdb);
215 StructureSelectionManager
216 .getStructureSelectionManager(
217 (StructureSelectionManagerProvider) app)
218 .registerPDBEntry(pdb);
224 // this may not really be a problem but we give a warning
227 "Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
235 pdbs.addElement(new Object[] { pdb, seqs, chains, protocol });
239 app.newStructureView(pdb, seqs, chains, protocol);
245 } while (param != null || pdbFileCount < 10);
248 SequenceI[][] seqs = new SequenceI[pdbs.size()][];
249 PDBEntry[] pdb = new PDBEntry[pdbs.size()];
250 String[][] chains = new String[pdbs.size()][];
251 String[] protocols = new String[pdbs.size()];
252 for (int pdbsi = 0, pdbsiSize = pdbs
253 .size(); pdbsi < pdbsiSize; pdbsi++)
255 Object[] o = pdbs.elementAt(pdbsi);
256 pdb[pdbsi] = (PDBEntry) o[0];
257 seqs[pdbsi] = (SequenceI[]) o[1];
258 chains[pdbsi] = (String[]) o[2];
259 protocols[pdbsi] = (String) o[3];
261 app.alignedStructureView(pdb, seqs, chains, protocols);
268 * Load in a Jnetfile if specified by parameter. Returns true if loaded, else
274 protected boolean loadJnetFile()
276 boolean result = false;
277 String param = app.getParameter("jnetfile");
280 // jnet became jpred around 2016
281 param = app.getParameter("jpredfile");
288 DataSourceType protocol = resolveFileProtocol(app, ret);
289 JPredFile predictions = new JPredFile(ret[0], protocol);
290 JnetAnnotationMaker.add_annotation(predictions,
291 app.getViewport().getAlignment(), 0, false);
292 // false == do not add sequence profile from concise output
293 app.getViewport().getAlignment().setupJPredAlignment();
294 app.updateForAnnotations();
296 } catch (Exception ex)
298 ex.printStackTrace();
305 * Load annotations if specified by parameter. Returns true if loaded, else
311 protected boolean loadAnnotations()
313 boolean result = false;
314 String param = app.getParameter("annotations");
318 DataSourceType protocol = resolveFileProtocol(app, ret);
320 if (new AnnotationFile().annotateAlignmentView(app.getViewport(),
323 app.updateForAnnotations();
329 .println("Annotations were not added from annotation file '"
337 * Load features file and view settings as specified by parameters. Returns
338 * true if features were loaded, else false.
343 protected boolean loadFeatures()
345 boolean result = false;
346 // ///////////////////////////
347 // modify display of features
348 // we do this before any features have been loaded, ensuring any hidden
349 // groups are hidden when features first displayed
351 // hide specific groups
353 String param = app.getParameter("hidefeaturegroups");
356 app.setFeatureGroupState(separatorListToArray(param, separator),
358 // app.setFeatureGroupStateOn(newAlignFrame, param, false);
360 // show specific groups
361 param = app.getParameter("showfeaturegroups");
364 app.setFeatureGroupState(separatorListToArray(param, separator),
366 // app.setFeatureGroupStateOn(newAlignFrame, param, true);
368 // and now load features
369 param = app.getParameter("features");
373 DataSourceType protocol = resolveFileProtocol(app, ret);
375 result = app.parseFeaturesFile(ret[0], protocol);
378 param = app.getParameter("showFeatureSettings");
379 if (param != null && param.equalsIgnoreCase("true"))
381 app.newFeatureSettings();
387 * Load a score file if specified by parameter. Returns true if file was
388 * loaded, else false.
392 protected boolean loadScoreFile()
394 boolean result = false;
395 String sScoreFile = app.getParameter("scoreFile");
396 if (sScoreFile != null && !"".equals(sScoreFile))
403 "Attempting to load T-COFFEE score file from the scoreFile parameter");
405 result = app.loadScoreFile(sScoreFile);
409 "Failed to parse T-COFFEE parameter as a valid score file ('"
410 + sScoreFile + "')");
412 } catch (Exception e)
414 System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
415 sScoreFile, e.getMessage());
421 String[] ret = new String[1];
424 * Load a tree for the alignment if specified by parameter. Returns true if a
425 * tree was loaded, else false.
430 protected boolean loadTree()
432 boolean result = false;
433 String treeFile = app.getParameter("tree");
434 if (treeFile == null)
436 treeFile = app.getParameter("treeFile");
439 if (treeFile != null)
444 NewickFile fin = new NewickFile(treeFile,
445 resolveFileProtocol(app, ret));
448 if (fin.getTree() != null)
450 app.loadTree(fin, ret[0]);
454 System.out.println("Successfully imported tree.");
462 "Tree parameter did not resolve to a valid tree.");
465 } catch (Exception ex)
467 ex.printStackTrace();
474 * form a complete URL given a path to a resource and a reference location on
478 * - an absolute path on the same server as localref or a document
479 * located relative to localref
481 * - a URL on the same server as url
482 * @return a complete URL for the resource located by url
484 public static String resolveUrlForLocalOrAbsolute(String targetPath,
487 String resolvedPath = "";
488 if (targetPath.startsWith("/"))
490 String codebase = localref.toString();
491 String localfile = localref.getFile();
492 resolvedPath = codebase.substring(0,
493 codebase.length() - localfile.length()) + targetPath;
498 * get URL path and strip off any trailing file e.g.
499 * www.jalview.org/examples/index.html#applets?a=b is trimmed to
500 * www.jalview.org/examples/
502 String urlPath = localref.toString();
503 String directoryPath = urlPath;
504 int lastSeparator = directoryPath.lastIndexOf("/");
505 if (lastSeparator > 0)
507 directoryPath = directoryPath.substring(0, lastSeparator + 1);
510 if (targetPath.startsWith("/"))
513 * construct absolute URL to a file on the server - this is not allowed?
515 // String localfile = localref.getFile();
516 // resolvedPath = urlPath.substring(0,
517 // urlPath.length() - localfile.length())
519 resolvedPath = directoryPath + targetPath.substring(1);
523 resolvedPath = directoryPath + targetPath;
527 // System.err.println(
528 // "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
534 * parse the string into a list
538 * @return elements separated by separator
540 public static String[] separatorListToArray(String list, String separator)
542 // TODO use StringUtils version (slightly different...)
543 int seplen = separator.length();
544 if (list == null || list.equals("") || list.equals(separator))
548 Vector<String> jv = new Vector<>();
550 while ((pos = list.indexOf(separator, cp)) > cp)
552 jv.addElement(list.substring(cp, pos));
555 if (cp < list.length())
557 String c = list.substring(cp);
558 if (!c.equals(separator))
565 String[] v = new String[jv.size()];
566 for (int i = 0; i < v.length; i++)
568 v[i] = jv.elementAt(i);
570 jv.removeAllElements();
573 // System.err.println("Array from '" + separator
574 // + "' separated List:\n" + v.length);
575 // for (int i = 0; i < v.length; i++)
577 // System.err.println("item " + i + " '" + v[i] + "'");
584 // System.err.println(
585 // "Empty Array from '" + separator + "' separated List");
590 public static DataSourceType resolveFileProtocol(JalviewApp app,
593 String path = retPath[0];
597 if (path.startsWith("PASTE"))
599 retPath[0] = path.substring(5);
600 return DataSourceType.PASTE;
606 if (path.indexOf("://") >= 0)
608 return DataSourceType.URL;
612 * try relative to document root
614 URL documentBase = app.getDocumentBase();
615 String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
616 if (HttpUtils.isValidUrl(withDocBase))
620 // System.err.println("Prepended document base '" + documentBase
621 // + "' to make: '" + withDocBase + "'");
623 retPath[0] = withDocBase;
624 return DataSourceType.URL;
628 * try relative to codebase (if different to document base)
630 URL codeBase = app.getCodeBase();
631 String withCodeBase = resolveUrlForLocalOrAbsolute(path, codeBase);
632 if (!withCodeBase.equals(withDocBase)
633 && HttpUtils.isValidUrl(withCodeBase))
637 // System.err.println("Prepended codebase '" + codeBase
638 // + "' to make: '" + withCodeBase + "'");
640 retPath[0] = withCodeBase;
641 return DataSourceType.URL;
645 * try locating by classloader; try this last so files in the directory
646 * are resolved using document base
648 if (inArchive(app.getClass(), path))
650 return DataSourceType.CLASSLOADER;
656 * Discovers whether the given file is in the Applet Archive
662 private static boolean inArchive(Class<?> c, String f)
664 // This might throw a security exception in certain browsers
665 // Netscape Communicator for instance.
668 boolean rtn = (c.getResourceAsStream("/" + f) != null);
671 // System.err.println("Resource '" + f + "' was "
672 // + (rtn ? "" : "not ") + "located by classloader.");
675 } catch (Exception ex)
677 System.out.println("Exception checking resources: " + f + " " + ex);
682 public void callInitCallback()
684 String initjscallback = app.getParameter("oninit");
685 if (initjscallback == null)
689 initjscallback = initjscallback.trim();
690 if (initjscallback.length() > 0)
697 * read sequence1...sequenceN as a raw alignment
702 public String getPastedSequence(JalviewApp jalviewApp)
704 StringBuffer data = new StringBuffer("PASTE");
707 while ((file = app.getParameter("sequence" + i)) != null)
709 data.append(file.toString() + "\n");
712 if (data.length() > 5)
714 file = data.toString();
720 * concatenate the list with separator
724 * @return concatenated string
726 public static String arrayToSeparatorList(String[] list, String separator)
728 // TODO use StringUtils version
729 StringBuffer v = new StringBuffer();
730 if (list != null && list.length > 0)
732 for (int i = 0, iSize = list.length; i < iSize; i++)
746 // .println("Returning '" + separator + "' separated List:\n");
747 // System.err.println(v);
753 // System.err.println(
754 // "Returning empty '" + separator + "' separated List\n");
756 return "" + separator;
759 public String arrayToSeparatorList(String[] array)
761 return arrayToSeparatorList(array, separator);
764 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
766 StringBuffer result = new StringBuffer("");
767 if (sep == null || sep.length() == 0)
769 sep = separator; // "+0x00AC;
771 AlignViewport v = ((AlignFrame) alf).getViewport();
772 if (v.getSelectionGroup() != null)
774 SequenceI[] seqs = v.getSelectionGroup()
775 .getSequencesInOrder(v.getAlignment());
777 for (int i = 0; i < seqs.length; i++)
779 result.append(seqs[i].getName());
784 return result.toString();
787 public void setFeatureGroupStateOn(final AlignFrameI alf,
788 final String groups, boolean state)
790 java.awt.EventQueue.invokeLater(new Runnable()
795 ((AlignFrame) alf).setFeatureGroupState(
796 separatorListToArray(groups, separator), state);
801 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
803 return arrayToSeparatorList(
804 ((AlignFrame) alf).getFeatureGroupsOfState(visible));
807 public void scrollViewToIn(final AlignFrameI alf, final String topRow,
808 final String leftHandColumn)
810 java.awt.EventQueue.invokeLater(new Runnable()
817 ((AlignFrame) alf).scrollTo(new Integer(topRow).intValue(),
818 new Integer(leftHandColumn).intValue());
820 } catch (Exception ex)
822 System.err.println("Couldn't parse integer arguments (topRow='"
823 + topRow + "' and leftHandColumn='" + leftHandColumn
825 ex.printStackTrace();
831 public void scrollViewToRowIn(final AlignFrameI alf, final String topRow)
834 java.awt.EventQueue.invokeLater(new Runnable()
841 ((AlignFrame) alf).scrollToRow(new Integer(topRow).intValue());
843 } catch (Exception ex)
845 System.err.println("Couldn't parse integer arguments (topRow='"
847 ex.printStackTrace();
854 public void scrollViewToColumnIn(final AlignFrameI alf,
855 final String leftHandColumn)
857 java.awt.EventQueue.invokeLater(new Runnable()
866 .scrollToColumn(new Integer(leftHandColumn).intValue());
868 } catch (Exception ex)
871 "Couldn't parse integer arguments (leftHandColumn='"
872 + leftHandColumn + "')");
873 ex.printStackTrace();
880 public boolean addPdbFile(AlignFrameI alf, String sequenceId,
881 String pdbEntryString, String pdbFile)
883 AlignFrame alFrame = (AlignFrame) alf;
884 SequenceI toaddpdb = alFrame.getViewport().getAlignment()
885 .findName(sequenceId);
886 boolean needtoadd = false;
887 if (toaddpdb != null)
889 Vector<PDBEntry> pdbe = toaddpdb.getAllPDBEntries();
890 PDBEntry pdbentry = null;
891 if (pdbe != null && pdbe.size() > 0)
893 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
895 pdbentry = pdbe.elementAt(pe);
896 if (!pdbentry.getId().equals(pdbEntryString)
897 && !pdbentry.getFile().equals(pdbFile))
907 if (pdbentry == null)
909 pdbentry = new PDBEntry();
910 pdbentry.setId(pdbEntryString);
911 pdbentry.setFile(pdbFile);
912 needtoadd = true; // add this new entry to sequence.
914 // resolve data source
915 // TODO: this code should be a refactored to an io package
916 DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
918 if (protocol == null)
924 pdbentry.setProperty("protocol", protocol);
925 toaddpdb.addPDBId(pdbentry);
926 alFrame.alignPanel.getStructureSelectionManager()
927 .registerPDBEntry(pdbentry);
933 public AlignFrameI loadAlignment(String text, int width, int height,
936 AlignmentI al = null;
940 FileFormatI format = new IdentifyFile().identify(text,
941 DataSourceType.PASTE);
942 al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE,
944 if (al.getHeight() > 0)
946 return new AlignFrame(al, width, height, title);
948 } catch (IOException ex)
950 ex.printStackTrace();
955 public String getFeatureGroupsOn(AlignFrameI alf)
957 return arrayToSeparatorList(
958 ((AlignFrame) alf).getFeatureGroups());
961 public void highlightIn(final AlignFrameI alf, final String sequenceId,
962 final String position, final String alignedPosition)
964 // TODO: could try to highlight in all alignments if alf==null
965 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
966 ((AlignFrame) alf).getViewport().getAlignment()
967 .getSequencesArray());
968 final SequenceI sq = matcher.findIdMatch(sequenceId);
974 apos = new Integer(position).intValue();
976 } catch (NumberFormatException ex)
980 final int pos = apos;
981 // use vamsas listener to broadcast to all listeners in scope
982 if (alignedPosition != null && (alignedPosition.trim().length() == 0
983 || alignedPosition.toLowerCase().indexOf("false") > -1))
985 java.awt.EventQueue.invokeLater(new Runnable()
990 StructureSelectionManager
991 .getStructureSelectionManager(Desktop.getInstance())
992 .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
998 java.awt.EventQueue.invokeLater(new Runnable()
1003 StructureSelectionManager
1004 .getStructureSelectionManager(Desktop.getInstance())
1005 .mouseOverVamsasSequence(sq, pos, null);
1012 public void selectIn(final AlignFrameI alf, String sequenceIds,
1013 String columns, String sep)
1015 if (sep == null || sep.length() == 0)
1023 System.err.println("Selecting region using separator string '"
1028 String[] ids = JalviewAppLoader.separatorListToArray(sequenceIds, sep);
1029 String[] cols = JalviewAppLoader.separatorListToArray(columns, sep);
1030 final SequenceGroup sel = new SequenceGroup();
1031 final ColumnSelection csel = new ColumnSelection();
1032 AlignmentI al = ((AlignFrame) alf).getViewport().getAlignment();
1033 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
1034 ((AlignFrame) alf).getViewport().getAlignment()
1035 .getSequencesArray());
1036 int start = 0, end = al.getWidth(), alw = al.getWidth();
1037 boolean seqsfound = true;
1038 if (ids != null && ids.length > 0)
1041 for (int i = 0; i < ids.length; i++)
1043 if (ids[i].trim().length() == 0)
1047 SequenceI sq = matcher.findIdMatch(ids[i]);
1051 sel.addSequence(sq, false);
1055 boolean inseqpos = false;
1056 if (cols != null && cols.length > 0)
1058 boolean seset = false;
1059 for (int i = 0; i < cols.length; i++)
1061 String cl = cols[i].trim();
1062 if (cl.length() == 0)
1067 if ((p = cl.indexOf("-")) > -1)
1069 int from = -1, to = -1;
1072 from = new Integer(cl.substring(0, p)).intValue();
1074 } catch (NumberFormatException ex)
1077 "ERROR: Couldn't parse first integer in range element column selection string '"
1078 + cl + "' - format is 'from-to'");
1083 to = new Integer(cl.substring(p + 1)).intValue();
1085 } catch (NumberFormatException ex)
1088 "ERROR: Couldn't parse second integer in range element column selection string '"
1089 + cl + "' - format is 'from-to'");
1092 if (from >= 0 && to >= 0)
1109 // comment to prevent range extension
1119 for (int r = from; r <= to; r++)
1121 if (r >= 0 && r < alw)
1128 System.err.println("Range '" + cl + "' deparsed as [" + from
1134 System.err.println("ERROR: Invalid Range '" + cl
1135 + "' deparsed as [" + from + "," + to + "]");
1143 r = new Integer(cl).intValue();
1145 } catch (NumberFormatException ex)
1147 if (cl.toLowerCase().equals("sequence"))
1149 // we are in the dataset sequence's coordinate frame.
1155 "ERROR: Couldn't parse integer from point selection element of column selection string '"
1160 if (r >= 0 && r <= alw)
1170 // comment to prevent range extension
1183 System.err.println("Point selection '" + cl
1184 + "' deparsed as [" + r + "]");
1189 System.err.println("ERROR: Invalid Point selection '" + cl
1190 + "' deparsed as [" + r + "]");
1197 // we only propagate the selection when it was the null selection, or the
1198 // given sequences were found in the alignment.
1199 if (inseqpos && sel.getSize() > 0)
1201 // assume first sequence provides reference frame ?
1202 SequenceI rs = sel.getSequenceAt(0);
1203 start = rs.findIndex(start);
1204 end = rs.findIndex(end);
1205 List<Integer> cs = new ArrayList<>(csel.getSelected());
1207 for (Integer selectedCol : cs)
1209 csel.addElement(rs.findIndex(selectedCol));
1212 sel.setStartRes(start);
1214 EventQueue.invokeLater(new Runnable()
1219 ((AlignFrame) alf).select(sel, csel, ((AlignFrame) alf)
1220 .getCurrentView().getAlignment().getHiddenColumns());
1226 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1228 AlignmentI alorder = ((AlignFrame) alf).getViewport().getAlignment();
1229 String[] order = new String[alorder.getHeight()];
1230 for (int i = 0; i < order.length; i++)
1232 order[i] = alorder.getSequenceAt(i).getName();
1234 return arrayToSeparatorList(order, sep);
1237 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1238 String format, String suffix)
1242 AlignViewport vp = ((AlignFrame) alf).getViewport();
1243 FileFormatI theFormat = FileFormats.getInstance().forName(format);
1244 boolean seqlimits = (suffix == null
1245 || suffix.equalsIgnoreCase("true"));
1246 if (vp.getSelectionGroup() != null)
1248 // JBPNote: getSelectionAsNewSequence behaviour has changed - this
1249 // method now returns a full copy of sequence data
1250 // TODO consider using getSequenceSelection instead here
1251 String reply = new AppletFormatAdapter().formatSequences(theFormat,
1252 new Alignment(vp.getSelectionAsNewSequence()),
1256 } catch (IllegalArgumentException ex)
1258 ex.printStackTrace();
1259 return "Error retrieving alignment, possibly invalid format specifier: "
1265 public String orderAlignmentBy(AlignFrameI alf, String order,
1266 String undoName, String sep)
1268 if (sep == null || sep.length() == 0)
1272 String[] ids = JalviewAppLoader.separatorListToArray(order, sep);
1273 SequenceI[] sqs = null;
1274 if (ids != null && ids.length > 0)
1276 jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
1277 ((AlignFrame) alf).getViewport().getAlignment()
1278 .getSequencesArray());
1280 sqs = new SequenceI[ids.length];
1281 for (int i = 0; i < ids.length; i++)
1283 if (ids[i].trim().length() == 0)
1287 SequenceI sq = matcher.findIdMatch(ids[i]);
1295 SequenceI[] sqq = new SequenceI[s];
1296 System.arraycopy(sqs, 0, sqq, 0, s);
1309 final AlignmentOrder aorder = new AlignmentOrder(sqs);
1311 if (undoName != null && undoName.trim().length() == 0)
1315 final String _undoName = undoName;
1316 // TODO: deal with synchronization here: cannot raise any events until after
1317 // this has returned.
1318 return ((AlignFrame) alf).sortBy(aorder, _undoName) ? "true" : "";
1321 public String getAlignmentFrom(AlignFrameI alf, String format,
1326 boolean seqlimits = (suffix == null
1327 || suffix.equalsIgnoreCase("true"));
1329 FileFormatI theFormat = FileFormats.getInstance().forName(format);
1330 String reply = new AppletFormatAdapter().formatSequences(theFormat,
1331 ((AlignFrame) alf).getViewport().getAlignment(), seqlimits);
1333 } catch (IllegalArgumentException ex)
1335 ex.printStackTrace();
1336 return "Error retrieving alignment, possibly invalid format specifier: "
1341 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1343 if (new AnnotationFile().annotateAlignmentView(
1344 ((AlignFrame) alf).getViewport(), annotation,
1345 DataSourceType.PASTE))
1347 ((AlignFrame) alf).alignPanel.fontChanged();
1348 ((AlignFrame) alf).alignPanel.setScrollValues(0, 0);
1352 ((AlignFrame) alf).parseFeaturesFile(annotation,
1353 DataSourceType.PASTE);
1357 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1358 boolean autoenabledisplay)
1360 boolean ret = ((AlignFrame) alf).parseFeaturesFile(features,
1361 DataSourceType.PASTE);
1366 if (autoenabledisplay)
1368 ((AlignFrame) alf).getViewport().setShowSequenceFeatures(true);
1369 // this next was for a checkbox in JalviewLite
1370 // ((AlignFrame) alf).getViewport().sequenceFeatures.setState(true);
1375 public String getFeaturesFrom(AlignFrameI alf, String format)
1377 AlignFrame f = ((AlignFrame) alf);
1380 FeaturesFile formatter = new FeaturesFile();
1381 if (format.equalsIgnoreCase("Jalview"))
1383 features = formatter.printJalviewFormat(
1384 f.getViewport().getAlignment().getSequencesArray(),
1385 f.alignPanel.getFeatureRenderer(), true);
1389 features = formatter.printGffFormat(
1390 f.getViewport().getAlignment().getSequencesArray(),
1391 f.alignPanel.getFeatureRenderer(), true);
1394 if (features == null)
1402 public String getAnnotationFrom(AlignFrameI alf)
1404 AlignFrame f = (AlignFrame) alf;
1405 String annotation = new AnnotationFile()
1406 .printAnnotationsForView(f.getViewport());
1410 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1412 return (AlignFrameI) ((AlignFrame) alf).newView(name, true);
1415 public String[] separatorListToArray(String list)
1417 return separatorListToArray(list, separator);
1420 public Object[] getSelectionForListener(AlignFrameI currentFrame,
1421 SequenceGroup seqsel, ColumnSelection colsel,
1422 HiddenColumns hidden, SelectionSource source, Object alignFrame)
1424 // System.err.println("Testing selection event relay to
1425 // jsfunction:"+_listener);
1427 AlignFrame src = (AlignFrame) alignFrame;
1430 if (source instanceof AlignViewport
1431 && ((AlignFrame) currentFrame).getViewport() == source)
1433 // should be valid if it just generated an event!
1434 src = (AlignFrame) currentFrame;
1438 String[] seqs = new String[] {};
1439 String[] cols = new String[] {};
1440 int strt = 0, end = (src == null) ? -1
1441 : src.alignPanel.av.getAlignment().getWidth();
1442 if (seqsel != null && seqsel.getSize() > 0)
1444 seqs = new String[seqsel.getSize()];
1445 for (int i = 0; i < seqs.length; i++)
1447 seqs[i] = seqsel.getSequenceAt(i).getName();
1449 if (strt < seqsel.getStartRes())
1451 strt = seqsel.getStartRes();
1453 if (end == -1 || end > seqsel.getEndRes())
1455 end = seqsel.getEndRes();
1458 if (colsel != null && !colsel.isEmpty())
1462 end = colsel.getMax() + 1;
1464 cols = new String[colsel.getSelected().size()];
1465 for (int i = 0; i < cols.length; i++)
1467 cols[i] = "" + (1 + colsel.getSelected().get(i).intValue());
1472 if (seqsel != null && seqsel.getSize() > 0)
1474 // send a valid range, otherwise we send the empty selection
1475 cols = new String[2];
1476 cols[0] = "" + (1 + strt) + "-" + (1 + end);
1479 return new Object[] { src, setid, arrayToSeparatorList(seqs),
1480 arrayToSeparatorList(cols) };