From 3328ff82d86879e92139b1b2c98a1653939ee353 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Mon, 14 Aug 2017 15:16:46 +0100 Subject: [PATCH] JAL-2629 add insert sequence at method on alignment --- src/jalview/datamodel/Alignment.java | 23 +++++++++++++++--- src/jalview/datamodel/AlignmentI.java | 3 ++- src/jalview/hmmer/HMMAlignThread.java | 43 +++------------------------------ src/jalview/io/FileLoader.java | 15 ++++++------ 4 files changed, 32 insertions(+), 52 deletions(-) diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 38d0092..975a771 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -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; } - - - } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 58df1b0..561706f 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -592,7 +592,8 @@ public interface AlignmentI extends AnnotatedCollectionI public void setHiddenColumns(HiddenColumns cols); public List getHMMConsensusSequences(boolean remove); - + + void insertSequenceAt(int i, SequenceI snew); diff --git a/src/jalview/hmmer/HMMAlignThread.java b/src/jalview/hmmer/HMMAlignThread.java index 4f4e46c..a778e14 100644 --- a/src/jalview/hmmer/HMMAlignThread.java +++ b/src/jalview/hmmer/HMMAlignThread.java @@ -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 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(); diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 9f46494..b861c07 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -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); -- 1.7.10.2