private void mergeTables(
      final CyTable source, final CyTable target, final Class<? extends CyIdentifiable> type) {
    CyColumn sourceKey = source.getPrimaryKey();
    CyColumn targetKey = target.getPrimaryKey();
    String keyName = sourceKey.getName();

    // Make sure keys match
    if (keyName.equals(targetKey.getName())) {
      // Merge columns first, because even if the source table has no rows to merge,
      // the columns have to be restored
      mergeColumns(keyName, source, target);

      for (CyRow sourceRow : source.getAllRows()) {
        if (cancelled) return;

        Long key = sourceRow.get(keyName, Long.class);
        CyIdentifiable entry = cache.getObjectById(key, type);
        Long mappedKey = entry != null ? entry.getSUID() : null;

        if (mappedKey == null) mappedKey = key;

        CyRow targetRow = target.getRow(mappedKey);
        mergeRow(keyName, sourceRow, targetRow);
      }
    }
  }
  private List<String> getAttributeList(
      CyNetwork network,
      Set<Class<?>> allowedNodeAttributeTypes,
      Set<Class<?>> allowedEdgeAttributeTypes) {
    List<String> attributes = new ArrayList<String>();
    Set<Class<?>> allowedTypes;
    CyTable table;
    if (allowedNodeAttributeTypes.size() > 0) {
      allowedTypes = allowedNodeAttributeTypes;
      table = network.getDefaultNodeTable();
    } else if (allowedEdgeAttributeTypes.size() > 0) {
      allowedTypes = allowedEdgeAttributeTypes;
      table = network.getDefaultEdgeTable();
    } else {
      return attributes;
    }

    for (final CyColumn column : table.getColumns()) {
      if (allowedTypes.contains(column.getType())) {
        attributes.add(column.getName());
      }
    }

    if (attributes.size() > 0) attributes.add(0, UNWEIGHTED);
    return attributes;
  }
 private List<String> getSupportedAttributes(Set<Class<?>> types, CyTable table) {
   List<String> attributes = new ArrayList<String>();
   attributes.add(UNWEIGHTED);
   for (CyColumn column : table.getColumns()) {
     for (Class<?> type : types) {
       if (column.getType().equals(type)) {
         attributes.add(column.getName());
         break;
       }
     }
   }
   if (attributes.size() > 1) return attributes;
   return null;
 }
