Exemple #1
0
  /**
   * @param type
   * @return a map whose keys are the values corresponding to nodes of type 'type' and the values
   *     are the number of them
   */
  private Map<String, Integer> extractNodes(NodeType type) {
    Map<String, Integer> resultNodes = new HashMap<String, Integer>();

    List<ISANode> node = graph.getNodes(type);

    for (ISANode nodeOfInterest : node) {
      // extract the values!
      for (int rowIndex = 1; rowIndex < assayTable.length; rowIndex++) {
        if (nodeOfInterest.getIndex() < assayTable[rowIndex].length) {

          String[] row =
              Arrays.copyOf(assayTable[rowIndex], assayTable[rowIndex].length, String[].class);
          String value = row[nodeOfInterest.getIndex()];
          if (value != null && !value.equals("")) {
            if (!resultNodes.containsKey(value)) {
              resultNodes.put(value, 1);
            } else {
              int newCount = resultNodes.get(value) + 1;
              resultNodes.put(value, newCount);
            }
          }
        }
      }
    }

    return resultNodes;
  }
Exemple #2
0
  /** @return Map with structure: < attribute name , < attribute value , row count >> */
  public Map<String, Map<String, Integer>> extractMaterialAttributes() {
    Map<String, Map<String, Integer>> resultNodes = new HashMap<String, Map<String, Integer>>();

    List<ISANode> node = graph.getNodes(NodeType.MATERIAL_NODE);

    for (ISANode nodeOfInterest : node) {
      // extract the values!
      MaterialNode materialNode = (MaterialNode) nodeOfInterest;

      for (ISANode property : materialNode.getMaterialAttributes()) {

        for (int rowIndex = 1; rowIndex < assayTable.length; rowIndex++) {

          if (property.getIndex() < assayTable[rowIndex].length) {
            String[] row =
                Arrays.copyOf(assayTable[rowIndex], assayTable[rowIndex].length, String[].class);

            String value = row[property.getIndex()];
            if (value != null && !value.equals("")) {

              if (!resultNodes.containsKey(property.getName())) {
                resultNodes.put(property.getName(), new HashMap<String, Integer>());
              }

              if (!resultNodes.get(property.getName()).containsKey(value)) {
                resultNodes.get(property.getName()).put(value, 1);
              } else {
                int newCount = resultNodes.get(property.getName()).get(value) + 1;
                resultNodes.get(property.getName()).put(value, newCount);
              }
            }
          }
        }
      }
    }
    return resultNodes;
  }
