Ejemplo n.º 1
0
  private void display() {

    CyServiceRegistrarImpl register = new CyServiceRegistrarImpl(bc);

    CyNetworkViewManager viewManager = register.getService(CyNetworkViewManager.class);
    CyNetworkViewFactory viewFactory = register.getService(CyNetworkViewFactory.class);
    CyNetworkView networkView = viewFactory.createNetworkView(network);
    viewManager.addNetworkView(networkView);

    VisualMappingFunctionFactory passthroughFactory =
        register.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
    VisualMappingFunctionFactory continuousFactory =
        register.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
    VisualMappingManager vmManager = register.getService(VisualMappingManager.class);
    VisualStyleFactory vsFactory = register.getService(VisualStyleFactory.class);
    VisualStyle vs =
        vsFactory.createVisualStyle(
            network.getDefaultNetworkTable().getRow(network.getSUID()).get("name", String.class));

    PassthroughMapping pMapping =
        (PassthroughMapping)
            passthroughFactory.createVisualMappingFunction(
                "name", String.class, BasicVisualLexicon.NODE_LABEL);

    vs.addVisualMappingFunction(pMapping);
    vs.apply(networkView);

    ContinuousMapping mapping =
        (ContinuousMapping)
            continuousFactory.createVisualMappingFunction(
                "score", Double.class, BasicVisualLexicon.NODE_FILL_COLOR);

    Double val1 = getMinimum(network.getDefaultNodeTable().getColumn("score"));
    BoundaryRangeValues<Paint> brv1 =
        new BoundaryRangeValues<Paint>(Color.GREEN, Color.GREEN, Color.GREEN);

    Double val3 = getMaximum(network.getDefaultNodeTable().getColumn("score"));
    BoundaryRangeValues<Paint> brv3 =
        new BoundaryRangeValues<Paint>(Color.RED, Color.RED, Color.RED);

    Double val2 = (val1 + val3 + val1 + val1) / 4;
    BoundaryRangeValues<Paint> brv2 =
        new BoundaryRangeValues<Paint>(Color.YELLOW, Color.YELLOW, Color.YELLOW);

    mapping.addPoint(val1, brv1);
    mapping.addPoint(val2, brv2);
    mapping.addPoint(val3, brv3);

    vs.addVisualMappingFunction(mapping);
    vs.apply(networkView);

    vmManager.addVisualStyle(vs);
    vmManager.setVisualStyle(vs, networkView);
    networkView.updateView();
  }
