JAL-2629 removed SequenceI.get/setLastPosition and related code
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 20 Feb 2018 15:36:24 +0000 (15:36 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 20 Feb 2018 15:36:24 +0000 (15:36 +0000)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceCollectionI.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/datamodel/SequenceI.java
src/jalview/hmmer/HMMBuildThread.java
src/jalview/hmmer/HMMSearchThread.java
src/jalview/hmmer/HmmerCommand.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/workers/InformationThread.java
test/jalview/hmmer/HMMERTest.java

index f4be087..7f42d98 100755 (executable)
@@ -1924,43 +1924,20 @@ public class Alignment implements AlignmentI
 
   /**
    * Returns all HMM consensus sequences. This will not return real sequences
-   * with HMMs. If remove is set to true, the consensus sequences will be
-   * removed from the alignment.
+   * with HMMs.
    */
-  @Override // TODO make this more efficient.
-  public List<SequenceI> getHMMConsensusSequences(boolean remove)
+  @Override
+  public List<SequenceI> getHMMConsensusSequences()
   {
     List<SequenceI> seqs = new ArrayList<>();
-    int position = 0;
-    int seqsRemoved = 0;
-    boolean endReached = false;
 
-    while (!endReached)
+    for (int position = 0; position < sequences.size(); position++)
     {
       SequenceI seq = sequences.get(position);
       if (seq.isHMMConsensusSequence())
       {
-        if (remove)
-        {
-          sequences.remove(position);
-          seqsRemoved++;
-          seq.setPreviousPosition(seqsRemoved + position - 1);
-        }
-        else
-        {
-          position++;
-        }
         seqs.add(seq);
       }
-      else
-      {
-        position++;
-      }
-
-      if (position >= sequences.size())
-      {
-        endReached = true;
-      }
     }
     return seqs;
   }
index 7f200da..6a5e4d0 100755 (executable)
@@ -55,8 +55,6 @@ public class Sequence extends ASequence implements SequenceI
 
   private char[] sequence;
 
-  int previousPosition;
-
   String description;
 
   int start;
@@ -1971,18 +1969,6 @@ public class Sequence extends ASequence implements SequenceI
     hasInfo = true;
   }
 
-  @Override
-  public int getPreviousPosition()
-  {
-    return previousPosition;
-  }
-
-  @Override
-  public void setPreviousPosition(int previousPosition)
-  {
-    this.previousPosition = previousPosition;
-  }
-
   /**
    * {@inheritDoc}
    */
index 2dd0ad3..4203b16 100644 (file)
@@ -72,11 +72,9 @@ public interface SequenceCollectionI
   boolean isNucleotide();
 
   /**
-   * Returns all HMM consensus sequences.
+   * Returns all HMM consensus sequences (possibly an empty list)
    * 
-   * @param remove
-   *          If true, remove all HMM consensus sequences from the alignment.
    * @return
    */
-  List<SequenceI> getHMMConsensusSequences(boolean remove);
+  List<SequenceI> getHMMConsensusSequences();
 }
index 4b9427c..c2c4541 100755 (executable)
@@ -1605,7 +1605,6 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   public boolean isShowHMMSequenceLogo()
   {
-    // TODO Auto-generated method stub
     return showHMMSequenceLogo;
   }
 
@@ -1617,7 +1616,6 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   public boolean isNormaliseHMMSequenceLogo()
   {
-    // TODO Auto-generated method stub
     return normaliseHMMSequenceLogo;
   }
 
@@ -1628,43 +1626,20 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   /**
    * Returns all HMM consensus sequences. This will not return real sequences
-   * with HMMs. If remove is set to true, the consensus sequences will be
-   * removed from the alignment.
+   * with HMMs.
    */
-  @Override // TODO make this more efficient.
-  public List<SequenceI> getHMMConsensusSequences(boolean remove)
+  @Override
+  public List<SequenceI> getHMMConsensusSequences()
   {
     List<SequenceI> seqs = new ArrayList<>();
-    int position = 0;
-    int seqsRemoved = 0;
-    boolean endReached = false;
 
-    while (!endReached)
+    for (int position = 0; position < sequences.size(); position++)
     {
       SequenceI seq = sequences.get(position);
       if (seq.isHMMConsensusSequence())
       {
-        if (remove)
-        {
-          sequences.remove(position);
-          seqsRemoved++;
-          seq.setPreviousPosition(seqsRemoved + position - 1);
-        }
-        else
-        {
-          position++;
-        }
         seqs.add(seq);
       }
-      else
-      {
-        position++;
-      }
-
-      if (position >= sequences.size())
-      {
-        endReached = true;
-      }
     }
     return seqs;
   }
