X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fhmmer%2FHMMSearch.java;h=21a3b208bc14889e78171122efc31fb73c4c12da;hb=49b68fe2a01763c44661e2012363f9847bfc789f;hp=7413d14ddaf341f0f812f6421a2bd2509ce8752d;hpb=d31b51985d01217340aa5f6470d3fd3c2314e3eb;p=jalview.git diff --git a/src/jalview/hmmer/HMMSearch.java b/src/jalview/hmmer/HMMSearch.java index 7413d14..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; @@ -31,10 +31,39 @@ import javax.swing.JOptionPane; public class HMMSearch extends HmmerCommand { - private static final String PARAMNAME_NO_OF_RESULTS = MessageManager.getString("label.number_of_results"); - static final String HMMSEARCH = "hmmsearch"; + /* + * constants for i18n lookup of passed parameter names + */ + static final String DATABASE_KEY = "label.database"; + + static final String THIS_ALIGNMENT_KEY = "label.this_alignment"; + + static final String USE_ACCESSIONS_KEY = "label.use_accessions"; + + static final String AUTO_ALIGN_SEQS_KEY = "label.auto_align_seqs"; + + static final String NUMBER_OF_RESULTS_KEY = "label.number_of_results"; + + static final String TRIM_TERMINI_KEY = "label.trim_termini"; + + static final String REPORTING_CUTOFF_KEY = "label.reporting_cutoff"; + + static final String CUTOFF_NONE = "None"; + + static final String CUTOFF_SCORE = "Score"; + + static final String CUTOFF_EVALUE = "E-Value"; + + static final String SEQ_EVALUE_KEY = "label.seq_evalue"; + + static final String DOM_EVALUE_KEY = "label.dom_evalue"; + + static final String SEQ_SCORE_KEY = "label.seq_score"; + + static final String DOM_SCORE_KEY = "label.dom_score"; + boolean realign = false; boolean trim = false; @@ -43,6 +72,8 @@ public class HMMSearch extends HmmerCommand SequenceI[] seqs; + private String databaseName; + /** * Constructor for the HMMSearchThread * @@ -70,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); @@ -138,66 +169,99 @@ public class HMMSearch extends HmmerCommand String dbPath = ""; File databaseFile = null; + boolean useEvalueCutoff = false; + boolean useScoreCutoff = false; + String seqEvalueCutoff = null; + String domEvalueCutoff = null; + String seqScoreCutoff = null; + String domScoreCutoff = null; + databaseName = "Alignment"; + if (params != null) { for (ArgumentI arg : params) { String name = arg.getName(); - if (MessageManager.getString("label.number_of_results") + if (MessageManager.getString(NUMBER_OF_RESULTS_KEY) .equals(name)) { seqsToReturn = Integer.parseInt(arg.getValue()); } - else if (MessageManager.getString("label.auto_align_seqs") + else if (MessageManager.getString(AUTO_ALIGN_SEQS_KEY) .equals(name)) { - realign = true; // TODO: not used + realign = true; } - else if (MessageManager.getString("label.use_accessions") + else if (MessageManager.getString(USE_ACCESSIONS_KEY) .equals(name)) { args.add("--acc"); } - else if (MessageManager.getString("label.seq_e_value").equals(name)) + else if (MessageManager.getString(REPORTING_CUTOFF_KEY) + .equals(name)) + { + if (CUTOFF_EVALUE.equals(arg.getValue())) + { + useEvalueCutoff = true; + } + else if (CUTOFF_SCORE.equals(arg.getValue())) + { + useScoreCutoff = true; + } + } + else if (MessageManager.getString(SEQ_EVALUE_KEY).equals(name)) { - args.add("--incE"); - args.add(arg.getValue()); + seqEvalueCutoff = arg.getValue(); } - else if (MessageManager.getString("label.seq_score").equals(name)) + else if (MessageManager.getString(SEQ_SCORE_KEY).equals(name)) { - args.add("-incT"); - args.add(arg.getValue()); + seqScoreCutoff = arg.getValue(); } - else if (MessageManager.getString("label.dom_e_value_desc") + else if (MessageManager.getString(DOM_EVALUE_KEY) .equals(name)) { - args.add("--incdomE"); - args.add(arg.getValue()); + domEvalueCutoff = arg.getValue(); } - else if (MessageManager.getString("label.dom_score").equals(name)) + else if (MessageManager.getString(DOM_SCORE_KEY).equals(name)) { - args.add("--incdomT"); - args.add(arg.getValue()); + domScoreCutoff = arg.getValue(); } - else if (MessageManager.getString("label.trim_termini") + else if (MessageManager.getString(TRIM_TERMINI_KEY) .equals(name)) { trim = true; } - else if (MessageManager.getString("label.database").equals(name)) + else if (MessageManager.getString(DATABASE_KEY).equals(name)) { dbFound = true; dbPath = arg.getValue(); - if (!MessageManager.getString("label.this_alignment") + if (!MessageManager.getString(THIS_ALIGNMENT_KEY) .equals(dbPath)) { + int pos = dbPath.lastIndexOf(File.separator); + databaseName = dbPath.substring(pos + 1); databaseFile = new File(dbPath); } } } } - if (!dbFound || MessageManager.getString("label.this_alignment") + if (useEvalueCutoff) + { + args.add("-E"); + args.add(seqEvalueCutoff); + args.add("--domE"); + args.add(domEvalueCutoff); + } + else if (useScoreCutoff) + { + args.add("-T"); + args.add(seqScoreCutoff); + args.add("--domT"); + args.add(domScoreCutoff); + } + + if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY) .equals(dbPath)) { /* @@ -214,12 +278,6 @@ public class HMMSearch extends HmmerCommand copy.deleteSequence(hmmSeq); } exportStockholm(copy.getSequencesArray(), databaseFile, null); - // StockholmFile stoFile = new StockholmFile(copy); - // stoFile.setSeqs(copy.getSequencesArray()); - // String alignmentString = stoFile.print(); - // PrintWriter writer = new PrintWriter(databaseFile); - // writer.print(alignmentString); - // writer.close(); } args.add(getFilePath(hmmFile)); @@ -230,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 */ @@ -259,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("label.trim_termini"), - 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(); @@ -292,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)); @@ -312,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);