Search in sources :

Example 1 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class JSONProducer method toJSON.

public String toJSON(BEASTInterface beastObject, Collection<BEASTInterface> others) {
    try {
        StringBuffer buf = new StringBuffer();
        // buf.append("{\"version\": \"2.0\",\n\"namespace\": \"" + DEFAULT_NAMESPACE + "\",\n\n" +
        // "\"" + JSONParser.ANALYSIS_ELEMENT + "\": [\n");
        buf.append("{version: \"" + (new BEASTVersion2()).getMajorVersion() + "\",\nnamespace: \"" + DEFAULT_NAMESPACE + "\",\n\n" + XMLParser.BEAST_ELEMENT + ": [\n");
        // buf.append("\n\n");
        isDone = new HashSet<>();
        isInputsDone = new HashMap<>();
        IDs = new HashSet<>();
        indentCount = 1;
        List<BEASTInterface> priorityBeastObjects = new ArrayList<>();
        findPriorityBeastObjects(beastObject, priorityBeastObjects);
        for (BEASTInterface beastObject2 : priorityBeastObjects) {
            if (!isDone.contains(beastObject2)) {
                // name = name.substring(name.lastIndexOf('.') + 1).toLowerCase();
                beastObjectToJSON(beastObject2, BEASTInterface.class, buf, null, true);
                buf.append(",");
            }
        }
        buf.append("\n\n");
        beastObjectToJSON(beastObject, BEASTInterface.class, buf, null, true);
        String end = "\n]\n}";
        buf.append(end);
        String JSON = buf.toString();
        String[] nameSpaces = DEFAULT_NAMESPACE.split(":");
        for (String nameSpace : nameSpaces) {
            // JSON = JSON.replaceAll("\"spec\": \"" + nameSpace + ".", "\"spec\": \"");
            JSON = JSON.replaceAll("spec: \"" + nameSpace + ".", "spec: \"");
        }
        return JSON;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface) BEASTVersion2(beast.app.BEASTVersion2) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 2 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class LogComparator method main.

/**
 * main
 */
public static void main(String[] args) {
    LogAnalyser analyser1 = null;
    LogAnalyser analyser2 = null;
    try {
        if (args.length == 0) {
            BEASTVersion2 version = new BEASTVersion2();
            File file = Utils.getLoadFile("LogComparator " + version.getVersionString() + " - Select first log file to analyse", null, "BEAST log (*.log) Files", "log", "txt");
            if (file == null) {
                return;
            }
            analyser1 = new LogAnalyser(file.getAbsolutePath());
            file = Utils.getLoadFile("LogComparator " + version.getVersionString() + " - Select second log file to analyse", null, "BEAST log (*.log) Files", "log", "txt");
            if (file == null) {
                return;
            }
            analyser2 = new LogAnalyser(file.getAbsolutePath());
        } else {
            analyser1 = new LogAnalyser(args[0]);
            analyser2 = new LogAnalyser(args[1]);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    LogComparator logComparator = new LogComparator(analyser1, analyser2);
    logComparator.print(System.out, true);
}
Also used : File(java.io.File) BEASTVersion2(beast.app.BEASTVersion2)

Example 3 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class XMLProducer method toXML.

public String toXML(BEASTInterface beastObject, Collection<BEASTInterface> others) {
    try {
        StringBuffer buf = new StringBuffer();
        Set<String> requiredPacakges = getPackagesAndVersions(beastObject);
        String required = requiredPacakges.toString();
        required = required.substring(1, required.length() - 1);
        required = required.replaceAll(", ", ":");
        buf.append("<" + XMLParser.BEAST_ELEMENT + " version='" + new BEASTVersion2().getMajorVersion() + "'" + " required='" + required + "'" + " namespace='" + DEFAULT_NAMESPACE + "'>\n");
        for (String element : element2ClassMap.keySet()) {
            if (!reservedElements.contains(element)) {
                buf.append("<map name='" + element + "'>" + element2ClassMap.get(element) + "</map>\n");
            }
        }
        buf.append("\n\n");
        isDone = new HashSet<>();
        isInputsDone = new HashMap<>();
        IDs = new HashSet<>();
        indent = 0;
        beastObjectToXML(beastObject, buf, null, true);
        String endBeastString = "</" + XMLParser.BEAST_ELEMENT + ">";
        buf.append(endBeastString);
        // return buf.toString();
        // beautify XML hierarchy
        String xml = cleanUpXML(buf.toString(), m_sXMLBeuatifyXSL);
        // TODO: fix m_sIDRefReplacementXSL script to deal with nested taxon sets
        // String xml2 = cleanUpXML(xml, m_sIDRefReplacementXSL);
        String xml2 = xml;
        xml = findPlates(xml2);
        // beatify by applying name spaces to spec attributes
        String[] nameSpaces = DEFAULT_NAMESPACE.split(":");
        for (String nameSpace : nameSpaces) {
            xml = xml.replaceAll("spec=\"" + nameSpace + ".", "spec=\"");
        }
        buf = new StringBuffer();
        if (others.size() > 0) {
            for (BEASTInterface beastObject2 : others) {
                if (!IDs.contains(beastObject2.getID())) {
                    beastObjectToXML(beastObject2, buf, null, false);
                }
            }
        }
        int endIndex = xml.indexOf(endBeastString);
        String extras = buf.toString();
        // prevent double -- inside XML comment, this can happen in sequences
        extras = extras.replaceAll("--", "- - ");
        xml = // + "\n\n<!-- " + DO_NOT_EDIT_WARNING + " \n\n" +
        xml.substring(0, endIndex) + // extras +  "\n\n-->\n\n"
        endBeastString;
        xml = xml.replaceAll("xmlns=\"http://www.w3.org/TR/xhtml1/strict\"", "");
        xml = dedupName(xml);
        xml = sortTags(xml);
        // return buf2.toString();
        return xml;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BEASTInterface(beast.core.BEASTInterface) BEASTVersion2(beast.app.BEASTVersion2) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 4 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class Beauti method main2.

public static Beauti main2(String[] args) {
    Utils6.startSplashScreen();
    Utils6.logToSplashScreen("Initialising BEAUti");
    try {
        ByteArrayOutputStream baos = null;
        for (String arg : args) {
            if (arg.equals("-v") || arg.equals("-version")) {
                System.out.println((new BEASTVersion2()).getVersionString());
                System.exit(0);
            }
            if (arg.equals("-h") || arg.equals("-help")) {
                System.out.println(usage());
                System.exit(0);
            }
            if (arg.equals("-capture")) {
                final PrintStream beautiLog = System.err;
                baos = new ByteArrayOutputStream() {

                    @Override
                    public synchronized void write(byte[] b, int off, int len) {
                        super.write(b, off, len);
                        beautiLog.write(b, off, len);
                    }

                    @Override
                    public synchronized void write(int b) {
                        super.write(b);
                        beautiLog.write(b);
                    }

                    @Override
                    public void write(byte[] b) throws java.io.IOException {
                        super.write(b);
                        beautiLog.write(b);
                    }

                    @Override
                    public void flush() throws java.io.IOException {
                        super.flush();
                        beautiLog.flush();
                    }

                    @Override
                    public void close() throws IOException {
                        super.close();
                        beautiLog.close();
                    }
                };
                PrintStream p = new PrintStream(baos);
                System.setOut(p);
                System.setErr(p);
                Log.err = p;
                Log.warning = p;
                Log.info = p;
                Log.debug = p;
                Log.trace = p;
            }
        }
        PackageManager.loadExternalJars();
        // if (!Utils.isMac()) {
        Utils.loadUIManager();
        // }
        BEASTObjectPanel.init();
        BeautiDoc doc = new BeautiDoc();
        BeautiDoc.baos = baos;
        if (doc.parseArgs(args) == ActionOnExit.WRITE_XML) {
            return null;
        }
        final Beauti beauti = new Beauti(doc);
        if (Utils.isMac() && Utils6.getMajorJavaVersion() == 8) {
            // Mac-only stuff
            try {
                URL url = ClassLoader.getSystemResource(ModelBuilder.ICONPATH + "beauti.png");
                Icon icon = null;
                if (url != null) {
                    icon = new ImageIcon(url);
                } else {
                    Log.warning.println("Unable to find image: " + ModelBuilder.ICONPATH + "beauti.png");
                }
                jam.framework.Application application = new jam.framework.MultiDocApplication(null, "BEAUti", "about", icon) {

                    @Override
                    protected JFrame getDefaultFrame() {
                        return null;
                    }

                    @Override
                    public void doQuit() {
                        beauti.a_quit.actionPerformed(null);
                    }

                    @Override
                    public void doAbout() {
                        beauti.a_about.actionPerformed(null);
                    }

                    @Override
                    public DocumentFrame doOpenFile(File file) {
                        return null;
                    }

                    @Override
                    public DocumentFrame doNew() {
                        return null;
                    }
                };
                jam.mac.Utils.macOSXRegistration(application);
            } catch (Exception e) {
            // ignore
            }
            try {
                Class<?> class_ = Class.forName("jam.maconly.OSXAdapter");
                Method method = class_.getMethod("enablePrefs", boolean.class);
                method.invoke(null, false);
            } catch (java.lang.NoSuchMethodException e) {
            // ignore
            }
        }
        beauti.setUpPanels();
        beauti.currentTab = beauti.panels[0];
        beauti.hidePanels();
        beauti.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (beauti.currentTab == null) {
                    beauti.currentTab = beauti.panels[0];
                }
                if (beauti.currentTab != null) {
                    if (!beauti.isInitialising) {
                        beauti.currentTab.config.sync(beauti.currentTab.partitionIndex);
                    }
                    BeautiPanel panel = (BeautiPanel) beauti.getSelectedComponent();
                    beauti.currentTab = panel;
                    beauti.refreshPanel();
                }
            }
        });
        beauti.setVisible(true);
        beauti.refreshPanel();
        JFrame frame = new JFrame("BEAUti 2: " + doc.getTemplateName() + " " + doc.getFileName());
        beauti.frame = frame;
        ImageIcon icon = Utils.getIcon(BEAUTI_ICON);
        if (icon != null) {
            frame.setIconImage(icon.getImage());
        }
        JMenuBar menuBar = beauti.makeMenuBar();
        frame.setJMenuBar(menuBar);
        if (doc.getFileName() != null || doc.alignments.size() > 0) {
            beauti.a_save.setEnabled(true);
            beauti.a_saveas.setEnabled(true);
        }
        frame.add(beauti);
        int size = UIManager.getFont("Label.font").getSize();
        frame.setSize(1024 * size / 13, 768 * size / 13);
        frame.setLocation(BEAUtiIntances * 10, BEAUtiIntances * 10);
        frame.setVisible(true);
        // check file needs to be save on closing main frame
        frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        BEAUtiIntances++;
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                if (!beauti.quit()) {
                    return;
                }
                JFrame frame = (JFrame) e.getSource();
                frame.dispose();
                BEAUtiIntances--;
                if (BEAUtiIntances == 0) {
                    System.exit(0);
                }
            }
        });
        // Toolkit toolkit = Toolkit.getDefaultToolkit();
        // // PropertyChangeListener plistener = new
        // PropertyChangeListener() {
        // // @Override
        // // public void propertyChange(PropertyChangeEvent event) {
        // // Object o = event.getSource();
        // // Object o2 = event.getNewValue();
        // // event.getPropertyName();
        // // System.err.println(">>> " + event.getPropertyName() + " " +
        // o.getClass().getName() + "\n" + o2.getClass().getName());
        // // }
        // // };
        // AWTEventListener listener = new AWTEventListener() {
        // @Override
        // public void eventDispatched(AWTEvent event) {
        // Object o = event.getSource();
        // String label = "";
        // try {
        // Method method = o.getClass().getMethod("getText", Object.class);
        // label = (String) method.invoke(o);
        // } catch (Exception e) {
        // // TODO: handle exception
        // }
        // if (event.paramString().matches(".*\\([0-9]*,[0-9]*\\).*")) {
        // String s = event.paramString();
        // String sx = s.substring(s.indexOf('(') + 1);
        // String sy = sx;
        // sx = sx.substring(0, sx.indexOf(','));
        // sy = sy.substring(sy.indexOf(',') + 1, sy.indexOf(')'));
        // int x = Integer.parseInt(sx);
        // int y = Integer.parseInt(sy);
        // Component c = beauti.findComponentAt(x, y);
        // if (c != null) {
        // System.err.println(c.getClass().getName());
        // }
        // }
        // 
        // System.err.println(label + " " + event.paramString() + " " +
        // o.getClass().getName());
        // 
        // }
        // };
        // toolkit.addAWTEventListener(listener,
        // AWTEvent.ACTION_EVENT_MASK|AWTEvent.ITEM_EVENT_MASK|AWTEvent.MOUSE_EVENT_MASK);
        // // beauti.addPropertyChangeListener(plistener);
        Utils6.endSplashScreen();
        return beauti;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ImageIcon(javax.swing.ImageIcon) WindowAdapter(java.awt.event.WindowAdapter) URL(java.net.URL) JFrame(javax.swing.JFrame) ChangeListener(javax.swing.event.ChangeListener) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ChangeEvent(javax.swing.event.ChangeEvent) WindowEvent(java.awt.event.WindowEvent) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) File(java.io.File) BEASTVersion2(beast.app.BEASTVersion2) JMenuBar(javax.swing.JMenuBar)

