Example usage for org.jfree.chart.plot CombinedRangeXYPlot setGap

List of usage examples for org.jfree.chart.plot CombinedRangeXYPlot setGap

Introduction

In this page you can find the example usage for org.jfree.chart.plot CombinedRangeXYPlot setGap.

Prototype

public void setGap(double gap) 

Source Link

Document

Sets the amount of space between subplots.

Usage

From source file:org.gwaspi.reports.PlinkReportLoaderCombined.java

public static CombinedRangeXYPlot loadAssocUnadjLogPvsPos(File plinkReport, Set<String> redMarkers)
        throws IOException {

    NumberAxis sharedAxis = new NumberAxis("-log?(P)");
    sharedAxis.setTickMarkInsideLength(3.0f);
    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis);
    combinedPlot.setGap(0);

    XYSeries series1 = null;/*from  w  w w.j  av a2 s  .  com*/
    XYSeries series2 = null;
    FileReader inputFileReader = null;
    BufferedReader inputBufferReader = null;
    try {
        inputFileReader = new FileReader(plinkReport);
        inputBufferReader = new BufferedReader(inputFileReader);

        // Getting data from file and subdividing to series all points by chromosome
        String l;
        String tempChr = "";
        // read but ignore the header
        /*String header = */inputBufferReader.readLine();
        int count = 0;
        while ((l = inputBufferReader.readLine()) != null) {
            if (count % 10000 == 0) {
                log.info("loadAssocUnadjLogPvsPos -> reader count: {}", count);
            }
            count++;

            l = l.trim().replaceAll("\\s+", ",");
            String[] cVals = l.split(",");
            String markerId = cVals[1];
            int position = Integer.parseInt(cVals[2]);
            String s_pVal = cVals[8];

            if (!s_pVal.equals("NA")) {
                double pValue = Double.parseDouble(s_pVal); // P value

                if (cVals[0].toString().equals(tempChr)) {
                    if (redMarkers.contains(markerId)) { // Insert in alternate color series
                        series2.add(position, pValue);
                    } else {
                        series1.add(position, pValue);
                    }

                    //                  series1.add(position, logPValue);
                } else {
                    if (!tempChr.isEmpty()) { // Not the first time round!
                        XYSeriesCollection tempChrData = new XYSeriesCollection();
                        tempChrData.addSeries(series1);
                        tempChrData.addSeries(series2);
                        appendToCombinedRangePlot(combinedPlot, tempChr, tempChrData, false);
                    }

                    tempChr = cVals[0];
                    series1 = new XYSeries("Imputed");
                    series2 = new XYSeries("Observed"); // Alternate color series
                    if (redMarkers.contains(markerId)) { // Insert inlternate color series
                        series2.add(position, pValue);
                    } else {
                        series1.add(position, pValue);
                    }

                    //                  series1 = new XYSeries(cVals[0]);
                    //                  series1.add(position, logPValue);
                }
            }
        }
        // Append last chromosome to combined plot
        XYSeriesCollection tempChrData = new XYSeriesCollection();
        tempChrData.addSeries(series1);
        tempChrData.addSeries(series2);
        appendToCombinedRangePlot(combinedPlot, tempChr, tempChrData, true);
    } finally {
        try {
            if (inputBufferReader != null) {
                inputBufferReader.close();
            } else if (inputFileReader != null) {
                inputFileReader.close();
            }
        } catch (Exception ex) {
            log.warn(null, ex);
        }
    }

    return combinedPlot;
}

From source file:org.gwaspi.reports.PlinkReportLoader.java

