Merge branch 'develop' into spike/JAL-1950_hmmer3client
authorJim Procter <jprocter@issues.jalview.org>
Mon, 5 Dec 2016 21:48:02 +0000 (21:48 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 5 Dec 2016 21:48:02 +0000 (21:48 +0000)
1  2 
src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/gui/AlignViewport.java
src/jalview/util/Comparison.java
src/jalview/util/HttpUtils.java
src/jalview/ws/rest/RestClient.java
test/jalview/ws/rest/ShmmrRSBSService.java

@@@ -922,7 -922,6 +922,7 @@@ public class AlignmentAnnotatio
     * @param seqRef
     * @param startRes
     * @param alreadyMapped
 +   *          - annotation are at aligned columns
     */
    public void createSequenceMapping(SequenceI seqRef, int startRes,
            boolean alreadyMapped)
     *       already
     */
    public void remap(SequenceI newref, HashMap<Integer, int[]> mapping,
-           int from, int to,
-           int idxoffset)
+           int from, int to, int idxoffset)
    {
      if (mapping != null)
      {
   * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
   * The Jalview Authors are detailed in the 'AUTHORS' file.
   */
- /*
-  * Jalview - A Sequence Alignment Editor and Viewer
-  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
-  *
-  * This program is free software; you can redistribute it and/or
-  * modify it under the terms of the GNU General Public License
-  * as published by the Free Software Foundation; either version 2
-  * of the License, or (at your option) any later version.
-  *
-  * This program is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  * GNU General Public License for more details.
-  *
-  * You should have received a copy of the GNU General Public License
-  * along with this program; if not, write to the Free Software
-  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-  */
  package jalview.gui;
  
  import jalview.analysis.AlignmentUtils;
@@@ -55,6 -37,7 +37,7 @@@ import jalview.datamodel.AlignmentI
  import jalview.datamodel.ColumnSelection;
  import jalview.datamodel.PDBEntry;
  import jalview.datamodel.SearchResults;
+ import jalview.datamodel.SearchResultsI;
  import jalview.datamodel.Sequence;
  import jalview.datamodel.SequenceGroup;
  import jalview.datamodel.SequenceI;
@@@ -276,11 -259,9 +259,11 @@@ public class AlignViewport extends Alig
  
      setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
  
 -    alignment
 -            .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
 -
 +    if (Cache.getDefault("NORMALISE_GAPS", true))
 +    {
 +      alignment.setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(
 +              0));
 +    }
      // We must set conservation and consensus before setting colour,
      // as Blosum and Clustal require this to be done
      if (hconsensus == null && !isDataset)
        List<SequenceI> choosenSeqs = new ArrayList<SequenceI>();
        for (SequenceI sq : alignment.getSequences())
        {
-         Vector<PDBEntry> pdbRefEntries = sq.getDatasetSequence().getAllPDBEntries();
+         Vector<PDBEntry> pdbRefEntries = sq.getDatasetSequence()
+                 .getAllPDBEntries();
          if (pdbRefEntries == null)
          {
            continue;
            }
          }
        }
-       seqvectors.add(choosenSeqs.toArray(new SequenceI[choosenSeqs.size()]));
+       seqvectors
+               .add(choosenSeqs.toArray(new SequenceI[choosenSeqs.size()]));
      }
      return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
    }
          MessageManager.getString("label.new_window"), };
      final String question = JvSwingUtils.wrapTooltip(true,
              MessageManager.getString("label.open_split_window?"));
-     int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
+     int response = JvOptionPane.showOptionDialog(Desktop.desktop, question,
              MessageManager.getString("label.open_split_window"),
-             JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
+             JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
              options, options[0]);
  
      if (response != 1 && response != 2)
  
      // TODO if we want this (e.g. to enable reload of the alignment from file),
      // we will need to add parameters to the stack.
-     // if (!protocol.equals(AppletFormatAdapter.PASTE))
+     // if (!protocol.equals(DataSourceType.PASTE))
      // {
      // alignFrame.setFileName(file, format);
      // }
       * there is no complement, or it is not following highlights, or no mapping
       * is found, the result will be empty.
       */
