From d6ad9619070895df810de190dd202b1698632438 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 26 May 2008 09:55:37 +0000 Subject: [PATCH] minor bugfix for case when PDB sequence strings are not parsed and added new javascript API methods for getting selected sequences (https://mantis.lifesci.dundee.ac.uk/view.php?id=32977) --- src/jalview/bin/JalviewLite.java | 84 +++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 4945ec0..c7cc4f3 100755 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -44,16 +44,42 @@ public class JalviewLite //The following public methods maybe called //externally, eg via javascript in HTML page /** - * @return list of selected sequences separated by "¬" + * @return String list of selected sequence IDs, each terminated by "¬" (¬) */ public String getSelectedSequences() { return getSelectedSequencesFrom(getDefaultTargetFrame()); } + /** + * @param sep separator string or null for default + * @return String list of selected sequence IDs, each terminated by sep or ("¬" as default) + */ + public String getSelectedSequences(String sep) + { + return getSelectedSequencesFrom(getDefaultTargetFrame(), sep); + } + /** + * @param alf alignframe containing selection + * @return String list of selected sequence IDs, each terminated by "¬" + * + */ public String getSelectedSequencesFrom(AlignFrame alf) { + return getSelectedSequencesFrom(alf, "¬"); + } + /** + * get list of selected sequence IDs separated by given separator + * @param alf window containing selection + * @param sep separator string to use - default is "¬" + * @return String list of selected sequence IDs, each terminated by the given separator + */ + public String getSelectedSequencesFrom(AlignFrame alf, String sep) + { StringBuffer result = new StringBuffer(""); - + if (sep==null || sep.length()==0) + { + sep = "¬"; + } if (alf.viewport.getSelectionGroup() != null) { SequenceI[] seqs = alf.viewport.getSelectionGroup(). @@ -62,13 +88,52 @@ public class JalviewLite for (int i = 0; i < seqs.length; i++) { - result.append(seqs[i].getName() + "¬"); + result.append(seqs[i].getName()); + result.append(sep); } } return result.toString(); } - + + /** + * get sequences selected in current alignFrame and return their alignment in format 'format' either with or without suffix + * @param alf - where selection is + * @param format - format of alignment file + * @param suffix - "true" to append /start-end string to each sequence ID + * @return selected sequences as flat file or empty string if there was no current selection + */ + public String getSelectedSequencesAsAlignment(String format, String suffix) { + return getSelectedSequencesAsAlignmentFrom(currentAlignFrame, format, suffix); + } + + /** + * get sequences selected in alf and return their alignment in format 'format' either with or without suffix + * @param alf - where selection is + * @param format - format of alignment file + * @param suffix - "true" to append /start-end string to each sequence ID + * @return selected sequences as flat file or empty string if there was no current selection + */ + public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf, String format, String suffix) + { + try + { + boolean seqlimits = suffix.equalsIgnoreCase("true"); + if (alf.viewport.getSelectionGroup()!=null) + { + String reply = new AppletFormatAdapter().formatSequences(format, + new Alignment(alf.viewport.getSelectionAsNewSequence()), seqlimits); + return reply; + } + } + catch (Exception ex) + { + ex.printStackTrace(); + return "Error retrieving alignment in " + format + " format. "; + } + return ""; + } + public String getAlignment(String format) { return getAlignmentFrom(getDefaultTargetFrame(), format, "true"); @@ -703,7 +768,16 @@ public class JalviewLite { for (int i = 0; i < seqs.length; i++) { - ( (Sequence) seqs[i]).addPDBId(pdb); + if (seqs[i]!=null) + { + ( (Sequence) seqs[i]).addPDBId(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 (jmolAvailable) -- 1.7.10.2