コード例 #1
0
  @Override
  protected BufferedDataTable[] execute(BufferedDataTable[] inData, ExecutionContext exec)
      throws Exception {

    List<File> inputFiles =
        FileSelectPanel.getInputFiles(propInputDir.getStringValue(), getAllowedFileExtensions());

    if (inputFiles.isEmpty()) {
      throw new RuntimeException("No files selected");
    }

    // first group files into plate-groups
    Map<String, List<File>> plateFiles = splitFilesIntoPlates(inputFiles);

    if (inputFiles.isEmpty()) {
      throw new RuntimeException("No valid envision-files in selection " + inputFiles);
    }

    // split files
    List<String> allAttributes = mergeAttributes(plateFiles);
    List<Attribute> colAttributes = compileColumnModel(allAttributes);

    DataTableSpec outputSpec = AttributeUtils.compileTableSpecs(colAttributes);
    BufferedDataContainer container = exec.createDataContainer(outputSpec);

    // populate the table
    int fileCounter = 0, rowCounter = 0;
    for (String barcode : plateFiles.keySet()) {

      logger.info("Processing plate " + barcode);

      Plate plate = new Plate();

      // invalidate plate-dims as these become fixed in the loop
      plate.setNumColumns(-1);
      plate.setNumRows(-1);

      for (File file : plateFiles.get(barcode)) {
        String attributeName = getAttributeNameOfEnvisionFile(file);
        parseFile(plate, attributeName, file);

        BufTableUtils.updateProgress(exec, fileCounter++, inputFiles.size());
      }

      // now create the data-rows for this table
      for (Well well : plate.getWells()) {
        if (well.getReadOutNames().isEmpty()) {
          continue;
        }

        DataCell[] knimeRow = new DataCell[colAttributes.size()];

        // first add the barcode-column
        knimeRow[0] = new StringCell(barcode);

        knimeRow[1] = colAttributes.get(1).createCell(well.getPlateRow());
        knimeRow[2] = colAttributes.get(2).createCell(well.getPlateColumn());

        for (String attributeName : allAttributes) {
          int rowIndex = allAttributes.indexOf(attributeName);
          Double value = well.getReadout(attributeName);

          if (value != null) {
            knimeRow[3 + rowIndex] = new DoubleCell(value);
          } else {
            knimeRow[3 + rowIndex] = DataType.getMissingCell();
          }
        }

        DataRow tableRow = new DefaultRow(new RowKey("" + rowCounter++), knimeRow);
        container.addRowToTable(tableRow);
      }
    }

    container.close();

    return new BufferedDataTable[] {container.getTable()};
  }
コード例 #2
0
  @Override
  protected BufferedDataTable[] execute(BufferedDataTable[] inData, ExecutionContext exec)
      throws Exception {

    BufferedDataTable input = inData[0];

    // Get the condition attribute
    Attribute treatmentAttribute =
        new InputTableAttribute(this.treatmentAttribute.getStringValue(), input);

    // Get the library and reference condition names
    String libraryName = AbstractScreenTrafoModel.getAndValidateTreatment(reference);
    String referenceName = AbstractScreenTrafoModel.getAndValidateTreatment(library);

    // Get the parameter and make sure there all double value columns
    List<Attribute> parameters = getParameterList(input);

    // Split the columns according to groups contained in the condition column
    Map<String, List<DataRow>> groupedRows = AttributeUtils.splitRows(input, treatmentAttribute);
    List<DataRow> libraryRows = groupedRows.get(libraryName);
    List<DataRow> referenceRows = groupedRows.get(referenceName);

    int progress = parameters.size();
    BufTableUtils.updateProgress(exec, progress / 2, progress);

    // Initialize
    BufferedDataContainer container = exec.createDataContainer(new DataTableSpec(getListSpec()));
    MutualInformation mutualinfo = new MutualInformation();
    mutualinfo.set_base(logbase.getDoubleValue());
    mutualinfo.set_method(method.getStringValue());
    mutualinfo.set_axeslinking(linkaxes.getBooleanValue());

    DataCell[] cells = new DataCell[container.getTableSpec().getNumColumns()];
    int p = 0;

    // Calculate mutual information
    for (Attribute parameter : parameters) {

      Double[] x = getDataVec(libraryRows, parameter);
      Double[] y = getDataVec(referenceRows, parameter);
      mutualinfo.set_vectors(x, y);

      if (binning.getIntValue() == 0) {
        mutualinfo.set_binning();
      } else {
        mutualinfo.set_binning(binning.getIntValue());
      }
      int[] bins = mutualinfo.get_binning();

      Double[] res = mutualinfo.calculate();

      cells[0] = new StringCell(parameter.getName());
      cells[1] = new DoubleCell(res[0]);
      cells[2] = new DoubleCell(res[1]);
      cells[3] = new DoubleCell(res[2]);
      cells[4] = new IntCell(bins[0]);
      cells[5] = new IntCell(bins[1]);
      cells[6] = new DoubleCell(mutualinfo.get_logbase());
      cells[7] = new StringCell(mutualinfo.get_method());

      container.addRowToTable(new DefaultRow("row" + p, cells));

      BufTableUtils.updateProgress(exec, (progress + p++) / 2, progress);
      exec.checkCanceled();
    }

    container.close();
    return new BufferedDataTable[] {container.getTable()};
  }