+ /**
+ * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
+ * else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadPdbFiles(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ /*
+ * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
+ * related to JAL-434
+ */
+
+ applet.setAlignPdbStructures(
+ getDefaultParameter("alignpdbfiles", false));
+ /*
+ * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
+ * PDB|1GAQ|1GAQ|C">
+ *
+ * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
+ *
+ * <param name="PDBfile3" value="1q0o Q45135_9MICO">
+ */
+
+ int pdbFileCount = 0;
+ // Accumulate pdbs here if they are heading for the same view (if
+ // alignPdbStructures is true)
+ Vector pdbs = new Vector();
+ // create a lazy matcher if we're asked to
+ jalview.analysis.SequenceIdMatcher matcher = (applet
+ .getDefaultParameter("relaxedidmatch", false))
+ ? new jalview.analysis.SequenceIdMatcher(
+ alignFrame.getAlignViewport().getAlignment()
+ .getSequencesArray())
+ : null;
+
+ String param;
+ do
+ {
+ if (pdbFileCount > 0)
+ {
+ param = applet.getParameter("PDBFILE" + pdbFileCount);
+ }
+ else
+ {
+ param = applet.getParameter("PDBFILE");
+ }
+
+ if (param != null)
+ {
+ PDBEntry pdb = new PDBEntry();
+
+ String seqstring;
+ SequenceI[] seqs = null;
+ String[] chains = null;
+
+ StringTokenizer st = new StringTokenizer(param, " ");
+
+ if (st.countTokens() < 2)
+ {
+ String sequence = applet.getParameter("PDBSEQ");
+ if (sequence != null)
+ {
+ seqs = new SequenceI[] { matcher == null
+ ? (Sequence) alignFrame.getAlignViewport()
+ .getAlignment().findName(sequence)
+ : matcher.findIdMatch(sequence) };
+ }
+
+ }
+ else
+ {
+ param = st.nextToken();
+ List<SequenceI> tmp = new ArrayList<>();
+ List<String> tmp2 = new ArrayList<>();
+
+ while (st.hasMoreTokens())
+ {
+ seqstring = st.nextToken();
+ StringTokenizer st2 = new StringTokenizer(seqstring, "=");
+ if (st2.countTokens() > 1)
+ {
+ // This is the chain
+ tmp2.add(st2.nextToken());
+ seqstring = st2.nextToken();
+ }
+ tmp.add(matcher == null
+ ? (Sequence) alignFrame.getAlignViewport()
+ .getAlignment().findName(seqstring)
+ : matcher.findIdMatch(seqstring));
+ }
+
+ seqs = tmp.toArray(new SequenceI[tmp.size()]);
+ if (tmp2.size() == tmp.size())
+ {
+ chains = tmp2.toArray(new String[tmp2.size()]);
+ }
+ }
+ param = resolveFileProtocol(param);
+ // TODO check JAL-357 for files in a jar (CLASSLOADER)
+ pdb.setFile(param);
+
+ if (seqs != null)
+ {
+ for (int i = 0; i < seqs.length; i++)
+ {
+ if (seqs[i] != null)
+ {
+ ((Sequence) seqs[i]).addPDBId(pdb);
+ StructureSelectionManager
+ .getStructureSelectionManager(applet)
+ .registerPDBEntry(pdb);
+ }
+ else
+ {
+ if (JalviewLite.debug)
+ {
+ // this may not really be a problem but we give a warning
+ // anyway
+ System.err.println(
+ "Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
+ + i + ")");
+ }
+ }
+ }
+
+ if (!alignPdbStructures)
+ {
+ alignFrame.newStructureView(applet, pdb, seqs, chains,
+ protocol);
+ }
+ else
+ {
+ pdbs.addElement(new Object[] { pdb, seqs, chains, protocol });
+ }
+ }
+ }
+
+ pdbFileCount++;
+ } while (param != null || pdbFileCount < 10);
+ if (pdbs.size() > 0)
+ {
+ SequenceI[][] seqs = new SequenceI[pdbs.size()][];
+ PDBEntry[] pdb = new PDBEntry[pdbs.size()];
+ String[][] chains = new String[pdbs.size()][];
+ String[] protocols = new String[pdbs.size()];
+ for (int pdbsi = 0, pdbsiSize = pdbs
+ .size(); pdbsi < pdbsiSize; pdbsi++)
+ {
+ Object[] o = (Object[]) pdbs.elementAt(pdbsi);
+ pdb[pdbsi] = (PDBEntry) o[0];
+ seqs[pdbsi] = (SequenceI[]) o[1];
+ chains[pdbsi] = (String[]) o[2];
+ protocols[pdbsi] = (String) o[3];
+ }
+ alignFrame.alignedStructureView(applet, pdb, seqs, chains,
+ protocols);
+ result = true;
+ }
+ return result;
+ }
+
+ /**
+ * Load in a Jnetfile if specified by parameter. Returns true if loaded,
+ * else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadJnetFile(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String param = applet.getParameter("jnetfile");
+ if (param == null)
+ {
+ // jnet became jpred around 2016
+ param = applet.getParameter("jpredfile");
+ }
+ if (param != null)
+ {
+ try
+ {
+ param = resolveFileProtocol(param);
+ JPredFile predictions = new JPredFile(param, protocol);
+ JnetAnnotationMaker.add_annotation(predictions,
+ alignFrame.viewport.getAlignment(), 0, false);
+ // false == do not add sequence profile from concise output
+
+ alignFrame.viewport.getAlignment().setupJPredAlignment();
+
+ alignFrame.alignPanel.fontChanged();
+ alignFrame.alignPanel.setScrollValues(0, 0);
+ result = true;
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Load annotations if specified by parameter. Returns true if loaded, else
+ * false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadAnnotations(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String param = applet.getParameter("annotations");
+ if (param != null)
+ {
+ param = resolveFileProtocol(param);
+
+ if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
+ param, protocol))
+ {
+ alignFrame.alignPanel.fontChanged();
+ alignFrame.alignPanel.setScrollValues(0, 0);
+ result = true;
+ }
+ else
+ {
+ System.err.println(
+ "Annotations were not added from annotation file '"
+ + param + "'");
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Load features file and view settings as specified by parameters. Returns
+ * true if features were loaded, else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadFeatures(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ // ///////////////////////////
+ // modify display of features
+ // we do this before any features have been loaded, ensuring any hidden
+ // groups are hidden when features first displayed
+ //
+ // hide specific groups
+ //
+ String param = applet.getParameter("hidefeaturegroups");
+ if (param != null)
+ {
+ alignFrame.setFeatureGroupState(separatorListToArray(param), false);
+ // applet.setFeatureGroupStateOn(newAlignFrame, param, false);
+ }
+ // show specific groups
+ param = applet.getParameter("showfeaturegroups");
+ if (param != null)
+ {
+ alignFrame.setFeatureGroupState(separatorListToArray(param), true);
+ // applet.setFeatureGroupStateOn(newAlignFrame, param, true);
+ }
+ // and now load features
+ param = applet.getParameter("features");
+ if (param != null)
+ {
+ param = resolveFileProtocol(param);
+
+ result = alignFrame.parseFeaturesFile(param, protocol);
+ }
+
+ param = applet.getParameter("showFeatureSettings");
+ if (param != null && param.equalsIgnoreCase(TRUE))
+ {
+ alignFrame.viewport.setShowSequenceFeatures(true);
+ new FeatureSettings(alignFrame.alignPanel);
+ }
+ return result;
+ }
+
+ /**
+ * Load a score file if specified by parameter. Returns true if file was
+ * loaded, else false.
+ *
+ * @param alignFrame
+ */
+ protected boolean loadScoreFile(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String sScoreFile = applet.getParameter("scoreFile");
+ if (sScoreFile != null && !"".equals(sScoreFile))
+ {
+ try
+ {
+ if (debug)
+ {
+ System.err.println(
+ "Attempting to load T-COFFEE score file from the scoreFile parameter");
+ }
+ result = alignFrame.loadScoreFile(sScoreFile);
+ if (!result)
+ {
+ System.err.println(
+ "Failed to parse T-COFFEE parameter as a valid score file ('"
+ + sScoreFile + "')");
+ }
+ } catch (Exception e)
+ {
+ System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
+ sScoreFile, e.getMessage());
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Load a tree for the alignment if specified by parameter. Returns true if
+ * a tree was loaded, else false.
+ *
+ * @param alignFrame
+ * @return
+ */
+ protected boolean loadTree(AlignFrame alignFrame)
+ {
+ boolean result = false;
+ String treeFile = applet.getParameter("tree");
+ if (treeFile == null)
+ {
+ treeFile = applet.getParameter("treeFile");
+ }
+
+ if (treeFile != null)
+ {
+ try
+ {
+ treeFile = resolveFileProtocol(treeFile);
+ NewickFile fin = new NewickFile(treeFile, protocol);
+ fin.parse();
+
+ if (fin.getTree() != null)
+ {
+ alignFrame.loadTree(fin, treeFile);
+ result = true;
+ dbgMsg("Successfully imported tree.");
+ }
+ else
+ {
+ dbgMsg("Tree parameter did not resolve to a valid tree.");
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Discovers whether the given file is in the Applet Archive
+ *
+ * @param f
+ * String
+ * @return boolean
+ */
+ boolean inArchive(String f)
+ {
+ // This might throw a security exception in certain browsers
+ // Netscape Communicator for instance.
+ try
+ {
+ boolean rtn = (getClass().getResourceAsStream("/" + f) != null);
+ if (debug)
+ {
+ System.err.println("Resource '" + f + "' was "
+ + (rtn ? "" : "not ") + "located by classloader.");
+ }
+ return rtn;
+ } catch (Exception ex)
+ {
+ System.out.println("Exception checking resources: " + f + " " + ex);
+ return false;
+ }
+ }