Exemplo n.º 4
0
 boolean getSetData() {
   inputKeyColName = new TreeMap<String, String>();
   aimKeyColName = new TreeMap<String, String>();
   Collection<CyColumn> columnList = wgs.net.getDefaultNodeTable().getColumns();
   CyColumn col = null;
   Iterator<CyColumn> iter = columnList.iterator();
   while (iter.hasNext()) {
     col = iter.next();
     String colName;
     if (col.getType() != Double.class) continue;
     else colName = col.getName();
     if (colName.length() > lengthID) {
       if (colName.substring(0, lengthID).equals(inputSetID))
         inputKeyColName.put(colName.substring(lengthID), colName);
       if (colName.substring(0, lengthID).equals(outputAimID))
         aimKeyColName.put(colName.substring(lengthID), colName);
     }
   }
   if (inputKeyColName.isEmpty()) return false;
   Iterator<String> setIt = inputKeyColName.keySet().iterator();
   Iterator<String> aimIt = aimKeyColName.keySet().iterator();
   while (setIt.hasNext() & aimIt.hasNext()) if (!setIt.next().equals(aimIt.next())) return false;
   activIn = new double[inputKeyColName.keySet().size()][];
   activAim = new double[aimKeyColName.keySet().size()][];
   int set = 0;
   for (String key : inputKeyColName.keySet()) {
     activIn[set] = new double[wgs.nodes.size()];
     for (int n = 0; n < wgs.nodes.size(); n++) {
       Double d = wgs.net.getRow(wgs.nodes.get(n)).get(inputKeyColName.get(key), Double.class);
       if (d != null) {
         activIn[set][n] = d;
         if (d != 0.0) menuUtils.srcDialog.add(n);
       } else activIn[set][n] = 0.0;
     }
     activAim[set] = new double[wgs.nodes.size()];
     for (int n = 0; n < wgs.nodes.size(); n++) {
       Double d = wgs.net.getRow(wgs.nodes.get(n)).get(aimKeyColName.get(key), Double.class);
       if (d != null) activAim[set][n] = d;
       else activAim[set][n] = 0.0;
     }
     set++;
   }
   activOk = new int[inputKeyColName.keySet().size()];
   activNo = new int[inputKeyColName.keySet().size()];
   inhibOk = new int[inputKeyColName.keySet().size()];
   inhibNo = new int[inputKeyColName.keySet().size()];
   return true;
 }
  public ListSingleSelection<String> getTargetColumns(CyNetwork network) {
    CyTable selectedTable = network.getTable(CyNode.class, CyRootNetwork.SHARED_ATTRS);

    List<String> colNames = new ArrayList<String>();
    for (CyColumn col : selectedTable.getColumns()) {
      // Exclude SUID from the mapping key list
      if (col.getName().equalsIgnoreCase("SUID")) {
        continue;
      }
      colNames.add(col.getName());
    }

    ListSingleSelection<String> columns = new ListSingleSelection<String>(colNames);

    // columns.setSelectedValue("shared name"); this does not work, why
    return columns;
  }
  private void mergeColumns(final String keyName, final CyTable source, final CyTable target) {
    for (CyColumn column : source.getColumns()) {
      String columnName = column.getName();

      if (columnName.equals(keyName)) continue;

      if (target.getColumn(columnName) == null) {
        Class<?> type = column.getType();
        boolean immutable = column.isImmutable();

        if (type.equals(List.class)) {
          Class<?> elementType = column.getListElementType();
          target.createListColumn(columnName, elementType, immutable);
        } else {
          target.createColumn(columnName, type, immutable);
        }
      }
    }
  }
Exemplo n.º 7
0
 private Double getMean(CyColumn c) {
   Double x = 5d;
   List<Double> values = c.getValues(Double.class);
   Iterator<Double> it = values.iterator();
   while (it.hasNext()) {
     Double y = it.next();
     x += y;
   }
   x = x / values.size();
   return x;
 }
  private void mergeRow(String keyName, CyRow sourceRow, CyRow targetRow) {
    for (CyColumn column : sourceRow.getTable().getColumns()) {
      if (cancelled) return;

      String columnName = column.getName();

      if (columnName.equals(keyName)) continue;

      Class<?> type = column.getType();

      if (type.equals(List.class)) {
        Class<?> elementType = column.getListElementType();
        List<?> list = sourceRow.getList(columnName, elementType);
        targetRow.set(columnName, list);
      } else {
        Object value = sourceRow.get(columnName, type);
        targetRow.set(columnName, value);
      }
    }
  }
  private Collection<String> getAttributes(boolean node) {
    CyNetwork network = applicationManager.getCurrentNetwork();
    CyTable table = node ? network.getDefaultNodeTable() : network.getDefaultEdgeTable();
    Collection<CyColumn> columns = table.getColumns();

    Set<String> attributes =
        new TreeSet<String>(
            new Comparator<String>() {
              public int compare(String s1, String s2) {
                return s1.compareToIgnoreCase(s2);
              }
            });

    for (CyColumn column : columns) {
      if (!CyIdentifiable.SUID.equals(column.getName())
          && (node || Number.class.isAssignableFrom(column.getType()))) {
        attributes.add(column.getName());
      }
    }
    return attributes;
  }
