Exemple #1
0
 /**
  * Create new test directory within the system-defined unit test master directory. The newly
  * created directory will be a sub-directory of the master directory.
  *
  * @param dirName Directory name to be created within the master directory.
  * @return Absolute path name of test directory.
  */
 public static String newTestDirectory(final String dirName) {
   String tempDir = UnitTestUtils.getUnitTestProperty("temp.dir");
   File dir = new File(tempDir);
   if (!dir.exists()) {
     throw new RuntimeException("Please create directory '" + tempDir + "' for unit testing");
   }
   String testDirName = tempDir + "/" + dirName;
   File testDir = new File(testDirName);
   if (!testDir.exists()) {
     testDir.mkdir();
   }
   return testDirName;
 }
/**
 * Tester for <code>IdeogramPlotPainter</code>.
 *
 * @author dhall
 */
public final class IdeogramPlotPainterTester extends TestCase {

  // ===============================
  //     Constants
  // ===============================

  /** Name of temporary directory for storing generated ata files. This is not an absolute path. */
  private static final String TEMP_DIR_NAME = "ideogram_plot_painter_test_dir";

  /**
   * Path to temporary directory for storing data files. It will be a subdirectory of the main unit
   * test temporary directory specified by the property 'temp.dir' in 'unit_test.properties.'
   */
  private static final String TEMP_DIR_PATH =
      UnitTestUtils.createUnitTestDirectory(TEMP_DIR_NAME).getAbsolutePath();

  /** Number of bioassays to generate in tests. */
  private static final int NUM_BIO_ASSAYS = 2;

  /** Number of chromosomes in tests. */
  private static final int NUM_CHROMOSOMES = 5;

  /** Number of experiments in tests. */
  private static final int NUM_EXPERIMENTS = 2;

  /** Number of array datum per chromosome in. */
  private static final int NUM_DATUM_PER_CHROMOSOME = 50;

  /** Length of chromosome in base pairs. */
  private static final long CHROM_LENGTH = 100000000;

  /** Number of cytobands. */
  private static final int NUM_CYTOBANDS = 10;

  // ===================================
  //     Test cases
  // ===================================

  /**
   * Test paintIdeogramPlot() method.
   *
   * @throws Exception if something bad happens
   */
  public void testPaintIdeogramPlot() throws Exception {

    // Create test experiments
    long gap = CHROM_LENGTH / NUM_DATUM_PER_CHROMOSOME;
    ExperimentGenerator expGen = new ExperimentGenerator(gap);
    Collection<Experiment> experiments = new ArrayList<Experiment>();
    for (int i = 0; i < NUM_EXPERIMENTS; i++) {
      Experiment exp =
          expGen.newInMemoryExperiment(NUM_BIO_ASSAYS, NUM_CHROMOSOMES, NUM_DATUM_PER_CHROMOSOME);
      exp.setQuantitationType(QuantitationType.COPY_NUMBER);
      experiments.add(exp);
      for (BioAssay ba : exp.getBioAssays()) {
        ba.setColor(Color.BLUE);
      }
    }
    for (int i = 0; i < NUM_EXPERIMENTS; i++) {
      Experiment exp =
          expGen.newInMemoryExperiment(NUM_BIO_ASSAYS, NUM_CHROMOSOMES, NUM_DATUM_PER_CHROMOSOME);
      exp.setQuantitationType(QuantitationType.FOLD_CHANGE);
      experiments.add(exp);
      for (BioAssay ba : exp.getBioAssays()) {
        ba.setColor(Color.RED);
      }
    }

    // Create plot parameters
    IdeogramPlotParameters params = new IdeogramPlotParameters();
    for (int i = 1; i <= NUM_CHROMOSOMES; i++) {
      params.add(new GenomeInterval((short) i, 1, CHROM_LENGTH));
    }
    params.setIdeogramSize(ChromosomeIdeogramSize.MEDIUM);
    params.setNumPlotsPerRow(2);

    // Create plotting panel
    RasterFileTestPlotPanel panel = new RasterFileTestPlotPanel(TEMP_DIR_PATH);

    // Create chromosome array data getter
    InMemoryChromosomeArrayDataGetter cadg = new InMemoryChromosomeArrayDataGetter();

    // Instantiate ideogram plot painter
    IdeogramPlotPainter painter = new IdeogramPlotPainter(cadg);

    // Create cytologial map DAO
    CytologicalMapDaoImpl cDao = new CytologicalMapDaoImpl(CHROM_LENGTH, NUM_CYTOBANDS);
    painter.setCytologicalMapDao(cDao);

    // Create plot
    painter.paintPlot(panel, experiments, params);

    // Add some additional reference widgets
    panel.add(
        new Caption("Left", null, Orientation.HORIZONTAL, false, panel.getDrawingCanvas()),
        HorizontalAlignment.LEFT_OF,
        VerticalAlignment.CENTERED);
    panel.add(
        new Caption("Right", null, Orientation.HORIZONTAL, false, panel.getDrawingCanvas()),
        HorizontalAlignment.RIGHT_OF,
        VerticalAlignment.CENTERED);

    // Output graphics to file
    panel.toPngFile("plot-in-memory.png");
  }
}