From 6dda78dd65a8f6f25356d9fe95078afbba4eadcd Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 20 Feb 2018 15:36:24 +0000 Subject: [PATCH 1/1] JAL-2629 removed SequenceI.get/setLastPosition and related code --- src/jalview/datamodel/Alignment.java | 31 +++------------------- src/jalview/datamodel/Sequence.java | 14 ---------- src/jalview/datamodel/SequenceCollectionI.java | 6 ++--- src/jalview/datamodel/SequenceGroup.java | 33 +++--------------------- src/jalview/datamodel/SequenceI.java | 4 --- src/jalview/hmmer/HMMBuildThread.java | 22 +++++++++++----- src/jalview/hmmer/HMMSearchThread.java | 17 +++++++----- src/jalview/hmmer/HmmerCommand.java | 24 ----------------- src/jalview/viewmodel/AlignmentViewport.java | 26 +++++++++---------- src/jalview/workers/InformationThread.java | 4 +-- test/jalview/hmmer/HMMERTest.java | 10 +++---- 11 files changed, 55 insertions(+), 136 deletions(-) diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index f4be087..7f42d98 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -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 getHMMConsensusSequences(boolean remove) + @Override + public List getHMMConsensusSequences() { List 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; } diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 7f200da..6a5e4d0 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -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} */ diff --git a/src/jalview/datamodel/SequenceCollectionI.java b/src/jalview/datamodel/SequenceCollectionI.java index 2dd0ad3..4203b16 100644 --- a/src/jalview/datamodel/SequenceCollectionI.java +++ b/src/jalview/datamodel/SequenceCollectionI.java @@ -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 getHMMConsensusSequences(boolean remove); + List getHMMConsensusSequences(); } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 4b9427c..c2c4541 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -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 getHMMConsensusSequences(boolean remove) + @Override + public List getHMMConsensusSequences() { List 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; } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index d8cd58e..e5edc91 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -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 diff --git a/src/jalview/hmmer/HMMBuildThread.java b/src/jalview/hmmer/HMMBuildThread.java index 4e3dc2e..24106d6 100644 --- a/src/jalview/hmmer/HMMBuildThread.java +++ b/src/jalview/hmmer/HMMBuildThread.java @@ -187,19 +187,20 @@ public class HMMBuildThread extends HmmerCommand implements Runnable try { SequenceI[] array; - List seqs = null; + List 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); diff --git a/src/jalview/hmmer/HMMSearchThread.java b/src/jalview/hmmer/HMMSearchThread.java index 16c7c68..d3f8968 100644 --- a/src/jalview/hmmer/HMMSearchThread.java +++ b/src/jalview/hmmer/HMMSearchThread.java @@ -48,8 +48,6 @@ public class HMMSearchThread extends HmmerCommand implements Runnable long barID; - SequenceI hmmSeq; - List 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 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)); diff --git a/src/jalview/hmmer/HmmerCommand.java b/src/jalview/hmmer/HmmerCommand.java index 0f45184..a9d7018 100644 --- a/src/jalview/hmmer/HmmerCommand.java +++ b/src/jalview/hmmer/HmmerCommand.java @@ -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 diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 3506ea0..2651b79 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -2023,7 +2023,7 @@ public abstract class AlignmentViewport updateInformation(ap); List 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 diff --git a/src/jalview/workers/InformationThread.java b/src/jalview/workers/InformationThread.java index 8f8dac5..6b1bd76 100644 --- a/src/jalview/workers/InformationThread.java +++ b/src/jalview/workers/InformationThread.java @@ -38,7 +38,7 @@ public class InformationThread extends AlignCalcWorker return; } calcMan.notifyStart(this); - long started = System.currentTimeMillis(); + // long started = System.currentTimeMillis(); List information = getInformationAnnotations(); try @@ -121,7 +121,7 @@ public class InformationThread extends AlignCalcWorker protected void computeInformation(AlignmentI alignment) { int width = alignment.getWidth(); - List hmmSeqs = alignment.getHMMConsensusSequences(false); + List hmmSeqs = alignment.getHMMConsensusSequences(); int index = 0; for (SequenceI seq : hmmSeqs) diff --git a/test/jalview/hmmer/HMMERTest.java b/test/jalview/hmmer/HMMERTest.java index 7707dca..c922133 100644 --- a/test/jalview/hmmer/HMMERTest.java +++ b/test/jalview/hmmer/HMMERTest.java @@ -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 hmmSeqs = al.getHMMConsensusSequences(false); - assertNotEquals(hmmSeqs, null); - + List hmmSeqs = al.getHMMConsensusSequences(); + assertNotNull(hmmSeqs); } } -- 1.7.10.2