Example usage for java.io PrintStream format

List of usage examples for java.io PrintStream format

Introduction

In this page you can find the example usage for java.io PrintStream format.

Prototype

public PrintStream format(Locale l, String format, Object... args) 

Source Link

Document

Writes a formatted string to this output stream using the specified format string and arguments.

Usage

From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java

private List<String> writeFeedMS1Values(List<Pair<Double, List<XZ>>> ms1s, Double maxIntensity, OutputStream os)
        throws IOException {
    // Write data output to outfile
    PrintStream out = new PrintStream(os);

    List<String> plotID = new ArrayList<>(ms1s.size());
    for (Pair<Double, List<XZ>> ms1ForFeed : ms1s) {
        Double feedingConcentration = ms1ForFeed.getLeft();
        List<XZ> ms1 = ms1ForFeed.getRight();

        plotID.add(String.format("concentration: %5e", feedingConcentration));
        // print out the spectra to outDATA
        for (XZ xz : ms1) {
            out.format("%.4f\t%.4f\n", xz.getTime(), xz.getIntensity());
            out.flush();//from   w w  w  .j  a  v  a  2s . c  om
        }
        // delimit this dataset from the rest
        out.print("\n\n");
    }

    return plotID;
}

From source file:com.act.lcms.MS2.java

private void plot(MS2Collected Ams2Peaks, MS2Collected Bms2Peaks, Double mz, String outPrefix, String fmt)
        throws IOException {

    MS2Collected[] ms2Spectra = new MS2Collected[] { Ams2Peaks, Bms2Peaks };

    String outPDF = outPrefix + "." + fmt;
    String outDATA = outPrefix + ".data";

    // Write data output to outfile
    PrintStream out = new PrintStream(new FileOutputStream(outDATA));

    List<String> plotID = new ArrayList<>(ms2Spectra.length);
    for (MS2Collected yzSlice : ms2Spectra) {
        plotID.add(String.format("time: %.4f, volts: %.4f", yzSlice.triggerTime, yzSlice.voltage));
        // print out the spectra to outDATA
        for (YZ yz : yzSlice.ms2) {
            out.format("%.4f\t%.4f\n", yz.mz, yz.intensity);
            out.flush();/*from  www. j av  a2 s .  c  om*/
        }
        // delimit this dataset from the rest
        out.print("\n\n");
    }

    // close the .data
    out.close();

    // render outDATA to outPDF using gnuplot
    // 105.0 here means 105% for the y-range of a [0%:100%] plot. We want to leave some buffer space at
    // at the top, and hence we go a little outside of the 100% max range.
    new Gnuplotter().plot2DImpulsesWithLabels(outDATA, outPDF, plotID.toArray(new String[plotID.size()]),
            mz + 50.0, "mz", 105.0, "intensity (%)", fmt);
}

From source file:info.mikaelsvensson.devtools.analysis.shared.reportprinter.PlainTextReportPrinter.java

@Override
public void printList(PrintStream printStream, String listHeader, List<Map<String, String>> keyValuePairsList) {
    int i = 1;//www  .  j  a  v  a 2s.  com
    for (Map<String, String> map : keyValuePairsList) {
        printHeader(listHeader
                + (keyValuePairsList.size() > 1 ? ", item " + (i++) + " of " + keyValuePairsList.size() : ""),
                false, printStream);
        int maxKeyLength = 0;
        for (Map.Entry<String, String> entry : map.entrySet()) {
            maxKeyLength = Math.max(maxKeyLength, entry.getKey().length());
        }
        maxKeyLength += 3;
        String newLineReplacement = '\n' + StringUtils.repeat(' ', maxKeyLength);
        final String format = "    %-" + maxKeyLength + "s%s%n";
        for (Map.Entry<String, String> entry : map.entrySet()) {
            printStream.format(format, entry.getKey(), entry.getValue().replace("\n", newLineReplacement));
        }
    }
}

From source file:fr.univnantes.lina.UIMAProfiler.java