Exemple #3
0
  private void createGraph() {
    graph = new Graph();
    String[] columns = Arrays.copyOf(assayTable[0], assayTable[0].length, String[].class);

    int index = 0;

    ProcessNode lastProcess = null;
    NodeWithComments lastMaterialOrData = null;
    NodeWithComments lastSample = null;
    ISAFactorValue lastFactorValue = null;
    ProtocolExecutionNode lastProtocolExecutionNode = null;
    List<ProtocolExecutionNode> protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();

    for (String column : columns) {

      if (column.matches(Date.REGEXP)) {
        Date date = new Date(index, column);
        if (lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.addDate(date);
        }

      } else if (column.matches(Performer.REGEXP)) {
        Performer performer = new Performer(index, column);
        if (lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.addPerformer(performer);
        }

      } else if (column.matches(ProtocolExecutionNode.REGEXP)) {
        ProtocolExecutionNode protocolExecutionNode = new ProtocolExecutionNode(index, column);
        protocolExecutionNodes.add(protocolExecutionNode);
        lastProtocolExecutionNode = protocolExecutionNode;

        if (lastMaterialOrData != null) {
          protocolExecutionNode.setInputNode(lastMaterialOrData);
        }

        graph.addNode(protocolExecutionNode);

      } else if (column.matches(ProcessNode.REGEXP)) {
        ProcessNode processNode = new ProcessNode(index, column);

        graph.addNode(processNode);
        if (lastMaterialOrData != null) {
          // but it could be a DataNode rather than a material node... do I need a new object?
          // processNode.setInputNode(
          //       new MaterialNode(lastMaterialOrData.getIndex(), lastMaterialOrData.getName()));
          processNode.setInputNode(lastMaterialOrData);
        }
        lastProcess = processNode;
        if (lastProcess != null) {
          lastProcess.addProtocolExecutionNodes(protocolExecutionNodes);
          protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();
        }

      } else if (column.contains(ISADataNode.CONTAINS) && !column.contains("Comment")) {
        NodeWithComments dataNode = new DataNode(index, column);
        graph.addNode(dataNode);
        lastMaterialOrData = dataNode;

        if (lastProcess != null) {
          lastProcess.setOutputNode(dataNode);
          lastProcess = null;
        } else if (lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.setOutputNode(dataNode);
          lastProtocolExecutionNode = null;
        }

        if (lastMaterialOrData != null
            && lastProcess == null
            && lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.setOutputNode(dataNode);
          protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();
        }

      } else if (column.matches(ISAMaterialAttribute.REGEXP)) {

        ISAMaterialAttribute materialAttribute = new MaterialAttribute(index, column);
        if (lastMaterialOrData != null && lastMaterialOrData instanceof MaterialNode) {
          ((MaterialNode) graph.getNode(lastMaterialOrData.getIndex()))
              .addMaterialAttribute(materialAttribute);
        }

      } else if (column.matches(MaterialNode.REGEXP)) {

        NodeWithComments materialNode = null;
        if (column.matches(ISASampleNode.REGEXP)) {
          materialNode = new SampleNode(index, column);
          lastSample = materialNode;
        } else {
          materialNode = new MaterialNode(index, column);
        }
        // if there is a previous material node
        // and no process node, add a dummy process node
        if (lastMaterialOrData != null
            && lastProcess == null
            && lastProtocolExecutionNode != null) {
          lastProtocolExecutionNode.setOutputNode(materialNode);
          protocolExecutionNodes = new ArrayList<ProtocolExecutionNode>();
        }

        graph.addNode(materialNode);
        lastMaterialOrData = materialNode;
        if (lastProcess != null) {
          lastProcess.setOutputNode(materialNode);
          lastProcess = null;
        }

      } else if (column.matches(ISAFactorValue.REGEXP)) {

        ISAFactorValue factorValue = new FactorValue(index, column);
        lastFactorValue = factorValue;
        if (lastSample != null && lastSample instanceof SampleNode) {
          ((SampleNode) graph.getNode(lastSample.getIndex())).addFactorValue(factorValue);
        }

      } else if (column.matches(ISAUnit.REGEXP)) {

        ISAUnit unit = new Unit(index, column);
        if (lastFactorValue != null) {
          lastFactorValue.setUnit(unit);
        }

      } else if (column.matches(ProcessParameter.REGEXP)) {

        ProcessParameter parameter = new ProcessParameter(index, column);

        if (lastProtocolExecutionNode != null) {
          ((ProcessNode) graph.getNode(lastProtocolExecutionNode.getIndex()))
              .addParameter(parameter);
        }

      } else if (column.matches(CommentNode.REGEXP)) {

        CommentNode commentNode = new CommentNode(index, column);

        if (lastProcess != null
            && lastMaterialOrData != null
            && lastProtocolExecutionNode != null) {

          // lastProcess greater index
          if (lastProcess.getIndex() > lastMaterialOrData.getIndex()
              && lastProcess.getIndex() > lastProtocolExecutionNode.getIndex()) {
            lastProcess.addComment(commentNode);
          } else if (lastMaterialOrData.getIndex() > lastProcess.getIndex()
              && lastMaterialOrData.getIndex() > lastProtocolExecutionNode.getIndex()) {
            lastMaterialOrData.addComment(commentNode);
          } else if (lastProtocolExecutionNode.getIndex() > lastProcess.getIndex()
              && lastProtocolExecutionNode.getIndex() > lastMaterialOrData.getIndex()) {
            lastProtocolExecutionNode.addComment(commentNode);
          }

        } else { // one of them is null

          if (lastProcess != null && lastMaterialOrData != null) {

            if (lastProcess.getIndex() > lastMaterialOrData.getIndex()) {
              lastProcess.addComment(commentNode);
            } else {
              lastMaterialOrData.addComment(commentNode);
            }

          } else if (lastProcess != null && lastProtocolExecutionNode != null) {

            if (lastProcess.getIndex() > lastProtocolExecutionNode.getIndex()) {
              lastProcess.addComment(commentNode);
            } else {
              lastProtocolExecutionNode.addComment(commentNode);
            }

          } else if (lastMaterialOrData != null && lastProtocolExecutionNode != null) {

            if (lastMaterialOrData.getIndex() > lastProtocolExecutionNode.getIndex()) {
              lastMaterialOrData.addComment(commentNode);
            } else {
              lastProtocolExecutionNode.addComment(commentNode);
            }

          } else {

            // only one is not null

            if (lastMaterialOrData != null) {
              lastMaterialOrData.addComment(commentNode);
            } else if (lastProcess != null) {
              lastProcess.addComment(commentNode);
            } else if (lastProtocolExecutionNode != null) {
              lastProtocolExecutionNode.addComment(commentNode);
            }
          }
        }
      }
      index++;
    }
  }