public static CombinedRangeXYPlot loadAssocUnadjLogPvsPos(File plinkReport, Set<String> redMarkersHS)
        throws IOException {

    XYSeriesCollection chrData = new XYSeriesCollection();

    NumberAxis sharedAxis = new NumberAxis("-log?(P)");

    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis);
    combinedPlot.setGap(0);

    XYSeries series1 = null;/*from  ww  w  .  ja va2 s.  co  m*/
    XYSeries series2 = null;

    FileReader inputFileReader = null;
    BufferedReader inputBufferReader = null;
    String tempChr = null;
    try {
        inputFileReader = new FileReader(plinkReport);
        inputBufferReader = new BufferedReader(inputFileReader);

        // Getting data from file and subdividing to series all points by chromosome
        String l;
        tempChr = "";
        String header = inputBufferReader.readLine();
        int count = 0;
        while ((l = inputBufferReader.readLine()) != null) {

            if (count % 10000 == 0) {
                log.info("loadAssocUnadjLogPvsPos -> reader count: {}", count);
            }
            count++;

            l = l.trim().replaceAll("\\s+", ",");
            String[] cVals = l.split(",");

            String markerId = cVals[1];
            int position = Integer.parseInt(cVals[2]);
            String s_pVal = cVals[8];

            if (!s_pVal.equals("NA")) {
                double logPValue = Math.abs(Math.log(Double.parseDouble(s_pVal)) / Math.log(10));

                if (cVals[0].toString().equals(tempChr)) {
                    if (redMarkersHS.contains(markerId)) {
                        series2.add(position, logPValue);
                    } else {
                        series1.add(position, logPValue);
                    }
                    labeler.put(tempChr + "_" + position, markerId);
                } else {
                    if (!tempChr.isEmpty()) { // SKIP FIRST TIME (NO DATA YET!)
                        chrData.addSeries(series1);
                        chrData.addSeries(series2);
                        appendToCombinedRangePlot(combinedPlot, tempChr, chrData);
                    }
                    tempChr = cVals[0];
                    series1 = new XYSeries("Imputed");
                    series2 = new XYSeries("Observed");
                    labeler.put(tempChr + "_" + position, markerId);

                    if (redMarkersHS.contains(markerId)) {
                        series2.add(position, logPValue);
                    } else {
                        series1.add(position, logPValue);
                    }
                }
            }
        }
    } finally {
        if (inputBufferReader != null) {
            inputBufferReader.close();
        } else if (inputFileReader != null) {
            inputFileReader.close();
        }
    }

    chrData.addSeries(series1);
    chrData.addSeries(series2);
    appendToCombinedRangePlot(combinedPlot, tempChr, chrData); // ADD LAST CHR TO PLOT

    return combinedPlot;
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

