Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  /**
   * *
   *
   * <p>Method to create the data groups. This method determines the labels to be used for groups.
   *
   * @param fileContents a matrix of Objects, which is the contents of the spreadsheet
   * @param group a string indicating the column to consider to form the groups, e.g. Factor
   * @param exactMatch true or false indicating whether the string match is exact or not
   * @param includeColumnNames true or false indicating if the columns names are included in the
   *     result (e.g if true the result will be 'Factor Value[<specific value>]', otherwise it will
   *     be '<specific value>' only)
   * @return Map<String, String>
   */
  private Map<String, StudyGroup> getDataGroupsWithTypeByColumn(
      Object[][] fileContents, String group, boolean exactMatch, boolean includeColumnNames) {

    // map for resulting groups
    // group name, study group object
    Map<String, StudyGroup> groups = new HashMap<String, StudyGroup>();

    String[] columnNames = Arrays.copyOf(fileContents[0], fileContents[0].length, String[].class);

    boolean allowedUnit = false;
    for (int row = 1; row < fileContents.length; row++) {
      Map<String, String> groupDefinition = new HashMap<String, String>();

      String groupVal = "";
      int elementsNumber = 0;
      for (int col = 0; col < columnNames.length; col++) {
        String column = columnNames[col];

        boolean match = false;

        if (exactMatch) {
          if (column.equalsIgnoreCase(group)) {
            match = true;
          } else if (allowedUnit && column.equalsIgnoreCase("unit")) {
            match = true;
          }
        } else {
          if (column.contains(group)) {
            match = true;
          } else if (allowedUnit && column.equalsIgnoreCase("unit")) {
            match = true;
          }
        }

        if (match) {
          if (!fileContents[row][col].equals("")) {
            groupVal +=
                (elementsNumber > 0 ? "|" : "")
                    + (includeColumnNames ? extractColumnType(column) + "=" : " ")
                    + fileContents[row][col];
            groupDefinition.put(extractColumnType(column), (String) fileContents[row][col]);
            elementsNumber++;
            allowedUnit = true;
          }
        } else
          allowedUnit =
              column.contains("Term Source REF") || column.contains("Term Accession Number");
      }
      if (!groupVal.equals("")) {
        groupVal = groupVal.trim();

        if (!groups.containsKey(groupVal)) {
          groups.put(groupVal, new StudyGroup(group, groupVal));
        }

        StudyGroup studyGroup = groups.get(groupVal);
        studyGroup.addGroupMember(getColValAtRow(fileContents, columnNames, "Sample Name", row));
        studyGroup.setGroupDefinition(groupDefinition);
      }
    }

    return groups;
  }