/* PAUPConsensusTrees actor calls PAUP for finding consensus trees. * * Copyright (c) 2004 The Regents of the University of California. * All rights reserved. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the * above copyright notice and the following two paragraphs appear in * all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN * IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY * OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * PT_COPYRIGHT_VERSION_2 * COPYRIGHTENDKEY */ package org.cipres.kepler; import java.io.File; import ptolemy.kernel.CompositeEntity; import ptolemy.kernel.util.*; import ptolemy.data.IntToken; import ptolemy.data.BooleanToken; import ptolemy.data.StringToken; import ptolemy.data.expr.Parameter; import org.cipres.helpers.GUIRun; import org.cipres.kepler.registry.ActorInfo; import org.cipres.kepler.registry.CipresKeplerRegistry; import org.cipres.kepler.registry.Globals; import org.cipres.util.CipresFile; ////////////////////////////////////////////////////////////////////////// ////PAUPConsensusTrees /** * This actor calls PAUP to find consensus trees for a group of trees. * * @author Zhijie Guan, Alex Borchers * @version $Id: $ */ public class PAUPConsensusTrees extends GUIRunCIPRes { // TODO: assign a proper hash value to this static final long serialVersionUID = 1L; /** Construct PAUPConsensusTrees source with the given container and name. * @param container The container. * @param name The name of this actor. * @exception IllegalActionException If the entity cannot be contained * by the proposed container. * @exception NameDuplicationException If the container already has an * actor with this name. */ public PAUPConsensusTrees(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException { super(container, name); // get program information CipresKeplerRegistry registry = Globals.getInstance().getRegistry(); _paupActor = registry.getActor("ConsensusTree_Paup"); // set program related information command.setToken( new StringToken(_paupActor.getAppPath()) ); uiXMLFile.setToken( new StringToken(_paupActor.getGuiXmlFile()) ); outputFile.setToken( new StringToken(registry.getDefaultStdOutDir() + "PAUPConsensusOut.log") ); errorFile.setToken( new StringToken(registry.getDefaultStdOutDir() + "PAUPConsensusError.log") ); workingDirectory.setToken( new StringToken(_paupActor.getWorkingDir()) ); parameterForOutput.setToken( new StringToken("outfile") ); paupCmdFile = new Parameter(this, "paupCmdFile", new StringToken("")); paupCmdFile.setToken(new StringToken(registry.getDefaultStdOutDir() + "paup_consensus_cmds.nex")); paupCmdFile.setDisplayName("PAUP Command File Name"); paupCmdFile.setVisibility(Settable.EXPERT); // set ports "importance" inputParameterName.setRequired(true); inputParameterValue.setRequired(true); outputParameterValue.setUseful(true); // set inputParameterName, inputParameterName and names display new Parameter(inputParameterName, "_showName", BooleanToken.TRUE); new Parameter(inputParameterValue, "_showName", BooleanToken.TRUE); new Parameter(outputParameterValue, "_showName", BooleanToken.TRUE); } /////////////////////////////////////////////////////////////////// //// ports and parameters //// /** The parameter for PAUP command file. This parameter will be set to String. */ public Parameter paupCmdFile; /////////////////////////////////////////////////////////////////// //// functional variables //// /////////////////////////////////////////////////////////////////// //// public methods //// /** Run PAUP for finding consensus trees. * @exception IllegalActionException If it is thrown by the * send() method sending out the token. */ public void fire() throws IllegalActionException { if ( inputParameterValue.hasToken(0) && inputParameterName.hasToken(0) ) { try { GUIRun grun = new GUIRun("PAUP Consensus Trees"); grun.setUseShell(true); // if (command.hasToken(0)) { grun.setExecutable( ((StringToken)command.getToken()).stringValue() ); // } // if (uiXMLFile.hasToken(0)) { grun.setUIXMLFile( ((StringToken)uiXMLFile.getToken()).stringValue() ); // } // if (outputFile.hasToken(0)) { grun.setOutputFilename( ((StringToken)outputFile.getToken()).stringValue() ); // } // if (errorFile.hasToken(0)) { grun.setErrorFilename( ((StringToken)errorFile.getToken()).stringValue() ); // } // if (workingDirectory.hasToken(0)) { grun.setWorkingDirPath( ((StringToken)workingDirectory.getToken()).stringValue() ); // } grun.setArgumentValue( ((StringToken)inputParameterName.get(0)).stringValue(), ((StringToken)inputParameterValue.get(0)).stringValue() ); grun.setArgumentsWithGUIGen(); // outfile is the file that user assigned for PAUP output // infile is the file that user assigned for PAUP input File outfile = new File(grun.getArgumentValue("outfile")); File infile = new File(grun.getArgumentValue("infile")); //this command has paup: //1. import input and write to output //2. execute contree and append trees to output final StringBuilder commands = new StringBuilder(); commands.append("EXECUTE "); commands.append(infile.getAbsolutePath()); commands.append("; EXPORT File="); commands.append(outfile.getAbsolutePath()); commands.append(" FORMAT = NEXUS TREES=NO REPLACE=YES; CLEARTREES NOWARN=YES; SET WARNRESET=NO; "); final String[] grunArgs = grun.getArguments(); for (int i = 0 ; i < grunArgs.length ; i++) { commands.append(" "); commands.append(grunArgs[i]); } commands.append(" TreeFile ="); commands.append(outfile.getAbsolutePath()); commands.append(" APPEND=YES;"); String[] paupCmdFileName = { ((StringToken)paupCmdFile.getToken()).stringValue() }; CipresFile cmdFile = new CipresFile(paupCmdFileName[0]); cmdFile.fillFromString("#NEXUS\nBEGIN PAUP;\n" + commands.toString() + " QUIT;\nEND;"); grun.setArguments(paupCmdFileName); grun.setWaitForExecution(true); grun.execute(); exitCode.send(0, new IntToken(grun.getExitCode())); standardOutput.send(0, new StringToken(grun.getStandardOutput())); standardError.send(0, new StringToken(grun.getStandardError())); outputParameterValue.send(0, new StringToken( grun.getArgumentValue( ((StringToken)parameterForOutput.getToken()).stringValue() ) ) ); } catch (Exception e) { e.printStackTrace(); } } } /** Post fire the actor. Return false to indicated that the * process has finished. If it returns true, the process will * continue indefinitely. */ public boolean postfire() { return false; } /** private variables * _paupActor records program information for PAUP. */ private ActorInfo _paupActor; }