3 import jalview.gui.AlignFrame;
4 import jalview.io.AppletFormatAdapter;
5 import jalview.io.DataSourceType;
6 import jalview.io.FileFormatException;
7 import jalview.io.FileFormatI;
8 import jalview.io.FileLoader;
9 import jalview.io.IdentifyFile;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Objects;
15 import javax.swing.JFrame;
16 import javax.swing.JInternalFrame;
19 * Entry point for Jalview as Javascript. Expects parameter names as for the
20 * JalviewLite applet, formatted as for the Jalview application, for example
23 * JalviewJS file /examples/uniref50.fa features /examples/exampleFeatures.txt \
24 * PDBFile "/examples/pdb1.txt seq1"
27 * Note that (unlike the applet) parameter names are case sensitive
29 // TODO or format as file=/examples/uniref50.fa (etc)?
30 public class JalviewJS
32 private static final String PARAM_FILE = "file";
34 private static final String PARAM_FILE2 = "file2";
36 private static final String PARAM_TREE = "tree";
38 private static final String PARAM_FEATURES = "features";
40 private static final String PARAM_ANNOTATIONS = "annotations";
42 private static final String PARAM_SHOW_ANNOTATION = "showAnnotation";
44 private static final String PARAM_PDBFILE = "PDBFile";
46 public static void main(String[] args)
50 new JalviewJS().doMain(args);
51 } catch (FileFormatException e)
57 private String paramFile;
59 private String paramFile2;
61 private String paramTree;
63 private String paramFeatures;
65 private String paramAnnotations;
67 private String paramShowAnnotation;
69 private List<String> paramPdbFile;
72 * Parses parameters and shows the frame and any loaded panels
74 * @throws FileFormatException
76 void doMain(String[] args) throws FileFormatException
79 if (paramFile == null)
90 * Prints a chastising, yet helpful, error message on syserr
94 System.err.println("Usage: JalviewJS file <alignmentFileName>");
95 System.err.println("See documentation for full parameter list");
99 * Parses any supplied parameters. Note that (unlike for the applet),
100 * parameter names are case sensitive.
104 * @see http://www.jalview.org/examples/index.html#appletParameters
106 void loadParameters(String[] args)
108 ArgsParser parser = new ArgsParser(args);
109 paramFile = parser.getValue(PARAM_FILE);
110 paramFile2 = parser.getValue(PARAM_FILE2);
111 paramTree = parser.getValue(PARAM_TREE);
112 paramFeatures = parser.getValue(PARAM_FEATURES);
113 paramAnnotations = parser.getValue(PARAM_ANNOTATIONS);
114 paramShowAnnotation = parser.getValue(PARAM_SHOW_ANNOTATION);
115 paramPdbFile = loadPdbParameters(parser);
119 * Reads parameter PDBFile, PDBFile1, PDFile2, ... and saves the value(s) (if
125 List<String> loadPdbParameters(ArgsParser parser)
127 List<String> values = new ArrayList<>();
128 String value = parser.getValue(PARAM_PDBFILE);
136 value = parser.getValue(PARAM_PDBFILE + String.valueOf(i));
150 * Constructs and displays a JFrame containing an alignment panel (and any
151 * additional panels depending on parameters supplied)
153 * @throws FileFormatException
155 void showFrame() throws FileFormatException
157 JFrame frame = new JFrame(this.paramFile);
158 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
160 JInternalFrame alignFrame = createAlignFrame();
161 frame.setContentPane(alignFrame.getContentPane());
164 frame.setSize(AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
165 frame.setVisible(true);
169 * Constructs and returns the frame containing the alignment and its
173 * @throws FileFormatException
175 JInternalFrame createAlignFrame() throws FileFormatException
177 Objects.requireNonNull(this.paramFile);
179 DataSourceType protocol = AppletFormatAdapter
180 .checkProtocol(this.paramFile);
181 FileFormatI format = new IdentifyFile().identify(this.paramFile,
183 FileLoader fileLoader = new FileLoader(false);
184 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(this.paramFile,