From: Thomas <170013569@dundee.ac.uk> Date: Fri, 12 Jul 2019 13:42:48 +0000 (+0100) Subject: JAL-2629 hmmer searches now read domain rather than full scores X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=72404f561ccd190eab1990874f017bbe94bf9e10;p=jalview.git JAL-2629 hmmer searches now read domain rather than full scores --- diff --git a/src/jalview/hmmer/HMMSearch.java b/src/jalview/hmmer/HMMSearch.java index f670633..f05823e 100644 --- a/src/jalview/hmmer/HMMSearch.java +++ b/src/jalview/hmmer/HMMSearch.java @@ -157,6 +157,8 @@ public class HMMSearch extends Search inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE)); seqs = file.getSeqsAsArray(); + readDomainTable(searchOutputFile, false); + if (searchAlignment) { recoverSequences(sequencesHash, seqs); @@ -179,7 +181,7 @@ public class HMMSearch extends Search } } } - readTable(searchOutputFile); + int seqCount = Math.min(seqs.length, seqsToReturn); SequenceI[] hmmAndSeqs = new SequenceI[seqCount + 1]; diff --git a/src/jalview/hmmer/HmmerCommand.java b/src/jalview/hmmer/HmmerCommand.java index b5698eb..f38be02 100644 --- a/src/jalview/hmmer/HmmerCommand.java +++ b/src/jalview/hmmer/HmmerCommand.java @@ -397,8 +397,8 @@ public abstract class HmmerCommand implements Runnable } /** - * Answers the HMM profile for the profile sequence the user selected (default - * is just the first HMM sequence in the alignment) + * Answers the query sequence the user selected (default is just the first + * sequence in the alignment) * * @return */ diff --git a/src/jalview/hmmer/JackHMMER.java b/src/jalview/hmmer/JackHMMER.java index d822439..12c0492 100644 --- a/src/jalview/hmmer/JackHMMER.java +++ b/src/jalview/hmmer/JackHMMER.java @@ -26,6 +26,8 @@ import javax.swing.JOptionPane; public class JackHMMER extends Search { + SequenceI seq = null; + /** * Constructor for the JackhmmerThread * @@ -45,7 +47,7 @@ public class JackHMMER extends Search @Override public void run() { - SequenceI seq = getSequence(); + seq = getSequence(); if (seq == null) { // shouldn't happen if we got this far @@ -138,15 +140,18 @@ public class JackHMMER extends Search inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE)); seqs = file.getSeqsAsArray(); + readDomainTable(searchOutputFile, true); + if (searchAlignment) { recoverSequences(sequencesHash, seqs); } - readTable(searchOutputFile); + int seqCount = seqs.length; + AlignmentI al = new Alignment(seqs); AlignFrame alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, diff --git a/src/jalview/hmmer/Search.java b/src/jalview/hmmer/Search.java index 2fad426..5c7da7c 100644 --- a/src/jalview/hmmer/Search.java +++ b/src/jalview/hmmer/Search.java @@ -46,6 +46,59 @@ public abstract class Search extends HmmerCommand { } + /* + void readOutputFile(File inputTableTemp) throws IOException + { + BufferedReader br = new BufferedReader(new FileReader(inputTableTemp)); + + + String line = ""; + while (!line.startsWith("//")) + { + + while (!line.startsWith(">> ") && !line.startsWith("//")) + { + line = br.readLine(); + } + + if (line.startsWith("//")) + { + break; + } + + Scanner scanner = new Scanner(line); + String name = scanner.next(); + name = scanner.next(); + + br.readLine(); + br.readLine(); + + List domains = new ArrayList<>(); + + for (SequenceI seq : seqs) + { + if (seq.getName().contains(name)) + { + domains.add(seq); + } + } + + if (domains.contains(getSequence())) + { + domains.remove(getSequence()); + } + + if (domains.size() > 0) + { + readOutputTable(br, domains); + } + + line = br.readLine(); + } + + } + + /** * Reads in the scores table output by jackhmmer and adds annotation to * sequences for E-value and bit score @@ -53,22 +106,11 @@ public abstract class Search extends HmmerCommand * @param inputTableTemp * @throws IOException */ - void readTable(File inputTableTemp) throws IOException + /* + void readOutputTable(BufferedReader br, List seqs) throws IOException { - BufferedReader br = new BufferedReader(new FileReader(inputTableTemp)); - String line = ""; - while (!line.startsWith("Query:")) - { - line = br.readLine(); - } - while (!line.contains("-------")) - { - line = br.readLine(); - } - line = br.readLine(); - - int index = 0; - + String line = br.readLine(); + while (!"".equals(line) && line != null) { if (" ------ inclusion threshold ------".equals(line)) @@ -76,53 +118,97 @@ public abstract class Search extends HmmerCommand line = br.readLine(); continue; } - + Scanner scanner = new Scanner(line); + scanner.next(); + scanner.next(); + String score = scanner.next(); + + scanner.next(); + String evalue = scanner.next(); - - if (evalue.equals("+") || evalue.equals("-")) + + scanner.next(); + scanner.next(); + scanner.next(); + scanner.next(); + + int start = scanner.nextInt(); + int end = scanner.nextInt(); + + SequenceI seq = null; + for (SequenceI sequence : seqs) + { + if (sequence.getStart() >= start && sequence.getEnd() <= end) + { + seq = sequence; + break; + } + } + + if (seq != null) { - evalue = scanner.next(); + addScoreAnnotations(evalue, score, seq); } - - - String score = scanner.next(); - checkSequenceOrder(index, scanner); - SequenceI seq = seqs[index]; - addScoreAnnotations(evalue, score, seq); + scanner.close(); line = br.readLine(); - index++; } - - br.close(); } + */ - void checkSequenceOrder(int index, Scanner scanner) + void readDomainTable(File inputTableTemp, boolean includesQuery) + throws IOException { - String seqName = null; + BufferedReader br = new BufferedReader(new FileReader(inputTableTemp)); - for (int i = 0; i < 7; i++) + String line = br.readLine(); + br.readLine(); + br.readLine(); + line = br.readLine(); + + int index; + + if (includesQuery) { - seqName = scanner.next(); + index = 1; } - - if (!seqs[index].getName().equals(seqName)) + else { - SequenceI temp = seqs[index]; + index = 0; + } + while (!line.startsWith("#")) + { + if (line.contains("inclusion threshold")) + { + line = br.readLine(); + continue; + } + + Scanner scanner = new Scanner(line); + String name = scanner.next(); - for (int j = 0; j < seqs.length; j++) + for (int i = 0; i < 10; i++) { - if (seqs[j].getName().equals(seqName)) - { - seqs[index] = seqs[j]; - seqs[j] = temp; - break; - } + scanner.next(); } + + String evalue = scanner.next(); + scanner.next(); + String score = scanner.next(); + + addScoreAnnotations(evalue, score, seqs[index]); + index++; + + scanner.close(); + line = br.readLine(); } + br.close(); } + + + void addScoreAnnotations(String eValue, String bitScore, SequenceI seq) { String label = "Search Scores"; @@ -157,7 +243,7 @@ public abstract class Search extends HmmerCommand void buildArguments(List args, File searchOutputFile, File hitsAlignmentFile, File queryFile) throws IOException { - args.add("-o"); + args.add("--domtblout"); args.add(getFilePath(searchOutputFile, true)); args.add("-A"); args.add(getFilePath(hitsAlignmentFile, true));