Package edu.ucla.sspace.util

Examples of edu.ucla.sspace.util.ColorGenerator


            else
                node.setAttribute("label", String.valueOf(vertex));
            nodes.appendChild(node);
        }

        ColorGenerator cg = null;
        if (useColors)
            cg = new ColorGenerator();

        int edgeId = 0;
        for (E e : g.edges()) {
            Element edge = doc.createElement("edge");
            edges.appendChild(edge);
            edge.setAttribute("id", "" + (edgeId++));
            edge.setAttribute("source", String.valueOf(e.from()));
            edge.setAttribute("target", String.valueOf(e.to()));
            edge.setAttribute("label", String.valueOf(e.edgeType()));
            if (useColors) {
                Element cEdge = doc.createElement("viz:color");
                edge.appendChild(cEdge);
                Color c = edgeColors.get(e.edgeType());
                if (c == null) {
                    c = cg.next();
                    edgeColors.put(e.edgeType(), c);
                }
                cEdge.setAttribute("r", String.valueOf(c.getRed()));
                cEdge.setAttribute("g", String.valueOf(c.getGreen()));
                cEdge.setAttribute("b", String.valueOf(c.getBlue()));
View Full Code Here


                    DotIO dio = new DotIO();
                   
                    // Generate a consistent set of edge colors to user across
                    // all the motif visualizations
                    Map<String,Color> edgeColors = new HashMap<String,Color>();
                    ColorGenerator cg = new ColorGenerator();
                    for (String type : dm.edgeTypes())
                        edgeColors.put(type, cg.next());

                    PrintWriter pw = new PrintWriter(new File(baseDir, "index.html"));
                    PrintWriter imgScript = new PrintWriter(new File(baseDir, "img-script.sh"));
                    imgScript.println("#!/bin/bash");
                    pw.println("<html>");
                    pw.println("<head><script src=\"http://www.kryogenix.org/code/browser/sorttable/sorttable.js\"></script></head>");
                    // pw.println("<head><script src=\"sorttable.js\"></script></head>");
                    pw.println("<body><table border=\"2\" class=\"sortable\">");
                    pw.println("  <tr>" +
                               "<td><h1><u>Motif</u></h1></td>" +
                               "<td><h1><u>Count</u></h1></td>" +
                               "<td><h1><u>Z-Score</u></h1></td>" +
                               "<td><h1><u>Mean Count in Random Graphs</u></h1></td>" +
                               "<td><h1><u>StdDev in Random Graphs</u></h1></td>" +
                               "</tr>");
                    int graphNum = 0;
                    for (Map.Entry<Multigraph<String,DirectedTypedEdge<String>>,Fanmod.Result> e :
                             motifToZScore.entrySet()) {
                        File dotFile = new File(baseDir, "graph-" + (graphNum++) + ".dot");
                        dio.writeDirectedMultigraph(e.getKey(), dotFile, edgeColors);
                        String imgFile = dotFile.getName();
                        imgFile = imgFile.substring(0, imgFile.length() - 3) + "gif";
                        imgScript.printf("dot -Tgif %s -o %s%n", dotFile.getName(), imgFile);
                        int count = e.getValue().count;
                        double zScore = e.getValue().statistic;
                        double mean = e.getValue().meanCountInNullModel;
                        double stddev = e.getValue().stddevInNullModel;
                        pw.printf("  <tr><td><img src=\"%s\"></td><td>%d</td><td>%f</td><td>%f</td><td>%f</td></tr>%n",
                                  imgFile, count, zScore, mean, stddev);
                    }
                    pw.println("</table></body></html>");
                    imgScript.close();
                    pw.close();
                }
               
                info(LOGGER, "writing final motifs to %s",
                     opts.getPositionalArg(1));
                // Write the results to file
                File output = new File(opts.getPositionalArg(1));
                // Copy the motifs to a new HashSet to avoid writing the result
                // as a KeySet, which includes the fanmod result values.
                SerializableUtil.save(
                    new HashSet<Multigraph<String,
                        DirectedTypedEdge<String>>>(motifToZScore.keySet()), output);
            }

            else if (isMultigraph) {
                boolean findSimpleMotifs = opts.hasOption('s');
                UndirectedMultigraph<String> um =
                    GraphIO.readUndirectedMultigraph(f, vertexLabels);
                Map<Multigraph<String,TypedEdge<String>>,Fanmod.Result>
                    motifToZScore = fanmod.findMotifs(
                      um, findSimpleMotifs, motifSize, numRandomGraphs, filter);
                info(LOGGER, "found %d motifs with z-score above %f%n",
                     motifToZScore.size(), minZScore);
                if (opts.hasOption('H')) {
                    File baseDir = new File(opts.getStringOption('H'));
                    // Check that we can create output in that directory
                    if (!baseDir.exists())
                        baseDir.mkdir();
                    DotIO dio = new DotIO();
                    // Generate a consistent set of edge colors to user across
                    // all the motif visualizations
                    Map<String,Color> edgeColors = new HashMap<String,Color>();
                    ColorGenerator cg = new ColorGenerator();
                    for (String type : um.edgeTypes())
                        edgeColors.put(type, cg.next());

                    PrintWriter pw = new PrintWriter(new File(baseDir, "index.html"));
                    PrintWriter imgScript = new PrintWriter(new File(baseDir, "img-script.sh"));
                    imgScript.println("#!/bin/bash");
                    pw.println("<html>");
View Full Code Here

     *        contents will be overwritten
     */
    public <T,E extends TypedEdge<T>> void writeUndirectedMultigraph(
                        Multigraph<T,E> g, File f) throws IOException {
        Map<T,Color> edgeColors = new HashMap<T,Color>();
        ColorGenerator cg = new ColorGenerator();
        for (T type : g.edgeTypes())
            edgeColors.put(type, cg.next());
        this.writeUndirectedMultigraph(g, f, edgeColors, null, false);
    }
View Full Code Here

                         Multigraph<T,E> g, File f, Map<T,Color> edgeColors,
                        Indexer<String> vertexLabels, boolean useLabels)
                        throws IOException {
   
        PrintWriter pw = new PrintWriter(f);
        ColorGenerator cg = new ColorGenerator();
        pw.println("graph g {");
        // Write the vertices, which may be disconnected
        for (int v : g.vertices()) {
            if (useLabels) {
                String label = vertexLabels.lookup(v);
                if (label == null)
                    label = String.valueOf(v);
                pw.println("  " + v + " [label=\"" + label + "\"];");
            }
            else
                pw.println("  " + v + ";");
        }
        for (E e : g.edges()) {
            Color c = edgeColors.get(e.edgeType());
            if (c == null) {
                c = cg.next();
                edgeColors.put(e.edgeType(), c);
            }
            String hexColor = Integer.toHexString(c.getRGB());
            hexColor = hexColor.substring(2, hexColor.length());
             pw.printf("  %d -- %d [label=\"%s\", color=\"#%s\"]%n", e.from(), e.to(),
View Full Code Here

                         Multigraph<T,E> g, File f, Map<T,Color> edgeColors,
                         MultiMap<Integer,String> vertexMetadata)
                        throws IOException {
   
        PrintWriter pw = new PrintWriter(f);
        ColorGenerator cg = new ColorGenerator();
        pw.println("graph g {");
        // Write the vertices, which may be disconnected
        for (int v : g.vertices()) {
            StringBuilder sb = new StringBuilder();
            for (String attr : vertexMetadata.get(v))
                sb.append(attr).append(' ');
            pw.println("  " + v + " [" + sb + "];");
        }
        for (E e : g.edges()) {
            Color c = edgeColors.get(e.edgeType());
            if (c == null) {
                c = cg.next();
                edgeColors.put(e.edgeType(), c);
            }
            String hexColor = Integer.toHexString(c.getRGB());
            hexColor = hexColor.substring(2, hexColor.length());
             pw.printf("  %d -- %d [label=\"%s\", color=\"#%s\"]%n", e.from(), e.to(),
View Full Code Here

     *        contents will be overwritten
     */
    public <T,E extends DirectedTypedEdge<T>> void writeDirectedMultigraph(
                        Multigraph<T,E> g, File f) throws IOException {
        Map<T,Color> edgeColors = new HashMap<T,Color>();
        ColorGenerator cg = new ColorGenerator();
        for (T type : g.edgeTypes())
            edgeColors.put(type, cg.next());
        this.writeDirectedMultigraph(g, f, edgeColors);
    }
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.util.ColorGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.