Exemplo n.º 1
0
  public HeatMapData(ProteinComparisonDataset comparison) {

    datasetLabels = new ArrayList<String>(comparison.getDatasetCount() + 1);

    for (Dataset ds : comparison.getDatasets()) {
      datasetLabels.add(("ID_" + ds.getDatasetId()));
    }

    rows = new ArrayList<HeatMapRow>(comparison.getTotalProteinCount() + 1);

    int index = 0;
    for (ComparisonProtein protein : comparison.getProteins()) {

      HeatMapRow row = new HeatMapRow();
      row.setIndexInList(index++);
      rows.add(row);

      List<HeatMapCell> cells = new ArrayList<HeatMapCell>();

      row.setRowName(protein.getProteinListing().getFastaReferences().get(0).getShortAccession());
      List<String> allNames = new ArrayList<String>(1);
      allNames.add(row.getRowName());
      row.setRowAllNames(allNames);

      // add cell for molecular wt.
      String molWtCellColor = getColorForMolWt(protein.getMolecularWeight());
      HeatMapCell cell1 = new HeatMapCell();
      cell1.setLabel("");
      cell1.setHexColor(molWtCellColor);
      cells.add(cell1);

      for (Dataset ds : comparison.getDatasets()) {

        HeatMapCell cell = new HeatMapCell();
        cells.add(cell);
        cell.setLabel("");
        DatasetProteinInformation dpi = protein.getDatasetProteinInformation(ds);
        if (dpi == null || !dpi.isPresent()) {
          cell.setHexColor("#FFFFFF");
        } else {
          float heatMapSpectrumCount = dpi.getHeatMapSpectrumCount();
          cell.setHexColor(comparison.getHeatMapColor(heatMapSpectrumCount));
        }

        // http://chart.apis.google.com/chart?chs=320x200&cht=bvs&chd=t:1,19,27,53,61&chds=0,61&chco=FFCC33&chxt=x,y&chxr=1,0,61,10&chxl=0:|Jan|Feb|Mar|Apr|May
        String plotUrl = getPlotUrl(protein, comparison.getDatasets());

        row.setPlotUrl(plotUrl);
      }
      row.setCells(cells);
    }
  }
Exemplo n.º 2
0
  private String getPlotUrl(ComparisonProtein protein, List<? extends Dataset> datasets) {

    String plotUrl = "http://chart.apis.google.com/chart?cht=bhg&chxt=x,y";
    String data1 = "";
    String data2 = "";
    // String colors = "";
    String xrange = "";
    String scale = "";
    String xlabel = "";
    String chartSize = "chs=";

    // chart title
    // String title =
    // "&chtt="+protein.getProteinListing().getFastaReferences().get(0).getShortAccession();
    // plotUrl += title;

    int idx = 0;
    int maxSc = 0;
    int maxLabel = 0;

    boolean allDatasetsHaveNames = true;
    for (Dataset ds : datasets) {
      if (ds.getDatasetName() == null || ds.getDatasetName().length() == 0) {
        allDatasetsHaveNames = false;
        break;
      }
    }

    for (Dataset ds : datasets) {

      DatasetProteinInformation dpi = protein.getDatasetProteinInformation(ds);

      if (allDatasetsHaveNames) {
        xlabel = "|" + ds.getDatasetName() + xlabel;
      } else {
        xlabel = "|" + ds.getDatasetId() + xlabel;
      }

      // colors += "|"+DatasetColor.get(idx).hexValue();
      idx++;

      maxLabel = (int) Math.max(maxLabel, ("" + ds.getDatasetId()).length());

      if (dpi == null || !dpi.isPresent()) {
        data1 += ",0";
        data2 += ",0";
      } else {
        data1 += "," + dpi.getNormalizedSpectrumCountRounded();
        data2 += "," + dpi.getSpectrumCount();
        maxSc = (int) Math.max(maxSc, dpi.getNormalizedSpectrumCount());
      }
    }
    int barWidth = (maxLabel * 6) / 2;
    if (barWidth < 12) barWidth = 12;
    String barSpacing = barWidth + ",1,10";
    int chartHeight = ((barWidth * 2 + 1 + 10) * datasets.size()) + 50;
    chartSize += "250x" + chartHeight;
    plotUrl += "&" + chartSize;
    plotUrl += "&chbh=" + barSpacing;

    // colors = colors.substring(1);
    plotUrl += "&chco=C6D9FD,4D89F9";

    data1 = data1.substring(1);
    data1 = "t:" + data1;
    data2 = data2.substring(1);
    data2 = "|" + data2;
    plotUrl += "&chd=" + data1 + data2;

    int div = (int) Math.ceil((double) maxSc / 10.0);
    if (div > 5) {
      div = Math.round((float) div / 5.0f) * 5;
    }
    xrange = "0,0," + maxSc + "," + div;
    plotUrl += "&chxr=" + xrange;

    scale = "0," + maxSc;
    plotUrl += "&chds=" + scale;

    // x-axis labels
    plotUrl += "&chxl=1:" + xlabel + "|";

    // bar labels
    plotUrl += "&chm=N,000000,0,,10|N,000000,1,,10";

    // legend
    plotUrl += "&chdl=Norm.+Spectrum+Count|Spectrum+Count&chdlp=b";
    return plotUrl;
  }