index d8cd58e..e5edc91 100755 (executable)
@@ -501,10 +501,6 @@ public interface SequenceI extends ASequenceI
 
   void setHasInfo(boolean status);
 
-  int getPreviousPosition();
-
-  void setPreviousPosition(int previousPosition);
-
   /**
    * Returns a (possibly empty) list of sequence features that overlap the given
    * alignment column range, optionally restricted to one or more specified
index 4e3dc2e..24106d6 100644 (file)
@@ -187,19 +187,20 @@ public class HMMBuildThread extends HmmerCommand implements Runnable
       try
       {
         SequenceI[] array;
-        List<SequenceI> seqs = null;
+        List<SequenceI> hmmSeqs = null;
         if (forGroup)
         {
-          seqs = group.getHMMConsensusSequences(true);
-          if (seqs.size() > 0)
+          hmmSeqs = group.getHMMConsensusSequences();
+          if (hmmSeqs.size() > 0)
           {
+            // todo why this test? means can't re-run hmmbuild on a group?
             return;
           }
           array = group.getSelectionAsNewSequences(alignment);
         }
         else
         {
-          seqs = alignment.getHMMConsensusSequences(true);
+          hmmSeqs = alignment.getHMMConsensusSequences();
           if (!alignment.isAligned())
           {
             alignment.padGaps();
@@ -216,12 +217,19 @@ public class HMMBuildThread extends HmmerCommand implements Runnable
           }
           return;
         }
-        SequenceI[] newArr = new SequenceI[array.length];
+
+        /*
+         * copy over sequences excluding hmm consensus sequences
+         */
+        SequenceI[] newArr = new SequenceI[array.length - hmmSeqs.size()];
         int index = 0;
         for (SequenceI seq : array)
         {
-          newArr[index] = new Sequence(seq);
-          index++;
+          if (!seq.isHMMConsensusSequence())
+          {
+            newArr[index] = new Sequence(seq);
+            index++;
+          }
         }
 
         uniquifySequences(newArr);
index 16c7c68..d3f8968 100644 (file)
@@ -48,8 +48,6 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
 
   long barID;
 
-  SequenceI hmmSeq;
-
   List<ArgumentI> params;
 
   File hmmTemp = null;
@@ -97,7 +95,7 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
       hmm = af.getSelectedHMM();
     }
 
-    hmmSeq = af.getSelectedHMMSequence();
+    SequenceI hmmSeq = af.getSelectedHMMSequence();
     barID = System.currentTimeMillis();
     af.setProgressBar(MessageManager.getString("status.running_hmmsearch"),
             barID);
