Search in sources :

Example 1 with ArgsParseException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.main.ArgsParseException in project clusterMaker2 by RBVI.

the class TransClust method main.

/**
 * The main method for the TransClust program. Starts the program
 * appropriately.
 * @param args The input variables.
 */
public static void main(String[] args) {
    TransClust.args = args;
    /* initialise logging */
    Logger logger = Logger.getLogger("");
    Handler[] handler = logger.getHandlers();
    for (Handler h : handler) {
        if (h instanceof ConsoleHandler) {
            h.setLevel(Level.INFO);
            h.setFormatter(new ConsoleFormatter());
            h.setFilter(new UniqueFilter());
        }
    }
    /* check if no input is given */
    if (args.length == 0) {
        log.severe("ERROR: Please define at least an input file/directory and an " + "output file for the results. Use -help for more details or see the " + "respective documentation.\n\n");
        System.out.println(ArgsUtility.createUsage().toString());
        System.exit(-1);
    }
    /* print usage */
    if ((args.length == 1) && ((args[0].trim().equalsIgnoreCase("-help")) || (args[0].trim().equalsIgnoreCase("--help")))) {
        System.out.println(ArgsUtility.createUsage().toString());
        System.exit(-1);
    } else /* start with parameters from console */
    {
        try {
            new Console(args);
        } catch (InvalidInputFileException e) {
            log.severe("ERROR: An invalid file/path name was given.");
            e.printStackTrace();
            System.exit(-1);
        } catch (ArgsParseException e) {
            log.severe(e.getMessage());
            log.severe("ERROR: please see usage details!");
            System.out.println(ArgsUtility.createUsage().toString());
        } catch (IOException e) {
        }
    }
}
Also used : ArgsParseException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ArgsParseException) ConsoleFormatter(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ConsoleFormatter) InvalidInputFileException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException) UniqueFilter(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.UniqueFilter) Console(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.Console) FileHandler(java.util.logging.FileHandler) ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) IOException(java.io.IOException) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 2 with ArgsParseException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.main.ArgsParseException in project clusterMaker2 by RBVI.

the class Console method parseArgsAndInitProgram.

/**
 * This method parses the input parameters from the console and starts the
 * program with the correct parameters and in the correct mode. At this
 * stage all input parameters are in this form: key value. Both key and
 * value contain no spaces and if the value does, then it is bounded by
 * apostrophes.
 *
 * @throws InvalidInputFileException
 * @throws ArgsParseException
 * @throws IOException
 */
private void parseArgsAndInitProgram() throws InvalidInputFileException, ArgsParseException, IOException {
    boolean inputAndOutputGiven = findAndReadConfigIfGivenAndSetMode();
    initGivenParameters();
    if (TaskConfig.gui) {
    /* start gui with previous set parameters */
    } else if (inputAndOutputGiven && !TaskConfig.gui) {
        ClusteringManagerTask manageTask = new ClusteringManagerTask();
        // run without initialising new thread.
        manageTask.run();
    } else {
        /* either input or output is missing */
        throw new ArgsParseException("Either input file/directory (-i) or output file (-o) is missing!");
    }
}
Also used : ClusteringManagerTask(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManagerTask)

Example 3 with ArgsParseException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.main.ArgsParseException in project clusterMaker2 by RBVI.

the class Console method findAndReadConfigIfGivenAndSetMode.

/**
 * Looks through the input variables to see if a config file is defined. If
 * so all parameters are read from this config file. If some do not exist, a
 * warning is given, but the program continues. It may be the case that
 * these parameters are unwanted or belong to an unused implementation. It
 * also looks if a mode was given and sets this, otherwise the default is
 * used.
 *
 * It also checks whether input AND output files/directories are given,
 * which is compulsory when starting with the console and not with the gui.
 *
 * @return boolean value if an input and an output file (both) are given.
 * @throws InvalidInputFileException
 *             If the given config class does not end in .conf.
 */
