From: TZVanaalten Date: Wed, 9 Aug 2017 15:19:45 +0000 (+0100) Subject: JAL-2629 buffers are now temporary files X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=14f7749faaa412520da17345d6dccb010d5009d8;p=jalview.git JAL-2629 buffers are now temporary files --- diff --git a/src/jalview/hmmer/HMMAlignThread.java b/src/jalview/hmmer/HMMAlignThread.java index 3879a87..79a8092 100644 --- a/src/jalview/hmmer/HMMAlignThread.java +++ b/src/jalview/hmmer/HMMAlignThread.java @@ -1,17 +1,19 @@ package jalview.hmmer; import jalview.bin.Cache; +import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.AlignmentOrder; import jalview.datamodel.HiddenMarkovModel; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.Desktop; import jalview.gui.Preferences; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.FileLoader; import jalview.util.MessageManager; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; @@ -19,6 +21,7 @@ import java.util.Map; public class HMMAlignThread implements Runnable { + HMMERCommands cmds = new HMMERCommands(); AlignFrame af; @@ -46,13 +49,28 @@ public class HMMAlignThread implements Runnable barID = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); - HMMERCommands.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); + cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); + try + { + cmds.HMMBUFFER = File.createTempFile("hmm", ".hmm").getAbsolutePath() + + cmds.SPACE; + cmds.ALIGNMENTBUFFER = File.createTempFile("output", ".sto") + .getAbsolutePath() + cmds.SPACE; + cmds.ALIGNMENTINPUT = File.createTempFile("input", ".sto") + .getAbsolutePath() + cmds.SPACE; + cmds.OUTPUTALIGNMENT = "-o " + cmds.ALIGNMENTINPUT + cmds.SPACE; + } catch (IOException e1) + { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { try { hmmSeqs = alignment.getHMMConsensusSequences(true); - HMMERCommands.exportData(alignment, true, true, hmm); + cmds.exportData(alignment, true, true, hmm); } catch (FileNotFoundException e) { // TODO Auto-generated catch block @@ -87,16 +105,14 @@ public class HMMAlignThread implements Runnable private void runCommand() throws IOException, InterruptedException { - String command = HMMERCommands.HMMERFOLDER + HMMERCommands.HMMALIGN; + String command = cmds.HMMERFOLDER + cmds.HMMALIGN; if (!hmm.getFileHeader().contains("HMMER3/f")) { - command += HMMERCommands.ALLCOL; + command += cmds.ALLCOL; } - command += HMMERCommands.TRIM + HMMERCommands.OUTPUTALIGNMENT - + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.HMMBUFFER - + HMMERCommands.JALVIEWDIRECTORY - + HMMERCommands.ALIGNMENTBUFFER; - HMMERCommands.runCommand(command); + command += cmds.TRIM + cmds.OUTPUTALIGNMENT + cmds.HMMBUFFER + + cmds.ALIGNMENTBUFFER; + cmds.runCommand(command); } private void importData() throws IOException, InterruptedException @@ -104,22 +120,32 @@ public class HMMAlignThread implements Runnable if (newFrame) { FileLoader loader = new FileLoader(); - AlignmentOrder order = new AlignmentOrder(alignment); - AlignFrame newAFrame = loader.LoadFileWaitTillLoaded( - HMMERCommands.ALIGNMENTINPUT, DataSourceType.FILE); + 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(cmds.ALIGNMENTINPUT, + DataSourceType.FILE, FileFormat.Stockholm, null); + + + Map copy = new HashMap<>( hmmSeqs); - addSeqs(newAFrame, copy); - SequenceI seq = newAFrame.getViewport().getAlignment() + addSeqs(aFrame, copy); + SequenceI seq = aFrame.getViewport().getAlignment() .getSequenceAt(0); - hmm.mapToReferenceAnnotation(newAFrame, seq); + seq.getHMM().mapToReferenceAnnotation(aFrame, seq); addSeqs(af, hmmSeqs); } else { af.getViewport().getAlignment().getSequences().clear(); af.setIsRecurring(true); - af.loadJalviewDataFile(HMMERCommands.ALIGNMENTBUFFER, + af.loadJalviewDataFile(cmds.ALIGNMENTBUFFER, DataSourceType.FILE, FileFormat.Stockholm, null); af.setIsRecurring(false); addSeqs(af, hmmSeqs); @@ -132,7 +158,7 @@ public class HMMAlignThread implements Runnable { SequenceI seq = entry.getValue(); Integer pos = entry.getKey(); - HMMERCommands.addHMMConsensusSequence(alignFrame, seq, pos); + cmds.addHMMConsensusSequence(alignFrame, seq, pos); } } diff --git a/src/jalview/hmmer/HMMBuildThread.java b/src/jalview/hmmer/HMMBuildThread.java index e48dce3..cf89863 100644 --- a/src/jalview/hmmer/HMMBuildThread.java +++ b/src/jalview/hmmer/HMMBuildThread.java @@ -10,13 +10,14 @@ import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.util.MessageManager; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; public class HMMBuildThread implements Runnable { - + HMMERCommands cmds = new HMMERCommands(); AlignFrame af; AlignmentI alignment; @@ -36,14 +37,24 @@ public class HMMBuildThread implements Runnable barID = System.currentTimeMillis(); af.setProgressBar(MessageManager.getString("status.running_hmmbuild"), barID); - HMMERCommands.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); + cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH); + try + { + cmds.HMMBUFFER = File.createTempFile("hmm", ".hmm").getAbsolutePath() + + cmds.SPACE; + cmds.ALIGNMENTBUFFER = File.createTempFile("output", ".sto") + .getAbsolutePath() + cmds.SPACE; + } catch (IOException e1) + { + e1.printStackTrace(); + } try { try { hmmSeqs = alignment.getHMMConsensusSequences(true); - HMMERCommands.exportData(alignment, true, false, + cmds.exportData(alignment, true, false, new HiddenMarkovModel()); } catch (FileNotFoundException e) { @@ -82,23 +93,21 @@ public class HMMBuildThread implements Runnable private void runCommand() throws IOException, InterruptedException { - final String command = HMMERCommands.HMMERFOLDER - + HMMERCommands.HMMBUILD + HMMERCommands.NAME - + af.getName() + HMMERCommands.SPACE - + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.HMMBUFFER - + HMMERCommands.JALVIEWDIRECTORY + HMMERCommands.ALIGNMENTBUFFER; - HMMERCommands.runCommand(command); + final String command = cmds.HMMERFOLDER + cmds.HMMBUILD + cmds.NAME + + af.getName() + cmds.SPACE + cmds.HMMBUFFER + + cmds.ALIGNMENTBUFFER; + cmds.runCommand(command); } private void importData() throws IOException, InterruptedException { - af.loadJalviewDataFile(HMMERCommands.HMMBUFFER, DataSourceType.FILE, + af.loadJalviewDataFile(cmds.HMMBUFFER, DataSourceType.FILE, FileFormat.HMMER3, null); for (Map.Entry entry : hmmSeqs.entrySet()) { SequenceI seq = entry.getValue(); Integer pos = entry.getKey(); - HMMERCommands.addHMMConsensusSequence(af, seq, pos); + cmds.addHMMConsensusSequence(af, seq, pos); } af.alignPanel.alignmentChanged(); } diff --git a/src/jalview/hmmer/HMMERCommands.java b/src/jalview/hmmer/HMMERCommands.java index 54516b5..5e35ef0 100644 --- a/src/jalview/hmmer/HMMERCommands.java +++ b/src/jalview/hmmer/HMMERCommands.java @@ -17,33 +17,32 @@ import java.util.List; public class HMMERCommands { // Path of hmmer binaries directory - static String HMMERFOLDER = "/Documents/"; + String HMMERFOLDER = "/Documents/"; - static final String JALVIEWDIRECTORY = System.getProperty("user.dir") + public String JALVIEWDIRECTORY = System.getProperty("user.dir") + "/"; - static String HMMALIGN = "/hmmalign "; + public String HMMALIGN = "/hmmalign "; - static String HMMBUILD = "/hmmbuild "; + public String HMMBUILD = "/hmmbuild "; - static String HMMSEARCH = "/hmmsearch "; + public String HMMSEARCH = "/hmmsearch "; - static final String HMMBUFFER = "src/jalview/hmmer/hmm_buffer.hmm "; + public String HMMBUFFER; - static final String ALIGNMENTBUFFER = "src/jalview/hmmer/alignment_buffer.sto "; + public String ALIGNMENTBUFFER; - static final String ALIGNMENTINPUT = "src/jalview/hmmer/alignment_input.sto "; + public String ALIGNMENTINPUT; - static final String OUTPUTALIGNMENT = "-o " + JALVIEWDIRECTORY - + ALIGNMENTINPUT; + public String OUTPUTALIGNMENT; - static final String NAME = "-n "; + public String NAME = "-n "; - static final String SPACE = " "; + public String SPACE = " "; - static final String ALLCOL = "--allcol "; + public String ALLCOL = "--allcol "; - static final String TRIM = "--trim "; + public String TRIM = "--trim "; /** @@ -53,7 +52,7 @@ public class HMMERCommands * @throws IOException * @throws InterruptedException */ - public static void runCommand(String command) + public void runCommand(String command) throws IOException, InterruptedException { final Process p = Runtime.getRuntime().exec(command); @@ -89,7 +88,7 @@ public class HMMERCommands * @param alignment * @throws IOException */ - public static void exportData(AlignmentI alignment, + public void exportData(AlignmentI alignment, boolean exportAlignment, boolean exportHMM, HiddenMarkovModel hmm) throws IOException { @@ -117,7 +116,7 @@ public class HMMERCommands } } - public static void addHMMConsensusSequence(AlignFrame af, SequenceI seq, + public void addHMMConsensusSequence(AlignFrame af, SequenceI seq, Integer position) { seq.getHMM().initHMMSequence(af, position);