Ejemplo n.º 2
0
  protected final Set<CyNetwork> getNetworksByQuery(final String query, final String column) {
    final Set<CyNetwork> networks = networkManager.getNetworkSet();
    final Set<CyNetwork> matchedNetworks = new HashSet<>();

    for (final CyNetwork network : networks) {
      // First, check shared table
      CyTable table = network.getDefaultNetworkTable();
      if (table.getColumn(column) == null) {
        table = network.getTable(CyNetwork.class, CyNetwork.LOCAL_ATTRS);
      }
      // If column does not exists in the default table, check local one:
      if (table.getColumn(column) == null) {
        // Still not found?  Give up and continue.
        // TODO: should we check hidden tables, too?
        continue;
      }
      final Object rawQuery = MapperUtil.getRawValue(query, table.getColumn(column).getType());
      final Collection<CyRow> rows = table.getMatchingRows(column, rawQuery);
      if (rows.isEmpty() == false) {
        matchedNetworks.add(network);
      }
    }
    return matchedNetworks;
  }
  @Override
  public void run(TaskMonitor taskMonitor) throws Exception {
    desktopApp.getJFrame().getGlassPane().setVisible(true);
    taskMonitor.setTitle("Gene Set / Mutation Analysis");
    taskMonitor.setStatusMessage("Loading file...");
    taskMonitor.setProgress(.25d);
    try {
      Map<String, Integer> geneToSampleNumber = null;
      Map<String, String> geneToSampleString = null;
      Map<String, Set<String>> sampleToGenes = null;
      Set<String> selectedGenes = null;

      if (format.equals("MAF")) {

        sampleToGenes =
            new MATFileLoader().loadSampleToGenes(file.getAbsolutePath(), chooseHomoGenes);
        selectedGenes =
            CancerAnalysisUtilitites.selectGenesInSamples(sampleCutoffValue, sampleToGenes);
      } else if (format.equals("GeneSample")) {
        geneToSampleNumber = new HashMap<String, Integer>();
        geneToSampleString = new HashMap<String, String>();
        loadGeneSampleFile(file, geneToSampleNumber, geneToSampleString);
        selectedGenes = selectGenesBasedOnSampleCutoff(geneToSampleNumber, sampleCutoffValue);
      } else if (format.equals("GeneSet")) {
        selectedGenes = loadGeneSetFile(file);
      }
      // Check if it is possible to construct the network
      // given the sample size.
      if (useLinkers) {
        taskMonitor.setStatusMessage("Checking FI Network size...");
        FINetworkService fiService = PlugInScopeObjectManager.getManager().getNetworkService();
        Integer cutoff = fiService.getNetworkBuildSizeCutoff();
        if (cutoff != null && selectedGenes.size() >= cutoff) {
          JOptionPane.showMessageDialog(
              desktopApp.getJFrame(),
              "The size of the gene set is too big. Linker genes should not be used!\n"
                  + "Please try again without using linker genes.",
              "Error in Building Network",
              JOptionPane.ERROR_MESSAGE);
          desktopApp.getJFrame().getGlassPane().setVisible(false);
          return;
        }
      }

      CytoPanel controlPane = desktopApp.getCytoPanel(CytoPanelName.WEST);
      int selectedIndex = controlPane.getSelectedIndex();
      taskMonitor.setStatusMessage("Constructing FI Network...");
      taskMonitor.setProgress(.50d);
      CyNetwork network = constructFINetwork(selectedGenes, file.getName());
      network.getDefaultNetworkTable().getRow(network.getSUID()).set("name", file.getName());
      if (network == null) {
        JOptionPane.showMessageDialog(
            desktopApp.getJFrame(),
            "Cannot find any functional interaction among provided genes.\n"
                + "No network can be constructed.\n"
                + "Note: only human gene names are supported.",
            "Empty Network",
            JOptionPane.INFORMATION_MESSAGE);
        desktopApp.getJFrame().getGlassPane().setVisible(false);
        return;
      }
      netManager.addNetwork(network);

      // Fix for missing default value persistence in CyTables
      // Should be remedied in the 3.1 api
      CyTable nodeTable = network.getDefaultNodeTable();
      for (Object name : network.getNodeList()) {
        CyNode node = (CyNode) name;
        Long nodeSUID = node.getSUID();
        nodeTable.getRow(nodeSUID).set("isLinker", false);
      }

      controlPane.setSelectedIndex(selectedIndex);
      if (sampleToGenes != null) {
        geneToSampleNumber = new HashMap<String, Integer>();
        geneToSampleString = new HashMap<String, String>();
        Map<String, Set<String>> geneToSamples =
            InteractionUtilities.switchKeyValues(sampleToGenes);
        geneToSamples.keySet().retainAll(selectedGenes);
        for (String gene : geneToSamples.keySet()) {
          Set<String> samples = geneToSamples.get(gene);
          geneToSampleNumber.put(gene, samples.size());
          geneToSampleString.put(gene, InteractionUtilities.joinStringElements(";", samples));
        }
      }
      taskMonitor.setStatusMessage("Formatting network attributes...");
      taskMonitor.setProgress(.65d);
      CyTableManager tableManager = new CyTableManager();
      CyNetworkView view = viewFactory.createNetworkView(network);
      tableManager.storeFINetworkVersion(view);
      tableManager.storeDataSetType(network, CyTableFormatter.getSampleMutationData());
      viewManager.addNetworkView(view);
      if (geneToSampleNumber != null && !geneToSampleNumber.isEmpty()) {
        tableManager.loadNodeAttributesByName(view, "sampleNumber", geneToSampleNumber);
      }
      if (geneToSampleString != null && !geneToSampleString.isEmpty()) {
        tableManager.loadNodeAttributesByName(view, "samples", geneToSampleString);
      }
      // Check if linker genes are to be used.
      if (useLinkers) {
        taskMonitor.setStatusMessage("Fetching linker genes...");
        Map<String, Boolean> geneToIsLinker = new HashMap<String, Boolean>();
        for (Object name : network.getNodeList()) {
          CyNode node = (CyNode) name;
          Long suid = node.getSUID();
          String nodeName = network.getDefaultNodeTable().getRow(suid).get("name", String.class);
          geneToIsLinker.put(nodeName, !selectedGenes.contains(nodeName));
        }
        tableManager.loadNodeAttributesByName(view, "isLinker", geneToIsLinker);
      }
      if (fetchFIAnnotations) {
        taskMonitor.setStatusMessage("Fetching FI annotations...");
        new FIAnnotationHelper().annotateFIs(view, new RESTFulFIService(), tableManager);
      }
      if (view.getModel().getEdgeCount() != 0) {
        for (CyEdge edge : view.getModel().getEdgeList()) {
          tableManager.storeEdgeName(edge, view);
        }
      }
      BundleContext context = PlugInScopeObjectManager.getManager().getBundleContext();
      ServiceReference visHelperRef = context.getServiceReference(FIVisualStyle.class.getName());
      if (visHelperRef != null) {
        FIVisualStyleImpl styleHelper = (FIVisualStyleImpl) context.getService(visHelperRef);
        styleHelper.setVisualStyle(view);
        styleHelper.setLayout();
      }
      //            BundleContext context =
      // PlugInScopeObjectManager.getManager().getBundleContext();
      //            ServiceReference styleHelperRef =
      // context.getServiceReference(FIVisualStyleImpl.class.getName());
      //            FIVisualStyleImpl styleHelper = (FIVisualStyleImpl)
      // context.getService(styleHelperRef);

      taskMonitor.setProgress(1.0d);
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          desktopApp.getJFrame(),
          "Error in Loading File: " + e.getMessage(),
          "Error in Loading",
          JOptionPane.ERROR_MESSAGE);
      desktopApp.getJFrame().getGlassPane().setVisible(false);
    }
    desktopApp.getJFrame().getGlassPane().setVisible(false);
  }