public static CombinedRangeXYPlot buildManhattanPlot(OperationKey testOpKey) throws IOException {

    // PLOT DEFAULTS
    final Config config = Config.getSingleton();
    final double threshold = config.getDouble(PLOT_MANHATTAN_THRESHOLD_CONFIG,
            PLOT_MANHATTAN_THRESHOLD_DEFAULT);
    final Color background = config.getColor(PLOT_MANHATTAN_BACKGROUND_CONFIG,
            PLOT_MANHATTAN_BACKGROUND_DEFAULT);
    final Color backgroundAlternative = config.getColor(PLOT_MANHATTAN_BACKGROUND_ALTERNATIVE_CONFIG,
            PLOT_MANHATTAN_BACKGROUND_ALTERNATIVE_DEFAULT);
    final Color main = config.getColor(PLOT_MANHATTAN_MAIN_CONFIG, PLOT_MANHATTAN_MAIN_DEFAULT);

    Map<MarkerKey, MarkerManhattenData> markerKeyChrPosPVal = assembleManhattenPlotData(testOpKey);

    XYSeriesCollection currChrSC = new XYSeriesCollection();

    NumberAxis sharedAxis = new NumberAxis("-log?(P)");

    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis);
    combinedPlot.setGap(0);

    XYSeries currChrS = null;//from   w w  w .ja v a 2 s  . com

    // Subdividing points into sub-XYSeries, per chromosome
    String currChr = "";
    Map<String, MarkerKey> labeler = new LinkedHashMap<String, MarkerKey>(); // FIXME This is unused, was a global static var before (also private though), was the data added here actually used somewhere? (i think not)
    for (Map.Entry<MarkerKey, MarkerManhattenData> entry : markerKeyChrPosPVal.entrySet()) {
        MarkerKey markerKey = entry.getKey();
        MarkerManhattenData data = entry.getValue();

        if (data.getPValue() != null) {
            final double pVal = data.getPValue(); // Is allready free of NaN and infinity
            if (pVal < 1) {
                if (data.getChromosome().equals(currChr)) {
                    currChrS.add(data.getPosition(), pVal);
                    labeler.put(currChr + "_" + data.getPosition(), markerKey);
                } else {
                    if (!currChr.isEmpty()) { // SKIP FIRST TIME (NO DATA YET!)
                        // add the last (now compleeted) chromosomes data-set,
                        // before starting the new one
                        currChrSC.addSeries(currChrS);
                        appendToCombinedRangeManhattanPlot(combinedPlot, currChr, currChrSC, false, threshold,
                                background, backgroundAlternative, main);
                    }
                    currChr = data.getChromosome();
                    currChrSC = new XYSeriesCollection();
                    currChrS = new XYSeries(currChr);
                    labeler.put(currChr + "_" + data.getPosition(), markerKey);

                    currChrS.add(data.getPosition(), pVal);
                }
            }
        }
    }
    if (currChrS != null) {
        currChrSC.addSeries(currChrS);
        // ADD LAST CHR TO PLOT
        appendToCombinedRangeManhattanPlot(combinedPlot, currChr, currChrSC, true, threshold, background,
                backgroundAlternative, main);
    }

    // Remove Legend from the bottom of the chart
    combinedPlot.setFixedLegendItems(new LegendItemCollection());

    return combinedPlot;
}

From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java

/**
 * Creates a plot which contains multiple chromosome histograms
 * @param chromosomeHistograms/*from w w w. j  a  v  a2  s  .  c  o  m*/
 *          the chromosome histograms
 * @param xAxisLabel
 *          the X axis label
 * @param yAxisLabel
 *          the Y axis label
 * @return
 *          the object for the multiple chromosome plots
 */
public JFreeChart createMultiChromosomeHistogram(
        final List<? extends ChromosomeHistogramValues> chromosomeHistograms, final String xAxisLabel,
        final String yAxisLabel) {
    // create the y-axis that is shared by all of the chromosomes
    NumberAxis yAxis = new NumberAxis();
    if (yAxisLabel != null) {
        yAxis.setLabel(yAxisLabel);
    }

    // the combined plot makes all of the chromosomes to share the same
    // y-axis but to have thier own x-axis
    CombinedRangeXYPlot combinedChromosomePlot = new CombinedRangeXYPlot(yAxis);
    combinedChromosomePlot.setGap(4.0);

    // iterate through the chromosomes adding a new plot for each one
    for (ChromosomeHistogramValues currChromHist : chromosomeHistograms) {
        // use a weight to ensure that the amount of space that the
        // subgraph gets on the x-axis is proportional to the chromosome's
        // extent
        final int currWeight = (int) (currChromHist.getExtentInBasePairs() / 1000 + 1);

        final NumberAxis currXAxis = new NumberAxis();
        currXAxis.setAutoRangeIncludesZero(false);
        currXAxis.setTickLabelsVisible(false);
        currXAxis.setTickMarksVisible(false);
        currXAxis.setLabel(Integer.toString(currChromHist.getChromosomeNumber()));

        final XYPlot currPlot = this.createSnpIntervalHistogramPlot(currChromHist.getIntervals(),
                currChromHist.getVisualInterval(), currXAxis, null);

        combinedChromosomePlot.add(currPlot, currWeight);
    }

    JFreeChart multiChromosomeChart = new JFreeChart(combinedChromosomePlot);
    multiChromosomeChart.removeLegend();

    return multiChromosomeChart;
}