4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.Collections;
7 import java.util.HashMap;
8 import java.util.Iterator;
10 import java.util.Locale;
13 import jalview.analysis.AlignmentUtils;
14 import jalview.bin.ArgParser.Arg;
15 import jalview.bin.ArgParser.ArgValues;
16 import jalview.datamodel.AlignmentAnnotation;
17 import jalview.gui.AlignFrame;
18 import jalview.gui.Desktop;
19 import jalview.io.AppletFormatAdapter;
20 import jalview.io.DataSourceType;
21 import jalview.io.FileFormatException;
22 import jalview.io.FileFormatI;
23 import jalview.io.FileLoader;
24 import jalview.io.IdentifyFile;
25 import jalview.util.HttpUtils;
26 import jalview.util.MessageManager;
27 import jalview.util.Platform;
28 import jalview.ws.dbsources.EBIAlfaFold;
34 private static boolean headless;
36 private static ArgParser argParser;
38 private Map<String, AlignFrame> afMap;
40 public static void processArgs(ArgParser ap, boolean h)
44 for (String id : argParser.linkedIds())
46 Commands cmds = new Commands();
49 cmds.processUnlinked(id);
53 cmds.processLinked(id);
60 this(Desktop.instance);
63 public Commands(Desktop d)
66 afMap = new HashMap<String, AlignFrame>();
69 protected void processUnlinked(String id)
74 protected void processLinked(String id)
76 Map<Arg, ArgValues> m = argParser.linkedArgs(id);
79 // script to execute after all loading is completed one way or another
80 String groovyscript = m.get(Arg.GROOVY) == null ? null
81 : m.get(Arg.GROOVY).getValue();
82 String file = m.get(Arg.OPEN) == null ? null
83 : m.get(Arg.OPEN).getValue();
85 FileFormatI format = null;
86 DataSourceType protocol = null;
89 if (m.get(Arg.OPEN) != null)
95 OPEN: for (String openFile : m.get(Arg.OPEN).getValues())
105 desktop.setProgressBar(
106 MessageManager.getString(
107 "status.processing_commandline_args"),
108 progress = System.currentTimeMillis());
112 if (!Platform.isJS())
114 * ignore in JavaScript -- can't just file existence - could load it?
119 if (!HttpUtils.startsWithHttpOrHttps(openFile))
121 if (!(new File(openFile)).exists())
123 Console.warn("Can't find file '" + openFile + "'");
129 DataSourceType protocol = AppletFormatAdapter
130 .checkProtocol(openFile);
132 FileFormatI format = null;
135 format = new IdentifyFile().identify(openFile, protocol);
136 } catch (FileFormatException e1)
138 Console.error("Unknown file format for '" + openFile + "'");
144 // get kind of temperature factor annotation
145 AlignmentAnnotation.TFType tempfacType = null;
146 if ((m.get(Arg.NOTEMPFAC) == null
147 || !m.get(Arg.NOTEMPFAC).getBoolean())
148 && m.get(Arg.TEMPFAC) != null)
152 tempfacType = AlignmentAnnotation.TFType
153 .valueOf(m.get(Arg.TEMPFAC).getValue()
154 .toUpperCase(Locale.ROOT));
155 Console.debug("Obtained Temperature Factor type of '"
156 + tempfacType + "'");
157 } catch (IllegalArgumentException e)
159 StringBuilder sb = new StringBuilder().append("Cannot set --")
160 .append(Arg.TEMPFAC.getName()).append(" to '")
162 .append("', ignoring. Valid values are: ");
163 Iterator<AlignmentAnnotation.TFType> it = Arrays
164 .stream(AlignmentAnnotation.TFType.values())
168 sb.append(it.next().toString().toLowerCase(Locale.ROOT));
172 Console.warn(sb.toString());
177 "Opening '" + openFile + "' in new alignment frame");
178 FileLoader fileLoader = new FileLoader(!headless);
179 af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, format,
183 if (m.get(Arg.WRAP) != null && m.get(Arg.WRAP).getBoolean())
185 af.getCurrentView().setWrapAlignment(true);
188 // change alignment frame title
189 if (m.get(Arg.TITLE) != null)
190 af.setTitle(m.get(Arg.TITLE).getValue());
192 // show secondary structure annotations?
193 if (m.get(Arg.SSANNOTATION) != null
194 && !m.get(Arg.SSANNOTATION).getBoolean())
196 // do this better (annotation types?)
197 AlignmentUtils.showOrHideSequenceAnnotations(
198 af.getCurrentView().getAlignment(),
199 Collections.singleton("Secondary Structure"), null,
203 // show temperature factor annotations?
204 if (m.get(Arg.NOTEMPFAC) != null
205 && m.get(Arg.NOTEMPFAC).getBoolean())
207 // do this better (annotation types?)
208 List<String> hideThese = new ArrayList<>();
209 hideThese.add("Temperature Factor");
210 hideThese.add(MessageManager
211 .getString("label.alphafold_reliability"));
212 AlignmentUtils.showOrHideSequenceAnnotations(
213 af.getCurrentView().getAlignment(), hideThese, null,
218 if (m.get(Arg.TEMPFAC_LABEL) != null)
220 AlignmentAnnotation aa = AlignmentUtils
221 .getFirstSequenceAnnotationOfType(
222 af.getCurrentView().getAlignment(),
223 AlignmentAnnotation.LINE_GRAPH);
224 Console.debug("***** Trying to change label from '"
225 + (aa == null ? aa : aa.label) + "' to '"
226 + m.get(Arg.TEMPFAC_LABEL).getValue() + "'");
229 aa.label = m.get(Arg.TEMPFAC_LABEL).getValue();
237 if (m.get(Arg.PAEMATRIX) != null)
239 File paeFile = new File(m.get(Arg.PAEMATRIX).getValue());
240 EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
244 // store the AlignFrame for this id
250 "Opening '" + openFile + "' in existing alignment frame");
251 af.getCurrentView().addFile(new File(openFile), format);
255 .println("Command " + Arg.OPEN + " executed successfully!");
258 if (first) // first=true means nothing opened
262 Console.error("Could not open any files in headless mode");
268 Console.warn("No more files to open");
270 desktop.setProgressBar(null, progress);