-     SearchResults sr = new SearchResults();
+     SearchResultsI sr = new SearchResults();
      int verticalOffset = findComplementScrollTarget(sr);
      if (!sr.isEmpty())
      {
@@@ -245,7 -245,7 +245,7 @@@ public class Compariso
     */
    public static final boolean isGap(char c)
    {
 -    return (c == GAP_DASH || c == GAP_DOT || c == GAP_SPACE) ? true : false;
 +    return (c == GAP_DASH || c == GAP_DOT || c == GAP_SPACE);
    }
  
    /**
              .size()]);
      return isNucleotide(oneDArray);
    }
+   /**
+    * Compares two residues either case sensitively or case insensitively
+    * depending on the caseSensitive flag
+    * 
+    * @param c1
+    *          first char
+    * @param c2
+    *          second char to compare with
+    * @param caseSensitive
+    *          if true comparison will be case sensitive otherwise its not
+    * @return
+    */
+   public static boolean isSameResidue(char c1, char c2,
+           boolean caseSensitive)
+   {
+     if (caseSensitive)
+     {
+       return (c1 == c2);
+     }
+     else
+     {
+       return Character.toUpperCase(c1) == Character.toUpperCase(c2);
+     }
+   }
  }
@@@ -1,4 -1,4 +1,4 @@@
- /*******************************************************************************
+ /*
   * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
   * Copyright (C) $$Year-Rel$$ The Jalview Authors
   * 
   * You should have received a copy of the GNU General Public License
   * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
   * The Jalview Authors are detailed in the 'AUTHORS' file.
-  ******************************************************************************/
+  */
  package jalview.util;
  
 +import java.io.BufferedInputStream;
 +import java.io.File;
 +import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.URL;
@@@ -67,46 -64,4 +67,46 @@@ public class HttpUtil
      return false;
    }
  
 +  /**
 +   * download from given URL and return a pointer to temporary file
 +   */
 +  public static File fetchURLToTemp(String url) throws OutOfMemoryError,
 +          IOException
 +  {
 +    long time = System.currentTimeMillis();
 +    URL rcall = new URL(url);
 +
 +    InputStream is = new BufferedInputStream(rcall.openStream());
 +    File outFile = null;
 +    try
 +    {
 +      outFile = File.createTempFile("jalview", ".xml");
 +      outFile.deleteOnExit();
 +      if (outFile.length() == 0)
 +      {
 +        outFile.delete();
 +        return null;
 +      }
 +    } catch (Exception ex)
 +    {
 +    }
 +
 +    if (outFile != null)
 +    {
 +      FileOutputStream fio = new FileOutputStream(outFile);
 +      byte[] bb = new byte[32 * 1024];
 +      int l;
 +      while ((l = is.read(bb)) > 0)
 +      {
 +        fio.write(bb, 0, l);
 +      }
 +      fio.close();
 +      is.close();
 +      return outFile;
 +    }
 +    else
 +    {
 +      return null;
 +    }
 +  }
  }
@@@ -26,20 -26,21 +26,20 @@@ import jalview.gui.AlignFrame
  import jalview.gui.AlignViewport;
  import jalview.gui.AlignmentPanel;
  import jalview.gui.Desktop;
+ import jalview.gui.JvOptionPane;
  import jalview.gui.WebserviceInfo;
 -import jalview.io.packed.DataProvider.JvDataType;
  import jalview.util.MessageManager;
  import jalview.ws.WSClient;
  import jalview.ws.WSClientI;
  import jalview.ws.WSMenuEntryProviderI;
 +import jalview.ws.rest.clientdefs.ShmrRestClient;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
 -import java.util.Hashtable;
  import java.util.Vector;
  
  import javax.swing.JMenu;
  import javax.swing.JMenuItem;
- import javax.swing.JOptionPane;
  import javax.swing.event.MenuEvent;
  import javax.swing.event.MenuListener;
  
