JAL-2629 add insert sequence at method on alignment
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Mon, 14 Aug 2017 14:16:46 +0000 (15:16 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Mon, 14 Aug 2017 14:16:46 +0000 (15:16 +0100)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/hmmer/HMMAlignThread.java
src/jalview/io/FileLoader.java

index 38d0092..975a771 100755 (executable)
@@ -288,6 +288,26 @@ public class Alignment implements AlignmentI
     }
   }
 
+  @Override
+  public void insertSequenceAt(int i, SequenceI snew)
+  {
+    synchronized (sequences)
+    {
+      if (sequences.size() > i)
+      {
+        sequences.add(i, snew);
+        return;
+
+      }
+      else
+      {
+        sequences.add(snew);
+        hiddenSequences.adjustHeightSequenceAdded();
+      }
+      return;
+    }
+  }
+
   /**
    * DOCUMENT ME!
    * 
@@ -1998,7 +2018,4 @@ public class Alignment implements AlignmentI
     }
     return seqs;
   }
-
-
-
 }
index 58df1b0..561706f 100755 (executable)
@@ -592,7 +592,8 @@ public interface AlignmentI extends AnnotatedCollectionI
   public void setHiddenColumns(HiddenColumns cols);
   
   public List<SequenceI> getHMMConsensusSequences(boolean remove);
-  
+
+  void insertSequenceAt(int i, SequenceI snew);
 
   
 
index 4f4e46c..a778e14 100644 (file)
@@ -80,7 +80,7 @@ public class HMMAlignThread implements Runnable
   @Override
   public void run()
   {
-    if (af.getViewport().getSelectedHMM() == null)
+         if (af.getViewport().getSelectedHMM() == null)
     {
       JOptionPane.showMessageDialog(af,
               MessageManager.getString("warn.no_selected_hmm"));
@@ -88,10 +88,10 @@ public class HMMAlignThread implements Runnable
     }
     else
     {
-      hmm = af.getViewport().getSelectedHMM();
+       hmm = af.getViewport().getSelectedHMM();
     }
     barID = System.currentTimeMillis();
-    af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
+    af.setProgressBar(MessageManager.getString("status.running_hmmalign"),
             barID);
     cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
 
@@ -198,47 +198,10 @@ public class HMMAlignThread implements Runnable
             DataSourceType.FILE);
     SequenceI[] result = file.getSeqsAsArray();
     AlignmentOrder msaorder = new AlignmentOrder(result);
-    // always recover the order - makes parseResult()'s life easier.
     jalview.analysis.AlignmentSorter.recoverOrder(result);
     jalview.analysis.SeqsetUtils.deuniquify(cmds.hash, result);
     allOrders.add(msaorder);
     allResults[index] = result;
-
-    /*
-    if (newFrame)
-    {
-      FileLoader loader = new FileLoader();
-      AlignFrame aFrame = new AlignFrame(new Alignment(new SequenceI[1]),
-              AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
-      Desktop.addInternalFrame(aFrame, aFrame.getTitle(),
-              AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
-      aFrame.setTitle(
-              af.getName() + "Aligned to " + hmm.getName() + "'s HMM");
-      af.getViewport().setAlignment(null);
-    
-      aFrame.loadJalviewDataFile(inputTemp.getAbsolutePath(),
-              DataSourceType.FILE, FileFormat.Stockholm, null);
-    
-    
-    
-      Map<Integer, SequenceI> copy = new HashMap<>(
-              hmmSeqs);
-      addSeqs(aFrame, copy);
-      SequenceI seq = aFrame.getViewport().getAlignment()
-              .getSequenceAt(0);
-      seq.getHMM().mapToReferenceAnnotation(aFrame, seq);
-      addSeqs(af, hmmSeqs);
-    }
-    else
-    {
-      af.getViewport().getAlignment().getSequences().clear();
-      af.setIsRecurring(true);
-      af.loadJalviewDataFile(inputTemp.getAbsolutePath(),
-              DataSourceType.FILE, FileFormat.Stockholm, null);
-      af.setIsRecurring(false);
-      addSeqs(af, hmmSeqs);
-    }
-    */
     hmmTemp.delete();
     outTemp.delete();
     inputTemp.delete();
index 9f46494..b861c07 100755 (executable)
@@ -407,20 +407,19 @@ public class FileLoader implements Runnable
                         alignment.getWidth() - sg.getEndRes(), '-');
                 SequenceI topSeq = sg.getSequencesInOrder(alignment)[0];
                 int topIndex = alignment.findIndex(topSeq);
-                alignment.getSequences().add(topIndex, seq);
+                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())
+                 for (int i = 0; i < alignment.getAbsoluteHeight(); i++)
                   {
-                    alignment.getSequences().add(i, seq);
-                    break;
-                  }
-
+                    if (!alignment.getSequenceAt(i).isHMMConsensusSequence())
+                    {
+                      alignment.getSequences().add(i, seq);
+                      break;
+                    }
                 }
               }
               viewport.setAlignment(alignment);