package org.cipres.kepler.sandbox; import java.io.*; import javax.swing.JOptionPane; import org.cipres.kepler.registry.*; import org.cipres.CipresIDL.api1.MatrixAlign; import org.cipres.guigen.ServiceCommandPanel; import org.cipres.helpers.CipresServiceDialog; import org.cipres.helpers.RegistryEntryWrapper; public class KeplerTest { public final static String SEP = System.getProperty("file.separator"); //THE FOLLOWING WILL BE DEDUCED WHEN USER SELECTS ACTOR public final static String CLUSTAL_ACTOR_NAME = "SequenceAlign_Clustal"; public final static String INFER_TREE_PARS_PAUP = "InferTreeByParsimony_Paup"; public final static String CONSENSUS_TREE_PAUP = "ConsensusTree_Paup"; //THESE ARE SET FOR CONVENIENCE FOR TESTING BUT WILL EVENTUALLY BE GENERATED //AUTOMATICALLY BY APPLICATION public final static String HOME_DIR = System.getProperty("user.home") + SEP; public final static String TEMP_DIR = HOME_DIR + "temp" + SEP; public final static String PAUP_NEXUS_OUT = TEMP_DIR + "paup_output.nex"; public final static String NEXUS_SUBSET_TAXA_OUT = TEMP_DIR + "subsetter_taxa_output.nex"; public final static String NEXUS_SUBSET_TREES_OUT = TEMP_DIR + "subsetter_trees_output.nex"; public final static String PAUP_CMD_FILE = TEMP_DIR + "paup_cmds.nex"; public final static String PAUP_TREES_OUT = TEMP_DIR + "paup_trees.nex"; //public final static String CLUSTAL_FASTA_IN = FILES_DIR + "zfish_nt_12T.fasta"; //public final static String CLUSTAL_FASTA_IN = FILES_DIR + "globin.pep"; public final static String CLUSTAL_NEXUS_OUT = TEMP_DIR + "clustal_output.nex"; public final static String PROTEIN_NEXUS = TEMP_DIR + "protein.nex"; public final static String NEXUS_TO_PHYLIP = TEMP_DIR + "NexusToPhylip.phylip"; public final static String PHYLIP_TO_NEXUS = TEMP_DIR + "PhylipToNexus.nex"; public final static String CONTREE_OUTPUT = TEMP_DIR + "ConTreesNexus.nex"; public static String TEST_NEXUS; public static void main(String[] args) { try { CipresKeplerRegistry reg = Globals.getInstance().getRegistry(); ServiceRunner serviceRunner = new ServiceRunner(); //for testing fasta->clustal->subsetter->TreeInfer->ConTree->NexToPhylip->PhylipToNex if(args[0].equalsIgnoreCase("0")){ //run Clustal on fasta file File clustalNexFileOutput = new File(CLUSTAL_NEXUS_OUT); String clustalFastaInput = Globals.getInstance().getSampleFilesDir() + "zfish_nt_12T.fasta"; clustalNexFileOutput = serviceRunner.runClustal(clustalFastaInput, CLUSTAL_NEXUS_OUT); //take clustal output and send to Subsetter File nexSubsetterOutput = new File(NEXUS_SUBSET_TAXA_OUT); nexSubsetterOutput = serviceRunner.subsetNexusByTaxa(clustalNexFileOutput, new File(NEXUS_SUBSET_TAXA_OUT)); //Take subset nexus file and send to paup for tree inference File paupInferNexFileOutput = serviceRunner.runPaupInfer( nexSubsetterOutput, new File(PAUP_NEXUS_OUT), null); //Take inference output trees and send to tree Subsetter //Can't use this until bug in ReadNexusServer is fixed File treeSubsetterOutput = new File(NEXUS_SUBSET_TREES_OUT); treeSubsetterOutput = serviceRunner.subsetTrees(paupInferNexFileOutput,treeSubsetterOutput); //Take tree Subsetter output and create consensus tree(s) File paupContreeNexFileOutput = serviceRunner.runPaupConsensusTrees( paupInferNexFileOutput, new File(CONTREE_OUTPUT)); paupContreeNexFileOutput.getAbsoluteFile(); //translate paup output to phylip File NexToPhylip = PhyloFileUtils.NexusToPhylip(paupContreeNexFileOutput, NEXUS_TO_PHYLIP); //translate the phylip back to paup PhyloFileUtils.PhylipToNexus(NexToPhylip, PHYLIP_TO_NEXUS); System.exit(0); } // for testing ActorIterator if(args[0].equalsIgnoreCase("1")){ ActorInfo actor = reg.getActor(INFER_TREE_PARS_PAUP); ActorIterator actorIterator = new ActorIterator( new File(actor.getGuiXmlFile())); File nexusIn = new File(Globals.getInstance().getSampleFilesDir() + "TestNexusFile.nex"); actorIterator.setParameterValueInAll("infile",nexusIn.getAbsolutePath()); actorIterator.setOutfileParamInAll(actor.getActorName()); actorIterator.setVisible(true); ServiceCommandPanel[] pnls = actorIterator.getServiceCommandPanels(); if(pnls!=null) { //null returned if user clicks 'Cancel' //run paup_infer on each set of commands and send to forester to viz tree(s) File paupInferNexFileOutput; for (int i = 0; i < pnls.length; i++) { paupInferNexFileOutput = serviceRunner.runPaupInfer( new File(pnls[i].getParameterValue("infile")), new File(pnls[i].getParameterValue("outfile")), pnls[i].getCmdBlock()); serviceRunner.showTreeForester(paupInferNexFileOutput); } } System.exit(0); } //for testing registry editor if(args[0].equalsIgnoreCase("2")){ //Print out current default InputFileDir System.out.println("InputFileDir = " + reg.getDefaultInputFileDir()); //edit and get edited registry reg = CipresKeplerRegistry.EditRegistry(); //Print out the default stdOutDir from the edited registry System.out.println("InputFileDir = " + reg.getDefaultInputFileDir()); System.exit(0); } //for testing TreeViz if(args[0].equalsIgnoreCase("3")){ File f = new File(Globals.getInstance().getSampleFilesDir() + "TestNexusFile.nex"); serviceRunner.showTreeForester(f); //System.exit(0); } //for testing Seaview if(args[0].equalsIgnoreCase("4")){ File f = new File(Globals.getInstance().getSampleFilesDir() + "TestNexusFile.nex"); serviceRunner.editAlignment_Seaview(f); //System.exit(0); } if (args[0].equalsIgnoreCase("5")) { RegistryEntryWrapper clustalWrapper = null; try { // get RecIDCM3 algorithm wrapper clustalWrapper = Globals.getInstance().getRegistry().getCipresService(MatrixAlign.class); // use GuiGen to get users' settings CipresServiceDialog dialog = clustalWrapper .getServiceDialog(null); //int status = dialog.showAndInitialize(); int status = dialog.show(); if (status == CipresServiceDialog.OK) { String cmds = dialog.getPanel().getCmdBlock(); MatrixAlign service = (MatrixAlign) clustalWrapper .getService(); // set the tree and matrix into the CORBA service org.omg.CORBA.StringHolder reply = new org.omg.CORBA.StringHolder(); boolean executeSucceeded = false; service.getScore(); executeSucceeded = service.execute(cmds, reply); System.out.println(executeSucceeded); } else if (status == CipresServiceDialog.ERROR) { JOptionPane.showMessageDialog(null, "error initializing service"); } } catch (Exception e) { e.printStackTrace(); } finally { if (clustalWrapper != null) { // release the RecIDCM3 service clustalWrapper.releaseService(); } System.exit(0); } } } catch (Exception e) { e.printStackTrace(); } finally { //System.exit(0); } } }