@@@ -323,7 -324,7 +323,7 @@@ public class RestClient extends WSClien
      else
      {
        // TODO: try to tell the user why the job couldn't be started.
-       JOptionPane
+       JvOptionPane
                .showMessageDialog(
                        Desktop.desktop,
                        (jobsthread.hasWarnings() ? jobsthread.getWarnings()
                                        .getString("label.job_couldnt_be_started_check_input")),
                        MessageManager
                                .getString("label.unable_start_web_service_analysis"),
-                       JOptionPane.WARNING_MESSAGE);
+                       JvOptionPane.WARNING_MESSAGE);
      }
    }
  
 -  public static RestClient makeShmmrRestClient()
 -  {
 -    String action = "Analysis", description = "Sequence Harmony and Multi-Relief (Brandt et al. 2010)", name = MessageManager
 -            .getString("label.multiharmony");
 -    Hashtable<String, InputType> iparams = new Hashtable<String, InputType>();
 -    jalview.ws.rest.params.JobConstant toolp;
 -    // toolp = new jalview.ws.rest.JobConstant("tool","jalview");
 -    // iparams.put(toolp.token, toolp);
 -    // toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
 -    // iparams.put(toolp.token, toolp);
 -    // toolp = new
 -    // jalview.ws.rest.params.JobConstant("mbjob[description]","step 1");
 -    // iparams.put(toolp.token, toolp);
 -    // toolp = new jalview.ws.rest.params.JobConstant("start_search","1");
 -    // iparams.put(toolp.token, toolp);
 -    // toolp = new jalview.ws.rest.params.JobConstant("blast","0");
 -    // iparams.put(toolp.token, toolp);
 -
 -    jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment();
 -    // SHMR server has a 65K limit for content pasted into the 'ali' parameter,
 -    // so we always upload our files.
 -    aliinput.token = "ali_file";
 -    aliinput.writeAsFile = true;
 -    iparams.put(aliinput.token, aliinput);
 -    jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector();
 -    sgroups.setMinsize(2);
 -    sgroups.min = 2;// need at least two group defined to make a partition
 -    iparams.put("groups", sgroups);
 -    sgroups.token = "groups";
 -    sgroups.sep = " ";
 -    RestServiceDescription shmrService = new RestServiceDescription(
 -            action,
 -            description,
 -            name,
 -            "http://zeus.few.vu.nl/programs/shmrwww/index.php?tool=jalview",// ?tool=jalview&mbjob[method]=shmr&mbjob[description]=step1",
 -            "?tool=jalview", iparams, true, false, '-');
 -    // a priori knowledge of the data returned from the service
 -    shmrService.addResultDatatype(JvDataType.ANNOTATION);
 -    return new RestClient(shmrService);
 -  }
 -
    public AlignmentPanel recoverAlignPanelForView()
    {
      AlignmentPanel[] aps = Desktop
          for (RestServiceDescription descr : RestServiceDescription
                  .parseDescriptions(jalview.bin.Cache.getDefault(
                          RSBS_SERVICES,
 -                        makeShmmrRestClient().service.toString())))
 +                        ShmrRestClient.makeShmmrRestClient().service.toString())))
          {
            services.add(descr.toString());
          }
@@@ -24,10 -24,11 +24,12 @@@ import static org.testng.AssertJUnit.as
  import static org.testng.AssertJUnit.assertTrue;
  
  import jalview.gui.AlignFrame;
+ import jalview.gui.JvOptionPane;
 +import jalview.ws.rest.clientdefs.ShmrRestClient;
  
  import java.util.Map;
  
+ import org.testng.annotations.BeforeClass;
  import org.testng.annotations.Test;
  
  /**
  public class ShmmrRSBSService
  {
  
+   @BeforeClass(alwaysRun = true)
+   public void setUpJvOptionPane()
+   {
+     JvOptionPane.setInteractiveMode(false);
+     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+   }
    @Test(groups = { "Functional" })
    public void testShmmrService()
    {
      assertTrue(
              "Test Rsd Exchange using using default Shmmr service failed.",
              testRsdExchange("Test using default Shmmr service",
 -                    RestClient.makeShmmrRestClient().service));
 +                    ShmrRestClient.makeShmmrRestClient().service));
    }
  
    @Test(groups = { "Functional" })
    public void testShmmrServiceDataprep() throws Exception
    {
 -    RestClient _rc = RestClient.makeShmmrRestClient();
 +    RestClient _rc = ShmrRestClient.makeShmmrRestClient();
      assertNotNull(_rc);
      AlignFrame alf = new jalview.io.FileLoader(false)
              .LoadFileWaitTillLoaded("examples/testdata/smad.fa",
-                     jalview.io.FormatAdapter.FILE);
+                     jalview.io.DataSourceType.FILE);
      assertNotNull("Couldn't find test data.", alf);
      alf.loadJalviewDataFile("examples/testdata/smad_groups.jva",
-             jalview.io.FormatAdapter.FILE, null, null);
+             jalview.io.DataSourceType.FILE, null, null);
      assertTrue(
              "Couldn't load the test data's annotation file (should be 5 groups but found "
                      + alf.getViewport().getAlignment().getGroups().size()