JAL-2629 fix files permission issue on Mac
authortzvanaalten <tzvanaalten@172.17.105.62>
Thu, 10 Aug 2017 10:01:22 +0000 (11:01 +0100)
committertzvanaalten <tzvanaalten@172.17.105.62>
Thu, 10 Aug 2017 10:01:22 +0000 (11:01 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/hmmer/HMMAlignThread.java
src/jalview/hmmer/HMMBuildThread.java
src/jalview/hmmer/HMMERCommands.java
src/jalview/io/HMMFile.java

index c0b7fed..d670eba 100644 (file)
@@ -4747,7 +4747,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             getViewport().updateInformation(alignPanel);
 
             isAnnotation = true;
-            getViewport().alignmentChanged(alignPanel);
 
           }
           else if (FileFormat.Jnet.equals(format))
index 79a8092..4513dfe 100644 (file)
@@ -35,6 +35,12 @@ public class HMMAlignThread implements Runnable
 
   Map<Integer, SequenceI> hmmSeqs;
 
+  File hmmTemp = null;
+
+  File outTemp = null;
+
+  File inputTemp = null;
+
   public HMMAlignThread(AlignFrame af, boolean createNewFrame)
   {
     this.af = af;
@@ -52,13 +58,12 @@ public class HMMAlignThread implements Runnable
     cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
     try
     {
-      cmds.HMMBUFFER = File.createTempFile("hmm", ".hmm").getAbsolutePath()
-              + cmds.SPACE;
-      cmds.ALIGNMENTBUFFER = File.createTempFile("output", ".sto")
-              .getAbsolutePath() + cmds.SPACE;
-      cmds.ALIGNMENTINPUT = File.createTempFile("input", ".sto")
-              .getAbsolutePath() + cmds.SPACE;
-      cmds.OUTPUTALIGNMENT = "-o " + cmds.ALIGNMENTINPUT + cmds.SPACE;
+      hmmTemp = File.createTempFile("hmm", ".hmm");
+      hmmTemp.deleteOnExit();
+      outTemp = File.createTempFile("output", ".sto");
+      outTemp.deleteOnExit();
+      inputTemp = File.createTempFile("input", ".sto");
+      inputTemp.deleteOnExit();
     } catch (IOException e1)
     {
       // TODO Auto-generated catch block
@@ -70,7 +75,8 @@ public class HMMAlignThread implements Runnable
       try
       {
         hmmSeqs = alignment.getHMMConsensusSequences(true);
-        cmds.exportData(alignment, true, true, hmm);
+        cmds.exportData(alignment, outTemp.getAbsoluteFile(), hmm,
+                hmmTemp.getAbsoluteFile());
       } catch (FileNotFoundException e)
       {
         // TODO Auto-generated catch block
@@ -110,8 +116,9 @@ public class HMMAlignThread implements Runnable
     {
       command += cmds.ALLCOL;
     }
-    command += cmds.TRIM + cmds.OUTPUTALIGNMENT + cmds.HMMBUFFER
-            + cmds.ALIGNMENTBUFFER;
+    command += cmds.TRIM + " -o" + inputTemp.getAbsolutePath() + cmds.SPACE
+            + hmmTemp.getAbsolutePath() + cmds.SPACE
+            + outTemp.getAbsolutePath();
     cmds.runCommand(command);
   }
 
@@ -128,7 +135,7 @@ public class HMMAlignThread implements Runnable
               af.getName() + "Aligned to " + hmm.getName() + "'s HMM");
       af.getViewport().setAlignment(null);
 
-      aFrame.loadJalviewDataFile(cmds.ALIGNMENTINPUT,
+      aFrame.loadJalviewDataFile(inputTemp.getAbsolutePath(),
               DataSourceType.FILE, FileFormat.Stockholm, null);
 
 
@@ -145,11 +152,14 @@ public class HMMAlignThread implements Runnable
     {
       af.getViewport().getAlignment().getSequences().clear();
       af.setIsRecurring(true);
-      af.loadJalviewDataFile(cmds.ALIGNMENTBUFFER,
+      af.loadJalviewDataFile(inputTemp.getAbsolutePath(),
               DataSourceType.FILE, FileFormat.Stockholm, null);
       af.setIsRecurring(false);
       addSeqs(af, hmmSeqs);
     }
+    hmmTemp.delete();
+    outTemp.delete();
+    inputTemp.delete();
   }
 
   private void addSeqs(AlignFrame alignFrame, Map<Integer, SequenceI> map)
index cf89863..2876893 100644 (file)
@@ -2,7 +2,6 @@ package jalview.hmmer;
 
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.HiddenMarkovModel;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Preferences;
@@ -21,6 +20,10 @@ public class HMMBuildThread implements Runnable
   AlignFrame af;
   AlignmentI alignment;
 
+  File hmmTemp = null;
+
+  File stoTemp = null;
+
   long barID;
 
   Map<Integer, SequenceI> hmmSeqs;
@@ -35,15 +38,16 @@ public class HMMBuildThread implements Runnable
   public void run()
   {
     barID = System.currentTimeMillis();
+    System.out.println(System.getProperty("java.io.tmpdir"));
     af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
             barID);
     cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
     try
     {
-      cmds.HMMBUFFER = File.createTempFile("hmm", ".hmm").getAbsolutePath()
-              + cmds.SPACE;
-      cmds.ALIGNMENTBUFFER = File.createTempFile("output", ".sto")
-              .getAbsolutePath() + cmds.SPACE;
+      hmmTemp = File.createTempFile("hmm", ".hmm");
+      hmmTemp.deleteOnExit();
+      stoTemp = File.createTempFile("output", ".sto");
+      stoTemp.deleteOnExit();
     } catch (IOException e1)
     {
       e1.printStackTrace();
@@ -54,8 +58,7 @@ public class HMMBuildThread implements Runnable
     try
     {
         hmmSeqs = alignment.getHMMConsensusSequences(true);
-        cmds.exportData(alignment, true, false,
-                new HiddenMarkovModel());
+        cmds.exportData(alignment, stoTemp, null, null);
     } catch (FileNotFoundException e)
     {
       // TODO Auto-generated catch block
@@ -72,6 +75,7 @@ public class HMMBuildThread implements Runnable
     }
     try
     {
+
       importData();
     } catch (IOException | InterruptedException e)
     {
@@ -94,14 +98,14 @@ public class HMMBuildThread implements Runnable
   private void runCommand() throws IOException, InterruptedException
   {
     final String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME
-            + af.getName() + cmds.SPACE + cmds.HMMBUFFER
-            + cmds.ALIGNMENTBUFFER;
+            + af.getName() + cmds.SPACE + hmmTemp.getAbsolutePath()
+            + cmds.SPACE + stoTemp.getAbsolutePath() + cmds.SPACE;
     cmds.runCommand(command);
   }
   
   private void importData() throws IOException, InterruptedException
   {
-    af.loadJalviewDataFile(cmds.HMMBUFFER, DataSourceType.FILE,
+    af.loadJalviewDataFile(hmmTemp.getAbsolutePath(), DataSourceType.FILE,
             FileFormat.HMMER3, null);
     for (Map.Entry<Integer, SequenceI> entry : hmmSeqs.entrySet())
     {
@@ -110,6 +114,8 @@ public class HMMBuildThread implements Runnable
       cmds.addHMMConsensusSequence(af, seq, pos);
     }
     af.alignPanel.alignmentChanged();
+    hmmTemp.delete();
+    stoTemp.delete();
   }
   
   
index 5e35ef0..8de3fe1 100644 (file)
@@ -9,6 +9,7 @@ import jalview.io.HMMFile;
 import jalview.io.StockholmFile;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -89,10 +90,10 @@ public class HMMERCommands
    * @throws IOException
    */
   public void exportData(AlignmentI alignment,
-          boolean exportAlignment, boolean exportHMM, HiddenMarkovModel hmm)
+          File stoLocation, HiddenMarkovModel hmm, File hmmLocation)
           throws IOException
   {
-    if (exportAlignment)
+    if (alignment != null)
     {
       if (!alignment.isAligned())
       {
@@ -104,15 +105,15 @@ public class HMMERCommands
       StockholmFile file = new StockholmFile(new Alignment(array));
       file.setSeqs(array);
       String output = file.print();
-      PrintWriter writer = new PrintWriter(ALIGNMENTBUFFER);
+      PrintWriter writer = new PrintWriter(stoLocation);
       writer.println(output);
       writer.close();
     }
 
-    if (exportHMM)
+    if (hmm != null)
     {
       HMMFile file = new HMMFile(hmm);
-      file.exportFile(HMMBUFFER);
+      file.exportFile(hmmLocation);
     }
   }
 
index 234c108..8870837 100644 (file)
@@ -5,6 +5,7 @@ import jalview.datamodel.HiddenMarkovModel;
 import jalview.datamodel.SequenceI;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -41,7 +42,7 @@ public class HMMFile extends AlignFile
 
   private final String EMPTY = "";
 
-  //This is a line that needs to be added to each HMMER£ file. It is purely for readability.
+  //This is a line that needs to be added to each HMMER� file. It is purely for readability.
   private static final String TRANSITIONTYPELINE = "m->m     m->i     m->d     i->m     i->i     d->m     d->d";
 
   /**
@@ -346,6 +347,27 @@ public class HMMFile extends AlignFile
   }
 
   /**
+   * Writes a HMM to a file/
+   * 
+   * @param exportLocation
+   *          Filename, URL or Pasted String to write to.
+   * @throws FileNotFoundException
+   * @throws UnsupportedEncodingException
+   *
+   **/
+
+  public void exportFile(File exportLocation) throws IOException
+  {
+    PrintWriter writer = new PrintWriter(exportLocation);
+    appendFileProperties(writer);
+    appendModel(writer);
+    writer.println("//");
+
+    writer.close();
+
+  }
+
+  /**
    * Returns a string to be added to the StringBuilder containing the entire
    * output String.
    *