private boolean findAndReadConfigIfGivenAndSetMode() throws InvalidInputFileException, ArgsParseException {
    boolean input = false;
    boolean output = false;
    String configPath = TaskConfig.DEFAULTCONFIG;
    for (int i = 0; i < args.length; i++) {
        /* check whether an input file is given */
        if (args[i].trim().equals("-i")) {
            input = true;
            ++i;
        }
        if (args[i].trim().equals("-o")) {
            output = true;
            ++i;
        }
        /* check for mode parameter */
        if (args[i].trim().equals("-mode")) {
            String value = args[i + 1].trim();
            try {
                int md = Integer.parseInt(value);
                if (md == TaskConfig.GENERAL_TRAINING_MODE) {
                    TaskConfig.mode = TaskConfig.GENERAL_TRAINING_MODE;
                } else if (md == TaskConfig.CLUSTERING_MODE) {
                    TaskConfig.mode = TaskConfig.CLUSTERING_MODE;
                } else if (md == TaskConfig.COMPARISON_MODE) {
                    TaskConfig.mode = TaskConfig.COMPARISON_MODE;
                } else if (md == TaskConfig.HIERARICHAL_MODE) {
                    TaskConfig.mode = TaskConfig.HIERARICHAL_MODE;
                } else {
                    throw new ArgsParseException("The given mode is incorrect - it does not exist! " + md);
                }
            } catch (Exception e) {
                throw new ArgsParseException("The given mode is not an interger value: " + value);
            }
            ++i;
        }
        /* check for config parameter */
        if (args[i].trim().equals("-config")) {
            String value = args[i + 1].trim();
            if (value.endsWith(".conf")) {
                TaskConfig.useConfigFile = true;
                TaskConfig.inputConfigPath = value;
                configPath = value;
            } else {
                throw new InvalidInputFileException("An invalid config file was entered. The file must end with '.conf'. Please try again! Given file=" + value);
            }
            ++i;
        }
        /* check for if -cf parameter is set */
        if (args[i].trim().equals("-cf")) {
            TaskConfig.useConfigFile = Boolean.parseBoolean(args[i + 1].trim());
            ++i;
        }
    }
    if (TaskConfig.useConfigFile) {
        try {
            FileInputStream s = new FileInputStream(configPath);
            PropertyResourceBundle configrb = new PropertyResourceBundle(s);
            // log.debug("Using config file " + configPath);
            TaskConfig.initFromConfigFile(configrb);
            FORCEnDLayoutConfig.initFromConfigFile(configrb);
            GeometricClusteringConfig.initSLCFromConfigFile(configrb);
            GeometricClusteringConfig.initKmeansFromConfigFile(configrb);
        } catch (MissingResourceException ex) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "WARNING: Resources are missing in the given config file: " + TaskConfig.DEFAULTCONFIG + ", key=" + ex.getKey() + ". Either you have defined these parameters in the input, or the default values are used from the " + TaskConfig.DEFAULTCONFIG + ". Or these parameters do not interest you, because they belong to an unused implemtation.");
        } catch (IOException ex) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: Unable to read the given config file: " + configPath);
            System.exit(-1);
        } catch (InvalidTypeException ex) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: You have perhaps given an incorrect class name of an " + "implemtation. Please note that this is case sensitive.");
            System.exit(-1);
        }
    }
    if (input && output)
        return true;
    else
        return false;
}
Also used : InvalidInputFileException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) InvalidInputFileException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) InvalidTypeException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidTypeException) FileInputStream(java.io.FileInputStream) PropertyResourceBundle(java.util.PropertyResourceBundle) InvalidTypeException(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidTypeException)

Example 4 with ArgsParseException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.main.ArgsParseException in project clusterMaker2 by RBVI.

the class IteratorThread method calculateHierarichal.