Exemplo n.º 10
0
 private Double getMinimum(CyColumn c) {
   Double x = Double.MAX_VALUE;
   List<Double> values = c.getValues(Double.class);
   Iterator<Double> it = values.iterator();
   while (it.hasNext()) {
     Double y = it.next();
     if (y < x) {
       x = y;
     }
   }
   return x;
 }
  @Override
  public boolean handleIt(
      final CyIdentifiable to,
      final CyColumn toColumn,
      final Map<CyIdentifiable, CyColumn> mapFromGOFromAttr) {

    if (to == null || toColumn == null || mapFromGOFromAttr == null) {
      throw new java.lang.NullPointerException("All parameters should not be null.");
    }

    final CyTable table = toColumn.getTable();
    final CyRow row = table.getRow(to.getSUID());
    final ColumnType type = ColumnType.getType(toColumn);

    if (type == ColumnType.STRING) {
      final String toValue = row.get(toColumn.getName(), String.class);
      final Set<String> values = new TreeSet<String>();
      values.add(toValue);

      for (Map.Entry<CyIdentifiable, CyColumn> entry : mapFromGOFromAttr.entrySet()) {
        final CyIdentifiable from = entry.getKey();
        final CyColumn fromColumn = entry.getValue();
        final CyRow fromRow = fromColumn.getTable().getRow(from.getSUID());

        // TODO figure out which network to be using
        String fromValue = fromRow.get(fromColumn.getName(), String.class);
        if (fromValue != null) {
          values.add(fromValue.toString());
        }
      }

      StringBuilder str = new StringBuilder();
      for (String v : values) {
        str.append(v + ";");
      }

      str.deleteCharAt(str.length() - 1);
      row.set(toColumn.getName(), str.toString());

      return true;
    }

    // FIXME: how about Integer, Double, Boolean?
    return false;
  }
  /** Create the dialog. */
  @SuppressWarnings("serial")
  private PortalImportDialog() {

    setTitle("Load Data From cBio Portal");
    setBounds(100, 100, 650, 500);
    BorderLayout borderLayout = new BorderLayout();
    borderLayout.setVgap(2);
    borderLayout.setHgap(2);
    getContentPane().setLayout(borderLayout);
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(5, 5));
    {
      JScrollPane scrollPane = new JScrollPane();
      scrollPane.setViewportBorder(
          new TitledBorder(
              new LineBorder(new Color(184, 207, 229)),
              "Select Genomic Profile(s)",
              TitledBorder.LEADING,
              TitledBorder.TOP,
              null,
              new Color(51, 51, 51)));
      contentPanel.add(scrollPane, BorderLayout.CENTER);
      {
        profileList =
            new JList() {
              public String getToolTipText(MouseEvent event) { // tooltip for each profile
                Point point = event.getPoint();
                // Get the item in the list box at the mouse location
                int index = this.locationToIndex(point);
                // Get the value of the item in the list
                return ((GeneticProfile) this.getModel().getElementAt(index)).getDescription();
              }
            };
        scrollPane.setViewportView(profileList);
      }
    }
    {
      JPanel panel = new JPanel();
      contentPanel.add(panel, BorderLayout.NORTH);
      panel.setLayout(new GridLayout(2, 1, 0, 0));
      {
        JLabel lblNewLabel = new JLabel("Select a Cancer Study");
        panel.add(lblNewLabel);
      }
      cancerStudyComboBox = new JComboBox();
      panel.add(cancerStudyComboBox);
      cancerStudyComboBox.setRenderer(
          new BasicComboBoxRenderer() {
            public Component getListCellRendererComponent(
                JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
                if (-1 < index) {
                  list.setToolTipText(
                      "<html><body>"
                          + ((CancerStudy) cancerStudyComboBox.getModel().getElementAt(index))
                              .getDescription()
                          + "</body></html>");
                }
              } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
              }
              setFont(list.getFont());
              setText((value == null) ? "" : value.toString());
              return this;
            }
          });
      {
        JPanel panel_1 = new JPanel();
        contentPanel.add(panel_1, BorderLayout.SOUTH);
        panel_1.setLayout(new GridLayout(4, 1, 0, 0));
        {
          JLabel lblNewLabel_1 = new JLabel("Select Patient/Case Set");
          panel_1.add(lblNewLabel_1);
        }
        {
          caseSetComboBox = new JComboBox();
          panel_1.add(caseSetComboBox);
          caseSetComboBox.setRenderer(
              new BasicComboBoxRenderer() {
                public Component getListCellRendererComponent(
                    JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                  if (isSelected) {
                    setBackground(list.getSelectionBackground());
                    setForeground(list.getSelectionForeground());
                    if (-1 < index) {
                      list.setToolTipText(
                          "<html><body>"
                              + ((CaseList) caseSetComboBox.getModel().getElementAt(index))
                                  .getDescription()
                              + "</body></html>");
                    }
                  } else {
                    setBackground(list.getBackground());
                    setForeground(list.getForeground());
                  }
                  setFont(list.getFont());
                  setText((value == null) ? "" : value.toString());
                  return this;
                }
              });
        }
        {
          JLabel lblNewLabel_2 = new JLabel("Select Node Attribute for Gene Symbols");
          panel_1.add(lblNewLabel_2);
        }
        {
          geneSymbolComboBox = new JComboBox();
          panel_1.add(geneSymbolComboBox);
          // Get the node attributes from current network
          Collection<CyColumn> cols =
              MondrianApp.getInstance()
                  .getAppManager()
                  .getCurrentNetwork()
                  .getDefaultNodeTable()
                  .getColumns();
          List<String> attrs = new ArrayList<String>();
          final List<String> toolTips = new ArrayList<String>();
          for (CyColumn col : cols) {
            if (col.getType() != String.class) {
              continue; // Looking for gene symbols, which should be String column
            }
            attrs.add(col.getName());
            List<Object> values = col.getValues(col.getType());
            String toolTip = "<html><body>";
            for (int j = 0; j < Math.min(values.size(), 3); j++) {
              toolTip += values.get(j).toString();
              if (j < Math.min(values.size(), 3) - 1) toolTip += "<br/>";
            }
            if (values.size() > 3) toolTip += "<br/>...";
            toolTip += "</body></html>";
            toolTips.add(toolTip);
          }
          geneSymbolComboBox.setModel(
              new DefaultComboBoxModel(attrs.toArray(new String[attrs.size()])));
          geneSymbolComboBox.setRenderer(
              new BasicComboBoxRenderer() {
                public Component getListCellRendererComponent(
                    JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                  if (isSelected) {
                    setBackground(list.getSelectionBackground());
                    setForeground(list.getSelectionForeground());
                    if (-1 < index) {
                      list.setToolTipText(toolTips.get(index));
                    }
                  } else {
                    setBackground(list.getBackground());
                    setForeground(list.getForeground());
                  }
                  setFont(list.getFont());
                  setText((value == null) ? "" : value.toString());
                  return this;
                }
              });
        }
      }
      cancerStudyComboBox.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              CancerStudy study = (CancerStudy) cancerStudyComboBox.getSelectedItem();
              if (!study.equals(portalClient.getCurrentCancerStudy())) {
                DialogTaskManager taskManager = MondrianApp.getInstance().getTaskManager();
                taskManager.execute(new TaskIterator(new LoadCancerStudyTask()));
              }
            }
          });
    }
    {
      JPanel buttonPane = new JPanel();
      buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
      getContentPane().add(buttonPane, BorderLayout.SOUTH);
      {
        JButton okButton = new JButton("OK");
        okButton.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                PortalImportDialog.getInstance().setVisible(false);
                DialogTaskManager taskManager = MondrianApp.getInstance().getTaskManager();
                taskManager.execute(new TaskIterator(new ImportDataTask()));
              }
            });
        okButton.setActionCommand("OK");
        buttonPane.add(okButton);
        getRootPane().setDefaultButton(okButton);
      }
      {
        JButton cancelButton = new JButton("Cancel");
        cancelButton.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                PortalImportDialog.getInstance().setVisible(false);
              }
            });
        cancelButton.setActionCommand("Cancel");
        buttonPane.add(cancelButton);
      }
    }
    DialogTaskManager taskManager = MondrianApp.getInstance().getTaskManager();
    taskManager.execute(new TaskIterator(new InitializeCancerStudyTask()));
  }