@Override
public void display(PrintStream stream) {
    if (isEmpty())
        return;/*from ww  w.  j  av a 2  s. co m*/
    stream.println(
            "###########################################################################################");
    stream.println(
            "#################################### " + this.name + " ####################################");
    stream.println(
            "###########################################################################################");
    String formatString = "%30s %10sms\n";
    if (!tasks.isEmpty()) {
        stream.println("--------------- Tasks --------------");
        for (String taskName : tasks.keySet()) {
            long t = 0;
            for (ProfilingTask task : tasks.get(taskName))
                t += task.getTotal();
            stream.format(formatString, taskName, t);
        }
        stream.format(formatString, "TOTAL", getTotal());
    }
    if (!counters.isEmpty()) {
        stream.println("--------------- Hits ------------------");
        formatString = "%30s %10s\n";
        long total = 0;
        Comparator<String> comp = new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.compare(counters.get(o2).intValue(), counters.get(o1).intValue());
            }
        };
        List<String> sortedkeys = new LinkedList<String>();
        sortedkeys.addAll(counters.keySet());
        Collections.sort(sortedkeys, comp);
        for (String hitName : sortedkeys) {
            int h = counters.get(hitName).intValue();
            total += h;
            stream.format(formatString, hitName, h);
        }
        stream.format(formatString, "TOTAL", total);
        if (latexFormat) {
            stream.println("--------------- Hits (Latex) ----------");
            total = 0;
            sortedkeys = new LinkedList<String>();
            sortedkeys.addAll(counters.keySet());
            Collections.sort(sortedkeys, comp);
            for (String hitName : sortedkeys) {
                int h = counters.get(hitName).intValue();
                total += h;
                stream.println(hitName + " & " + counters.get(hitName).intValue() + " \\\\");
            }
            stream.println("TOTAL & " + total + " \\\\");
        }
    }
    if (!examples.isEmpty()) {
        stream.println("-------------- Examples ---------------");
        List<String> keySet = Lists.newArrayList(examples.keySet());
        Collections.shuffle(keySet);
        for (String hitName : keySet) {
            int i = 0;
            stream.println("* " + hitName);
            for (Object o : examples.get(hitName)) {
                i++;
                if (i > exampleLimit)
                    break;
                String str = o == null ? "null"
                        : o.toString().replaceAll("\n", " ").replaceAll("\r", " ").toLowerCase();
                stream.println("\t" + str);
            }
        }
    }
    if (!pointStatus.isEmpty()) {
        stream.println("-------------- Point status -----------");
        for (String point : pointStatus.keySet()) {
            stream.println(point + ": " + pointStatus.get(point));
        }
    }
    stream.flush();
}

From source file:com.act.lcms.MS2Simple.java

private void plot(List<Pair<MS2Collected, Integer>> ms2Spectra, Double mz, List<Double> ms2SearchMZs,
        String outPrefix, String fmt) throws IOException {
    String outPDF = outPrefix + "." + fmt;
    String outDATA = outPrefix + ".data";

    // Write data output to outfile
    PrintStream out = new PrintStream(new FileOutputStream(outDATA));

    List<String> plotID = new ArrayList<>(ms2Spectra.size());
    for (Pair<MS2Collected, Integer> pair : ms2Spectra) {
        MS2Collected yzSlice = pair.getLeft();
        String caption;/*ww  w. ja v a 2 s . co m*/
        if (ms2SearchMZs != null && ms2SearchMZs.size() > 0) {
            caption = String.format("target: %.4f, time: %.4f, volts: %.4f, %d / %d matches",
                    yzSlice.triggerMass, yzSlice.triggerTime, yzSlice.voltage,
                    pair.getRight() == null ? 0 : pair.getRight(), ms2SearchMZs.size());
        } else {
            caption = String.format("target: %.4f, time: %.4f, volts: %.4f", yzSlice.triggerMass,
                    yzSlice.triggerTime, yzSlice.voltage);
        }
        plotID.add(caption);
        // Compute the total intensity on the fly so we can plot on a percentage scale.
        double maxIntensity = 0.0;
        for (YZ yz : yzSlice.ms2) {
            if (yz.intensity > maxIntensity) {
                maxIntensity = yz.intensity;
            }
        }
        // print out the spectra to outDATA
        for (YZ yz : yzSlice.ms2) {
            out.format("%.4f\t%.4f\n", yz.mz, 100.0 * yz.intensity / maxIntensity);
            out.flush();
        }
        // delimit this dataset from the rest
        out.print("\n\n");
    }

    // close the .data
    out.close();

    // render outDATA to outPDF using gnuplot
    // 105.0 here means 105% for the y-range of a [0%:100%] plot. We want to leave some buffer space at
    // at the top, and hence we go a little outside of the 100% max range.
    /* We intend to plot the fragmentation pattern, and so do not expect to see fragments that are bigger than the
     * original selected molecule.  We truncate the x-range to the specified m/z but since that will make values close
     * to the max hard to see we add a buffer and truncate the plot in the x-range to m/z + 50.0. */
    new Gnuplotter().plot2DImpulsesWithLabels(outDATA, outPDF, plotID.toArray(new String[plotID.size()]),
            mz + 50.0, "mz", 105.0, "intensity (%)", fmt);
}

From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java