private Hashtable<String, Hashtable<String, Boolean>> calculateHierarichal(double threshold, BufferedWriter bw, Edges es, HashMap<Integer, String> proteins2integers, HashMap<String, Integer> integers2proteins, Hashtable<String, Hashtable<String, Boolean>> clusterReference, Hashtable<String, Hashtable<String, Boolean>> clusters, Vector<String> singletons, Hashtable<Integer, Vector<Integer>> mergedNodes) throws IOException, ArgsParseException, InvalidInputFileException, InvalidTypeException {
    Vector<ConnectedComponent> connectedComponents = new Vector<ConnectedComponent>();
    if (threshold == TaskConfig.minThreshold) {
        Vector<Vector<Integer>> v = Splitter.splitIntoConnectedComponents(es, proteins2integers, (float) threshold, false);
        boolean[] already = new boolean[proteins2integers.size()];
        for (Vector<Integer> vector : v) {
            int count = 0;
            Vector<Integer> representants = new Vector<Integer>();
            for (int i = 0; i < vector.size(); i++) {
                if (!already[vector.get(i)]) {
                    representants.add(vector.get(i));
                    Vector<Integer> v2 = mergedNodes.get(vector.get(i));
                    for (int j = 0; j < v2.size(); j++) {
                        already[v2.get(j)] = true;
                    }
                    count++;
                }
            }
            ICCEdges cc2d2 = TaskConfig.ccEdgesEnum.createCCEdges(count);
            String[] ids = new String[count];
            Arrays.fill(ids, "");
            for (int i = 0; i < representants.size(); i++) {
                Vector<Integer> merged1 = mergedNodes.get(representants.get(i));
                for (int j = 0; j < merged1.size(); j++) {
                    if (j == 0)
                        ids[i] += proteins2integers.get(merged1.get(j));
                    else
                        ids[i] += "," + proteins2integers.get(merged1.get(j));
                }
                for (int j = i + 1; j < representants.size(); j++) {
                    Vector<Integer> merged2 = mergedNodes.get(representants.get(j));
                    float costs = 0;
                    for (int k = 0; k < merged1.size(); k++) {
                        for (int k2 = 0; k2 < merged2.size(); k2++) {
                            costs += (float) (InOut.getEdgeValue(merged1.get(k), merged2.get(k2), es) - threshold);
                        }
                    }
                    cc2d2.setEdgeCost(i, j, costs);
                }
            }
            ConnectedComponent cc = new ConnectedComponent(cc2d2, ids, null);
            connectedComponents.add(cc);
        }
    } else {
        boolean[] already = new boolean[proteins2integers.size()];
        for (Iterator<String> iterator = clusters.keySet().iterator(); iterator.hasNext(); ) {
            String key = iterator.next();
            Hashtable<String, Boolean> cluster = clusters.get(key);
            Vector<Integer> vector = new Vector<Integer>();
            for (Iterator<String> iter = cluster.keySet().iterator(); iter.hasNext(); ) {
                String element = iter.next();
                vector.add(integers2proteins.get(element));
            }
            int count = 0;
            Vector<Integer> representants = new Vector<Integer>();
            for (int i = 0; i < vector.size(); i++) {
                if (!already[vector.get(i)]) {
                    representants.add(vector.get(i));
                    Vector<Integer> v2 = mergedNodes.get(vector.get(i));
                    for (int j = 0; j < v2.size(); j++) {
                        already[v2.get(j)] = true;
                    }
                    count++;
                }
            }
            ICCEdges cc2d2 = TaskConfig.ccEdgesEnum.createCCEdges(count);
            String[] ids = new String[count];
            Arrays.fill(ids, "");
            for (int i = 0; i < representants.size(); i++) {
                Vector<Integer> merged1 = mergedNodes.get(representants.get(i));
                for (int j = 0; j < merged1.size(); j++) {
                    if (j == 0)
                        ids[i] += proteins2integers.get(merged1.get(j));
                    else
                        ids[i] += "," + proteins2integers.get(merged1.get(j));
                }
                for (int j = i + 1; j < representants.size(); j++) {
                    Vector<Integer> merged2 = mergedNodes.get(representants.get(j));
                    float costs = 0;
                    for (int k = 0; k < merged1.size(); k++) {
                        for (int k2 = 0; k2 < merged2.size(); k2++) {
                            costs += (float) (InOut.getEdgeValue(merged1.get(k), merged2.get(k2), es) - threshold);
                        }
                    }
                    cc2d2.setEdgeCost(i, j, costs);
                }
            }
            ConnectedComponent cc = new ConnectedComponent(cc2d2, ids, null);
            connectedComponents.add(cc);
        // String key =  iterator.next();
        // Hashtable<String, Boolean> cluster = clusters.get(key);
        // CC2DArray cc2d = new CC2DArray(cluster.size());
        // String[] ids = new String[cluster.size()];
        // int iterator_i = 0;
        // for (Iterator<String> iterator2 = cluster.keySet().iterator(); iterator2.hasNext();) {
        // String key2 = iterator2.next();
        // ids[iterator_i] = key2;
        // iterator_i++;
        // }
        // for (int i = 0; i < ids.length; i++) {
        // for (int j = i+1; j < ids.length; j++) {
        // cc2d.setEdgeCost(i, j, (float) (InOut.getEdgeValue(integers2proteins.get(ids[i]), integers2proteins.get(ids[j]), es)-threshold));
        // }
        // }
        // ConnectedComponent cc = new ConnectedComponent(cc2d,ids,null);
        // connectedComponents.add(cc);
        }
    }
    clusters = new Hashtable<String, Hashtable<String, Boolean>>();
    ClusteringManager cm = new ClusteringManager(null);
    ArrayList<Semaphore> allSemaphores = new ArrayList<Semaphore>();
    Semaphore maxThreadSemaphore = new Semaphore(TaskConfig.maxNoThreads, true);
    for (int i = 0; i < connectedComponents.size(); i++) {
        Semaphore semaphore = new Semaphore(1);
        allSemaphores.add(semaphore);
        cm.runClusteringForOneConnectedComponent(connectedComponents.get(i), null, semaphore, maxThreadSemaphore, System.currentTimeMillis());
        int[] elements2cluster = connectedComponents.get(i).getClusters();
        for (int j = 0; j < connectedComponents.get(i).getNumberOfClusters(); j++) {
            Hashtable<String, Boolean> cluster = new Hashtable<String, Boolean>();
            for (int k = 0; k < elements2cluster.length; k++) {
                if (elements2cluster[k] == j) {
                    String[] ids = connectedComponents.get(i).getObjectID(k).split(",");
                    for (int l = 0; l < ids.length; l++) {
                        cluster.put(ids[l], true);
                    }
                }
            }
            clusters.put(new Random().nextDouble() + "", cluster);
        }
    }
    /* wait for all clustering tasks to finish */
    for (Semaphore s : allSemaphores) {
        try {
            s.acquire();
        } catch (InterruptedException e) {
            TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
        // e.printStackTrace();
        }
    }
    bw.write(threshold + "\t");
    if (clusterReference != null) {
        double fmeasure = Fmeassure.fMeassure(clusterReference, clusters);
        bw.write(fmeasure + "\t");
        TaskConfig.monitor.setStatusMessage("fmeasure: " + fmeasure);
    } else {
        bw.write("-\t");
    }
    int[] distribution = new int[1000000];
    int max = 1;
    boolean first = true;
    Vector<String> keysToRemove = new Vector<String>();
    for (Iterator<String> iterator = clusters.keySet().iterator(); iterator.hasNext(); ) {
        String key = iterator.next();
        Hashtable<String, Boolean> h = clusters.get(key);
        if (!first)
            bw.write(";");
        if (h.size() == 1) {
            singletons.add(h.keySet().iterator().next());
            keysToRemove.add(key);
        } else {
            first = true;
            for (Iterator<String> iterator2 = h.keySet().iterator(); iterator2.hasNext(); ) {
                String id = iterator2.next();
                if (first) {
                    first = false;
                    bw.write(id);
                } else
                    bw.write("," + id);
            }
            distribution[h.size()]++;
            if (h.size() > max)
                max = h.size();
        }
    }
    for (String key : keysToRemove) {
        clusters.remove(key);
    }
    for (String id : singletons) {
        bw.write(";" + id);
    }
    distribution[1] = singletons.size();
    StringBuffer sb = new StringBuffer("cluster distribution: ");
    for (int i = max; i >= 0; i--) {
        if (distribution[i] > 0)
            sb.append(i + ":" + distribution[i] + ", ");
    }
    TaskConfig.monitor.setStatusMessage(sb.toString());
    TaskConfig.monitor.setStatusMessage("");
    bw.newLine();
    return clusters;
}
Also used : ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) ClusteringManager(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager) Random(java.util.Random) Vector(java.util.Vector) Hashtable(java.util.Hashtable) ICCEdges(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges) ConnectedComponent(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)

