001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.cipres.kepler; 031 032import org.cipres.kepler.registry.ActorInfo; 033import org.cipres.kepler.registry.CipresKeplerRegistry; 034import org.cipres.kepler.registry.Globals; 035 036import ptolemy.actor.TypedIOPort; 037import ptolemy.data.StringToken; 038import ptolemy.data.type.BaseType; 039import ptolemy.kernel.CompositeEntity; 040import ptolemy.kernel.util.IllegalActionException; 041import ptolemy.kernel.util.NameDuplicationException; 042 043////////////////////////////////////////////////////////////////////////// 044////AlignmentEditor_Seaview 045/** 046 * Given an alignment, the AlignmentEditor_Seaview actor displays the alignment 047 * in the seaview window and facititates the user to edit the alignment. Note1: 048 * since Seaview is an application running as another process with GUI, the 049 * actor cannot monitor the execution of Seaview. Thus the actor cannot know 050 * when the user finishes the work and closes the Seaview window. Note2: Here we 051 * assume the user will save the output file with the same name as the input 052 * file. We will change it to let the user input the output file name in the 053 * future. 054 * 055 * @author Zhijie Guan, Alex Borchers 056 * @version $Id: AlignmentEditor_Seaview.java 24234 2010-05-06 05:21:26Z welker $ 057 */ 058 059public class AlignmentEditor_Seaview extends JRunCIPRes { 060 061 /** 062 * Construct a AlignmentEditor_Seaview actor with the given container and 063 * name. 064 * 065 * @param container 066 * The container. 067 * @param name 068 * The name of this actor. 069 * @exception IllegalActionException 070 * If the entity cannot be contained by the proposed 071 * container. 072 * @exception NameDuplicationException 073 * If the container already has an actor with this name. 074 */ 075 076 public AlignmentEditor_Seaview(CompositeEntity container, String name) 077 throws NameDuplicationException, IllegalActionException { 078 super(container, name); 079 080 // get the information of Seaview application 081 CipresKeplerRegistry registry = Globals.getInstance().getRegistry(); 082 _seaviewActor = registry.getActor("AlignmentEditor_Seaview"); 083 084 // SeaView has different invocation methods in different OSs 085 // In Mac, SeaView runs by "open -a Seaview.app input_file_name" 086 // In all the other OS, SeaView runs by "Seaview input_file_name" 087 if (System.getProperty("os.name").startsWith("Mac")) { 088 command.setToken(new StringToken("open -a " 089 + _seaviewActor.getAppPathForOS())); 090 } else { 091 command.setToken(new StringToken(_seaviewActor.getAppPathForOS())); 092 } 093 094 // set the standard output file 095 outputFile.setToken(new StringToken(registry.getDefaultStdOutDir() 096 + "SeaviewOut.log")); 097 098 // set the stardard error file 099 errorFile.setToken(new StringToken(registry.getDefaultStdOutDir() 100 + "SeaviewError.log")); 101 102 // set the working directory 103 workingDirectory.setToken(new StringToken(_seaviewActor 104 .getWorkingDirecotry())); 105 106 // initialize the port for getting in the input file name 107 inputFileName = new TypedIOPort(this, "inputFileName", true, false); 108 inputFileName.setDisplayName("Input File Name"); 109 inputFileName.setTypeEquals(BaseType.STRING); 110 111 // initialize the port for sending out the output file name 112 outputFileName = new TypedIOPort(this, "outputFileName", false, true); 113 outputFileName.setDisplayName("Output File Name"); 114 outputFileName.setTypeEquals(BaseType.STRING); 115 116 } 117 118 // ///////////////////////////////////////////////////////////////// 119 // // ports and parameters //// 120 121 /** 122 * The input file name is transferred into the actor through this port. The 123 * input file contains the alignment for reviewing and editing. 124 */ 125 public TypedIOPort inputFileName; 126 127 /** 128 * The output file name is sent out throught this port. The output file 129 * contains the edited alignment. 130 */ 131 public TypedIOPort outputFileName; 132 133 // ///////////////////////////////////////////////////////////////// 134 // // functional variables //// 135 136 // ///////////////////////////////////////////////////////////////// 137 // // public methods //// 138 139 /** 140 * Run seaview for alignment reviw and manipulation. 141 * 142 * @exception IllegalActionException 143 * If it is thrown by the send() method sending out the 144 * token. 145 */ 146 public void fire() throws IllegalActionException { 147 148 // get the input file name and send it to JRun object as the command 149 // argument 150 StringToken inputFileNameToken = (StringToken) inputFileName.get(0); 151 arguments.setToken(inputFileNameToken); 152 153 super.fire(); 154 155 // the output file name must be the same as the input file name 156 // currently we don't support the function that an user can save the 157 // result to another file 158 outputFileName.send(0, inputFileNameToken); 159 } 160 161 /** 162 * Post fire the actor. Return false to indicated that the process has 163 * finished. If it returns true, the process will continue indefinitely. 164 */ 165 // Note here we want to let this actor be able to run multiple times to view 166 // and edit 167 // multiple different alignments. 168 /* 169 * public boolean postfire() { return false; } 170 */ 171 172 /** 173 * private variables This is the ActorInfo object which comes from the 174 * Cipres-kepler registry and records all the appliation information for 175 * Seaview. 176 */ 177 private ActorInfo _seaviewActor; 178 179}