public List<Pair<String, String>> writeMS1Values(Map<String, List<XZ>> ms1s, Double maxIntensity,
        Map<String, Double> metlinMzs, OutputStream os, boolean heatmap, boolean applyThreshold,
        Set<String> ionsToWrite) throws IOException {
    // Write data output to outfile
    PrintStream out = new PrintStream(os);

    List<Pair<String, String>> plotID = new ArrayList<>(ms1s.size());
    for (Map.Entry<String, List<XZ>> ms1ForIon : ms1s.entrySet()) {
        String ion = ms1ForIon.getKey();
        // Skip ions not in the ionsToWrite set if that set is defined.
        if (ionsToWrite != null && !ionsToWrite.contains(ion)) {
            continue;
        }//from  w w w  . j  a v  a  2 s .com

        List<XZ> ms1 = ms1ForIon.getValue();
        String plotName = String.format("ion: %s, mz: %.5f", ion, metlinMzs.get(ion));
        plotID.add(Pair.of(ion, plotName));
        // print out the spectra to outDATA
        for (XZ xz : ms1) {
            if (heatmap) {
                /*
                * When we are building heatmaps, we use gnuplots pm3d package
                * along with `dgrid3d 2000,2` (which averages data into grids
                * that are 2000 on the time axis and 2 in the y axis), and
                * `view map` that flattens a 3D graphs into a 2D view.
                * We want time to be on the x-axis and intensity on the z-axis
                * (because that is the one that is mapped to heat colors)
                * but then we need an artificial y-axis. We create proxy y=1
                * and y=2 datapoints, and then dgrid3d averaging over 2 creates
                * a vertical "strip".
                */
                out.format("%.4f\t1\t%.4f\n", xz.getTime(), xz.getIntensity());
                out.format("%.4f\t2\t%.4f\n", xz.getTime(), xz.getIntensity());
            } else {
                out.format("%.4f\t%.4f\n", xz.getTime(), xz.getIntensity());
            }
            out.flush();
        }
        // delimit this dataset from the rest
        out.print("\n\n");
    }

    return plotID;
}

From source file:org.apache.mahout.classifier.ConfusionMatrixDumper.java

private static void printCountsHeader(ConfusionMatrix cm, PrintStream out, boolean vertical) {
    List<String> labels = stripDefault(cm);
    int longest = getLongestHeader(labels);
    if (vertical) {
        // do vertical - rotation is a bitch
        out.format("<tr class='%s' style='height:%dem'><th>&nbsp;</th>%n", CSS_TALL_HEADER, longest / 2);
        for (String label : labels) {
            out.format("<th><div class='%s'>%s</div></th>", CSS_VERTICAL, label);
        }//from   www  .j  a  v  a  2s .c om
        out.println("</tr>");
    } else {
        // header - empty cell in upper left
        out.format("<tr class='%s'><td class='%s'></td>%n", CSS_TABLE, CSS_LABEL);
        for (String label : labels) {
            out.format("<td>%s</td>", label);
        }
        out.format("</tr>");
    }
}

From source file:org.lockss.devtools.PdfTools.java

protected void doTokenStreams() throws Exception {
    initializePdfDocument();//from   w w w  .  j  a  v a  2  s . c  o m
    PrintStream ps = null;
    try {
        ps = new PrintStream(new FileOutputStream(cline.getOptionValue(TOKEN_STREAMS)));
        List<PdfPage> pages = pdfDocument.getPages();
        for (int pag = 0; pag < pages.size(); ++pag) {
            List<PdfTokenStream> streams = pages.get(pag).getAllTokenStreams();
            for (int str = 0; str < streams.size(); ++str) {
                ps.format("Page %d - Stream %d\n", pag, str);
                List<PdfToken> tokens = streams.get(str).getTokens();
                for (int tok = 0; tok < tokens.size(); ++tok) {
                    ps.format("%d\t%s\n", tok, PdfUtil.prettyPrint(tokens.get(tok)));
                }
                ps.println();
            }
            ps.println();
        }
    } finally {
        IOUtil.safeClose(ps);
    }
}

From source file:sf.net.experimaestro.manager.plans.GroupBy.java

@Override
protected void printDOTNode(PrintStream out, Map<Operator, MutableInt> counts) {
    super.printDOTNode(out, counts);
    for (Operator operator : operators)
        out.format("p%s -> p%s [ style=\"dotted\", weight=0 ];%n", System.identityHashCode(operator),
                System.identityHashCode(this));
}

From source file:sf.net.experimaestro.manager.plans.Join.java

@Override
public boolean printDOT(PrintStream out, HashSet<Operator> planNodes, Map<Operator, MutableInt> counts) {
    if (super.printDOT(out, planNodes, counts)) {
        for (JoinReference join : joins)
            out.format("p%s -> p%s [style=\"dotted\"];%n", identityHashCode(join.operator),
                    identityHashCode(this));

    }//www  .  j a va  2 s  . c  o  m
    return false;
}