X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fhmmer%2FHMMSearch.java;h=1506c0f50d2a9172633dc3f6f4fedf2ad2e1c772;hb=bedfa8b30d527da43c403b96ab45aec8ab317555;hp=21a3b208bc14889e78171122efc31fb73c4c12da;hpb=49b68fe2a01763c44661e2012363f9847bfc789f;p=jalview.git diff --git a/src/jalview/hmmer/HMMSearch.java b/src/jalview/hmmer/HMMSearch.java index 21a3b20..1506c0f 100644 --- a/src/jalview/hmmer/HMMSearch.java +++ b/src/jalview/hmmer/HMMSearch.java @@ -4,6 +4,7 @@ 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; @@ -160,10 +161,29 @@ public class HMMSearch extends HmmerCommand List args = new ArrayList<>(); args.add(command); + buildArguments(args, searchOutputFile, hitsAlignmentFile, hmmFile); + + return runCommand(args); + } + + /** + * Appends command line arguments to the given list, to specify input and + * output files for the search, and any additional options that may have been + * passed from the parameters dialog + * + * @param args + * @param searchOutputFile + * @param hitsAlignmentFile + * @param hmmFile + * @throws IOException + */ + protected void buildArguments(List args, File searchOutputFile, + File hitsAlignmentFile, File hmmFile) throws IOException + { args.add("-o"); - args.add(getFilePath(searchOutputFile)); + args.add(getFilePath(searchOutputFile, true)); args.add("-A"); - args.add(getFilePath(hitsAlignmentFile)); + args.add(getFilePath(hitsAlignmentFile, true)); boolean dbFound = false; String dbPath = ""; @@ -176,6 +196,7 @@ public class HMMSearch extends HmmerCommand String seqScoreCutoff = null; String domScoreCutoff = null; databaseName = "Alignment"; + boolean searchAlignment = false; if (params != null) { @@ -187,6 +208,18 @@ public class HMMSearch extends HmmerCommand { seqsToReturn = Integer.parseInt(arg.getValue()); } + else if (MessageManager.getString("action.search").equals(name)) + { + searchAlignment = arg.getValue().equals( + MessageManager.getString(HMMSearch.THIS_ALIGNMENT_KEY)); + } + else if (MessageManager.getString(DATABASE_KEY).equals(name)) + { + dbPath = arg.getValue(); + int pos = dbPath.lastIndexOf(File.separator); + databaseName = dbPath.substring(pos + 1); + databaseFile = new File(dbPath); + } else if (MessageManager.getString(AUTO_ALIGN_SEQS_KEY) .equals(name)) { @@ -261,8 +294,9 @@ public class HMMSearch extends HmmerCommand args.add(domScoreCutoff); } - if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY) - .equals(dbPath)) +// if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY) +// .equals(dbPath)) + if (searchAlignment) { /* * no external database specified for search, so @@ -280,10 +314,8 @@ public class HMMSearch extends HmmerCommand exportStockholm(copy.getSequencesArray(), databaseFile, null); } - args.add(getFilePath(hmmFile)); - args.add(getFilePath(databaseFile)); - - return runCommand(args); + args.add(getFilePath(hmmFile, true)); + args.add(getFilePath(databaseFile, true)); } /** @@ -309,14 +341,55 @@ public class HMMSearch extends HmmerCommand StockholmFile file = new StockholmFile(new FileParse( inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE)); seqs = file.getSeqsAsArray(); - + // look for PP cons and ref seq in alignment only annotation + AlignmentAnnotation modelpos = null, ppcons = null; + for (AlignmentAnnotation aa : file.getAnnotations()) + { + if (aa.sequenceRef == null) + { + if (aa.label.equals("Reference Positions")) // RF feature type in + // stockholm parser + { + modelpos = aa; + } + if (aa.label.equals("Posterior Probability")) + { + ppcons = aa; + } + } + } readTable(searchOutputFile); int seqCount = Math.min(seqs.length, seqsToReturn); SequenceI[] hmmAndSeqs = new SequenceI[seqCount + 1]; + hmmSeq = hmmSeq.deriveSequence(); // otherwise all bad things happen hmmAndSeqs[0] = hmmSeq; System.arraycopy(seqs, 0, hmmAndSeqs, 1, seqCount); - + if (modelpos != null) + { + // TODO need - get ungapped sequence method + hmmSeq.setSequence( + hmmSeq.getDatasetSequence().getSequenceAsString()); + Annotation[] refpos = modelpos.annotations; + // insert gaps to match with refseq positions + int gc = 0, lcol = 0; + for (int c = 0; c < refpos.length; c++) + { + if (refpos[c] != null && ("x".equals(refpos[c].displayCharacter))) + { + if (gc > 0) + { + hmmSeq.insertCharAt(lcol + 1, gc, '-'); + } + gc = 0; + lcol = c; + } + else + { + gc++; + } + } + } if (realign) { realignResults(hmmAndSeqs); @@ -324,6 +397,14 @@ public class HMMSearch extends HmmerCommand else { AlignmentI al = new Alignment(hmmAndSeqs); + if (ppcons != null) + { + al.addAnnotation(ppcons); + } + if (modelpos != null) + { + al.addAnnotation(modelpos); + } AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); String ttl = "hmmSearch of " + databaseName + " using " @@ -389,7 +470,7 @@ public class HMMSearch extends HmmerCommand { line = br.readLine(); } - for (int i = 0; i < 5; i++) + for (int i = 0; i < 6; i++) { line = br.readLine(); } @@ -398,24 +479,18 @@ public class HMMSearch extends HmmerCommand while (!" ------ inclusion threshold ------".equals(line) && !"".equals(line)) { + SequenceI seq = seqs[index]; + AlignmentAnnotation pp = seq + .getAlignmentAnnotations("", "Posterior Probability") + .get(0); 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); - // } - AlignmentAnnotation annot = new AlignmentAnnotation("E-value", - "Score", null); - annot.setCalcId(HMMSEARCH); - double eValue = Double.parseDouble(str); - annot.setScore(eValue); - annot.setSequenceRef(seqs[index]); - seqs[index].addAlignmentAnnotation(annot); - + String str = scanner.next(); + addScoreAnnotation(str, seq, "hmmsearch E-value", + "Full sequence E-value", pp); + str = scanner.next(); + addScoreAnnotation(str, seq, "hmmsearch Score", + "Full sequence bit score", pp); + seq.removeAlignmentAnnotation(pp); scanner.close(); line = br.readLine(); index++; @@ -424,4 +499,59 @@ public class HMMSearch extends HmmerCommand br.close(); } + /** + * A helper method that adds one score-only (non-positional) annotation to a + * sequence + * + * @param value + * @param seq + * @param label + * @param description + */ + protected void addScoreAnnotation(String value, SequenceI seq, + String label, String description) + { + addScoreAnnotation(value, seq, label, description, null); + } + + /** + * A helper method that adds one score-only (non-positional) annotation to a + * sequence + * + * @param value + * @param seq + * @param label + * @param description + * @param pp + * existing posterior probability annotation - values copied to new + * annotation row + */ + protected void addScoreAnnotation(String value, SequenceI seq, + String label, String description, AlignmentAnnotation pp) + { + try + { + AlignmentAnnotation annot = null; + if (pp == null) + { + new AlignmentAnnotation(label, + description, null); + } + else + { + annot = new AlignmentAnnotation(pp); + annot.label = label; + annot.description = description; + } + annot.setCalcId(HMMSEARCH); + double eValue = Double.parseDouble(value); + annot.setScore(eValue); + annot.setSequenceRef(seq); + seq.addAlignmentAnnotation(annot); + } catch (NumberFormatException e) + { + System.err.println("Error parsing " + label + " from " + value); + } + } + }