Example 5 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class EBSPAnalyser method main.

/**
 * @param args
 */
public static void main(String[] args) {
    BEASTVersion2 version = new BEASTVersion2();
    final String versionString = version.getVersionString();
    String nameString = "EBSP Analyser " + versionString;
    String aboutString = "<html><center><p>" + versionString + ", " + version.getDateString() + "</p>" + "<p>by<br>" + "<p>Joseph Heled and Remco Bouckaert</p>" + "<p>Department of Computer Science, University of Auckland<br>" + "<a href=\"mailto:jheled@gmail.com\">jheled@gmail.com</a></p>" + "<a href=\"mailto:remco@cs.auckland.ac.nz\">remco@cs.auckland.ac.nz</a></p>" + "<p>Part of the BEAST 2 package:<br>" + "<a href=\"http://beast2.cs.auckland.ac.nz/\">http://beast2.cs.auckland.ac.nz/</a></p>" + "</center></html>";
    try {
        EBSPAnalyser analyser = new EBSPAnalyser();
        if (args.length == 0) {
            Utils.loadUIManager();
            System.setProperty("com.apple.macos.useScreenMenuBar", "true");
            System.setProperty("apple.laf.useScreenMenuBar", "true");
            System.setProperty("apple.awt.showGrowBox", "true");
            // TODO: set up ICON
            java.net.URL url = EBSPAnalyser.class.getResource("images/EBSPAnalyser.png");
            javax.swing.Icon icon = null;
            if (url != null) {
                icon = new javax.swing.ImageIcon(url);
            }
            // ConsoleApplication consoleApp =
            new ConsoleApplication(nameString, aboutString, icon, true);
            analyser.printTitle(aboutString);
            String titleString = "<html><center><p>EBSPAnalyser<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p></center></html>";
            EBSPAnalyserDialog dialog = analyser.new EBSPAnalyserDialog(new JFrame(), titleString, icon);
            if (!dialog.showDialog(nameString)) {
                return;
            }
            String[] args2 = dialog.getArgs();
            try {
                analyser.parseArgs(args2);
                analyser.run();
            } catch (Exception ex) {
                Log.err.println("Exception: " + ex.getMessage());
                ex.printStackTrace();
            }
            System.out.println("Finished - Quit program to exit.");
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } else {
            analyser.printTitle(aboutString);
            analyser.parseArgs(args);
            analyser.run();
        }
    } catch (Exception e) {
        System.out.println(getUsage());
        e.printStackTrace();
    }
}
Also used : Icon(javax.swing.Icon) IOException(java.io.IOException) ConsoleApplication(jam.console.ConsoleApplication) JFrame(javax.swing.JFrame) BEASTVersion2(beast.app.BEASTVersion2)

Aggregations

BEASTVersion2 (beast.app.BEASTVersion2)8 IOException (java.io.IOException)7 File (java.io.File)4 JFrame (javax.swing.JFrame)4 ArrayList (java.util.ArrayList)3 BEASTInterface (beast.core.BEASTInterface)2 ConsoleApplication (jam.console.ConsoleApplication)2 PrintStream (java.io.PrintStream)2 Icon (javax.swing.Icon)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 BeastMCMC (beast.app.BeastMCMC)1 Arguments (beast.app.util.Arguments)1 XMLParserException (beast.util.XMLParserException)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1