Search in sources :

Example 1 with InvalidInputFileException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.

the class PP_RearrangeAndMergeBest method mergeBest.

protected void mergeBest(ArrayList<ArrayList<Integer>> clusterObject) throws InvalidInputFileException {
    // System.out.println("start merging");
    ICCEdges cc2d = TaskConfig.ccEdgesEnum.createCCEdges(clusterObject.size());
    String[] ids = new String[clusterObject.size()];
    for (int i = 0; i < ids.length; i++) {
        ids[i] = i + "";
        for (int j = i + 1; j < ids.length; j++) {
            cc2d.setEdgeCost(i, j, -(float) calculateCostChange(clusterObject.get(i), clusterObject.get(j)));
        // System.out.println(i + "\t" + j + "\t" + cc2d.getEdgeCost(i, j));
        }
    }
    ConnectedComponent cc2 = new ConnectedComponent(cc2d, ids, null, false);
    ClusteringManager cm = new ClusteringManager(null);
    // cm.runClusteringForOneConnectedComponent(cc2, null, null, null, System.currentTimeMillis());
    new GreedyClusterer(cc2);
    // long dummy = TaskConfig.fpMaxTimeMillis;
    // TaskConfig.fpMaxTimeMillis = Long.MAX_VALUE;
    // FixedParameterClusterer dc = new FixedParameterClusterer(cc2,cc2.getClusteringScore());
    // TaskConfig.fpMaxTimeMillis = dummy;
    // if(cc2.getClusteringScore() != this.bestScore){
    // PP_DivideAndRecluster pp = new PP_DivideAndRecluster();
    // pp.initPostProcessing(cc2);
    // pp.run();
    // }
    ArrayList<ArrayList<Integer>> clusterObjectNew = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < cc2.getNumberOfClusters(); i++) {
        ArrayList<Integer> v = new ArrayList<Integer>();
        clusterObjectNew.add(v);
    }
    int[] clustering = cc2.getClusters();
    for (int i = 0; i < clustering.length; i++) {
        clusterObjectNew.get(clustering[i]).addAll(clusterObject.get(i));
    }
    clusterObject = clusterObjectNew;
    this.bestScore = cc2.calculateClusteringScore(clustering);
// System.out.println("end merging");
}
Also used : ClusteringManager(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager) GreedyClusterer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.greedy.GreedyClusterer) ConnectedComponent(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent) ArrayList(java.util.ArrayList) ICCEdges(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges)

Example 2 with InvalidInputFileException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException 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 3 with InvalidInputFileException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.

the class GeneralParameterTraining method runOneGeneration.

private void runOneGeneration(IParameters[][] parameters, ArrayList<File> connectedComponents, int gen) throws InvalidInputFileException, InvalidTypeException {
    TaskConfig.monitor.setStatusMessage("Start training generation: " + gen);
    int size = parameters.length;
    /* do clustering for each set of parameter configurations */
    for (int i = 0; i < size; i++) {
        /* copy the cc (ConnectedComponent) ArrayList - shares same resources! */
        ArrayList<ConnectedComponent> newConnectedComponents = new ArrayList<ConnectedComponent>(connectedComponents.size());
        // for (int j = 0; j < connectedComponents.size(); j++) {
        // ConnectedComponent cc = new CostMatrixReader(connectedComponents.get(j)).getConnectedComponent();
        // ConnectedComponent newCC = cc.copy();
        /* sets a new positions array for the copy */
        // newCC.setCCPositions(cc.copyCCPositions());
        // newConnectedComponents.add(newCC);
        // }
        /* start clustering */
        clusteringManager.setConnectedComponents(connectedComponents);
        clusteringManager.setLayouterParameters(parameters[i]);
        clusteringManager.runClustering();
        FORCEnDParameters fndparam = (FORCEnDParameters) parameters[i][0];
        fndparam.printParamters();
        newConnectedComponents.clear();
    }
// log.debug("Finished training generation: "+gen);
}
Also used : FORCEnDParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.forcend.FORCEnDParameters) ConnectedComponent(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent) ArrayList(java.util.ArrayList)

Example 4 with InvalidInputFileException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.

the class ClusteringManager method initParametersAndCCs.

/**
 * Sets transitive connected components file if in input directory. Finds all cost matrix files
 * given and creates a new {@link ConnectedComponent} instance for each and adds them to
 * the list of ConnectedComponents.
 *
 * Also initialises the {@link IParameters} from the input configuration.
 * @throws InvalidInputFileException
 */
