JAL-2629 remove gap padding, and now has option to remove annotations
[jalview.git] / src / jalview / io / FileLoader.java
index 0152cc4..b861c07 100755 (executable)
@@ -27,8 +27,9 @@ import jalview.api.FeaturesSourceI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
@@ -41,7 +42,8 @@ import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.ws.utils.UrlDownloadClient;
 
-import java.nio.file.Files;
+import java.io.File;
+import java.io.IOException;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -207,6 +209,12 @@ public class FileLoader implements Runnable
       // refer to it as.
       return;
     }
+    if (file != null
+            && file.indexOf(System.getProperty("java.io.tmpdir")) > -1)
+    {
+      // ignore files loaded from the system's temporary directory
+      return;
+    }
     String type = protocol == DataSourceType.FILE ? "RECENT_FILE"
             : "RECENT_URL";
 
@@ -332,15 +340,22 @@ public class FileLoader implements Runnable
             if (downloadStructureFile)
             {
               String structExt = format.getExtensions().split(",")[0];
-              String tempStructurefile = Files.createTempFile(".jalview_",
-                      "." + structExt).toString();
-              UrlDownloadClient.download(file, tempStructurefile);
-              file = tempStructurefile;
-              protocol = DataSourceType.FILE;
+              String urlLeafName = file.substring(file.lastIndexOf(System
+                      .getProperty("file.separator")), file
+                      .lastIndexOf("."));
+              String tempStructureFileStr = createNamedJvTempFile(
+                      urlLeafName, structExt);
+              UrlDownloadClient.download(file, tempStructureFileStr);
+              al = fa.readFile(tempStructureFileStr, DataSourceType.FILE,
+                      format);
+              source = fa.getAlignFile();
+            }
+            else
+            {
+              al = fa.readFile(file, protocol, format);
+              source = fa.getAlignFile(); // keep reference for later if
+                                          // necessary.
             }
-            al = fa.readFile(file, protocol, format);
-            source = fa.getAlignFile(); // keep reference for later if
-                                        // necessary.
           }
         } catch (java.io.IOException ex)
         {
@@ -378,6 +393,43 @@ public class FileLoader implements Runnable
             }
             // append to existing alignment
             viewport.addAlignment(al, title);
+            if (source instanceof HMMFile)
+            {
+              AlignmentI alignment = viewport.getAlignment();
+              SequenceI seq = alignment
+                      .getSequenceAt(alignment.getAbsoluteHeight() - 1);
+              alignment.deleteSequence(alignment.getAbsoluteHeight() - 1);
+              SequenceGroup sg = viewport.getSelectionGroup();
+              if (sg != null)
+              {
+                seq.insertCharAt(0, sg.getStartRes(), '-');
+                seq.insertCharAt(sg.getEndRes() + 1,
+                        alignment.getWidth() - sg.getEndRes(), '-');
+                SequenceI topSeq = sg.getSequencesInOrder(alignment)[0];
+                int topIndex = alignment.findIndex(topSeq);
+                alignment.insertSequenceAt(topIndex, seq);
+                sg.setSeqrep(seq);
+                viewport.getSelectionGroup().addSequence(seq, false);
+              }
+              else
+              {
+                 for (int i = 0; i < alignment.getAbsoluteHeight(); i++)
+                  {
+                    if (!alignment.getSequenceAt(i).isHMMConsensusSequence())
+                    {
+                      alignment.getSequences().add(i, seq);
+                      break;
+                    }
+                }
+              }
+              viewport.setAlignment(alignment);
+              viewport.initInformation();
+              viewport.updateInformation(viewport.getAlignPanel());
+              viewport.getAlignPanel().adjustAnnotationHeight();
+              viewport.updateSequenceIdColours();
+              viewport.getAlignPanel().paintAlignment(true);
+              viewport.alignmentChanged(viewport.getAlignPanel());
+            }
           }
           else
           {
@@ -385,8 +437,8 @@ public class FileLoader implements Runnable
 
             if (source instanceof ComplexAlignFile)
             {
-              ColumnSelection colSel = ((ComplexAlignFile) source)
-                      .getColumnSelection();
+              HiddenColumns colSel = ((ComplexAlignFile) source)
+                      .getHiddenColumns();
               SequenceI[] hiddenSeqs = ((ComplexAlignFile) source)
                       .getHiddenSequences();
               String colourSchemeName = ((ComplexAlignFile) source)
@@ -569,6 +621,29 @@ public class FileLoader implements Runnable
 
   }
 
+  /**
+   * This method creates the file -
+   * {tmpdir}/jalview/{current_timestamp}/fileName.exetnsion using the supplied
+   * file name and extension
+   * 
+   * @param fileName
+   *          the name of the temp file to be created
+   * @param extension
+   *          the extension of the temp file to be created
+   * @return
+   */
+  private static String createNamedJvTempFile(String fileName,
+          String extension) throws IOException
+  {
+    String seprator = System.getProperty("file.separator");
+    String jvTempDir = System.getProperty("java.io.tmpdir") + "jalview"
+            + seprator + System.currentTimeMillis();
+    File tempStructFile = new File(jvTempDir + seprator + fileName + "."
+            + extension);
+    tempStructFile.mkdirs();
+    return tempStructFile.toString();
+  }
+
   /*
    * (non-Javadoc)
    *