4 import java.util.Collections;
5 import java.util.HashMap;
8 import jalview.analysis.AlignmentUtils;
9 import jalview.bin.ArgParser.Arg;
10 import jalview.bin.ArgParser.ArgValues;
11 import jalview.gui.AlignFrame;
12 import jalview.gui.Desktop;
13 import jalview.io.AppletFormatAdapter;
14 import jalview.io.DataSourceType;
15 import jalview.io.FileFormatException;
16 import jalview.io.FileFormatI;
17 import jalview.io.FileLoader;
18 import jalview.io.IdentifyFile;
19 import jalview.util.HttpUtils;
20 import jalview.util.MessageManager;
21 import jalview.util.Platform;
27 private static boolean headless;
29 private static ArgParser argParser;
31 private Map<String, AlignFrame> afMap;
33 public static void processArgs(ArgParser ap, boolean h)
37 for (String id : argParser.linkedIds())
39 Commands cmds = new Commands();
42 cmds.processUnlinked(id);
46 cmds.processLinked(id);
53 this(Desktop.instance);
56 public Commands(Desktop d)
59 afMap = new HashMap<String, AlignFrame>();
62 protected void processUnlinked(String id)
67 protected void processLinked(String id)
69 Map<Arg, ArgValues> m = argParser.linkedArgs(id);
70 FileLoader fileLoader = new FileLoader(!headless);
73 // script to execute after all loading is completed one way or another
74 String groovyscript = m.get(Arg.GROOVY) == null ? null
75 : m.get(Arg.GROOVY).getValue();
76 String file = m.get(Arg.OPEN) == null ? null
77 : m.get(Arg.OPEN).getValue();
79 FileFormatI format = null;
80 DataSourceType protocol = null;
83 if (m.get(Arg.OPEN) != null)
89 OPEN: for (String openFile : m.get(Arg.OPEN).getValues())
93 Console.debug("********** id = " + id + ", openFile = " + openFile);
100 desktop.setProgressBar(
101 MessageManager.getString(
102 "status.processing_commandline_args"),
103 progress = System.currentTimeMillis());
107 if (!Platform.isJS())
109 * ignore in JavaScript -- can't just file existence - could load it?
114 if (!HttpUtils.startsWithHttpOrHttps(openFile))
116 if (!(new File(openFile)).exists())
118 Console.warn("Can't find file '" + openFile + "'");
124 DataSourceType protocol = AppletFormatAdapter
125 .checkProtocol(openFile);
127 FileFormatI format = null;
130 format = new IdentifyFile().identify(openFile, protocol);
131 } catch (FileFormatException e1)
133 Console.error("Unknown file format for '" + openFile + "'");
140 "Opening '" + openFile + "' in new alignment frame");
141 af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
143 if (m.get(Arg.TITLE) != null)
144 af.setTitle(m.get(Arg.TITLE).getValue());
145 if (m.get(Arg.SSANNOTATION) != null
146 && !m.get(Arg.SSANNOTATION).getBoolean())
148 // do this better (annotation types?)
149 AlignmentUtils.showOrHideSequenceAnnotations(
150 af.getCurrentView().getAlignment(),
151 Collections.singleton("Secondary Structure"), null,
154 if (m.get(Arg.NOTEMPFAC) != null
155 && m.get(Arg.NOTEMPFAC).getBoolean())
157 // do this better (annotation types?)
158 AlignmentUtils.showOrHideSequenceAnnotations(
159 af.getCurrentView().getAlignment(),
160 Collections.singleton("Temperature Factor"), null,
162 AlignmentUtils.showOrHideSequenceAnnotations(
163 af.getCurrentView().getAlignment(),
164 Collections.singleton("Alphafold Reliability"), null,
168 // store the AlignFrame for this id
174 "Opening '" + openFile + "' in existing alignment frame");
175 af.getCurrentView().addFile(new File(openFile), format);
179 .println("Command " + Arg.OPEN + " executed successfully!");
182 if (first) // first=true means nothing opened
186 Console.error("Could not open any files in headless mode");
192 Console.warn("No more files to open");
194 desktop.setProgressBar(null, progress);