From 49b68fe2a01763c44661e2012363f9847bfc789f Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 15 May 2018 10:45:22 +0100 Subject: [PATCH] JAL-2629 JAL-2937 respect 'align automatically' option for HMMSearch --- src/jalview/hmmer/HMMSearch.java | 102 ++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/src/jalview/hmmer/HMMSearch.java b/src/jalview/hmmer/HMMSearch.java index efc34ae..21a3b20 100644 --- a/src/jalview/hmmer/HMMSearch.java +++ b/src/jalview/hmmer/HMMSearch.java @@ -4,10 +4,10 @@ import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; -import jalview.datamodel.Annotation; import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.io.DataSourceType; import jalview.io.FileParse; @@ -72,6 +72,8 @@ public class HMMSearch extends HmmerCommand SequenceI[] seqs; + private String databaseName; + /** * Constructor for the HMMSearchThread * @@ -99,7 +101,7 @@ public class HMMSearch extends HmmerCommand return; } - SequenceI hmmSeq = hmm.getConsensusSequence();// af.getSelectedHMMSequence(); + SequenceI hmmSeq = hmm.getConsensusSequence(); long msgId = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmsearch"), msgId); @@ -173,6 +175,7 @@ public class HMMSearch extends HmmerCommand String domEvalueCutoff = null; String seqScoreCutoff = null; String domScoreCutoff = null; + databaseName = "Alignment"; if (params != null) { @@ -187,7 +190,7 @@ public class HMMSearch extends HmmerCommand else if (MessageManager.getString(AUTO_ALIGN_SEQS_KEY) .equals(name)) { - realign = true; // TODO: not used + realign = true; } else if (MessageManager.getString(USE_ACCESSIONS_KEY) .equals(name)) @@ -235,6 +238,8 @@ public class HMMSearch extends HmmerCommand if (!MessageManager.getString(THIS_ALIGNMENT_KEY) .equals(dbPath)) { + int pos = dbPath.lastIndexOf(File.separator); + databaseName = dbPath.substring(pos + 1); databaseFile = new File(dbPath); } } @@ -283,7 +288,7 @@ public class HMMSearch extends HmmerCommand /** * Imports the data from the temporary file to which the output of hmmsearch - * is directed. + * was directed. The results are optionally realigned using hmmalign. * * @param hmmSeq */ @@ -312,27 +317,21 @@ public class HMMSearch extends HmmerCommand hmmAndSeqs[0] = hmmSeq; System.arraycopy(seqs, 0, hmmAndSeqs, 1, seqCount); - /* - * and align the search results to the HMM profile - */ - AlignmentI al = new Alignment(hmmAndSeqs); - AlignFrame frame = new AlignFrame(al, 1, 1); - List alignArgs = new ArrayList<>(); - String defSeq = hmmSeq.getName(); - List options = Collections.singletonList(defSeq); - Option option = new Option(MessageManager.getString("label.use_hmm"), - "", true, defSeq, defSeq, options, null); - alignArgs.add(option); - if (trim) + if (realign) + { + realignResults(hmmAndSeqs); + } + else { - alignArgs.add(new BooleanOption( - MessageManager.getString(TRIM_TERMINI_KEY), - MessageManager.getString("label.trim_termini_desc"), true, - true, true, null)); + AlignmentI al = new Alignment(hmmAndSeqs); + AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + String ttl = "hmmSearch of " + databaseName + " using " + + hmmSeq.getName(); + Desktop.addInternalFrame(alignFrame, ttl, AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); } - HmmerCommand hmmalign = new HMMAlign(frame, alignArgs); - hmmalign.run(); - frame = null; + hmmTemp.delete(); inputAlignmentTemp.delete(); searchOutputFile.delete(); @@ -345,6 +344,43 @@ public class HMMSearch extends HmmerCommand } } + /** + * Realigns the given sequences using hmmalign, to the HMM profile sequence + * which is the first in the array, and opens the results in a new frame + * + * @param hmmAndSeqs + */ + protected void realignResults(SequenceI[] hmmAndSeqs) + { + /* + * and align the search results to the HMM profile + */ + AlignmentI al = new Alignment(hmmAndSeqs); + AlignFrame frame = new AlignFrame(al, 1, 1); + List alignArgs = new ArrayList<>(); + String alignTo = hmmAndSeqs[0].getName(); + List options = Collections.singletonList(alignTo); + Option option = new Option(MessageManager.getString("label.use_hmm"), + "", true, alignTo, alignTo, options, null); + alignArgs.add(option); + if (trim) + { + alignArgs.add(new BooleanOption( + MessageManager.getString(TRIM_TERMINI_KEY), + MessageManager.getString("label.trim_termini_desc"), true, + true, true, null)); + } + HmmerCommand hmmalign = new HMMAlign(frame, alignArgs); + hmmalign.run(); + } + + /** + * Reads in the scores table output by hmmsearch and adds annotation to + * sequences for E-value and bit score + * + * @param inputTableTemp + * @throws IOException + */ void readTable(File inputTableTemp) throws IOException { BufferedReader br = new BufferedReader(new FileReader(inputTableTemp)); @@ -365,16 +401,18 @@ public class HMMSearch extends HmmerCommand Scanner scanner = new Scanner(line); String str = scanner.next(); // full sequence eValue score - float eValue = Float.parseFloat(str); - int seqLength = seqs[index].getLength(); - Annotation[] annots = new Annotation[seqLength]; - for (int j = 0; j < seqLength; j++) - { - annots[j] = new Annotation(eValue); - } + // float eValue = Float.parseFloat(str); + // int seqLength = seqs[index].getLength(); + // Annotation[] annots = new Annotation[seqLength]; + // for (int j = 0; j < seqLength; j++) + // { + // annots[j] = new Annotation(eValue); + // } AlignmentAnnotation annot = new AlignmentAnnotation("E-value", - "Score", annots); - annot.setScore(Double.parseDouble(str)); + "Score", null); + annot.setCalcId(HMMSEARCH); + double eValue = Double.parseDouble(str); + annot.setScore(eValue); annot.setSequenceRef(seqs[index]); seqs[index].addAlignmentAnnotation(annot); -- 1.7.10.2