Example 5 with ArgsParseException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.main.ArgsParseException in project clusterMaker2 by RBVI.

the class CostMatrixCreator method main.

/**
 * @param args
 * @throws IOException
 * @throws ArgsParseException
 */
public static void main(String[] args) throws IOException, ArgsParseException {
    Args options = new Args(args, "-");
    if (options.options.containsKey("help") || options.options.containsKey("h") || options.options.containsKey("-help")) {
        printUsage();
        System.exit(0);
    }
    Config.init(options);
    if (Config.gui) {
        MainFrame f = new MainFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        // f.pack();
        f.setSize(900, 900);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int top = (screenSize.height - f.getHeight()) / 2;
        int left = (screenSize.width - f.getWidth()) / 2;
        f.setLocation(left, top);
        JPanel fPanel = (JPanel) f.getContentPane();
        fPanel.add(new JSeparator());
        fPanel.add(new JLabel(" "));
        fPanel.add(new JLabel("Status:"));
        fPanel.add(new JLabel(" "));
        fPanel.add(Console.getConsolePanel());
        Console.println("Welcome...");
        fPanel.updateUI();
    } else {
        HashMap<Integer, String> proteins2integers = new HashMap<Integer, String>();
        HashMap<String, Integer> integers2proteins = new HashMap<String, Integer>();
        if (Config.createSimilarityFile) {
            Creator c = new Creator();
            c.run(proteins2integers, integers2proteins);
        }
        if (Config.splitAndWriteCostMatrices) {
            Splitter s = new Splitter();
            s.run(proteins2integers, integers2proteins);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) HashMap(java.util.HashMap) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MainFrame(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.gui.MainFrame) JSeparator(javax.swing.JSeparator)

Aggregations

InvalidInputFileException (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException)2 IOException (java.io.IOException)2 MainFrame (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.gui.MainFrame)1 ConnectedComponent (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)1 ICCEdges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges)1 ClusteringManager (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager)1 ClusteringManagerTask (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManagerTask)1 InvalidTypeException (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidTypeException)1 ArgsParseException (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ArgsParseException)1 Console (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.Console)1 ConsoleFormatter (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ConsoleFormatter)1 UniqueFilter (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.UniqueFilter)1 Dimension (java.awt.Dimension)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 MissingResourceException (java.util.MissingResourceException)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 Random (java.util.Random)1