@@ -131,7 +129,7 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
     }
     try
     {
-      importData();
+      importData(hmmSeq);
     } catch (IOException | InterruptedException e)
     {
       // TODO Auto-generated catch block
@@ -234,7 +232,11 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
     {
       AlignmentI alignment = af.getViewport().getAlignment();
       AlignmentI copy = new Alignment(alignment);
-      copy.getHMMConsensusSequences(true);
+      List<SequenceI> hmms = copy.getHMMConsensusSequences();
+      for (SequenceI seq : hmms)
+      {
+        copy.deleteSequence(seq);
+      }
       StockholmFile stoFile = new StockholmFile(copy);
       stoFile.setSeqs(copy.getSequencesArray());
       String alignmentString = stoFile.print();
@@ -253,8 +255,11 @@ public class HMMSearchThread extends HmmerCommand implements Runnable
   /**
    * Imports the data from the temporary file to which the output of hmmsearch
    * is directed.
+   * 
+   * @param hmmSeq
    */
-  private void importData() throws IOException, InterruptedException
+  private void importData(SequenceI hmmSeq)
+          throws IOException, InterruptedException
   {
     BufferedReader br = new BufferedReader(
             new FileReader(inputAlignmentTemp));
index 0f45184..a9d7018 100644 (file)
@@ -182,30 +182,6 @@ public class HmmerCommand
   }
 
   /**
-   * Adds any HMM sequences removed before submitting the alignment as a job
-   * back into the alignment.
-   * 
-   * @param af
-   */
-  public void addHMMConsensusSequences(AlignFrame af)
-  {
-    AlignmentI al = af.getViewport().getAlignment();
-    if (hmmSeqs == null || hmmSeqs.size() < 1)
-    {
-      return;
-    }
-    for (SequenceI seq : hmmSeqs)
-    {
-      Integer position = seq.getPreviousPosition();
-      al.getSequences().add(position, seq);
-    }
-    af.getViewport().setAlignment(al);
-    af.alignPanel.adjustAnnotationHeight();
-    af.getViewport().updateSequenceIdColours();
-    af.buildSortByAnnotationScoresMenu();
-  }
-
-  /**
    * Returns the list of HMM sequences removed
    * 
    * @return
index 3506ea0..2651b79 100644 (file)
@@ -2023,7 +2023,7 @@ public abstract class AlignmentViewport
     updateInformation(ap);
 
     List<SequenceI> hmmSequences;
-    hmmSequences = alignment.getHMMConsensusSequences(false);
+    hmmSequences = alignment.getHMMConsensusSequences();
 
     for (SequenceI seq : hmmSequences)
     {
@@ -2165,30 +2165,28 @@ public abstract class AlignmentViewport
   @Override
   public void initInformation()
   {
-    for (SequenceI seq : alignment.getHMMConsensusSequences(false))
+    for (SequenceI seq : alignment.getHMMConsensusSequences())
     {
       if (!seq.hasHMMAnnotation())
       {
-        AlignmentAnnotation information;
-        information = new AlignmentAnnotation(seq.getName(),
+        AlignmentAnnotation info = new AlignmentAnnotation(seq.getName(),
                 MessageManager.getString("label.information_description"),
                 new Annotation[1], 0f, 6.52f,
                 AlignmentAnnotation.BAR_GRAPH);
-        information.hasText = true;
-        information.autoCalculated = true;
-        information.hasText = true;
-        information.autoCalculated = false;
-        information.sequenceRef = seq;
-        information.setCalcId("HMM");
-        this.information.add(information);
+        info.hasText = true;
+        info.autoCalculated = true;
+        info.hasText = true;
+        info.autoCalculated = false;
+        info.sequenceRef = seq;
+        info.setCalcId("HMM");
+        this.information.add(info);
         hinformation.add(new Profiles(new ProfileI[1]));
-        alignment.addAnnotation(information);
+        alignment.addAnnotation(info);
         seq.updateHMMMapping();
         seq.setHasInfo(true);
-        seq.addAlignmentAnnotation(information);
+        seq.addAlignmentAnnotation(info);
       }
     }
-
   }
 
   // these should be extracted from the view model - style and settings for
index 8f8dac5..6b1bd76 100644 (file)
@@ -38,7 +38,7 @@ public class InformationThread extends AlignCalcWorker
       return;
     }
     calcMan.notifyStart(this);
-    long started = System.currentTimeMillis();
+    // long started = System.currentTimeMillis();
 
     List<AlignmentAnnotation> information = getInformationAnnotations();
     try
@@ -121,7 +121,7 @@ public class InformationThread extends AlignCalcWorker
   protected void computeInformation(AlignmentI alignment)
   {
     int width = alignment.getWidth();
-    List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
+    List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences();
     int index = 0;
 
     for (SequenceI seq : hmmSeqs)
index 7707dca..c922133 100644 (file)
@@ -2,6 +2,7 @@ package jalview.hmmer;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.fail;
 
 import jalview.bin.Jalview;
@@ -99,12 +100,11 @@ public class HMMERTest {
       fail();
     }
 
-    AlignFrame frame = Desktop.getAlignFrames()[0];
-    AlignmentI al = frame.getViewport().getAlignment();
+    AlignFrame fr = Desktop.getAlignFrames()[0];
+    AlignmentI al = fr.getViewport().getAlignment();
     assertNotEquals(al, null);
-    List<SequenceI> hmmSeqs = al.getHMMConsensusSequences(false);
-    assertNotEquals(hmmSeqs, null);
-
+    List<SequenceI> hmmSeqs = al.getHMMConsensusSequences();
+    assertNotNull(hmmSeqs);
   }
 }