public void initParametersAndCCs() throws InvalidInputFileException {
    if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE || TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
        // this.connectedComponents = new ArrayList<ConnectedComponent>();
        this.connectedComponents = new ArrayList<File>();
        TaskConfig.transitiveConnectedComponents = null;
        /* read the input file or directory */
        File cmFile = new File(this.cmPath);
        if (cmFile.isDirectory()) {
            log.finer("Input is a directory!");
            /* get all files in the directory */
            File[] files = cmFile.listFiles();
            /* check boolean whether cm files exist in directory */
            boolean noCostMatrices = true;
            boolean noTCCfile = true;
            for (int i = 0; i < files.length; i++) {
                String filePath = files[i].toString();
                /* find tcc file in directory */
                if (filePath.endsWith(".tcc") || filePath.endsWith(".rtcc")) {
                    noTCCfile = false;
                    TaskConfig.transitiveConnectedComponents = filePath;
                    log.info("Transitive connected components file: " + filePath);
                    InfoFile.appendToProjectDetails("Transitive connected component file: " + filePath);
                }
                /* find cm files*/
                if (files[i].toString().endsWith(".cm") || files[i].toString().endsWith(".rcm")) {
                    // cm files exist
                    noCostMatrices = false;
                    connectedComponents.add(files[i]);
                // create the connected component (cc) object and add to list
                // CostMatrixReader cmReader = new CostMatrixReader(files[i]);
                // ConnectedComponent cc = cmReader.getConnectedComponent();
                // connectedComponents.add(cc);
                }
            }
            if (noCostMatrices) {
                if (noTCCfile) {
                    throw new InvalidInputFileException("There are no cost matrix " + "files in the input directory and also no transitive connected components file, " + "or check whether the file extensions equal .cm, .rcm, or .tcc");
                }
            }
        } else {
            /* only one cost matrix file is given */
            log.finer("One cm file given");
            /* only one cost matrix as input - start clustering process */
            if (!cmFile.toString().endsWith(".tcc")) {
                // create the connected component (cc) object and add to list
                // CostMatrixReader cmReader = new CostMatrixReader(cmFile);
                // ConnectedComponent cc = cmReader.getConnectedComponent();
                // connectedComponents.add(cc);
                connectedComponents.add(cmFile);
            } else {
                if (cmFile.toString().endsWith(".tcc")) {
                    TaskConfig.transitiveConnectedComponents = cmFile.toString();
                    log.info("Only a transitive connected component file is given: " + cmFile.toString());
                    InfoFile.appendToProjectDetails("Only a transitive connected component file is given: " + cmFile.toString() + ". Therefore NO CLUSTERING IS PERFORMED, just the the " + "clusters from the TCC file are written into the clusters file.");
                } else {
                    throw new InvalidInputFileException("Either the input cost matrix is of " + "wrong file type. The file extension should be \".cm\" or \".rcm\"," + "or in the given TCC file is of the wrong type and should be \".tcc\".");
                }
            }
        }
    }
    /* initialise parameters from config */
    // LayoutFactory.EnumLayouterClass[] layouterEnumTypes = TaskConfig.layouterEnumTypes;
    layouterParameters = new IParameters[TaskConfig.layouterEnumTypes.length];
    for (int i = 0; i < TaskConfig.layouterEnumTypes.length; i++) {
        IParameters param = TaskConfig.layouterEnumTypes[i].createIParameters();
        param.readParametersFromConfig();
        layouterParameters[i] = param;
    }
    if (this.connectedComponents == null) {
    }
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) InfoFile(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.InfoFile) ClusterFile(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile) File(java.io.File)

Example 5 with InvalidInputFileException

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.

the class ClusteringManager method runClusteringForOneConnectedComponent.

/**
 * Runs clustering for one {@link ConnectedComponent} and sets the total score to
 * the parameters if in the general training mode.
 * @param cc The connected component object.
 * @param clusterFile The clusters file (null if in general training mode)
 * @param semaphore The Semaphore to give to the clustering task to keep track of it.
 * @param time
 * @throws InvalidInputFileException
 */
public void runClusteringForOneConnectedComponent(ConnectedComponent cc, ClusterFile clusterFile, Semaphore semaphore, Semaphore maxThreadSemaphore, long time) throws InvalidInputFileException {
    /* check whether layouterParameters has been initialised */
    if (this.layouterParameters == null) {
        if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE || TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE)
            log.warning("Incorrect use of the ClusteringManager, the layouter parameters list" + "hadn't been initialised. Called method to initialise this and the connected components from " + "the config");
        this.initParametersAndCCs();
    }
    // if(TaskConfig.mode == TaskConfig.CLUSTERING_MODE){
    if (TaskConfig.doLayoutParameterTraining && !TaskConfig.greedy) {
        for (int i = 0; i < this.layouterParameters.length; i++) {
            /* start parameter training for the cc */
            IParameterTraining paramTrain = TaskConfig.parameterTrainingEnum.createParameterTrainer();
            paramTrain.initialise(TaskConfig.layouterEnumTypes[i], TaskConfig.noOfParameterConfigurationsPerGeneration, TaskConfig.noOfGenerations);
            paramTrain.setMaxThreadSemaphoreAndThreadsList(maxThreadSemaphore, this.allThreads);
            IParameters bestparam = paramTrain.run(cc);
            log.fine("PARAMETER TRAINING RESULT\n: " + cc.getCcPath() + "\n" + bestparam.toString());
            this.layouterParameters[i] = bestparam;
        }
    }
    // }
    /* run clustering with the previously determined parameters */
    ClusteringTask clusterTask = new ClusteringTask(cc, this.layouterParameters, TaskConfig.layouterEnumTypes, clusterFile);
    clusterTask.setTime(time);
    // if(!TaskConfig.doLayoutParameterTraining&&TaskConfig.useThreads){
    // clusterTask.setSemaphore(semaphore);
    // Thread t = new Thread(clusterTask);
    // clusterTask.setMaxThreadSemaphore(maxThreadSemaphore, allThreads, t);
    // t.start();
    // }else{
    clusterTask.run();
// }
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) IParameterTraining(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.parameter_training.IParameterTraining)

Aggregations

ConnectedComponent (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)5 ArrayList (java.util.ArrayList)5 IParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters)4 ICCEdges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges)3 ClusteringManager (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager)3 Semaphore (java.util.concurrent.Semaphore)3 CostMatrixReader (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.CostMatrixReader)2 FORCEnDParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.forcend.FORCEnDParameters)2 InvalidInputFileException (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException)2 ClusterFile (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile)2 InfoFile (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.InfoFile)2 File (java.io.File)2 IOException (java.io.IOException)2 Hashtable (java.util.Hashtable)2 Random (java.util.Random)2 Vector (java.util.Vector)2 GreedyClusterer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.greedy.GreedyClusterer)1 IteratorThread (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread)1 ILayoutInitialiser (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.ILayoutInitialiser)1 IParameterTraining (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.parameter_training.IParameterTraining)1